bosh_openstack_cpi 0.0.7 → 1.5.0.pre.1113
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -5
- data/USAGE.md +55 -27
- data/bin/bosh_openstack_console +2 -10
- data/lib/bosh_openstack_cpi.rb +1 -0
- data/lib/cloud/openstack.rb +7 -2
- data/lib/cloud/openstack/cloud.rb +345 -261
- data/lib/cloud/openstack/dynamic_network.rb +1 -0
- data/lib/cloud/openstack/helpers.rb +77 -19
- data/lib/cloud/openstack/manual_network.rb +35 -0
- data/lib/cloud/openstack/network.rb +1 -0
- data/lib/cloud/openstack/network_configurator.rb +76 -37
- data/lib/cloud/openstack/tag_manager.rb +17 -0
- data/lib/cloud/openstack/version.rb +2 -1
- data/lib/cloud/openstack/vip_network.rb +15 -12
- metadata +40 -75
- data/Rakefile +0 -62
- data/bosh_cpi.md +0 -82
- data/lib/cloud/openstack/registry_client.rb +0 -127
- data/spec/assets/sample_config.yml +0 -14
- data/spec/integration/cpi_test.rb +0 -119
- data/spec/spec_helper.rb +0 -146
- data/spec/unit/attach_disk_spec.rb +0 -111
- data/spec/unit/cloud_spec.rb +0 -31
- data/spec/unit/configure_networks_spec.rb +0 -106
- data/spec/unit/create_disk_spec.rb +0 -82
- data/spec/unit/create_stemcell_spec.rb +0 -315
- data/spec/unit/create_vm_spec.rb +0 -252
- data/spec/unit/delete_disk_spec.rb +0 -37
- data/spec/unit/delete_stemcell_spec.rb +0 -80
- data/spec/unit/delete_vm_spec.rb +0 -25
- data/spec/unit/detach_disk_spec.rb +0 -78
- data/spec/unit/helpers_spec.rb +0 -74
- data/spec/unit/network_configurator_spec.rb +0 -57
- data/spec/unit/reboot_vm_spec.rb +0 -32
- data/spec/unit/set_vm_metadata_spec.rb +0 -34
- data/spec/unit/validate_deployment_spec.rb +0 -17
@@ -1,82 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
it "creates an OpenStack volume" do
|
8
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
9
|
-
disk_params = {
|
10
|
-
:name => "volume-#{unique_name}",
|
11
|
-
:description => "",
|
12
|
-
:size => 2
|
13
|
-
}
|
14
|
-
volume = double("volume", :id => "v-foobar")
|
15
|
-
|
16
|
-
cloud = mock_cloud do |openstack|
|
17
|
-
openstack.volumes.should_receive(:create).
|
18
|
-
with(disk_params).and_return(volume)
|
19
|
-
end
|
20
|
-
|
21
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
22
|
-
cloud.should_receive(:wait_resource).with(volume, :available)
|
23
|
-
|
24
|
-
cloud.create_disk(2048).should == "v-foobar"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "rounds up disk size" do
|
28
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
29
|
-
disk_params = {
|
30
|
-
:name => "volume-#{unique_name}",
|
31
|
-
:description => "",
|
32
|
-
:size => 3
|
33
|
-
}
|
34
|
-
volume = double("volume", :id => "v-foobar")
|
35
|
-
|
36
|
-
cloud = mock_cloud do |openstack|
|
37
|
-
openstack.volumes.should_receive(:create).
|
38
|
-
with(disk_params).and_return(volume)
|
39
|
-
end
|
40
|
-
|
41
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
42
|
-
cloud.should_receive(:wait_resource).with(volume, :available)
|
43
|
-
|
44
|
-
cloud.create_disk(2049)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "check min and max disk size" do
|
48
|
-
expect {
|
49
|
-
mock_cloud.create_disk(100)
|
50
|
-
}.to raise_error(Bosh::Clouds::CloudError, /Minimum disk size is 1 GiB/)
|
51
|
-
|
52
|
-
expect {
|
53
|
-
mock_cloud.create_disk(2000 * 1024)
|
54
|
-
}.to raise_error(Bosh::Clouds::CloudError, /Maximum disk size is 1 TiB/)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "puts disk in the same AZ as a server" do
|
58
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
59
|
-
disk_params = {
|
60
|
-
:name => "volume-#{unique_name}",
|
61
|
-
:description => "",
|
62
|
-
:size => 1,
|
63
|
-
:availability_zone => "foobar-land"
|
64
|
-
}
|
65
|
-
server = double("server", :id => "i-test",
|
66
|
-
:availability_zone => "foobar-land")
|
67
|
-
volume = double("volume", :id => "v-foobar")
|
68
|
-
|
69
|
-
cloud = mock_cloud do |openstack|
|
70
|
-
openstack.servers.should_receive(:get).
|
71
|
-
with("i-test").and_return(server)
|
72
|
-
openstack.volumes.should_receive(:create).
|
73
|
-
with(disk_params).and_return(volume)
|
74
|
-
end
|
75
|
-
|
76
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
77
|
-
cloud.should_receive(:wait_resource).with(volume, :available)
|
78
|
-
|
79
|
-
cloud.create_disk(1024, "i-test")
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
@@ -1,315 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
@tmp_dir = Dir.mktmpdir
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "Image upload based flow" do
|
12
|
-
|
13
|
-
it "creates stemcell using an image without kernel nor ramdisk" do
|
14
|
-
image = double("image", :id => "i-bar", :name => "i-bar")
|
15
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
16
|
-
image_params = {
|
17
|
-
:name => "BOSH-#{unique_name}",
|
18
|
-
:disk_format => "ami",
|
19
|
-
:container_format => "ami",
|
20
|
-
:location => "#{@tmp_dir}/root.img",
|
21
|
-
:is_public => true
|
22
|
-
}
|
23
|
-
|
24
|
-
cloud = mock_glance do |glance|
|
25
|
-
glance.images.should_receive(:create).
|
26
|
-
with(image_params).and_return(image)
|
27
|
-
end
|
28
|
-
|
29
|
-
Dir.should_receive(:mktmpdir).and_yield(@tmp_dir)
|
30
|
-
cloud.should_receive(:unpack_image).with(@tmp_dir, "/tmp/foo")
|
31
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
32
|
-
|
33
|
-
sc_id = cloud.create_stemcell("/tmp/foo", {
|
34
|
-
"container_format" => "ami",
|
35
|
-
"disk_format" => "ami"
|
36
|
-
})
|
37
|
-
|
38
|
-
sc_id.should == "i-bar"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "creates stemcell using an image with kernel and ramdisk id's" do
|
42
|
-
image = double("image", :id => "i-bar", :name => "i-bar")
|
43
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
44
|
-
image_params = {
|
45
|
-
:name => "BOSH-#{unique_name}",
|
46
|
-
:disk_format => "ami",
|
47
|
-
:container_format => "ami",
|
48
|
-
:location => "#{@tmp_dir}/root.img",
|
49
|
-
:is_public => true,
|
50
|
-
:properties => {
|
51
|
-
:kernel_id => "k-id",
|
52
|
-
:ramdisk_id => "r-id",
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
cloud = mock_glance do |glance|
|
57
|
-
glance.images.should_receive(:create).
|
58
|
-
with(image_params).and_return(image)
|
59
|
-
end
|
60
|
-
|
61
|
-
Dir.should_receive(:mktmpdir).and_yield(@tmp_dir)
|
62
|
-
cloud.should_receive(:unpack_image).with(@tmp_dir, "/tmp/foo")
|
63
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
64
|
-
|
65
|
-
sc_id = cloud.create_stemcell("/tmp/foo", {
|
66
|
-
"container_format" => "ami",
|
67
|
-
"disk_format" => "ami",
|
68
|
-
"kernel_id" => "k-id",
|
69
|
-
"ramdisk_id" => "r-id",
|
70
|
-
"kernel_file" => "kernel.img",
|
71
|
-
"ramdisk_file" => "initrd.img"
|
72
|
-
})
|
73
|
-
|
74
|
-
sc_id.should == "i-bar"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "creates stemcell using an image with kernel and ramdisk files" do
|
78
|
-
image = double("image", :id => "i-bar", :name => "i-bar")
|
79
|
-
kernel = double("image", :id => "k-img-id", :name => "k-img-id")
|
80
|
-
ramdisk = double("image", :id => "r-img-id", :name => "r-img-id")
|
81
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
82
|
-
kernel_params = {
|
83
|
-
:name => "BOSH-#{unique_name}-AKI",
|
84
|
-
:disk_format => "aki",
|
85
|
-
:container_format => "aki",
|
86
|
-
:location => "#{@tmp_dir}/kernel.img",
|
87
|
-
:properties => {
|
88
|
-
:stemcell => "BOSH-#{unique_name}",
|
89
|
-
}
|
90
|
-
}
|
91
|
-
ramdisk_params = {
|
92
|
-
:name => "BOSH-#{unique_name}-ARI",
|
93
|
-
:disk_format => "ari",
|
94
|
-
:container_format => "ari",
|
95
|
-
:location => "#{@tmp_dir}/initrd.img",
|
96
|
-
:properties => {
|
97
|
-
:stemcell => "BOSH-#{unique_name}",
|
98
|
-
}
|
99
|
-
}
|
100
|
-
image_params = {
|
101
|
-
:name => "BOSH-#{unique_name}",
|
102
|
-
:disk_format => "ami",
|
103
|
-
:container_format => "ami",
|
104
|
-
:location => "#{@tmp_dir}/root.img",
|
105
|
-
:is_public => true,
|
106
|
-
:properties => {
|
107
|
-
:kernel_id => "k-img-id",
|
108
|
-
:ramdisk_id => "r-img-id",
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
cloud = mock_glance do |glance|
|
113
|
-
glance.images.should_receive(:create).
|
114
|
-
with(kernel_params).and_return(kernel)
|
115
|
-
glance.images.should_receive(:create).
|
116
|
-
with(ramdisk_params).and_return(ramdisk)
|
117
|
-
glance.images.should_receive(:create).
|
118
|
-
with(image_params).and_return(image)
|
119
|
-
end
|
120
|
-
|
121
|
-
Dir.should_receive(:mktmpdir).and_yield(@tmp_dir)
|
122
|
-
cloud.should_receive(:unpack_image).with(@tmp_dir, "/tmp/foo")
|
123
|
-
File.stub(:exists?).and_return(true)
|
124
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
125
|
-
|
126
|
-
sc_id = cloud.create_stemcell("/tmp/foo", {
|
127
|
-
"container_format" => "ami",
|
128
|
-
"disk_format" => "ami",
|
129
|
-
"kernel_file" => "kernel.img",
|
130
|
-
"ramdisk_file" => "initrd.img"
|
131
|
-
})
|
132
|
-
|
133
|
-
sc_id.should == "i-bar"
|
134
|
-
end
|
135
|
-
|
136
|
-
it "sets image properies from cloud_properties" do
|
137
|
-
image = double("image", :id => "i-bar", :name => "i-bar")
|
138
|
-
kernel = double("image", :id => "k-img-id", :name => "k-img-id")
|
139
|
-
ramdisk = double("image", :id => "r-img-id", :name => "r-img-id")
|
140
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
141
|
-
kernel_params = {
|
142
|
-
:name => "BOSH-#{unique_name}-AKI",
|
143
|
-
:disk_format => "aki",
|
144
|
-
:container_format => "aki",
|
145
|
-
:location => "#{@tmp_dir}/kernel.img",
|
146
|
-
:properties => {
|
147
|
-
:stemcell => "BOSH-#{unique_name}",
|
148
|
-
}
|
149
|
-
}
|
150
|
-
ramdisk_params = {
|
151
|
-
:name => "BOSH-#{unique_name}-ARI",
|
152
|
-
:disk_format => "ari",
|
153
|
-
:container_format => "ari",
|
154
|
-
:location => "#{@tmp_dir}/initrd.img",
|
155
|
-
:properties => {
|
156
|
-
:stemcell => "BOSH-#{unique_name}",
|
157
|
-
}
|
158
|
-
}
|
159
|
-
image_params = {
|
160
|
-
:name => "BOSH-#{unique_name}",
|
161
|
-
:disk_format => "ami",
|
162
|
-
:container_format => "ami",
|
163
|
-
:location => "#{@tmp_dir}/root.img",
|
164
|
-
:is_public => true,
|
165
|
-
:properties => {
|
166
|
-
:kernel_id => "k-img-id",
|
167
|
-
:ramdisk_id => "r-img-id",
|
168
|
-
:stemcell_name => "bosh-stemcell",
|
169
|
-
:stemcell_version => "x.y.z"
|
170
|
-
}
|
171
|
-
}
|
172
|
-
|
173
|
-
cloud = mock_glance do |glance|
|
174
|
-
glance.images.should_receive(:create).
|
175
|
-
with(kernel_params).and_return(kernel)
|
176
|
-
glance.images.should_receive(:create).
|
177
|
-
with(ramdisk_params).and_return(ramdisk)
|
178
|
-
glance.images.should_receive(:create).
|
179
|
-
with(image_params).and_return(image)
|
180
|
-
end
|
181
|
-
|
182
|
-
Dir.should_receive(:mktmpdir).and_yield(@tmp_dir)
|
183
|
-
cloud.should_receive(:unpack_image).with(@tmp_dir, "/tmp/foo")
|
184
|
-
File.stub(:exists?).and_return(true)
|
185
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
186
|
-
|
187
|
-
sc_id = cloud.create_stemcell("/tmp/foo", {
|
188
|
-
"name" => "bosh-stemcell",
|
189
|
-
"version" => "x.y.z",
|
190
|
-
"container_format" => "ami",
|
191
|
-
"disk_format" => "ami",
|
192
|
-
"kernel_file" => "kernel.img",
|
193
|
-
"ramdisk_file" => "initrd.img"
|
194
|
-
})
|
195
|
-
|
196
|
-
sc_id.should == "i-bar"
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should throw an error for non existent root image in stemcell archive" do
|
200
|
-
begin
|
201
|
-
dir = Dir.mkdir("tmp")
|
202
|
-
Dir.chdir 'tmp'
|
203
|
-
|
204
|
-
kernel_img = File.new('kernel.img', 'w')
|
205
|
-
ramdisk_img = File.new('initrd.img', 'w')
|
206
|
-
|
207
|
-
tgz = Zlib::GzipWriter.new(File.open('stemcell.tgz', 'wb'))
|
208
|
-
array = ['kernel.img']
|
209
|
-
|
210
|
-
Minitar.pack(array, tgz)
|
211
|
-
|
212
|
-
cloud = mock_glance
|
213
|
-
error_expected = "Root image is missing from stemcell archive"
|
214
|
-
error_actual = ""
|
215
|
-
begin
|
216
|
-
cloud.create_stemcell("./stemcell.tgz", {
|
217
|
-
"name" => "bosh-stemcell",
|
218
|
-
"version" => "x.y.z",
|
219
|
-
"container_format" => "ami",
|
220
|
-
"disk_format" => "ami",
|
221
|
-
"kernel_file" => "kernel.img",
|
222
|
-
"ramdisk_file" => "initrd.img"
|
223
|
-
})
|
224
|
-
rescue Bosh::Clouds::CloudError => e
|
225
|
-
error_actual = e.to_s
|
226
|
-
end
|
227
|
-
error_actual.should eq(error_expected)
|
228
|
-
ensure
|
229
|
-
File.delete('kernel.img')
|
230
|
-
File.delete('initrd.img')
|
231
|
-
File.delete('stemcell.tgz')
|
232
|
-
Dir.chdir '..'
|
233
|
-
Dir.delete('tmp')
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should throw an error for non existent kernel image in stemcell archive" do
|
238
|
-
begin
|
239
|
-
dir = Dir.mkdir("tmp")
|
240
|
-
Dir.chdir 'tmp'
|
241
|
-
root_img = File.new('root.img','w')
|
242
|
-
if root_img
|
243
|
-
root_img.syswrite("ABCDEF")
|
244
|
-
end
|
245
|
-
ramdisk_img = File.new('initrd.img', 'w')
|
246
|
-
|
247
|
-
tgz = Zlib::GzipWriter.new(File.open('stemcell.tgz', 'wb'))
|
248
|
-
array = ['root.img']
|
249
|
-
|
250
|
-
Minitar.pack(array, tgz)
|
251
|
-
|
252
|
-
cloud = mock_glance
|
253
|
-
error_expected = "Kernel image kernel.img is missing from stemcell archive"
|
254
|
-
error_actual = ""
|
255
|
-
begin
|
256
|
-
cloud.create_stemcell("./stemcell.tgz", {
|
257
|
-
"name" => "bosh-stemcell",
|
258
|
-
"version" => "x.y.z",
|
259
|
-
"container_format" => "ami",
|
260
|
-
"disk_format" => "ami",
|
261
|
-
"kernel_file" => "kernel.img",
|
262
|
-
"ramdisk_file" => "initrd.img"
|
263
|
-
})
|
264
|
-
rescue Bosh::Clouds::CloudError => e
|
265
|
-
error_actual = e.to_s
|
266
|
-
end
|
267
|
-
error_actual.should eq(error_expected)
|
268
|
-
ensure
|
269
|
-
File.delete('root.img')
|
270
|
-
File.delete('initrd.img')
|
271
|
-
File.delete('stemcell.tgz')
|
272
|
-
Dir.chdir '..'
|
273
|
-
Dir.delete('tmp')
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
it "should throw an error for non existent ramdisk image in stemcell archive" do
|
278
|
-
begin
|
279
|
-
dir = Dir.mkdir("tmp")
|
280
|
-
Dir.chdir 'tmp'
|
281
|
-
root_img = File.new('root.img','w')
|
282
|
-
if root_img
|
283
|
-
root_img.syswrite("ABCDEF")
|
284
|
-
end
|
285
|
-
|
286
|
-
tgz = Zlib::GzipWriter.new(File.open('stemcell.tgz', 'wb'))
|
287
|
-
array = ['root.img']
|
288
|
-
|
289
|
-
Minitar.pack(array, tgz)
|
290
|
-
|
291
|
-
cloud = mock_glance
|
292
|
-
error_expected = "Ramdisk image initrd.img is missing from stemcell archive"
|
293
|
-
error_actual = ""
|
294
|
-
begin
|
295
|
-
cloud.create_stemcell("./stemcell.tgz", {
|
296
|
-
"name" => "bosh-stemcell",
|
297
|
-
"version" => "x.y.z",
|
298
|
-
"container_format" => "ami",
|
299
|
-
"disk_format" => "ami",
|
300
|
-
#"kernel_file" => "kernel.img",
|
301
|
-
"ramdisk_file" => "initrd.img"
|
302
|
-
})
|
303
|
-
rescue Bosh::Clouds::CloudError => e
|
304
|
-
error_actual = e.to_s
|
305
|
-
end
|
306
|
-
error_actual.should eq(error_expected)
|
307
|
-
ensure
|
308
|
-
File.delete('root.img')
|
309
|
-
File.delete('stemcell.tgz')
|
310
|
-
Dir.chdir '..'
|
311
|
-
Dir.delete('tmp')
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
data/spec/unit/create_vm_spec.rb
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::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/vda",
|
16
|
-
"ephemeral" => "/dev/vdb",
|
17
|
-
"persistent" => {}
|
18
|
-
},
|
19
|
-
"env" => {
|
20
|
-
"test_env" => "value"
|
21
|
-
},
|
22
|
-
"foo" => "bar", # Agent env
|
23
|
-
"baz" => "zaz"
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
def openstack_params(unique_name, user_data, security_groups=[])
|
28
|
-
{
|
29
|
-
:name => "vm-#{unique_name}",
|
30
|
-
:image_ref => "sc-id",
|
31
|
-
:flavor_ref => "f-test",
|
32
|
-
:key_name => "test_key",
|
33
|
-
:security_groups => security_groups,
|
34
|
-
:user_data => Yajl::Encoder.encode(user_data),
|
35
|
-
:availability_zone => "foobar-1a"
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
before(:each) do
|
40
|
-
@registry = mock_registry
|
41
|
-
end
|
42
|
-
|
43
|
-
it "creates an OpenStack server and polls until it's ready" do
|
44
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
45
|
-
user_data = {
|
46
|
-
"registry" => {
|
47
|
-
"endpoint" => "http://registry:3333"
|
48
|
-
},
|
49
|
-
"server" => {
|
50
|
-
"name" => "vm-#{unique_name}"
|
51
|
-
}
|
52
|
-
}
|
53
|
-
server = double("server", :id => "i-test", :name => "i-test")
|
54
|
-
image = double("image", :id => "sc-id", :name => "sc-id")
|
55
|
-
flavor = double("flavor", :id => "f-test", :name => "m1.tiny")
|
56
|
-
address = double("address", :id => "a-test", :ip => "10.0.0.1",
|
57
|
-
:instance_id => "i-test")
|
58
|
-
|
59
|
-
cloud = mock_cloud do |openstack|
|
60
|
-
openstack.servers.should_receive(:create).
|
61
|
-
with(openstack_params(unique_name, user_data, %w[default])).
|
62
|
-
and_return(server)
|
63
|
-
openstack.images.should_receive(:find).and_return(image)
|
64
|
-
openstack.flavors.should_receive(:find).and_return(flavor)
|
65
|
-
openstack.addresses.should_receive(:each).and_yield(address)
|
66
|
-
end
|
67
|
-
|
68
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
69
|
-
address.should_receive(:server=).with(nil)
|
70
|
-
cloud.should_receive(:wait_resource).with(server, :active, :state)
|
71
|
-
|
72
|
-
@registry.should_receive(:update_settings).
|
73
|
-
with("i-test", agent_settings(unique_name))
|
74
|
-
|
75
|
-
vm_id = cloud.create_vm("agent-id", "sc-id",
|
76
|
-
resource_pool_spec,
|
77
|
-
{ "network_a" => dynamic_network_spec },
|
78
|
-
nil, { "test_env" => "value" })
|
79
|
-
vm_id.should == "i-test"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "passes dns servers in server user data when present" do
|
83
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
84
|
-
|
85
|
-
user_data = {
|
86
|
-
"registry" => {
|
87
|
-
"endpoint" => "http://registry:3333"
|
88
|
-
},
|
89
|
-
"server" => {
|
90
|
-
"name" => "vm-#{unique_name}"
|
91
|
-
},
|
92
|
-
"dns" => {
|
93
|
-
"nameserver" => ["1.2.3.4"]
|
94
|
-
}
|
95
|
-
}
|
96
|
-
server = double("server", :id => "i-test", :name => "i-test")
|
97
|
-
image = double("image", :id => "sc-id", :name => "sc-id")
|
98
|
-
flavor = double("flavor", :id => "f-test", :name => "m1.tiny")
|
99
|
-
address = double("address", :id => "a-test", :ip => "10.0.0.1",
|
100
|
-
:instance_id => "i-test")
|
101
|
-
network_spec = dynamic_network_spec
|
102
|
-
network_spec["dns"] = ["1.2.3.4"]
|
103
|
-
|
104
|
-
cloud = mock_cloud do |openstack|
|
105
|
-
openstack.servers.should_receive(:create).
|
106
|
-
with(openstack_params(unique_name, user_data, %w[default])).
|
107
|
-
and_return(server)
|
108
|
-
openstack.images.should_receive(:find).and_return(image)
|
109
|
-
openstack.flavors.should_receive(:find).and_return(flavor)
|
110
|
-
openstack.addresses.should_receive(:each).and_yield(address)
|
111
|
-
end
|
112
|
-
|
113
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
114
|
-
address.should_receive(:server=).with(nil)
|
115
|
-
cloud.should_receive(:wait_resource).with(server, :active, :state)
|
116
|
-
|
117
|
-
@registry.should_receive(:update_settings).
|
118
|
-
with("i-test", agent_settings(unique_name, network_spec))
|
119
|
-
|
120
|
-
vm_id = cloud.create_vm("agent-id", "sc-id",
|
121
|
-
resource_pool_spec,
|
122
|
-
{ "network_a" => network_spec },
|
123
|
-
nil, { "test_env" => "value" })
|
124
|
-
vm_id.should == "i-test"
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
it "creates an OpenStack server with security group" do
|
129
|
-
unique_name = UUIDTools::UUID.random_create.to_s
|
130
|
-
user_data = {
|
131
|
-
"registry" => {
|
132
|
-
"endpoint" => "http://registry:3333"
|
133
|
-
},
|
134
|
-
"server" => {
|
135
|
-
"name" => "vm-#{unique_name}"
|
136
|
-
}
|
137
|
-
}
|
138
|
-
security_groups = %w[bar foo]
|
139
|
-
network_spec = dynamic_network_spec
|
140
|
-
network_spec["cloud_properties"] = { "security_groups" => security_groups }
|
141
|
-
server = double("server", :id => "i-test", :name => "i-test")
|
142
|
-
image = double("image", :id => "sc-id", :name => "sc-id")
|
143
|
-
flavor = double("flavor", :id => "f-test", :name => "m1.tiny")
|
144
|
-
address = double("address", :id => "a-test", :ip => "10.0.0.1",
|
145
|
-
:instance_id => nil)
|
146
|
-
|
147
|
-
cloud = mock_cloud do |openstack|
|
148
|
-
openstack.servers.should_receive(:create).
|
149
|
-
with(openstack_params(unique_name, user_data, security_groups)).
|
150
|
-
and_return(server)
|
151
|
-
openstack.images.should_receive(:find).and_return(image)
|
152
|
-
openstack.flavors.should_receive(:find).and_return(flavor)
|
153
|
-
openstack.addresses.should_receive(:each).and_yield(address)
|
154
|
-
end
|
155
|
-
|
156
|
-
cloud.should_receive(:generate_unique_name).and_return(unique_name)
|
157
|
-
cloud.should_receive(:wait_resource).with(server, :active, :state)
|
158
|
-
|
159
|
-
@registry.should_receive(:update_settings).
|
160
|
-
with("i-test", agent_settings(unique_name, network_spec))
|
161
|
-
|
162
|
-
vm_id = cloud.create_vm("agent-id", "sc-id",
|
163
|
-
resource_pool_spec,
|
164
|
-
{ "network_a" => network_spec },
|
165
|
-
nil, { "test_env" => "value" })
|
166
|
-
vm_id.should == "i-test"
|
167
|
-
end
|
168
|
-
|
169
|
-
it "associates server with floating ip if vip network is provided" do
|
170
|
-
server = double("server", :id => "i-test", :name => "i-test")
|
171
|
-
image = double("image", :id => "sc-id", :name => "sc-id")
|
172
|
-
flavor = double("flavor", :id => "f-test", :name => "m1.tiny")
|
173
|
-
address = double("address", :id => "a-test", :ip => "10.0.0.1",
|
174
|
-
:instance_id => "i-test")
|
175
|
-
|
176
|
-
cloud = mock_cloud do |openstack|
|
177
|
-
openstack.servers.should_receive(:create).and_return(server)
|
178
|
-
openstack.images.should_receive(:find).and_return(image)
|
179
|
-
openstack.flavors.should_receive(:find).and_return(flavor)
|
180
|
-
openstack.addresses.should_receive(:find).and_return(address)
|
181
|
-
end
|
182
|
-
|
183
|
-
address.should_receive(:server=).with(nil)
|
184
|
-
address.should_receive(:server=).with(server)
|
185
|
-
cloud.should_receive(:wait_resource).with(server, :active, :state)
|
186
|
-
|
187
|
-
@registry.should_receive(:update_settings)
|
188
|
-
|
189
|
-
vm_id = cloud.create_vm("agent-id", "sc-id",
|
190
|
-
resource_pool_spec,
|
191
|
-
combined_network_spec)
|
192
|
-
end
|
193
|
-
|
194
|
-
def volume(zone)
|
195
|
-
vol = double("volume")
|
196
|
-
vol.stub(:availability_zone).and_return(zone)
|
197
|
-
vol
|
198
|
-
end
|
199
|
-
|
200
|
-
describe "#select_availability_zone" do
|
201
|
-
it "should return nil when all values are nil" do
|
202
|
-
cloud = mock_cloud
|
203
|
-
cloud.select_availability_zone(nil, nil).should == nil
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should select the resource pool availability_zone when disks are nil" do
|
207
|
-
cloud = mock_cloud
|
208
|
-
cloud.select_availability_zone(nil, "foobar-1a").should == "foobar-1a"
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should select the zone from a list of disks" do
|
212
|
-
cloud = mock_cloud do |openstack|
|
213
|
-
openstack.volumes.stub(:get).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 |openstack|
|
220
|
-
openstack.volumes.stub(:get).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
|
-
expect {
|
230
|
-
cloud.ensure_same_availability_zone([volume("foo"), volume("bar")],
|
231
|
-
nil)
|
232
|
-
}.to raise_error Bosh::Clouds::CloudError
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should raise an error when the zones differ" do
|
236
|
-
cloud = mock_cloud
|
237
|
-
expect {
|
238
|
-
cloud.ensure_same_availability_zone([volume("foo"), volume("bar")],
|
239
|
-
"foo")
|
240
|
-
}.to raise_error Bosh::Clouds::CloudError
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should raise an error when the zones differ" do
|
244
|
-
cloud = mock_cloud
|
245
|
-
expect {
|
246
|
-
cloud.ensure_same_availability_zone([volume("foo"), volume("foo")],
|
247
|
-
"bar")
|
248
|
-
}.to raise_error Bosh::Clouds::CloudError
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
end
|