-
Notifications
You must be signed in to change notification settings - Fork 120
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 methods for VM import between providers #36
Conversation
dd03e99
to
7780a59
Compare
Depends on ManageIQ/manageiq#13916 |
7780a59
to
a385c08
Compare
@matobet For the newer methods we are following a module approach so that we can test them outside of the Automate Engine. A good example to follow would be a method and spec like Method Spec |
a385c08
to
86417e3
Compare
@mkanoor Posted new (modularized) version of the scripts, can you please tell me if I'm on the right track? |
:storage_id => storage_id, | ||
:sparse => sparse | ||
) | ||
exit MIQ_OK |
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.
@matobet
We don't need the exit you can use @handle.root['ae_result'] = 'ok'
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.
done
|
||
provider.import_vm( | ||
vm.id, | ||
:name => name, |
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.
@matobet
Could we not use the local variables and directly use the attribute values from root
provider.import_vm(
@handle.root['vm'].id,
:name => @handle.root['dialog_name'],
:cluster_id => @handle.root['dialog_cluster'],
:storage_id => @handle.root['dialog_storage'],
:sparse => @handle.root['dialog_sparse'])
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.
done
86417e3
to
07756c3
Compare
values_hash = {} | ||
values_hash[''] = '-- select target infrastructure provider from list --' | ||
|
||
managers = @handle.vmdb('ManageIQ_Providers_Redhat_InfraManager').all.select(&:validate_import_vm) |
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 When writing the specs for this script, how should I approach to mocking this call to vmdb(ManageIQ_Providers_Redhat_InfraManager)
? I tried looking in other specs and found no example of this..
From what I understand the basic idea is to create the backing AR model, e.g.
let(:provider) { FactoryGirl.create(:ems_redhat) }
and then create the "wrapping"
let(:svc_model_provider) { MiqAeMethodService::MiqAeServiceManageIQ_Providers_Redhat_InfraManager.find(provider.id) }
but I'm not sure how to proceed in this case... (tests are currently failing with "Service Model not found"
.
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.
ok solved
07756c3
to
a52ae6c
Compare
end | ||
end | ||
list_values = { | ||
'sort_by' => :value, |
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.
@matobet
Do you want the Dialogs to show items sorted by ID or by description/name?
If you want it to displayed sorted by name description the sort_by => 'description'
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.
done
values_hash['!'] = '-- No clusters found --' | ||
else | ||
provider.ems_clusters.each do |cluster| | ||
values_hash[cluster.id.to_s] = cluster.name |
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.
@matobet
could the key here be just id and not id string
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.
done
if !provider_id.nil? && !provider_id.empty? && provider_id != '!' | ||
provider = @handle.vmdb(:ext_management_system, provider_id) | ||
if provider.nil? | ||
values_hash['!'] = '-- No clusters found --' |
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.
@matobet
We typically use nil => "None" as the default for
https://github.com/ManageIQ/manageiq-content/blob/master/content/automate/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors.rb#L27
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.
done
values_hash = {} | ||
values_hash[''] = '-- select cluster from list --' | ||
|
||
provider_id = @handle.root['dialog_provider'] |
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.
@matobet
Are you expecting the @handle.root['dialog_provider'] to be ! at some point as a default value
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 The '!'
value of provider_id
is being handled at line 17, if that is your question.
a52ae6c
to
6241c3e
Compare
|
||
def main | ||
values_hash = {} | ||
values_hash[''] = '-- select storage from list --' |
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.
@matobet
I think the key here should be nil
value_hash[nil] = '-- select storage from list --'
On line 21 you are setting nil to None if no providers are found.
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.
done
6241c3e
to
00f6d5b
Compare
@@ -0,0 +1,45 @@ | |||
module ManageIQ |
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.
@matobet
can you please add a spec for this method and all the other methods.
https://github.com/ManageIQ/manageiq-content/blob/master/spec/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials_spec.rb
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.
we are requesting that every automate method have an associated spec. Please add the missing specs for the list methods
00f6d5b
to
9a70856
Compare
@mkanoor done, but now this patch also depends on the core patch adding required factories for the specs ManageIQ/manageiq#14017 |
05e728f
to
3fe9d9d
Compare
8dce9b5
to
1cacf6e
Compare
@tinaafitz pushed new version, added missing tests and hopefully addressed your comments :) |
@@ -0,0 +1,53 @@ | |||
--- |
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.
@matobet We're working on documenting guidelines for adding State Machines to the ManageIQ domain.
Can you modify your ImportVM State Machine as follows:
Minimum Requirements for ManageIQ domain State Machines:
(In addition to the specific processing states required by the new state machine)
-
Minimum of 3 Pre states(pre1, pre2, pre3)
-
Minimum of 3 Post states(post1, post2, post3)
-
update_*_status method required for every states on_entry, on_exit, on_error
a. * update request with enhanced message including
updated_message = "[#{$evm.root['miq_server'].name}] "
updated_message += "Step [#{$evm.root['ae_state']}] "
updated_message += "Status [#{status}] "
updated_message += "Message [#{prov.message}] "
updated_message += "Current Retry Number [#{$evm.root['ae_state_retries']}]" if
$evm.root['ae_result'] == 'retry'
b. * set user_message in request:
prov.miq_request.user_message = updated_message
c. * create notification and error log message on error
if $evm.root['ae_result'] == "error"
$evm.create_notification(:level => "error"
:message => "VM Provision Error: #{updated_message}")
$evm.log(:error, "VM Provision Error: #{updated_message}")
end
- Finished state
Can use CommonMethods finished method:
/System/CommonMethods/StateMachineMethods/your_instance_name_here
(Add an instance to the /System/CommonMethods/StateMachineMethods class with your instance name. Can optionally modify task_finished method in that class for special processing)
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.
@tinaafitz ok, 1) and 2) seems pretty straightforward (I assume the states to be of type string
)
but regarding 3) what is exactly necessary? add 3 methods for each state of the state machine (with the new pre and post that would total to 8*3=24 new methods)?
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.
@tinaafitz and regarding 4) the state will be part of the ImportVm state machine (after the last "post" state)?
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.
@tinaafitz Done, please review at your nearest convenience :)
a9202e8
to
1a9520f
Compare
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.
@matobet - Great job on all of your changes!
I ran all of the spec tests and they look good.
I made just a few comments and I'm finished with the review. The next step is I'll ask @mkanoor for a final review.
Could you provide a brief explanation of setup/prerequisites/use cases for documentation purposes?
let(:miq_server) { EvmSpecHelper.local_miq_server } | ||
let(:ems) { FactoryGirl.create(:ems_redhat) } | ||
let(:vm) { FactoryGirl.create(:vm_redhat) } | ||
let(:miq_event) { FactoryGirl.create(:miq_event, :event_type => event_type) } |
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.
@matobet miq_event is not needed here.
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.
done
end | ||
|
||
def main | ||
options = { |
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.
@matobet - Could you add basic validation that the required arguments exist before calling execute to create the automation request?
Here's a sample basic validation method:
def validate_root_args(arg_names)
arg_names.each do |name|
unless $evm.root[name].present?
msg = "Error, required root attribute: #{name} not found"
$evm.log(:error, msg)
raise msg
end
end
end
and you can call it prior to calling execute....
validate_root_args(%w(vm dialog_name dialog_provider dialog_cluster dialog_sparse))
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.
done
|
||
def main | ||
provider = @handle.vmdb(:ext_management_system, @handle.root['provider_id']) | ||
@handle.log(:info, 'Submitting Import') |
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.
@matobet - Could you add basic validation that the required arguments exist before calling submit_import_vm?
Here's a sample basic validation method:
def validate_root_args(arg_names)
arg_names.each do |name|
unless $evm.root[name].present?
msg = "Error, required root attribute: #{name} not found"
$evm.log(:error, msg)
raise msg
end
end
end
and you can call it prior to calling execute....
validate_root_args(%w(vm name cluster_id storage_id sparse))
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.
done
Hi @tinaafitz thank you for the review, I addressed all your comments but I'm not sure what exactly do you mean by setup/prerequisites/use cases for documentation purposes? |
@matobet Thanks for making the changes. I'll ask @mkanoor to review. I think the information is all here, maybe if you could provide a brief explanation to a new user wanting to use v2. |
@matobet Can you fix the rubocop warning, we can use a next if the variable is present else raise an error |
|
@mkanoor done |
Checked commit matobet@62030d8 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@tinaafitz as per our discussion, posting here short feature description: Feature Overview
RESTAdded a new action to the providers REST resource that allows for importing vms. {
"action" : "import_vm",
"resource" : {
"source": { "href": "http://localhost:3000/api/vms/:source_vm_id" },
"target": {
"name": "<name of newly created VM in RHEV>",
"data_store": { "href": "http://localhost:3000/api/:target_data_store_id" },
"cluster": { "href": "http://localhost:3000/api/:target_cluster_id" },
"sparse": "[true|false]"
}
}
} For now only the combination of a Vmware source VM and a RHEV as the target provider is supported. UI
|
@matobet Looks good. |
Add automate methods for VM import between providers (cherry picked from commit bd5bb97) https://bugzilla.redhat.com/show_bug.cgi?id=1459996
Fine backport details:
|
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1404920
Added automate methods required to back the transform vm service dialog (ManageIQ/manageiq#13794 ManageIQ/manageiq-ui-classic#383) facilitating v2v conversion of VMs between two infra providers.
The dialog consists of 3 select boxes (target infra provider, cluster, storage domain) and a single checkbox that controls whether thin provisioning is enabled. To supply those select boxes we provided the
list_infra_providers
,list_clusters
andlist_storages
methods respectively.