kitchen-gce 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *~
2
+ *#
3
+ .ruby-version
4
+ *.gem
5
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source 'https://rubygems.org'
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Andrew Leonard (<andy@hurricane-ridge.com>)
2
+
3
+ Copyright (C) 2013, Andrew Leonard
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,136 @@
1
+ # Kitchen::Gce - A Test Kitchen Driver for Google Compute Engine
2
+
3
+ [![Code Climate](https://codeclimate.com/github/anl/kitchen-gce.png)](https://codeclimate.com/github/anl/kitchen-gce)
4
+
5
+ This is a [Test Kitchen](https://github.com/opscode/test-kitchen/)
6
+ driver for Google Compute Engine. While similar to EC2 and other IaaS
7
+ providers, GCE has a couple of advantages for Chef cookbook testing:
8
+
9
+ * (Subjectively) faster instance launch times; and
10
+ * Sub-hour billing.
11
+
12
+ ## Requirements
13
+
14
+ A [Google Cloud Platform](https://cloud.google.com) account is
15
+ required. If you do not already have an appropriate "project" in
16
+ which to run your test-kitchen instances, create one, noting the
17
+ "project id". Then, within the [Google API
18
+ Console](https://code.google.com/apis/console/), create a "service
19
+ account" for the project under the "API Access" tab. Save the key
20
+ file, and note the email address associated with the service account
21
+ (e.g. <number>@developer.gserviceaccount.com - not the project owner's
22
+ email address).
23
+
24
+ If you have not [set up SSH keys for your GCE
25
+ environment](https://developers.google.com/compute/docs/instances#sshkeys),
26
+ you must also do that prior to using kitchen-gce.
27
+
28
+ ## Installation
29
+
30
+ Assuming you are using Bundler, ensure the Gemfile within your Chef
31
+ cookbook contains at least the following:
32
+
33
+ ```ruby
34
+ source 'https://rubygems.org'
35
+
36
+ gem 'berkshelf'
37
+
38
+ group :integration do
39
+ gem 'test-kitchen', '~> 1.0.0.beta'
40
+ gem 'kitchen-gce'
41
+ end
42
+ ```
43
+
44
+ Then, execute `bundle install`.
45
+
46
+ ## Configuration
47
+
48
+ ### google_client_email
49
+
50
+ **Required** Email address associated with your GCE service account.
51
+ (N.B. - this is not the same as the Google Cloud Platform user's email
52
+ account; should be in the form
53
+ "123456789012@developer.gserviceaccount.com".)
54
+
55
+ ### google_key_location
56
+
57
+ **Required** Path to GCE service account key file.
58
+
59
+ ### google_project
60
+
61
+ **Required** Project ID of the GCE project into which test-kitchen
62
+ instances will be launched.
63
+
64
+ ### image_name
65
+
66
+ **Required** Operating system image to deploy.
67
+
68
+ ### machine_type
69
+
70
+ GCE instance type (size) to launch; default: `n1-standard-1`
71
+
72
+ ### name
73
+
74
+ Name to give to instance; unlike EC2's "Name" tag, this is used as an
75
+ instance identifier and must be unique. Default:
76
+ `test-kitchen-#{Time.now.to_i}`
77
+
78
+ ### username
79
+
80
+ Username to log into instance as; this user is assumed to have access
81
+ to the appropriate SSH keys. Default: `ENV['USER']`
82
+
83
+ ### zone_name
84
+
85
+ Location into which instances will be launched. Default: `us-central1-b`
86
+
87
+ ## Example
88
+
89
+ An example `.kitchen.yml` file using kitchen-gce might look something
90
+ like this:
91
+
92
+ ```ruby
93
+ ---
94
+ driver_plugin: gce
95
+ driver_config:
96
+ google_client_email: "123456789012@developer.gserviceaccount.com"
97
+ google_key_location: "<%= ENV['HOME']%>/gce/1234567890abcdef1234567890abcdef12345678-privatekey.p12"
98
+ google_project: "alpha-bravo-123"
99
+
100
+ platforms:
101
+ - name: debian-7
102
+ driver_config:
103
+ image_name: debian-7-wheezy-v20130926
104
+ require_chef_omnibus: true
105
+
106
+ suites:
107
+ - name: default
108
+ run_list: ["recipe[somecookbook]"]
109
+ attributes: {}
110
+ ```
111
+
112
+ ## Development
113
+
114
+ Source is hosted on [GitHub](https://github.com/anl/kitchen-gce).
115
+
116
+ * Pull requests are welcome, using topic branches if possible:
117
+
118
+ 1. Fork the repo.
119
+ 2. Create a feature branch, commit changes to it and push them.
120
+ 3. Submit a pull request.
121
+
122
+ * Report issues or submit feature requests on [GitHub](https://github.com/anl/kitchen-gce/issues)
123
+
124
+ ## Author, Acknowledgements, Etc.
125
+
126
+ Created and maintained by [Andrew Leonard](http://andyleonard.com)
127
+ ([andy@hurricane-ridge.com](mailto:andy@hurricane-ridge.com)).
128
+
129
+ The initial implementation drew heavily on the
130
+ [kitchen-ec2](https://github.com/opscode/kitchen-ec2/) gem for both
131
+ inspiration and implementation details. Any bugs, however, are solely
132
+ the author's own fault.
133
+
134
+ ## License
135
+
136
+ Apache 2.0.
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'kitchen-gce'
3
+ s.version = '0.0.1'
4
+ s.date = '2013-10-20'
5
+ s.summary = 'Kitchen::Driver::Gce'
6
+ s.description = 'A Test-Kitchen driver for Google Compute Engine'
7
+ s.authors = ['Andrew Leonard']
8
+ s.email = 'andy@hurricane-ridge.com'
9
+ s.files = `git ls-files`.split($/)
10
+ s.homepage = 'https://github.com/anl/kitchen-gce'
11
+ s.license = 'Apache 2.0'
12
+
13
+ s.add_dependency 'test-kitchen', '~> 1.0.0.beta.3'
14
+ s.add_dependency 'fog', '>= 1.11.0'
15
+ s.add_dependency 'google-api-client'
16
+ end
@@ -0,0 +1,80 @@
1
+ # Author:: Andrew Leonard (<andy@hurricane-ridge.com>)
2
+ #
3
+ # Copyright (C) 2013, Andrew Leonard
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.
16
+
17
+ require 'fog'
18
+
19
+ require 'kitchen'
20
+
21
+ module Kitchen
22
+ module Driver
23
+ class Gce < Kitchen::Driver::SSHBase
24
+
25
+ default_config :machine_type, 'n1-standard-1'
26
+ default_config :name, "test-kitchen-#{Time.now.to_i}"
27
+ default_config :username, ENV['USER']
28
+ default_config :zone_name, 'us-central1-b'
29
+
30
+ required_config :google_client_email
31
+ required_config :google_key_location
32
+ required_config :google_project
33
+ required_config :image_name
34
+
35
+ def create(state)
36
+ server= create_instance
37
+ state[:server_id] = server.identity
38
+
39
+ info("GCE instance <#{state[:server_id]}> created.")
40
+ server.wait_for { print '.'; ready? } ; print '(server ready)'
41
+ state[:hostname] = server.public_ip_address || server.private_ip_address
42
+ wait_for_sshd(state[:hostname], config[:username])
43
+ puts '(ssh ready)'
44
+ rescue Fog::Errors::Error, Excon::Errors::Error => ex
45
+ raise ActionFailed, ex.message
46
+ end
47
+
48
+ def destroy(state)
49
+ return if state[:server_id].nil?
50
+
51
+ server = connection.servers.get(state[:server_id])
52
+ server.destroy unless server.nil?
53
+ info("GCE instance <#{state[:server_id]}> destroyed.")
54
+ state.delete(:server_id)
55
+ state.delete(:hostname)
56
+ end
57
+
58
+ private
59
+
60
+ def connection
61
+ Fog::Compute.new({
62
+ :provider => 'google',
63
+ :google_client_email => config[:google_client_email],
64
+ :google_key_location => config[:google_key_location],
65
+ :google_project => config[:google_project],
66
+ })
67
+ end
68
+
69
+ def create_instance
70
+ connection.servers.create({
71
+ :name => config[:name],
72
+ :image_name => config[:image_name],
73
+ :machine_type => config[:machine_type],
74
+ :zone_name => config[:zone_name],
75
+ })
76
+ end
77
+
78
+ end
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-gce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Leonard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-20 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.beta.3
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.beta.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.11.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.11.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: google-api-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
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
+ description: A Test-Kitchen driver for Google Compute Engine
63
+ email: andy@hurricane-ridge.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - Gemfile
70
+ - LICENSE
71
+ - README.md
72
+ - kitchen-gce.gemspec
73
+ - lib/kitchen/driver/gce.rb
74
+ homepage: https://github.com/anl/kitchen-gce
75
+ licenses:
76
+ - Apache 2.0
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.23
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Kitchen::Driver::Gce
99
+ test_files: []