kitchen-openstack 3.1.0 → 3.2.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: 0b45b8838c9ce9a545a07a8901639a6eb32ddd42
4
- data.tar.gz: 7f1064f7e1b13a831174e2b04c8545f4f22eb4ee
3
+ metadata.gz: e830463daf8d4d150001659002c7ff5fa7c4c4de
4
+ data.tar.gz: c13997f2c1b6ace249a892d02f34e5f9072a1b2e
5
5
  SHA512:
6
- metadata.gz: 4668a5ee747b461c5cf2402f136e82fec77b76e7a43836bd8987c0f3b1054caaaf2e860dd4c3c4776f17e85677220a56a9194d3387b800e6a0e866dd71cfea7a
7
- data.tar.gz: d680ce65e0b59b420afa1375c8c290d50d6141dfdea5bfee781de7e4cd9c89cf4d8adfbd6a18471cf58f7ce4dda32e641258594a3839e821af6fc140e945bc8a
6
+ metadata.gz: 4f4e9a1af44350c69f720ab08c04141a38460a4ade5d0515a3376e18271e3f8ca010dcd8a68afbf281ee89913a8f5654759c5e2c264624b04ad44055f1fae3a0
7
+ data.tar.gz: 7c17dc8168d7ca657373d9ee09da2a25aea19be14caa1b456b92154059c609a57e9c3b209ba46e4bffe0fd44e550b380bea5f95f2aff2a90cd8cf25eec0919e1
data/.gitignore CHANGED
@@ -18,3 +18,6 @@ tmp
18
18
  .kitchen
19
19
  *.sw?
20
20
  *~
21
+ .direnv/
22
+ .envrc
23
+ .ruby-version
data/.rubocop.yml CHANGED
@@ -3,9 +3,13 @@ CyclomaticComplexity:
3
3
  MethodLength:
4
4
  Max: 30
5
5
  ClassLength:
6
- Max: 300
6
+ Max: 320
7
7
  ClassVars:
8
8
  Enabled: false
9
+ BlockLength:
10
+ Enabled: false
11
+ ConditionalAssignment:
12
+ Enabled: false
9
13
  PerceivedComplexity:
10
14
  Max: 10
11
15
  AbcSize:
data/.travis.yml CHANGED
@@ -7,5 +7,6 @@ gemfile:
7
7
  - Gemfile
8
8
 
9
9
  rvm:
10
- - 2.0.0
11
- - ruby-head
10
+ - ruby-head
11
+ - 2.3.1
12
+ - 2.2.5
data/CHANGELOG.md CHANGED
@@ -1,7 +1,25 @@
1
1
  # Change Log
2
2
 
3
- ## [v3.1.0](https://github.com/test-kitchen/kitchen-openstack/tree/v3.1.0)
3
+ ## [v3.2.0](https://github.com/test-kitchen/kitchen-openstack/tree/v3.2.0)
4
4
 
5
+ [Full Changelog](https://github.com/test-kitchen/kitchen-openstack/compare/v3.1.0...v3.2.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - Enhancement: generate openstack keypair on create [\#150](https://github.com/test-kitchen/kitchen-openstack/issues/150)
10
+ - kitchen-openstack should use SSH Agent [\#149](https://github.com/test-kitchen/kitchen-openstack/issues/149)
11
+ - Permission Denied on kitchen runs after first [\#146](https://github.com/test-kitchen/kitchen-openstack/issues/146)
12
+ - Config-drive [\#143](https://github.com/test-kitchen/kitchen-openstack/issues/143)
13
+ - Support Identity v3 [\#137](https://github.com/test-kitchen/kitchen-openstack/issues/137)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Expose excon timeout configuration [\#156](https://github.com/test-kitchen/kitchen-openstack/pull/156) ([MariusCC](https://github.com/MariusCC))
18
+ - Dynamically allocate Floating IP for the test server. [\#155](https://github.com/test-kitchen/kitchen-openstack/pull/155) ([dannytrigo](https://github.com/dannytrigo))
19
+ - Defer ssh key handling to transport. [\#154](https://github.com/test-kitchen/kitchen-openstack/pull/154) ([cliles](https://github.com/cliles))
20
+ - fix failing to get IP when there is no public IP. [\#152](https://github.com/test-kitchen/kitchen-openstack/pull/152) ([onceking](https://github.com/onceking))
21
+
22
+ ## [v3.1.0](https://github.com/test-kitchen/kitchen-openstack/tree/v3.1.0) (2016-06-02)
5
23
  [Full Changelog](https://github.com/test-kitchen/kitchen-openstack/compare/v3.0.0...v3.1.0)
6
24
 
7
25
  **Closed issues:**
@@ -10,6 +28,7 @@
10
28
 
11
29
  **Merged pull requests:**
12
30
 
31
+ - v3.1.0 [\#145](https://github.com/test-kitchen/kitchen-openstack/pull/145) ([jjasghar](https://github.com/jjasghar))
13
32
  - Add config drive [\#144](https://github.com/test-kitchen/kitchen-openstack/pull/144) ([bradkwadsworth](https://github.com/bradkwadsworth))
14
33
  - Update to check IP version when using `openstack\_network\_name`. [\#142](https://github.com/test-kitchen/kitchen-openstack/pull/142) ([nmische](https://github.com/nmische))
15
34
  - minor grammar tweak to sleep message [\#140](https://github.com/test-kitchen/kitchen-openstack/pull/140) ([dpetzel](https://github.com/dpetzel))
data/README.md CHANGED
@@ -104,30 +104,6 @@ specified then the `server_name` takes precedence.
104
104
 
105
105
  If you want to have a static prefix for a random server name.
106
106
 
107
- ### private\_key\_path
108
-
109
- The path to your private ssh key.
110
-
111
- ### public\_key\_path
112
-
113
- The path to your public ssh key.
114
-
115
- If a `key_name` is provided it will be used instead of any
116
- `public_key_path` that is specified.
117
-
118
- If a `key_name` is provided without any `private_key_path`, unexpected
119
- behavior may result if your local RSA/DSA private key doesn't match that
120
- OpenStack key. If you do key injection via `cloud-init` like this issue:
121
- [#77](https://github.com/test-kitchen/kitchen-openstack/issues/77). The
122
- `key_name` should be a blank string if you need to skip it. Example:
123
-
124
- ```yml
125
- driver:
126
- [-- snip --]
127
- key_name: ""
128
- user_data: cloud_init
129
- ```
130
-
131
107
  ### port
132
108
 
133
109
  Set the SSH port for the remote access.
@@ -156,6 +132,13 @@ connections you want declare this.
156
132
  ### glance\_cache\_wait\_timeout
157
133
  When OpenStack downloads the image into cache, it takes extra time to provision. Timeout controls maximum amount of time to wait for machine to move from the Build/Spawn phase to Active.
158
134
 
135
+ ### connect\_timeout
136
+ Connect timeout controls maximum amount of time to wait for machine to respond to ssh login request.
137
+
138
+ ### read\_timeout
139
+ ### write\_timeout
140
+ Expose read/write timeout parameters passed down to HTTP connection created via [excon](https://github.com/excon/excon). Default timeouts (from excon) are 60 seconds.
141
+
159
142
  ### server\_wait
160
143
 
161
144
  `server_wait` is a workaround to deal with how some VMs with `cloud-init`.
@@ -226,6 +209,14 @@ The default is `false`.
226
209
  **Deprecated** You should be using transport now. This will sleep for so many seconds. `no_ssh_tcp_check` needs
227
210
  to be set to `true`.
228
211
 
212
+ ### private\_key\_path
213
+
214
+ **Deprecated** You should be using transport now. The guest image should use `cloud-init` or some other method to fetch key from meta-data service.
215
+
216
+ ### public\_key\_path
217
+
218
+ **Deprecated** You should be using transport now. The guest image should use `cloud-init` or some other method to fetch key from meta-data service.
219
+
229
220
  ## Disk Configuration
230
221
 
231
222
  ### <a name="config-block_device_mapping"></a> block\_device\_mapping
@@ -287,9 +278,16 @@ Any floating IP will be the IP used for Test Kitchen's Remote calls to the node.
287
278
 
288
279
  ### floating\_ip\_pool
289
280
 
290
- A `floating_ip_pool` can be provided to acquire the first free floating ip from
291
- the pool to attach to the instance. It will be the IP used for Test Kitchen's
292
- Remote calls to the node.
281
+ A `floating_ip_pool` can be provided to allocate a floating IP from
282
+ the pool to the instance. If `allocate_floating_ip` is true, the IP will be allocated,
283
+ otherwise the first free floating IP will be used. It will be the IP used for
284
+ Test Kitchen's Remote calls to the node. If allocated, the floating IP will be
285
+ released once the instance is destroyed.
286
+
287
+ ### allocate\_floating\_ip
288
+
289
+ If true, allocate a new IP from the specified `floating_ip_pool` and release is afterwards.
290
+ Otherwise, if false (the default), an existing allocated IP.
293
291
 
294
292
  ### \[public\|private\]\_ip\_order
295
293
 
@@ -368,9 +366,13 @@ driver:
368
366
  require_chef_omnibus: [e.g. 'true' or a version number if you need Chef]
369
367
  image_ref: [SERVER IMAGE ID]
370
368
  flavor_ref: [SERVER FLAVOR ID]
369
+ key_name: [KEY NAME]
370
+ read_timeout: 180
371
+ write_timeout: 180
372
+ connect_timeout: 180
371
373
 
372
374
  transport:
373
- ssh_key: /path/to/id_rsa # probably the same as private_key_path
375
+ ssh_key: /path/to/id_rsa #Path to private key that matches the above openstack key_name
374
376
  connection_timeout: 10
375
377
  connection_retries: 5
376
378
  username: ubuntu
@@ -4,7 +4,7 @@
4
4
  # Author:: JJ Asghar (<jj@chef.io>)
5
5
  #
6
6
  # Copyright (C) 2013-2015, Jonathan Hartman
7
- # Copyright (C) 2015-2016, Chef Inc
7
+ # Copyright (C) 2015-2017, Chef Inc
8
8
  #
9
9
  # Licensed under the Apache License, Version 2.0 (the "License");
10
10
  # you may not use this file except in compliance with the License.
@@ -27,7 +27,8 @@ require_relative 'openstack/volume'
27
27
  module Kitchen
28
28
  module Driver
29
29
  # This takes from the Base Class and creates the OpenStack driver.
30
- class Openstack < Kitchen::Driver::Base # rubocop:disable Metrics/ClassLength, Metrics/LineLength
30
+ # rubocop: disable Metrics/ClassLength
31
+ class Openstack < Kitchen::Driver::Base
31
32
  @@ip_pool_lock = Mutex.new
32
33
 
33
34
  kitchen_driver_api_version 2
@@ -36,15 +37,6 @@ module Kitchen
36
37
  default_config :server_name, nil
37
38
  default_config :server_name_prefix, nil
38
39
  default_config :key_name, nil
39
- default_config :private_key_path do
40
- %w(id_rsa id_dsa).map do |k|
41
- f = File.expand_path("~/.ssh/#{k}")
42
- f if File.exist?(f)
43
- end.compact.first
44
- end
45
- default_config :public_key_path do |driver|
46
- driver[:private_key_path] + '.pub' if driver[:private_key_path]
47
- end
48
40
  default_config :port, '22'
49
41
  default_config :use_ipv6, false
50
42
  default_config :openstack_tenant, nil
@@ -52,6 +44,7 @@ module Kitchen
52
44
  default_config :openstack_service_name, nil
53
45
  default_config :openstack_network_name, nil
54
46
  default_config :floating_ip_pool, nil
47
+ default_config :allocate_floating_ip, false
55
48
  default_config :floating_ip, nil
56
49
  default_config :private_ip_order, 0
57
50
  default_config :public_ip_order, 0
@@ -62,26 +55,19 @@ module Kitchen
62
55
  default_config :no_ssh_tcp_check_sleep, 120
63
56
  default_config :glance_cache_wait_timeout, 600
64
57
  default_config :block_device_mapping, nil
65
-
66
- required_config :private_key_path
67
- required_config :public_key_path do |_, value, driver|
68
- if value.nil? && driver[:key_name].nil?
69
- fail(UserError, # rubocop:disable SignalException
70
- 'Either a `:public_key_path` or `:key_name` is required')
71
- end
72
- end
58
+ default_config :connect_timeout, 60
59
+ default_config :read_timeout, 60
60
+ default_config :write_timeout, 60
73
61
 
74
62
  # Set the proper server name in the config
75
63
  def config_server_name
76
64
  return if config[:server_name]
77
65
 
78
- if config[:server_name_prefix]
79
- config[:server_name] = server_name_prefix(
80
- config[:server_name_prefix]
81
- )
82
- else
83
- config[:server_name] = default_name
84
- end
66
+ config[:server_name] = if config[:server_name_prefix]
67
+ server_name_prefix(config[:server_name_prefix])
68
+ else
69
+ default_name
70
+ end
85
71
  end
86
72
 
87
73
  def create(state)
@@ -119,7 +105,17 @@ module Kitchen
119
105
 
120
106
  disable_ssl_validation if config[:disable_ssl_validation]
121
107
  server = compute.servers.get(state[:server_id])
122
- server.destroy unless server.nil?
108
+
109
+ unless server.nil?
110
+ if config[:floating_ip_pool] && config[:allocate_floating_ip]
111
+ ip = get_ip(server)
112
+ floating_ip_id = network.list_floating_ips(floating_ip_address: ip)
113
+ .body['floatingips'][0]['id']
114
+ network.delete_floating_ip(floating_ip_id)
115
+ info "OpenStack Floating IP <#{ip}> released."
116
+ end
117
+ server.destroy
118
+ end
123
119
  info "OpenStack instance <#{state[:server_id]}> destroyed."
124
120
  state.delete(:server_id)
125
121
  state.delete(:hostname)
@@ -129,10 +125,12 @@ module Kitchen
129
125
 
130
126
  def openstack_server
131
127
  server_def = {
132
- provider: 'OpenStack'
128
+ provider: 'OpenStack',
129
+ connection_options: {}
133
130
  }
134
131
  required_server_settings.each { |s| server_def[s] = config[s] }
135
132
  optional_server_settings.each { |s| server_def[s] = config[s] if config[s] } # rubocop:disable Metrics/LineLength
133
+ connection_options.each { |s| server_def[:connection_options][s] = config[s] if config[s] } # rubocop:disable Metrics/LineLength
136
134
  server_def
137
135
  end
138
136
 
@@ -146,6 +144,10 @@ module Kitchen
146
144
  end - required_server_settings
147
145
  end
148
146
 
147
+ def connection_options
148
+ [:read_timeout, :write_timeout, :connect_timeout]
149
+ end
150
+
149
151
  def network
150
152
  Fog::Network.new(openstack_server)
151
153
  end
@@ -177,7 +179,6 @@ module Kitchen
177
179
 
178
180
  [
179
181
  :security_groups,
180
- :public_key_path,
181
182
  :key_name,
182
183
  :user_data,
183
184
  :config_drive
@@ -278,14 +279,21 @@ module Kitchen
278
279
  def attach_ip_from_pool(server, pool)
279
280
  @@ip_pool_lock.synchronize do
280
281
  info "Attaching floating IP from <#{pool}> pool"
281
- free_addrs = compute.addresses.map do |i|
282
- i.ip if i.fixed_ip.nil? && i.instance_id.nil? && i.pool == pool
283
- end.compact
284
- if free_addrs.empty?
285
- fail ActionFailed, "No available IPs in pool <#{pool}>" # rubocop:disable Metrics/LineLength, SignalException
282
+ if config[:allocate_floating_ip]
283
+ resp = network.create_floating_ip(pool)
284
+ ip = resp.body['floatingip']['floating_ip_address']
285
+ info "Attaching floating IP from <#{pool}> pool"
286
+ config[:floating_ip] = ip
287
+ else
288
+ free_addrs = compute.addresses.map do |i|
289
+ i.ip if i.fixed_ip.nil? && i.instance_id.nil? && i.pool == pool
290
+ end.compact
291
+ if free_addrs.empty?
292
+ fail ActionFailed, "No available IPs in pool <#{pool}>" # rubocop:disable Metrics/LineLength, SignalException
293
+ end
294
+ config[:floating_ip] = free_addrs[0]
286
295
  end
287
- config[:floating_ip] = free_addrs[0]
288
- attach_ip(server, free_addrs[0])
296
+ attach_ip(server, config[:floating_ip])
289
297
  end
290
298
  end
291
299
 
@@ -330,7 +338,7 @@ module Kitchen
330
338
  end
331
339
 
332
340
  pub, priv = get_public_private_ips(server)
333
- priv ||= server.ip_addresses unless pub
341
+ priv = server.ip_addresses if Array(pub).empty? && Array(priv).empty?
334
342
  pub, priv = parse_ips(pub, priv)
335
343
  pub[config[:public_ip_order].to_i] ||
336
344
  priv[config[:private_ip_order].to_i] ||
@@ -339,9 +347,9 @@ module Kitchen
339
347
 
340
348
  def filter_ips(addresses)
341
349
  if config[:use_ipv6]
342
- return addresses.select { |i| IPAddr.new(i['addr']).ipv6? }
350
+ addresses.select { |i| IPAddr.new(i['addr']).ipv6? }
343
351
  else
344
- return addresses.select { |i| IPAddr.new(i['addr']).ipv4? }
352
+ addresses.select { |i| IPAddr.new(i['addr']).ipv4? }
345
353
  end
346
354
  end
347
355
 
@@ -3,7 +3,7 @@
3
3
  # Author:: Jonathan Hartman (<j@p4nt5.com>)
4
4
  #
5
5
  # Copyright (C) 2013-2015, Jonathan Hartman
6
- # Copyright (C) 2015-2016, Chef Software Inc
6
+ # Copyright (C) 2015-2017, Chef Software Inc
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -22,6 +22,6 @@ module Kitchen
22
22
  #
23
23
  # @author Jonathan Hartman <j@p4nt5.com>
24
24
  module Driver
25
- OPENSTACK_VERSION = '3.1.0'.freeze
25
+ OPENSTACK_VERSION = '3.2.0'.freeze
26
26
  end
27
27
  end
@@ -9,6 +9,7 @@ require 'rspec'
9
9
  require 'kitchen'
10
10
  require 'ohai'
11
11
 
12
+ # rubocop: disable Metrics/BlockLength
12
13
  describe Kitchen::Driver::Openstack::Volume do
13
14
  let(:os) do
14
15
  {
@@ -15,13 +15,12 @@ require 'ohai'
15
15
  require 'excon'
16
16
  require 'fog'
17
17
 
18
+ # rubocop: disable Metrics/BlockLength
18
19
  describe Kitchen::Driver::Openstack do
19
20
  let(:logged_output) { StringIO.new }
20
21
  let(:logger) { Logger.new(logged_output) }
21
22
  let(:config) { Hash.new }
22
23
  let(:state) { Hash.new }
23
- let(:dsa) { File.expand_path('~/.ssh/id_dsa') }
24
- let(:rsa) { File.expand_path('~/.ssh/id_rsa') }
25
24
  let(:instance_name) { 'potatoes' }
26
25
  let(:transport) { Kitchen::Transport::Dummy.new }
27
26
  let(:platform) { Kitchen::Platform.new(name: 'fake_platform') }
@@ -43,31 +42,10 @@ describe Kitchen::Driver::Openstack do
43
42
  allow_any_instance_of(described_class).to receive(:instance)
44
43
  .and_return(instance)
45
44
  allow(File).to receive(:exist?).and_call_original
46
- allow(File).to receive(:exist?).with(dsa).and_return(true)
47
- allow(File).to receive(:exist?).with(rsa).and_return(true)
48
45
  end
49
46
 
50
47
  describe '#finalize_config' do
51
48
  before(:each) { allow(File).to receive(:exist?).and_return(false) }
52
-
53
- context 'both private and public key info provided' do
54
- let(:config) do
55
- { private_key_path: '/tmp/key', public_key_path: '/tmp/key.pub' }
56
- end
57
-
58
- it 'raises no error' do
59
- expect(driver.finalize_config!(instance)).to be
60
- end
61
- end
62
-
63
- context 'no key information provided provided' do
64
- let(:config) { {} }
65
-
66
- it 'raises an error' do
67
- expected = Kitchen::UserError
68
- expect { driver.finalize_config!(instance) }.to raise_error(expected)
69
- end
70
- end
71
49
  end
72
50
 
73
51
  describe '#initialize' do
@@ -80,44 +58,16 @@ describe Kitchen::Driver::Openstack do
80
58
  expect(driver[:no_ssh_tcp_check_sleep]).to eq(120)
81
59
  end
82
60
 
83
- context 'both DSA and RSA SSH keys available for the user' do
84
- it 'prefers the local user\'s RSA private key' do
85
- expect(driver[:private_key_path]).to eq(rsa)
86
- end
87
-
88
- it 'prefers the local user\'s RSA public key' do
89
- expect(driver[:public_key_path]).to eq(rsa + '.pub')
90
- end
61
+ it 'sets a default Openstack API read timeout' do
62
+ expect(driver[:read_timeout]).to eq(60)
91
63
  end
92
64
 
93
- context 'only a DSA SSH key available for the user' do
94
- before(:each) do
95
- allow(File).to receive(:exist?).and_return(false)
96
- allow(File).to receive(:exist?).with(dsa).and_return(true)
97
- end
98
-
99
- it 'uses the local user\'s DSA private key' do
100
- expect(driver[:private_key_path]).to eq(dsa)
101
- end
102
-
103
- it 'uses the local user\'s DSA public key' do
104
- expect(driver[:public_key_path]).to eq(dsa + '.pub')
105
- end
65
+ it 'sets a default Openstack API write timeout' do
66
+ expect(driver[:write_timeout]).to eq(60)
106
67
  end
107
68
 
108
- context 'only a RSA SSH key available for the user' do
109
- before(:each) do
110
- allow(File).to receive(:exist?).and_return(false)
111
- allow(File).to receive(:exist?).with(rsa).and_return(true)
112
- end
113
-
114
- it 'uses the local user\'s RSA private key' do
115
- expect(driver[:private_key_path]).to eq(rsa)
116
- end
117
-
118
- it 'uses the local user\'s RSA public key' do
119
- expect(driver[:public_key_path]).to eq(rsa + '.pub')
120
- end
69
+ it 'sets a default ssh connection timeout' do
70
+ expect(driver[:connect_timeout]).to eq(60)
121
71
  end
122
72
 
123
73
  nils = [
@@ -151,10 +101,13 @@ describe Kitchen::Driver::Openstack do
151
101
  openstack_tenant: 'that_one',
152
102
  openstack_region: 'atlantis',
153
103
  openstack_service_name: 'the_service',
154
- private_key_path: '/path/to/id_rsa',
155
104
  floating_ip_pool: 'swimmers',
156
105
  floating_ip: '11111',
157
106
  network_ref: '0xCAFFE',
107
+ use_ssh_agent: true,
108
+ connect_timeout: 123,
109
+ read_timeout: 234,
110
+ write_timeout: 345,
158
111
  block_device_mapping: {
159
112
  make_volume: true,
160
113
  snapshot_id: '44',
@@ -230,7 +183,7 @@ describe Kitchen::Driver::Openstack do
230
183
  # Inside the yield block we are calling ready? So we fake it here
231
184
  allow(d).to receive(:ready?).and_return(true)
232
185
  allow(server).to receive(:wait_for)
233
- .with(an_instance_of(Fixnum)).and_yield
186
+ .with(an_instance_of(Integer)).and_yield
234
187
 
235
188
  allow(d).to receive(:get_ip).and_return('1.2.3.4')
236
189
  allow(d).to receive(:bourne_shell?).and_return(false)
@@ -314,6 +267,39 @@ describe Kitchen::Driver::Openstack do
314
267
  driver.destroy(state)
315
268
  end
316
269
  end
270
+
271
+ context 'Deallocate floating IP' do
272
+ let(:config) do
273
+ {
274
+ floating_ip_pool: 'swimmers',
275
+ allocate_floating_ip: true
276
+ }
277
+ end
278
+ let(:ip) { '1.1.1.1' }
279
+ let(:ip_id) { '123' }
280
+
281
+ let(:network_response) do
282
+ double(body: { 'floatingips' => [{ 'id' => ip_id }] })
283
+ end
284
+
285
+ let(:network) do
286
+ s = double('network')
287
+ expect(s).to receive(:list_floating_ips).with(floating_ip_address: ip).and_return(network_response) # rubocop:disable Metrics/LineLength
288
+ expect(s).to receive(:delete_floating_ip).with(ip_id)
289
+ s
290
+ end
291
+
292
+ let(:driver) do
293
+ d = super()
294
+ allow(d).to receive(:get_ip).and_return(ip)
295
+ allow(d).to receive(:compute).and_return(compute)
296
+ allow(d).to receive(:network).and_return(network)
297
+ d
298
+ end
299
+ it 'deallocates the ip' do
300
+ driver.destroy(state)
301
+ end
302
+ end
317
303
  end
318
304
 
319
305
  describe '#openstack_server' do
@@ -324,7 +310,13 @@ describe Kitchen::Driver::Openstack do
324
310
  openstack_auth_url: 'http://',
325
311
  openstack_tenant: 'me',
326
312
  openstack_region: 'ORD',
327
- openstack_service_name: 'stack'
313
+ openstack_service_name: 'stack',
314
+ connection_options:
315
+ {
316
+ read_timeout: 60,
317
+ write_timeout: 60,
318
+ connect_timeout: 60
319
+ }
328
320
  }
329
321
  end
330
322
 
@@ -360,7 +352,13 @@ describe Kitchen::Driver::Openstack do
360
352
  openstack_auth_url: 'http:',
361
353
  openstack_tenant: 'link',
362
354
  openstack_region: 'ord',
363
- openstack_service_name: 'the_service'
355
+ openstack_service_name: 'the_service',
356
+ connection_options:
357
+ {
358
+ read_timeout: 60,
359
+ write_timeout: 60,
360
+ connect_timeout: 60
361
+ }
364
362
  }
365
363
  end
366
364
 
@@ -402,7 +400,6 @@ describe Kitchen::Driver::Openstack do
402
400
  image_ref: '111',
403
401
  flavor_ref: '1',
404
402
  availability_zone: nil,
405
- public_key_path: 'tarpals',
406
403
  block_device_mapping: {
407
404
  volume_size: '5',
408
405
  volume_id: '333',
@@ -459,26 +456,6 @@ describe Kitchen::Driver::Openstack do
459
456
  end
460
457
  end
461
458
 
462
- context 'a provided public key path' do
463
- let(:config) do
464
- {
465
- server_name: 'hello',
466
- image_ref: '111',
467
- flavor_ref: '1',
468
- availability_zone: nil,
469
- public_key_path: 'tarpals'
470
- }
471
- end
472
- before(:each) do
473
- @expected = config.merge(name: config[:server_name])
474
- @expected.delete_if { |k, _| k == :server_name }
475
- end
476
-
477
- it 'passes that public key path to Fog' do
478
- expect(driver.send(:create_server)).to eq(@expected)
479
- end
480
- end
481
-
482
459
  context 'a provided key name' do
483
460
  let(:config) do
484
461
  {
@@ -486,7 +463,6 @@ describe Kitchen::Driver::Openstack do
486
463
  image_ref: '111',
487
464
  flavor_ref: '1',
488
465
  availability_zone: nil,
489
- public_key_path: 'montgomery',
490
466
  key_name: 'tarpals'
491
467
  }
492
468
  end
@@ -508,7 +484,6 @@ describe Kitchen::Driver::Openstack do
508
484
  image_ref: '111',
509
485
  flavor_ref: '1',
510
486
  availability_zone: nil,
511
- public_key_path: 'montgomery',
512
487
  key_name: 'tarpals',
513
488
  security_groups: ['ping-and-ssh']
514
489
  }
@@ -531,7 +506,6 @@ describe Kitchen::Driver::Openstack do
531
506
  image_ref: '111',
532
507
  flavor_ref: '1',
533
508
  availability_zone: 'elsewhere',
534
- public_key_path: 'montgomery',
535
509
  key_name: 'tarpals'
536
510
  }
537
511
  end
@@ -551,8 +525,7 @@ describe Kitchen::Driver::Openstack do
551
525
  {
552
526
  server_name: 'hello',
553
527
  image_ref: '111',
554
- flavor_ref: '1',
555
- public_key_path: 'tarpals'
528
+ flavor_ref: '1'
556
529
  }
557
530
  end
558
531
 
@@ -560,8 +533,7 @@ describe Kitchen::Driver::Openstack do
560
533
  expect(servers).to receive(:create).with(name: 'hello',
561
534
  image_ref: '111',
562
535
  flavor_ref: '1',
563
- availability_zone: nil,
564
- public_key_path: 'tarpals')
536
+ availability_zone: nil)
565
537
  driver.send(:create_server)
566
538
  end
567
539
  end
@@ -571,8 +543,7 @@ describe Kitchen::Driver::Openstack do
571
543
  {
572
544
  server_name: 'hello',
573
545
  image_ref: 'fedora',
574
- flavor_ref: 'small',
575
- public_key_path: 'tarpals'
546
+ flavor_ref: 'small'
576
547
  }
577
548
  end
578
549
 
@@ -580,8 +551,7 @@ describe Kitchen::Driver::Openstack do
580
551
  expect(servers).to receive(:create).with(name: 'hello',
581
552
  image_ref: '222',
582
553
  flavor_ref: '2',
583
- availability_zone: nil,
584
- public_key_path: 'tarpals')
554
+ availability_zone: nil)
585
555
  driver.send(:create_server)
586
556
  end
587
557
  end
@@ -592,8 +562,7 @@ describe Kitchen::Driver::Openstack do
592
562
  server_name: 'hello',
593
563
  # pass regex as string as yml returns string values
594
564
  image_ref: '/edo/',
595
- flavor_ref: '/in/',
596
- public_key_path: 'tarpals'
565
+ flavor_ref: '/in/'
597
566
  }
598
567
  end
599
568
 
@@ -601,8 +570,7 @@ describe Kitchen::Driver::Openstack do
601
570
  expect(servers).to receive(:create).with(name: 'hello',
602
571
  image_ref: '222',
603
572
  flavor_ref: '1',
604
- availability_zone: nil,
605
- public_key_path: 'tarpals')
573
+ availability_zone: nil)
606
574
  driver.send(:create_server)
607
575
  end
608
576
  end
@@ -613,7 +581,6 @@ describe Kitchen::Driver::Openstack do
613
581
  server_name: 'hello',
614
582
  image_ref: '111',
615
583
  flavor_ref: '1',
616
- public_key_path: 'tarpals',
617
584
  network_ref: '1'
618
585
  }
619
586
  end
@@ -627,7 +594,6 @@ describe Kitchen::Driver::Openstack do
627
594
  image_ref: '111',
628
595
  flavor_ref: '1',
629
596
  availability_zone: nil,
630
- public_key_path: 'tarpals',
631
597
  nics: networks
632
598
  )
633
599
  driver.send(:create_server)
@@ -640,7 +606,6 @@ describe Kitchen::Driver::Openstack do
640
606
  server_name: 'hello',
641
607
  image_ref: '111',
642
608
  flavor_ref: '1',
643
- public_key_path: 'tarpals',
644
609
  network_ref: 'vlan1'
645
610
  }
646
611
  end
@@ -654,7 +619,6 @@ describe Kitchen::Driver::Openstack do
654
619
  image_ref: '111',
655
620
  flavor_ref: '1',
656
621
  availability_zone: nil,
657
- public_key_path: 'tarpals',
658
622
  nics: networks
659
623
  )
660
624
  driver.send(:create_server)
@@ -667,7 +631,6 @@ describe Kitchen::Driver::Openstack do
667
631
  server_name: 'hello',
668
632
  image_ref: '111',
669
633
  flavor_ref: '1',
670
- public_key_path: 'tarpals',
671
634
  network_ref: %w(1 2)
672
635
  }
673
636
  end
@@ -682,7 +645,6 @@ describe Kitchen::Driver::Openstack do
682
645
  image_ref: '111',
683
646
  flavor_ref: '1',
684
647
  availability_zone: nil,
685
- public_key_path: 'tarpals',
686
648
  nics: networks
687
649
  )
688
650
  driver.send(:create_server)
@@ -695,7 +657,6 @@ describe Kitchen::Driver::Openstack do
695
657
  server_name: 'hello',
696
658
  image_ref: '111',
697
659
  flavor_ref: '1',
698
- public_key_path: 'tarpals',
699
660
  user_data: 'cloud-init.txt'
700
661
  }
701
662
  end
@@ -712,7 +673,6 @@ describe Kitchen::Driver::Openstack do
712
673
  image_ref: '111',
713
674
  flavor_ref: '1',
714
675
  availability_zone: nil,
715
- public_key_path: 'tarpals',
716
676
  user_data: data
717
677
  )
718
678
  driver.send(:create_server)
@@ -725,7 +685,6 @@ describe Kitchen::Driver::Openstack do
725
685
  server_name: 'hello',
726
686
  image_ref: '111',
727
687
  flavor_ref: '1',
728
- public_key_path: 'tarpals',
729
688
  config_drive: true
730
689
  }
731
690
  end
@@ -736,7 +695,6 @@ describe Kitchen::Driver::Openstack do
736
695
  image_ref: '111',
737
696
  flavor_ref: '1',
738
697
  availability_zone: nil,
739
- public_key_path: 'tarpals',
740
698
  config_drive: true
741
699
  )
742
700
  driver.send(:create_server)
@@ -876,6 +834,29 @@ describe Kitchen::Driver::Openstack do
876
834
  end
877
835
  end
878
836
 
837
+ describe '#allocate_ip_from_pool' do
838
+ let(:server) { nil }
839
+ let(:pool) { 'swimmers' }
840
+ let(:config) { { allocate_floating_ip: true } }
841
+ let(:ip) { '1.1.1.1' }
842
+ let(:address) do
843
+ double(ip: ip, fixed_ip: nil, instance_id: nil, pool: pool)
844
+ end
845
+ let(:network_response) do
846
+ double(body: { 'floatingip' => { 'floating_ip_address' => ip } })
847
+ end
848
+ let(:network) { double(create_floating_ip: network_response) }
849
+
850
+ before(:each) do
851
+ allow(driver).to receive(:attach_ip).with(server, ip).and_return('bing!')
852
+ allow(driver).to receive(:network).and_return(network)
853
+ end
854
+
855
+ it 'determines an IP to attempt to attach' do
856
+ expect(driver.send(:attach_ip_from_pool, server, pool)).to eq('bing!')
857
+ end
858
+ end
859
+
879
860
  describe '#attach_ip' do
880
861
  let(:ip) { '1.1.1.1' }
881
862
  let(:addresses) { {} }
@@ -1238,12 +1219,10 @@ describe Kitchen::Driver::Openstack do
1238
1219
  openstack_service_name: 'stack',
1239
1220
  image_ref: '22',
1240
1221
  flavor_ref: '33',
1241
- public_key_path: '/tmp',
1242
1222
  username: 'admin',
1243
1223
  port: '2222',
1244
1224
  server_name: 'puppy',
1245
1225
  server_name_prefix: 'parsnip',
1246
- private_key_path: '/path/to/id_rsa',
1247
1226
  floating_ip_pool: 'swimmers',
1248
1227
  floating_ip: '11111',
1249
1228
  network_ref: '0xCAFFE',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-openstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Hartman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-02 00:00:00.000000000 Z
12
+ date: 2017-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-kitchen