-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
spec/models/manageiq/providers/vmware/infra_manager/inventory/collector_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
describe ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector do | ||
let(:ems) { FactoryGirl.create(:ems_vmware_with_authentication) } | ||
let(:collector) { described_class.new(ems) } | ||
|
||
context "#process_object_update" do | ||
let(:root_folder) { RbVmomi::VIM::Folder(nil, "group-d1") } | ||
let(:datacenter) { RbVmomi::VIM::Datacenter(nil, "datacenter-1") } | ||
let(:virtual_machine) { RbVmomi::VIM::VirtualMachine(nil, "vm-1") } | ||
|
||
context "enter" do | ||
it "Folder" do | ||
object_update = RbVmomi::VIM::ObjectUpdate( | ||
:obj => root_folder, | ||
:kind => "enter", | ||
:changeSet => [ | ||
RbVmomi::VIM::PropertyChange(:name => "childEntity", :op => "assign", :val => [datacenter]), | ||
RbVmomi::VIM::PropertyChange(:name => "name", :op => "assign", :val => "Datacenters"), | ||
RbVmomi::VIM::PropertyChange(:name => "parent", :op => "assign"), | ||
] | ||
) | ||
|
||
props = collector.process_object_update(object_update) | ||
|
||
expect(props).to have_attributes( | ||
"name" => "Datacenters", | ||
"parent" => nil, | ||
"childEntity" => [datacenter] | ||
) | ||
end | ||
|
||
it "VirtualMachine" do | ||
object_update = virtual_machine_enter_object_update | ||
|
||
props = collector.process_object_update(object_update) | ||
expect(props).to have_attributes( | ||
"summary.config.uuid" => "eaf4991e-ab31-4f86-9ec0-aeb5d5a27c33", | ||
"summary.config.name" => "vm1", | ||
"summary.config.vmPathName" => "[datastore1] vm1/vm1.vmx", | ||
"summary.config.template" => false, | ||
) | ||
end | ||
end | ||
|
||
context "modify" do | ||
context "Change the name of an existing vm" do | ||
before do | ||
object_update = virtual_machine_enter_object_update | ||
collector.process_object_update(object_update) | ||
end | ||
|
||
it "Returns the changed name" do | ||
object_update = RbVmomi::VIM::ObjectUpdate( | ||
:obj => virtual_machine, | ||
:kind => "modify", | ||
:changeSet => [ | ||
RbVmomi::VIM::PropertyChange(:name => "summary.config.name", :op => "assign", :val => "vm2"), | ||
] | ||
) | ||
|
||
props = collector.process_object_update(object_update) | ||
expect(props).to have_attributes( | ||
"summary.config.name" => "vm2" | ||
) | ||
end | ||
|
||
it "Merges the cached properties with the name change" do | ||
object_update = RbVmomi::VIM::ObjectUpdate( | ||
:obj => virtual_machine, | ||
:kind => "modify", | ||
:changeSet => [ | ||
RbVmomi::VIM::PropertyChange(:name => "summary.config.name", :op => "assign", :val => "vm2"), | ||
] | ||
) | ||
|
||
props = collector.process_object_update(object_update) | ||
expect(props).to have_attributes( | ||
"summary.config.uuid" => "eaf4991e-ab31-4f86-9ec0-aeb5d5a27c33", | ||
"summary.config.name" => "vm2", | ||
"summary.config.vmPathName" => "[datastore1] vm1/vm1.vmx", | ||
"summary.config.template" => false, | ||
) | ||
end | ||
end | ||
end | ||
|
||
def virtual_machine_enter_object_update | ||
RbVmomi::VIM::ObjectUpdate( | ||
:obj => virtual_machine, | ||
:kind => "enter", | ||
:changeSet => [ | ||
RbVmomi::VIM::PropertyChange(:name => "summary.config.uuid", | ||
:op => "assign", | ||
:val => "eaf4991e-ab31-4f86-9ec0-aeb5d5a27c33"), | ||
RbVmomi::VIM::PropertyChange(:name => "summary.config.name", | ||
:op => "assign", | ||
:val => "vm1"), | ||
RbVmomi::VIM::PropertyChange(:name => "summary.config.vmPathName", | ||
:op => "assign", | ||
:val => "[datastore1] vm1/vm1.vmx"), | ||
RbVmomi::VIM::PropertyChange(:name => "summary.runtime.powerState", | ||
:op => "assign", | ||
:val => "poweredOff"), | ||
RbVmomi::VIM::PropertyChange(:name => "summary.config.template", | ||
:op => "assign", | ||
:val => false), | ||
] | ||
) | ||
end | ||
end | ||
end |