kitchen-ec2 0.10.0 → 1.0.0.beta.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.
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for EC2 Test Kitchen driver
24
- EC2_VERSION = "0.10.0"
24
+ EC2_VERSION = "1.0.0.beta.1"
25
25
  end
26
26
  end
@@ -57,22 +57,6 @@ describe Kitchen::Driver::Aws::Client do
57
57
  end
58
58
  end
59
59
 
60
- it "loads deprecated credentials fourth to last" do
61
- expect(shared).to_not receive(:loadable?)
62
- ClimateControl.modify(
63
- "AWS_ACCESS_KEY" => "key2",
64
- "AWS_SECRET_KEY" => "value2",
65
- "AWS_TOKEN" => "token2"
66
- ) do
67
- expect(Kitchen::Driver::Aws::Client.get_credentials("profile", nil, nil, nil)).to \
68
- be_a(Aws::Credentials).and have_attributes(
69
- :access_key_id => "key2",
70
- :secret_access_key => "value2",
71
- :session_token => "token2"
72
- )
73
- end
74
- end
75
-
76
60
  it "loads provided credentials first" do
77
61
  expect(shared).to_not receive(:loadable?)
78
62
  expect(Kitchen::Driver::Aws::Client.get_credentials("profile", "key3", "value3", nil)).to \
@@ -115,7 +99,8 @@ describe Kitchen::Driver::Aws::Client do
115
99
  "access_key_id",
116
100
  "secret_access_key",
117
101
  "session_token",
118
- "http_proxy"
102
+ "http_proxy",
103
+ 999
119
104
  )
120
105
  }
121
106
  let(:creds) { double("creds") }
@@ -125,6 +110,7 @@ describe Kitchen::Driver::Aws::Client do
125
110
  expect(Aws.config[:region]).to eq("us-west-1")
126
111
  expect(Aws.config[:credentials]).to eq(creds)
127
112
  expect(Aws.config[:http_proxy]).to eq("http_proxy")
113
+ expect(Aws.config[:retry_limit]).to eq(999)
128
114
  end
129
115
  end
130
116
  end
@@ -0,0 +1,350 @@
1
+ require "kitchen/driver/ec2"
2
+ require "kitchen/provisioner/dummy"
3
+ require "kitchen/transport/dummy"
4
+ require "kitchen/verifier/dummy"
5
+
6
+ describe "Default images for various platforms" do
7
+
8
+ class FakeImage
9
+ def self.next_ami
10
+ @n ||= 0
11
+ @n += 1
12
+ [sprintf("ami-%08x", @n), Time.now + @n]
13
+ end
14
+
15
+ def initialize(name: "foo")
16
+ @id, @creation_date = FakeImage.next_ami
17
+ @name = name
18
+ @creation_date = @creation_date.strftime("%F %T")
19
+ @architecture = :x86_64
20
+ @volume_type = "gp2"
21
+ @root_device_type = "ebs"
22
+ @virtualization_type = "hvm"
23
+ @root_device_name = "root"
24
+ @device_name = "root"
25
+ end
26
+ attr_reader :id
27
+ attr_reader :name
28
+ attr_reader :creation_date
29
+ attr_reader :architecture
30
+ attr_reader :volume_type
31
+ attr_reader :root_device_type
32
+ attr_reader :virtualization_type
33
+ attr_reader :root_device_name
34
+ attr_reader :device_name
35
+
36
+ def block_device_mappings
37
+ [self]
38
+ end
39
+
40
+ def ebs
41
+ self
42
+ end
43
+ end
44
+
45
+ let(:driver) do
46
+ Kitchen::Driver::Ec2.new(:region => "us-west-2", :aws_ssh_key_id => "foo", **config)
47
+ end
48
+ let(:config) { {} }
49
+ def new_instance(platform_name: "blarghle")
50
+ Kitchen::Instance.new(
51
+ :driver => driver,
52
+ :suite => Kitchen::Suite.new(:name => "suite-name"),
53
+ :platform => Kitchen::Platform.new(:name => platform_name),
54
+ :provisioner => Kitchen::Provisioner::Dummy.new,
55
+ :transport => Kitchen::Transport::Dummy.new,
56
+ :verifier => Kitchen::Verifier::Dummy.new,
57
+ :state_file => Kitchen::StateFile.new("/nonexistent", "suite-name-#{platform_name}")
58
+ )
59
+ end
60
+
61
+ PLATFORM_SEARCHES = {
62
+ "centos" => [
63
+ { :name => "owner-alias", :values => %w[aws-marketplace] },
64
+ { :name => "name", :values => ["CentOS Linux *", "CentOS-*-GA-*"] }
65
+ ],
66
+ "centos-7" => [
67
+ { :name => "owner-alias", :values => %w[aws-marketplace] },
68
+ { :name => "name", :values => ["CentOS Linux 7*", "CentOS-7*-GA-*"] }
69
+ ],
70
+ "centos-6" => [
71
+ { :name => "owner-alias", :values => %w[aws-marketplace] },
72
+ { :name => "name", :values => ["CentOS Linux 6*", "CentOS-6*-GA-*"] }
73
+ ],
74
+ "centos-6.3" => [
75
+ { :name => "owner-alias", :values => %w[aws-marketplace] },
76
+ { :name => "name", :values => ["CentOS Linux 6.3*", "CentOS-6.3*-GA-*"] }
77
+ ],
78
+ "centos-x86_64" => [
79
+ { :name => "owner-alias", :values => %w[aws-marketplace] },
80
+ { :name => "name", :values => ["CentOS Linux *", "CentOS-*-GA-*"] },
81
+ { :name => "architecture", :values => %w[x86_64] }
82
+ ],
83
+ "centos-6.3-x86_64" => [
84
+ { :name => "owner-alias", :values => %w[aws-marketplace] },
85
+ { :name => "name", :values => ["CentOS Linux 6.3*", "CentOS-6.3*-GA-*"] },
86
+ { :name => "architecture", :values => %w[x86_64] }
87
+ ],
88
+ "centos-7-x86_64" => [
89
+ { :name => "owner-alias", :values => %w[aws-marketplace] },
90
+ { :name => "name", :values => ["CentOS Linux 7*", "CentOS-7*-GA-*"] },
91
+ { :name => "architecture", :values => %w[x86_64] }
92
+ ],
93
+
94
+ "debian" => [
95
+ { :name => "owner-id", :values => %w[379101102735] },
96
+ { :name => "name", :values => %w[debian-jessie-*] }
97
+ ],
98
+ "debian-8" => [
99
+ { :name => "owner-id", :values => %w[379101102735] },
100
+ { :name => "name", :values => %w[debian-jessie-*] }
101
+ ],
102
+ "debian-7" => [
103
+ { :name => "owner-id", :values => %w[379101102735] },
104
+ { :name => "name", :values => %w[debian-wheezy-*] }
105
+ ],
106
+ "debian-6" => [
107
+ { :name => "owner-id", :values => %w[379101102735] },
108
+ { :name => "name", :values => %w[debian-squeeze-*] }
109
+ ],
110
+ "debian-x86_64" => [
111
+ { :name => "owner-id", :values => %w[379101102735] },
112
+ { :name => "name", :values => %w[debian-jessie-*] },
113
+ { :name => "architecture", :values => %w[x86_64] }
114
+ ],
115
+ "debian-6-x86_64" => [
116
+ { :name => "owner-id", :values => %w[379101102735] },
117
+ { :name => "name", :values => %w[debian-squeeze-*] },
118
+ { :name => "architecture", :values => %w[x86_64] }
119
+ ],
120
+
121
+ "rhel" => [
122
+ { :name => "owner-id", :values => %w[309956199498] },
123
+ { :name => "name", :values => %w[RHEL-*] }
124
+ ],
125
+ "rhel-6" => [
126
+ { :name => "owner-id", :values => %w[309956199498] },
127
+ { :name => "name", :values => %w[RHEL-6*] }
128
+ ],
129
+ "rhel-7.1" => [
130
+ { :name => "owner-id", :values => %w[309956199498] },
131
+ { :name => "name", :values => %w[RHEL-7.1*] }
132
+ ],
133
+ "rhel-x86_64" => [
134
+ { :name => "owner-id", :values => %w[309956199498] },
135
+ { :name => "name", :values => %w[RHEL-*] },
136
+ { :name => "architecture", :values => %w[x86_64] }
137
+ ],
138
+ "rhel-6-x86_64" => [
139
+ { :name => "owner-id", :values => %w[309956199498] },
140
+ { :name => "name", :values => %w[RHEL-6*] },
141
+ { :name => "architecture", :values => %w[x86_64] }
142
+ ],
143
+ "el" => [
144
+ { :name => "owner-id", :values => %w[309956199498] },
145
+ { :name => "name", :values => %w[RHEL-*] }
146
+ ],
147
+ "el-6-x86_64" => [
148
+ { :name => "owner-id", :values => %w[309956199498] },
149
+ { :name => "name", :values => %w[RHEL-6*] },
150
+ { :name => "architecture", :values => %w[x86_64] }
151
+ ],
152
+
153
+ "fedora" => [
154
+ { :name => "owner-id", :values => %w[125523088429] },
155
+ { :name => "name", :values => %w[Fedora-Cloud-Base-*] }
156
+ ],
157
+ "fedora-22" => [
158
+ { :name => "owner-id", :values => %w[125523088429] },
159
+ { :name => "name", :values => %w[Fedora-Cloud-Base-22-*] }
160
+ ],
161
+ "fedora-x86_64" => [
162
+ { :name => "owner-id", :values => %w[125523088429] },
163
+ { :name => "name", :values => %w[Fedora-Cloud-Base-*] },
164
+ { :name => "architecture", :values => %w[x86_64] }
165
+ ],
166
+ "fedora-22-x86_64" => [
167
+ { :name => "owner-id", :values => %w[125523088429] },
168
+ { :name => "name", :values => %w[Fedora-Cloud-Base-22-*] },
169
+ { :name => "architecture", :values => %w[x86_64] }
170
+ ],
171
+
172
+ "freebsd" => [
173
+ { :name => "owner-id", :values => %w[118940168514] },
174
+ { :name => "name", :values => ["FreeBSD *-RELEASE*", "FreeBSD/EC2 *-RELEASE*"] }
175
+ ],
176
+ "freebsd-10" => [
177
+ { :name => "owner-id", :values => %w[118940168514] },
178
+ { :name => "name", :values => ["FreeBSD 10*-RELEASE*", "FreeBSD/EC2 10*-RELEASE*"] }
179
+ ],
180
+ "freebsd-10.1" => [
181
+ { :name => "owner-id", :values => %w[118940168514] },
182
+ { :name => "name", :values => ["FreeBSD 10.1*-RELEASE*", "FreeBSD/EC2 10.1*-RELEASE*"] }
183
+ ],
184
+ "freebsd-x86_64" => [
185
+ { :name => "owner-id", :values => %w[118940168514] },
186
+ { :name => "name", :values => ["FreeBSD *-RELEASE*", "FreeBSD/EC2 *-RELEASE*"] },
187
+ { :name => "architecture", :values => %w[x86_64] }
188
+ ],
189
+ "freebsd-10-x86_64" => [
190
+ { :name => "owner-id", :values => %w[118940168514] },
191
+ { :name => "name", :values => ["FreeBSD 10*-RELEASE*", "FreeBSD/EC2 10*-RELEASE*"] },
192
+ { :name => "architecture", :values => %w[x86_64] }
193
+ ],
194
+
195
+ "ubuntu" => [
196
+ { :name => "owner-id", :values => %w[099720109477] },
197
+ { :name => "name", :values => %w[ubuntu/images/*/ubuntu-*-*] }
198
+ ],
199
+ "ubuntu-14" => [
200
+ { :name => "owner-id", :values => %w[099720109477] },
201
+ { :name => "name", :values => %w[ubuntu/images/*/ubuntu-*-14*] }
202
+ ],
203
+ "ubuntu-12.04" => [
204
+ { :name => "owner-id", :values => %w[099720109477] },
205
+ { :name => "name", :values => %w[ubuntu/images/*/ubuntu-*-12.04*] }
206
+ ],
207
+ "ubuntu-x86_64" => [
208
+ { :name => "owner-id", :values => %w[099720109477] },
209
+ { :name => "name", :values => %w[ubuntu/images/*/ubuntu-*-*] },
210
+ { :name => "architecture", :values => %w[x86_64] }
211
+ ],
212
+ "ubuntu-14-x86_64" => [
213
+ { :name => "owner-id", :values => %w[099720109477] },
214
+ { :name => "name", :values => %w[ubuntu/images/*/ubuntu-*-14*] },
215
+ { :name => "architecture", :values => %w[x86_64] }
216
+ ],
217
+
218
+ "windows" => [
219
+ { :name => "owner-alias", :values => %w[amazon] },
220
+ { :name => "name", :values => %w[
221
+ Windows_Server-*-RTM-English-*-Base-*
222
+ Windows_Server-*-SP*-English-*-Base-*
223
+ Windows_Server-*-R*_RTM-English-*-Base-*
224
+ Windows_Server-*-R*_SP*-English-*-Base-*] }
225
+ ],
226
+ "windows-2008" => [
227
+ { :name => "owner-alias", :values => %w[amazon] },
228
+ { :name => "name", :values => %w[
229
+ Windows_Server-2008-RTM-English-*-Base-*
230
+ Windows_Server-2008-SP*-English-*-Base-*] }
231
+ ],
232
+ "windows-2012" => [
233
+ { :name => "owner-alias", :values => %w[amazon] },
234
+ { :name => "name", :values => %w[
235
+ Windows_Server-2012-RTM-English-*-Base-*
236
+ Windows_Server-2012-SP*-English-*-Base-*] }
237
+ ],
238
+ "windows-2012r2" => [
239
+ { :name => "owner-alias", :values => %w[amazon] },
240
+ { :name => "name", :values => %w[
241
+ Windows_Server-2012-R2_RTM-English-*-Base-*
242
+ Windows_Server-2012-R2_SP*-English-*-Base-*] }
243
+ ],
244
+ "windows-2012sp1" => [
245
+ { :name => "owner-alias", :values => %w[amazon] },
246
+ { :name => "name", :values => %w[
247
+ Windows_Server-2012-SP1-English-*-Base-*] }
248
+ ],
249
+ "windows-2012rtm" => [
250
+ { :name => "owner-alias", :values => %w[amazon] },
251
+ { :name => "name", :values => %w[
252
+ Windows_Server-2012-RTM-English-*-Base-*] }
253
+ ],
254
+ "windows-2012r2sp1" => [
255
+ { :name => "owner-alias", :values => %w[amazon] },
256
+ { :name => "name", :values => %w[
257
+ Windows_Server-2012-R2_SP1-English-*-Base-*] }
258
+ ],
259
+ "windows-2012r2rtm" => [
260
+ { :name => "owner-alias", :values => %w[amazon] },
261
+ { :name => "name", :values => %w[
262
+ Windows_Server-2012-R2_RTM-English-*-Base-*] }
263
+ ],
264
+ "windows-x86_64" => [
265
+ { :name => "owner-alias", :values => %w[amazon] },
266
+ { :name => "name", :values => %w[
267
+ Windows_Server-*-RTM-English-*-Base-*
268
+ Windows_Server-*-SP*-English-*-Base-*
269
+ Windows_Server-*-R*_RTM-English-*-Base-*
270
+ Windows_Server-*-R*_SP*-English-*-Base-*] },
271
+ { :name => "architecture", :values => %w[x86_64] }
272
+ ],
273
+ "windows-2012r2-x86_64" => [
274
+ { :name => "owner-alias", :values => %w[amazon] },
275
+ { :name => "name", :values => %w[
276
+ Windows_Server-2012-R2_RTM-English-*-Base-*
277
+ Windows_Server-2012-R2_SP*-English-*-Base-*] },
278
+ { :name => "architecture", :values => %w[x86_64] }
279
+ ],
280
+ "windows-server" => [
281
+ { :name => "owner-alias", :values => %w[amazon] },
282
+ { :name => "name", :values => %w[
283
+ Windows_Server-*-RTM-English-*-Base-*
284
+ Windows_Server-*-SP*-English-*-Base-*
285
+ Windows_Server-*-R*_RTM-English-*-Base-*
286
+ Windows_Server-*-R*_SP*-English-*-Base-*] }
287
+ ],
288
+ "windows-server-2012r2-x86_64" => [
289
+ { :name => "owner-alias", :values => %w[amazon] },
290
+ { :name => "name", :values => %w[
291
+ Windows_Server-2012-R2_RTM-English-*-Base-*
292
+ Windows_Server-2012-R2_SP*-English-*-Base-*] },
293
+ { :name => "architecture", :values => %w[x86_64] }
294
+ ]
295
+ }
296
+
297
+ describe "Platform defaults" do
298
+ PLATFORM_SEARCHES.each do |platform_name, filters|
299
+ context "when platform is #{platform_name}" do
300
+ let(:image) { FakeImage.new(:name => platform_name.split("-", 2)[0]) }
301
+
302
+ it "searches for #{filters} and uses the resulting image" do
303
+ expect(driver.ec2.resource).
304
+ to receive(:images).with(:filters => filters).and_return([image])
305
+ expect(driver.ec2.resource).
306
+ to receive(:image).with(image.id).and_return(image)
307
+
308
+ instance = new_instance(:platform_name => platform_name)
309
+ expect(instance.driver.instance_generator.ec2_instance_data[:image_id]).
310
+ to eq image.id
311
+ end
312
+ end
313
+ end
314
+ end
315
+
316
+ context "when image_search is provided" do
317
+ let(:image) { FakeImage.new(:name => "ubuntu") }
318
+ let(:config) { { :image_search => { :name => "SuperImage" } } }
319
+
320
+ context "and platform.name is a well known platform name" do
321
+ it "searches for an image id without using the standard filters" do
322
+ expect(driver.ec2.resource).
323
+ to receive(:images).
324
+ with(:filters => [{ :name => "name", :values => %w[SuperImage] }]).
325
+ and_return([image])
326
+ expect(driver.ec2.resource).
327
+ to receive(:image).with(image.id).and_return(image)
328
+
329
+ instance = new_instance(:platform_name => "ubuntu")
330
+ expect(instance.driver.instance_generator.ec2_instance_data[:image_id]).
331
+ to eq image.id
332
+ end
333
+ end
334
+
335
+ context "and platform.name is not a well known platform name" do
336
+ let(:image) { FakeImage.new(:name => "ubuntu") }
337
+ it "does not search for (or find) an image, and informs the user they need to set image_id" do
338
+ expect(driver.ec2.resource).
339
+ to receive(:images).
340
+ with(:filters => [{ :name => "name", :values => %w[SuperImage] }]).
341
+ and_return([image])
342
+ expect(driver.ec2.resource).
343
+ to receive(:image).with(image.id).and_return(image)
344
+
345
+ instance = new_instance(:platform_name => "blarghle")
346
+ expect(instance.driver.instance_generator.ec2_instance_data[:image_id]).to eq image.id
347
+ end
348
+ end
349
+ end
350
+ end
@@ -29,38 +29,6 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
29
29
  let(:logger) { instance_double(Logger) }
30
30
  let(:generator) { Kitchen::Driver::Aws::InstanceGenerator.new(config, ec2, logger) }
31
31
 
32
- describe "#debug_if_root_device" do
33
- let(:image_id) { "ami-123456" }
34
- let(:config) { { :image_id => image_id } }
35
- let(:image) { double("image") }
36
-
37
- before do
38
- allow(resource).to receive(:image).with(image_id).and_return(image)
39
- end
40
-
41
- it "returns nil when provided nil" do
42
- expect(generator.debug_if_root_device(nil)).to eq(nil)
43
- end
44
-
45
- it "returns nil when provided empty" do
46
- expect(generator.debug_if_root_device([])).to eq(nil)
47
- end
48
-
49
- it "returns nil when the image cannot be found" do
50
- expect(image).to receive(:root_device_name).and_raise(
51
- ::Aws::EC2::Errors::InvalidAMIIDNotFound.new({}, "")
52
- )
53
- expect(logger).to_not receive(:info)
54
- expect(generator.debug_if_root_device([{ :device_name => "name" }])).to eq(nil)
55
- end
56
-
57
- it "logs an info message when the device mappings are overriding the root device" do
58
- expect(image).to receive(:root_device_name).and_return("name")
59
- expect(logger).to receive(:info)
60
- expect(generator.debug_if_root_device([{ :device_name => "name" }])).to eq(nil)
61
- end
62
- end
63
-
64
32
  describe "#prepared_user_data" do
65
33
  context "when config[:user_data] is a file" do
66
34
  let(:tmp_file) { Tempfile.new("prepared_user_data_test") }
@@ -90,180 +58,121 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
90
58
  end
91
59
  end
92
60
 
93
- describe "block_device_mappings" do
94
- before do
95
- expect(generator).to receive(:debug_if_root_device)
96
- end
97
-
98
- it "returns empty if nothing is provided" do
99
- expect(generator.block_device_mappings).to eq([])
61
+ describe "#ec2_instance_data" do
62
+ it "returns empty on nil" do
63
+ expect(generator.ec2_instance_data).to eq(
64
+ :instance_type => nil,
65
+ :ebs_optimized => nil,
66
+ :image_id => nil,
67
+ :key_name => nil,
68
+ :subnet_id => nil,
69
+ :private_ip_address => nil
70
+ )
100
71
  end
101
72
 
102
- context "when populated with multiple mappings" do
73
+ context "when populated with minimum requirements" do
103
74
  let(:config) do
104
- { :block_device_mappings => [
105
- {
106
- :ebs_volume_size => 13,
107
- :ebs_delete_on_termination => true,
108
- :ebs_device_name => "/dev/sda1"
109
- },
110
- {
111
- :ebs_volume_size => 15,
112
- :ebs_delete_on_termination => false,
113
- :ebs_device_name => "/dev/sda2",
114
- :ebs_volume_type => "gp2",
115
- :ebs_snapshot_id => "id",
116
- :ebs_virtual_name => "test"
117
- },
118
- {
119
- :ebs_volume_size => 100,
120
- :ebs_delete_on_termination => true,
121
- :ebs_device_name => "/dev/sda3",
122
- :ebs_volume_type => "io1",
123
- :ebs_iops => 100
124
- }
125
- ] }
75
+ {
76
+ :instance_type => "micro",
77
+ :ebs_optimized => true,
78
+ :image_id => "ami-123",
79
+ :aws_ssh_key_id => "key",
80
+ :subnet_id => "s-456",
81
+ :private_ip_address => "0.0.0.0"
82
+ }
126
83
  end
127
84
 
128
- it "returns the transformed mappings" do
129
- expect(generator.block_device_mappings).to match(
130
- [
131
- {
132
- :ebs => {
133
- :volume_size => 13,
134
- :delete_on_termination => true
135
- },
136
- :device_name => "/dev/sda1"
137
- },
138
- {
139
- :ebs => {
140
- :volume_size => 15,
141
- :volume_type => "gp2",
142
- :snapshot_id => "id",
143
- :delete_on_termination => false
144
- },
145
- :device_name => "/dev/sda2",
146
- :virtual_name => "test"
147
- },
148
- {
149
- :ebs => {
150
- :volume_size => 100,
151
- :volume_type => "io1",
152
- :iops => 100,
153
- :delete_on_termination => true
154
- },
155
- :device_name => "/dev/sda3"
156
- }
157
- ]
85
+ it "returns the minimum data" do
86
+ expect(generator.ec2_instance_data).to eq(
87
+ :instance_type => "micro",
88
+ :ebs_optimized => true,
89
+ :image_id => "ami-123",
90
+ :key_name => "key",
91
+ :subnet_id => "s-456",
92
+ :private_ip_address => "0.0.0.0"
158
93
  )
159
94
  end
160
-
161
95
  end
162
96
 
163
- context "when populatd with deprecated configs" do
97
+ context "when passed an empty block_device_mappings" do
164
98
  let(:config) do
165
99
  {
166
- :ebs_volume_size => 13,
167
- :ebs_delete_on_termination => true,
168
- :ebs_device_name => "/dev/sda1",
169
- :ebs_volume_type => "gp2"
100
+ :instance_type => "micro",
101
+ :ebs_optimized => true,
102
+ :image_id => "ami-123",
103
+ :aws_ssh_key_id => "key",
104
+ :subnet_id => "s-456",
105
+ :private_ip_address => "0.0.0.0",
106
+ :block_device_mappings => []
170
107
  }
171
108
  end
172
109
 
173
- it "returns the transformed mappings" do
174
- expect(generator.block_device_mappings).to match(
175
- [
176
- {
177
- :ebs => {
178
- :volume_size => 13,
179
- :delete_on_termination => true,
180
- :volume_type => "gp2"
181
- },
182
- :device_name => "/dev/sda1"
183
- }
184
- ]
110
+ it "does not return block_device_mappings" do
111
+ expect(generator.ec2_instance_data).to eq(
112
+ :instance_type => "micro",
113
+ :ebs_optimized => true,
114
+ :image_id => "ami-123",
115
+ :key_name => "key",
116
+ :subnet_id => "s-456",
117
+ :private_ip_address => "0.0.0.0"
185
118
  )
186
119
  end
187
120
  end
188
121
 
189
- context "when populated with deprecated configs and new configs" do
122
+ context "when availability_zone is provided as 'eu-west-1c'" do
190
123
  let(:config) do
191
124
  {
192
- :ebs_volume_size => 13,
193
- :ebs_delete_on_termination => true,
194
- :ebs_device_name => "/dev/sda1",
195
- :ebs_volume_type => "gp2",
196
- :block_device_mappings => [
197
- {
198
- :ebs_volume_size => 15,
199
- :ebs_delete_on_termination => false,
200
- :ebs_device_name => "/dev/sda2",
201
- :ebs_volume_type => "gp2",
202
- :ebs_snapshot_id => "id",
203
- :ebs_virtual_name => "test"
204
- }
205
- ]
125
+ :region => "eu-east-1",
126
+ :availability_zone => "eu-west-1c"
206
127
  }
207
128
  end
208
-
209
- it "ignores the old configs" do
210
- expect(generator.block_device_mappings).to match(
211
- [
212
- {
213
- :ebs => {
214
- :volume_size => 15,
215
- :volume_type => "gp2",
216
- :snapshot_id => "id",
217
- :delete_on_termination => false
218
- },
219
- :device_name => "/dev/sda2",
220
- :virtual_name => "test"
221
- }
222
- ]
129
+ it "returns that in the instance data" do
130
+ expect(generator.ec2_instance_data).to eq(
131
+ :instance_type => nil,
132
+ :ebs_optimized => nil,
133
+ :image_id => nil,
134
+ :key_name => nil,
135
+ :subnet_id => nil,
136
+ :private_ip_address => nil,
137
+ :placement => { :availability_zone => "eu-west-1c" }
223
138
  )
224
139
  end
225
140
  end
226
- end
227
-
228
- describe "#ec2_instance_data" do
229
- before do
230
- expect(generator).to receive(:debug_if_root_device)
231
- end
232
141
 
233
- it "returns empty on nil" do
234
- expect(generator.ec2_instance_data).to eq(
235
- :placement => { :availability_zone => nil },
236
- :instance_type => nil,
237
- :ebs_optimized => nil,
238
- :image_id => nil,
239
- :key_name => nil,
240
- :subnet_id => nil,
241
- :private_ip_address => nil
242
- )
142
+ context "when availability_zone is provided as 'c'" do
143
+ let(:config) do
144
+ {
145
+ :region => "eu-east-1",
146
+ :availability_zone => "c"
147
+ }
148
+ end
149
+ it "adds the region to it in the instance data" do
150
+ expect(generator.ec2_instance_data).to eq(
151
+ :instance_type => nil,
152
+ :ebs_optimized => nil,
153
+ :image_id => nil,
154
+ :key_name => nil,
155
+ :subnet_id => nil,
156
+ :private_ip_address => nil,
157
+ :placement => { :availability_zone => "eu-east-1c" }
158
+ )
159
+ end
243
160
  end
244
161
 
245
- context "when populated with minimum requirements" do
162
+ context "when availability_zone is not provided" do
246
163
  let(:config) do
247
164
  {
248
- :availability_zone => "eu-west-1a",
249
- :instance_type => "micro",
250
- :ebs_optimized => true,
251
- :image_id => "ami-123",
252
- :aws_ssh_key_id => "key",
253
- :subnet_id => "s-456",
254
- :private_ip_address => "0.0.0.0"
165
+ :region => "eu-east-1"
255
166
  }
256
167
  end
257
-
258
- it "returns the minimum data" do
168
+ it "is not added to the instance data" do
259
169
  expect(generator.ec2_instance_data).to eq(
260
- :placement => { :availability_zone => "eu-west-1a" },
261
- :instance_type => "micro",
262
- :ebs_optimized => true,
263
- :image_id => "ami-123",
264
- :key_name => "key",
265
- :subnet_id => "s-456",
266
- :private_ip_address => "0.0.0.0"
170
+ :instance_type => nil,
171
+ :ebs_optimized => nil,
172
+ :image_id => nil,
173
+ :key_name => nil,
174
+ :subnet_id => nil,
175
+ :private_ip_address => nil
267
176
  )
268
177
  end
269
178
  end
@@ -277,7 +186,6 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
277
186
 
278
187
  it "adds a network_interfaces block" do
279
188
  expect(generator.ec2_instance_data).to eq(
280
- :placement => { :availability_zone => nil },
281
189
  :instance_type => nil,
282
190
  :ebs_optimized => nil,
283
191
  :image_id => nil,
@@ -297,7 +205,6 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
297
205
 
298
206
  it "adds a network_interfaces block" do
299
207
  expect(generator.ec2_instance_data).to eq(
300
- :placement => { :availability_zone => nil },
301
208
  :instance_type => nil,
302
209
  :ebs_optimized => nil,
303
210
  :image_id => nil,
@@ -322,7 +229,6 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
322
229
 
323
230
  it "adds a network_interfaces block" do
324
231
  expect(generator.ec2_instance_data).to eq(
325
- :placement => { :availability_zone => nil },
326
232
  :instance_type => nil,
327
233
  :ebs_optimized => nil,
328
234
  :image_id => nil,
@@ -348,7 +254,6 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
348
254
 
349
255
  it "adds a network_interfaces block" do
350
256
  expect(generator.ec2_instance_data).to eq(
351
- :placement => { :availability_zone => nil },
352
257
  :instance_type => nil,
353
258
  :ebs_optimized => nil,
354
259
  :image_id => nil,
@@ -388,7 +293,6 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
388
293
 
389
294
  it "adds a network_interfaces block" do
390
295
  expect(generator.ec2_instance_data).to eq(
391
- :placement => { :availability_zone => nil },
392
296
  :instance_type => nil,
393
297
  :ebs_optimized => nil,
394
298
  :image_id => nil,
@@ -417,12 +321,14 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
417
321
  :private_ip_address => "0.0.0.0",
418
322
  :block_device_mappings => [
419
323
  {
420
- :ebs_volume_size => 15,
421
- :ebs_delete_on_termination => false,
422
- :ebs_device_name => "/dev/sda2",
423
- :ebs_volume_type => "gp2",
424
- :ebs_snapshot_id => "id",
425
- :ebs_virtual_name => "test"
324
+ :device_name => "/dev/sda2",
325
+ :virtual_name => "test",
326
+ :ebs => {
327
+ :volume_size => 15,
328
+ :delete_on_termination => false,
329
+ :volume_type => "gp2",
330
+ :snapshot_id => "id"
331
+ }
426
332
  }
427
333
  ],
428
334
  :security_group_ids => ["sg-789"],
@@ -434,21 +340,20 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
434
340
 
435
341
  it "returns the maximum data" do
436
342
  expect(generator.ec2_instance_data).to eq(
437
- :placement => { :availability_zone => "eu-west-1a" },
438
343
  :instance_type => "micro",
439
344
  :ebs_optimized => true,
440
345
  :image_id => "ami-123",
441
346
  :key_name => "key",
442
347
  :block_device_mappings => [
443
348
  {
349
+ :device_name => "/dev/sda2",
350
+ :virtual_name => "test",
444
351
  :ebs => {
445
352
  :volume_size => 15,
446
353
  :delete_on_termination => false,
447
354
  :volume_type => "gp2",
448
355
  :snapshot_id => "id"
449
- },
450
- :device_name => "/dev/sda2",
451
- :virtual_name => "test"
356
+ }
452
357
  }
453
358
  ],
454
359
  :iam_instance_profile => { :name => "iam-123" },
@@ -460,6 +365,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
460
365
  :groups => ["sg-789"],
461
366
  :private_ip_address => "0.0.0.0"
462
367
  }],
368
+ :placement => { :availability_zone => "eu-west-1a" },
463
369
  :user_data => Base64.encode64("foo")
464
370
  )
465
371
  end