cucumber-chef 3.0.0.rc.1 → 3.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/WIKI.md +8 -2
  2. data/chef_repo/Cheffile +4 -0
  3. data/chef_repo/Gemfile +3 -0
  4. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/LICENSE +0 -0
  5. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/README.md +0 -0
  6. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/attributes/default.rb +0 -0
  7. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/metadata.rb +0 -0
  8. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/recipes/default.rb +0 -0
  9. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/recipes/lxc.rb +0 -0
  10. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/recipes/test_lab.rb +0 -0
  11. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/db-168-192.erb +0 -0
  12. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/db-test-lab.erb +0 -0
  13. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/dhcpd-conf.erb +0 -0
  14. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/lxc-initializer-config.erb +0 -0
  15. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/lxc-install-chef.erb +0 -0
  16. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/motd.erb +0 -0
  17. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/named-conf-local.erb +0 -0
  18. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/solrconfig.erb +0 -0
  19. data/chef_repo/{cookbooks → site-cookbooks}/cucumber-chef/templates/default/ssh-config.erb +0 -0
  20. data/examples/README.md +2 -6
  21. data/lib/cucumber/chef/provisioner.rb +44 -38
  22. data/lib/cucumber/chef/templates/bootstrap/ubuntu-precise-test-lab.erb +25 -54
  23. data/lib/cucumber/chef/version.rb +1 -1
  24. metadata +20 -20
  25. data/examples/users_add.feature +0 -51
  26. data/examples/users_auto_remove.feature +0 -50
data/WIKI.md CHANGED
@@ -1,6 +1,5 @@
1
- [![Dependency Status](https://gemnasium.com/jovelabs/cucumber-chef.png)](https://gemnasium.com/jovelabs/cucumber-chef)
2
-
3
1
  [![Build Status](https://secure.travis-ci.org/jovelabs/cucumber-chef.png)](http://travis-ci.org/jovelabs/cucumber-chef)
2
+ [![Dependency Status](https://gemnasium.com/jovelabs/cucumber-chef.png)](https://gemnasium.com/jovelabs/cucumber-chef)
4
3
 
5
4
  I was not particularly happy with the state of the 2.x documents and considering workflow changes, etc it made sense to me to start over with the documentation. Since most things are the same the 2.x documentation will remain available in the repo as `WIKI.2.x.md`. This is WIP.
6
5
 
@@ -8,6 +7,13 @@ I was not particularly happy with the state of the 2.x documents and considering
8
7
 
9
8
  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.
10
9
 
10
+ # Example Chef-Repo
11
+
12
+ I have prepared a chef-repo which I use to develop off of and made it available to the community to use as a baseline for playing with cucumber-chef and experimenting with cucumber-chef.
13
+
14
+ * https://github.com/zpatten/cc-chef-repo
15
+
16
+
11
17
  # Prerequsites/Recommendations
12
18
 
13
19
  Your Chef-Repo should be setup in a manner as follows:
@@ -0,0 +1,4 @@
1
+ site 'http://community.opscode.com/api/v1'
2
+
3
+ cookbook "chef-server"
4
+ cookbook "chef-client"
data/chef_repo/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "librarian-chef"
data/examples/README.md CHANGED
@@ -1,7 +1,3 @@
1
- Examples
2
- ========
1
+ Examples:
3
2
 
4
- This directory contains various examples in the form of early feature tests for some of my cookbooks. You can find out more about the cookbooks on GitHub:
5
-
6
- https://github.com/jovelabs
7
- https://github.com/zpatten
3
+ * https://github.com/zpatten/cc-chef-repo
@@ -43,16 +43,11 @@ module Cucumber
43
43
  ################################################################################
44
44
 
45
45
  def build
46
+ upload_chef_repo
46
47
  bootstrap
47
48
  wait_for_chef_server
48
49
 
49
50
  download_chef_credentials
50
-
51
- upload_cookbook
52
- upload_role
53
-
54
- chef_first_run
55
-
56
51
  download_proxy_ssh_credentials
57
52
 
58
53
  reboot_test_lab
@@ -61,6 +56,35 @@ module Cucumber
61
56
 
62
57
  ################################################################################
63
58
  private
59
+ ################################################################################
60
+
61
+ def upload_chef_repo
62
+ ZTK::Benchmark.bench(:message => "Uploading embedded chef-repo", :mark => "completed in %0.4f seconds.", :ui => @ui) do
63
+ local_path = File.join(Cucumber::Chef.root_dir, "chef_repo")
64
+ @ui.logger.debug { "local_path == #{local_path.inspect}" }
65
+
66
+ remote_path = File.join("/tmp", "chef-solo")
67
+ @ui.logger.debug { "remote_path == #{remote_path.inspect}" }
68
+
69
+ glob_dir = File.join(local_path, "**")
70
+ @ui.logger.debug { "glob_dir == #{glob_dir.inspect}" }
71
+
72
+ @test_lab.bootstrap_ssh.exec(%(mkdir -p #{remote_path}))
73
+
74
+ Dir.glob(glob_dir).each do |file|
75
+ file = File.basename(file)
76
+ @ui.logger.debug { "file == #{file.inspect}" }
77
+
78
+ local_file = File.join(local_path, file)
79
+ remote_file = File.join(remote_path, file)
80
+
81
+ File.directory?(local_file) and @test_lab.bootstrap_ssh.exec(%(mkdir -p #{remote_file}))
82
+
83
+ @test_lab.bootstrap_ssh.upload(local_file, remote_file)
84
+ end
85
+ end
86
+ end
87
+
64
88
  ################################################################################
65
89
 
66
90
  def bootstrap
@@ -68,13 +92,20 @@ module Cucumber
68
92
 
69
93
  ZTK::Benchmark.bench(:message => "Bootstrapping #{Cucumber::Chef::Config.provider.upcase} instance", :mark => "completed in %0.4f seconds.", :ui => @ui) do
70
94
  chef_client_attributes = {
71
- "run_list" => "role[test_lab]",
95
+ "run_list" => %w(recipe[chef-server::rubygems-install] recipe[chef-server] recipe[chef-client] role[test_lab]),
72
96
  "cucumber_chef" => {
73
97
  "version" => Cucumber::Chef::VERSION,
74
98
  "prerelease" => Cucumber::Chef::Config.prerelease
75
99
  },
76
100
  "lab_user" => Cucumber::Chef.lab_user,
77
- "lxc_user" => Cucumber::Chef.lxc_user
101
+ "lxc_user" => Cucumber::Chef.lxc_user,
102
+ "chef_server" => {
103
+ "webui_enabled" => true
104
+ },
105
+ "chef_client" => {
106
+ "interval" => 900,
107
+ "splay" => 900
108
+ }
78
109
  }
79
110
 
80
111
  context = {
@@ -108,10 +139,15 @@ module Cucumber
108
139
  def download_chef_credentials
109
140
  ZTK::Benchmark.bench(:message => "Downloading chef-server credentials", :mark => "completed in %0.4f seconds.", :ui => @ui) do
110
141
  local_path = File.dirname(Cucumber::Chef.chef_identity)
142
+ @ui.logger.debug { "local_path == #{local_path.inspect}" }
143
+
111
144
  remote_path = File.join(Cucumber::Chef.lab_user_home_dir, ".chef")
145
+ @ui.logger.debug { "remote_path == #{remote_path.inspect}" }
112
146
 
113
147
  files = [ File.basename(Cucumber::Chef.chef_identity), "validation.pem" ]
114
148
  files.each do |file|
149
+ @ui.logger.debug { "file == #{file.inspect}" }
150
+
115
151
  @test_lab.bootstrap_ssh.download(File.join(remote_path, file), File.join(local_path, file))
116
152
  end
117
153
  end
@@ -134,36 +170,6 @@ module Cucumber
134
170
  end
135
171
  end
136
172
 
137
- ################################################################################
138
-
139
- def upload_cookbook
140
- @ui.logger.debug { "Uploading cucumber-chef cookbooks..." }
141
- ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' cookbooks", :mark => "completed in %0.4f seconds.", :ui => @ui) do
142
- @test_lab.knife_cli(%(cookbook upload cucumber-chef -o #{@cookbooks_path}), :silence => true)
143
- end
144
- end
145
-
146
- ################################################################################
147
-
148
- def upload_role
149
- @ui.logger.debug { "Uploading cucumber-chef test lab role..." }
150
- ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' roles", :mark => "completed in %0.4f seconds.", :ui => @ui) do
151
- @test_lab.knife_cli(%(role from file #{File.join(@roles_path, "test_lab.rb")}), :silence => true)
152
- end
153
- end
154
-
155
- ################################################################################
156
-
157
- def chef_first_run
158
- ZTK::Benchmark.bench(:message => "Performing chef-client run", :mark => "completed in %0.4f seconds.", :ui => @ui) do
159
- log_level = (ENV['LOG_LEVEL'].downcase rescue (Cucumber::Chef.is_rc? ? "debug" : "info"))
160
-
161
- command = "/usr/bin/chef-client -j /etc/chef/first-boot.json --log_level #{log_level} --once"
162
- command = "sudo #{command}"
163
- @test_lab.bootstrap_ssh.exec(command, :silence => true)
164
- end
165
- end
166
-
167
173
  ################################################################################
168
174
 
169
175
  def wait_for_chef_server
@@ -15,26 +15,33 @@ echo "127.0.0.1 <%= @hostname_full %> <%= @hostname_short %>" | tee -a /etc/host
15
15
  echo "<%= @hostname_full %>" | tee /etc/hostname
16
16
  hostname <%= @hostname_full %>
17
17
 
18
- echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | tee /etc/apt/sources.list.d/opscode.list
19
- mkdir -p /etc/apt/trusted.gpg.d
20
- gpg --fetch-key http://apt.opscode.com/packages@opscode.com.gpg.key
21
- gpg --export packages@opscode.com | tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null
22
- apt-get -q -y --force-yes update
23
- apt-get -q -y --force-yes -o Dpkg::Options::="--force-confnew" install opscode-keyring
24
- apt-get -q -y --force-yes update
25
- chown -R ${SUDO_USER}:${SUDO_USER} ${HOME}/.gnupg
26
- apt-get -q -y upgrade
27
-
28
- cat <<EOF | debconf-set-selections
29
- chef chef/chef_server_url string http://<%= @hostname_short %>:4000
30
- chef-solr chef-solr/amqp_password password <%= @amqp_password %>
31
- chef-server-webui chef-server-webui/admin_password password <%= @admin_password %>
18
+ apt-get -y --force-yes update
19
+ apt-get -y --force-yes install build-essential
20
+
21
+ wget http://www.opscode.com/chef/install.sh
22
+ bash install.sh -v <%= @chef_version %>
23
+ rpm -Uvh --nodeps /tmp/*rpm
24
+ export PATH=/opt/chef/embedded/bin/:$PATH
25
+
26
+ mkdir -p /etc/chef/
27
+ mkdir -p /var/log/chef/
28
+
29
+ cat <<EOF > /etc/chef/solo.rb
30
+ file_cache_path "/tmp/chef-solo/"
31
+ cookbook_path %w(/tmp/chef-solo/cookbooks/ /tmp/chef-solo/site-cookbooks/)
32
+ role_path "/tmp/chef-solo/roles/"
33
+ EOF
34
+
35
+ cat <<EOF > /etc/chef/bootstrap.json
36
+ <%= @chef_client_attributes.to_json %>
32
37
  EOF
33
38
 
34
- CHEF_VERSION=`apt-cache showpkg chef | tee | grep -m 1 "<%= @chef_version %>" | cut -c -<%= @chef_version.length + 3 %>`
35
- CHEF_SERVER_VERSION=`apt-cache showpkg chef-server | tee | grep -m 1 "<%= @chef_version %>" | cut -c -<%= @chef_version.length + 3 %>`
39
+ cd /tmp/chef-solo/
40
+ gem install bundler --no-ri --no-rdoc
41
+ bundle install --standalone --path vendor/bundle --binstubs
42
+ bin/librarian-chef install
36
43
 
37
- apt-get -q -y --force-yes install chef=$CHEF_VERSION chef-server=$CHEF_SERVER_VERSION
44
+ chef-solo --config /etc/chef/solo.rb --json-attributes /etc/chef/bootstrap.json --logfile /var/log/chef/chef-solo.log --log_level debug
38
45
 
39
46
  echo -n "Waiting on validation.pem and webui.pem to appear..."
40
47
  until [ -f /etc/chef/validation.pem ] && [ -f /etc/chef/webui.pem ]; do
@@ -68,42 +75,6 @@ ${KNIFE_CONFIG_EXP_FILE}
68
75
 
69
76
  knife client create <%= @user %> -d -a -f ${HOME}/.chef/<%= @user %>.pem
70
77
 
71
- chown -R ${SUDO_USER}:${SUDO_USER} ${HOME}
72
-
73
- # nc -w 1 127.0.0.1 4040
74
- # if [ $? -ne 0 ]; then
75
- # /etc/init.d/chef-server-webui stop && sleep 3
76
- # /usr/sbin/chef-server-webui -e production &
77
- # while true; do
78
- # nc -w 1 127.0.0.1 4040
79
- # if [ $? -eq 0 ]; then
80
- # break
81
- # fi
82
- # sleep 1
83
- # done
84
- # kill `jobs -p` && sleep 3
85
- # /etc/init.d/chef-server-webui start && sleep 3
86
- # fi
87
-
88
- if [ ! -f /etc/chef/client.pem ]; then
89
- /etc/init.d/chef-client restart
90
- echo -n "Waiting on client.pem to appear..."
91
- i="0"
92
- until [ -f /etc/chef/client.pem ]; do
93
- i=$[$i+1]
94
- sleep 1
95
- echo -n "."
96
- if [ $i -gt 60 ]; then
97
- echo -n "restart-chef-client"
98
- /etc/init.d/chef-client restart
99
- i="0"
100
- fi
101
- done
102
- echo "done."
103
- fi
104
-
105
- cat <<EOF > /etc/chef/first-boot.json
106
- <%= @chef_client_attributes.to_json %>
107
- EOF
78
+ chown -Rv ${SUDO_USER}:${SUDO_USER} ${HOME}
108
79
 
109
80
  touch ${CUCUMBER_CHEF_BOOTSTRAP_DONE}
@@ -24,7 +24,7 @@ module Cucumber
24
24
 
25
25
  ################################################################################
26
26
 
27
- VERSION = "3.0.0.rc.1" unless const_defined?(:VERSION)
27
+ VERSION = "3.0.0.rc.2" unless const_defined?(:VERSION)
28
28
 
29
29
  ################################################################################
30
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc.1
4
+ version: 3.0.0.rc.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-31 00:00:00.000000000 Z
13
+ date: 2013-04-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fog
@@ -230,27 +230,27 @@ files:
230
230
  - bin/cc-console
231
231
  - bin/cc-knife
232
232
  - bin/cucumber-chef
233
- - chef_repo/cookbooks/cucumber-chef/LICENSE
234
- - chef_repo/cookbooks/cucumber-chef/README.md
235
- - chef_repo/cookbooks/cucumber-chef/attributes/default.rb
236
- - chef_repo/cookbooks/cucumber-chef/metadata.rb
237
- - chef_repo/cookbooks/cucumber-chef/recipes/default.rb
238
- - chef_repo/cookbooks/cucumber-chef/recipes/lxc.rb
239
- - chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb
240
- - chef_repo/cookbooks/cucumber-chef/templates/default/db-168-192.erb
241
- - chef_repo/cookbooks/cucumber-chef/templates/default/db-test-lab.erb
242
- - chef_repo/cookbooks/cucumber-chef/templates/default/dhcpd-conf.erb
243
- - chef_repo/cookbooks/cucumber-chef/templates/default/lxc-initializer-config.erb
244
- - chef_repo/cookbooks/cucumber-chef/templates/default/lxc-install-chef.erb
245
- - chef_repo/cookbooks/cucumber-chef/templates/default/motd.erb
246
- - chef_repo/cookbooks/cucumber-chef/templates/default/named-conf-local.erb
247
- - chef_repo/cookbooks/cucumber-chef/templates/default/solrconfig.erb
248
- - chef_repo/cookbooks/cucumber-chef/templates/default/ssh-config.erb
233
+ - chef_repo/Cheffile
234
+ - chef_repo/Gemfile
249
235
  - chef_repo/roles/test_lab.rb
236
+ - chef_repo/site-cookbooks/cucumber-chef/LICENSE
237
+ - chef_repo/site-cookbooks/cucumber-chef/README.md
238
+ - chef_repo/site-cookbooks/cucumber-chef/attributes/default.rb
239
+ - chef_repo/site-cookbooks/cucumber-chef/metadata.rb
240
+ - chef_repo/site-cookbooks/cucumber-chef/recipes/default.rb
241
+ - chef_repo/site-cookbooks/cucumber-chef/recipes/lxc.rb
242
+ - chef_repo/site-cookbooks/cucumber-chef/recipes/test_lab.rb
243
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/db-168-192.erb
244
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/db-test-lab.erb
245
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/dhcpd-conf.erb
246
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/lxc-initializer-config.erb
247
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/lxc-install-chef.erb
248
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/motd.erb
249
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/named-conf-local.erb
250
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/solrconfig.erb
251
+ - chef_repo/site-cookbooks/cucumber-chef/templates/default/ssh-config.erb
250
252
  - cucumber-chef.gemspec
251
253
  - examples/README.md
252
- - examples/users_add.feature
253
- - examples/users_auto_remove.feature
254
254
  - features/installing.feature
255
255
  - features/steps/installing_steps.rb
256
256
  - features/steps/setup_steps.rb
@@ -1,51 +0,0 @@
1
- @users
2
- Feature: Perform test driven infrastructure with Cucumber-Chef
3
- In order to learn how to develop test driven infrastructure
4
- As an infrastructure developer
5
- I want to better understand how to use Cucumber-Chef
6
-
7
- Background:
8
- * I have a server called "users"
9
- * "users" is running "ubuntu" "lucid"
10
- * "users" has been provisioned
11
- * the following roles have been updated:
12
- | role | role_path |
13
- | users | ./support/roles/ |
14
- * the "users" role has been added to the "users" run list
15
- * the following databags have been updated:
16
- | databag | databag_path |
17
- | users | ./support/data_bags/users |
18
- * the chef-client has been run on "users"
19
- * I ssh to "users" with the following credentials:
20
- | username | keyfile |
21
- | root | ../.ssh/id_rsa |
22
-
23
- Scenario: The user has been added
24
- When I run "cat /etc/passwd | grep [b]dobbs"
25
- Then I should see "bdobbs" in the output
26
- And I should see "/home/bdobbs" in the output
27
- And I should see "/bin/bash" in the output
28
-
29
- Scenario: The user's groups have been added
30
- When I run "cat /etc/group | grep [b]dobbs"
31
- Then I should see "bdobbs" in the output
32
- And I should see "sysop" in the output
33
- And I should see "dba" in the output
34
- And I should see "dev" in the output
35
-
36
- Scenario: The user's ssh keys have been populated
37
- When I run "cat /home/bdobbs/.ssh/authorized_keys"
38
- Then I should see "ssh-rsa" in the output
39
- And I should see "bob@dobbs" in the output
40
-
41
- Scenario: The user's ssh config has been populated
42
- When I run "cat /home/bdobbs/.ssh/config"
43
- Then I should see "KeepAlive yes" in the output
44
- And I should see "ServerAliveInterval 60" in the output
45
-
46
- Scenario: The user can ssh in to the system with their key pair
47
- * I ssh to "users" with the following credentials:
48
- | username | keyfile |
49
- | bdobbs | ./support/keys/bdobbs |
50
- When I run "hostname"
51
- Then I should see "users" in the output
@@ -1,50 +0,0 @@
1
- @users
2
- Feature: Perform test driven infrastructure with Cucumber-Chef
3
- In order to learn how to develop test driven infrastructure
4
- As an infrastructure developer
5
- I want to better understand how to use Cucumber-Chef
6
-
7
- Background:
8
- * I have a server called "users"
9
- * "users" is running "ubuntu" "lucid"
10
- * "users" has been provisioned
11
- * the following roles have been updated:
12
- | role | role_path |
13
- | users | ./support/roles/ |
14
- * the "users" role has been added to the "users" run list
15
- * the following databags have been updated:
16
- | databag | databag_path |
17
- | users | ./support/data_bags/users |
18
- * the chef-client has been run on "users"
19
- * I ssh to "users" with the following credentials:
20
- | username | keyfile |
21
- | root | ../.ssh/id_rsa |
22
-
23
- Scenario: The user has been removed
24
- * the following databags have been updated:
25
- | databag | databag_path |
26
- | users | ./support/data_bags/users-auto-remove |
27
- * the chef-client has been run on "users"
28
- When I run "cat /etc/passwd | grep [b]dobbs"
29
- Then I should not see "bdobbs" in the output
30
- And I should not see "/home/bdobbs" in the output
31
- And I should not see "/bin/bash" in the output
32
-
33
- Scenario: The user's group has been removed
34
- * the following databags have been updated:
35
- | databag | databag_path |
36
- | users | ./support/data_bags/users-auto-remove |
37
- * the chef-client has been run on "users"
38
- When I run "cat /etc/group | grep [b]dobbs"
39
- Then I should not see "bdobbs" in the output
40
- And I should not see "sysop" in the output
41
- And I should not see "dba" in the output
42
- And I should not see "dev" in the output
43
-
44
- Scenario: The user's directory has been preserved on remove
45
- * the following databags have been updated:
46
- | databag | databag_path |
47
- | users | ./support/data_bags/users-auto-remove |
48
- * the chef-client has been run on "users"
49
- When I run "[[ -e /home/bdobbs ]] && echo OK"
50
- Then I should see "OK" in the output