kitchen-openstack 1.7.1 → 1.8.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: ada2dfc8390553bc3b419e50b3561a97a52dcb18
4
- data.tar.gz: 91b3b46bd248411691f9bff8fa424c3225580cc9
3
+ metadata.gz: 140b00aba886334a4da296bc6d3e6fb8777f002c
4
+ data.tar.gz: 1220ac0c3fa7569c320a732923bbe37704227517
5
5
  SHA512:
6
- metadata.gz: cbf3719c9a0baf7c0e54a8618598525be1484910efe0a8d1ec3714a0c9fc3a8b705bc9776db5b2ece5f1e5b532334db814ad2e601a4b5c326a35c5cbb699a493
7
- data.tar.gz: e4af2de8a2b0433441a58e50bad8557c63800d18bc07cc45633dadac0878808100e1581c8c20b39499a44b5101c054934b14e762069f278b6be557c1300debb2
6
+ metadata.gz: e4c827d8f26500ac3cf9650d56db7202c5616e4da400ef0ce5d78943bab7bfa305422a46e8cb0683c86421d1baa7d6f144a25690d11a8b032e0cb3fb0f0b9a13
7
+ data.tar.gz: 8e780867cc2b7b8163fb3fbb6b144fae3329028cfc07aaa2a505f00ee0aa833300083d06a1980575db46d15239df1843509387c51ae4487aacbe179333061105
data/.travis.yml CHANGED
@@ -3,7 +3,20 @@ cache: bundler
3
3
 
4
4
  sudo: false
5
5
 
6
+ gemfile:
7
+ - Gemfile
8
+ - Gemfile.ohai-7
9
+
6
10
  rvm:
7
11
  - 1.9.3
8
12
  - 2.0.0
9
13
  - ruby-head
14
+
15
+ matrix:
16
+ exclude:
17
+ - rvm: 1.9.3
18
+ gemfile: Gemfile
19
+ - rvm: 2.0.0
20
+ gemfile: Gemfile.ohai-7
21
+ - rvm: ruby-head
22
+ gemfile: Gemfile.ohai-7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.8.0 / 2015-04-08
2
+
3
+ ### New Features
4
+
5
+ * PR [#74][] - Support attaching block storage volumes; via [@LiamHaworth][]
6
+
1
7
  # 1.7.1 / 2015-01-07
2
8
 
3
9
  * PR [#70][] - Use configured password for SSH access, if provided
@@ -138,6 +144,7 @@ certain specified NICs; via [@monsterzz][]
138
144
 
139
145
  * Initial release! Woo!
140
146
 
147
+ [#74]: https://github.com/test-kitchen/kitchen-openstack/pull/74
141
148
  [#70]: https://github.com/test-kitchen/kitchen-openstack/pull/70
142
149
  [#66]: https://github.com/test-kitchen/kitchen-openstack/pull/66
143
150
  [#63]: https://github.com/test-kitchen/kitchen-openstack/pull/63
@@ -170,6 +177,7 @@ certain specified NICs; via [@monsterzz][]
170
177
  [#7]: https://github.com/test-kitchen/kitchen-openstack/pull/7
171
178
  [#2]: https://github.com/test-kitchen/kitchen-openstack/pull/2
172
179
 
180
+ [@LiamHaworth]: https://github.com/LiamHaworth
173
181
  [@ftclausen]: https://github.com/ftclausen
174
182
  [@fortable1999]: https://github.com/fortable1999
175
183
  [@stevejmason]: https://github.com/stevejmason
data/Gemfile.ohai-7 ADDED
@@ -0,0 +1,8 @@
1
+ # Encoding: UTF-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'ohai', '~> 7.0'
6
+
7
+ # Specify your gem's dependencies in kitchen-openstack.gemspec
8
+ gemspec
data/README.md CHANGED
@@ -66,7 +66,16 @@ behavior can be overridden with additional options:
66
66
  - [...ID TO CREATE INSTANCE WITH]
67
67
  no_ssh_tcp_check: [DEFAULTS TO false, SKIPS TCP CHECK WHEN true]
68
68
  no_ssh_tcp_check_sleep: [NUM OF SECONDS TO SLEEP IF no_ssh_tcp_check IS SET]
69
-
69
+ block_device_mapping:
70
+ make_volume: [DEFAULTS TO false, MAKES A NEW VOLUME WHEN true]
71
+ snapshot_id: [WHEN SET WILL MAKE VOLUME FROM VOLUME SNAPSHOT]
72
+ volume_id: [WILL ATTACH VOLUME WHEN SET]
73
+ volume_size: [THE SIZE OF THE VOLUME TO BE ATTACHED/MADE]
74
+ device_name: [SET TO vda UNLESS YOU KNOW WHAT YOU ARE DOING]
75
+ availability_zone: [THE BLOCK STORAGE AVAILABILITY ZONE, DEFAULTS TO nova]
76
+ volume_type: [THE VOLUME TYPE, THIS IS OPTIONAL]
77
+ delete_on_termination: [WILL DELETE VOLUME ON INSTANCE DESTROY WHEN true, OTHERWISE SET TO false]
78
+
70
79
  If a `server_name_prefix` is specified then this prefix will be used when
71
80
  generating random names of the form `<NAME PREFIX>-<RANDOM STRING>` e.g.
72
81
  `myproject-asdfghjk`. If both `server_name_prefix` and `server_name` are
@@ -15,13 +15,13 @@ Gem::Specification.new do |spec|
15
15
  spec.license = 'Apache'
16
16
 
17
17
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
- spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(/^(test|spec|features)\//)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.required_ruby_version = '>= 1.9.3'
23
23
 
24
- spec.add_dependency 'test-kitchen', '~> 1.1'
24
+ spec.add_dependency 'test-kitchen', '~> 1.2'
25
25
  spec.add_dependency 'fog', '~> 1.18'
26
26
  # Newer Fogs throw a warning if unf isn't there :(
27
27
  spec.add_dependency 'unf'
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author:: Jonathan Hartman (<j@p4nt5.com>)
4
4
  #
5
- # Copyright (C) 2013, Jonathan Hartman
5
+ # Copyright (C) 2013-2015, Jonathan Hartman
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ require 'etc'
23
23
  require 'ipaddr'
24
24
  require 'socket'
25
25
  require 'ohai'
26
+ require_relative 'openstack/volume'
26
27
 
27
28
  module Kitchen
28
29
  module Driver
@@ -59,6 +60,7 @@ module Kitchen
59
60
  default_config :network_ref, nil
60
61
  default_config :no_ssh_tcp_check, false
61
62
  default_config :no_ssh_tcp_check_sleep, 120
63
+ default_config :block_device_mapping, nil
62
64
 
63
65
  def create(state)
64
66
  unless config[:server_name]
@@ -129,6 +131,14 @@ module Kitchen
129
131
  Fog::Compute.new(openstack_server)
130
132
  end
131
133
 
134
+ def volume
135
+ Volume.new
136
+ end
137
+
138
+ def get_bdm(config)
139
+ volume.get_bdm(config, openstack_server)
140
+ end
141
+
132
142
  def create_server
133
143
  server_def = init_configuration
134
144
 
@@ -139,6 +149,10 @@ module Kitchen
139
149
  end
140
150
  end
141
151
 
152
+ if config[:block_device_mapping]
153
+ server_def[:block_device_mapping] = get_bdm(config)
154
+ end
155
+
142
156
  [
143
157
  :security_groups,
144
158
  :public_key_path,
@@ -233,7 +247,7 @@ module Kitchen
233
247
  warn 'Server name prefix empty or invalid; using fully generated name'
234
248
  default_name
235
249
  else
236
- random_suffix = ('a'..'z').to_a.shuffle[0, 8].join
250
+ random_suffix = ('a'..'z').to_a.sample(8).join
237
251
  server_name_prefix + '-' + random_suffix
238
252
  end
239
253
  end
@@ -0,0 +1,68 @@
1
+ # Encoding: UTF-8
2
+ #
3
+ # Author:: Jonathan Hartman (<j@p4nt5.com>)
4
+ #
5
+ # Copyright (C) 2013-2015, Jonathan Hartman
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'fog'
20
+ require 'kitchen'
21
+
22
+ module Kitchen
23
+ module Driver
24
+ class Openstack < Kitchen::Driver::SSHBase
25
+ # A class to allow the Kitchen Openstack driver
26
+ # to use Openstack volumes
27
+ #
28
+ # @author Liam Haworth <liam.haworth@bluereef.com.au>
29
+ class Volume
30
+ def volume(openstack_server)
31
+ Fog::Volume.new(openstack_server)
32
+ end
33
+
34
+ def volume_ready?(vol_id, os)
35
+ resp = volume(os).get_volume_details(vol_id)
36
+ status = resp[:body]['volume']['status']
37
+ fail "Failed to make volume <#{vol_id}>" if status == 'error'
38
+ status == 'available'
39
+ end
40
+
41
+ def create_volume(config, os)
42
+ opt = {}
43
+ bdm = config[:block_device_mapping]
44
+ vanilla_options = [:snapshot_id, :imageRef, :volume_type,
45
+ :source_volid, :availability_zone]
46
+ vanilla_options.select { |o| bdm[o] }.each do |key|
47
+ opt[key] = bdm[key]
48
+ end
49
+ resp = volume(os).create_volume("#{config[:server_name]}-volume",
50
+ "#{config[:server_name]} volume",
51
+ bdm[:volume_size],
52
+ opt)
53
+ vol_id = resp[:body]['volume']['id']
54
+ sleep(1) until volume_ready?(vol_id, os)
55
+ vol_id
56
+ end
57
+
58
+ def get_bdm(config, os)
59
+ bdm = config[:block_device_mapping]
60
+ bdm[:volume_id] = create_volume(config, os) if bdm[:make_volume]
61
+ bdm.delete_if { |k, _| k == :make_volume }
62
+ bdm.delete_if { |k, _| k == :snapshot_id }
63
+ bdm
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -21,6 +21,6 @@ module Kitchen
21
21
  #
22
22
  # @author Jonathan Hartman <j@p4nt5.com>
23
23
  module Driver
24
- OPENSTACK_VERSION = '1.7.1'
24
+ OPENSTACK_VERSION = '1.8.0'
25
25
  end
26
26
  end
@@ -0,0 +1,121 @@
1
+ # Encoding: UTF-8
2
+
3
+ require_relative '../../../spec_helper'
4
+ require_relative '../../../../lib/kitchen/driver/openstack/volume'
5
+
6
+ require 'logger'
7
+ require 'stringio'
8
+ require 'rspec'
9
+ require 'kitchen'
10
+ require 'ohai'
11
+
12
+ describe Kitchen::Driver::Openstack::Volume do
13
+ let(:os) do
14
+ {
15
+ openstack_username: 'twilight',
16
+ openstack_api_key: 'sparkle',
17
+ openstack_auth_url: 'http:',
18
+ openstack_tenant: 'trixie',
19
+ openstack_region: 'syd',
20
+ openstack_service_name: 'the_service'
21
+ }
22
+ end
23
+
24
+ describe '#volume' do
25
+ let(:vol_driver) do
26
+ described_class.new
27
+ end
28
+
29
+ it 'creates a new block device connection' do
30
+ allow(Fog::Volume).to receive(:new) { |arg| arg }
31
+ expect(vol_driver.send(:volume, os)).to eq(os)
32
+ end
33
+ end
34
+
35
+ describe '#volume_ready?' do
36
+ let(:volume_details) do
37
+ {
38
+ body: { 'volume' => { 'status' => 'available' } }
39
+ }
40
+ end
41
+
42
+ let(:volume) do
43
+ double(
44
+ get_volume_details: volume_details
45
+ )
46
+ end
47
+
48
+ let(:vol_driver) do
49
+ d = described_class.new
50
+ allow(d).to receive(:volume).and_return(volume)
51
+ d
52
+ end
53
+
54
+ it 'checks if the volume is ready' do
55
+ expect(vol_driver.send(:volume_ready?, '333', os)).to eq(true)
56
+ end
57
+ end
58
+
59
+ describe '#create_volume' do
60
+ let(:config) do
61
+ {
62
+ server_name: 'applejack',
63
+ block_device_mapping: {
64
+ snapshot_id: '444',
65
+ volume_size: '5'
66
+ }
67
+ }
68
+ end
69
+
70
+ let(:create_volume) do
71
+ {
72
+ body: { 'volume' => { 'id' => '555' } }
73
+ }
74
+ end
75
+
76
+ let(:volume) do
77
+ double(
78
+ create_volume: create_volume
79
+ )
80
+ end
81
+
82
+ let(:vol_driver) do
83
+ d = described_class.new
84
+ allow(d).to receive(:volume).and_return(volume)
85
+ allow(d).to receive(:volume_ready?).and_return(true)
86
+ d
87
+ end
88
+
89
+ it 'creates a volume' do
90
+ expect(vol_driver.send(:create_volume, config, os)).to eq('555')
91
+ end
92
+ end
93
+
94
+ describe '#get_bdm' do
95
+ let(:config) do
96
+ {
97
+ block_device_mapping: {
98
+ make_volue: true,
99
+ snapshot_id: '333',
100
+ volume_id: '555',
101
+ volume_size: '5',
102
+ volume_device_name: 'vda',
103
+ delete_on_termination: true
104
+ }
105
+ }
106
+ end
107
+
108
+ let(:vol_driver) do
109
+ d = described_class.new
110
+ allow(d).to receive(:create_volume).and_return('555')
111
+ d
112
+ end
113
+
114
+ it 'returns the block device mapping config' do
115
+ expects = config[:block_device_mapping]
116
+ expects.delete_if { |k, _| k == :make_volume }
117
+ expects.delete_if { |k, _| k == :snapshot_id }
118
+ expect(vol_driver.send(:get_bdm, config, os)).to eq(expects)
119
+ end
120
+ end
121
+ end
@@ -1,22 +1,7 @@
1
1
  # Encoding: UTF-8
2
- #
3
- # Author:: Jonathan Hartman (<j@p4nt5.com>)
4
- #
5
- # Copyright (C) 2013, Jonathan Hartman
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
2
 
19
3
  require_relative '../../spec_helper'
4
+ require_relative '../../../lib/kitchen/driver/openstack'
20
5
 
21
6
  require 'logger'
22
7
  require 'stringio'
@@ -39,13 +24,11 @@ describe Kitchen::Driver::Openstack do
39
24
  )
40
25
  end
41
26
 
42
- let(:driver) do
43
- d = Kitchen::Driver::Openstack.new(config)
44
- d.instance = instance
45
- d
46
- end
27
+ let(:driver) { described_class.new(config) }
47
28
 
48
29
  before(:each) do
30
+ allow_any_instance_of(described_class).to receive(:instance)
31
+ .and_return(instance)
49
32
  allow(File).to receive(:exist?).and_call_original
50
33
  allow(File).to receive(:exist?).with(dsa).and_return(true)
51
34
  allow(File).to receive(:exist?).with(rsa).and_return(true)
@@ -140,7 +123,15 @@ describe Kitchen::Driver::Openstack do
140
123
  private_key_path: '/path/to/id_rsa',
141
124
  floating_ip_pool: 'swimmers',
142
125
  floating_ip: '11111',
143
- network_ref: '0xCAFFE'
126
+ network_ref: '0xCAFFE',
127
+ block_device_mapping: {
128
+ make_volume: true,
129
+ snapshot_id: '44',
130
+ volume_id: '55',
131
+ volume_size: '5',
132
+ device_name: 'vda',
133
+ delete_on_termination: true
134
+ }
144
135
  }
145
136
  end
146
137
 
@@ -162,8 +153,7 @@ describe Kitchen::Driver::Openstack do
162
153
  double(id: 'test123', wait_for: true, public_ip_addresses: %w(1.2.3.4))
163
154
  end
164
155
  let(:driver) do
165
- d = Kitchen::Driver::Openstack.new(config)
166
- d.instance = instance
156
+ d = super()
167
157
  allow(d).to receive(:default_name).and_return('a_monkey!')
168
158
  allow(d).to receive(:create_server).and_return(server)
169
159
  allow(d).to receive(:wait_for_sshd).with('1.2.3.4', 'root', port: '22')
@@ -224,8 +214,7 @@ describe Kitchen::Driver::Openstack do
224
214
  let(:compute) { double(servers: servers) }
225
215
 
226
216
  let(:driver) do
227
- d = Kitchen::Driver::Openstack.new(config)
228
- d.instance = instance
217
+ d = super()
229
218
  allow(d).to receive(:compute).and_return(compute)
230
219
  d
231
220
  end
@@ -262,8 +251,7 @@ describe Kitchen::Driver::Openstack do
262
251
  end
263
252
  let(:compute) { double(servers: servers) }
264
253
  let(:driver) do
265
- d = Kitchen::Driver::Openstack.new(config)
266
- d.instance = instance
254
+ d = super()
267
255
  allow(d).to receive(:compute).and_return(compute)
268
256
  d
269
257
  end
@@ -370,7 +358,13 @@ describe Kitchen::Driver::Openstack do
370
358
  image_ref: '111',
371
359
  flavor_ref: '1',
372
360
  availability_zone: nil,
373
- public_key_path: 'tarpals'
361
+ public_key_path: 'tarpals',
362
+ block_device_mapping: {
363
+ volume_size: '5',
364
+ volume_id: '333',
365
+ volume_device_name: 'vda',
366
+ delete_on_termination: 'true'
367
+ }
374
368
  }
375
369
  end
376
370
  let(:servers) do
@@ -394,11 +388,19 @@ describe Kitchen::Driver::Openstack do
394
388
  let(:network) do
395
389
  double(networks: double(all: [vlan1_net, vlan2_net]))
396
390
  end
391
+ let(:block_device_mapping) do
392
+ {
393
+ volume_id: '333',
394
+ volume_size: '5',
395
+ volume_device_name: 'vda',
396
+ delete_on_termination: 'true'
397
+ }
398
+ end
397
399
  let(:driver) do
398
- d = Kitchen::Driver::Openstack.new(config)
399
- d.instance = instance
400
+ d = super()
400
401
  allow(d).to receive(:compute).and_return(compute)
401
402
  allow(d).to receive(:network).and_return(network)
403
+ allow(d).to receive(:get_bdm).and_return(block_device_mapping)
402
404
  d
403
405
  end
404
406
 
@@ -828,8 +830,7 @@ describe Kitchen::Driver::Openstack do
828
830
  let(:ip_addresses) { nil }
829
831
  let(:parsed_ips) { [[], []] }
830
832
  let(:driver) do
831
- d = Kitchen::Driver::Openstack.new(config)
832
- d.instance = instance
833
+ d = super()
833
834
  allow(d).to receive(:parse_ips).and_return(parsed_ips)
834
835
  d
835
836
  end
data/spec/spec_helper.rb CHANGED
@@ -1,21 +1,4 @@
1
1
  # Encoding: UTF-8
2
- #
3
- # Author:: Jonathan Hartman (<j@p4nt5.com>)
4
- #
5
- # Copyright (C) 2013, Jonathan Hartman
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
2
 
20
3
  require 'rspec'
21
4
  require 'simplecov'
@@ -31,5 +14,3 @@ SimpleCov.minimum_coverage 90
31
14
  SimpleCov.start do
32
15
  add_filter '/vendor/'
33
16
  end
34
-
35
- require_relative '../lib/kitchen/driver/openstack'
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.7.1
4
+ version: 1.8.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: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.1'
26
+ version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fog
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -204,12 +204,15 @@ files:
204
204
  - ".travis.yml"
205
205
  - CHANGELOG.md
206
206
  - Gemfile
207
+ - Gemfile.ohai-7
207
208
  - LICENSE.txt
208
209
  - README.md
209
210
  - Rakefile
210
211
  - kitchen-openstack.gemspec
211
212
  - lib/kitchen/driver/openstack.rb
213
+ - lib/kitchen/driver/openstack/volume.rb
212
214
  - lib/kitchen/driver/openstack_version.rb
215
+ - spec/kitchen/driver/openstack/volume_spec.rb
213
216
  - spec/kitchen/driver/openstack_spec.rb
214
217
  - spec/spec_helper.rb
215
218
  homepage: https://github.com/test-kitchen/kitchen-openstack
@@ -237,6 +240,7 @@ signing_key:
237
240
  specification_version: 4
238
241
  summary: A Test Kitchen OpenStack Nova driver
239
242
  test_files:
243
+ - spec/kitchen/driver/openstack/volume_spec.rb
240
244
  - spec/kitchen/driver/openstack_spec.rb
241
245
  - spec/spec_helper.rb
242
246
  has_rdoc: