cucumber-chef 3.0.7 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -14,6 +14,5 @@ tmtags
14
14
  \#*
15
15
  .\#*
16
16
  *.swp
17
- .rvmrc
18
17
  *gem
19
18
  .idea/
@@ -0,0 +1 @@
1
+ cucumber-chef
@@ -0,0 +1 @@
1
+ ruby-1.9.3
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- [![Build Status](https://secure.travis-ci.org/zpatten/cucumber-chef.png)](http://travis-ci.org/zpatten/cucumber-chef)
1
+ [![Gem Version](https://badge.fury.io/rb/cucumber-chef.png)](http://badge.fury.io/rb/cucumber-chef)
2
2
  [![Dependency Status](https://gemnasium.com/zpatten/cucumber-chef.png)](https://gemnasium.com/zpatten/cucumber-chef)
3
+ [![Build Status](https://secure.travis-ci.org/zpatten/cucumber-chef.png)](http://travis-ci.org/zpatten/cucumber-chef)
4
+ [![Code Climate](https://codeclimate.com/github/zpatten/cucumber-chef.png)](https://codeclimate.com/github/zpatten/cucumber-chef)
3
5
 
4
6
  Cucumber-chef is a library of tools to enable the emerging discipline of infrastructure as code to practice test driven development. It provides a testing platform within which Cucumber tests can be run which provision virtual machines, configure them by applying the appropriate Chef roles to them, and then run acceptance and integration tests against the environment.
5
7
 
@@ -1,7 +1,7 @@
1
1
  ################################################################################
2
2
  #
3
- # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
- # Author: Zachary Patten <zachary@jovelabs.com>
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systemspec.com>
4
+ # Author: Zachary Patten <zachary@jovelabspec.com>
5
5
  # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
@@ -18,44 +18,41 @@
18
18
  # limitations under the License.
19
19
  #
20
20
  ################################################################################
21
-
22
- require File.expand_path("../lib/cucumber/chef/version", __FILE__)
23
-
24
- Gem::Specification.new do |s|
25
- s.name = "cucumber-chef"
26
- s.version = Cucumber::Chef::VERSION
27
- s.platform = Gem::Platform::RUBY
28
- s.authors = ["Stephen Nelson-Smith", "Zachary Patten"]
29
- s.email = ["stephen@atalanta-systems.com", "zachary@jovelabs.com"]
30
- s.homepage = "http://www.cucumber-chef.org"
31
- s.summary = "Test Driven Infrastructure"
32
- s.description = "Framework for test-driven infrastructure development."
33
- s.required_ruby_version = ">= 1.8.7"
34
- s.required_rubygems_version = ">= 1.3.6"
35
- s.licenses = ["Apache 2.0"]
21
+ lib = File.expand_path('../lib', __FILE__)
22
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
23
+ require 'cucumber/chef/version'
24
+
25
+ Gem::Specification.new do |spec|
26
+ spec.name = "cucumber-chef"
27
+ spec.version = Cucumber::Chef::VERSION
28
+ spec.authors = ["Stephen Nelson-Smith", "Zachary Patten"]
29
+ spec.email = ["stephen@atalanta-systemspec.com", "zachary@jovelabspec.com"]
30
+ spec.description = "Framework for test-driven infrastructure development."
31
+ spec.summary = "Test Driven Infrastructure"
32
+ spec.homepage = "http://www.cucumber-chef.org"
33
+ spec.license = "Apache 2.0"
34
+
35
+ spec.files = `git ls-files`.split($/)
36
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
37
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
38
+ spec.require_paths = ["lib"]
36
39
 
37
40
  # Providers
38
- s.add_dependency("fog", ">= 1.3.1")
41
+ spec.add_dependency("fog", ">= 1.3.1")
39
42
 
40
43
  # TDD
41
- s.add_dependency("cucumber", ">= 0")
42
- s.add_dependency("rspec", ">= 0")
44
+ spec.add_dependency("cucumber")
45
+ spec.add_dependency("rspec")
43
46
 
44
47
  # Support
45
- s.add_dependency("mixlib-config", ">= 1.1.2")
46
- s.add_dependency("rake", ">= 0.9.2")
47
- s.add_dependency("thor", ">= 0.15.2")
48
- s.add_dependency("ubuntu_ami", ">= 0.4.0")
49
- s.add_dependency("ztk", ">= 1.0.9")
50
-
51
- s.add_development_dependency("simplecov", ">= 0.6.4")
52
- s.add_development_dependency("pry", ">= 0")
53
- s.add_development_dependency("yard", ">= 0")
54
- s.add_development_dependency("redcarpet", ">= 0")
55
-
56
- s.files = `git ls-files`.split("\n")
57
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
58
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
59
-
60
- s.require_path = 'lib'
48
+ spec.add_dependency("mixlib-config", ">= 1.1.2")
49
+ spec.add_dependency("rake", ">= 0.9.2")
50
+ spec.add_dependency("thor", ">= 0.15.2")
51
+ spec.add_dependency("ubuntu_ami", ">= 0.4.0")
52
+ spec.add_dependency("ztk", ">= 1.0.9")
53
+
54
+ spec.add_development_dependency("simplecov")
55
+ spec.add_development_dependency("pry")
56
+ spec.add_development_dependency("yard")
57
+ spec.add_development_dependency("redcarpet")
61
58
  end
@@ -25,12 +25,15 @@ module Cucumber
25
25
  class VagrantError < Error; end
26
26
 
27
27
  class Vagrant
28
- # attr_accessor :env, :vm
29
28
 
30
- INVALID_STATES = %w(not_created aborted unknown).map(&:to_sym)
31
- RUNNING_STATES = %w(running).map(&:to_sym)
32
- SHUTDOWN_STATES = %w(paused saved poweroff).map(&:to_sym)
33
- VALID_STATES = RUNNING_STATES+SHUTDOWN_STATES
29
+ INVALID_STATES = %w(not_created aborted unknown).map(&:to_sym)
30
+ RUNNING_STATES = %w(running).map(&:to_sym)
31
+ SHUTDOWN_STATES = %w(paused saved poweroff).map(&:to_sym)
32
+ VALID_STATES = (RUNNING_STATES + SHUTDOWN_STATES)
33
+
34
+ MSG_NO_RUNNING_LAB = %(We could not find a running test lab.)
35
+ MSG_NO_STOPPED_LAB = %(We could not find a powered off test lab.)
36
+ MSG_NO_LAB = %(We could not find a test lab!)
34
37
 
35
38
  ################################################################################
36
39
 
@@ -44,29 +47,27 @@ module Cucumber
44
47
 
45
48
  def create
46
49
  ZTK::Benchmark.bench(:message => "Creating #{Cucumber::Chef::Config.provider.upcase} instance", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
50
+ context = build_create_context
51
+ vagrantfile_template = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "cucumber-chef", "Vagrantfile.erb")
52
+ vagrantfile = File.join(Cucumber::Chef.chef_repo, "Vagrantfile")
47
53
 
48
- context = {
49
- :ip => Cucumber::Chef.lab_ip,
50
- :cpus => Cucumber::Chef::Config.vagrant[:cpus],
51
- :memory => Cucumber::Chef::Config.vagrant[:memory]
52
- }
53
-
54
- vagrantfile_template = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "cucumber-chef", "Vagrantfile.erb")
55
-
56
- vagrantfile = File.join(Cucumber::Chef.chef_repo, "Vagrantfile")
57
-
58
- !File.exists?(vagrantfile) and IO.write(vagrantfile, ::ZTK::Template.render(vagrantfile_template, context))
54
+ if !File.exists?(vagrantfile)
55
+ IO.write(vagrantfile, ::ZTK::Template.render(vagrantfile_template, context))
56
+ end
59
57
 
60
58
  self.vagrant_cli("up", id)
61
59
  ZTK::TCPSocketCheck.new(:host => self.ip, :port => self.port, :wait => 120).wait
62
60
  end
63
61
 
64
62
  self
63
+ end
65
64
 
66
- rescue Exception => e
67
- @ui.logger.fatal { e.message }
68
- @ui.logger.fatal { e.backtrace.join("\n") }
69
- raise VagrantError, e.message
65
+ def build_create_context
66
+ {
67
+ :ip => Cucumber::Chef.lab_ip,
68
+ :cpus => Cucumber::Chef::Config.vagrant[:cpus],
69
+ :memory => Cucumber::Chef::Config.vagrant[:memory]
70
+ }
70
71
  end
71
72
 
72
73
  ################################################################################
@@ -74,16 +75,11 @@ module Cucumber
74
75
  ################################################################################
75
76
 
76
77
  def destroy
77
- if exists?
78
+ if self.exists?
78
79
  self.vagrant_cli("destroy", "--force", id)
79
80
  else
80
- raise VagrantError, "We could not find a test lab!"
81
+ raise VagrantError, MSG_NO_LAB
81
82
  end
82
-
83
- rescue Exception => e
84
- @ui.logger.fatal { e.message }
85
- @ui.logger.fatal { e.backtrace.join("\n") }
86
- raise VagrantError, e.message
87
83
  end
88
84
 
89
85
  ################################################################################
@@ -91,17 +87,12 @@ module Cucumber
91
87
  ################################################################################
92
88
 
93
89
  def up
94
- if (exists? && dead?)
90
+ if self.dead?
95
91
  self.vagrant_cli("up", id)
96
92
  ZTK::TCPSocketCheck.new(:host => self.ip, :port => self.port, :wait => 120).wait
97
93
  else
98
- raise VagrantError, "We could not find a powered off test lab."
94
+ raise VagrantError, MSG_NO_STOPPED_LAB
99
95
  end
100
-
101
- rescue Exception => e
102
- @ui.logger.fatal { e.message }
103
- @ui.logger.fatal { e.backtrace.join("\n") }
104
- raise VagrantError, e.message
105
96
  end
106
97
 
107
98
  ################################################################################
@@ -109,16 +100,11 @@ module Cucumber
109
100
  ################################################################################
110
101
 
111
102
  def down
112
- if (exists? && alive?)
103
+ if self.alive?
113
104
  self.vagrant_cli("halt", id)
114
105
  else
115
- raise AWSError, "We could not find a running test lab."
106
+ raise VagrantError, MSG_NO_RUNNING_LAB
116
107
  end
117
-
118
- rescue Exception => e
119
- @ui.logger.fatal { e.message }
120
- @ui.logger.fatal { e.backtrace.join("\n") }
121
- raise VagrantError, e.message
122
108
  end
123
109
 
124
110
  ################################################################################
@@ -126,16 +112,11 @@ module Cucumber
126
112
  ################################################################################
127
113
 
128
114
  def reload
129
- if (exists? && alive?)
115
+ if self.alive?
130
116
  self.vagrant_cli("reload", id)
131
117
  else
132
- raise AWSError, "We could not find a running test lab."
118
+ raise VagrantError, MSG_NO_RUNNING_LAB
133
119
  end
134
-
135
- rescue Exception => e
136
- @ui.logger.fatal { e.message }
137
- @ui.logger.fatal { e.backtrace.join("\n") }
138
- raise VagrantError, e.message
139
120
  end
140
121
 
141
122
  ################################################################################
@@ -145,11 +126,11 @@ module Cucumber
145
126
  end
146
127
 
147
128
  def alive?
148
- (RUNNING_STATES.include?(self.state) rescue false)
129
+ (self.exists? && (RUNNING_STATES.include?(self.state) rescue false))
149
130
  end
150
131
 
151
132
  def dead?
152
- (SHUTDOWN_STATES.include?(self.state) rescue true)
133
+ (self.exists? && (SHUTDOWN_STATES.include?(self.state) rescue true))
153
134
  end
154
135
 
155
136
  ################################################################################
@@ -87,65 +87,9 @@ module Cucumber
87
87
  raise ProvisionerError, "You must have the environment variable 'USER' set." if !Cucumber::Chef::Config.user
88
88
 
89
89
  ZTK::Benchmark.bench(:message => "Bootstrapping #{Cucumber::Chef::Config.provider.upcase} instance", :mark => "completed in %0.4f seconds.", :ui => @ui) do
90
- server_name = @test_lab.ip
91
-
92
- chef_solo_attributes = case Cucumber::Chef.chef_pre_11
93
- when true then
94
- {
95
- "chef-server" => {
96
- "webui_enabled" => true
97
- },
98
- "run_list" => %w(recipe[chef-server::rubygems-install] recipe[chef-server::apache-proxy] role[test_lab])
99
- }
100
- when false then
101
- {
102
- "chef-server" => {
103
- "api_fqdn" => server_name,
104
- "nginx" => {
105
- "enable_non_ssl" => true,
106
- "server_name" => server_name,
107
- "url" => "https://#{server_name}"
108
- },
109
- "lb" => {
110
- "fqdn" => server_name
111
- },
112
- "bookshelf" => {
113
- "vip" => server_name
114
- },
115
- "chef_server_webui" => {
116
- "enable" => true
117
- },
118
- "version" => Cucumber::Chef::Config.chef[:version],
119
- "prereleases" => Cucumber::Chef::Config.chef[:prereleases],
120
- "nightlies" => Cucumber::Chef::Config.chef[:nightlies]
121
- },
122
- "run_list" => %w(recipe[chef-server::default] role[test_lab])
123
- }
124
- end
125
-
126
- chef_solo_attributes.merge!(
127
- "cucumber_chef" => {
128
- "version" => Cucumber::Chef::VERSION,
129
- "prerelease" => Cucumber::Chef::Config.prerelease,
130
- "lab_user" => Cucumber::Chef.lab_user,
131
- "lxc_user" => Cucumber::Chef.lxc_user
132
- }
133
- )
134
-
135
- context = {
136
- :server_name => server_name,
137
- :lab_user => Cucumber::Chef.lab_user,
138
- :chef_pre_11 => Cucumber::Chef.chef_pre_11,
139
- :chef_solo_attributes => chef_solo_attributes,
140
- :chef_version => Cucumber::Chef::Config.chef[:version],
141
- :chef_validator => (Cucumber::Chef.chef_pre_11 ? '/etc/chef/validation.pem' : '/etc/chef-server/chef-validator.pem'),
142
- :chef_webui => (Cucumber::Chef.chef_pre_11 ? '/etc/chef/webui.pem' : '/etc/chef-server/chef-webui.pem'),
143
- :chef_admin => (Cucumber::Chef.chef_pre_11 ? '/etc/chef/admin.pem' : '/etc/chef-server/admin.pem'),
144
- :default_password => Cucumber::Chef::Config.chef[:default_password],
145
- :user => Cucumber::Chef::Config.user,
146
- :hostname_short => Cucumber::Chef.lab_hostname_short,
147
- :hostname_full => Cucumber::Chef.lab_hostname_full
148
- }
90
+ server_name = @test_lab.ip
91
+ chef_solo_attributes = build_chef_solo_attributes(server_name)
92
+ context = build_context(server_name, chef_solo_attributes)
149
93
 
150
94
  bootstrap_template = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "bootstrap", "ubuntu-precise-omnibus.erb")
151
95
 
@@ -165,6 +109,83 @@ module Cucumber
165
109
  end
166
110
  end
167
111
 
112
+ def build_chef_solo_10_attributes(server_name)
113
+ {
114
+ "chef-server" => {
115
+ "webui_enabled" => true
116
+ },
117
+ "run_list" => %w(recipe[chef-server::rubygems-install] recipe[chef-server::apache-proxy] role[test_lab])
118
+ }
119
+ end
120
+
121
+ def build_chef_solo_11_attributes(server_name)
122
+ {
123
+ "chef-server" => {
124
+ "api_fqdn" => server_name,
125
+ "nginx" => {
126
+ "enable_non_ssl" => true,
127
+ "server_name" => server_name,
128
+ "url" => "https://#{server_name}"
129
+ },
130
+ "lb" => {
131
+ "fqdn" => server_name
132
+ },
133
+ "bookshelf" => {
134
+ "vip" => server_name
135
+ },
136
+ "chef_server_webui" => {
137
+ "enable" => true
138
+ },
139
+ "version" => Cucumber::Chef::Config.chef[:version],
140
+ "prereleases" => Cucumber::Chef::Config.chef[:prereleases],
141
+ "nightlies" => Cucumber::Chef::Config.chef[:nightlies]
142
+ },
143
+ "run_list" => %w(recipe[chef-server::default] role[test_lab])
144
+ }
145
+ end
146
+
147
+ def build_cucumber_chef_attributes(server_name)
148
+ {
149
+ "cucumber_chef" => {
150
+ "version" => Cucumber::Chef::VERSION,
151
+ "prerelease" => Cucumber::Chef::Config.prerelease,
152
+ "lab_user" => Cucumber::Chef.lab_user,
153
+ "lxc_user" => Cucumber::Chef.lxc_user
154
+ }
155
+ }
156
+ end
157
+
158
+ def build_chef_solo_attributes(server_name)
159
+ # TODO: This really should switch on the version number.
160
+ chef_solo_attributes = case Cucumber::Chef.chef_pre_11
161
+ when true then
162
+ build_chef_solo_10_attributes(server_name)
163
+ when false then
164
+ build_chef_solo_11_attributes(server_name)
165
+ end
166
+
167
+ chef_solo_attributes.merge!(build_cucumber_chef_attributes(server_name))
168
+
169
+ chef_solo_attributes
170
+ end
171
+
172
+ def build_context(server_name, chef_solo_attributes)
173
+ {
174
+ :server_name => server_name,
175
+ :lab_user => Cucumber::Chef.lab_user,
176
+ :chef_pre_11 => Cucumber::Chef.chef_pre_11,
177
+ :chef_solo_attributes => chef_solo_attributes,
178
+ :chef_version => Cucumber::Chef::Config.chef[:version],
179
+ :chef_validator => (Cucumber::Chef.chef_pre_11 ? '/etc/chef/validation.pem' : '/etc/chef-server/chef-validator.pem'),
180
+ :chef_webui => (Cucumber::Chef.chef_pre_11 ? '/etc/chef/webui.pem' : '/etc/chef-server/chef-webui.pem'),
181
+ :chef_admin => (Cucumber::Chef.chef_pre_11 ? '/etc/chef/admin.pem' : '/etc/chef-server/admin.pem'),
182
+ :default_password => Cucumber::Chef::Config.chef[:default_password],
183
+ :user => Cucumber::Chef::Config.user,
184
+ :hostname_short => Cucumber::Chef.lab_hostname_short,
185
+ :hostname_full => Cucumber::Chef.lab_hostname_full
186
+ }
187
+ end
188
+
168
189
  ################################################################################
169
190
 
170
191
  def download_chef_credentials
@@ -18,6 +18,13 @@
18
18
  # limitations under the License.
19
19
  #
20
20
  ################################################################################
21
+ require 'cucumber/chef/utility/bootstrap_helper'
22
+ require 'cucumber/chef/utility/chef_helper'
23
+ require 'cucumber/chef/utility/dir_helper'
24
+ require 'cucumber/chef/utility/file_helper'
25
+ require 'cucumber/chef/utility/lab_helper'
26
+ require 'cucumber/chef/utility/log_helper'
27
+ require 'cucumber/chef/utility/lxc_helper'
21
28
 
22
29
  module Cucumber
23
30
  module Chef
@@ -26,6 +33,14 @@ module Cucumber
26
33
 
27
34
  module Utility
28
35
 
36
+ include Cucumber::Chef::Utility::BootstrapHelper
37
+ include Cucumber::Chef::Utility::ChefHelper
38
+ include Cucumber::Chef::Utility::DirHelper
39
+ include Cucumber::Chef::Utility::FileHelper
40
+ include Cucumber::Chef::Utility::LabHelper
41
+ include Cucumber::Chef::Utility::LogHelper
42
+ include Cucumber::Chef::Utility::LXCHelper
43
+
29
44
  ################################################################################
30
45
 
31
46
  def is_rc?
@@ -86,179 +101,31 @@ module Cucumber
86
101
 
87
102
  ################################################################################
88
103
 
89
- def chef_pre_11
90
- return false if (Cucumber::Chef::Config.chef[:version].downcase == "latest")
91
- (Cucumber::Chef::Config.chef[:version].to_f < 11.0)
92
- end
93
-
94
- ################################################################################
95
- # Path Helpers
96
- ################################################################################
97
-
98
- def chef_repo
99
- (Cucumber::Chef.locate_parent(".chef") rescue nil)
100
- end
101
-
102
- def in_chef_repo?
103
- ((chef_repo && File.exists?(chef_repo) && File.directory?(chef_repo)) ? true : false)
104
- end
105
-
106
- ################################################################################
107
-
108
- def root_dir
109
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", ".."), File.dirname(__FILE__))
104
+ def provider_config
105
+ Cucumber::Chef::Config[Cucumber::Chef::Config.provider]
110
106
  end
111
107
 
112
- ################################################################################
113
-
114
- def home_dir
115
- home_dir = (ENV['CUCUMBER_CHEF_HOME'] || File.join(Cucumber::Chef.locate_parent(".chef"), ".cucumber-chef"))
116
- FileUtils.mkdir_p(File.dirname(home_dir))
117
- home_dir
118
- end
119
-
120
- ################################################################################
121
-
122
- def artifacts_dir
123
- artifacts_dir = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "artifacts")
124
- FileUtils.mkdir_p(File.dirname(artifacts_dir))
125
- artifacts_dir
108
+ def ensure_directory(dir)
109
+ FileUtils.mkdir_p(File.dirname(dir))
126
110
  end
127
111
 
128
- ################################################################################
129
-
130
- def log_file
131
- log_file = File.join(Cucumber::Chef.home_dir, "cucumber-chef.log")
132
- FileUtils.mkdir_p(File.dirname(log_file))
133
- log_file
134
- end
135
-
136
- ################################################################################
137
-
138
- def config_rb
139
- config_rb = File.join(Cucumber::Chef.home_dir, "config.rb")
140
- FileUtils.mkdir_p(File.dirname(config_rb))
141
- config_rb
142
- end
143
-
144
- ################################################################################
145
-
146
- def labfile
147
- labfile = File.join(Cucumber::Chef.chef_repo, "Labfile")
148
- FileUtils.mkdir_p(File.dirname(labfile))
149
- labfile
150
- end
151
-
152
- ################################################################################
153
-
154
- # def knife_rb
155
- # knife_rb = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "knife.rb")
156
- # FileUtils.mkdir_p(File.dirname(knife_rb))
157
- # knife_rb
158
- # end
159
-
160
- ################################################################################
161
-
162
- def chef_user
163
- Cucumber::Chef::Config.user
164
- end
165
-
166
- def chef_identity
167
- chef_identity = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "#{chef_user}.pem")
168
- FileUtils.mkdir_p(File.dirname(chef_identity))
169
- chef_identity
170
- end
171
-
172
- ################################################################################
173
- # Bootstraping SSH Helpers
174
- ################################################################################
175
-
176
- def bootstrap_user
177
- Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:bootstrap_user]
178
- end
179
-
180
- def bootstrap_user_home_dir
181
- user = Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:bootstrap_user]
112
+ def build_home_dir(user)
182
113
  ((user == "root") ? "/root" : "/home/#{user}")
183
114
  end
184
115
 
185
- def bootstrap_identity
186
- bootstrap_identity = Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:identity_file]
187
- File.exists?(bootstrap_identity) && File.chmod(0400, bootstrap_identity)
188
- bootstrap_identity
116
+ def ensure_identity_permissions(identity)
117
+ (File.exists?(identity) && File.chmod(0400, identity))
189
118
  end
190
119
 
191
- ################################################################################
192
- # Test Lab SSH Helpers
193
- ################################################################################
194
-
195
- def lab_user
196
- Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:lab_user]
197
- end
198
-
199
- def lab_user_home_dir
200
- user = Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:lab_user]
201
- ((user == "root") ? "/root" : "/home/#{user}")
202
- end
203
-
204
- def lab_identity
205
- lab_identity = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "id_rsa-#{lab_user}")
206
- File.exists?(lab_identity) && File.chmod(0400, lab_identity)
207
- lab_identity
208
- end
209
-
210
- def lab_ip
211
- Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:ssh][:lab_ip]
212
- end
213
-
214
- def lab_ssh_port
215
- Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:ssh][:lab_port]
216
- end
217
-
218
- def lab_hostname_short
219
- Cucumber::Chef::Config.test_lab[:hostname]
220
- end
221
-
222
- def lab_hostname_full
223
- "#{lab_hostname_short}.#{Cucumber::Chef::Config.test_lab[:tld]}"
224
- end
225
-
226
- ################################################################################
227
- # Container SSH Helpers
228
- ################################################################################
229
-
230
- def lxc_user
231
- Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:lxc_user]
232
- end
233
-
234
- def lxc_user_home_dir
235
- user = Cucumber::Chef::Config[Cucumber::Chef::Config.provider][:lxc_user]
236
- ((user == "root") ? "/root" : "/home/#{user}")
237
- end
238
-
239
- def lxc_identity
240
- lxc_identity = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "id_rsa-#{lxc_user}")
241
- File.exists?(lxc_identity) && File.chmod(0400, lxc_identity)
242
- lxc_identity
243
- end
244
-
245
- ################################################################################
246
-
247
120
  def tag(name=nil)
248
121
  [ name, "v#{Cucumber::Chef::VERSION}" ].compact.join(" ")
249
122
  end
250
123
 
251
- ################################################################################
252
-
253
124
  def build_command(name, *args)
254
125
  executable = (Cucumber::Chef.locate(:file, "bin", name) rescue "/usr/bin/env #{name}")
255
126
  [executable, args].flatten.compact.join(" ")
256
127
  end
257
128
 
258
- ################################################################################
259
- # BOOT
260
- ################################################################################
261
-
262
129
  def boot(name=nil)
263
130
  if !in_chef_repo?
264
131
  message = "It does not look like you are inside a chef-repo! Please relocate to one and execute your command again!"
@@ -273,51 +140,10 @@ module Cucumber
273
140
 
274
141
  ################################################################################
275
142
 
276
- def logger
277
- if (!defined?($logger) || $logger.nil?)
278
- $logger = ZTK::Logger.new(Cucumber::Chef.log_file)
279
- Cucumber::Chef.is_rc? and ($logger.level = ZTK::Logger::DEBUG)
280
-
281
- dependencies = {
282
- "cucumber_chef_version" => Cucumber::Chef::VERSION.inspect,
283
- "fog_version" => ::Fog::VERSION.inspect,
284
- "ruby_version" => RUBY_VERSION.inspect,
285
- "ruby_patchlevel" => RUBY_PATCHLEVEL.inspect,
286
- "ruby_platform" => RUBY_PLATFORM.inspect,
287
- "ztk_version" => ::ZTK::VERSION.inspect
288
- }
289
- if RUBY_VERSION >= "1.9"
290
- dependencies.merge!("ruby_engine" => RUBY_ENGINE.inspect)
291
- end
292
-
293
- details = {
294
- "program" => $0.to_s.inspect,
295
- "uname" => %x(uname -a).chomp.strip.inspect,
296
- "chef_repo" => chef_repo.inspect,
297
- "log_file" => log_file.inspect,
298
- "config_rb" => config_rb.inspect,
299
- "labfile" => labfile.inspect
300
- }
301
-
302
- max_key_length = [dependencies.keys.collect{ |key| key.to_s.length }.max, details.keys.collect{ |key| key.to_s.length }.max].max + 2
303
-
304
- $logger.info { ("=" * 80) }
305
- details.sort.each do |key, value|
306
- $logger.info { " %s%s: %s" % [ key.upcase, '.' * (max_key_length - key.length), value.to_s ] }
307
- end
308
- $logger.info { ("-" * (max_key_length * 2)) }
309
- dependencies.sort.each do |key, value|
310
- $logger.info { " %s%s: %s" % [ key.upcase, '.' * (max_key_length - key.length), value.to_s ] }
311
- end
312
- $logger.info { ("-" * (max_key_length * 2)) }
313
-
314
- end
315
-
316
- $logger
317
- end
318
-
319
143
  end
320
144
 
145
+ ################################################################################
146
+
321
147
  end
322
148
  end
323
149
 
@@ -0,0 +1,46 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ module Cucumber
23
+ module Chef
24
+
25
+ module Utility
26
+ module BootstrapHelper
27
+
28
+ def bootstrap_user
29
+ provider_config[:bootstrap_user]
30
+ end
31
+
32
+ def bootstrap_user_home_dir
33
+ build_home_dir(provider_config[:bootstrap_user])
34
+ end
35
+
36
+ def bootstrap_identity
37
+ bootstrap_identity = provider_config[:identity_file]
38
+ ensure_identity_permissions(bootstrap_identity)
39
+ bootstrap_identity
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,55 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ module Cucumber
23
+ module Chef
24
+
25
+ module Utility
26
+ module ChefHelper
27
+
28
+ def chef_pre_11
29
+ return false if (Cucumber::Chef::Config.chef[:version].downcase == "latest")
30
+ (Cucumber::Chef::Config.chef[:version].to_f < 11.0)
31
+ end
32
+
33
+ def chef_repo
34
+ (Cucumber::Chef.locate_parent(".chef") rescue nil)
35
+ end
36
+
37
+ def in_chef_repo?
38
+ ((chef_repo && File.exists?(chef_repo) && File.directory?(chef_repo)) ? true : false)
39
+ end
40
+
41
+ def chef_user
42
+ Cucumber::Chef::Config.user
43
+ end
44
+
45
+ def chef_identity
46
+ result = File.join(provider_dir, "#{chef_user}.pem")
47
+ ensure_directory(result)
48
+ result
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,54 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ module Cucumber
23
+ module Chef
24
+
25
+ module Utility
26
+ module DirHelper
27
+
28
+ def root_dir
29
+ File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", ".."), File.dirname(__FILE__))
30
+ end
31
+
32
+ def home_dir
33
+ result = (ENV['CUCUMBER_CHEF_HOME'] || File.join(Cucumber::Chef.locate_parent(".chef"), ".cucumber-chef"))
34
+ ensure_directory(result)
35
+ result
36
+ end
37
+
38
+ def provider_dir
39
+ result = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s)
40
+ ensure_directory(result)
41
+ result
42
+ end
43
+
44
+ def artifacts_dir
45
+ result = File.join(provider_dir, "artifacts")
46
+ ensure_directory(result)
47
+ result
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,56 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ module Cucumber
23
+ module Chef
24
+
25
+ module Utility
26
+ module FileHelper
27
+
28
+ def log_file
29
+ result = File.join(Cucumber::Chef.home_dir, "cucumber-chef.log")
30
+ ensure_directory(result)
31
+ result
32
+ end
33
+
34
+ def config_rb
35
+ result = File.join(Cucumber::Chef.home_dir, "config.rb")
36
+ ensure_directory(result)
37
+ result
38
+ end
39
+
40
+ def labfile
41
+ result = File.join(Cucumber::Chef.chef_repo, "Labfile")
42
+ ensure_directory(result)
43
+ result
44
+ end
45
+
46
+ # def knife_rb
47
+ # knife_rb = File.join(provider_dir, "knife.rb")
48
+ # FileUtils.mkdir_p(File.dirname(knife_rb))
49
+ # knife_rb
50
+ # end
51
+
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,62 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ module Cucumber
23
+ module Chef
24
+
25
+ module Utility
26
+ module LabHelper
27
+
28
+ def lab_user
29
+ provider_config[:lab_user]
30
+ end
31
+
32
+ def lab_user_home_dir
33
+ build_home_dir(provider_config[:lab_user])
34
+ end
35
+
36
+ def lab_identity
37
+ lab_identity = File.join(provider_dir, "id_rsa-#{lab_user}")
38
+ ensure_identity_permissions(lab_identity)
39
+ lab_identity
40
+ end
41
+
42
+ def lab_ip
43
+ provider_config[:ssh][:lab_ip]
44
+ end
45
+
46
+ def lab_ssh_port
47
+ provider_config[:ssh][:lab_port]
48
+ end
49
+
50
+ def lab_hostname_short
51
+ Cucumber::Chef::Config.test_lab[:hostname]
52
+ end
53
+
54
+ def lab_hostname_full
55
+ "#{lab_hostname_short}.#{Cucumber::Chef::Config.test_lab[:tld]}"
56
+ end
57
+
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,100 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ module Cucumber
23
+ module Chef
24
+
25
+ module Utility
26
+ module LogHelper
27
+
28
+ def log_key_value(key, value, max_key_length)
29
+ $logger.info { " %s%s: %s" % [ key.upcase, '.' * (max_key_length - key.length), value.to_s ] }
30
+ end
31
+
32
+ def log_page_break(max_key_length, char='-')
33
+ $logger.info { (char * (max_key_length * 2)) }
34
+ end
35
+
36
+ def log_dependencies
37
+ dependencies = {
38
+ "cucumber_chef_version" => Cucumber::Chef::VERSION.inspect,
39
+ "fog_version" => ::Fog::VERSION.inspect,
40
+ "ruby_version" => RUBY_VERSION.inspect,
41
+ "ruby_patchlevel" => RUBY_PATCHLEVEL.inspect,
42
+ "ruby_platform" => RUBY_PLATFORM.inspect,
43
+ "ztk_version" => ::ZTK::VERSION.inspect
44
+ }
45
+
46
+ if RUBY_VERSION >= "1.9"
47
+ dependencies.merge!("ruby_engine" => RUBY_ENGINE.inspect)
48
+ end
49
+
50
+ dependencies
51
+ end
52
+
53
+ def log_details
54
+ {
55
+ "program" => $0.to_s.inspect,
56
+ "uname" => %x(uname -a).chomp.strip.inspect,
57
+ "chef_repo" => chef_repo.inspect,
58
+ "log_file" => log_file.inspect,
59
+ "config_rb" => config_rb.inspect,
60
+ "labfile" => labfile.inspect
61
+ }
62
+ end
63
+
64
+ def logger
65
+ if (!defined?($logger) || $logger.nil?)
66
+ $logger = ZTK::Logger.new(Cucumber::Chef.log_file)
67
+
68
+ if Cucumber::Chef.is_rc?
69
+ $logger.level = ZTK::Logger::DEBUG
70
+ end
71
+
72
+ dependencies = log_dependencies
73
+ details = log_details
74
+
75
+ max_key_length = [dependencies.keys.map(&:length).max, details.keys.map(&:length).max].max + 2
76
+
77
+ log_page_break(max_key_length, '=')
78
+
79
+ details.sort.each do |key, value|
80
+ log_key_value(key, value, max_key_length)
81
+ end
82
+
83
+ log_page_break(max_key_length)
84
+
85
+ dependencies.sort.each do |key, value|
86
+ log_key_value(key, value, max_key_length)
87
+ end
88
+
89
+ log_page_break(max_key_length)
90
+
91
+ end
92
+
93
+ $logger
94
+ end
95
+
96
+ end
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,62 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ module Cucumber
23
+ module Chef
24
+
25
+ module Utility
26
+ module LXCHelper
27
+
28
+ def lxc_user
29
+ provider_config[:lxc_user]
30
+ end
31
+
32
+ def lxc_user_home_dir
33
+ build_home_dir(provider_config[:lxc_user])
34
+ end
35
+
36
+ def lxc_identity
37
+ lxc_identity = File.join(provider_dir, "id_rsa-#{lxc_user}")
38
+ ensure_identity_permissions(lxc_identity)
39
+ lxc_identity
40
+ end
41
+
42
+ def lxc_ip
43
+ provider_config[:ssh][:lxc_ip]
44
+ end
45
+
46
+ def lxc_ssh_port
47
+ provider_config[:ssh][:lxc_port]
48
+ end
49
+
50
+ def lxc_hostname_short
51
+ Cucumber::Chef::Config.test_lxc[:hostname]
52
+ end
53
+
54
+ def lxc_hostname_full
55
+ "#{lxc_hostname_short}.#{Cucumber::Chef::Config.test_lxc[:tld]}"
56
+ end
57
+
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -24,7 +24,7 @@ module Cucumber
24
24
 
25
25
  ################################################################################
26
26
 
27
- VERSION = "3.0.7" unless const_defined?(:VERSION)
27
+ VERSION = "3.0.8" unless const_defined?(:VERSION)
28
28
 
29
29
  ################################################################################
30
30
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cucumber-chef
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.0.7
5
+ version: 3.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Stephen Nelson-Smith
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2013-04-13 00:00:00 Z
14
+ date: 2013-04-14 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog
@@ -108,7 +108,7 @@ dependencies:
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: 0.6.4
111
+ version: "0"
112
112
  type: :development
113
113
  prerelease: false
114
114
  version_requirements: *id009
@@ -147,8 +147,8 @@ dependencies:
147
147
  version_requirements: *id012
148
148
  description: Framework for test-driven infrastructure development.
149
149
  email:
150
- - stephen@atalanta-systems.com
151
- - zachary@jovelabs.com
150
+ - stephen@atalanta-systemspec.com
151
+ - zachary@jovelabspec.com
152
152
  executables:
153
153
  - cc-console
154
154
  - cc-knife
@@ -160,7 +160,8 @@ extra_rdoc_files: []
160
160
  files:
161
161
  - .gitignore
162
162
  - .rspec
163
- - .rvmrc.template
163
+ - .ruby-gemset
164
+ - .ruby-version
164
165
  - .travis.yml
165
166
  - Gemfile
166
167
  - LICENSE
@@ -235,6 +236,13 @@ files:
235
236
  - lib/cucumber/chef/templates/cucumber/readme.erb
236
237
  - lib/cucumber/chef/test_lab.rb
237
238
  - lib/cucumber/chef/utility.rb
239
+ - lib/cucumber/chef/utility/bootstrap_helper.rb
240
+ - lib/cucumber/chef/utility/chef_helper.rb
241
+ - lib/cucumber/chef/utility/dir_helper.rb
242
+ - lib/cucumber/chef/utility/file_helper.rb
243
+ - lib/cucumber/chef/utility/lab_helper.rb
244
+ - lib/cucumber/chef/utility/log_helper.rb
245
+ - lib/cucumber/chef/utility/lxc_helper.rb
238
246
  - lib/cucumber/chef/version.rb
239
247
  - spec/cucumber/chef/config_spec.rb
240
248
  - spec/cucumber/chef/provisioner_spec.rb
@@ -253,13 +261,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
261
  requirements:
254
262
  - - ">="
255
263
  - !ruby/object:Gem::Version
256
- version: 1.8.7
264
+ hash: -4003573981982952912
265
+ segments:
266
+ - 0
267
+ version: "0"
257
268
  required_rubygems_version: !ruby/object:Gem::Requirement
258
269
  none: false
259
270
  requirements:
260
271
  - - ">="
261
272
  - !ruby/object:Gem::Version
262
- version: 1.3.6
273
+ hash: -4003573981982952912
274
+ segments:
275
+ - 0
276
+ version: "0"
263
277
  requirements: []
264
278
 
265
279
  rubyforge_project:
@@ -1,2 +0,0 @@
1
- rvm use ruby-1.9.3@cucumber-chef --create
2
- export USE_BUNDLER=force