bosh_aws_cpi 0.7.0 → 1.5.0.pre.1113

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README.md +22 -19
  2. data/bin/bosh_aws_console +1 -13
  3. data/lib/bosh_aws_cpi.rb +1 -1
  4. data/lib/cloud/aws/aki_picker.rb +7 -7
  5. data/lib/cloud/aws/availability_zone_selector.rb +40 -0
  6. data/lib/cloud/aws/cloud.rb +359 -476
  7. data/lib/cloud/aws/dynamic_network.rb +0 -6
  8. data/lib/cloud/aws/helpers.rb +10 -68
  9. data/lib/cloud/aws/instance_manager.rb +171 -0
  10. data/lib/cloud/aws/manual_network.rb +26 -0
  11. data/lib/cloud/aws/network_configurator.rb +33 -62
  12. data/lib/cloud/aws/resource_wait.rb +189 -0
  13. data/lib/cloud/aws/stemcell.rb +68 -0
  14. data/lib/cloud/aws/stemcell_creator.rb +114 -0
  15. data/lib/cloud/aws/tag_manager.rb +30 -0
  16. data/lib/cloud/aws/version.rb +1 -1
  17. data/lib/cloud/aws/vip_network.rb +9 -7
  18. data/lib/cloud/aws.rb +11 -2
  19. data/scripts/stemcell-copy.sh +37 -0
  20. metadata +45 -81
  21. data/Rakefile +0 -50
  22. data/lib/cloud/aws/registry_client.rb +0 -109
  23. data/spec/assets/stemcell-copy +0 -31
  24. data/spec/integration/cpi_test.rb +0 -78
  25. data/spec/spec_helper.rb +0 -121
  26. data/spec/unit/aki_picker_spec.rb +0 -29
  27. data/spec/unit/attach_disk_spec.rb +0 -143
  28. data/spec/unit/cloud_spec.rb +0 -32
  29. data/spec/unit/configure_networks_spec.rb +0 -113
  30. data/spec/unit/create_disk_spec.rb +0 -73
  31. data/spec/unit/create_stemcell_spec.rb +0 -113
  32. data/spec/unit/create_vm_spec.rb +0 -249
  33. data/spec/unit/delete_disk_spec.rb +0 -34
  34. data/spec/unit/delete_stemcell_spec.rb +0 -29
  35. data/spec/unit/delete_vm_spec.rb +0 -25
  36. data/spec/unit/detach_disk_spec.rb +0 -63
  37. data/spec/unit/helpers_spec.rb +0 -64
  38. data/spec/unit/network_configurator_spec.rb +0 -57
  39. data/spec/unit/reboot_vm_spec.rb +0 -38
  40. data/spec/unit/set_vm_metadata_spec.rb +0 -30
  41. data/spec/unit/validate_deployment_spec.rb +0 -16
@@ -1,113 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require "spec_helper"
4
-
5
- describe Bosh::AwsCloud::Cloud do
6
-
7
- before :each do
8
- @tmp_dir = Dir.mktmpdir
9
- end
10
-
11
- after(:each) do
12
- FileUtils.rm_rf(@tmp_dir)
13
- end
14
-
15
- describe "EBS-volume based flow" do
16
-
17
- it "creates stemcell by copying an image to a new EBS volume" do
18
- volume = double("volume", :id => "v-foo")
19
- current_instance = double("instance",
20
- :id => "i-current",
21
- :availability_zone => "us-nowhere-2b")
22
- attachment = double("attachment",
23
- :device => "/dev/sdh",
24
- :volume => volume)
25
-
26
- snapshot = double("snapshot", :id => "s-baz", :delete => nil)
27
- image = double("image", :id => "i-bar")
28
-
29
- unique_name = UUIDTools::UUID.random_create.to_s
30
-
31
- image_params = {
32
- :name => "BOSH-#{unique_name}",
33
- :architecture => "x86_64",
34
- :kernel_id => "aki-b4aa75dd",
35
- :root_device_name => "/dev/sda1",
36
- :description => "bosh-stemcell 1.2.3",
37
- :block_device_mappings => {
38
- "/dev/sda" => { :snapshot_id => "s-baz" },
39
- "/dev/sdb" => "ephemeral0"
40
- }
41
- }
42
-
43
-
44
- image.should_receive(:add_tag).with("Name", {:value=>"bosh-stemcell 1.2.3"})
45
-
46
- cloud = mock_cloud do |ec2|
47
- ec2.volumes.stub(:[]).with("v-foo").and_return(volume)
48
- ec2.instances.stub(:[]).with("i-current").and_return(current_instance)
49
- ec2.images.should_receive(:create).with(image_params).and_return(image)
50
- end
51
-
52
- cloud.should_receive(:find_aki).with("x86_64", "/dev/sda1")
53
- .and_return("aki-b4aa75dd")
54
-
55
- cloud.stub(:generate_unique_name).and_return(unique_name)
56
- cloud.stub(:current_instance_id).and_return("i-current")
57
-
58
- old_mappings = {
59
- "/dev/sdf" => double("attachment",
60
- :volume => double("volume",
61
- :id => "v-zb")),
62
- "/dev/sdg" => double("attachment",
63
- :volume => double("volume",
64
- :id => "v-ppc"))
65
- }
66
-
67
- extra_mapping = {
68
- "/dev/sdh" => attachment
69
- }
70
-
71
- new_mappings = old_mappings.merge(extra_mapping)
72
-
73
- current_instance.stub(:block_device_mappings).
74
- and_return(old_mappings, new_mappings)
75
-
76
- cloud.should_receive(:create_disk).with(2048, "i-current").
77
- and_return("v-foo")
78
-
79
- volume.should_receive(:attach_to).with(current_instance, "/dev/sdh").
80
- and_return(attachment)
81
-
82
- cloud.should_receive(:wait_resource).with(attachment, :attached)
83
-
84
- cloud.stub(:sleep)
85
-
86
- File.stub(:blockdev?).with("/dev/sdh").and_return(false, false, false)
87
- File.stub(:blockdev?).with("/dev/xvdh").and_return(false, false, true)
88
-
89
- cloud.should_receive(:copy_root_image).with("/tmp/foo", "/dev/xvdh")
90
-
91
- volume.should_receive(:create_snapshot).and_return(snapshot)
92
- cloud.should_receive(:wait_resource).with(snapshot, :completed)
93
-
94
- cloud.should_receive(:wait_resource).with(image, :available, :state)
95
-
96
- volume.should_receive(:detach_from).with(current_instance, "/dev/sdh").
97
- and_return(attachment)
98
-
99
- cloud.should_receive(:wait_resource).with(attachment, :detached)
100
-
101
- cloud.should_receive(:delete_disk).with("v-foo")
102
-
103
- cloud_properties = {
104
- "root_device_name" => "/dev/sda1",
105
- "architecture" => "x86_64",
106
- "name" => "bosh-stemcell",
107
- "version" => "1.2.3"
108
- }
109
- cloud.create_stemcell("/tmp/foo", cloud_properties).should == "i-bar"
110
- end
111
-
112
- end
113
- end
@@ -1,249 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require "spec_helper"
4
-
5
- describe Bosh::AwsCloud::Cloud, "create_vm" do
6
-
7
- def agent_settings(unique_name, network_spec=dynamic_network_spec)
8
- {
9
- "vm" => {
10
- "name" => "vm-#{unique_name}"
11
- },
12
- "agent_id" => "agent-id",
13
- "networks" => { "network_a" => network_spec },
14
- "disks" => {
15
- "system" => "/dev/sda1",
16
- "ephemeral" => "/dev/sdb",
17
- "persistent" => {}
18
- },
19
- "env" => {
20
- "test_env" => "value"
21
- },
22
- "foo" => "bar", # Agent env
23
- "baz" => "zaz"
24
- }
25
- end
26
-
27
- def fake_image_set
28
- image = double("image", :root_device_name => "/dev/sda1")
29
- double("images_set", :images_set => [image])
30
- end
31
-
32
- def ec2_params(user_data, security_groups=[])
33
- {
34
- :image_id => "sc-id",
35
- :count => 1,
36
- :key_name => "test_key",
37
- :security_groups => security_groups,
38
- :instance_type => "m3.zb",
39
- :user_data => Yajl::Encoder.encode(user_data),
40
- :availability_zone => "foobar-1a"
41
- }
42
- end
43
-
44
- before(:each) do
45
- @registry = mock_registry
46
- end
47
-
48
- it "creates EC2 instance and polls until it's ready" do
49
- unique_name = UUIDTools::UUID.random_create.to_s
50
-
51
- user_data = {
52
- "registry" => {
53
- "endpoint" => "http://registry:3333"
54
- }
55
- }
56
-
57
- sec_grp = double("security_group", :name => "default")
58
- instance = double("instance",
59
- :id => "i-test",
60
- :elastic_ip => nil,
61
- :security_groups => [sec_grp])
62
- client = double("client", :describe_images => fake_image_set)
63
-
64
- cloud = mock_cloud do |ec2|
65
- ec2.instances.should_receive(:create).
66
- with(ec2_params(user_data, %w[default])).
67
- and_return(instance)
68
- ec2.should_receive(:client).and_return(client)
69
- end
70
-
71
- cloud.should_receive(:generate_unique_name).and_return(unique_name)
72
- cloud.should_receive(:wait_resource).with(instance, :running)
73
- @registry.should_receive(:update_settings)
74
- .with("i-test", agent_settings(unique_name))
75
-
76
- vm_id = cloud.create_vm("agent-id", "sc-id",
77
- resource_pool_spec,
78
- { "network_a" => dynamic_network_spec },
79
- nil, { "test_env" => "value" })
80
-
81
- vm_id.should == "i-test"
82
- end
83
-
84
- it "passes dns servers in ec2 user data when present" do
85
- unique_name = UUIDTools::UUID.random_create.to_s
86
-
87
- user_data = {
88
- "registry" => {
89
- "endpoint" => "http://registry:3333"
90
- },
91
- "dns" => { "nameserver" => ["1.2.3.4"] }
92
- }
93
-
94
- sec_grp = double("security_group", :name => "default")
95
- instance = double("instance",
96
- :id => "i-test",
97
- :elastic_ip => nil,
98
- :security_groups => sec_grp)
99
- client = double("client", :describe_images => fake_image_set)
100
-
101
- network_spec = dynamic_network_spec
102
- network_spec["dns"] = ["1.2.3.4"]
103
-
104
- cloud = mock_cloud do |ec2|
105
- ec2.instances.should_receive(:create).
106
- with(ec2_params(user_data, %w[default])).
107
- and_return(instance)
108
- ec2.should_receive(:client).and_return(client)
109
- end
110
-
111
- cloud.should_receive(:generate_unique_name).and_return(unique_name)
112
- cloud.should_receive(:wait_resource).with(instance, :running)
113
- @registry.should_receive(:update_settings)
114
- .with("i-test", agent_settings(unique_name, network_spec))
115
-
116
- vm_id = cloud.create_vm("agent-id", "sc-id",
117
- resource_pool_spec,
118
- { "network_a" => network_spec },
119
- nil, { "test_env" => "value" })
120
-
121
- vm_id.should == "i-test"
122
- end
123
-
124
- it "creates EC2 instance with security group" do
125
- unique_name = UUIDTools::UUID.random_create.to_s
126
-
127
- user_data = {
128
- "registry" => {
129
- "endpoint" => "http://registry:3333"
130
- }
131
- }
132
-
133
- instance = double("instance",
134
- :id => "i-test",
135
- :elastic_ip => nil,
136
- :security_groups => [])
137
- client = double("client", :describe_images => fake_image_set)
138
-
139
- security_groups = %w[bar foo]
140
- network_spec = dynamic_network_spec
141
- network_spec["cloud_properties"] = {
142
- "security_groups" => security_groups
143
- }
144
-
145
- cloud = mock_cloud do |ec2|
146
- ec2.instances.should_receive(:create).
147
- with(ec2_params(user_data, security_groups)).
148
- and_return(instance)
149
- ec2.should_receive(:client).and_return(client)
150
- end
151
-
152
- cloud.should_receive(:generate_unique_name).and_return(unique_name)
153
- cloud.should_receive(:wait_resource).with(instance, :running)
154
- @registry.should_receive(:update_settings)
155
- .with("i-test", agent_settings(unique_name, network_spec))
156
-
157
- vm_id = cloud.create_vm("agent-id", "sc-id",
158
- resource_pool_spec,
159
- { "network_a" => network_spec },
160
- nil, { "test_env" => "value" })
161
-
162
- vm_id.should == "i-test"
163
- end
164
-
165
- it "associates instance with elastic ip if vip network is provided" do
166
- sec_grp = double("security_group", :name => "default")
167
- instance = double("instance",
168
- :id => "i-test",
169
- :elastic_ip => nil,
170
- :security_groups => [sec_grp])
171
- client = double("client", :describe_images => fake_image_set)
172
-
173
- cloud = mock_cloud do |ec2|
174
- ec2.instances.should_receive(:create).and_return(instance)
175
- image = double("image")
176
- image.should_receive(:root_device_name).and_return("/dev/sda1")
177
-
178
- result = double("result")
179
- result.should_receive(:images_set).and_return([image])
180
-
181
- client = double("client")
182
- client.should_receive(:describe_images).with({:image_ids=>["sc-id"]}).
183
- and_return(result)
184
-
185
- ec2.should_receive(:client).and_return(client)
186
- end
187
-
188
- instance.should_receive(:associate_elastic_ip).with("10.0.0.1")
189
- cloud.should_receive(:wait_resource).with(instance, :running)
190
- @registry.should_receive(:update_settings)
191
-
192
- vm_id = cloud.create_vm("agent-id", "sc-id",
193
- resource_pool_spec,
194
- combined_network_spec)
195
- end
196
-
197
- def volume(zone)
198
- vol = double("volume")
199
- vol.stub(:availability_zone).and_return(zone)
200
- vol
201
- end
202
-
203
- describe "#select_availability_zone" do
204
-
205
- it "should select the default availability_zone when all values are nil" do
206
- cloud = mock_cloud
207
- cloud.select_availability_zone(nil, nil).should ==
208
- Bosh::AwsCloud::Cloud::DEFAULT_AVAILABILITY_ZONE
209
- end
210
-
211
- it "should select the zone from a list of disks" do
212
- cloud = mock_cloud do |ec2|
213
- ec2.volumes.stub(:[]).and_return(volume("foo"), volume("foo"))
214
- end
215
- cloud.select_availability_zone(%w[cid1 cid2], nil).should == "foo"
216
- end
217
-
218
- it "should select the zone from a list of disks and a default" do
219
- cloud = mock_cloud do |ec2|
220
- ec2.volumes.stub(:[]).and_return(volume("foo"), volume("foo"))
221
- end
222
- cloud.select_availability_zone(%w[cid1 cid2], "foo").should == "foo"
223
- end
224
- end
225
-
226
- describe "#ensure_same_availability_zone" do
227
- it "should raise an error when the zones differ" do
228
- cloud = mock_cloud
229
- lambda {
230
- cloud.ensure_same_availability_zone([volume("foo"), volume("bar")], nil)
231
- }.should raise_error Bosh::Clouds::CloudError
232
- end
233
-
234
- it "should raise an error when the zones differ" do
235
- cloud = mock_cloud
236
- lambda {
237
- cloud.ensure_same_availability_zone([volume("foo"), volume("bar")], "foo")
238
- }.should raise_error Bosh::Clouds::CloudError
239
- end
240
-
241
- it "should raise an error when the zones differ" do
242
- cloud = mock_cloud
243
- lambda {
244
- cloud.ensure_same_availability_zone([volume("foo"), volume("foo")], "bar")
245
- }.should raise_error Bosh::Clouds::CloudError
246
- end
247
- end
248
-
249
- end
@@ -1,34 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require File.expand_path("../../spec_helper", __FILE__)
4
-
5
- describe Bosh::AwsCloud::Cloud do
6
-
7
- it "deletes an EC2 volume" do
8
- volume = double("volume", :id => "v-foo")
9
-
10
- cloud = mock_cloud do |ec2|
11
- ec2.volumes.stub(:[]).with("v-foo").and_return(volume)
12
- end
13
-
14
- volume.should_receive(:state).and_return(:available)
15
- volume.should_receive(:delete)
16
- cloud.should_receive(:wait_resource).with(volume, :deleted)
17
-
18
- cloud.delete_disk("v-foo")
19
- end
20
-
21
- it "doesn't delete volume unless it's state is `available'" do
22
- volume = double("volume", :id => "v-foo", :state => :busy)
23
-
24
- cloud = mock_cloud do |ec2|
25
- ec2.volumes.stub(:[]).with("v-foo").and_return(volume)
26
- end
27
-
28
- expect {
29
- cloud.delete_disk("v-foo")
30
- }.to raise_error(Bosh::Clouds::CloudError,
31
- "Cannot delete volume `v-foo', state is busy")
32
- end
33
-
34
- end
@@ -1,29 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require File.expand_path("../../spec_helper", __FILE__)
4
-
5
- describe Bosh::AwsCloud::Cloud do
6
-
7
- it "deregisters EC2 image" do
8
- image = double("image", :id => "i-foo")
9
-
10
- snapshot = double("snapshot")
11
- snapshot.should_receive(:delete)
12
-
13
- snapshots = double("snapshots")
14
- snapshots.should_receive(:[]).with("snap-123").and_return(snapshot)
15
-
16
- cloud = mock_cloud do |ec2|
17
- ec2.images.stub(:[]).with("i-foo").and_return(image)
18
- ec2.should_receive(:snapshots).and_return(snapshots)
19
- end
20
-
21
- image.should_receive(:deregister)
22
-
23
- map = { "/dev/sda" => {:snapshot_id => "snap-123"} }
24
- image.should_receive(:block_device_mappings).and_return(map)
25
-
26
- cloud.delete_stemcell("i-foo")
27
- end
28
-
29
- end
@@ -1,25 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require File.expand_path("../../spec_helper", __FILE__)
4
-
5
- describe Bosh::AwsCloud::Cloud do
6
-
7
- before(:each) do
8
- @registry = mock_registry
9
- end
10
-
11
- it "deletes an EC2 instance" do
12
- instance = double("instance", :id => "i-foobar")
13
-
14
- cloud = mock_cloud do |ec2|
15
- ec2.instances.stub(:[]).with("i-foobar").and_return(instance)
16
- end
17
-
18
- instance.should_receive(:terminate)
19
- cloud.should_receive(:wait_resource).with(instance, :terminated)
20
-
21
- @registry.should_receive(:delete_settings).with("i-foobar")
22
-
23
- cloud.delete_vm("i-foobar")
24
- end
25
- end
@@ -1,63 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require File.expand_path("../../spec_helper", __FILE__)
4
-
5
- describe Bosh::AwsCloud::Cloud do
6
-
7
- before(:each) do
8
- @registry = mock_registry
9
- end
10
-
11
- it "detaches EC2 volume from an instance" do
12
- instance = double("instance", :id => "i-test")
13
- volume = double("volume", :id => "v-foobar")
14
- attachment = double("attachment", :device => "/dev/sdf")
15
-
16
- cloud = mock_cloud do |ec2|
17
- ec2.instances.should_receive(:[]).with("i-test").and_return(instance)
18
- ec2.volumes.should_receive(:[]).with("v-foobar").and_return(volume)
19
- end
20
-
21
- mappings = {
22
- "/dev/sdf" => mock("attachment",
23
- :volume => mock("volume", :id => "v-foobar")),
24
- "/dev/sdg" => mock("attachment",
25
- :volume => mock("volume", :id => "v-deadbeef")),
26
- }
27
-
28
- instance.should_receive(:block_device_mappings).and_return(mappings)
29
-
30
- volume.should_receive(:detach_from).
31
- with(instance, "/dev/sdf").and_return(attachment)
32
-
33
- cloud.should_receive(:wait_resource).with(attachment, :detached)
34
-
35
- old_settings = {
36
- "foo" => "bar",
37
- "disks" => {
38
- "persistent" => {
39
- "v-foobar" => "/dev/sdf",
40
- "v-deadbeef" => "/dev/sdg"
41
- }
42
- }
43
- }
44
-
45
- new_settings = {
46
- "foo" => "bar",
47
- "disks" => {
48
- "persistent" => {
49
- "v-deadbeef" => "/dev/sdg"
50
- }
51
- }
52
- }
53
-
54
- @registry.should_receive(:read_settings).
55
- with("i-test").
56
- and_return(old_settings)
57
-
58
- @registry.should_receive(:update_settings).with("i-test", new_settings)
59
-
60
- cloud.detach_disk("i-test", "v-foobar")
61
- end
62
-
63
- end
@@ -1,64 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require File.expand_path("../../spec_helper", __FILE__)
4
-
5
- describe Bosh::AwsCloud::Helpers do
6
- it "should time out" do
7
- Bosh::Clouds::Config.stub(:task_checkpoint)
8
- cloud = mock_cloud
9
-
10
- resource = double("resource")
11
- resource.stub(:status).and_return(:start)
12
- cloud.stub(:sleep)
13
-
14
- expect {
15
- cloud.wait_resource(resource, :stop, :status, 0.1)
16
- }.to raise_error Bosh::Clouds::CloudError, /Timed out/
17
- end
18
-
19
- it "should not time out" do
20
- cloud = mock_cloud
21
-
22
- resource = double("resource")
23
- resource.stub(:status).and_return(:start, :stopping, :stopping, :stop)
24
- cloud.stub(:sleep)
25
-
26
- lambda {
27
- cloud.wait_resource(resource, :stop, :status, 0.1)
28
- }.should_not raise_error Bosh::Clouds::CloudError
29
- end
30
-
31
- it "should raise error when target state is wrong" do
32
- Bosh::Clouds::Config.stub(:task_checkpoint)
33
- cloud = mock_cloud
34
-
35
- resource = double("resource")
36
- resource.stub(:status).and_return(:started, :failed)
37
- cloud.stub(:sleep)
38
-
39
- expect {
40
- cloud.wait_resource(resource, :stopped, :status, 0.1)
41
- }.to raise_error Bosh::Clouds::CloudError, /is failed, expected stopped/
42
- end
43
-
44
- it "should swallow AWS::EC2::Errors::InvalidInstanceID::NotFound" do
45
- Bosh::Clouds::Config.stub(:task_checkpoint)
46
- cloud = mock_cloud
47
-
48
- resource = double("resource")
49
- return_values = [:raise, :raise, :raise, :start, :start, :stop]
50
- i = 0
51
- resource.stub(:status) do
52
- i += 1
53
- if return_values[i] == :raise
54
- raise AWS::EC2::Errors::InvalidInstanceID::NotFound
55
- end
56
- return_values[i]
57
- end
58
- cloud.stub(:sleep)
59
-
60
- #lambda {
61
- cloud.wait_resource(resource, :stop, :status, 0.1)
62
- #}.should_not raise_error AWS::EC2::Errors::InvalidInstanceID::NotFound
63
- end
64
- end
@@ -1,57 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require File.expand_path("../../spec_helper", __FILE__)
4
-
5
- describe Bosh::AwsCloud::NetworkConfigurator do
6
-
7
- def set_security_groups(spec, security_groups)
8
- spec["cloud_properties"] = {
9
- "security_groups" => security_groups
10
- }
11
- end
12
-
13
- it "should raise an error if the spec isn't a hash" do
14
- lambda {
15
- Bosh::AwsCloud::NetworkConfigurator.new("foo")
16
- }.should raise_error ArgumentError
17
- end
18
-
19
- describe "security groups" do
20
- it "should be extracted from both dynamic and vip network" do
21
- spec = {}
22
- spec["network_a"] = dynamic_network_spec
23
- set_security_groups(spec["network_a"], %w[foo])
24
- spec["network_b"] = vip_network_spec
25
- set_security_groups(spec["network_b"], %w[bar])
26
-
27
- nc = Bosh::AwsCloud::NetworkConfigurator.new(spec)
28
- nc.security_groups(nil).should == %w[bar foo]
29
- end
30
-
31
- it "should return the default groups if none are extracted" do
32
- spec = {}
33
- spec["network_a"] = {"type" => "dynamic"}
34
-
35
- nc = Bosh::AwsCloud::NetworkConfigurator.new(spec)
36
- nc.security_groups(%w[foo]).should == %w[foo]
37
- end
38
-
39
- it "should return an empty list if no default group is set" do
40
- spec = {}
41
- spec["network_a"] = {"type" => "dynamic"}
42
-
43
- nc = Bosh::AwsCloud::NetworkConfigurator.new(spec)
44
- nc.security_groups(nil).should == []
45
- end
46
-
47
- it "should raise an error when it isn't an array" do
48
- spec = {}
49
- spec["network_a"] = dynamic_network_spec
50
- set_security_groups(spec["network_a"], "foo")
51
-
52
- lambda {
53
- Bosh::AwsCloud::NetworkConfigurator.new(spec)
54
- }.should raise_error ArgumentError, "security groups must be an Array"
55
- end
56
- end
57
- end
@@ -1,38 +0,0 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
- require File.expand_path("../../spec_helper", __FILE__)
4
-
5
- describe Bosh::AwsCloud::Cloud do
6
-
7
- before :each do
8
- @instance = double("instance", :id => "i-foobar")
9
-
10
- @cloud = mock_cloud(mock_cloud_options) do |ec2|
11
- ec2.instances.stub(:[]).with("i-foobar").and_return(@instance)
12
- end
13
- end
14
-
15
- it "reboots an EC2 instance (CPI call picks soft reboot)" do
16
- @cloud.should_receive(:soft_reboot).with(@instance)
17
- @cloud.reboot_vm("i-foobar")
18
- end
19
-
20
- it "soft reboots an EC2 instance" do
21
- @instance.should_receive(:reboot)
22
- @cloud.send(:soft_reboot, @instance)
23
- end
24
-
25
- it "hard reboots an EC2 instance" do
26
- # N.B. This requires ebs-store instance
27
- @instance.should_receive(:stop).ordered
28
- @cloud.should_receive(:wait_resource).
29
- with(@instance, :stopped).ordered
30
-
31
- @instance.should_receive(:start)
32
- @cloud.should_receive(:wait_resource).ordered.
33
- with(@instance, :running)
34
-
35
- @cloud.send(:hard_reboot, @instance)
36
- end
37
-
38
- end