Skip to content

Commit

Permalink
Render snapshot for VM
Browse files Browse the repository at this point in the history
Refresh parser now renders snapshot for VM.
VCloud only returns creation time, size and
poweredOn, which tells if if the virtual machine was
powered on when the snapshot was created. So `uid` and
`ems_ref` are created from VM's id and creation time
of snapshot.
  • Loading branch information
sasoc committed Feb 27, 2018
1 parent d8c04f7 commit 8d7f84b
Show file tree
Hide file tree
Showing 3 changed files with 11,161 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def parse_vm(vm)
:name => name,
:vendor => "vmware",
:raw_power_state => status,
:snapshots => [parse_snapshot(vm)].compact,

:hardware => {
:guest_os => guest_os,
Expand Down Expand Up @@ -217,4 +218,21 @@ def parse_vapp_template(vapp_template)

return uid, new_result
end

def parse_snapshot(vm)
resp = @connection.get_snapshot_section(vm.id).data
if (snapshot_resp = resp.fetch_path(:body, :Snapshot))
{
:name => "#{vm.name} (snapshot)",
:uid => "#{vm.id}_#{snapshot_resp[:created]}",
:ems_ref => "#{vm.id}_#{snapshot_resp[:created]}",
:parent_id => vm.id,
:parent_uid => vm.id,
:create_time => snapshot_resp[:created],
:total_size => snapshot_resp[:size]
}
else
return nil
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
end

it "will perform a full refresh" do
# Mock snapshot collection since VCR cassete does not contain those request yet.
# TODO: record a new VCR cassette when provider development is done.
allow_any_instance_of(ManageIQ::Providers::Vmware::CloudManager::RefreshParser).to receive(:parse_snapshot).and_return(nil)

2.times do # Run twice to verify that a second run with existing data does not change anything
@ems.reload
VCR.use_cassette(described_class.name.underscore, :allow_unused_http_interactions => true) do
Expand All @@ -58,6 +62,18 @@
end
end

it "will perform refresh for snapshot" do
2.times do # Run twice to verify that a second run with existing data does not change anything
@ems.reload
VCR.use_cassette(described_class.name.underscore + '_snapshots') do
EmsRefresh.refresh(@ems)
end
@ems.reload

assert_specific_vm_with_snapshot
end
end

def assert_table_counts
expect(ExtManagementSystem.count).to eq(2) # cloud_manager + network_manager
expect(Flavor.count).to eq(0)
Expand Down Expand Up @@ -348,4 +364,18 @@ def assert_specific_orchestration_template
expect(@template.content.include?('ovf:Envelope')).to be_truthy
expect(@template.md5).to eq('729bfcafe52065bdee376931efe104d9')
end

def assert_specific_vm_with_snapshot
vm = ManageIQ::Providers::Vmware::CloudManager::Vm.find_by(:name => "saso-vm")

expect(vm.snapshots.first).not_to be_nil
expect(vm.snapshots.first).to have_attributes(
:ems_ref => 'vm-f910f019-38a4-4d6a-a6cb-be403cc35ff3_2018-02-23T12:37:58.151+01:00',
:uid => 'vm-f910f019-38a4-4d6a-a6cb-be403cc35ff3_2018-02-23T12:37:58.151+01:00',
:parent_uid => 'vm-f910f019-38a4-4d6a-a6cb-be403cc35ff3',
:name => 'saso-vm (snapshot)',
:total_size => 21_474_836_480
)
expect(vm.snapshots.first.create_time.to_s).to eq('2018-02-23 11:37:58 UTC')
end
end
Loading

0 comments on commit 8d7f84b

Please sign in to comment.