kitchen-ec2 0.9.3 → 0.9.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21b2743d4aad92b8fb4f5d02d3619c0b1b83c6eb
4
- data.tar.gz: 6dc57776d894c34fad0da0701e4c6d4a59076698
3
+ metadata.gz: ce1e378058d18afcc07e2f59a986588f9e05887f
4
+ data.tar.gz: 2e902c288551eab23b6f0ed314dd7616277a13de
5
5
  SHA512:
6
- metadata.gz: 3358dc9d1df3053b5f6efaf4f4ec2673f46eb3b81a1b81d080a22f92203bf851abe1133429a16dd5d78adf0ca1cf5d62298c632b011b58d1ce3d9651e4dcc950
7
- data.tar.gz: 430c0e2766480db4d1053afa73f2b609d9379e283d139fe2e6a36cfbf9f21e386ab0853ec26b417ec5fcfda6e640775b0b31a5af5c80c6f58961d4457498bd62
6
+ metadata.gz: ef7beeddeeca20586ef7800e42c841b530f04fc2bc16098e79478e37654770c1bf163ea9a9e3707827d3f060eda2b71886eb50d7b3123740932d060dcac0297f
7
+ data.tar.gz: 3bd25b6b3654267dfe2262a796659e647749f57fd1095551e414ded3c5fc5f327965eb0f2b719369e290c94536ed5ff6fd2aef265340e84af9927c44495f8253
data/.rubocop.yml CHANGED
@@ -13,3 +13,6 @@ Metrics/CyclomaticComplexity:
13
13
 
14
14
  Metrics/PerceivedComplexity:
15
15
  Max: 30
16
+
17
+ Metrics/AbcSize:
18
+ Max: 60
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.9.4 / 2015-06-03
2
+
3
+ ### Bug Fixes
4
+
5
+ * Pull Request [#142][]: Fixing NoMethodError, providing logger to instance_generator
6
+
7
+ ### New Features
8
+
9
+ ### Improvements
10
+
1
11
  ## 0.9.3 / 2015-05-29
2
12
 
3
13
  ### Bug Fixes
@@ -154,6 +164,7 @@
154
164
  [#128]: https://github.com/test-kitchen/kitchen-ec2/issues/128
155
165
  [#131]: https://github.com/test-kitchen/kitchen-ec2/issues/131
156
166
  [#140]: https://github.com/test-kitchen/kitchen-ec2/issues/140
167
+ [#142]: https://github.com/test-kitchen/kitchen-ec2/issues/142
157
168
  [@Atalanta]: https://github.com/Atalanta
158
169
  [@Igorshp]: https://github.com/Igorshp
159
170
  [@JamesAwesome]: https://github.com/JamesAwesome
data/README.md CHANGED
@@ -425,7 +425,7 @@ Apache 2.0 (see [LICENSE][license])
425
425
  [issues]: https://github.com/test-kitchen/kitchen-ec2/issues
426
426
  [license]: https://github.com/test-kitchen/kitchen-ec2/blob/master/LICENSE
427
427
  [repo]: https://github.com/test-kitchen/kitchen-ec2
428
- [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
428
+ [driver_usage]: https://github.com/test-kitchen/kitchen-ec2
429
429
  [chef_omnibus_dl]: http://www.getchef.com/chef/install/
430
430
 
431
431
  [amis_json]: https://github.com/test-kitchen/kitchen-ec2/blob/master/data/amis.json
@@ -30,13 +30,12 @@ module Kitchen
30
30
  # @author Tyler Ball <tball@chef.io>
31
31
  class InstanceGenerator
32
32
 
33
- include Logging
33
+ attr_reader :config, :ec2, :logger
34
34
 
35
- attr_reader :config, :ec2
36
-
37
- def initialize(config, ec2)
35
+ def initialize(config, ec2, logger)
38
36
  @config = config
39
37
  @ec2 = ec2
38
+ @logger = logger
40
39
  end
41
40
 
42
41
  # Transform the provided config into the hash to send to AWS. Some fields
@@ -125,6 +124,7 @@ module Kitchen
125
124
  # If the provided bdms match the root device in the AMI, emit log that
126
125
  # states this
127
126
  def debug_if_root_device(bdms)
127
+ return if bdms.nil? || bdms.empty?
128
128
  image_id = config[:image_id]
129
129
  image = ec2.resource.image(image_id)
130
130
  begin
@@ -136,7 +136,7 @@ module Kitchen
136
136
  end
137
137
  bdms.find { |bdm|
138
138
  if bdm[:device_name] == root_device_name
139
- info("Overriding root device [#{root_device_name}] from image [#{image_id}]")
139
+ logger.info("Overriding root device [#{root_device_name}] from image [#{image_id}]")
140
140
  end
141
141
  }
142
142
  end
@@ -159,6 +159,8 @@ module Kitchen
159
159
 
160
160
  if config[:availability_zone].nil?
161
161
  config[:availability_zone] = config[:region] + "b"
162
+ elsif config[:availability_zone] =~ /^[a-z]$/
163
+ config[:availability_zone] = config[:region] + config[:availability_zone]
162
164
  end
163
165
  # TODO: when we get rid of flavor_id, move this to a default
164
166
  if config[:instance_type].nil?
@@ -196,27 +198,7 @@ module Kitchen
196
198
 
197
199
  state[:server_id] = server.id
198
200
  info("EC2 instance <#{state[:server_id]}> created.")
199
- wait_log = proc do |attempts|
200
- c = attempts * config[:retryable_sleep]
201
- t = config[:retryable_tries] * config[:retryable_sleep]
202
- info "Waited #{c}/#{t}s for instance <#{state[:server_id]}> to become ready."
203
- end
204
- begin
205
- server = server.wait_until(
206
- :max_attempts => config[:retryable_tries],
207
- :delay => config[:retryable_sleep],
208
- :before_attempt => wait_log
209
- ) do |s|
210
- hostname = hostname(s, config[:interface])
211
- # Euca instances often report ready before they have an IP
212
- s.exists? && s.state.name == "running" && !hostname.nil? && hostname != "0.0.0.0"
213
- end
214
- rescue ::Aws::Waiters::Errors::WaiterFailed
215
- error("Ran out of time waiting for the server with id [#{state[:server_id]}]" \
216
- " to become ready, attempting to destroy it")
217
- destroy(state)
218
- raise
219
- end
201
+ wait_until_ready(server, state)
220
202
 
221
203
  info("EC2 instance <#{state[:server_id]}> ready.")
222
204
  state[:hostname] = hostname(server)
@@ -262,7 +244,7 @@ module Kitchen
262
244
  end
263
245
 
264
246
  def instance_generator
265
- @instance_generator ||= Aws::InstanceGenerator.new(config, ec2)
247
+ @instance_generator ||= Aws::InstanceGenerator.new(config, ec2, instance.logger)
266
248
  end
267
249
 
268
250
  # This copies transport config from the current config object into the
@@ -334,6 +316,30 @@ module Kitchen
334
316
  server.create_tags(:tags => tags)
335
317
  end
336
318
 
319
+ def wait_until_ready(server, state)
320
+ wait_log = proc do |attempts|
321
+ c = attempts * config[:retryable_sleep]
322
+ t = config[:retryable_tries] * config[:retryable_sleep]
323
+ info "Waited #{c}/#{t}s for instance <#{state[:server_id]}> to become ready."
324
+ end
325
+ begin
326
+ server.wait_until(
327
+ :max_attempts => config[:retryable_tries],
328
+ :delay => config[:retryable_sleep],
329
+ :before_attempt => wait_log
330
+ ) do |s|
331
+ hostname = hostname(s, config[:interface])
332
+ # Euca instances often report ready before they have an IP
333
+ s.exists? && s.state.name == "running" && !hostname.nil? && hostname != "0.0.0.0"
334
+ end
335
+ rescue ::Aws::Waiters::Errors::WaiterFailed
336
+ error("Ran out of time waiting for the server with id [#{state[:server_id]}]" \
337
+ " to become ready, attempting to destroy it")
338
+ destroy(state)
339
+ raise
340
+ end
341
+ end
342
+
337
343
  def amis
338
344
  @amis ||= begin
339
345
  json_file = File.join(File.dirname(__FILE__),
@@ -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.9.3"
24
+ EC2_VERSION = "0.9.4"
25
25
  end
26
26
  end
@@ -24,12 +24,10 @@ require "base64"
24
24
  describe Kitchen::Driver::Aws::InstanceGenerator do
25
25
 
26
26
  let(:config) { Hash.new }
27
-
28
27
  let(:resource) { instance_double(Aws::EC2::Resource) }
29
-
30
28
  let(:ec2) { instance_double(Kitchen::Driver::Aws::Client, :resource => resource) }
31
-
32
- let(:generator) { Kitchen::Driver::Aws::InstanceGenerator.new(config, ec2) }
29
+ let(:logger) { instance_double(Logger) }
30
+ let(:generator) { Kitchen::Driver::Aws::InstanceGenerator.new(config, ec2, logger) }
33
31
 
34
32
  describe "#debug_if_root_device" do
35
33
  let(:image_id) { "ami-123456" }
@@ -37,20 +35,28 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
37
35
  let(:image) { double("image") }
38
36
 
39
37
  before do
40
- expect(resource).to receive(:image).with(image_id).and_return(image)
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)
41
47
  end
42
48
 
43
49
  it "returns nil when the image cannot be found" do
44
50
  expect(image).to receive(:root_device_name).and_raise(
45
51
  ::Aws::EC2::Errors::InvalidAMIIDNotFound.new({}, "")
46
52
  )
47
- expect(generator).to_not receive(:info)
48
- expect(generator.debug_if_root_device({})).to eq(nil)
53
+ expect(logger).to_not receive(:info)
54
+ expect(generator.debug_if_root_device([{ :device_name => "name" }])).to eq(nil)
49
55
  end
50
56
 
51
57
  it "logs an info message when the device mappings are overriding the root device" do
52
58
  expect(image).to receive(:root_device_name).and_return("name")
53
- expect(generator).to receive(:info)
59
+ expect(logger).to receive(:info)
54
60
  expect(generator.debug_if_root_device([{ :device_name => "name" }])).to eq(nil)
55
61
  end
56
62
  end
@@ -88,6 +88,12 @@ describe Kitchen::Driver::Ec2 do
88
88
  driver.finalize_config!(instance)
89
89
  expect(config[:availability_zone]).to eq("us-east-1b")
90
90
  end
91
+
92
+ it "expands the availability zone if provided as a letter" do
93
+ config[:availability_zone] = "d"
94
+ driver.finalize_config!(instance)
95
+ expect(config[:availability_zone]).to eq("us-east-1d")
96
+ end
91
97
  end
92
98
 
93
99
  describe "#hostname" do
@@ -171,6 +177,10 @@ describe Kitchen::Driver::Ec2 do
171
177
  end
172
178
 
173
179
  describe "#submit_server" do
180
+ before do
181
+ expect(driver).to receive(:instance).at_least(:once).and_return(instance)
182
+ end
183
+
174
184
  it "submits the server request" do
175
185
  expect(generator).to receive(:ec2_instance_data).and_return({})
176
186
  expect(client).to receive(:create_instance).with(:min_count => 1, :max_count => 1)
@@ -184,6 +194,10 @@ describe Kitchen::Driver::Ec2 do
184
194
  { :spot_instance_requests => [{ :spot_instance_request_id => "id" }] }
185
195
  }
186
196
 
197
+ before do
198
+ expect(driver).to receive(:instance).at_least(:once).and_return(instance)
199
+ end
200
+
187
201
  it "submits the server request" do
188
202
  expect(generator).to receive(:ec2_instance_data).and_return({})
189
203
  expect(actual_client).to receive(:request_spot_instances).with(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen