From afc4d9e59b8e673f4660f1a97385b1afade538e4 Mon Sep 17 00:00:00 2001 From: Daniel Aragao Date: Fri, 11 Jul 2014 11:40:45 +1000 Subject: [PATCH] Adding tests for vm and vms parsers. These represent the XML crunching from GET requests in compute. --- tests/vcloud_director/fixtures/vapp.xml | 532 ++++++++++++++++++++++ tests/vcloud_director/fixtures/vm.xml | 213 +++++++++ tests/vcloud_director/parsers/vm_tests.rb | 109 +++++ 3 files changed, 854 insertions(+) create mode 100644 tests/vcloud_director/fixtures/vapp.xml create mode 100644 tests/vcloud_director/fixtures/vm.xml create mode 100644 tests/vcloud_director/parsers/vm_tests.rb diff --git a/tests/vcloud_director/fixtures/vapp.xml b/tests/vcloud_director/fixtures/vapp.xml new file mode 100644 index 000000000..0c1bb54d4 --- /dev/null +++ b/tests/vcloud_director/fixtures/vapp.xml @@ -0,0 +1,532 @@ + + + + + + + + + + + + + + + + + + + + + + + Lease settings section + + 0 + 0 + + + VApp startup section + + + + + + The list of logical networks + + + + + + + + + The configuration parameters for logical networks + + + + + + + + true + 192.168.96.1 + 255.255.255.0 + 192.168.33.71 + 192.168.33.72 + test.com + true + + + 192.168.96.2 + 192.168.96.128 + + + + + + bridged + false + + true + + + + + + + + true + 10.81.196.1 + 255.255.255.0 + true + + + 10.81.196.201 + 10.81.196.240 + + + + + + bridged + false + + true + + + + Snapshot information section + + 2014-07-08T23:33:21.817-04:00 + + + + false + + + + + + + + + + + + + + + + + + + + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + summoning-dark + vmx-08 + + + 00:50:56:29:0c:a0 + 1 + true + nfs-net-01 + E1000 ethernet adapter on "nfs-net-01" + Network adapter 1 + 1 + E1000 + 10 + + + 00:50:56:29:0c:9f + 0 + true + Non-DMZNetwork + E1000 ethernet adapter on "Non-DMZNetwork" + Network adapter 0 + 2 + E1000 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 3 + lsilogicsas + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 3 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 4 + 5 + + + 1 + false + CD/DVD Drive + CD/DVD Drive 1 + + 3002 + 4 + 15 + + + hertz * 10^6 + Number of Virtual CPUs + 2 virtual CPU(s) + 5 + 0 + 3 + 2 + 0 + + + + byte * 2^20 + Memory Size + 2048 MB of memory + 6 + 0 + 4 + 2048 + 0 + + + + + + + + + + + + + + + + + Specifies the operating system installed + Microsoft Windows Server 2008 R2 (64-bit) + + + + Specifies the available VM network connections + 0 + + 1 + 10.81.196.205 + true + 00:50:56:29:0c:a0 + POOL + + + 0 + 192.168.96.4 + true + 00:50:56:29:0c:9f + POOL + + + + + Specifies Guest OS Customization Settings + true + false + f09c53c0-d0b3-4a31-9c8d-19de2c676e1e + false + false + false + true + false + summoning-dark + + + + Specifies Runtime info + + + + Snapshot information section + + 2014-07-08T23:33:24.510-04:00 + a395377e-8f69-4ba4-8b09-f5ea93f7367e + + + VMware ESXi + 5.1.0 + VMware, Inc. + en + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + sam-vimes + vmx-09 + + + 00:50:56:29:0c:a1 + 0 + true + Non-DMZNetwork + Vmxnet3 ethernet adapter on "Non-DMZNetwork" + Network adapter 0 + 1 + VMXNET3 + 10 + + + 00:50:56:29:0c:a2 + 1 + true + nfs-net-01 + Vmxnet3 ethernet adapter on "nfs-net-01" + Network adapter 1 + 2 + VMXNET3 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 3 + lsilogic + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 3 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 4 + 5 + + + 1 + true + CD/DVD Drive + CD/DVD Drive 1 + + 3002 + 4 + 15 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 5 + 0 + 3 + 1 + 0 + + + + byte * 2^20 + Memory Size + 2048 MB of memory + 6 + 0 + 4 + 2048 + 0 + + + + + + + + + + + + + + + + + Specifies the operating system installed + Oracle Linux 4/5/6 (64-bit) + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.96.5 + true + 00:50:56:29:0c:a1 + POOL + + + 1 + 10.81.196.206 + true + 00:50:56:29:0c:a2 + POOL + + + + + Specifies Guest OS Customization Settings + true + false + 315485fb-e4a2-4dae-8890-2c21439da1fb + false + false + false + true + false + if [ x$1 == x"postcustomization" ]; then fi + sam-vimes.test.com + + + + Specifies Runtime info + + + + Snapshot information section + + 2014-07-08T23:33:24.537-04:00 + 3186dd46-8976-49d3-b9f9-9bbd432d187e + + + VMware ESXi + 5.1.0 + VMware, Inc. + en + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + false + + + + + \ No newline at end of file diff --git a/tests/vcloud_director/fixtures/vm.xml b/tests/vcloud_director/fixtures/vm.xml new file mode 100644 index 000000000..548ee3ec1 --- /dev/null +++ b/tests/vcloud_director/fixtures/vm.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + nas.test.com + vmx-09 + + + 00:50:56:29:0c:18 + 0 + true + Non-DMZNetwork + Vmxnet3 ethernet adapter on "Non-DMZNetwork" + Network adapter 0 + 1 + VMXNET3 + 10 + + + 00:50:56:29:0c:19 + 1 + true + nfs-net-01 + Vmxnet3 ethernet adapter on "nfs-net-01" + Network adapter 1 + 2 + VMXNET3 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 3 + lsilogic + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 3 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 4 + 5 + + + 1 + true + CD/DVD Drive + CD/DVD Drive 1 + + 3002 + 4 + 15 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 5 + 0 + 3 + 1 + 0 + + + + byte * 2^20 + Memory Size + 2048 MB of memory + 6 + 0 + 4 + 2048 + 0 + + + + + + + + + + + + + + + + + Specifies the operating system installed + Oracle Linux 4/5/6 (64-bit) + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.96.10 + true + 00:50:56:29:0c:18 + POOL + + + 1 + 10.81.196.204 + true + 00:50:56:29:0c:19 + POOL + + + + + Specifies Guest OS Customization Settings + true + false + 17a2a3a9-248c-475d-8ee0-8dd45f7f8368 + false + false + false + true + false + if [ x$1 == x"postcustomization" ]; then fi + nas.test.com + + + + Specifies Runtime info + + + + Snapshot information section + + 2014-07-08T00:35:59.703-04:00 + b6b1835b-cb2a-49c2-832f-93212a757858 + + + VMware ESXi + 5.1.0 + VMware, Inc. + en + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + false + + + diff --git a/tests/vcloud_director/parsers/vm_tests.rb b/tests/vcloud_director/parsers/vm_tests.rb new file mode 100644 index 000000000..167b431cd --- /dev/null +++ b/tests/vcloud_director/parsers/vm_tests.rb @@ -0,0 +1,109 @@ +require 'fog/xml' +require 'fog/vcloud_director/parsers/compute/vm' + +Shindo.tests('Parsers::Compute::VcloudDirector::Vm', ['vclouddirector', 'all']) do + parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::Compute::VcloudDirector::Vm.new) + vm_response_xml = File.open(File.join(__dir__, '..', 'fixtures','vm.xml')).read + parser.parse(vm_response_xml) + vm = parser.document.response[:vm] + + tests('correctly parses vm xml reponse from a GET') do + tests('#id').returns('vm-17a2a3a9-248c-475d-8ee0-8dd45f7f8368'){ vm[:id] } + tests('#ip_address').returns('10.81.196.204'){ vm[:ip_address] } + tests('#deployed').returns(true){ vm[:deployed] } + tests('#status').returns('on'){ vm[:status] } + tests('#name').returns('nas.test.com'){ vm[:name] } + tests('#type').returns('application/vnd.vmware.vcloud.vm+xml'){ vm[:type] } + tests('#cpu').returns('1'){ vm[:cpu] } + tests('#memory').returns('2048'){ vm[:memory] } + tests('#operating_system').returns('Oracle Linux 4/5/6 (64-bit)'){ vm[:operating_system] } + tests('#links').returns(false){ vm[:links].empty? } + + tests('#network_adapters').returns(2){ vm[:network_adapters].size } + + primary_nic = vm[:network_adapters].select { |nic| nic[:primary] }.first + tests('#network_adapters:ip_address').returns('192.168.96.10'){ primary_nic[:ip_address] } + tests('#network_adapters:primary').returns(true){ primary_nic[:primary] } + tests('#network_adapters:ip_allocation_mode').returns('POOL'){ primary_nic[:ip_allocation_mode] } + tests('#network_adapters:network').returns('Non-DMZNetwork'){ primary_nic[:network] } + + secondary_nic = vm[:network_adapters].select { |nic| nic[:primary] == false }.first + tests('#network_adapters:ip_address').returns('10.81.196.204'){ secondary_nic[:ip_address] } + tests('#network_adapters:primary').returns(false){ secondary_nic[:primary] } + tests('#network_adapters:ip_allocation_mode').returns('POOL'){ secondary_nic[:ip_allocation_mode] } + tests('#network_adapters:network').returns('nfs-net-01'){ secondary_nic[:network] } + + tests('#disks').returns(false){ vm[:disks].empty? } + tests('#disks:0').returns({'Hard disk 1'=>10240}){ vm[:disks][0] } + end + +end + +Shindo.tests('Parsers::Compute::VcloudDirector::Vms', ['vclouddirector', 'all']) do + parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::Compute::VcloudDirector::Vms.new) + vapp_response_xml = File.open(File.join(__dir__, '..', 'fixtures','vapp.xml')).read + parser.parse(vapp_response_xml) + vms = parser.document.response[:vms] + + tests('correctly parses first vm from vapp xml reponse') do + tests('vms[0]#id').returns('vm-f09c53c0-d0b3-4a31-9c8d-19de2c676e1e'){ vms[0][:id] } + tests('vms[0]#ip_address').returns('192.168.96.4'){ vms[0][:ip_address] } + tests('vms[0]#deployed').returns(false){ vms[0][:deployed] } + tests('vms[0]#status').returns('on'){ vms[0][:status] } + tests('vms[0]#name').returns('summoning-dark'){ vms[0][:name] } + tests('vms[0]#type').returns('application/vnd.vmware.vcloud.vm+xml'){ vms[0][:type] } + tests('vms[0]#cpu').returns('2'){ vms[0][:cpu] } + tests('vms[0]#memory').returns('2048'){ vms[0][:memory] } + tests('vms[0]#operating_system').returns('Microsoft Windows Server 2008 R2 (64-bit)'){ vms[0][:operating_system] } + tests('vms[0]#links').returns(false){ vms[0][:links].empty? } + tests('vms[0]#network_adapters').returns(false){ vms[0][:network_adapters].empty? } + + tests('#network_adapters').returns(2){ vms[0][:network_adapters].size } + + primary_nic = vms[0][:network_adapters].select { |nic| nic[:primary] }.first + tests('vms[0]#network_adapters:ip_address').returns('192.168.96.4'){ primary_nic[:ip_address] } + tests('vms[0]#network_adapters:primary').returns(true){ primary_nic[:primary] } + tests('vms[0]#network_adapters:ip_allocation_mode').returns('POOL'){ primary_nic[:ip_allocation_mode] } + tests('vms[0]#network_adapters:network').returns('Non-DMZNetwork'){ primary_nic[:network] } + + secondary_nic = vms[0][:network_adapters].select { |nic| nic[:primary] == false }.first + tests('vms[0]#network_adapters:ip_address').returns('10.81.196.205'){ secondary_nic[:ip_address] } + tests('vms[0]#network_adapters:primary').returns(false){ secondary_nic[:primary] } + tests('vms[0]#network_adapters:ip_allocation_mode').returns('POOL'){ secondary_nic[:ip_allocation_mode] } + tests('vms[0]#network_adapters:network').returns('nfs-net-01'){ secondary_nic[:network] } + + tests('vms[0]#disks').returns(false){ vms[0][:disks].empty? } + tests('vms[0]#disks:0').returns({'Hard disk 1'=>61440}){ vms[0][:disks][0] } + end + + tests('correctly parses second vm from vapp xml reponse') do + tests('vms[1]#id').returns('vm-315485fb-e4a2-4dae-8890-2c21439da1fb'){ vms[1][:id] } + tests('vms[1]#ip_address').returns('10.81.196.206'){ vms[1][:ip_address] } + tests('vms[1]#deployed').returns(false){ vms[1][:deployed] } + tests('vms[1]#status').returns('on'){ vms[1][:status] } + tests('vms[1]#name').returns('sam-vimes'){ vms[1][:name] } + tests('vms[1]#type').returns('application/vnd.vmware.vcloud.vm+xml'){ vms[1][:type] } + tests('vms[1]#cpu').returns('1'){ vms[1][:cpu] } + tests('vms[1]#memory').returns('2048'){ vms[1][:memory] } + tests('vms[1]#operating_system').returns('Oracle Linux 4/5/6 (64-bit)'){ vms[1][:operating_system] } + tests('vms[1]#links').returns(false){ vms[1][:links].empty? } + + tests('#network_adapters').returns(2){ vms[1][:network_adapters].size } + + primary_nic = vms[1][:network_adapters].select { |nic| nic[:primary] }.first + tests('vms[0]#network_adapters:ip_address').returns('192.168.96.5'){ primary_nic[:ip_address] } + tests('vms[0]#network_adapters:primary').returns(true){ primary_nic[:primary] } + tests('vms[0]#network_adapters:ip_allocation_mode').returns('POOL'){ primary_nic[:ip_allocation_mode] } + tests('vms[0]#network_adapters:network').returns('Non-DMZNetwork'){ primary_nic[:network] } + + secondary_nic = vms[1][:network_adapters].select { |nic| nic[:primary] == false }.first + tests('vms[0]#network_adapters:ip_address').returns('10.81.196.206'){ secondary_nic[:ip_address] } + tests('vms[0]#network_adapters:primary').returns(false){ secondary_nic[:primary] } + tests('vms[0]#network_adapters:ip_allocation_mode').returns('POOL'){ secondary_nic[:ip_allocation_mode] } + tests('vms[0]#network_adapters:network').returns('nfs-net-01'){ secondary_nic[:network] } + + tests('vms[1]#disks').returns(false){ vms[1][:disks].empty? } + tests('vms[1]#disks:0').returns({'Hard disk 1'=>10240}){ vms[1][:disks][0] } + end + +end