kitchen-openstack 1.6.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fbad99eac55c81d83ff01f71923df56b60984a9
4
- data.tar.gz: effda2e0a07e3f9f94ec25092869721a65812894
3
+ metadata.gz: e6059fb2f510144b58793252bb820a17f15b60e1
4
+ data.tar.gz: 1839ff785f4c4864ecee83317e6849c13bf96919
5
5
  SHA512:
6
- metadata.gz: bf46986fa541331a45fe596d29202c28712b086115e4bdf0a4ea126830ee4f413c6a7864ea67c6035944bb74fd0131fd53ae793580b4c6c6a08d12e195f6fada
7
- data.tar.gz: 7f0163070fce30dee8c62085001b631fa462b39d77079e92b5a506527d1946a8b5492c4809326ce84a78f2772a78b77a694cd93de31570596937c95397d08abe
6
+ metadata.gz: 6237abba4531cb071ea8681478a3069cdc5605c8ba60bef2f9defa56a3a5519699343d000f7ed4805b825867c6123ffcd19e358760a20944529993588599f346
7
+ data.tar.gz: 52857088b9f309bcbe3178912f0be5318be8eb0cc587ed16b3500ea8709d415e1cd3fe8a6f6c16728e7f6537732d27bf05ace5edf9b1e8000acfde69e61c56d1
@@ -1,3 +1,11 @@
1
+ # 1.7.0 / 2014-10-25
2
+
3
+ ### New Features
4
+
5
+ * PR [#66][] - Allow setting a timed sleep for SSH check edge cases
6
+ * PR [#63][] - Add support for a static server name prefix; via [@ftclausen][]
7
+ * PR [#62][] - Add availability zone support; via [@fortable1999][]
8
+
1
9
  # 1.6.1 / 2014-10-07
2
10
 
3
11
  ### Bug Fixes
@@ -126,6 +134,9 @@ certain specified NICs; via [@monsterzz][]
126
134
 
127
135
  * Initial release! Woo!
128
136
 
137
+ [#66]: https://github.com/test-kitchen/kitchen-openstack/pull/66
138
+ [#63]: https://github.com/test-kitchen/kitchen-openstack/pull/63
139
+ [#62]: https://github.com/test-kitchen/kitchen-openstack/pull/62
129
140
  [#60]: https://github.com/test-kitchen/kitchen-openstack/pull/60
130
141
  [#58]: https://github.com/test-kitchen/kitchen-openstack/pull/58
131
142
  [#56]: https://github.com/test-kitchen/kitchen-openstack/pull/56
@@ -154,6 +165,8 @@ certain specified NICs; via [@monsterzz][]
154
165
  [#7]: https://github.com/test-kitchen/kitchen-openstack/pull/7
155
166
  [#2]: https://github.com/test-kitchen/kitchen-openstack/pull/2
156
167
 
168
+ [@ftclausen]: https://github.com/ftclausen
169
+ [@fortable1999]: https://github.com/fortable1999
157
170
  [@stevejmason]: https://github.com/stevejmason
158
171
  [@StaymanHou]: https://github.com/StaymanHou
159
172
  [@jer]: https://github.com/jer
data/README.md CHANGED
@@ -46,6 +46,7 @@ key will be used (with an RSA key taking precedence over a DSA), though that
46
46
  behavior can be overridden with additional options:
47
47
 
48
48
  server_name: [A UNIQUE SERVER NAME]
49
+ server_name_prefix: [STATIC PREFIX FOR RANDOM SERVER NAME]
49
50
  private_key_path: [PATH TO YOUR PRIVATE SSH KEY]
50
51
  public_key_path: [PATH TO YOUR SSH PUBLIC KEY]
51
52
  username: [SSH USER]
@@ -53,6 +54,7 @@ behavior can be overridden with additional options:
53
54
  key_name: [SSH KEY NAME]
54
55
  openstack_tenant: [YOUR OPENSTACK TENANT ID]
55
56
  openstack_region: [A VALID OPENSTACK REGION]
57
+ availability_zone: [AN OPENSTACK AVAILABILITY ZONE]
56
58
  openstack_service_name: [YOUR OPENSTACK COMPUTE SERVICE NAME]
57
59
  openstack_network_name: [YOUR OPENSTACK NETWORK NAME USED TO CONNECT]
58
60
  security_groups:
@@ -61,6 +63,13 @@ behavior can be overridden with additional options:
61
63
  network_ref:
62
64
  - [OPENSTACK NETWORK NAMES OR...]
63
65
  - [...ID TO CREATE INSTANCE WITH]
66
+ no_ssh_tcp_check: [DEFAULTS TO false, SKIPS TCP CHECK WHEN true]
67
+ no_ssh_tcp_check_sleep: [NUM OF SECONDS TO SLEEP IF no_ssh_tcp_check IS SET]
68
+
69
+ If a `server_name_prefix` is specified then this prefix will be used when
70
+ generating random names of the form `<NAME PREFIX>-<RANDOM STRING>` e.g.
71
+ `myproject-asdfghjk`. If both `server_name_prefix` and `server_name` are
72
+ specified then the `server_name` takes precedence.
64
73
 
65
74
  If a `key_name` is provided it will be used instead of any
66
75
  `public_key_path` that is specified.
@@ -33,6 +33,7 @@ module Kitchen
33
33
  @@ip_pool_lock = Mutex.new
34
34
 
35
35
  default_config :server_name, nil
36
+ default_config :server_name_prefix, nil
36
37
  default_config :key_name, nil
37
38
  default_config :private_key_path do
38
39
  %w(id_rsa id_dsa).map do |k|
@@ -52,11 +53,22 @@ module Kitchen
52
53
  default_config :openstack_network_name, nil
53
54
  default_config :floating_ip_pool, nil
54
55
  default_config :floating_ip, nil
56
+ default_config :availability_zone, nil
55
57
  default_config :security_groups, nil
56
58
  default_config :network_ref, nil
59
+ default_config :no_ssh_tcp_check, false
60
+ default_config :no_ssh_tcp_check_sleep, 120
57
61
 
58
62
  def create(state)
59
- config[:server_name] ||= default_name
63
+ unless config[:server_name]
64
+ if config[:server_name_prefix]
65
+ config[:server_name] = server_name_prefix(
66
+ config[:server_name_prefix]
67
+ )
68
+ else
69
+ config[:server_name] = default_name
70
+ end
71
+ end
60
72
  config[:disable_ssl_validation] && disable_ssl_validation
61
73
  server = create_server
62
74
  state[:server_id] = server.id
@@ -145,7 +157,8 @@ module Kitchen
145
157
  {
146
158
  name: config[:server_name],
147
159
  image_ref: find_image(config[:image_ref]).id,
148
- flavor_ref: find_flavor(config[:flavor_ref]).id
160
+ flavor_ref: find_flavor(config[:flavor_ref]).id,
161
+ availability_zone: config[:availability_zone]
149
162
  }
150
163
  end
151
164
 
@@ -198,6 +211,32 @@ module Kitchen
198
211
  ].join('-')
199
212
  end
200
213
 
214
+ def server_name_prefix(server_name_prefix)
215
+ # Generate what should be a unique server name with given prefix
216
+ # of up to 63 total chars
217
+ #
218
+ # Provided prefix: variable, max 54
219
+ # Separator: 1
220
+ # Random string: 8
221
+ # ===================
222
+ # Max: 63
223
+ #
224
+ if server_name_prefix.length > 54
225
+ warn 'Server name prefix too long, truncated to 54 characters'
226
+ server_name_prefix = server_name_prefix[0..53]
227
+ end
228
+
229
+ server_name_prefix.gsub!(/\W/, '')
230
+
231
+ if server_name_prefix.empty?
232
+ warn 'Server name prefix empty or invalid; using fully generated name'
233
+ default_name
234
+ else
235
+ random_suffix = ('a'..'z').to_a.shuffle[0, 8].join
236
+ server_name_prefix + '-' + random_suffix
237
+ end
238
+ end
239
+
201
240
  def attach_ip_from_pool(server, pool)
202
241
  @@ip_pool_lock.synchronize do
203
242
  info "Attaching floating IP from <#{pool}> pool"
@@ -265,8 +304,7 @@ module Kitchen
265
304
  end
266
305
 
267
306
  def setup_ssh(server, state)
268
- wait_for_sshd(state[:hostname], config[:username], port: config[:port])
269
- info '(ssh ready)'
307
+ tcp_check(state)
270
308
  if config[:key_name]
271
309
  info "Using OpenStack keypair <#{config[:key_name]}>"
272
310
  end
@@ -289,6 +327,19 @@ module Kitchen
289
327
  ])
290
328
  end
291
329
 
330
+ def tcp_check(state)
331
+ # allow driver config to bypass SSH tcp check -- because
332
+ # it doesn't respect ssh_config values that might be required
333
+ if config[:no_ssh_tcp_check]
334
+ sleep(config[:no_ssh_tcp_check_sleep])
335
+ else
336
+ wait_for_sshd(state[:hostname],
337
+ config[:username],
338
+ port: config[:port])
339
+ end
340
+ info '(ssh ready)'
341
+ end
342
+
292
343
  def disable_ssl_validation
293
344
  require 'excon'
294
345
  Excon.defaults[:ssl_verify_peer] = false
@@ -21,6 +21,6 @@ module Kitchen
21
21
  #
22
22
  # @author Jonathan Hartman <j@p4nt5.com>
23
23
  module Driver
24
- OPENSTACK_VERSION = '1.6.1'
24
+ OPENSTACK_VERSION = '1.7.0'
25
25
  end
26
26
  end
@@ -53,6 +53,14 @@ describe Kitchen::Driver::Openstack do
53
53
 
54
54
  describe '#initialize'do
55
55
  context 'default options' do
56
+ it 'uses the normal SSH status check' do
57
+ expect(driver[:no_ssh_tcp_check]).to eq(false)
58
+ end
59
+
60
+ it 'sets a default TCP check wait time' do
61
+ expect(driver[:no_ssh_tcp_check_sleep]).to eq(120)
62
+ end
63
+
56
64
  context 'both DSA and RSA SSH keys available for the user' do
57
65
  it 'prefers the local user\'s RSA private key' do
58
66
  expect(driver[:private_key_path]).to eq(rsa)
@@ -105,6 +113,8 @@ describe Kitchen::Driver::Openstack do
105
113
  :openstack_service_name,
106
114
  :floating_ip_pool,
107
115
  :floating_ip,
116
+ :availability_zone,
117
+ :security_groups,
108
118
  :network_ref
109
119
  ]
110
120
  nils.each do |i|
@@ -123,6 +133,7 @@ describe Kitchen::Driver::Openstack do
123
133
  username: 'admin',
124
134
  port: '2222',
125
135
  server_name: 'puppy',
136
+ server_name_prefix: 'parsnip',
126
137
  openstack_tenant: 'that_one',
127
138
  openstack_region: 'atlantis',
128
139
  openstack_service_name: 'the_service',
@@ -139,6 +150,10 @@ describe Kitchen::Driver::Openstack do
139
150
  expect(drv[k]).to eq(v)
140
151
  end
141
152
  end
153
+
154
+ it 'overrides server name prefix with explicit server name, if given' do
155
+ expect(driver[:server_name]).to eq(config[:server_name])
156
+ end
142
157
  end
143
158
  end
144
159
 
@@ -354,6 +369,7 @@ describe Kitchen::Driver::Openstack do
354
369
  server_name: 'hello',
355
370
  image_ref: '111',
356
371
  flavor_ref: '1',
372
+ availability_zone: nil,
357
373
  public_key_path: 'tarpals'
358
374
  }
359
375
  end
@@ -403,6 +419,7 @@ describe Kitchen::Driver::Openstack do
403
419
  server_name: 'hello',
404
420
  image_ref: '111',
405
421
  flavor_ref: '1',
422
+ availability_zone: nil,
406
423
  public_key_path: 'tarpals'
407
424
  }
408
425
  end
@@ -422,6 +439,7 @@ describe Kitchen::Driver::Openstack do
422
439
  server_name: 'hello',
423
440
  image_ref: '111',
424
441
  flavor_ref: '1',
442
+ availability_zone: nil,
425
443
  public_key_path: 'montgomery',
426
444
  key_name: 'tarpals'
427
445
  }
@@ -443,6 +461,7 @@ describe Kitchen::Driver::Openstack do
443
461
  server_name: 'hello',
444
462
  image_ref: '111',
445
463
  flavor_ref: '1',
464
+ availability_zone: nil,
446
465
  public_key_path: 'montgomery',
447
466
  key_name: 'tarpals',
448
467
  security_groups: ['ping-and-ssh']
@@ -459,6 +478,28 @@ describe Kitchen::Driver::Openstack do
459
478
  end
460
479
  end
461
480
 
481
+ context 'a provided availability zone' do
482
+ let(:config) do
483
+ {
484
+ server_name: 'hello',
485
+ image_ref: '111',
486
+ flavor_ref: '1',
487
+ availability_zone: 'elsewhere',
488
+ public_key_path: 'montgomery',
489
+ key_name: 'tarpals'
490
+ }
491
+ end
492
+
493
+ before(:each) do
494
+ @expected = config.merge(name: config[:server_name])
495
+ @expected.delete_if { |k, _| k == :server_name }
496
+ end
497
+
498
+ it 'passes that availability zone to Fog' do
499
+ expect(driver.send(:create_server)).to eq(@expected)
500
+ end
501
+ end
502
+
462
503
  context 'image/flavor specifies id' do
463
504
  let(:config) do
464
505
  {
@@ -473,6 +514,7 @@ describe Kitchen::Driver::Openstack do
473
514
  expect(servers).to receive(:create).with(name: 'hello',
474
515
  image_ref: '111',
475
516
  flavor_ref: '1',
517
+ availability_zone: nil,
476
518
  public_key_path: 'tarpals')
477
519
  driver.send(:create_server)
478
520
  end
@@ -492,6 +534,7 @@ describe Kitchen::Driver::Openstack do
492
534
  expect(servers).to receive(:create).with(name: 'hello',
493
535
  image_ref: '222',
494
536
  flavor_ref: '2',
537
+ availability_zone: nil,
495
538
  public_key_path: 'tarpals')
496
539
  driver.send(:create_server)
497
540
  end
@@ -512,6 +555,7 @@ describe Kitchen::Driver::Openstack do
512
555
  expect(servers).to receive(:create).with(name: 'hello',
513
556
  image_ref: '222',
514
557
  flavor_ref: '1',
558
+ availability_zone: nil,
515
559
  public_key_path: 'tarpals')
516
560
  driver.send(:create_server)
517
561
  end
@@ -536,6 +580,7 @@ describe Kitchen::Driver::Openstack do
536
580
  name: 'hello',
537
581
  image_ref: '111',
538
582
  flavor_ref: '1',
583
+ availability_zone: nil,
539
584
  public_key_path: 'tarpals',
540
585
  nics: networks
541
586
  )
@@ -562,6 +607,7 @@ describe Kitchen::Driver::Openstack do
562
607
  name: 'hello',
563
608
  image_ref: '111',
564
609
  flavor_ref: '1',
610
+ availability_zone: nil,
565
611
  public_key_path: 'tarpals',
566
612
  nics: networks
567
613
  )
@@ -589,6 +635,7 @@ describe Kitchen::Driver::Openstack do
589
635
  name: 'hello',
590
636
  image_ref: '111',
591
637
  flavor_ref: '1',
638
+ availability_zone: nil,
592
639
  public_key_path: 'tarpals',
593
640
  nics: networks
594
641
  )
@@ -618,6 +665,7 @@ describe Kitchen::Driver::Openstack do
618
665
  name: 'hello',
619
666
  image_ref: '111',
620
667
  flavor_ref: '1',
668
+ availability_zone: nil,
621
669
  public_key_path: 'tarpals',
622
670
  user_data: data)
623
671
  driver.send(:create_server)
@@ -679,6 +727,53 @@ describe Kitchen::Driver::Openstack do
679
727
  end
680
728
  end
681
729
 
730
+ describe '#server_name_prefix' do
731
+ let(:login) { 'user' }
732
+ let(:hostname) { 'host' }
733
+ let(:prefix) { 'parsnip' }
734
+
735
+ # These are still used in the "blank prefix" test
736
+ before(:each) do
737
+ allow(Etc).to receive(:getlogin).and_return(login)
738
+ allow(Socket).to receive(:gethostname).and_return(hostname)
739
+ end
740
+
741
+ it 'generates a name with the selected prefix' do
742
+ expect(driver.send(:server_name_prefix, prefix))
743
+ .to match(/^parsnip-(\S*)/)
744
+ end
745
+
746
+ context 'very long prefix provided' do
747
+ let(:long_prefix) { 'a' * 70 }
748
+
749
+ it 'limits the generated name to 63 characters' do
750
+ expect(driver.send(:server_name_prefix, long_prefix).length)
751
+ .to be <= (63)
752
+ end
753
+ end
754
+
755
+ context 'a prefix with punctuation' do
756
+ let(:bad_char_prefix) { 'pa-rsn.ip' }
757
+
758
+ it 'strips out the dots to prevent bad server names' do
759
+ expect(driver.send(:server_name_prefix, bad_char_prefix))
760
+ .to_not include('.')
761
+ end
762
+
763
+ it 'strips out all but the one hyphen separator' do
764
+ expect(driver.send(:server_name_prefix, bad_char_prefix)
765
+ .count('-')).to eq(1)
766
+ end
767
+ end
768
+
769
+ context 'blank prefix' do
770
+ it 'generates fully random server name' do
771
+ expect(driver.send(:server_name_prefix, ''))
772
+ .to match(/potatoes-user-host-(\S*)/)
773
+ end
774
+ end
775
+ end
776
+
682
777
  describe '#attach_ip_from_pool' do
683
778
  let(:server) { nil }
684
779
  let(:pool) { 'swimmers' }
@@ -978,6 +1073,43 @@ describe Kitchen::Driver::Openstack do
978
1073
  end
979
1074
  end
980
1075
 
1076
+ describe '#setup_ssh' do
1077
+ let(:server) { double }
1078
+ before(:each) do
1079
+ [:tcp_check, :do_ssh_setup].each do |m|
1080
+ allow_any_instance_of(described_class).to receive(m)
1081
+ end
1082
+ end
1083
+
1084
+ it 'calls the TCP check' do
1085
+ expect_any_instance_of(described_class).to receive(:tcp_check).with(state)
1086
+ driver.send(:setup_ssh, server, state)
1087
+ end
1088
+ end
1089
+
1090
+ describe '#tcp_check' do
1091
+ let(:state) { { hostname: 'hostname' } }
1092
+
1093
+ context 'standard SSH check' do
1094
+ it 'calls the normal Kitchen SSH wait' do
1095
+ expect_any_instance_of(described_class).not_to receive(:sleep)
1096
+ expect_any_instance_of(described_class).to receive(:wait_for_sshd)
1097
+ .with('hostname', 'root', port: '22')
1098
+ driver.send(:tcp_check, state)
1099
+ end
1100
+ end
1101
+
1102
+ context 'override SSH wait' do
1103
+ let(:config) { { no_ssh_tcp_check: true } }
1104
+
1105
+ it 'sleeps instead of monitoring the SSH port' do
1106
+ expect_any_instance_of(described_class).not_to receive(:wait_for_sshd)
1107
+ expect_any_instance_of(described_class).to receive(:sleep).with(120)
1108
+ driver.send(:tcp_check, state)
1109
+ end
1110
+ end
1111
+ end
1112
+
981
1113
  describe '#disable_ssl_validation' do
982
1114
  it 'turns off Excon SSL cert validation' do
983
1115
  expect(driver.send(:disable_ssl_validation)).to eq(false)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-openstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Hartman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen