From 77e5a3b76e74bd07a0ea1546308eed50d0f796f2 Mon Sep 17 00:00:00 2001 From: Martin Betak Date: Thu, 1 Jun 2017 12:13:14 +0200 Subject: [PATCH] v2v: Add automate methods for post-import network configuration Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1404920 --- .../VmImport.class/__class__.yaml | 31 ++++++++++--- .../__methods__/configure_vm_networks.rb | 43 +++++++++++++++++++ .../__methods__/configure_vm_networks.yaml | 12 ++++++ .../__methods__/wait_for_vm_import.rb | 1 + .../__methods__/configure_vm_networks_spec.rb | 29 +++++++++++++ .../__methods__/wait_for_vm_import_spec.rb | 1 + 6 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.rb create mode 100644 content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.yaml create mode 100644 spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks_spec.rb diff --git a/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__class__.yaml b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__class__.yaml index b8dd4c347..2c265ced5 100644 --- a/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__class__.yaml +++ b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__class__.yaml @@ -134,11 +134,32 @@ object: max_time: - field: aetype: state - name: post1 + name: ConfigureNetworks display_name: datatype: string priority: 7 owner: + default_value: METHOD::configure_vm_networks + substitute: false + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: update_vm_import_status(status => 'Updating imported VM's networks') + on_exit: update_vm_import_status(status => 'Configuration of VM networks completed') + on_error: update_vm_import_status(status => 'Error configuring imported VM's + networks') + max_retries: '100' + max_time: + - field: + aetype: state + name: post1 + display_name: + datatype: string + priority: 8 + owner: default_value: substitute: true message: create @@ -157,7 +178,7 @@ object: name: post2 display_name: datatype: string - priority: 8 + priority: 9 owner: default_value: substitute: true @@ -177,7 +198,7 @@ object: name: post3 display_name: datatype: string - priority: 9 + priority: 10 owner: default_value: substitute: true @@ -197,7 +218,7 @@ object: name: email display_name: datatype: string - priority: 10 + priority: 11 owner: default_value: substitute: true @@ -217,7 +238,7 @@ object: name: finish display_name: datatype: string - priority: 11 + priority: 12 owner: default_value: substitute: true diff --git a/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.rb b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.rb new file mode 100644 index 000000000..16e7354c0 --- /dev/null +++ b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.rb @@ -0,0 +1,43 @@ +# +# Description: This method initiates post-import configuration of VM network interfaces. +# + +module ManageIQ + module Automate + module Infrastructure + module VM + module Transform + module StateMachines + class ConfigureVmNetworks + def initialize(handle = $evm) + @handle = handle + end + + def main + validate_root_args %w(provider_id) + + provider = @handle.vmdb(:ext_management_system, @handle.root['provider_id']) + vm_id = @handle.get_state_var('imported_vm_id') + @handle.log(:info, "Configuring VM ID: #{vm_id} Networks") + provider.submit_configure_imported_vm_networks(@handle.root['user'].userid, vm_id) + end + + def validate_root_args(arg_names) + arg_names.each do |name| + next if @handle.root[name].present? + msg = "Error, required root attribute: #{name} not found" + @handle.log(:error, msg) + raise msg + end + end + end + end + end + end + end + end +end + +if __FILE__ == $PROGRAM_NAME + ManageIQ::Automate::Infrastructure::VM::Transform::StateMachines::ConfigureVmNetworks.new.main +end diff --git a/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.yaml b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.yaml new file mode 100644 index 000000000..74a4135fb --- /dev/null +++ b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.yaml @@ -0,0 +1,12 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: configure_vm_networks + display_name: + description: + scope: instance + language: ruby + location: inline + inputs: [] diff --git a/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import.rb b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import.rb index e36f1b82a..9febc0569 100644 --- a/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import.rb +++ b/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import.rb @@ -19,6 +19,7 @@ def main status = vm.custom_get(:import_status) case status when 'success' + @handle.set_state_var('imported_vm_id', vm.id) @handle.root['ae_result'] = 'ok' when 'failure' @handle.root['ae_result'] = 'error' diff --git a/spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks_spec.rb b/spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks_spec.rb new file mode 100644 index 000000000..bbe1866f6 --- /dev/null +++ b/spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks_spec.rb @@ -0,0 +1,29 @@ +require_domain_file + +describe ManageIQ::Automate::Infrastructure::VM::Transform::StateMachines::ConfigureVmNetworks do + let(:user) { FactoryGirl.create(:user_admin) } + let(:provider) { FactoryGirl.create(:ems_redhat) } + + let(:svc_model_user) { MiqAeMethodService::MiqAeServiceUser.find(user.id) } + let(:svc_model_provider) { MiqAeMethodService::MiqAeServiceManageIQ_Providers_Redhat_InfraManager.find(provider.id) } + + let(:root_object) do + Spec::Support::MiqAeMockObject.new( + :user => svc_model_user, + :name => 'my_vm', + :provider_id => provider.id + ) + end + + let(:vm_id) { 42 } + + let(:ae_service) { Spec::Support::MiqAeMockService.new(root_object, 'imported_vm_id' => vm_id) } + + it 'Calls :submit_import_vm on the provider object with correct params' do + allow(ae_service).to receive(:vmdb).with(:ext_management_system, provider.id).and_return(svc_model_provider) + + expect(svc_model_provider).to receive(:submit_configure_imported_vm_networks).with(user.userid, vm_id) + + described_class.new(ae_service).main + end +end diff --git a/spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import_spec.rb b/spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import_spec.rb index 887990233..3e3e0b8bd 100644 --- a/spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import_spec.rb +++ b/spec/content/automate/ManageIQ/Infrastructure/VM/Transform/StateMachines/VmImport.class/__methods__/wait_for_vm_import_spec.rb @@ -25,6 +25,7 @@ described_class.new(ae_service).main expect(ae_service.root['ae_result']).to eq('ok') + expect(ae_service.get_state_var('imported_vm_id')).to eq(vm.id) end end