Skip to content

Commit

Permalink
Merge pull request #684 from lfu/retire_ovf_vm_ibm_16312
Browse files Browse the repository at this point in the history
Support the retirement of VM provisioned by OVF service template
  • Loading branch information
agrare authored Jan 11, 2021
2 parents 78c8526 + 6d04930 commit 66ee8d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ def check_refreshed(action)
dest = find_destination_in_vmdb
if dest
add_resource!(dest, :name => action)
tag_lifecycle(dest)

if dest.kind_of?(ResourcePool)
dest.vms.each { |vm| add_resource!(vm, :name => action) }
dest.vms.each do |vm|
add_resource!(vm, :name => action)
tag_lifecycle(vm)
end
end

[true, nil]
Expand Down Expand Up @@ -151,4 +155,14 @@ def parse_dialog_options
def action_option_key(action)
"#{action.downcase}_options".to_sym
end

def tag_lifecycle(target)
target.tag_add("retire_full", :ns => "/managed", :cat => "lifecycle")
Notification.create(
:type => "automate_user_info",
:subject => self,
:options => {:message => "[#{target.class}] [#{target.id}] has been tagged with /lifecycle/retire_full"},
:user_id => evm_owner.id
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

FactoryBot.create(:service_ovf,
:options => {:provision_options => provision_options}.merge(config_info_options),
:service_template => service_template).tap do |svc|
end
:evm_owner => FactoryBot.create(:user),
:service_template => service_template)
end

let(:dialog_options) do
Expand Down Expand Up @@ -110,12 +110,21 @@

describe '#check_refreshed' do
it 'successful deployment response ' do
response = {:value => {:succeeded => true, :resource_id=>{:type=>"VirtualMachine", :id=>"vm-934"}}}
response = {:value => {:succeeded => true, :resource_id => {:type => "VirtualMachine", :id => "vm-934"}}}
loaded_service.update(:options => loaded_service.options.merge(:deploy_response => response))
expect(loaded_service.check_refreshed(action)).to eq([false, nil])

FactoryBot.create(:vm_vmware, :ems_ref_type => "VirtualMachine", :ems_ref => "vm-934", :ems_id => ems.id)
vm = FactoryBot.create(:vm_vmware, :ems_ref_type => "VirtualMachine", :ems_ref => "vm-934", :ems_id => ems.id)
event_hash = {
:type => "automate_user_info",
:subject => loaded_service,
:user_id => loaded_service.evm_owner.id,
:options => {:message => "[#{vm.class}] [#{vm.id}] has been tagged with /lifecycle/retire_full"}
}

expect(Notification).to receive(:create).with(event_hash)
expect(loaded_service.check_refreshed(action)).to eq([true, nil])
expect(Vm.find_tagged_with(:all => "lifecycle/retire_full", :ns => "/managed")).to eq([vm])
end

it 'no successful deployment response ' do
Expand Down

0 comments on commit 66ee8d0

Please sign in to comment.