kitchen-openstack 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .kitchen
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+
3
+ gemfile:
4
+ - Gemfile
5
+
6
+ rvm:
7
+ - 1.8.7
8
+ - 1.9.2
9
+ - 1.9.3
10
+ - 2.0.0
11
+
12
+ # vim: ai et ts=2 sts=2 sw=2 ft=yaml
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kitchen-openstack.gemspec
4
+ gemspec
5
+
6
+ # vim: ai et ts=2 sts=2 sw=2 ft=ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Jonathan Hartman (<j@p4nt5.com>)
2
+
3
+ Copyright (c) 2013 Jonathan Hartman
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Kitchen::OpenStack
2
+
3
+ An OpenStack Nova driver for Test Kitchen 1.0!
4
+
5
+ Shamelessly copied from [Fletcher Nichol](https://github.com/fnichol)'s
6
+ awesome work on an [EC2 driver](https://github.com/opscode/kitchen-ec2).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'kitchen-openstack'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install kitchen-openstack
21
+
22
+ ## Usage
23
+
24
+ Provide, at a minimum, the required driver options in your `.kitchen.yml` file:
25
+
26
+ driver_plugin: openstack
27
+ driver_config:
28
+ openstack_username: [YOUR OPENSTACK USERNAME]
29
+ openstack_api_key: [YOUR OPENSTACK API KEY]
30
+ openstack_auth_url: [YOUR OPENSTACK AUTH URL]
31
+ openstack_tenant: [YOUR OPENSTACK TENANT ID]
32
+ require_chef_omnibus: latest (if you'll be using Chef)
33
+ image_ref: [SERVER IMAGE ID]
34
+ flavor_ref: [SERVER FLAVOR ID]
35
+
36
+ By default, a unique server name will be generated and the current user's SSH
37
+ key will be used, though that behavior can be overridden with additional
38
+ options:
39
+
40
+ name: [A UNIQUE SERVER NAME]
41
+ public_key_path: [PATH TO YOUR SSH PUBLIC KEY]
42
+ username: [SSH USER]
43
+ port: [SSH PORT]
44
+
45
+ Only disable SSL cert validation if you absolutely know what you are doing,
46
+ but are stuck with an OpenStack deployment without valid SSL certs.
47
+
48
+ disable_ssl_validation: true
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'tailor/rake_task'
3
+ require 'cane/rake_task'
4
+
5
+ desc 'Run Cane to check quality metrics'
6
+ Cane::RakeTask.new
7
+
8
+ desc 'Run Tailor to lint check code'
9
+ Tailor::RakeTask.new
10
+
11
+ desc 'Display LOC stats'
12
+ task :loc do
13
+ puts "\n## LOC Stats"
14
+ sh 'countloc -r lib/kitchen'
15
+ end
16
+
17
+ task :default => [ :cane, :tailor, :loc ]
18
+
19
+ # vim: ai et ts=2 sts=2 sw=2 ft=ruby fdm=marker
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/driver/openstack_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kitchen-openstack'
8
+ spec.version = Kitchen::Driver::OPENSTACK_VERSION
9
+ spec.authors = ['Jonathan Hartman']
10
+ spec.email = ['j@p4nt5.com']
11
+ spec.description = %q{A Test Kitchen OpenStack Nova driver}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/RoboticCheese/kitchen-openstack'
14
+ spec.license = 'Apache'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'test-kitchen', '~> 1.0.0.alpha'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'tailor'
26
+ spec.add_development_dependency 'cane'
27
+ spec.add_development_dependency 'countloc'
28
+ end
29
+
30
+ # vim: ai et ts=2 sts=2 sw=2 ft=ruby
@@ -0,0 +1,105 @@
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
+ require 'benchmark'
20
+ require 'fog'
21
+ require 'kitchen'
22
+ require 'etc'
23
+ require 'socket'
24
+
25
+ module Kitchen
26
+ module Driver
27
+ # Openstack driver for Kitchen.
28
+ #
29
+ # @author Jonathan Hartman <j@p4nt5.com>
30
+ class Openstack < Kitchen::Driver::SSHBase
31
+ default_config :name, nil
32
+ default_config :public_key_path, File.expand_path('~/.ssh/id_dsa.pub')
33
+ default_config :username, 'root'
34
+ default_config :port, '22'
35
+
36
+ def create(state)
37
+ if not config[:name]
38
+ # Generate what should be a unique server name
39
+ config[:name] = "#{instance.name}-#{Etc.getlogin}-" +
40
+ "#{Socket.gethostname}-#{Array.new(8){rand(36).to_s(36)}.join}"
41
+ end
42
+ if config[:disable_ssl_validation]
43
+ require 'excon'
44
+ Excon.defaults[:ssl_verify_peer] = false
45
+ end
46
+ server = create_server
47
+ state[:server_id] = server.id
48
+ info("OpenStack instance <#{state[:server_id]}> created.")
49
+ server.wait_for { print '.'; ready? } ; puts "\n(server ready)"
50
+ if server.addresses['public'] and !server.addresses['public'].empty?
51
+ # server.public_ip_address stopped working in Fog 1.10.0
52
+ state[:hostname] = server.addresses['public'].first['addr']
53
+ else
54
+ state[:hostname] = server.addresses['private'].first['addr']
55
+ end
56
+ # As a consequence of IP weirdness, the OpenStack setup() method is
57
+ # also borked
58
+ ssh = Fog::SSH.new(state[:hostname], config[:username],
59
+ {:password => server.password})
60
+ pub_key = open(config[:public_key_path]).read
61
+ ssh.run([
62
+ %{mkdir .ssh},
63
+ %{echo "#{pub_key}" >> ~/.ssh/authorized_keys},
64
+ %{passwd -l #{config[:username]}}
65
+ ])
66
+ wait_for_sshd(state[:hostname]) ; puts '(ssh ready)'
67
+ rescue Fog::Errors::Error, Excon::Errors::Error => ex
68
+ raise ActionFailed, ex.message
69
+ end
70
+
71
+ def destroy(state)
72
+ return if state[:server_id].nil?
73
+
74
+ server = compute.servers.get(state[:server_id])
75
+ server.destroy unless server.nil?
76
+ info("OpenStack instance <#{state[:server_id]}> destroyed.")
77
+ state.delete(:server_id)
78
+ state.delete(:hostname)
79
+ end
80
+
81
+ private
82
+
83
+ def compute
84
+ Fog::Compute.new(
85
+ :provider => 'OpenStack',
86
+ :openstack_username => config[:openstack_username],
87
+ :openstack_api_key => config[:openstack_api_key],
88
+ :openstack_auth_url => config[:openstack_auth_url],
89
+ :openstack_tenant => config[:openstack_tenant]
90
+ )
91
+ end
92
+
93
+ def create_server
94
+ compute.servers.create(
95
+ :name => config[:name],
96
+ :image_ref => config[:image_ref],
97
+ :flavor_ref => config[:flavor_ref],
98
+ :public_key_path => config[:public_key_path]
99
+ )
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ # vim: ai et ts=2 sts=2 sw=2 ft=ruby
@@ -0,0 +1,26 @@
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
+ module Kitchen
20
+ module Driver
21
+ # Version string for OpenStack Kitchen driver
22
+ OPENSTACK_VERSION = '0.1.0'
23
+ end
24
+ end
25
+
26
+ # vim: ai et ts=2 sts=2 sw=2 ft=ruby
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-openstack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan Hartman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-kitchen
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0.alpha
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0.alpha
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: tailor
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: cane
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: countloc
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A Test Kitchen OpenStack Nova driver
111
+ email:
112
+ - j@p4nt5.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .travis.yml
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - kitchen-openstack.gemspec
124
+ - lib/kitchen/driver/openstack.rb
125
+ - lib/kitchen/driver/openstack_version.rb
126
+ homepage: https://github.com/RoboticCheese/kitchen-openstack
127
+ licenses:
128
+ - Apache
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.23
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: A Test Kitchen OpenStack Nova driver
151
+ test_files: []
152
+ has_rdoc: