Skip to content

Commit

Permalink
Merge pull request #241 from borod108/bugs/1571291snapshot_removal
Browse files Browse the repository at this point in the history
Fix refreshing targeted vm after snapshot removal
(cherry picked from commit 233273d)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1581287
  • Loading branch information
agrare authored and simaishi committed May 22, 2018
1 parent 221f774 commit 5643660
Show file tree
Hide file tree
Showing 3 changed files with 2,469 additions and 11 deletions.
Expand Up @@ -97,20 +97,16 @@ def hosts
end

def vms
v = []
return v if select_vms(references(:vms)).blank?

manager.with_provider_connection(VERSION_HASH) do |connection|
select_vms(references(:vms)).each do |ems_ref|
@vms = manager.with_provider_connection(VERSION_HASH) do |connection|
select_vms(references(:vms)).map do |ems_ref|
begin
v << connection.system_service.vms_service.vm_service(uuid_from_ems_ref(ems_ref)).get
connection.system_service.vms_service.vm_service(uuid_from_ems_ref(ems_ref)).get
rescue OvirtSDK4::Error # when 404
nil
end
end
end

v
end if @vms.blank?
@vms
end

def select_vms(references_lst)
Expand Down
Expand Up @@ -14,7 +14,7 @@
allow(Spec::Support::OvirtSDK::ConnectionVCR).to receive(:new).and_call_original
allow(Spec::Support::OvirtSDK::ConnectionVCR).to receive(:new).with(kind_of(Hash)) do |opts|
Spec::Support::OvirtSDK::ConnectionVCR.new(opts,
'spec/vcr_cassettes/manageiq/providers/redhat/infra_manager/refresh/ovirt_sdk_refresh_graph_target_vm.yml',
'spec/vcr_cassettes/manageiq/providers/redhat/infra_manager/refresh/ovirt_sdk_refresh_graph_target_vm_deleted_snapshot.yml',
false)
end
stub_const("OvirtSDK4::Connection", Spec::Support::OvirtSDK::ConnectionVCR)
Expand All @@ -40,7 +40,7 @@ def load_response_mock_for(filename)
stub_settings_merge(:ems_refresh => { :rhevm => {:inventory_object_refresh => true }})
EmsRefresh.refresh(@ems)
@ems.reload
vm = VmOrTemplate.where(:name => "my-cirros-vm").first
vm = VmOrTemplate.where(:name => "vm1").first
expect(vm.ems_id).to eq(@ems.id)
saved_vm = vm_to_comparable_hash(vm)
saved_counted_models = COUNTED_MODELS.map { |m| [m.name, m.count] }
Expand All @@ -51,6 +51,16 @@ def load_response_mock_for(filename)
expect(saved_counted_models).to eq(counted_models)
end

it 'refreshes successfuly after snapshot removal' do
stub_settings_merge(:ems_refresh => { :rhevm => {:inventory_object_refresh => true }})
EmsRefresh.refresh(@ems)
@ems.reload
vm = VmOrTemplate.where(:name => "vm1").first
expect(vm.reload.snapshots.count).to eq(2)
EmsRefresh.refresh(vm)
expect(vm.reload.snapshots.count).to eq(1)
end

def vm_to_comparable_hash(vm)
h = vm.attributes
h.delete("updated_on")
Expand Down

0 comments on commit 5643660

Please sign in to comment.