Skip to content
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

v2v: Add automate methods for post-import network configuration #123

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -157,7 +178,7 @@ object:
name: post2
display_name:
datatype: string
priority: 8
priority: 9
owner:
default_value:
substitute: true
Expand All @@ -177,7 +198,7 @@ object:
name: post3
display_name:
datatype: string
priority: 9
priority: 10
owner:
default_value:
substitute: true
Expand All @@ -197,7 +218,7 @@ object:
name: email
display_name:
datatype: string
priority: 10
priority: 11
owner:
default_value:
substitute: true
Expand All @@ -217,7 +238,7 @@ object:
name: finish
display_name:
datatype: string
priority: 11
priority: 12
owner:
default_value:
substitute: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matobet Can we add a test for this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tinaafitz done

# 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
Original file line number Diff line number Diff line change
@@ -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: []
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matobet, can we update the spec test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tinaafitz done

@handle.root['ae_result'] = 'ok'
when 'failure'
@handle.root['ae_result'] = 'error'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down