Skip to content

Commit

Permalink
Merge pull request #230 from borod108/bugs/snapshot_active
Browse files Browse the repository at this point in the history
Properly fetch snapshot current state
(cherry picked from commit 6f2a100)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1588038
  • Loading branch information
masayag authored and simaishi committed Jun 6, 2018
1 parent dabd06e commit eace037
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Expand Up @@ -260,8 +260,9 @@ def vm_inv_to_snapshot_hashes(inv)
return result if inv.nil?

parent_id = nil
inv.each_with_index do |snapshot, idx|
result << snapshot_inv_to_snapshot_hashes(snapshot, idx == inv.length - 1, parent_id)
inv.each do |snapshot|
current = snapshot.snapshot_type == "active"
result << snapshot_inv_to_snapshot_hashes(snapshot, current, parent_id)
parent_id = snapshot.id
end
result
Expand All @@ -274,7 +275,7 @@ def snapshot_inv_to_snapshot_hashes(inv, current, parent_uid = nil)
name = description = inv.description
name = "Active Image" if name[0, 13] == '_ActiveImage_'

result = {
{
:uid_ems => inv.id,
:uid => inv.id,
:parent_uid => parent_uid,
Expand All @@ -283,8 +284,6 @@ def snapshot_inv_to_snapshot_hashes(inv, current, parent_uid = nil)
:create_time => create_time,
:current => current,
}

result
end

def vm_inv_to_custom_attribute_hashes(inv)
Expand Down
Expand Up @@ -502,7 +502,7 @@ def snapshots(persister_vm, vm)
snapshots = snapshots.sort_by(&:date).reverse

parent_id = nil
snapshots.each_with_index do |snapshot, idx|
snapshots.each do |snapshot|
name = description = snapshot.description
name = "Active Image" if name[0, 13] == '_ActiveImage_'

Expand All @@ -513,8 +513,8 @@ def snapshots(persister_vm, vm)
:name => name,
:description => description,
:create_time => snapshot.date.getutc,
:current => idx == snapshots.length - 1,
:vm_or_template => persister_vm
:current => snapshot.snapshot_type == "active",
:vm_or_template => persister_vm,
)
parent_id = snapshot.id
end
Expand Down
Expand Up @@ -483,19 +483,20 @@ def assert_specific_vm_powered_on
expect(v.snapshots.size).to eq(3)

# TODO: Fix this boolean column
snapshot = v.snapshots.detect { |s| s.current == 1 } # TODO: Fix this boolean column
snapshot = v.snapshots.detect { |s| s.name = "Active VM" } # TODO: Fix this boolean column
expect(snapshot).to have_attributes(
:uid => "6e3e547f-9544-42cf-842d-9104828d8511",
:parent_uid => "05ff445a-0bfc-44c3-90d1-a338e9095510",
:uid_ems => "6e3e547f-9544-42cf-842d-9104828d8511",
:name => "Active VM",
:description => "Active VM",
:current => 1,
:current => 0,
:total_size => nil,
:filename => nil
)
snapshot_parent = ::Snapshot.find_by(:name => "vm1_snap")
expect(snapshot.parent).to eq(snapshot_parent)
expect(snapshot_parent.current).to eq(1)

expect(v.hardware).to have_attributes(
:guest_os => "other",
Expand Down
Expand Up @@ -447,20 +447,20 @@ def assert_specific_vm_powered_on

expect(v.snapshots.size).to eq(3)

# TODO: Fix this boolean column
snapshot = v.snapshots.detect { |s| s.current == 1 } # TODO: Fix this boolean column
snapshot = v.snapshots.detect { |s| s.name == "Active VM" } # TODO: Fix this boolean column
expect(snapshot).to have_attributes(
:uid => "6e3e547f-9544-42cf-842d-9104828d8511",
:parent_uid => "05ff445a-0bfc-44c3-90d1-a338e9095510",
:uid_ems => "6e3e547f-9544-42cf-842d-9104828d8511",
:name => "Active VM",
:description => "Active VM",
:current => 1,
:current => 0,
:total_size => nil,
:filename => nil
)
snapshot_parent = ::Snapshot.find_by(:name => "vm1_snap")
expect(snapshot.parent).to eq(snapshot_parent)
expect(snapshot_parent.current).to eq(1)

expect(v.hardware).to have_attributes(
:guest_os => "other",
Expand Down
Expand Up @@ -5223,7 +5223,7 @@ https://localhost:8443/ovirt-engine/api/vms/3a9401a0-bf3d-4496-8acf-edd3e903511f
<date>2016-07-05T13:14:08.116+03:00</date>
<persist_memorystate>false</persist_memorystate>
<snapshot_status>ok</snapshot_status>
<snapshot_type>active</snapshot_type>
<snapshot_type>regular</snapshot_type>
</snapshot>
<snapshot href="/ovirt-engine/api/vms/3a9401a0-bf3d-4496-8acf-edd3e903511f/snapshots/05ff445a-0bfc-44c3-90d1-a338e9095510" id="05ff445a-0bfc-44c3-90d1-a338e9095510">
<actions>
Expand All @@ -5236,7 +5236,7 @@ https://localhost:8443/ovirt-engine/api/vms/3a9401a0-bf3d-4496-8acf-edd3e903511f
<date>2016-12-15T09:51:43.247+02:00</date>
<persist_memorystate>true</persist_memorystate>
<snapshot_status>ok</snapshot_status>
<snapshot_type>regular</snapshot_type>
<snapshot_type>active</snapshot_type>
<vm id="3a9401a0-bf3d-4496-8acf-edd3e903511f">
<name>vm1</name>
<bios>
Expand Down

0 comments on commit eace037

Please sign in to comment.