cucumber-chef 1.0.3 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +8 -35
  2. data/.rspec +1 -0
  3. data/.rvmrc.template +2 -0
  4. data/.travis.yml +22 -0
  5. data/Gemfile +2 -15
  6. data/LICENSE +202 -201
  7. data/NOTICE +9 -0
  8. data/README.md +696 -92
  9. data/Rakefile +39 -25
  10. data/TODO.md +28 -0
  11. data/bin/cc-knife +32 -0
  12. data/bin/cucumber-chef +409 -79
  13. data/chef_repo/cookbooks/cucumber-chef/LICENSE +202 -0
  14. data/chef_repo/cookbooks/cucumber-chef/README.md +69 -0
  15. data/chef_repo/cookbooks/cucumber-chef/attributes/default.rb +27 -0
  16. data/chef_repo/cookbooks/cucumber-chef/metadata.rb +13 -0
  17. data/chef_repo/cookbooks/cucumber-chef/recipes/default.rb +23 -0
  18. data/chef_repo/cookbooks/cucumber-chef/recipes/lxc.rb +315 -0
  19. data/chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb +146 -0
  20. data/chef_repo/cookbooks/cucumber-chef/templates/default/db-168-192.erb +15 -0
  21. data/chef_repo/cookbooks/cucumber-chef/templates/default/db-test-lab.erb +15 -0
  22. data/chef_repo/cookbooks/cucumber-chef/templates/default/dhcpd-conf.erb +44 -0
  23. data/chef_repo/cookbooks/cucumber-chef/templates/default/gemrc.erb +10 -0
  24. data/{cookbooks/cucumber-chef/files/default/cucumber-net → chef_repo/cookbooks/cucumber-chef/templates/default/lxc-initializer-config.erb} +1 -1
  25. data/chef_repo/cookbooks/cucumber-chef/templates/default/lxc-install-chef.erb +3 -0
  26. data/chef_repo/cookbooks/cucumber-chef/templates/default/motd.erb +10 -0
  27. data/chef_repo/cookbooks/cucumber-chef/templates/default/named-conf-local.erb +25 -0
  28. data/{cookbooks/cucumber-chef/files/default/permissive-ssh-config → chef_repo/cookbooks/cucumber-chef/templates/default/ssh-config.erb} +3 -1
  29. data/chef_repo/roles/test_lab.rb +24 -0
  30. data/cucumber-chef.gemspec +50 -123
  31. data/examples/README.md +7 -0
  32. data/examples/users_add.feature +51 -0
  33. data/examples/users_auto_remove.feature +50 -0
  34. data/features/support/env.rb +3 -2
  35. data/lib/cucumber/chef/bootstrap.rb +94 -0
  36. data/lib/cucumber/chef/command.rb +78 -0
  37. data/lib/cucumber/chef/config.rb +143 -93
  38. data/lib/cucumber/chef/helpers/chef_client.rb +87 -0
  39. data/lib/cucumber/chef/helpers/chef_server.rb +90 -0
  40. data/lib/cucumber/chef/helpers/command.rb +57 -0
  41. data/lib/cucumber/chef/helpers/container.rb +154 -0
  42. data/lib/cucumber/chef/helpers/minitest.rb +35 -0
  43. data/lib/cucumber/chef/helpers/server.rb +81 -0
  44. data/lib/cucumber/chef/helpers/test_lab.rb +46 -0
  45. data/lib/cucumber/chef/helpers/utility.rb +73 -0
  46. data/lib/cucumber/chef/helpers.rb +56 -0
  47. data/lib/cucumber/chef/logger.rb +90 -0
  48. data/lib/cucumber/chef/provisioner.rb +275 -69
  49. data/lib/cucumber/chef/ssh.rb +190 -0
  50. data/lib/cucumber/chef/steps/chef_steps.rb +32 -0
  51. data/lib/cucumber/chef/steps/minitest_steps.rb +29 -0
  52. data/lib/cucumber/chef/steps/provision_steps.rb +60 -0
  53. data/lib/cucumber/chef/steps/ssh_steps.rb +95 -0
  54. data/lib/cucumber/chef/steps.rb +27 -0
  55. data/lib/cucumber/chef/tcp_socket.rb +83 -0
  56. data/lib/cucumber/chef/template.rb +57 -0
  57. data/lib/cucumber/chef/templates/bootstrap/ubuntu-precise-test-lab.erb +99 -0
  58. data/lib/cucumber/chef/templates/cucumber/env.rb +56 -0
  59. data/lib/cucumber/chef/templates/cucumber/example_feature.erb +49 -0
  60. data/lib/cucumber/chef/templates/cucumber/example_steps.erb +11 -0
  61. data/lib/cucumber/chef/templates/cucumber/readme-data_bags.erb +1 -0
  62. data/lib/cucumber/chef/templates/cucumber/readme-keys.erb +1 -0
  63. data/lib/cucumber/chef/templates/cucumber/readme-roles.erb +1 -0
  64. data/lib/cucumber/chef/templates/cucumber/readme.erb +18 -0
  65. data/lib/cucumber/chef/templates/cucumber-chef/config-rb.erb +33 -0
  66. data/lib/cucumber/chef/templates/cucumber-chef/cucumber-yml.erb +2 -0
  67. data/lib/cucumber/chef/templates/cucumber-chef/knife-rb.erb +18 -0
  68. data/lib/cucumber/chef/test_lab.rb +308 -52
  69. data/lib/cucumber/chef/test_runner.rb +86 -15
  70. data/lib/cucumber/chef/utility.rb +128 -0
  71. data/lib/cucumber/chef/version.rb +30 -1
  72. data/lib/cucumber/chef.rb +53 -20
  73. data/lib/cucumber-chef.rb +24 -1
  74. data/spec/cucumber/chef/config_spec.rb +144 -78
  75. data/spec/cucumber/chef/provisioner_spec.rb +60 -16
  76. data/spec/cucumber/chef/test_lab_spec.rb +62 -19
  77. data/spec/spec_helper.rb +30 -26
  78. data/todo.org +17 -0
  79. metadata +267 -163
  80. data/.document +0 -5
  81. data/VERSION +0 -1
  82. data/cookbooks/cucumber-chef/README.rdoc +0 -8
  83. data/cookbooks/cucumber-chef/files/default/add-git-identity +0 -2
  84. data/cookbooks/cucumber-chef/files/default/controller-first-boot +0 -1
  85. data/cookbooks/cucumber-chef/files/default/cucumber-private-key +0 -27
  86. data/cookbooks/cucumber-chef/files/default/cucumber-run_list +0 -1
  87. data/cookbooks/cucumber-chef/files/default/git-private-key +0 -27
  88. data/cookbooks/cucumber-chef/files/default/install-chef +0 -1
  89. data/cookbooks/cucumber-chef/files/default/lxc-controller-network-config +0 -5
  90. data/cookbooks/cucumber-chef/files/default/lxc-lucid-chef +0 -378
  91. data/cookbooks/cucumber-chef/metadata.rb +0 -6
  92. data/cookbooks/cucumber-chef/recipes/controller.rb +0 -51
  93. data/cookbooks/cucumber-chef/recipes/lxc.rb +0 -35
  94. data/cookbooks/cucumber-chef/recipes/test_lab.rb +0 -23
  95. data/cookbooks/cucumber-chef/recipes/testrunner.rb +0 -46
  96. data/cookbooks/cucumber-chef/roles/controller.rb +0 -7
  97. data/cookbooks/cucumber-chef/roles/test_lab_test.rb +0 -9
  98. data/cookbooks/cucumber-chef/templates/default/controller-client.erb +0 -5
  99. data/cookbooks/cucumber-chef/templates/default/lxc-lucid-chef +0 -385
  100. data/lib/cucumber/chef/handy.rb +0 -90
  101. data/lib/cucumber/chef/templates/controller.erb +0 -35
  102. data/lib/cucumber/chef/templates/env.rb +0 -16
  103. data/lib/cucumber/chef/templates/example_feature.erb +0 -11
  104. data/lib/cucumber/chef/templates/example_step.erb +0 -19
  105. data/lib/cucumber/chef/templates/readme.erb +0 -14
  106. data/lib/cucumber/chef/templates/ubuntu10.04-gems.erb +0 -43
  107. data/lib/cucumber/ec2_server_create.rb +0 -99
  108. data/website/website.html +0 -385
data/README.md CHANGED
@@ -1,153 +1,757 @@
1
- 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 lightweight virtual machines, configure them by applying the appriporaite Chef roles to them, and then run acceptance and integration tests against the environment.
1
+ [![Build Status](https://secure.travis-ci.org/zpatten/cucumber-chef.png)](http://travis-ci.org/zpatten/cucumber-chef)
2
+
3
+ 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.
2
4
 
3
5
  ## Overview
4
6
 
5
- Cucumber-chef begins with a very simple premise. If we are framing our infratructure as code - if we're writing cookbooks, recipes and other pieces of automation in a high level programming language, such as Ruby, then it makes sense to follow the current wisdom across the software development world to maximise the quality, maintainability and reusability of our code, providing maximum chance that we'll deliver value with it. One area which has been shown to have a very positive effect is the practive of 'test-driven' development. In this paradigm, the developer begins by writing a test that captures the intended behaviour of the code they are going to write. This test will start out by failing. The developer then writes code to make the test pass, and iterates thereafter.
7
+ Cucumber-chef begins with a very simple premise. If we are framing our infrastructure as code - if we're writing cookbooks, recipes and other pieces of automation in a high level programming language, such as Ruby, then it makes sense to follow the current wisdom across the software development world to maximise the quality, maintainability and reusability of our code, providing maximum chance that we'll deliver value with it. One area which has been shown to have a very positive effect is the practive of 'test-driven' development. In this paradigm, the developer begins by writing a test that captures the intended behaviour of the code they are going to write. This test will start out by failing. The developer then writes code to make the test pass, and iterates thereafter.
8
+
9
+ Cucumber-chef provides a framework to make it easier to do test-driven development for infrastructure. It does this by providing a test infrastructure, which we call the "test lab", within which a number of different scenarios can be set up, and against which Cucumber features can we run. From the outset, Cucumber-chef's design was to provide a fast, lightweight and cheap way to fire up virtual machines for testing. At present this is achieved using Linux Containers on Amazon EC2. Supporting alternative provisioning backends is planned, which will allow the user to opt to test using local machines, alternative cloud providers, and ultimatey alternative virtualization technologies.
6
10
 
7
- Cucumber-chef provides a framework to make it easier to do test-driven development for infrastructure. It does this by providing a test infrastructure, in the cloud, which provides a very fast, lightweight and cheap way to fire up virtual machines for testing. We call this the "test lab".
11
+ For node convergence, Cucumber-Chef uses the open-source Chef server. It can be configured to use Hosted Chef or Private Chef. Supoprt for Chef-solo will be included in a future relase.
8
12
 
9
13
  As you might have guessed from the name, we're going to write high level acceptance tests using Cucumber. Cucumber-Chef provides step definitions and helper methods to make it easy to provision and manage machines with Chef, and then build end-to-end tests.
10
14
 
11
- ## Getting started
15
+ ## Getting Started
16
+
17
+ *LISTEN UP*
18
+
19
+ Here's the headline:
12
20
 
13
- Getting started with Cucumber-Chef is a simple, three step process:
21
+ With a /single command/ Cucumber-Chef will provision a machine, set up an open source Chef server, bootstrap it to support the creation of Linux containers, set up an environment from which to run tests, and automatically configure your system to use it.
14
22
 
15
- 1) Install Cucumber-Chef
16
- 2) Integrate with Hosted Chef and Amazon EC2
17
- 3) Run cucumber-chef setup
23
+ This means getting started with Cucumber-Chef is a simple, two step process.
24
+
25
+ 1. Install Cucumber-Chef
26
+
27
+ 2. Run `cucumber-chef init` to configure Cucumber-Chef.
28
+
29
+ 3. Run `cucumber-chef setup` to build your test lab.
18
30
 
19
31
  ### Installing Cucumber-Chef
20
32
 
21
- Installing Cucumber-Chef is simple. It's distributed as a RubyGem, so you can simply run:
33
+ Cucumber-Chef is distributed as a RubyGem. To install it you have two options - stable or development.
34
+
35
+ #### Installing the stable version
36
+
37
+ Simply install from RubyGems:
22
38
 
23
39
  $ gem install cucumber-chef
24
40
 
25
- Once installed, you can run cucumber-chef on the command line to get an overview of the tasks it can carry out.
41
+ Depending on your local setup (ie whether you're using RVM or rbenv, or distribution-provided Ruby), you may need to run this with superuser privileges.
42
+
43
+ #### Installing the development version
44
+
45
+ If you want to try a development version, simply clone this repo, and build the gem yourself:
46
+
47
+ $ git clone git://github.com/Atalanta/cucumber-chef -b BRANCH
48
+ $ cd cucumber-chef
49
+ $ bundle
50
+ $ rake build
51
+ $ gem install pkg/cucumber-chef-VERSION.gem
52
+
53
+ Again, depending on your local setup (ie whether you're using RVM or rbenv, or distribution-provided Ruby), you may need to run parts of this process with superuser privileges.
54
+
55
+ ### Running `cucumber-chef init`
56
+
57
+ Cucumber-Chef ships with an initialization task, which will interactively generate configuration file. This requires you to have, and know your Amazon Web Services credntials. On completion of the interactive configuration, it will provision a machine on EC2, and set up the entire infrastructure, using Chef.
58
+
59
+ Cucumber-Chef doesn't demand where you keep your configuration file. By default, the config will be created in `~/.cucumber-chef`, but this can be overridden. Cucumber-Chef is clever enough to find your config, so it's all cool.
26
60
 
27
- $ cucumber-chef
61
+ The two obvious places to keep this config, are in the top level of your Chef repository, or in a dedicated Cucumber-Chef repository, but you're free to do whatever works for you.
62
+
63
+ You can view and verify the current config at any time by running `cucumber-chef displayconfig`. If Cucumber-Chef thinks your config is incorrect, or incomplete, it'll tell you.
64
+
65
+ ## Using Cucumber-Chef
66
+
67
+ Once installed, you can run `cucumber-chef` on the command line to get an overview of the tasks it can carry out.
68
+
69
+ $ cucumber-chef
28
70
  Tasks:
29
- cucumber-chef connect # Connect to a container in your test lab
30
- cucumber-chef destroy # Destroy running test labs
31
- cucumber-chef displayconfig # Display the current config from knife.rb
32
- cucumber-chef help [TASK] # Describe available tasks or one specific task
33
- cucumber-chef info # Display information about the current test lab
34
- cucumber-chef project <project name> # Create a project template for testing an infrastructure
35
- cucumber-chef setup # Set up a cucumber-chef test lab in Amazon EC2
36
- cucumber-chef test # Run a cucumber-chef test suite from a workstation.
37
- cucumber-chef upload <project name> # Upload a cucumber-chef test
71
+ cucumber-chef create <project> # Create a project template for testing an infrastructure.
72
+ cucumber-chef diagnose <container> # Provide diagnostics from the chef-client on the specified container.
73
+ cucumber-chef displayconfig # Display the current cucumber-chef config.
74
+ cucumber-chef down # Shutdown the cucumber-chef test lab
75
+ cucumber-chef help [TASK] # Describe available tasks or one specific task
76
+ cucumber-chef info # Display information about the current test lab.
77
+ cucumber-chef init # Initalize cucumber-chef configuration
78
+ cucumber-chef ps [ps-options] # Snapshot of the current cucumber-chef test lab container processes.
79
+ cucumber-chef setup # Setup cucumber-chef test lab in Amazon EC2
80
+ cucumber-chef ssh [container] # SSH to cucumber-chef test lab or [container] if specified.
81
+ cucumber-chef teardown # Teardown cucumber-chef test lab in Amazon EC2
82
+ cucumber-chef test [cucumber-options] # Test a project using the cucumber-chef test suite.
83
+ cucumber-chef up # Startup the cucumber-chef test lab
84
+
85
+ After tunning set up, which takes about 15 minutes, you'll have a fully funtioning platform available for you to use. Let's just quickly review what that means. You will have an EC2 machine, fully managed by Chef, and providing the following:
38
86
 
39
- ### Integrate with Hosted Chef and Amazon EC2
87
+ * The ability to provision LXC containers
88
+ * The ability to run tests against LXC containers
89
+ * A dedicated environment for certain kinds of testing scenarios
40
90
 
41
- In it's current incarnation, Cucumber-Chef makes two important assumptions. Firstly, it assumes you're using Opscode Hosted Chef rather than your own Chef server. Secondly, it assume that you are comfortable with using Amazon's EC2 service for providing the 'bare metal' on which we set up the test lab.
91
+ The next stage is to set up a project. A project is simply a directory structure for containing your cucumber features and steps, already set up with an appropriate environment to make use of the step definitions provided with Cucumber-Chef. Cucumber-chef provides a task which will create a the directory for you, and populate it with a README and an example feature and steps. These represent futher documentation, and provide a model and steps to get you up and running with your testing as quickly as possible.
42
92
 
43
- Cucumber-chef is tightly integrated with Chef - it uses your knife.rb for credentials, and any cucumber-chef-specific configuration goes in knife.rb under the cucumber-chef namespace.
93
+ $ cd /path/to/chef-repo
94
+ $ cucumber-chef create myproject
44
95
 
45
- On installation, the first thing you should do is run:
96
+ This will create a directory, cucumber-chef, and a subdirectory, `myproject`.
46
97
 
47
- $ cucumber-chef displayconfig
98
+ └── myproject
99
+ ├── README
100
+ └── features
101
+ ├── myproject.feature
102
+ ├── step_definitions
103
+ │   └── myproject_steps.rb
104
+ └── support
105
+ └── env.rb
48
106
 
49
- This will look for your knife.rb, and extract the relevant sections, check them, and display them on the screen. If any entries are missing, it will alert you.
107
+ ### General Tasks
50
108
 
51
- The recommended best practice for Chef is to keep your knife.rb inside your organisation's Chef repository, inside the .chef directory, and use environment variables to specify username, organisation name and cloud provider credentials. Cucumber-chef supports and encourages this approach. It will search for a directory called .chef in your current directory, and then carry on going up the directory tree until it finds one. In practice this means that if you stay within the chef-repo directory for the organisation on which you're working, cucumber-chef will use the knife.rb; if your elsewhere in the filesystem rooted in your home directory, and have .chef in your home directory, cucumber-chef will use that. Otherwise you'll need to either change into a directory where a .chef can be found, or copy, creatre or link accordingly. In most cases we anticipate that you'll be inside the chef-repo of your organisation, and the documentation is written from this perspective.
109
+ #### `up`
52
110
 
53
- If you haven't already, refactor your knife.rb to look like this:
111
+ If you are using an EBS volume, you can start and stop your test lab. This task will attempt to start your Cucumber-Chef test lab if it is currently stopped.
54
112
 
55
- current_dir = File.dirname(__FILE__)
56
- user = ENV['OPSCODE_USER'] || ENV['USER']
57
- log_level :info
58
- log_location STDOUT
59
- node_name user
60
- client_key "#{ENV['HOME']}/.chef/#{user}.pem"
61
- validation_client_name "#{ENV['ORGNAME']}-validator"
62
- validation_key "#{ENV['HOME']}/.chef/#{ENV['ORGNAME']}-validator.pem"
63
- chef_server_url "https://api.opscode.com/organizations/#{ENV['ORGNAME']}"
64
- cache_type 'BasicFile'
65
- cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
66
- cookbook_path ["#{current_dir}/../cookbooks"]
113
+ #### `down`
67
114
 
68
- Now set your Hosted Chef username and organization name using environment variables:
115
+ If you are using an EBS volume, you can start and stop your test lab. This task will attempt to stop your Cucumber-Chef test lab if it is currently running.
69
116
 
70
- $ export OPSCODE_USER=platform_user_name
71
- $ export ORGNAME=platform_organisation
117
+ ## Writing Tests
72
118
 
73
- Now put your validator and client keys in $HOME/.chef. Verify that everything still works:
119
+ Once you've got your test lab set up, and you've generated a project, it's time to crack on with writing a test. The basic idea is this:
74
120
 
75
- $ knife client list
121
+ 1. An infrastructure requirement is established
122
+ 2. Write a cucumber feature that expresses the required behaviour of the infrastructure requirement
123
+ 3. Write steps that will build this infrastructure environment on the test lab, using the step definitions provided - these include the ability to create a container, apply roles to it, and destroy it again.
124
+ 4. Write cookbooks and recipes and supporting code to make the test pass
76
125
 
77
- If you get results back, we're in business.
126
+ ### Container Details
78
127
 
79
- Now add the EC2 configuration:
128
+ All containers operate off a bridged interface on the test-lab. All outbound, non-local traffic from the LXC containers are NAT'd through the test-lab and off to the outside world. This bridged interface on the test-lab is configured as follows:
80
129
 
81
- knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
82
- knife[:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
83
- knife[:aws_ssh_key_id] = ENV['AWS_SSH_KEY_ID']
84
- knife[:identity_file] = "/path/to/aws_ssh_key.pem"
85
- knife[:availability_zone] = "eu-west-1a"
86
- knife[:region] = "eu-west-1"
87
- knife[:aws_image_id] = "ami-339ca947"
130
+ CIDR: 192.168.0.0/16
131
+ IP Address: 192.168.255.254
132
+ Netmask: 255.255.255.0
133
+ Broadcast: 192.168.255.255
88
134
 
89
- Note that right now Cucumber-Chef only supports Ubuntu-based test labs.
135
+ You are free to use any IP in this /24, with the exception of the test-lab itself, which is at `192.168.255.254`.
90
136
 
91
- And set your environment variables:
137
+ ### Built In Test Steps
92
138
 
93
- $ export AWS_ACCESS_KEY_ID=SEKRITKEY
94
- $ export AWS_SECRET_ACCESS_KEY=REELYSEKRITKEY
95
- $ export AWS_SSH_KEY_ID
139
+ #### Provisioning
96
140
 
97
- And then ensure your AWS ssh key is in place.
141
+ We provide several built in steps to help you with provisioning. It is suggested you build a `Background` section for your features so these are not repeated with each scenario. This example `Background` section does the following:
98
142
 
99
- Now check your config again, with cucumber-chef display config. If you get no complaints, you're ready to set up a test lab.
143
+ * Sets up a server called `devopserver`.
144
+ * Makes the server persistant (it will remain up after the test finishes, which is the default behaviour).
145
+ * Assigns what linux distro and release to use for the container.
146
+ * Assigns it an IP address on the test lab network (this can be omitted for an auto-assigned IP).
147
+ * Tells Cucumber-Chef to provision the server.
148
+ * Adds the `chef-client::service` recipe in to the chef-client's run list.
149
+ * Executes `chef-client` with the generated run list.
150
+ * Starts an SSH session to the server so you can execute commands and test the output of those commands in the scenarios.
100
151
 
152
+ Here is the `Background` section as you might write it in a feature:
101
153
 
102
- ### Run cucumber-chef setup
154
+ Background:
155
+ * I have a server called "devopserver"
156
+ * "devopserver" should be persistant
157
+ * "devopserver" is running "ubuntu" "lucid"
158
+ * "devopserver" has an IP address of "192.168.73.31"
159
+ * "devopserver" has been provisioned
160
+ * the "chef-client::service" recipe has been added to the "devopserver" run list
161
+ * the chef-client has been run on "devopserver"
162
+ * I ssh to "devopserver" with the following credentials:
163
+ | username | password |
164
+ | root | root |
103
165
 
166
+ To get a persistent server with an auto-assigned IP address using the generated and populated test lab SSH key pairs for SSH authentication you could write something like this. Remember the tests run on the test lab, so we can just back out a directory and reference our test lab SSH private key directly:
104
167
 
105
- $ cucumber-chef setup
168
+ Background:
169
+ * I have a server called "devopserver"
170
+ * "devopserver" is running "ubuntu" "lucid"
171
+ * "devopserver" has been provisioned
172
+ * the "chef-client::service" recipe has been added to the "devopserver" run list
173
+ * the chef-client has been run on "devopserver"
174
+ * I ssh to "devopserver" with the following credentials:
175
+ | username | keyfile |
176
+ | root | ../.ssh/id_rsa |
106
177
 
107
- This command will set up a complete test lab environment, As long as you've provided valid AWS and Opscode credentials, it will do this automatically. The process takes about 15 minutes, after which you'll have a fully funtioning platform available for you to use. Let's just quickly review what that means. You will have an EC2 machine, fully managed by Chef, and providing the following:
178
+ You can add roles to the run list by writing:
108
179
 
109
- * The ability to provision LXC containers
110
- * The ability to run tests against LXC containers
111
- * A dedicated container for certain kinds of testing scenarios
180
+ * the "chef-client" role has been added to the "devopserver" run list
112
181
 
113
- The next stage is to set up a project. A project is simply a directory structure for containing your cucumber features and steps, already set up with an appropriate environment to make use of the step definitions provided with cucumber-chef. We think it makes most sense to have this in your organisation's chef repo. Cucumber-chef provides a task which will create a the directory for you, and populate it with a README and an example feature and step.
182
+ Here's an example `Scenario` section you might have to test if the chef-client is actually running as a daemon:
114
183
 
184
+ Scenario: Chef-Client is running as a daemon
185
+ When I run "ps aux | grep [c]hef-client"
186
+ Then I should see "chef-client" in the output
187
+ And I should see "-d" in the output
188
+ And I should see "-i 1800" in the output
189
+ And I should see "-s 20" in the output
115
190
 
116
- $ cd /path/to/chef-repo
117
- $ cucumber-chef project example
191
+ See the section below label *Example Test Run* for more examples.
118
192
 
119
- This will create a directory, cucumber-chef, and a subdirectory, example.
193
+ ##### List of Provisioning Steps
120
194
 
121
- └── example
122
- ├── README
123
- └── features
124
- ├── example.feature
125
- ├── step_definitions
126
- │   └── example_step.rb
127
- └── support
128
- └── env.rb
195
+ Create a server profile:
129
196
 
130
- ## Writing tests
197
+ I have a server called "(server)"
131
198
 
132
- Once you've got your test lab set up, and you've generated a project, it's time to crack on with writing a test. The basic idea is this:
199
+ Set a (server) to persist or not:
200
+
201
+ "(server)" should( not) be persistant
202
+
203
+ Set (server) to run linux of type (distro), using (release).
204
+
205
+ "(server)" is running "(distro)" "(release)"
206
+
207
+ Supported (distro -> releases):
208
+
209
+ ubuntu -> lucid, maverick, natty, oneiric, precise
210
+ fedora -> (release number)
211
+
212
+ Fedora releases 12, 13, 14 tested OK.
213
+
214
+ Assign (server) a specific IP address (must be on the test lab network segment):
215
+
216
+ "(server)" has an IP address of "(ip)"
217
+
218
+ Assign (server) a specific MAC address:
219
+
220
+ "(server)" has a MAC address of "(mac)"
221
+
222
+ Initiate the provision of a (server). All attributes of the server need to be set before this:
223
+
224
+ "(server)" has been provisioned
225
+
226
+ Add a role to the chef-client run list:
227
+
228
+ the "(role)" role has been added to the "(server)" run list
229
+
230
+ Add a recipe to the chef-client run list:
231
+
232
+ the "(recipe)" recipe has been added to the "(server)" run list
233
+
234
+ Run the chef-client:
235
+
236
+ the chef-client has been run on "(server)"
237
+
238
+ #### Chef Steps
239
+
240
+ To prep a server with a role and data bag:
241
+
242
+ * the following roles have been updated:
243
+ | role | role_path |
244
+ | users | ./support/roles/ |
245
+ * the "users" role has been added to the "users" run list
246
+ * the following databags have been updated:
247
+ | databag | databag_path |
248
+ | users | ./support/data_bags/users |
249
+
250
+ ##### List of Chef Steps
251
+
252
+ Update/push roles to the chef-server:
253
+
254
+ * the following roles have been updated:
255
+ | role | role_path |
256
+ | users | ./support/roles/ |
257
+
258
+ Update/push data bags to the chef-server:
259
+
260
+ * the following databags have been updated:
261
+ | databag | databag_path |
262
+ | users | ./support/data_bags/users |
263
+
264
+ #### SSH Steps
265
+
266
+ Here is how you might setup and initate an SSH session using password authentication to a server named `devopserver`:
267
+
268
+ * I have no public keys set
269
+ * I ssh to "devopserver" with the following credentials:
270
+ | username | password |
271
+ | root | root |
272
+
273
+ Here is how you might setup and initate an SSH session using public key authentication to a server named `users`:
274
+
275
+ * I ssh to "users" with the following credentials:
276
+ | username | keyfile |
277
+ | root | ../.ssh/id_rsa |
278
+
279
+ Since the cukes run on the test lab, we can directly reference the public key pairs already there and populated for us.
280
+
281
+ Suppose we have a cookbook that creates new users. After it runs we should be able to SSH in with our public keys. Let's test this. First we'll do our setup in the `Background`:
282
+
283
+ Background:
284
+ * I have a server called "users"
285
+ * "users" is running "ubuntu" "lucid"
286
+ * "users" has been provisioned
287
+ * the following roles have been updated:
288
+ | role | role_path |
289
+ | users | ./support/roles/ |
290
+ * the "users" role has been added to the "users" run list
291
+ * the following databags have been updated:
292
+ | databag | databag_path |
293
+ | users | ./support/data_bags/users |
294
+ * the chef-client has been run on "users"
295
+
296
+ And now for the `Scenario`:
297
+
298
+ Scenario: The user can ssh in to the system with their key pair
299
+ * I ssh to "users" with the following credentials:
300
+ | username | keyfile |
301
+ | bdobbs | ./support/keys/bdobbs |
302
+ When I run "hostname"
303
+ Then I should see "users" in the output
304
+
305
+
306
+ ##### List of SSH Steps
307
+
308
+ Sets the authentication method to password:
309
+
310
+ I have no public keys set
311
+
312
+ Start an SSH session to the server (server) using password authentication:
313
+
314
+ I ssh to "(server)" with the following credentials:
315
+ | username | password |
316
+ | root | root |
317
+
318
+ Start an SSH session to the server (server) using public key authentication:
319
+
320
+ I ssh to "(server)" with the following credentials:
321
+ | username | keyfile |
322
+ | root | id_rsa |
323
+
324
+ Executes (command) over the previously established SSH session on the server (server):
325
+
326
+ I run "(command)"
327
+
328
+ Check (command) output for an (expected) or (not-expected) string:
329
+
330
+ I should( not) see "(expected)" in the output
331
+
332
+ Check (command) output for existance of or lack of (server) settings:
333
+
334
+ I should( not) see the "(ip|mac)" of "(server)" in the output
335
+
336
+ #### Minitest
337
+
338
+ ##### List of Minitest Steps
339
+
340
+ I enable the running of MiniTest suites for "(server)"
341
+
342
+ the tests should run and pass on "(server)"
343
+
344
+ #### Cucumber Before Hook Centric Helpers
345
+
346
+ * `chef_set_client_config(config={})`
347
+
348
+ This method configures the chef-client's `client.rb` file. Currently you can specify `:orgname`, `:log_level`, `:log_location`, `:chef_server_url` and `:validation_client_name`. See your `env.rb` file if you need to change this to point it at a Hosted Chef Server or need to modify any of these values.
349
+
350
+ ##### Examples
351
+
352
+ # for Opscode Hosted chef-server use this:
353
+ #chef_set_client_config(:orgname => "cucumber-chef")
354
+
355
+ # for Opscode OS chef-server on the Cucumber-Chef test lab use this:
356
+ chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
357
+ :validation_client_name => "chef-validator")
358
+
359
+ ## Running Tests
360
+
361
+ You can write the tests and Chef code wherever you like. We're assuming you prefer working on your local machine, and checking into version control. But we don't really care. When it's time to run tests, Cucumber-Chef provides a task which handles this:
362
+
363
+ $ cucumber-chef test
364
+
365
+ Containers are now persisted by default. This means faster run times on average but if things get screwy, or you want to test from a clean slate, you can easily reset your containers. If you pass in either `-z` or `--destroy` all containers will be wiped before the test run starts.
366
+
367
+ $ cucumber-chef help test
368
+ Usage:
369
+ cucumber-chef test [cucumber-options]
370
+
371
+ Options:
372
+ -z, [--destroy] # destroy all containers before test run
373
+
374
+ Test a project using the cucumber-chef test suite.
375
+
376
+ You can now pass in options for cucumber or even setup profiles via `cucumber.yml`. Any command-line options specified after the project name will be passed on to cucumber. For example:
377
+
378
+ $ cucumber-chef test --tags @wip -c -v -b
379
+
380
+ To take advantage of cucumber profiles, create a `cucumber.yml` configuration file in the root of your chef-repo; just as you would with any other project using cucumber. In this file you can take full advantage of the Cucumber profiles as definied on their wiki, https://github.com/cucumber/cucumber/wiki/cucumber.yml.
381
+
382
+ Here is an example default project for `cucumber.yml` which turns on colored output, verbosity and full backtraces for all test runs:
383
+
384
+ ---
385
+ default: -c -v -b
386
+
387
+ Running the test task will upload your current project to the test lab, and run the tests, reporting the results back to the screen. Cucumber-chef also provides an upload task, so you can push the current project to the test lab, and then connect to test lab yourself to run tests in a more granular way. To do this, you need to know the IP of the test lab. You can find this out by running:
388
+
389
+ $ cucumber-chef info
390
+
391
+ At present, Cucumber-Chef only allows one test lab per AWS account. In practice, this has not been a constraint. LXC is incredibly lightweight, and a large number of containers can be provisioned on even a small EC2 instance.
392
+
393
+ ### When Things Go Oh So Wrong
394
+
395
+ We have put in a few tasks to help you diagnose any issues you may come across with the test lab, containers or your cookbooks and recipes. There are two main tasks available to help you with this: `ssh` and `diagnose`.
396
+
397
+ #### `ssh`
398
+
399
+ $ cucumber-chef help ssh
400
+ Usage:
401
+ cucumber-chef ssh [container]
402
+
403
+ Options:
404
+ [--test] # INTERNAL USE ONLY
405
+
406
+ SSH to cucumber-chef test lab or [container] if specified.
407
+
408
+ This command provides you with a rapid way to connect to either your test lab or containers. Think `vagrant ssh`; we took a queue from their wonderful gem and realized we want our gem to provide the same sort of functionality. The main difference between our `ssh` task and the way Vagrant's task works is that we generate a fresh ssh key pair whenever a test lab is setup; so you can rest assured no one else has a copy of the credientials. You also do not have to worry about generating or specifying your own key pair to override a default key pair as is the case with Vagrant if you do not want to use the one shipped with Vagrant.
409
+
410
+ $ cucumber-chef ssh
411
+ Attempting SSH connection to cucumber-chef 'test lab'...
412
+ _____ _ _____ _ __
413
+ / ____| | | / ____| | / _|
414
+ | | _ _ ___ _ _ _ __ ___ | |__ ___ _ __| | | |__ ___| |_
415
+ | | | | | |/ __| | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \ / _ \ _|
416
+ | |___| |_| | (__| |_| | | | | | | |_) | __/ | | |____| | | | __/ |
417
+ \_____\__,_|\___|\__,_|_| |_| |_|_.__/ \___|_| \_____|_| |_|\___|_|
418
+
419
+
420
+ Welcome to the Cucumber Chef Test Lab v2.0.0.rc1
421
+
422
+ Last login: Mon Jun 4 07:56:40 2012 from [REDACTED]
423
+ ubuntu@cucumber-chef:~$
424
+
425
+ Keep in mind with Amazon's EC2 the base `ubuntu` user is already in the sudoers file; so you can `sudo su -` without needing the password.
426
+
427
+ ubuntu@cucumber-chef:~$ sudo su -
428
+ root@cucumber-chef:~#
429
+
430
+ You can also specify a container name to SSH directly into that container. For now you are always logged in as `root` when you SSH to a container.
431
+
432
+ $ cucumber-chef ssh devopserver
433
+ Attempting SSH connection to cucumber-chef container 'devopserver'...
434
+ _____ _ _____ _ __
435
+ / ____| | | / ____| | / _|
436
+ | | _ _ ___ _ _ _ __ ___ | |__ ___ _ __| | | |__ ___| |_
437
+ | | | | | |/ __| | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \ / _ \ _|
438
+ | |___| |_| | (__| |_| | | | | | | |_) | __/ | | |____| | | | __/ |
439
+ \_____\__,_|\___|\__,_|_| |_| |_|_.__/ \___|_| \_____|_| |_|\___|_|
133
440
 
134
- 1) An infrastructure requirement is established
135
- 2) Write a cucumber feature that expresses the required behaviour of the infrastructure requirement
136
- 3) Write steps that will build this infrastructure environment on the test lab, using the step definitions provided - these include the ability to create a container, apply roles to it, and destroy it again.
137
- 4) Write cookbooks and recipes and supporting code to make the test pass
138
441
 
139
- ## Running tests
442
+ Welcome to the Cucumber Chef Test Lab v2.0.0.rc1
140
443
 
141
- You can write the tests and Chef code wherever you like. We're assuming you prefer working on your local machine, and checking into version control. But we don't really care. When it's time to run tests, cucumber-chef provides a task which handles this:
444
+ You are now logged in to the LXC 'devopserver'
142
445
 
143
- $ cucumber-chef test myproject
446
+ root@devopserver:~#
144
447
 
145
- At the moment cucumber-chef doesn't pass though clever filtering and tagging options that cucumber supports - you run all the tests. We're going to improve that soon, again, patches and pull requests very welcome.
448
+ #### `diagnose`
146
449
 
147
- Running the test task will upload your current project to the test lab, and run the tests, reporting the results back to the screen. Cucumber-chef also provides an upload task, so you can push the current project to the test lab, and then connect to test lab yourself to run tests in a more granular way. To do this, you need to know the IP of the test lab. You can find this out by running:
450
+ This command provides you with a rapid way to get to the chef-client logs without needing to SSH into a container. There are a few basic options with this task, let's take a look at them.
148
451
 
149
- $ cucumber-chef info
452
+ $ cucumber-chef help diagnose
453
+ Usage:
454
+ cucumber-chef diagnose <container>
150
455
 
151
- At present, Cucumber-Chef only allows one test lab per AWS account and Opscode Hosted Chef account.
456
+ Options:
457
+ -n, [--lines=N] # output the last N lines of the chef-client 'chef.log'
458
+ # Default: 1
459
+ -s, [--strace] # output the chef-client 'chef-stacktrace.out'
460
+ # Default: true
461
+ -l, [--log] # output the chef-client 'chef.log'
462
+ # Default: true
152
463
 
464
+ Provide diagnostics from the chef-client on the specified container.
153
465
 
466
+ With the default options in effect, this task will output the `chef-stacktrace.out` file along with the last line of the `chef.log` file. You can of course request as many lines as you desire from the `chef.log` file. For example to look at the last 1000 lines of only the `chef.log` file you would likely run the task as follows.
467
+
468
+ $ cucumber-chef diagnose devopserver --no-strace -n 1000
469
+
470
+ Maybe you only want to view the `chef-stacktrace.out` file?
471
+
472
+ $ cucumber-chef diagnose devopserver --no-log
473
+
474
+ Maybe you want to run it with the default options in play; you would likely get some output as follows.
475
+
476
+ $ cucumber-chef diagnose devopserver
477
+ Attempting to collect diagnostic information on cucumber-chef container 'sysopserver'...
478
+ ----------------------------------------------------------------------------
479
+ chef-stacktrace.out:
480
+ ----------------------------------------------------------------------------
481
+ Generated at 2012-06-04 08:30:20 +0000
482
+ Net::HTTPServerException: 412 "Precondition Failed"
483
+ /opt/opscode/embedded/lib/ruby/1.9.1/net/http.rb:2303:in `error!'
484
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:264:in `block in api_request'
485
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:328:in `retriable_rest_request'
486
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:240:in `api_request'
487
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:139:in `post_rest'
488
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/client.rb:313:in `sync_cookbooks'
489
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/client.rb:194:in `setup_run_context'
490
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/client.rb:162:in `run'
491
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/application/client.rb:254:in `block in run_application'
492
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/application/client.rb:241:in `loop'
493
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/application/client.rb:241:in `run_application'
494
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/application.rb:70:in `run'
495
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/bin/chef-client:26:in `<top (required)>'
496
+ /usr/bin/chef-client:19:in `load'
497
+ /usr/bin/chef-client:19:in `<main>'
498
+ ----------------------------------------------------------------------------
499
+ chef.log:
500
+ ----------------------------------------------------------------------------
501
+ [Mon, 04 Jun 2012 08:30:20 +0000] FATAL: Net::HTTPServerException: 412 "Precondition Failed"
502
+
503
+
504
+ #### `ps`
505
+
506
+ This command provides you with a snapshot of all the container processes running on the Cucumber-Chef test lab. You can pass in `ps` command line options to customize the output as you desire.
507
+
508
+ $ cucumber-chef help ps
509
+ Usage:
510
+ cucumber-chef ps [ps-options]
511
+
512
+ Snapshot of the current cucumber-chef test lab container processes.
513
+
514
+ Standard usage using `aux` options:
515
+
516
+ $ cucumber-chef ps aux
517
+ cucumber-chef v2.0.0.rc1
518
+
519
+ Getting container processes from cucumber-chef test lab...
520
+
521
+ ============================================================================
522
+ CONTAINER USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
523
+ sudo root 375 0.0 0.0 2368 608 ? S Jun21 0:00 upstart-udev-bridge --daemon
524
+ sudo syslog 384 0.0 0.0 27296 1264 ? Sl Jun21 0:00 rsyslogd -c4
525
+ sudo root 396 0.0 0.0 2236 388 ? S<s Jun21 0:00 udevd --daemon
526
+ sudo root 406 0.0 0.0 1840 556 pts/19 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
527
+ sudo root 410 0.0 0.0 1840 560 pts/17 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
528
+ sudo root 412 0.0 0.0 1840 560 pts/18 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
529
+ sudo root 416 0.0 0.0 2428 812 ? Ss Jun21 0:00 cron
530
+ sudo root 453 0.0 0.0 1840 564 pts/16 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
531
+ sudo root 455 0.0 0.0 1840 556 pts/20 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
532
+ sudo root 477 0.0 0.0 2288 576 ? Ss Jun21 0:00 dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0
533
+ sudo root 493 0.0 0.1 5600 2132 ? Ss Jun21 0:00 /usr/sbin/sshd -D
534
+ users root 20777 0.0 0.0 2720 1484 ? Ss Jun21 0:02 /sbin/init
535
+ users syslog 20876 0.0 0.0 27296 1172 ? Sl Jun21 0:02 rsyslogd -c4
536
+ users root 20877 0.0 0.0 2368 560 ? S Jun21 0:00 upstart-udev-bridge --daemon
537
+ users root 20883 0.0 0.0 2236 516 ? S<s Jun21 0:00 udevd --daemon
538
+ users root 20914 0.0 0.0 1840 544 pts/4 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
539
+ users root 20918 0.0 0.0 1840 540 pts/2 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
540
+ users root 20921 0.0 0.0 1840 544 pts/3 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
541
+ users root 20925 0.0 0.0 2428 788 ? Ss Jun21 0:00 cron
542
+ users root 20953 0.0 0.0 1840 544 pts/1 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
543
+ users root 20954 0.0 0.0 1840 544 pts/5 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
544
+ users root 20970 0.0 0.0 2288 572 ? Ss Jun21 0:00 dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0
545
+ users root 20987 0.0 0.1 5600 2128 ? Ss Jun21 0:01 /usr/sbin/sshd -D
546
+ users root 21308 0.0 0.0 1848 488 ? S Jun21 0:07 tail -n 250 -f client.log
547
+ users root 21519 0.0 0.0 1848 484 ? S 02:19 0:02 tail -n 250 -f /var/log/auth.log
548
+ users root 21851 0.0 0.0 1848 484 ? S 02:20 0:02 tail -n 250 -f /var/log/chef/client.log
549
+ chef-client root 27226 0.0 0.0 2728 1524 ? Ss Jun21 0:00 /sbin/init
550
+ chef-client syslog 27328 0.0 0.0 27296 1244 ? Sl Jun21 0:00 rsyslogd -c4
551
+ chef-client root 27329 0.0 0.0 2368 584 ? S Jun21 0:00 upstart-udev-bridge --daemon
552
+ chef-client root 27340 0.0 0.0 2236 520 ? S<s Jun21 0:00 udevd --daemon
553
+ chef-client root 27364 0.0 0.0 1840 548 pts/9 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
554
+ chef-client root 27368 0.0 0.0 1840 548 pts/7 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
555
+ chef-client root 27369 0.0 0.0 1840 548 pts/8 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
556
+ chef-client root 27371 0.0 0.0 2428 804 ? Ss Jun21 0:00 cron
557
+ chef-client root 27401 0.0 0.0 1840 548 pts/6 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
558
+ chef-client root 27402 0.0 0.0 1840 548 pts/10 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
559
+ chef-client root 27420 0.0 0.0 2288 572 ? Ss Jun21 0:00 dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0
560
+ chef-client root 27437 0.0 0.1 5600 2128 ? Ss Jun21 0:00 /usr/sbin/sshd -D
561
+ chef-client root 27616 0.2 1.2 26292 22128 ? Sl Jun21 6:00 /opt/opscode/embedded/bin/ruby /usr/bin/chef-client -d -P /var/run/chef/client.pid -L /var/log/chef/client.log -c /etc/chef/client.rb -i 1800 -s 20
562
+ timezone root 28244 0.0 0.0 2724 1568 ? Ss Jun21 0:00 /sbin/init
563
+ timezone root 28355 0.0 0.0 2368 600 ? S Jun21 0:00 upstart-udev-bridge --daemon
564
+ timezone syslog 28356 0.0 0.0 27296 1268 ? Sl Jun21 0:00 rsyslogd -c4
565
+ timezone root 28366 0.0 0.0 2236 504 ? S<s Jun21 0:00 udevd --daemon
566
+ timezone root 28385 0.0 0.0 1840 556 pts/14 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
567
+ timezone root 28388 0.0 0.0 1840 560 pts/12 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
568
+ timezone root 28390 0.0 0.0 1840 556 pts/13 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
569
+ timezone root 28397 0.0 0.0 2428 812 ? Ss Jun21 0:00 cron
570
+ timezone root 28423 0.0 0.0 1840 564 pts/11 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
571
+ timezone root 28426 0.0 0.0 1840 560 pts/15 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
572
+ timezone root 28449 0.0 0.0 2288 576 ? Ss Jun21 0:00 dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0
573
+ timezone root 28466 0.0 0.1 5600 2124 ? Ss Jun21 0:00 /usr/sbin/sshd -D
574
+ sudo root 32737 0.0 0.0 2720 1580 ? Ss Jun21 0:00 /sbin/init
575
+ users root 32741 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
576
+ users root 32742 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
577
+ chef-client root 32745 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
578
+ chef-client root 32747 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
579
+ timezone root 32754 0.0 0.0 2232 272 ? S< Jun21 0:00 udevd --daemon
580
+ timezone root 32755 0.0 0.0 2232 272 ? S< Jun21 0:00 udevd --daemon
581
+
582
+ ### Example Test Run
583
+
584
+ Here is an example of using Cucumber-Chef to do a basic test. In this test we will provision a server called `devopserver` and apply the `chef-client::service` recipe from the `chef-client` community cookbook. This example assumes you have your test lab provisioned and up and running. First things first, make sure you've downloaded the `chef-client` community cookbook and placed it in your chef-repo.
585
+
586
+ Now upload the `chef-client` community cookbook to your Cucumber-Chef test lab.
587
+
588
+ $ cc-knife cookbook upload chef-client
589
+ Uploading chef-client [1.1.2]
590
+ Uploaded 1 cookbook.
591
+
592
+ Next create your `devopserver` feature.
593
+
594
+ $ cucumber-chef create devopserver
595
+
596
+ Here is the feature we'll be using. This feature has some extra scenarios to illustrate how you might go about testing other parts of a system. Go into the features directory of your chef-repo and replace the contents of the `devopserver.feature` file with the text below.
597
+
598
+ @devopserver @wip
599
+ Feature: Perform test driven infrastructure with Cucumber-Chef
600
+ In order to learn how to develop test driven infrastructure
601
+ As an infrastructure developer
602
+ I want to better understand how to use Cucumber-Chef
603
+
604
+ Background:
605
+ * I have a server called "devopserver"
606
+ * "devopserver" is running "ubuntu" "lucid"
607
+ * "devopserver" has been provisioned
608
+ * the "chef-client::service" recipe has been added to the "devopserver" run list
609
+ * the chef-client has been run on "devopserver"
610
+ * I ssh to "devopserver" with the following credentials:
611
+ | username | keyfile |
612
+ | root | ../.ssh/id_rsa |
613
+
614
+ Scenario: Can connect to the provisioned server via SSH password authentication
615
+ And I run "hostname"
616
+ Then I should see "devopserver" in the output
617
+
618
+ Scenario: Default root shell is bash
619
+ And I run "echo $SHELL"
620
+ Then I should see "bash" in the output
621
+
622
+ Scenario: Default gateway and resolver are using Cucumber-Chef Test Lab
623
+ And I run "route -n | grep 'UG'"
624
+ Then I should see "192.168.255.254" in the output
625
+ And I run "cat /etc/resolv.conf"
626
+ Then I should see "192.168.255.254" in the output
627
+ And I should see "8.8.8.8" in the output
628
+ And I should see "8.8.4.4" in the output
629
+
630
+ Scenario: Primary interface is configured with my IP address and MAC address
631
+ And I run "ifconfig eth0"
632
+ Then I should see the "IP" of "devopserver" in the output
633
+ And I should see the "MAC" of "devopserver" in the output
634
+
635
+ Scenario: Local interface is not configured with my IP address or MAC address
636
+ And I run "ifconfig lo"
637
+ Then I should see "127.0.0.1" in the output
638
+ And I should not see the "IP" of "devopserver" in the output
639
+ And I should not see the "MAC" of "devopserver" in the output
640
+
641
+ Scenario: Chef-Client is running as a daemon
642
+ When I run "ps aux | grep [c]hef-client"
643
+ Then I should see "chef-client" in the output
644
+ And I should see "-d" in the output
645
+ And I should see "-i 1800" in the output
646
+ And I should see "-s 20" in the output
647
+
648
+ Now we're going to execute the test. Created features are pre tagged with the name of the feature (i.e. `@<name>`) and `@wip`. Be sure to pass that to the test runner so Cucumber knows to only run tests tagged with that, unless you want to test all your features.
649
+
650
+ $ cucumber-chef test --tags @devopserver
651
+ Using features directory: /home/couldbeyou/chef-repo/features
652
+ Cucumber-Chef Test Runner Initalized!
653
+ Cleaning up any previous test runs...done.
654
+ Uploading files required for this test run...done.
655
+ Executing Cucumber-Chef Test Runner
656
+ Using the default profile...
657
+ Code:
658
+ * ./support/env.rb
659
+ * ./devopserver/step_definitions/devopserver_steps.rb
660
+ * ./sample/step_definitions/sample_steps.rb
661
+
662
+ Features:
663
+ * ./devopserver/devopserver.feature
664
+ Parsing feature files took 0m0.076s
665
+
666
+ @devopserver @wip
667
+ Feature: Perform test driven infrastructure with Cucumber-Chef
668
+ In order to learn how to develop test driven infrastructure
669
+ As an infrastructure developer
670
+ I want to better understand how to use Cucumber-Chef
671
+
672
+ Background: # ./devopserver/devopserver.feature:7
673
+ * all servers are being destroyed
674
+ * I have a server called "devopserver" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:1
675
+ * "devopserver" is running "ubuntu" "lucid" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:5
676
+ * devopserver is being provisioned
677
+ * "devopserver" has been provisioned # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:25
678
+ * the "chef-client::service" recipe has been added to the "devopserver" run list # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:33
679
+ * the chef-client has been run on "devopserver" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:37
680
+ * I ssh to "devopserver" with the following credentials: # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:57
681
+ | username | keyfile |
682
+ | root | ../.ssh/id_rsa |
683
+
684
+ Scenario: Can connect to the provisioned server via SSH password authentication # ./devopserver/devopserver.feature:17
685
+ And I run "hostname" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
686
+ Then I should see "devopserver" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
687
+
688
+ Scenario: Default root shell is bash # ./devopserver/devopserver.feature:21
689
+ And I run "echo $SHELL" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
690
+ Then I should see "bash" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
691
+
692
+ Scenario: Default gateway and resolver are using Cucumber-Chef Test Lab # ./devopserver/devopserver.feature:25
693
+ And I run "route -n | grep 'UG'" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
694
+ Then I should see "192.168.255.254" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
695
+ And I run "cat /etc/resolv.conf" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
696
+ Then I should see "192.168.255.254" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
697
+ And I should see "8.8.8.8" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
698
+ And I should see "8.8.4.4" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
699
+
700
+ Scenario: Primary interface is configured with my IP address and MAC address # ./devopserver/devopserver.feature:33
701
+ And I run "ifconfig eth0" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
702
+ Then I should see the "IP" of "devopserver" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:90
703
+ And I should see the "MAC" of "devopserver" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:90
704
+
705
+ Scenario: Local interface is not configured with my IP address or MAC address # ./devopserver/devopserver.feature:38
706
+ And I run "ifconfig lo" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
707
+ Then I should see "127.0.0.1" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
708
+ And I should not see the "IP" of "devopserver" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:90
709
+ And I should not see the "MAC" of "devopserver" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:90
710
+
711
+ Scenario: Chef-Client is running as a daemon # ./devopserver/devopserver.feature:44
712
+ When I run "ps aux | grep [c]hef-client" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
713
+ Then I should see "chef-client" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
714
+ And I should see "-d" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
715
+ And I should see "-i 1800" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
716
+ And I should see "-s 20" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
717
+
718
+ 6 scenarios (6 passed)
719
+ 58 steps (58 passed)
720
+ 2m45.515s
721
+
722
+ If all goes well you should see output similar to what's above! Enjoy and have fun!
723
+
724
+ # LINKS
725
+
726
+ Source:
727
+
728
+ * https://github.com/Atalanta/cucumber-chef
729
+
730
+ Issues:
731
+
732
+ * https://github.com/Atalanta/cucumber-chef/issues
733
+
734
+ Wiki:
735
+
736
+ * https://github.com/Atalanta/cucumber-chef/wiki
737
+
738
+ # LICENSE
739
+
740
+ Cucumber-Chef - A test driven infrastructure system
741
+
742
+ * Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
743
+ * Author: Zachary Patten <zachary@jovelabs.com>
744
+ * Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
745
+ * License: Apache License, Version 2.0
746
+
747
+ Licensed under the Apache License, Version 2.0 (the "License");
748
+ you may not use this file except in compliance with the License.
749
+ You may obtain a copy of the License at
750
+
751
+ http://www.apache.org/licenses/LICENSE-2.0
752
+
753
+ Unless required by applicable law or agreed to in writing, software
754
+ distributed under the License is distributed on an "AS IS" BASIS,
755
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
756
+ See the License for the specific language governing permissions and
757
+ limitations under the License.