vcloud-launcher 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ # Running vCloud Launcher Integration Tests
2
+
3
+ ## Prerequisites
4
+
5
+ - Access to a suitable vCloud Director organisation.
6
+
7
+ **NB** It is not safe to run them against an environment that is in use (e.g. production, preview) as
8
+ many of the tests clear down all config at the beginning and/or end to ensure the environment is as
9
+ the tests expect.
10
+
11
+ - A config file with the settings configured.
12
+
13
+ There is a [template file](/spec/integration/vcloud_tools_testing_config.yaml.template) to help with this. Copy the template file to `/spec/integration` (i.e. next to the template file) and remove the `.template`. This file will now be ignored by Git and you can safely add the parameters relevant to your environment.
14
+
15
+ - You need to include the set-up for your testing environment in your [fog file](https://github.com/alphagov/vcloud-launcher#credentials).
16
+
17
+ - The tests use the [vCloud Tools Tester](http://rubygems.org/gems/vcloud-tools-tester) gem. You do not need to install this, `bundler` will do this for you.
18
+
19
+ ## Parameters
20
+
21
+ ````
22
+ default: # This is the fog credential that refers to your testing environment, e.g. `test_credential`
23
+ vdc_1_name: # The name of a VDC
24
+ vdc_2_name: # The name of another VDC - you need two in your organisation to run these tests
25
+ catalog: # A catalog
26
+ vapp_template: # A vApp Template within that catalog
27
+ network_1: # The name of the primary network
28
+ network_1_ip: # The IP address of the primary network
29
+ network_2: # The name of a secondary network
30
+ network_2_ip: # The IP address of the secondary network
31
+ storage_profile: # The name of a storage profile (not the default)
32
+ default_storage_profile_name: # The name of the default storage profile
33
+ default_storage_profile_href: # The href of the default storage profile
34
+ vdc_1_storage_profile_href: # The href of `storage_profile` in `vdc_1`
35
+ vdc_2_storage_profile_href: # The href of `storage_profile` in `vdc_2`
36
+ ````
37
+
38
+ ## To run the tests
39
+
40
+ `FOG_CREDENTIAL=test_credential bundle exec integration`
@@ -2,8 +2,8 @@
2
2
  vapps:
3
3
  - name: <%= vapp_name %>
4
4
  vdc_name: <%= vdc_name %>
5
- catalog: <%= catalog %>
6
- catalog_item: <%= vapp_template %>
5
+ catalog_name: <%= catalog %>
6
+ vapp_template_name: <%= vapp_template %>
7
7
  vm:
8
8
  hardware_config:
9
9
  memory: 8192
@@ -21,10 +21,10 @@ vapps:
21
21
  - size: '2048'
22
22
  name: Hard disk 3
23
23
  network_connections:
24
- - name: <%= network1 %>
25
- ip_address: <%= network1_ip %>
26
- - name: <%= network2 %>
27
- ip_address: <%= network2_ip %>
24
+ - name: <%= network_1 %>
25
+ ip_address: <%= network_1_ip %>
26
+ - name: <%= network_2 %>
27
+ ip_address: <%= network_2_ip %>
28
28
  bootstrap:
29
29
  script_path: <%= bootstrap_script %>
30
30
  vars:
@@ -2,5 +2,5 @@
2
2
  vapps:
3
3
  - name: <%= vapp_name %>
4
4
  vdc_name: <%= vdc_name %>
5
- catalog: <%= catalog %>
6
- catalog_item: <%= vapp_template %>
5
+ catalog_name: <%= catalog %>
6
+ vapp_template_name: <%= vapp_template %>
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  vapps:
3
3
  - name: <%= vapp_name_1 %>
4
- vdc_name: <%= vdc_name_1 %>
5
- catalog: <%= catalog %>
6
- catalog_item: <%= vapp_template %>
4
+ vdc_name: <%= vdc_1_name %>
5
+ catalog_name: <%= catalog %>
6
+ vapp_template_name: <%= vapp_template %>
7
7
  vm:
8
8
  hardware_config: &hardware_config
9
9
  memory: 4096
@@ -14,9 +14,9 @@ vapps:
14
14
  message: hello world
15
15
  storage_profile: <%= storage_profile %>
16
16
  - name: <%= vapp_name_2 %>
17
- vdc_name: <%= vdc_name_2 %>
18
- catalog: <%= catalog %>
19
- catalog_item: <%= vapp_template %>
17
+ vdc_name: <%= vdc_2_name %>
18
+ catalog_name: <%= catalog %>
19
+ vapp_template_name: <%= vapp_template %>
20
20
  vm:
21
21
  hardware_config:
22
22
  <<: *hardware_config
@@ -24,9 +24,9 @@ vapps:
24
24
  <<: *bootstrap
25
25
  storage_profile: <%= storage_profile %>
26
26
  - name: <%= vapp_name_3 %>
27
- vdc_name: <%= vdc_name_1 %>
28
- catalog: <%= catalog %>
29
- catalog_item: <%= vapp_template %>
27
+ vdc_name: <%= vdc_1_name %>
28
+ catalog_name: <%= catalog %>
29
+ vapp_template_name: <%= vapp_template %>
30
30
  vm:
31
31
  hardware_config:
32
32
  <<: *hardware_config
@@ -35,9 +35,9 @@ vapps:
35
35
  bootstrap:
36
36
  <<: *bootstrap
37
37
  - name: <%= vapp_name_4 %>
38
- vdc_name: <%= vdc_name_1 %>
39
- catalog: <%= catalog %>
40
- catalog_item: <%= vapp_template %>
38
+ vdc_name: <%= vdc_1_name %>
39
+ catalog_name: <%= catalog %>
40
+ vapp_template_name: <%= vapp_template %>
41
41
  vm:
42
42
  hardware_config:
43
43
  <<: *hardware_config
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'vcloud/tools/tester'
2
3
 
3
4
  describe Vcloud::Launcher::Launch do
4
5
  context "storage profile", :take_too_long => true do
@@ -8,22 +9,22 @@ describe Vcloud::Launcher::Launch do
8
9
  @fog_interface = Vcloud::Fog::ServiceInterface.new
9
10
  Vcloud::Launcher::Launch.new.run(@config_yaml, {'dont-power-on' => true})
10
11
 
11
- @vapp_query_result_1 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_1], @test_data[:vdc_name_1])
12
+ @vapp_query_result_1 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_1], @test_data[:vdc_1_name])
12
13
  @vapp_id_1 = @vapp_query_result_1[:href].split('/').last
13
14
  @vapp_1 = @fog_interface.get_vapp @vapp_id_1
14
15
  @vm_1 = @vapp_1[:Children][:Vm].first
15
16
 
16
- @vapp_query_result_2 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_2], @test_data[:vdc_name_2])
17
+ @vapp_query_result_2 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_2], @test_data[:vdc_2_name])
17
18
  @vapp_id_2 = @vapp_query_result_2[:href].split('/').last
18
19
  @vapp_2 = @fog_interface.get_vapp @vapp_id_2
19
20
  @vm_2 = @vapp_2[:Children][:Vm].first
20
21
 
21
- @vapp_query_result_3 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_3], @test_data[:vdc_name_1])
22
+ @vapp_query_result_3 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_3], @test_data[:vdc_1_name])
22
23
  @vapp_id_3 = @vapp_query_result_3[:href].split('/').last
23
24
  @vapp_3 = @fog_interface.get_vapp @vapp_id_3
24
25
  @vm_3 = @vapp_3[:Children][:Vm].first
25
26
 
26
- @vapp_query_result_4 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_4], @test_data[:vdc_name_1])
27
+ @vapp_query_result_4 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_4], @test_data[:vdc_1_name])
27
28
  @vapp_id_4 = @vapp_query_result_4[:href].split('/').last
28
29
  @vapp_4 = @fog_interface.get_vapp @vapp_id_4
29
30
  @vm_4 = @vapp_4[:Children][:Vm].first
@@ -83,21 +84,24 @@ describe Vcloud::Launcher::Launch do
83
84
  end
84
85
 
85
86
  def define_test_data
87
+ config_file = File.join(File.dirname(__FILE__),
88
+ "../vcloud_tools_testing_config.yaml")
89
+ parameters = Vcloud::Tools::Tester::TestParameters.new(config_file)
86
90
  {
87
- vapp_name_1: "vdc-1-sp-#{Time.now.strftime('%s')}",
88
- vapp_name_2: "vdc-2-sp-#{Time.now.strftime('%s')}",
89
- vapp_name_3: "vdc-3-sp-#{Time.now.strftime('%s')}",
90
- vapp_name_4: "vdc-4-sp-#{Time.now.strftime('%s')}",
91
- vdc_name_1: ENV['VDC_NAME_1'],
92
- vdc_name_2: ENV['VDC_NAME_2'],
93
- catalog: ENV['VCLOUD_CATALOG_NAME'],
94
- vapp_template: ENV['VCLOUD_TEMPLATE_NAME'],
95
- storage_profile: ENV['VCLOUD_STORAGE_PROFILE_NAME'],
96
- vdc_1_sp_href: ENV['VDC_1_STORAGE_PROFILE_HREF'],
97
- vdc_2_sp_href: ENV['VDC_2_STORAGE_PROFILE_HREF'],
98
- default_storage_profile_name: ENV['DEFAULT_STORAGE_PROFILE_NAME'],
99
- default_storage_profile_href: ENV['DEFAULT_STORAGE_PROFILE_HREF'],
100
- nonsense_storage_profile: "nonsense-storage-profile-name",
101
- bootstrap_script: File.join(File.dirname(__FILE__), "data/basic_preamble_test.erb"),
91
+ vapp_name_1: "vdc-1-sp-#{Time.now.strftime('%s')}",
92
+ vapp_name_2: "vdc-2-sp-#{Time.now.strftime('%s')}",
93
+ vapp_name_3: "vdc-3-sp-#{Time.now.strftime('%s')}",
94
+ vapp_name_4: "vdc-4-sp-#{Time.now.strftime('%s')}",
95
+ vdc_1_name: parameters.vdc_1_name,
96
+ vdc_2_name: parameters.vdc_2_name,
97
+ catalog: parameters.catalog,
98
+ vapp_template: parameters.vapp_template,
99
+ storage_profile: parameters.storage_profile,
100
+ vdc_1_sp_href: parameters.vdc_1_storage_profile_href,
101
+ vdc_2_sp_href: parameters.vdc_2_storage_profile_href,
102
+ default_storage_profile_name: parameters.default_storage_profile_name,
103
+ default_storage_profile_href: parameters.default_storage_profile_href,
104
+ nonsense_storage_profile: "nonsense-storage-profile-name",
105
+ bootstrap_script: File.join(File.dirname(__FILE__), "data/basic_preamble_test.erb"),
102
106
  }
103
107
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'pp'
3
3
  require 'erb'
4
4
  require 'ostruct'
5
+ require 'vcloud/tools/tester'
5
6
 
6
7
  describe Vcloud::Launcher::Launch do
7
8
  context "with minimum input setup" do
@@ -52,7 +53,7 @@ describe Vcloud::Launcher::Launch do
52
53
  @vapp[:name].should eq(@test_data[:vapp_name])
53
54
  @vapp[:'ovf:NetworkSection'][:'ovf:Network'].count.should eq(2)
54
55
  vapp_networks = @vapp[:'ovf:NetworkSection'][:'ovf:Network'].collect { |connection| connection[:ovf_name] }
55
- vapp_networks.should =~ [@test_data[:network1], @test_data[:network2]]
56
+ vapp_networks.should =~ [@test_data[:network_1], @test_data[:network_2]]
56
57
  end
57
58
 
58
59
  it "should create vm within vapp" do
@@ -91,16 +92,16 @@ describe Vcloud::Launcher::Launch do
91
92
  vm_network_connection.count.should eq(2)
92
93
 
93
94
 
94
- primary_nic = vm_network_connection.detect { |connection| connection[:network] == @test_data[:network1] }
95
- primary_nic[:network].should eq(@test_data[:network1])
95
+ primary_nic = vm_network_connection.detect { |connection| connection[:network] == @test_data[:network_1] }
96
+ primary_nic[:network].should eq(@test_data[:network_1])
96
97
  primary_nic[:NetworkConnectionIndex].should eq(@vm[:NetworkConnectionSection][:PrimaryNetworkConnectionIndex])
97
- primary_nic[:IpAddress].should eq(@test_data[:network1_ip])
98
+ primary_nic[:IpAddress].should eq(@test_data[:network_1_ip])
98
99
  primary_nic[:IpAddressAllocationMode].should eq('MANUAL')
99
100
 
100
- second_nic = vm_network_connection.detect { |connection| connection[:network] == @test_data[:network2] }
101
- second_nic[:network].should eq(@test_data[:network2])
101
+ second_nic = vm_network_connection.detect { |connection| connection[:network] == @test_data[:network_2] }
102
+ second_nic[:network].should eq(@test_data[:network_2])
102
103
  second_nic[:NetworkConnectionIndex].should eq('1')
103
- second_nic[:IpAddress].should eq(@test_data[:network2_ip])
104
+ second_nic[:IpAddress].should eq(@test_data[:network_2_ip])
104
105
  second_nic[:IpAddressAllocationMode].should eq('MANUAL')
105
106
 
106
107
  end
@@ -140,18 +141,21 @@ describe Vcloud::Launcher::Launch do
140
141
  end
141
142
 
142
143
  def define_test_data
144
+ config_file = File.join(File.dirname(__FILE__),
145
+ "../vcloud_tools_testing_config.yaml")
146
+ parameters = Vcloud::Tools::Tester::TestParameters.new(config_file)
143
147
  {
144
- vapp_name: "vapp-vcloud-tools-tests-#{Time.now.strftime('%s')}",
145
- vdc_name: ENV['VCLOUD_VDC_NAME'],
146
- catalog: ENV['VCLOUD_CATALOG_NAME'],
147
- vapp_template: ENV['VCLOUD_TEMPLATE_NAME'],
148
- network1: ENV['VCLOUD_NETWORK1_NAME'],
149
- network2: ENV['VCLOUD_NETWORK2_NAME'],
150
- network1_ip: ENV['VCLOUD_NETWORK1_IP'],
151
- network2_ip: ENV['VCLOUD_NETWORK2_IP'],
152
- storage_profile: ENV['VCLOUD_STORAGE_PROFILE_NAME'],
153
- bootstrap_script: File.join(File.dirname(__FILE__), "data/basic_preamble_test.erb"),
154
- date_metadata: DateTime.parse('2013-10-23 15:34:00 +0000')
148
+ vapp_name: "vapp-vcloud-tools-tests-#{Time.now.strftime('%s')}",
149
+ vdc_name: parameters.vdc_1_name,
150
+ catalog: parameters.catalog,
151
+ vapp_template: parameters.vapp_template,
152
+ storage_profile: parameters.storage_profile,
153
+ network_1: parameters.network_1,
154
+ network_2: parameters.network_2,
155
+ network_1_ip: parameters.network_1_ip,
156
+ network_2_ip: parameters.network_2_ip,
157
+ bootstrap_script: File.join(File.dirname(__FILE__), "data/basic_preamble_test.erb"),
158
+ date_metadata: DateTime.parse('2013-10-23 15:34:00 +0000')
155
159
  }
156
160
  end
157
161
  end
@@ -0,0 +1,14 @@
1
+ default:
2
+ vdc_1_name:
3
+ vdc_2_name:
4
+ catalog:
5
+ vapp_template:
6
+ network_1:
7
+ network_1_ip:
8
+ network_2:
9
+ network_2_ip:
10
+ storage_profile:
11
+ default_storage_profile_name:
12
+ default_storage_profile_href:
13
+ vdc_1_storage_profile_href:
14
+ vdc_2_storage_profile_href:
@@ -1,76 +1,74 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Vcloud
4
- describe Launcher::Launch do
5
- context "#run" do
6
- before(:each) do
7
- config_loader = double(:config_loader)
8
- expect(Vcloud::Core::ConfigLoader).to receive(:new).and_return(config_loader)
9
- @successful_app_1 = {
10
- :name => "successful app 1",
11
- :vdc_name => "Test Vdc",
12
- :catalog => "default",
13
- :catalog_item => "ubuntu-precise"
14
- }
15
- @fake_failing_app = {
16
- :name => "fake failing app",
17
- :vdc_name => "wrong vdc",
18
- :catalog => "default",
19
- :catalog_item => "ubuntu-precise"
20
- }
21
- @successful_app_2 = {
22
- :name => "successful app 2",
23
- :vdc_name => "Test Vdc",
24
- :catalog => "default",
25
- :catalog_item => "ubuntu-precise"
26
- }
27
- expect(config_loader).to receive(:load_config).
28
- and_return({:vapps => [@successful_app_1, @fake_failing_app, @successful_app_2]})
29
- end
30
-
31
- it "should stop on failure by default" do
32
- expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@successful_app_1).and_return(double(:vapp, :power_on => true))
33
- expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@fake_failing_app).and_raise(RuntimeError.new('failed to find vdc'))
34
- expect(Vcloud::Launcher::VappOrchestrator).not_to receive(:provision).with(@successful_app_2)
3
+ describe Vcloud::Launcher::Launch do
4
+ context "#run" do
5
+ before(:each) do
6
+ config_loader = double(:config_loader)
7
+ expect(Vcloud::Core::ConfigLoader).to receive(:new).and_return(config_loader)
8
+ @successful_app_1 = {
9
+ :name => "successful app 1",
10
+ :vdc_name => "Test Vdc",
11
+ :catalog_name => "default",
12
+ :vapp_template_name => "ubuntu-precise"
13
+ }
14
+ @fake_failing_app = {
15
+ :name => "fake failing app",
16
+ :vdc_name => "wrong vdc",
17
+ :catalog_name => "default",
18
+ :vapp_template_name => "ubuntu-precise"
19
+ }
20
+ @successful_app_2 = {
21
+ :name => "successful app 2",
22
+ :vdc_name => "Test Vdc",
23
+ :catalog_name => "default",
24
+ :vapp_template_name => "ubuntu-precise"
25
+ }
26
+ expect(config_loader).to receive(:load_config).
27
+ and_return({:vapps => [@successful_app_1, @fake_failing_app, @successful_app_2]})
28
+ end
35
29
 
36
- cli_options = {}
37
- Vcloud::Launcher::Launch.new.run('input_config_yaml', cli_options)
38
- end
30
+ it "should stop on failure by default" do
31
+ expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@successful_app_1).and_return(double(:vapp, :power_on => true))
32
+ expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@fake_failing_app).and_raise(RuntimeError.new('failed to find vdc'))
33
+ expect(Vcloud::Launcher::VappOrchestrator).not_to receive(:provision).with(@successful_app_2)
39
34
 
40
- it "should continue on error if cli option continue-on-error is set" do
41
- expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@successful_app_1).and_return(double(:vapp, :power_on => true))
42
- expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@fake_failing_app).and_raise(RuntimeError.new('failed to find vdc'))
43
- expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@successful_app_2).and_return(double(:vapp, :power_on => true))
35
+ cli_options = {}
36
+ subject.run('input_config_yaml', cli_options)
37
+ end
44
38
 
45
- cli_options = {"continue-on-error" => true}
46
- Vcloud::Launcher::Launch.new.run('input_config_yaml', cli_options)
47
- end
39
+ it "should continue on error if cli option continue-on-error is set" do
40
+ expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@successful_app_1).and_return(double(:vapp, :power_on => true))
41
+ expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@fake_failing_app).and_raise(RuntimeError.new('failed to find vdc'))
42
+ expect(Vcloud::Launcher::VappOrchestrator).to receive(:provision).with(@successful_app_2).and_return(double(:vapp, :power_on => true))
48
43
 
44
+ cli_options = {"continue-on-error" => true}
45
+ subject.run('input_config_yaml', cli_options)
49
46
  end
50
47
 
51
- context "#set_logging_level" do
48
+ end
52
49
 
53
- it "sets the logging level to DEBUG when :verbose is specified" do
54
- expect(Vcloud::Core.logger).to receive(:level=).with(Logger::DEBUG)
55
- Vcloud::Launcher::Launch.new.set_logging_level(:verbose => true)
56
- end
50
+ context "#set_logging_level" do
57
51
 
58
- it "sets the logging level to ERROR when :quiet is specified" do
59
- expect(Vcloud::Core.logger).to receive(:level=).with(Logger::ERROR)
60
- Vcloud::Launcher::Launch.new.set_logging_level(:quiet => true)
61
- end
52
+ it "sets the logging level to DEBUG when :verbose is specified" do
53
+ expect(Vcloud::Core.logger).to receive(:level=).with(Logger::DEBUG)
54
+ subject.set_logging_level(:verbose => true)
55
+ end
62
56
 
63
- it "sets the logging level to DEBUG when :quiet and :verbose are specified" do
64
- expect(Vcloud::Core.logger).to receive(:level=).with(Logger::DEBUG)
65
- Vcloud::Launcher::Launch.new.set_logging_level(:quiet => true, :verbose => true)
66
- end
57
+ it "sets the logging level to ERROR when :quiet is specified" do
58
+ expect(Vcloud::Core.logger).to receive(:level=).with(Logger::ERROR)
59
+ subject.set_logging_level(:quiet => true)
60
+ end
67
61
 
68
- it "sets the logging level to INFO by default" do
69
- expect(Vcloud::Core.logger).to receive(:level=).with(Logger::INFO)
70
- Vcloud::Launcher::Launch.new.set_logging_level({})
71
- end
62
+ it "sets the logging level to DEBUG when :quiet and :verbose are specified" do
63
+ expect(Vcloud::Core.logger).to receive(:level=).with(Logger::DEBUG)
64
+ subject.set_logging_level(:quiet => true, :verbose => true)
65
+ end
72
66
 
67
+ it "sets the logging level to INFO by default" do
68
+ expect(Vcloud::Core.logger).to receive(:level=).with(Logger::INFO)
69
+ subject.set_logging_level({})
73
70
  end
74
71
 
75
72
  end
73
+
76
74
  end
@@ -1,52 +1,85 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Vcloud
4
- module Launcher
5
- describe VappOrchestrator do
6
-
7
- context "provision a vapp" do
8
-
9
- before(:each) do
10
- @config = {
11
- :name => 'test-vapp-1',
12
- :vdc_name => 'test-vdc-1',
13
- :catalog => 'org-1-catalog',
14
- :catalog_item => 'org-1-template',
15
- :vm => {
16
- :network_connections => [{:name => 'org-vdc-1-net-1'}]
17
- }
3
+ describe Vcloud::Launcher::VappOrchestrator do
4
+ # Testing class methods rather than instance methods.
5
+ let(:subject) { Vcloud::Launcher::VappOrchestrator }
6
+
7
+ context "provision a vapp" do
8
+
9
+ let(:mock_fog_vm) {
10
+ double(:vm)
11
+ }
12
+ let(:mock_vapp) {
13
+ double(:vapp, :fog_vms => [mock_fog_vm], :reload => self)
14
+ }
15
+ let(:mock_vm_orchestrator) {
16
+ double(:vm_orchestrator, :customize => true)
17
+ }
18
+
19
+ before(:each) do
20
+ @config = {
21
+ :name => 'test-vapp-1',
22
+ :vdc_name => 'test-vdc-1',
23
+ :catalog_name => 'org-1-catalog',
24
+ :vapp_template_name => 'org-1-template',
25
+ :vm => {
26
+ :network_connections => [{:name => 'org-vdc-1-net-1'}]
18
27
  }
19
- end
28
+ }
29
+ end
20
30
 
21
- it "should return a vapp if it already exists" do
22
- existing_vapp = double(:vapp, :name => 'existing-vapp-1')
31
+ it "should return a vapp if it already exists" do
32
+ existing_vapp = double(:vapp, :name => 'existing-vapp-1')
23
33
 
24
- Core::Vapp.should_receive(:get_by_name_and_vdc_name).with('test-vapp-1', 'test-vdc-1').and_return(existing_vapp)
25
- Vcloud::Core.logger.should_receive(:info).with('Found existing vApp test-vapp-1 in vDC \'test-vdc-1\'. Skipping.')
26
- actual_vapp = VappOrchestrator.provision @config
27
- actual_vapp.should_not be_nil
28
- actual_vapp.should == existing_vapp
29
- end
34
+ Vcloud::Core::Vapp.should_receive(:get_by_name_and_vdc_name).with('test-vapp-1', 'test-vdc-1').and_return(existing_vapp)
35
+ Vcloud::Core.logger.should_receive(:info).with('Found existing vApp test-vapp-1 in vDC \'test-vdc-1\'. Skipping.')
36
+ actual_vapp = subject.provision @config
37
+ actual_vapp.should_not be_nil
38
+ actual_vapp.should == existing_vapp
39
+ end
30
40
 
31
- it "should create a vapp if it does not exist" do
32
- #this test highlights the problems in vapp
33
- mock_fog_vm = double(:vm)
34
- mock_vapp = double(:vapp, :fog_vms => [mock_fog_vm], :reload => self)
35
- mock_vm_orchestrator = double(:vm_orchestrator, :customize => true)
41
+ it "should create a vapp if it does not exist" do
42
+ #this test highlights the problems in vapp
36
43
 
44
+ Vcloud::Core::Vapp.should_receive(:get_by_name_and_vdc_name).with('test-vapp-1', 'test-vdc-1').and_return(nil)
45
+ Vcloud::Core::VappTemplate.should_receive(:get).with('org-1-template', 'org-1-catalog').and_return(double(:vapp_template, :id => 1))
37
46
 
38
- Core::Vapp.should_receive(:get_by_name_and_vdc_name).with('test-vapp-1', 'test-vdc-1').and_return(nil)
39
- Core::VappTemplate.should_receive(:get).with('org-1-catalog', 'org-1-template').and_return(double(:vapp_template, :id => 1))
47
+ Vcloud::Core::Vapp.should_receive(:instantiate).with('test-vapp-1', ['org-vdc-1-net-1'], 1, 'test-vdc-1')
48
+ .and_return(mock_vapp)
49
+ Vcloud::Launcher::VmOrchestrator.should_receive(:new).with(mock_fog_vm, mock_vapp).and_return(mock_vm_orchestrator)
40
50
 
41
- Core::Vapp.should_receive(:instantiate).with('test-vapp-1', ['org-vdc-1-net-1'], 1, 'test-vdc-1')
42
- .and_return(mock_vapp)
43
- VmOrchestrator.should_receive(:new).with(mock_fog_vm, mock_vapp).and_return(mock_vm_orchestrator)
51
+ new_vapp = subject.provision @config
52
+ new_vapp.should == mock_vapp
53
+ end
44
54
 
45
- new_vapp = VappOrchestrator.provision @config
46
- new_vapp.should == mock_vapp
47
- end
55
+ context "deprecated config items" do
56
+ let(:mock_vapp_template) {
57
+ double(:vapp_template, :id => 2)
58
+ }
59
+ before(:each) {
60
+ Vcloud::Core::Vapp.stub(:get_by_name_and_vdc_name)
61
+ Vcloud::Core::Vapp.stub(:instantiate).and_return(mock_vapp)
62
+ Vcloud::Launcher::VmOrchestrator.stub(:new).and_return(mock_vm_orchestrator)
63
+ }
48
64
 
65
+ it "should use catalog_item when vapp_template_name is not present" do
66
+ config = @config.clone
67
+ config.delete(:vapp_template_name)
68
+ config[:catalog_item] = 'deprecated-template'
69
+
70
+ Vcloud::Core::VappTemplate.should_receive(:get).with('deprecated-template', 'org-1-catalog').and_return(mock_vapp_template)
71
+ Vcloud::Launcher::VappOrchestrator.provision(config)
72
+ end
73
+
74
+ it "should use catalog when catalog_name is not present" do
75
+ config = @config.clone
76
+ config.delete(:catalog_name)
77
+ config[:catalog] = 'deprecated-catalog'
78
+
79
+ Vcloud::Core::VappTemplate.should_receive(:get).with('org-1-template', 'deprecated-catalog').and_return(mock_vapp_template)
80
+ Vcloud::Launcher::VappOrchestrator.provision(config)
49
81
  end
50
82
  end
83
+
51
84
  end
52
85
  end