kitchen-gce 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,11 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-09-20 08:00:47 -0700 using RuboCop version 0.26.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ # Configuration parameters: CountComments.
10
+ Metrics/ClassLength:
11
+ Max: 102
@@ -1,3 +1,11 @@
1
+ ## 0.2.0 / 2014-09-20
2
+
3
+ ### Improvements
4
+
5
+ * #10: Deprecate "area" in configuration for "region"
6
+ * #11: Fix name length, via @pdunnavant
7
+ * #12: Generate instance names that are valid for GCE
8
+
1
9
  ## 0.1.2 / 2014-04-16
2
10
 
3
11
  ### New Features
data/README.md CHANGED
@@ -49,16 +49,10 @@ Then, execute `bundle install`.
49
49
 
50
50
  ## Configuration
51
51
 
52
- ### area
52
+ ### area
53
53
 
54
- Area in which to launch instances. For the purposes of this driver,
55
- "area" is defined as the part prior to the first hyphen in an
56
- availability zone's name; e.g. in "us-central1-b", the area is "us".
57
- Specifying area but not "zone_name" allows kitchen-gce to avoid
58
- launching instances into a zone that is down for maintenance. If
59
- "any" is specified, kitchen-gce will select a zone from all areas.
60
- Default: `us` (lowest cost area); valid values: `any`, `asia`,
61
- `europe`, `us`
54
+ (Deprecated - use equivalent "region" instead. If both "area" and
55
+ "region" are set, the value of "region" will be used.)
62
56
 
63
57
  ### autodelete_disk
64
58
 
@@ -110,6 +104,17 @@ GCE network that instance will be attached to; default: `default`
110
104
  Path to the public half of the ssh key that will be deployed to
111
105
  `~username/.ssh/authorized_keys`; see also "username" below.
112
106
 
107
+ ### region
108
+
109
+ Region in which to launch instances. "Region" is defined as the part
110
+ prior to the second hyphen in an availability zone's name; e.g. in
111
+ "us-central1-b", the region is "us-central1". Specifying region but
112
+ not "zone_name" allows kitchen-gce to avoid launching instances into a
113
+ zone that is down for maintenance. If "any" is specified, kitchen-gce
114
+ will select a zone from all regions. Default: `us-central1` (lowest
115
+ cost region); valid values: `any`, `asia-east1`, `europe-west1`,
116
+ `us-central1`
117
+
113
118
  ### tags
114
119
 
115
120
  Array of tags to associate with instance; default: `[]`
@@ -121,7 +126,7 @@ Username test-kitchen will log into instance as; default: `ENV['USER']`
121
126
  ### zone_name
122
127
 
123
128
  Location into which instances will be launched. If not specified, a
124
- zone is chosen from available zones within the "area" (see above).
129
+ zone is chosen from available zones within the "region" (see above).
125
130
 
126
131
  ## Example
127
132
 
@@ -132,11 +137,11 @@ like this:
132
137
  ---
133
138
  driver_plugin: gce
134
139
  driver_config:
135
- area: any
136
140
  google_client_email: "123456789012@developer.gserviceaccount.com"
137
141
  google_key_location: "<%= ENV['HOME']%>/gce/1234567890abcdef1234567890abcdef12345678-privatekey.p12"
138
142
  google_project: "alpha-bravo-123"
139
143
  network: "kitchenci"
144
+ region: any
140
145
 
141
146
  platforms:
142
147
  - name: debian-7
@@ -1,8 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'kitchen-gce'
4
- s.version = '0.1.2'
5
- s.date = '2014-04-16'
4
+ s.version = '0.2.0'
5
+ s.date = '2014-09-20'
6
6
  s.summary = 'Kitchen::Driver::Gce'
7
7
  s.description = 'A Test-Kitchen driver for Google Compute Engine'
8
8
  s.authors = ['Andrew Leonard']
@@ -27,7 +27,7 @@ module Kitchen
27
27
  #
28
28
  # @author Andrew Leonard <andy@hurricane-ridge.com>
29
29
  class Gce < Kitchen::Driver::SSHBase
30
- default_config :area, 'us'
30
+ default_config :area, 'us-central1'
31
31
  default_config :autodelete_disk, true
32
32
  default_config :disk_size, 10
33
33
  default_config :machine_type, 'n1-standard-1'
@@ -90,6 +90,8 @@ module Kitchen
90
90
  end
91
91
 
92
92
  def create_instance
93
+ config[:region] ||= config[:area]
94
+
93
95
  config[:inst_name] ||= generate_inst_name
94
96
  config[:zone_name] ||= select_zone
95
97
 
@@ -112,20 +114,27 @@ module Kitchen
112
114
 
113
115
  def generate_inst_name
114
116
  # Inspired by generate_name from kitchen-rackspace
115
- base_name = instance.name[0..26] # UUID is 36 chars, max name length 63
116
- "#{base_name}-#{SecureRandom.uuid}"
117
+ name = instance.name.downcase
118
+ name.gsub!(/([^-a-z0-9])/, '-')
119
+ name = 't' + name unless name =~ /^[a-z]/
120
+ base_name = name[0..25] # UUID is 36 chars, max name length 63
121
+ gen_name = "#{base_name}-#{SecureRandom.uuid}"
122
+ unless gen_name =~ /^[a-z]([-a-z0-9]*[a-z0-9])?$/
123
+ fail "Invalid generated instance name: #{gen_name}"
124
+ end
125
+ gen_name
117
126
  end
118
127
 
119
128
  def select_zone
120
- if config[:area] == 'any'
129
+ if config[:region] == 'any'
121
130
  zone_regexp = /^[a-z]+\-/
122
131
  else
123
- zone_regexp = /^#{config[:area]}\-/
132
+ zone_regexp = /^#{config[:region]}\-/
124
133
  end
125
134
  zones = connection.zones.select do |z|
126
135
  z.status == 'UP' && z.name.match(zone_regexp)
127
136
  end
128
- fail 'No up zones in area' unless zones.length >= 1
137
+ fail 'No up zones in region' unless zones.length >= 1
129
138
  zones.sample.name
130
139
  end
131
140
 
@@ -44,7 +44,7 @@ describe Kitchen::Driver::Gce do
44
44
  let(:driver) do
45
45
  d = Kitchen::Driver::Gce.new(config)
46
46
  d.instance = instance
47
- d.stub(:wait_for_sshd).and_return(true)
47
+ allow(d).to receive(:wait_for_sshd) { true }
48
48
  d
49
49
  end
50
50
 
@@ -57,7 +57,7 @@ describe Kitchen::Driver::Gce do
57
57
  name: 'rspec-test-disk',
58
58
  size_gb: 10,
59
59
  zone_name: 'us-central1-b',
60
- source_image: 'debian-7-wheezy-v20131120'
60
+ source_image: 'debian-7-wheezy-v20130816'
61
61
  )
62
62
  end
63
63
 
@@ -80,12 +80,13 @@ describe Kitchen::Driver::Gce do
80
80
  context 'with default options' do
81
81
 
82
82
  defaults = {
83
- area: 'us',
83
+ area: 'us-central1',
84
84
  autodelete_disk: true,
85
85
  disk_size: 10,
86
86
  inst_name: nil,
87
87
  machine_type: 'n1-standard-1',
88
88
  network: 'default',
89
+ region: nil,
89
90
  tags: [],
90
91
  username: ENV['USER'],
91
92
  zone_name: nil }
@@ -99,12 +100,13 @@ describe Kitchen::Driver::Gce do
99
100
 
100
101
  context 'with overriden options' do
101
102
  overrides = {
102
- area: 'europe',
103
+ area: 'europe-west',
103
104
  autodelete_disk: false,
104
105
  disk_size: 15,
105
106
  inst_name: 'ci-instance',
106
107
  machine_type: 'n1-highmem-8',
107
108
  network: 'dev-net',
109
+ region: 'asia-east1',
108
110
  tags: %w(qa integration),
109
111
  username: 'root',
110
112
  zone_name: 'europe-west1-a'
@@ -158,8 +160,8 @@ describe Kitchen::Driver::Gce do
158
160
 
159
161
  let(:driver) do
160
162
  d = Kitchen::Driver::Gce.new(config)
161
- d.stub(create_instance: server)
162
- d.stub(:wait_for_up_instance).and_return(nil)
163
+ allow(d).to receive(:create_instance) { server }
164
+ allow(d).to receive(:wait_for_up_instance) { nil }
163
165
  d
164
166
  end
165
167
 
@@ -179,7 +181,7 @@ describe Kitchen::Driver::Gce do
179
181
  describe '#create_disk' do
180
182
  context 'with defaults and required options' do
181
183
  it 'returns a Google Disk object' do
182
- config[:image_name] = 'debian-7-wheezy-v20131120'
184
+ config[:image_name] = 'debian-7-wheezy-v20130816'
183
185
  config[:inst_name] = 'rspec-disk'
184
186
  config[:zone_name] = 'us-central1-a'
185
187
  expect(driver.send(:create_disk)).to be_a(Fog::Compute::Google::Disk)
@@ -200,6 +202,43 @@ describe Kitchen::Driver::Gce do
200
202
  expect(driver.send(:create_instance)).to be_a(
201
203
  Fog::Compute::Google::Server)
202
204
  end
205
+
206
+ it 'sets the region to the default "us-central1"' do
207
+ driver.send(:create_instance)
208
+ expect(config[:region]).to eq('us-central1')
209
+ end
210
+ end
211
+
212
+ context 'area set, region unset' do
213
+ let(:config) do
214
+ { area: 'europe-west1',
215
+ google_client_email: '123456789012@developer.gserviceaccount.com',
216
+ google_key_location: '/home/user/gce/123456-privatekey.p12',
217
+ google_project: 'alpha-bravo-123'
218
+ }
219
+ end
220
+
221
+ it 'sets region to the area value' do
222
+ driver.send(:create_instance)
223
+ expect(config[:region]).to eq(config[:area])
224
+ end
225
+ end
226
+
227
+ context 'area set, region set' do
228
+ let(:config) do
229
+ { area: 'fugazi',
230
+ google_client_email: '123456789012@developer.gserviceaccount.com',
231
+ google_key_location: '/home/user/gce/123456-privatekey.p12',
232
+ google_project: 'alpha-bravo-123',
233
+ region: 'europe-west1'
234
+ }
235
+ end
236
+
237
+ it 'sets the region independent of the area value' do
238
+ driver.send(:create_instance)
239
+ expect(config[:region]).to eq('europe-west1')
240
+ end
241
+
203
242
  end
204
243
  end
205
244
 
@@ -239,23 +278,60 @@ describe Kitchen::Driver::Gce do
239
278
  end
240
279
  end
241
280
 
242
- context 'with a name 28 characters or longer' do
281
+ context 'with a name 27 characters or longer' do
243
282
  let(:instance) do
244
- double(name: '1234567890123456789012345678')
283
+ double(name: 'a23456789012345678901234567')
245
284
  end
246
285
 
247
286
  it 'shortens the base name and appends a UUID' do
287
+ expect(driver.send(:generate_inst_name).length).to eq 63
248
288
  expect(driver.send(:generate_inst_name)).to match(
249
- /^123456789012345678901234567
289
+ /^a2345678901234567890123456
290
+ -[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/x)
291
+ end
292
+ end
293
+
294
+ context 'with a "name" value containing an invalid leading character' do
295
+ let(:instance) do
296
+ double(name: '12345')
297
+ end
298
+
299
+ it 'adds a leading "t"' do
300
+ expect(driver.send(:generate_inst_name)).to match(
301
+ /^t12345
302
+ -[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/x)
303
+ end
304
+ end
305
+
306
+ context 'with a "name" value containing uppercase letters' do
307
+ let(:instance) do
308
+ double(name: 'AbCdEf')
309
+ end
310
+
311
+ it 'downcases the "name" characters in the instance name' do
312
+ expect(driver.send(:generate_inst_name)).to match(
313
+ /^abcdef
314
+ -[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/x)
315
+ end
316
+ end
317
+
318
+ context 'with a name value containing invalid characters' do
319
+ let(:instance) do
320
+ double(name: 'a!b@c#d$e%f^g&h*i(j)')
321
+ end
322
+
323
+ it 'replaces the invalid characters with dashes' do
324
+ expect(driver.send(:generate_inst_name)).to match(
325
+ /^a-b-c-d-e-f-g-h-i-j-
250
326
  -[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/x)
251
327
  end
252
328
  end
253
329
  end
254
330
 
255
331
  describe '#select_zone' do
256
- context 'when choosing from any area' do
332
+ context 'when choosing from any region' do
257
333
  let(:config) do
258
- { area: 'any',
334
+ { region: 'any',
259
335
  google_client_email: '123456789012@developer.gserviceaccount.com',
260
336
  google_key_location: '/home/user/gce/123456-privatekey.p12',
261
337
  google_project: 'alpha-bravo-123'
@@ -270,24 +346,32 @@ describe Kitchen::Driver::Gce do
270
346
  end
271
347
  end
272
348
 
273
- context 'when choosing from the "europe" area' do
349
+ context 'when choosing from the "europe-west1" region' do
274
350
  let(:config) do
275
- { area: 'europe',
351
+ { region: 'europe-west1',
276
352
  google_client_email: '123456789012@developer.gserviceaccount.com',
277
353
  google_key_location: '/home/user/gce/123456-privatekey.p12',
278
354
  google_project: 'alpha-bravo-123'
279
355
  }
280
356
  end
281
357
 
282
- it 'chooses a zone in europe' do
358
+ it 'chooses a zone in europe-west1' do
283
359
  expect(driver.send(:select_zone)).to satisfy do |zone|
284
360
  %w(europe-west1-a).include?(zone)
285
361
  end
286
362
  end
287
363
  end
288
364
 
289
- context 'when choosing from the default "us" area' do
290
- it 'chooses a zone in the us' do
365
+ context 'when choosing from the default "us-central1" region' do
366
+ let(:config) do
367
+ { region: 'us-central1',
368
+ google_client_email: '123456789012@developer.gserviceaccount.com',
369
+ google_key_location: '/home/user/gce/123456-privatekey.p12',
370
+ google_project: 'alpha-bravo-123'
371
+ }
372
+ end
373
+
374
+ it 'chooses a zone in us-central1' do
291
375
  expect(driver.send(:select_zone)).to satisfy do |zone|
292
376
  %w(us-central1-a us-central1-b us-central2-a).include?(zone)
293
377
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-gce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-16 00:00:00.000000000 Z
12
+ date: 2014-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -162,6 +162,8 @@ extensions: []
162
162
  extra_rdoc_files: []
163
163
  files:
164
164
  - .gitignore
165
+ - .rubocop.yml
166
+ - .rubocop_todo.yml
165
167
  - .travis.yml
166
168
  - CHANGELOG.md
167
169
  - Gemfile
@@ -191,9 +193,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
193
  - - ! '>='
192
194
  - !ruby/object:Gem::Version
193
195
  version: '0'
194
- segments:
195
- - 0
196
- hash: 2668834953209194821
197
196
  requirements: []
198
197
  rubyforge_project:
199
198
  rubygems_version: 1.8.23.2