vcloud-walker 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +12 -0
  3. data/LICENSE +20 -0
  4. data/README.md +55 -0
  5. data/Rakefile +21 -0
  6. data/bin/vcloud-walk +41 -0
  7. data/docs/examples/catalogs.json +40 -0
  8. data/docs/examples/edgegateways.json +285 -0
  9. data/docs/examples/networks.json +53 -0
  10. data/docs/examples/vdcs.json +221 -0
  11. data/jenkins.sh +9 -0
  12. data/jenkins_integration_tests.sh +11 -0
  13. data/lib/vcloud/walker/fog_interface.rb +48 -0
  14. data/lib/vcloud/walker/resource/catalog.rb +29 -0
  15. data/lib/vcloud/walker/resource/catalog_item.rb +25 -0
  16. data/lib/vcloud/walker/resource/collection.rb +13 -0
  17. data/lib/vcloud/walker/resource/entity.rb +27 -0
  18. data/lib/vcloud/walker/resource/gateway_ipsec_vpn_service.rb +46 -0
  19. data/lib/vcloud/walker/resource/network.rb +38 -0
  20. data/lib/vcloud/walker/resource/organization.rb +45 -0
  21. data/lib/vcloud/walker/resource/vapp.rb +46 -0
  22. data/lib/vcloud/walker/resource/vdc.rb +35 -0
  23. data/lib/vcloud/walker/resource/vm.rb +85 -0
  24. data/lib/vcloud/walker/resource.rb +11 -0
  25. data/lib/vcloud/walker/vcloud_session.rb +13 -0
  26. data/lib/vcloud/walker/version.rb +5 -0
  27. data/lib/vcloud/walker.rb +23 -0
  28. data/scripts/configure_walker_ci_vse.rb +31 -0
  29. data/scripts/data/walker_ci/carrenza.yaml +17 -0
  30. data/scripts/data/walker_ci/skyscape.yaml +17 -0
  31. data/scripts/generate_fog_conf_file.sh +6 -0
  32. data/spec/fog_interface_spec.rb +93 -0
  33. data/spec/integration/vcloud_walker_spec.rb +74 -0
  34. data/spec/spec_helper.rb +45 -0
  35. data/spec/stubs/service_layer_stub.rb +109 -0
  36. data/spec/stubs/stubs.rb +46 -0
  37. data/spec/vcloud/walker_spec.rb +59 -0
  38. data/spec/walk/catalogs_spec.rb +31 -0
  39. data/spec/walk/entity_spec.rb +69 -0
  40. data/spec/walk/gateway_ipsec_vpn_service_spec.rb +157 -0
  41. data/spec/walk/network_spec.rb +70 -0
  42. data/spec/walk/organization_spec.rb +53 -0
  43. data/spec/walk/vapp_spec.rb +24 -0
  44. data/spec/walk/vdcs_spec.rb +30 -0
  45. data/spec/walk/vm_spec.rb +122 -0
  46. data/vcloud-walker.gemspec +31 -0
  47. metadata +274 -0
@@ -0,0 +1,85 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class Vms < Collection
5
+ def initialize fog_vms
6
+ fog_vms = [fog_vms] unless fog_vms.is_a? Array
7
+ fog_vms.each do |vm|
8
+ self << Resource::Vm.new(vm)
9
+ end
10
+ end
11
+ end
12
+
13
+
14
+ class Vm < Entity
15
+
16
+ attr_reader :id, :status, :cpu, :memory, :operating_system, :disks,
17
+ :primary_network_connection_index, :vmware_tools,
18
+ :virtual_system_type, :network_connections, :storage_profile,
19
+ :network_cards, :metadata
20
+
21
+ HARDWARE_RESOURCE_TYPES = {
22
+ :cpu => '3',
23
+ :memory => '4',
24
+ :hard_disk => '17',
25
+ :network_adapter => '10'
26
+ }
27
+
28
+ def initialize fog_vm
29
+ @id = extract_id(fog_vm[:href])
30
+ @status = fog_vm[:status]
31
+ @operating_system = fog_vm[:'ovf:OperatingSystemSection'][:'ovf:Description']
32
+ @network_connections = fog_vm[:NetworkConnectionSection][:NetworkConnection] if fog_vm[:NetworkConnectionSection]
33
+ @primary_network_connection_index = fog_vm[:NetworkConnectionSection][:PrimaryNetworkConnectionIndex]
34
+ extract_compute_capacity fog_vm[:'ovf:VirtualHardwareSection'][:'ovf:Item']
35
+ @vmware_tools = fog_vm[:RuntimeInfoSection][:VMWareTools]
36
+ @virtual_system_type = extract_virtual_system_type(fog_vm[:'ovf:VirtualHardwareSection'])
37
+ @storage_profile = {
38
+ :id => fog_vm[:StorageProfile][:href].split('/').last,
39
+ :name => fog_vm[:StorageProfile][:name],
40
+ }
41
+ @metadata = Vcloud::Core::Vm.get_metadata(id)
42
+ end
43
+
44
+
45
+ private
46
+ def extract_compute_capacity ovf_resources
47
+ %w(cpu memory disks network_cards).each { |resource| send("extract_#{resource}", ovf_resources) } unless ovf_resources.empty?
48
+ end
49
+
50
+ def extract_cpu(resources)
51
+ @cpu = resources.detect { |element| element[:'rasd:ResourceType']== HARDWARE_RESOURCE_TYPES[:cpu] }[:'rasd:ElementName']
52
+ end
53
+
54
+ def extract_memory(resources)
55
+ @memory = resources.detect { |element| element[:'rasd:ResourceType']== HARDWARE_RESOURCE_TYPES[:memory] }[:'rasd:ElementName']
56
+ end
57
+
58
+ def extract_disks(resources)
59
+ disk_resources = resources.select { |element| element[:'rasd:ResourceType']== HARDWARE_RESOURCE_TYPES[:hard_disk] }
60
+ @disks = disk_resources.collect do |d|
61
+ {:name => d[:'rasd:ElementName'], :size => d[:'rasd:HostResource'][:'ns12_capacity'].to_i}
62
+ end
63
+ end
64
+
65
+ def extract_network_cards(resources)
66
+ resources = resources.select {
67
+ |element| element[:'rasd:ResourceType'] == HARDWARE_RESOURCE_TYPES[:network_adapter]
68
+ }
69
+ @network_cards = resources.collect do |r|
70
+ {:name => r[:'rasd:ElementName'],
71
+ :type => r[:'rasd:ResourceSubType'],
72
+ :mac_address => r[:'rasd:Address'],
73
+ }
74
+ end
75
+ end
76
+
77
+ def extract_virtual_system_type virtual_hardware_section
78
+ virtual_system = virtual_hardware_section[:"ovf:System"]
79
+ virtual_system[:"vssd:VirtualSystemType"] if virtual_system
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,11 @@
1
+ require 'vcloud/walker/resource/entity'
2
+ require 'vcloud/walker/resource/organization'
3
+ require 'vcloud/walker/resource/collection'
4
+ require 'vcloud/walker/resource/catalog_item'
5
+ require 'vcloud/walker/resource/catalog'
6
+ require 'vcloud/walker/resource/network'
7
+ require 'vcloud/walker/resource/vapp'
8
+ require 'vcloud/walker/resource/vdc'
9
+ require 'vcloud/walker/resource/vm'
10
+ require 'vcloud/walker/resource/gateway_ipsec_vpn_service'
11
+
@@ -0,0 +1,13 @@
1
+ module Vcloud
2
+ module Walker
3
+ class VcloudSession
4
+
5
+ def self.instance
6
+ ::Fog::Compute::VcloudDirector.new
7
+ end
8
+
9
+ end
10
+
11
+ end
12
+ end
13
+
@@ -0,0 +1,5 @@
1
+ module Vcloud
2
+ module Walker
3
+ VERSION = '3.1.1'
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require 'fog'
2
+
3
+ require 'vcloud/core'
4
+ require 'vcloud/walker/vcloud_session'
5
+ require 'vcloud/walker/fog_interface'
6
+ require 'vcloud/walker/resource'
7
+ require 'vcloud/walker/version'
8
+
9
+ module Vcloud
10
+ module Walker
11
+
12
+ def self.walk(resource_to_walk)
13
+ valid_options = ['catalogs', 'vdcs', 'networks',
14
+ 'edgegateways', 'organization']
15
+ if valid_options.include? resource_to_walk
16
+ Vcloud::Walker::Resource::Organization.send(resource_to_walk)
17
+ else
18
+ puts "Possible options are '#{valid_options.join("','")}'."
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ require 'fog'
2
+
3
+ edge_gateway_id = ARGV[0]
4
+ raise "please provide edgegateway id. usage: bx ruby ./configure_walker_ci_vse.rb <edgegateway-id>" unless edge_gateway_id
5
+
6
+ lb_config = {
7
+ :IsEnabled => "true",
8
+ :Pool => [],
9
+ :VirtualServer => []
10
+ }
11
+
12
+ configuration = {
13
+ :FirewallService =>
14
+ {
15
+ :IsEnabled => true,
16
+ :DefaultAction => 'allow',
17
+ :LogDefaultAction => false,
18
+ :FirewallRule => []
19
+ },
20
+ :LoadBalancerService => lb_config,
21
+ :NatService => {
22
+ :IsEnabled => true,
23
+ :nat_type => 'portForwarding',
24
+ :Policy => 'allowTraffic',
25
+ :NatRule => []
26
+ }
27
+ }
28
+
29
+ vcloud = Fog::Compute::VcloudDirector.new
30
+ task = vcloud.post_configure_edge_gateway_services edge_gateway_id, configuration
31
+ vcloud.process_task(task.body)
@@ -0,0 +1,17 @@
1
+ ---
2
+ vapps:
3
+ - name: vcloud-walker-contract-testing-vapp
4
+ vdc_name: 0e7t-vcloud_tools_ci-OVDC-001
5
+ catalog: walker-ci
6
+ catalog_item: walker-ci-template
7
+ vm:
8
+ hardware_config:
9
+ memory: '1024'
10
+ cpu: '1'
11
+ extra_disks:
12
+ - size: '8192'
13
+ network_connections:
14
+ - name: walker-ci-network
15
+ ip_address: 192.168.254.100
16
+ metadata:
17
+ is_webserver: true
@@ -0,0 +1,17 @@
1
+ ---
2
+ vapps:
3
+ - name: vcloud-walker-contract-testing-vapp
4
+ vdc_name: 'vCloud CI (IL2-DEVTEST-BASIC)'
5
+ catalog: walker-ci
6
+ catalog_item: ubuntu-precise-201310041515
7
+ vm:
8
+ hardware_config:
9
+ memory: '1024'
10
+ cpu: '1'
11
+ extra_disks:
12
+ - size: '8192'
13
+ network_connections:
14
+ - name: Default
15
+ ip_address: 192.168.254.100
16
+ metadata:
17
+ is_webserver: true
@@ -0,0 +1,6 @@
1
+ cat <<EOF >fog_integration_test.config
2
+ default:
3
+ vcloud_director_username: '$API_USERNAME'
4
+ vcloud_director_password: '$API_PASSWORD'
5
+ vcloud_director_host: '$API_HOST'
6
+ EOF
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+ require 'rspec/mocks'
3
+
4
+ describe Vcloud::Walker::FogInterface do
5
+ context "GET entities" do
6
+ let(:org) { double(:fog_org, :id => 'org-123') }
7
+ let(:organizations) { double(:orgs) }
8
+ let(:session) { double(:fog_session, :org_name => 'org-123', :organizations => organizations) }
9
+
10
+ before(:each) do
11
+ Vcloud::Walker::VcloudSession.should_receive(:instance).with(any_args()).at_least(:once).and_return(session)
12
+ organizations.should_receive(:get_by_name).and_return(org)
13
+ end
14
+
15
+ it "should get catalogs for given org id" do
16
+ mock_catalogs = [double(:catalog1), double(:catalog2)]
17
+ org.should_receive(:catalogs).and_return(double(:catalogs, :all => mock_catalogs))
18
+
19
+ catalogs = Vcloud::Walker::FogInterface.get_catalogs
20
+
21
+ catalogs.count.should == 2
22
+ catalogs.should == mock_catalogs
23
+
24
+ end
25
+
26
+ it "should get networks for given org id" do
27
+ mock_networks = [double(:network1), double(:network2)]
28
+ org.should_receive(:networks).and_return(double(:networks, :all => mock_networks))
29
+
30
+ networks = Vcloud::Walker::FogInterface.get_networks
31
+ networks.count.should == 2
32
+ networks.should == mock_networks
33
+ end
34
+
35
+ it "should get vdcs for given org id" do
36
+ mock_vdcs = [double(:vdc1), double(:vdc2), double(:vdc3)]
37
+ org.should_receive(:vdcs).and_return(double(:vdcs, :all => mock_vdcs))
38
+
39
+ vdcs = Vcloud::Walker::FogInterface.get_vdcs
40
+ vdcs.count.should == 3
41
+ vdcs.should == mock_vdcs
42
+ end
43
+
44
+ it "should get edge gateways for given org" do
45
+ mock_vdc1 = double(:vdc, :id => 1)
46
+ get_edge_gateway_result = double('Excon::Response', :body => {:EdgeGatewayRecord => {:href => '/sausage'}})
47
+
48
+ org.should_receive(:vdcs).and_return(double(:vdcs, :all => [ mock_vdc1 ]))
49
+ session.should_receive(:get_org_vdc_gateways).with(1).and_return(get_edge_gateway_result)
50
+ session.should_receive(:get_edge_gateway).with('sausage').and_return(double(:eg, :body => :eg1))
51
+
52
+ edge_gateways = Vcloud::Walker::FogInterface.get_edge_gateways
53
+
54
+ edge_gateways.count.should == 1
55
+ edge_gateways.should == [:eg1]
56
+ end
57
+
58
+ it "should get edge gateways for given org with complex set up of 2 vdcs and 3 edge gateways" do
59
+ mock_vdc1 = double(:vdc, :id => 1)
60
+ get_edge_gateway_vdc_1_result = double('Excon::Response', :body => {:EdgeGatewayRecord => {:href => '/sausage'}})
61
+ mock_vdc2 = double(:vdc, :id => 2)
62
+ get_edge_gateway_vdc_2_result = double('Excon::Response', :body => {:EdgeGatewayRecord => [{:href => '/beans'}, {:href => '/hashbrown'}]})
63
+
64
+ org.should_receive(:vdcs).and_return(double(:vdcs, :all => [ mock_vdc1, mock_vdc2 ]))
65
+
66
+ session.should_receive(:get_org_vdc_gateways).with(1).and_return(get_edge_gateway_vdc_1_result)
67
+ session.should_receive(:get_org_vdc_gateways).with(2).and_return(get_edge_gateway_vdc_2_result)
68
+ session.should_receive(:get_edge_gateway).with('sausage').and_return(double(:eg, :body => :eg1))
69
+ session.should_receive(:get_edge_gateway).with('beans').and_return(double(:eg, :body => :eg2))
70
+ session.should_receive(:get_edge_gateway).with('hashbrown').and_return(double(:eg, :body => :eg3))
71
+
72
+ edge_gateways = Vcloud::Walker::FogInterface.get_edge_gateways
73
+
74
+ edge_gateways.count.should == 3
75
+ edge_gateways.should == [:eg1, :eg2, :eg3]
76
+ end
77
+
78
+ it "get_edge_gateways should be happy if there are no edge gateways" do
79
+ mock_vdc1 = double(:vdc, :id => 1)
80
+
81
+ # no edge gateways means no entries to find in the results, just some other noise
82
+ vdc_1_search_result = double('Excon::Response', :body => {:Link => {:href => 's'}})
83
+
84
+ org.should_receive(:vdcs).and_return(double(:vdcs, :all => [ mock_vdc1 ]))
85
+ session.should_receive(:get_org_vdc_gateways).with(1).and_return(vdc_1_search_result)
86
+
87
+ edge_gateways = Vcloud::Walker::FogInterface.get_edge_gateways
88
+
89
+ edge_gateways.count.should == 0
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'fog'
3
+ require 'stringio'
4
+ require 'vcloud/walker'
5
+
6
+ #######################################################################################
7
+ # The intention of these tests are to ensure we have confdence that our tooling will
8
+ # function when used, and as integration tests to cover the areas that get mocked
9
+ # and so to uncover assumptions on how we use the fog libraries.
10
+ #
11
+ # They are not there to test fog - that is the job of the fog tests, though
12
+ # this can be reconsidered if we get a of undetected bugs.
13
+ #
14
+ # Most if not all edge cases should be caught by the unit tests or the Fog tests.
15
+ #
16
+ # NB: These tests require that all EdgeGateways in the organization have the
17
+ # following services configured with at least one rule:
18
+ # NatService
19
+ # LoadBalancerService
20
+ #
21
+ # NB: Integration test also requires that at least one vApp is configured in
22
+ # the organization, otherwise tests fail with insufficient coverage.
23
+ #
24
+
25
+
26
+ describe Vcloud::Walker do
27
+ context 'walk an organization' do
28
+
29
+ it 'should integrate with fog to get vdcs' do
30
+
31
+ vdc_summaries = Vcloud::Walker.walk('vdcs').to_json
32
+
33
+ # assert that there are atleast one item and that includes the essencial sections
34
+ vdc_summaries.should have_json_path('0/id')
35
+ vdc_summaries.should have_json_path('0/name')
36
+ vdc_summaries.should have_json_path('0/vapps')
37
+ vdc_summaries.should have_json_path('0/quotas')
38
+ vdc_summaries.should have_json_path('0/compute_capacity')
39
+ end
40
+
41
+ it "should integrate with fog to get networks" do
42
+
43
+ network_summary = Vcloud::Walker.walk('networks').to_json
44
+
45
+ # assert that there are atleast one item and that includes the essencial sections
46
+ network_summary.should have_json_path('0/id')
47
+ network_summary.should have_json_path('0/name')
48
+ network_summary.should have_json_path('0/ip_ranges')
49
+ network_summary.should have_json_path('0/gateway')
50
+ end
51
+
52
+ it "should integrate with fog to get catalogs" do
53
+
54
+ catalogs_summary = Vcloud::Walker.walk('catalogs')
55
+ catalog_summary = catalogs_summary.detect{|c| !c[:items].empty? }.to_json
56
+
57
+ # assert that there are atleast one item and that includes the essencial sections
58
+ catalog_summary.should have_json_path('id')
59
+ catalog_summary.should have_json_path('name')
60
+ catalog_summary.should have_json_path('items')
61
+ catalog_summary.should have_json_path('items/0/vapp_template_id')
62
+ end
63
+
64
+ it "should integrate with fog to get edge gateway data" do
65
+
66
+ result = Vcloud::Walker.walk('edgegateways').to_json
67
+ # assert that there are atleast one item and that includes the essencial sections
68
+ result.should have_json_path('0/Configuration/EdgeGatewayServiceConfiguration/FirewallService')
69
+ result.should have_json_path('0/Configuration/EdgeGatewayServiceConfiguration/NatService')
70
+ result.should have_json_path('0/Configuration/EdgeGatewayServiceConfiguration/LoadBalancerService')
71
+ result.should have_json_path('0/Configuration/GatewayInterfaces/GatewayInterface')
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,45 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+
4
+ SimpleCov.profiles.define 'gem' do
5
+ add_filter '/spec/'
6
+ add_filter '/features/'
7
+ add_filter '/vendor/'
8
+
9
+ add_group 'Libraries', '/lib/'
10
+ end
11
+
12
+ SimpleCov.start 'gem'
13
+ end
14
+
15
+ $:.unshift File.expand_path("../../lib", __FILE__)
16
+
17
+ require 'rspec'
18
+ require 'rspec/mocks'
19
+ require 'json_spec'
20
+ require 'vcloud/walker'
21
+ require_relative 'stubs/stubs'
22
+ require_relative 'stubs/service_layer_stub'
23
+
24
+
25
+ def set_login_credential username = 'some-username', password = 'some-password'
26
+ ENV['API_USERNAME'] = username
27
+ ENV['API_PASSWORD'] = password
28
+ end
29
+
30
+ RSpec.configure do |config|
31
+ config.include JsonSpec::Helpers
32
+ end
33
+
34
+ if ENV['COVERAGE']
35
+ ACCEPTED_COVERAGE = 97
36
+ SimpleCov.at_exit do
37
+ SimpleCov.result.format!
38
+ # do not change the coverage percentage, instead add more unit tests to fix coverage failures.
39
+ if SimpleCov.result.covered_percent < ACCEPTED_COVERAGE
40
+ print "ERROR::BAD_CODE_COVERAGE\n"
41
+ print "Coverage is less than acceptable limit(#{ACCEPTED_COVERAGE}%). Please add more tests to improve the coverage"
42
+ exit(1)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,109 @@
1
+ module Fog
2
+ module ServiceLayerStub
3
+ def self.vapp_body
4
+ {:name => "vapp-atomic-centre",
5
+ :id => "urn:vcloud:vm:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
6
+ :href => 'https://myvdc.carrenza.net/api/vApp/vapp-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
7
+ :status => "on",
8
+ :description => "hosts the atomic centre app",
9
+ :deployed => true,
10
+ :NetworkConfigSection => {:NetworkConfig => [{:networkName => "Default", :IsDeployed => true, :Description => "default network",
11
+ :Configuration => {:IpScopes => 'abc'}, :ParentNetwork => nil}]},
12
+ :"ovf:NetworkSection" => {:'ovf:Network' => 'network'},
13
+ :Children =>
14
+ {
15
+ :Vm =>
16
+ {
17
+ :needsCustomization => "true",
18
+ :deployed => "true",
19
+ :status => "4", :name => "ubuntu-precise-201309091031",
20
+ :id => "urn:vcloud:vm:d19d84a5-c950-4497-a638-23eccc4226a5",
21
+ :type => "application/vnd.vmware.vcloud.vm+xml",
22
+ :href => "https://api.vcd.portal.examplecloud.com/api/vApp/vm-d19d84a5-c950-4497-a638-23eccc4226a5",
23
+ :Description => "ubuntu-precise | Version: 1.0 | Built using BoxGrinder",
24
+ :"ovf:OperatingSystemSection" =>
25
+ {
26
+ :"ovf:Description" => "Ubuntu Linux (64-bit)"
27
+ },
28
+ :NetworkConnectionSection =>
29
+ {
30
+ :ovf_required => "false",
31
+ :"ovf:Info" => "Specifies the available VM network connections",
32
+ :PrimaryNetworkConnectionIndex => "0",
33
+ :NetworkConnection =>
34
+ {
35
+ :network => "Default",
36
+ :needsCustomization => "true",
37
+ :NetworkConnectionIndex => "0",
38
+ :IpAddress => "192.168.2.2",
39
+ :IsConnected => "true",
40
+ :MACAddress => "00:50:56:01:0b:1a",
41
+ :IpAddressAllocationMode => "MANUAL"
42
+ },
43
+ },
44
+ :'ovf:VirtualHardwareSection' =>
45
+ {
46
+ :'ovf:Item' => [],
47
+ :"ovf:System" =>
48
+ {:"vssd:ElementName" => "Virtual Hardware Family", :"vssd:VirtualSystemType" => "vmx-08"}
49
+ },
50
+ :RuntimeInfoSection =>
51
+ {
52
+ :VMWareTools => {:version => "2147483647"}
53
+ },
54
+ :StorageProfile =>
55
+ {
56
+ :type => "application/vnd.vmware.vcloud.vdcStorageProfile+xml",
57
+ :name => "TEST-STORAGE-PROFILE",
58
+ :href => "https://api.vcd.portal.examplecloud.com/api/vdcStorageProfile/00000000-aaaa-bbbb-aaaa-000000000000"
59
+ }
60
+ }
61
+ }
62
+ }
63
+ end
64
+
65
+ def self.mock_vapp
66
+ RSpec::Mocks::Mock.new(:fog_vapp, :body => vapp_body)
67
+ end
68
+
69
+ def self.hardware_resources
70
+ [
71
+ {
72
+ :'rasd:ResourceType' =>:: Vcloud::Walker::Resource::Vm::HARDWARE_RESOURCE_TYPES[:hard_disk],
73
+ :"rasd:AddressOnParent" => "0",
74
+ :"rasd:Description" => "Hard disk",
75
+ :"rasd:ElementName" => "Hard disk 1",
76
+ :"rasd:HostResource" => {:ns12_capacity => "11265", :ns12_busSubType => "lsilogic", :ns12_busType => "6"},
77
+ },
78
+
79
+ {
80
+ :'rasd:ResourceType' => ::Vcloud::Walker::Resource::Vm::HARDWARE_RESOURCE_TYPES[:hard_disk],
81
+ :"rasd:AddressOnParent" => "1",
82
+ :"rasd:Description" => "Hard disk",
83
+ :"rasd:ElementName" => "Hard disk 2",
84
+ :"rasd:HostResource" => {:ns12_capacity => "307200", :ns12_busSubType => "lsilogic", :ns12_busType => "6"}
85
+ },
86
+ {
87
+ :'rasd:ResourceType' => ::Vcloud::Walker::Resource::Vm::HARDWARE_RESOURCE_TYPES[:cpu],
88
+ :"rasd:Description" => "Number of Virtual CPUs",
89
+ :"rasd:ElementName" => "2 virtual CPU(s)"
90
+ },
91
+ {
92
+ :'rasd:ResourceType' => ::Vcloud::Walker::Resource::Vm::HARDWARE_RESOURCE_TYPES[:memory],
93
+ :"rasd:Description" => "Memory Size",
94
+ :"rasd:ElementName" => "4096 MB of memory"
95
+ },
96
+ {
97
+ :'rasd:ResourceType' => ::Vcloud::Walker::Resource::Vm::HARDWARE_RESOURCE_TYPES[:network_adapter],
98
+ :'rasd:Address' => '00:50:56:00:00:01',
99
+ :'rasd:AddressOnParent' => '0',
100
+ :'rasd:AutomaticAllocation' => true,
101
+ :'rasd:Description' => 'E1000 ethernet adapter on "Default"',
102
+ :'rasd:ElementName' => 'Network adapter 0',
103
+ :'rasd:InstanceID' => '0',
104
+ :'rasd:ResourceSubType' => 'E1000',
105
+ },
106
+ ]
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,46 @@
1
+ class StubVdc
2
+ @edge_gateways
3
+
4
+ def initialize
5
+ @edge_gateways = []
6
+ @vapps = []
7
+ @description = 'vdc-1-description'
8
+ end
9
+
10
+ def edge_gateways(edge_gateways)
11
+ @edge_gateways = edge_gateways
12
+ self
13
+ end
14
+
15
+ def vapps(vapps)
16
+ @vapps = vapps
17
+ self
18
+ end
19
+
20
+ def desc(desc)
21
+ @description = desc
22
+ self
23
+ end
24
+
25
+ def build
26
+ vdc = RSpec::Mocks::Mock.new(:vdc,
27
+ :id => 'vdc-1',
28
+ :description => @description,
29
+ :name => 'atomic reactor data centre',
30
+ :network_quota => 20,
31
+ :nic_quota => 0,
32
+ :vm_quota => 150,
33
+ :compute_capacity => {:storage => '200'}
34
+ )
35
+ vdc.stub(:edgeGateways).and_return( @edge_gateways )
36
+ vdc.stub(:vapps).and_return( @vapps)
37
+ vdc
38
+ end
39
+ end
40
+
41
+
42
+ class StubCollectionBuilders
43
+ def self.vdcs(vdc)
44
+ [vdc]
45
+ end
46
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ module Vcloud
4
+ module Walker
5
+
6
+ describe "walk" do
7
+
8
+ context "pass correct resource calls" do
9
+
10
+ it "should correctly pass catalogs" do
11
+ test_array = [ "name" => "catalogs" ]
12
+ Vcloud::Walker::Resource::Organization.stub(:catalogs).and_return(test_array)
13
+ result_array = Vcloud::Walker.walk("catalogs")
14
+ result_array.should include("name" => "catalogs")
15
+ end
16
+
17
+ it "should correctly pass vdcs" do
18
+ test_array = [ "name" => "vdcs" ]
19
+ Vcloud::Walker::Resource::Organization.stub(:vdcs).and_return(test_array)
20
+ result_array = Vcloud::Walker.walk("vdcs")
21
+ result_array.should include("name" => "vdcs")
22
+ end
23
+
24
+ it "should correctly pass networks" do
25
+ test_array = [ "name" => "networks" ]
26
+ Vcloud::Walker::Resource::Organization.stub(:networks).and_return(test_array)
27
+ result_array = Vcloud::Walker.walk("networks")
28
+ result_array.should include("name" => "networks")
29
+ end
30
+
31
+ it "should correctly pass edgegateways" do
32
+ test_array = [ "name" => "edgegateways" ]
33
+ Vcloud::Walker::Resource::Organization.stub(:edgegateways).and_return(test_array)
34
+ result_array = Vcloud::Walker.walk("edgegateways")
35
+ result_array.should include("name" => "edgegateways")
36
+ end
37
+
38
+ it "should correctly pass organization" do
39
+ test_array = [ "name" => "organization" ]
40
+ Vcloud::Walker::Resource::Organization.stub(:organization).and_return(test_array)
41
+ result_array = Vcloud::Walker.walk("organization")
42
+ result_array.should include("name" => "organization")
43
+ end
44
+
45
+ end
46
+
47
+ context "invalid resources" do
48
+
49
+ it "should reject input that is not a valid resouce" do
50
+ result_array = Vcloud::Walker.walk("invalid")
51
+ result_array.should be_nil
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end