From a5eaa8ebf572746625a38430a2080bbb192758a3 Mon Sep 17 00:00:00 2001 From: Mike Pountney Date: Sun, 8 Jun 2014 21:36:42 +0100 Subject: [PATCH] Mock for get_network_connection_system_section_vapp --- ..._network_connection_system_section_vapp.rb | 43 +++++++++++++++++++ .../requests/compute/get_vapp.rb | 18 -------- .../requests/compute/vm_tests.rb | 5 ++- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/lib/fog/vcloud_director/requests/compute/get_network_connection_system_section_vapp.rb b/lib/fog/vcloud_director/requests/compute/get_network_connection_system_section_vapp.rb index 7bd52b4f7..a3360004d 100644 --- a/lib/fog/vcloud_director/requests/compute/get_network_connection_system_section_vapp.rb +++ b/lib/fog/vcloud_director/requests/compute/get_network_connection_system_section_vapp.rb @@ -20,6 +20,49 @@ module Fog ) end end + + class Mock + + def get_network_connection_system_section_vapp(id) + type = 'application/vnd.vmware.vcloud.networkConnectionSection+xml' + + unless vm = data[:vms][id] + raise Fog::Compute::VcloudDirector::Forbidden.new( + 'This operation is denied.' + ) + end + + Excon::Response.new( + :status => 200, + :headers => {'Content-Type' => "#{type};version=#{api_version}"}, + :body => get_vm_network_connection_section_body(id, vm) + ) + + end + + def get_vm_network_connection_section_body(id, vm) + # TODO: Needs work - does not handle multiple NIC case yet, or + # DHCP/POOL allocations + { + :type => "application/vnd.vmware.vcloud.networkConnectionSection+xml", + :href => make_href("vApp/#{id}/networkConnectionSection/"), + :ovf_required => "false", + :"ovf:Info" => "Specifies the available VM network connections", + :PrimaryNetworkConnectionIndex => "0", + :NetworkConnection => { + :network => vm[:nics][0][:network_name], + :needsCustomization => "false", + :NetworkConnectionIndex => "0", + :IpAddress => vm[:nics][0][:ip_address], + :IsConnected => "true", + :MACAddress => vm[:nics][0][:mac_address], + :IpAddressAllocationMode => "MANUAL" + } + } + end + + end + end end end diff --git a/lib/fog/vcloud_director/requests/compute/get_vapp.rb b/lib/fog/vcloud_director/requests/compute/get_vapp.rb index 9f0b2e797..148d63d90 100644 --- a/lib/fog/vcloud_director/requests/compute/get_vapp.rb +++ b/lib/fog/vcloud_director/requests/compute/get_vapp.rb @@ -200,24 +200,6 @@ module Fog } end - def get_vm_network_connection_section_body(id, vm) - { - :type => "application/vnd.vmware.vcloud.networkConnectionSection+xml", - :href => make_href("vApp/#{id}/networkConnectionSection/"), - :ovf_required => "false", - :"ovf:Info" => "Specifies the available VM network connections", - :PrimaryNetworkConnectionIndex => "0", - :NetworkConnection => { - :network => vm[:nics][0][:network_name], - :needsCustomization => "false", - :NetworkConnectionIndex => "0", - :IpAddress => vm[:nics][0][:ip_address], - :IsConnected => "true", - :MACAddress => vm[:nics][0][:mac_address], - :IpAddressAllocationMode => "MANUAL" - } - } - end def get_vm_runtime_info_section_body(id, vm) { diff --git a/tests/vcloud_director/requests/compute/vm_tests.rb b/tests/vcloud_director/requests/compute/vm_tests.rb index df4a33e4f..ef3622639 100644 --- a/tests/vcloud_director/requests/compute/vm_tests.rb +++ b/tests/vcloud_director/requests/compute/vm_tests.rb @@ -48,8 +48,11 @@ Shindo.tests('Compute::VcloudDirector | vm requests', ['vclouddirector']) do @service.get_guest_customization_system_section_vapp(vm_id).body end + tests("#get_vapp(#{vm_id}).body[:NetworkConnectionSection]").returns(Hash) do + @service.get_vapp(vm_id).body[:NetworkConnectionSection].class + end + tests("#get_network_connection_system_section_vapp(#{vm_id})").returns(Hash) do - pending if Fog.mocking? @service.get_network_connection_system_section_vapp(vm_id).body.class end