-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add automate engine support for array elements containing text values. #11667
Conversation
@mkanoor @Fryguy Please review cc @eclarizio @d-m-u |
@gmcculloug @tinaafitz this would get stored as my_values = [1,2,3] This is already supported in https://github.com/ManageIQ/manageiq/blob/master/lib/miq_automation_engine/engine/miq_ae_object.rb#L524 But there is a bug in this line which only seems to honor vmdb objects Another bug that exists is we cannot have spaces between values after the , |
expect(result["my_values"].first).to eq("abc") | ||
expect(result["my_values"].second).to be_kind_of(MiqAeMethodService::MiqAeServiceVmOrTemplate) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would just structure this slightly differently:
describe "#process_args_as_attributes" do
let(:result) { @miq_obj.process_args_as_attributes("Array::my_values" => my_values) }
context "with an array containing strings" do
let(:my_values) { "abc,xyz,,1" }
it "stores the values as an array of strings" do
expect(result["my_values"]).to eq(%w(abc xyz 1))
end
end
context "with an array containing strings and objects" do
let(:my_values) { "abc,VmOrTemplate::#{@vm.id}" }
it "stores the first value as a string" do
expect(result["my_values"].first).to eq("abc")
end
it "stores the second value as an MiqAeMethodService::MiqAeServiceVmOrTemplate" do
expect(result["my_values"].second).to be_kind_of(MiqAeMethodService::MiqAeServiceVmOrTemplate)
end
end
end
@mkanoor - Regarding the bug referenced in
Is there any known reason why that check took place? |
f4fce37
to
b07a184
Compare
end | ||
|
||
it "stores the second value as a Host object" do | ||
expect(result["my_values"].second).to eq("fred::12") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor - @gmcculloug's implementation will allow for "fred::12" to get passed as datatype fred
value 12
to process_args_as_attributes
.
We had talked earlier of forcing process_args_as_attributes
to raise an error if a datatype was invalid.
I prototyped some code to see how this would affect the the current specs.
CLASS_TYPES = %w( boolean TrueClass FalseClass time Time symbol Symbol integer Fixnum float Float array String password )
With the list of allowed datatypes as above
raise MiqAeException::InvalidClass unless CLASS_TYPES.include?(datatype)
This brought out other issues as there are sundry datatypes
passed through process_args_as_attributes
when the a new instance of the MiqAeEngine is instantiated. Many of these types are neither an exposed service model - or part of the basic types handled here: https://github.com/gmcculloug/manageiq/blob/b07a184a9c7cee349fac2725d93dc7afd6485a72/lib/miq_automation_engine/engine/miq_ae_object.rb#L527-L535
The original code would allow all of these invalid datatypes to pass through.
I'm wondering if @gmcculloug's implementation will allow for fewer legacy Automate code issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syncrou Are we checking if datatype is specified before we check for validity and raise the error
objects_str.split(',').collect do |element| | ||
if element.include?(CLASS_SEPARATOR) | ||
klass, str_value = element.split(CLASS_SEPARATOR) | ||
value = MiqAeObject.convert_value_based_on_datatype(str_value, klass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmcculloug - I ran into an issue with klass
if strip
is not called here.
when a string is passed in "integer::1, integer::3, integer::5" klass is set to " integer" and doesn't resolve correctly in convert_value_based_on_datatype
https://github.com/gmcculloug/manageiq/blob/b07a184a9c7cee349fac2725d93dc7afd6485a72/lib/miq_automation_engine/engine/miq_ae_object.rb#L532
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syncrou we would have to trim the klass value before we use it.
7c2b5c6
to
fb5887a
Compare
let(:result) { @miq_obj.process_args_as_attributes("Array::my_values" => my_values) } | ||
|
||
context "with an array containing invalid entries" do | ||
let(:my_values) { "VmOrTemplate::#{@vm.id},fred::12,,VmOrTemplate::#{FactoryGirl.create(:vm_vmware).id}" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syncrou
is the ,, testing nil values? But wouldn't fred::12 raise the exception before it processes the nil value
fb5887a
to
ab24e5c
Compare
@mkanoor - I modified the test you commented on and added a new one to handle the empty values. |
This pull request is not mergeable. Please rebase and repush. |
Raise exceptions if the passed in datatype can not be validated
ab24e5c
to
3d1954e
Compare
Checked commits gmcculloug/manageiq@82711a5~...3d1954e with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 spec/lib/miq_automation_engine/miq_ae_object_spec.rb
|
@mkanoor Please review |
@gmcculloug Is there a BZ for this (or any related PRs)? Can you please create one if it doesn't already exist? |
@simaishi BZ https://bugzilla.redhat.com/show_bug.cgi?id=1428552 opened to track this feature. Also requires #10270 and ManageIQ/manageiq-ui-classic#114 |
@gmcculloug |
Backported to Euwe via #14394 |
@mkanoor @mkanoor @syncrou I suspect I'm seeing an error related to this on euwe: We might be using the automate wrong, but anyway this change exposed the error. |
Automate supports passing an array of objects on the URL to the engine. This PR modifies that logic to allow strings to be passed as well. This functionality supports the multi-select drop-down being added to the Service Dialogs in PR #10270.
Links
Steps for Testing/QA
Test using the multi-select control from the service dialog wired to a custom button. Configure the button to call the
System/Request/InspectMe
method. Logging will show the array containing each selected key passed from the dialog field.