cucumber-chef 2.1.0.rc.12 → 2.1.0.rc.14

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ tmtags
16
16
  *.swp
17
17
  .rvmrc
18
18
  *gem
19
+ .idea/
data/README.md CHANGED
@@ -14,7 +14,7 @@ Issues:
14
14
 
15
15
  Wiki:
16
16
 
17
- * https://github.com/Atalanta/cucumber-chef/wiki
17
+ * https://github.com/Atalanta/cucumber-chef/blob/master/WIKI.md
18
18
 
19
19
  Chat:
20
20
 
data/WIKI.md ADDED
@@ -0,0 +1,822 @@
1
+ [![Build Status](https://secure.travis-ci.org/jovelabs/cucumber-chef.png)](http://travis-ci.org/jovelabs/cucumber-chef) [![Dependency Status](https://gemnasium.com/jovelabs/cucumber-chef.png)](https://gemnasium.com/jovelabs/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.
4
+
5
+ ## Overview
6
+
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.
10
+
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.
12
+
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.
14
+
15
+ ## Getting Started
16
+
17
+ *LISTEN UP*
18
+
19
+ Here's the headline:
20
+
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.
22
+
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.
30
+
31
+ ### Installing Cucumber-Chef
32
+
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:
38
+
39
+ $ gem install cucumber-chef
40
+
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.
60
+
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
70
+ Tasks:
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 up # Startup the cucumber-chef test lab
83
+
84
+ Running just `cucumber` on the command line will run your tests.
85
+
86
+ After running setup, 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:
87
+
88
+ * The ability to provision LXC containers
89
+ * The ability to run tests against LXC containers
90
+ * A dedicated environment for certain kinds of testing scenarios
91
+
92
+ 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.
93
+
94
+ $ cd /path/to/chef-repo
95
+ $ cucumber-chef create myproject
96
+
97
+ This will create a directory, cucumber-chef, and a subdirectory, `myproject`.
98
+
99
+ chef-repo/
100
+ ├── .chef
101
+ ├── cookbooks
102
+ ├── .cucumber-chef
103
+ │ ├── aws
104
+ │ │ └── checksums
105
+ │ ├── checksums
106
+ │ └── vagrant
107
+ │ ├── artifacts
108
+ │ └── checksums
109
+ ├── data_bags
110
+ ├── environments
111
+ ├── features
112
+ │ ├── support
113
+ │ │ ├── cc-hooks.rb
114
+ │ │ ├── env.rb
115
+ │ │ ├── data_bags
116
+ │ │ ├── environments
117
+ │ │ ├── keys
118
+ │ │ └── roles
119
+ ├── roles
120
+ └── site-cookbooks
121
+
122
+
123
+ └── myproject
124
+ ├── README
125
+ └── features
126
+ ├── myproject.feature
127
+ ├── step_definitions
128
+ │   └── myproject_steps.rb
129
+ └── support
130
+ └── env.rb
131
+
132
+ ### General Tasks
133
+
134
+ #### `up`
135
+
136
+ 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.
137
+
138
+ #### `down`
139
+
140
+ 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.
141
+
142
+ ## Writing Tests
143
+
144
+ 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:
145
+
146
+ 1. An infrastructure requirement is established
147
+ 2. Write a cucumber feature that expresses the required behaviour of the infrastructure requirement
148
+ 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.
149
+ 4. Write cookbooks and recipes and supporting code to make the test pass
150
+
151
+ ### Container Details
152
+
153
+ 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:
154
+
155
+ CIDR: 192.168.0.0/16
156
+ IP Address: 192.168.255.254
157
+ Netmask: 255.255.255.0
158
+ Broadcast: 192.168.255.255
159
+
160
+ 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`.
161
+
162
+ ### Built In Test Steps
163
+
164
+ #### Provisioning<a id="provisioning"></a>
165
+
166
+ 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:
167
+
168
+ * Sets up a server called `devopserver`.
169
+ * Makes the server persistant (it will remain up after the test finishes, which is the default behaviour).
170
+ * Assigns what linux distro and release to use for the container.
171
+ * Assigns it an IP address on the test lab network (this can be omitted for an auto-assigned IP).
172
+ * Tells Cucumber-Chef to provision the server.
173
+ * Adds the `chef-client::service` recipe in to the chef-client's run list.
174
+ * Executes `chef-client` with the generated run list.
175
+ * Starts an SSH session to the server so you can execute commands and test the output of those commands in the scenarios.
176
+
177
+ Here is the `Background` section as you might write it in a feature:
178
+
179
+ Background:
180
+ * I have a server called "devopserver"
181
+ * "devopserver" should be persistant
182
+ * "devopserver" is running "ubuntu" "lucid"
183
+ * "devopserver" has an IP address of "192.168.73.31"
184
+ * "devopserver" has been provisioned
185
+ * "devopserver" is in the "foobar" environment
186
+ * the "chef-client::service" recipe has been added to the "devopserver" run list
187
+ * the chef-client has been run on "devopserver"
188
+ * I ssh to "devopserver" with the following credentials:
189
+ | username | password |
190
+ | root | root |
191
+
192
+ 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:
193
+
194
+ Background:
195
+ * I have a server called "devopserver"
196
+ * "devopserver" is running "ubuntu" "lucid"
197
+ * "devopserver" has been provisioned
198
+ * "devopserver" is in the "foobar" environment
199
+ * the "chef-client::service" recipe has been added to the "devopserver" run list
200
+ * the chef-client has been run on "devopserver"
201
+ * I ssh to "devopserver" with the following credentials:
202
+ | username | keyfile |
203
+ | root | ../.ssh/id_rsa |
204
+
205
+ You can add roles to the run list by writing:
206
+
207
+ * the "chef-client" role has been added to the "devopserver" run list
208
+
209
+ Here's an example `Scenario` section you might have to test if the chef-client is actually running as a daemon:
210
+
211
+ Scenario: Chef-Client is running as a daemon
212
+ When I run "ps aux | grep [c]hef-client"
213
+ Then I should see "chef-client" in the output
214
+ And I should see "-d" in the output
215
+ And I should see "-i 1800" in the output
216
+ And I should see "-s 20" in the output
217
+
218
+ See the section below label *Example Test Run* for more examples.
219
+
220
+ ##### List of Provisioning Steps
221
+
222
+ Create a server profile:
223
+
224
+ I have a server called "(server)"
225
+
226
+ Set a (server) to persist or not:
227
+
228
+ "(server)" should( not) be persistant
229
+
230
+ Set (server) to run linux of type (distro), using (release).
231
+
232
+ "(server)" is running "(distro)" "(release)"
233
+
234
+ Supported (distro -> releases):
235
+
236
+ ubuntu -> lucid, maverick, natty, oneiric, precise
237
+ fedora -> (release number)
238
+
239
+ Fedora releases 12, 13, 14 tested OK.
240
+
241
+ Assign (server) a specific IP address (must be on the test lab network segment):
242
+
243
+ "(server)" has an IP address of "(ip)"
244
+
245
+ Assign (server) a specific MAC address:
246
+
247
+ "(server)" has a MAC address of "(mac)"
248
+
249
+ Initiate the provision of a (server). All attributes of the server need to be set before this:
250
+
251
+ "(server)" has been provisioned
252
+
253
+ #### Chef Steps
254
+
255
+ To prep a server with a role and data bag:
256
+
257
+ * the following roles have been updated:
258
+ | role | role_path |
259
+ | users | ./features/support/roles/ |
260
+ * the "users" role has been added to the "users" run list
261
+ * the following databags have been updated:
262
+ | databag | databag_path |
263
+ | users | ./features/support/data_bags/users |
264
+
265
+ ##### List of Chef Steps
266
+
267
+ Update/push cookbooks to the chef-server:
268
+
269
+ * the following cookbooks have been uploaded:
270
+ | cookbook | cookbook_path |
271
+ | users | ./cookbooks/ |
272
+
273
+ Update/push roles to the chef-server:
274
+
275
+ * the following roles have been updated:
276
+ | role | role_path |
277
+ | users | ./features/support/roles/ |
278
+
279
+ or
280
+
281
+ * the following roles have been updated:
282
+ | role | role_path |
283
+ | users | ./roles/ |
284
+
285
+ Update/push data bags to the chef-server:
286
+
287
+ * the following databags have been updated:
288
+ | databag | databag_path |
289
+ | users | ./features/support/data_bags/users |
290
+
291
+ or
292
+
293
+ * the following databags have been updated:
294
+ | databag | databag_path |
295
+ | users | ./data_bags/users |
296
+
297
+ Add a role to the chef-client run list:
298
+
299
+ the "(role)" role has been added to the "(server)" run list
300
+
301
+ Add a recipe to the chef-client run list:
302
+
303
+ the "(recipe)" recipe has been added to the "(server)" run list
304
+
305
+ Place the node in a specific chef environment:
306
+
307
+ "(server)" is in the "(environment)" environment
308
+
309
+ Run the chef-client:
310
+
311
+ the chef-client has been run on "(server)"
312
+
313
+ In order to push data bags/roles/cookbooks to the chef-server using one of the above steps, you will have to create a `cucumber.yml` file in the root of your `chef-repo` with the following contents (see [issue 88](https://github.com/Atalanta/cucumber-chef/issues/88)):
314
+
315
+ ---
316
+ default: -c -v --exclude support/data_bags --exclude support/roles --exclude support/cookbooks
317
+
318
+ Alternatively, you can simply reference the normal data bags/roles/cookbooks directory like so:
319
+
320
+ * the following roles have been updated:
321
+ | role | role_path |
322
+ | users | ./roles/ |
323
+
324
+ #### SSH Steps
325
+
326
+ Here is how you might setup and initate an SSH session using password authentication to a server named `devopserver`:
327
+
328
+ * I have no public keys set
329
+ * I ssh to "devopserver" with the following credentials:
330
+ | username | password |
331
+ | root | root |
332
+
333
+ Here is how you might setup and initate an SSH session using public key authentication to a server named `users`:
334
+
335
+ * I ssh to "users" with the following credentials:
336
+ | username | keyfile |
337
+ | root | ../.ssh/id_rsa |
338
+
339
+ Since the cukes run on the test lab, we can directly reference the public key pairs already there and populated for us.
340
+
341
+ 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`:
342
+
343
+ Background:
344
+ * I have a server called "users"
345
+ * "users" is running "ubuntu" "lucid"
346
+ * "users" has been provisioned
347
+ * the following roles have been updated:
348
+ | role | role_path |
349
+ | users | ./features/support/roles/ |
350
+ * the "users" role has been added to the "users" run list
351
+ * the following databags have been updated:
352
+ | databag | databag_path |
353
+ | users | ./features/support/data_bags/users |
354
+ * the chef-client has been run on "users"
355
+
356
+ And now for the `Scenario`:
357
+
358
+ Scenario: The user can ssh in to the system with their key pair
359
+ * I ssh to "users" with the following credentials:
360
+ | username | keyfile |
361
+ | bdobbs | ./features/support/keys/bdobbs |
362
+ When I run "hostname"
363
+ Then I should see "users" in the output
364
+
365
+
366
+ ##### List of SSH Steps
367
+
368
+ Sets the authentication method to password:
369
+
370
+ I have no public keys set
371
+
372
+ Start an SSH session to the server (server) using password authentication:
373
+
374
+ I ssh to "(server)" with the following credentials:
375
+ | username | password |
376
+ | root | root |
377
+
378
+ Start an SSH session to the server (server) using public key authentication:
379
+
380
+ I ssh to "(server)" with the following credentials:
381
+ | username | keyfile |
382
+ | root | id_rsa |
383
+
384
+ Executes (command) over the previously established SSH session on the server (server):
385
+
386
+ I run "(command)"
387
+
388
+ Check (command) output for an (expected) or (not-expected) string:
389
+
390
+ I should( not) see "(expected)" in the output
391
+
392
+ Check (command) output for existance of or lack of (server) settings:
393
+
394
+ I should( not) see the "(ip|mac)" of "(server)" in the output
395
+
396
+ Check for a (running) or (not-running) (process)
397
+
398
+ service "(nginx)" should( not) be running
399
+
400
+ #### Minitest
401
+
402
+ ##### List of Minitest Steps
403
+
404
+ I enable the running of MiniTest suites for "(server)"
405
+
406
+ the tests should run and pass on "(server)"
407
+
408
+ #### Cucumber Before Hook Centric Helpers
409
+
410
+ * `chef_set_client_config(config={})`
411
+
412
+ 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.
413
+
414
+ ##### Examples
415
+
416
+ # for Opscode Hosted chef-server use this:
417
+ #chef_set_client_config(:orgname => "cucumber-chef")
418
+
419
+ # for Opscode OS chef-server on the Cucumber-Chef test lab use this:
420
+ chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
421
+ :validation_client_name => "chef-validator")
422
+
423
+ ## Running Tests
424
+
425
+ 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 provides a task which handles this:
426
+
427
+ $ cucumber
428
+
429
+ 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.
430
+
431
+ $ cucumber-chef help teardown
432
+ Usage:
433
+ cucumber-chef teardown [container]
434
+
435
+ Teardown the cucumber-chef test lab in Amazon EC2 or a test lab [container] if specified.
436
+
437
+ Since to run a test you simply run cucumber, you can now pass in options for cucumber or even setup profiles via `cucumber.yml`. For example:
438
+
439
+ $ cucumber --tags @wip -c -v -b
440
+
441
+ 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.
442
+
443
+ Here is an example default project for `cucumber.yml` which turns on colored output, verbosity and full backtraces for all test runs:
444
+
445
+ ---
446
+ default: -c -v -b
447
+
448
+ 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:
449
+
450
+ $ cucumber-chef info
451
+
452
+ 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.
453
+
454
+ ### When Things Go Oh So Wrong
455
+
456
+ 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`.
457
+
458
+ #### `ssh`
459
+
460
+ $ cucumber-chef help ssh
461
+ Usage:
462
+ cucumber-chef ssh [container]
463
+
464
+ Options:
465
+ [--test] # INTERNAL USE ONLY
466
+
467
+ SSH to cucumber-chef test lab or [container] if specified.
468
+
469
+ 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.
470
+
471
+ $ cucumber-chef ssh
472
+ Attempting SSH connection to cucumber-chef 'test lab'...
473
+ _____ _ _____ _ __
474
+ / ____| | | / ____| | / _|
475
+ | | _ _ ___ _ _ _ __ ___ | |__ ___ _ __| | | |__ ___| |_
476
+ | | | | | |/ __| | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \ / _ \ _|
477
+ | |___| |_| | (__| |_| | | | | | | |_) | __/ | | |____| | | | __/ |
478
+ \_____\__,_|\___|\__,_|_| |_| |_|_.__/ \___|_| \_____|_| |_|\___|_|
479
+
480
+
481
+ Welcome to the Cucumber Chef Test Lab v2.0.0.rc1
482
+
483
+ Last login: Mon Jun 4 07:56:40 2012 from [REDACTED]
484
+ ubuntu@cucumber-chef:~$
485
+
486
+ 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.
487
+
488
+ ubuntu@cucumber-chef:~$ sudo su -
489
+ root@cucumber-chef:~#
490
+
491
+ 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.
492
+
493
+ $ cucumber-chef ssh devopserver
494
+ Attempting SSH connection to cucumber-chef container 'devopserver'...
495
+ _____ _ _____ _ __
496
+ / ____| | | / ____| | / _|
497
+ | | _ _ ___ _ _ _ __ ___ | |__ ___ _ __| | | |__ ___| |_
498
+ | | | | | |/ __| | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \ / _ \ _|
499
+ | |___| |_| | (__| |_| | | | | | | |_) | __/ | | |____| | | | __/ |
500
+ \_____\__,_|\___|\__,_|_| |_| |_|_.__/ \___|_| \_____|_| |_|\___|_|
501
+
502
+
503
+ Welcome to the Cucumber Chef Test Lab v2.0.0.rc1
504
+
505
+ You are now logged in to the LXC 'devopserver'
506
+
507
+ root@devopserver:~#
508
+
509
+ #### `diagnose`
510
+
511
+ 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.
512
+
513
+ $ cucumber-chef help diagnose
514
+ Usage:
515
+ cucumber-chef diagnose <container>
516
+
517
+ Options:
518
+ -n, [--lines=N] # output the last N lines of the chef-client 'chef.log'
519
+ # Default: 1
520
+ -s, [--strace] # output the chef-client 'chef-stacktrace.out'
521
+ # Default: true
522
+ -l, [--log] # output the chef-client 'chef.log'
523
+ # Default: true
524
+
525
+ Provide diagnostics from the chef-client on the specified container.
526
+
527
+ 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.
528
+
529
+ $ cucumber-chef diagnose devopserver --no-strace -n 1000
530
+
531
+ Maybe you only want to view the `chef-stacktrace.out` file?
532
+
533
+ $ cucumber-chef diagnose devopserver --no-log
534
+
535
+ Maybe you want to run it with the default options in play; you would likely get some output as follows.
536
+
537
+ $ cucumber-chef diagnose devopserver
538
+ Attempting to collect diagnostic information on cucumber-chef container 'sysopserver'...
539
+ ----------------------------------------------------------------------------
540
+ chef-stacktrace.out:
541
+ ----------------------------------------------------------------------------
542
+ Generated at 2012-06-04 08:30:20 +0000
543
+ Net::HTTPServerException: 412 "Precondition Failed"
544
+ /opt/opscode/embedded/lib/ruby/1.9.1/net/http.rb:2303:in `error!'
545
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:264:in `block in api_request'
546
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:328:in `retriable_rest_request'
547
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:240:in `api_request'
548
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/rest.rb:139:in `post_rest'
549
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/client.rb:313:in `sync_cookbooks'
550
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/client.rb:194:in `setup_run_context'
551
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/client.rb:162:in `run'
552
+ /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'
553
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/application/client.rb:241:in `loop'
554
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/application/client.rb:241:in `run_application'
555
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/application.rb:70:in `run'
556
+ /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/bin/chef-client:26:in `<top (required)>'
557
+ /usr/bin/chef-client:19:in `load'
558
+ /usr/bin/chef-client:19:in `<main>'
559
+ ----------------------------------------------------------------------------
560
+ chef.log:
561
+ ----------------------------------------------------------------------------
562
+ [Mon, 04 Jun 2012 08:30:20 +0000] FATAL: Net::HTTPServerException: 412 "Precondition Failed"
563
+
564
+
565
+ #### `ps`
566
+
567
+ 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.
568
+
569
+ $ cucumber-chef help ps
570
+ Usage:
571
+ cucumber-chef ps [ps-options]
572
+
573
+ Snapshot of the current cucumber-chef test lab container processes.
574
+
575
+ Standard usage using `aux` options:
576
+
577
+ $ cucumber-chef ps aux
578
+ cucumber-chef v2.0.0.rc1
579
+
580
+ Getting container processes from cucumber-chef test lab...
581
+
582
+ ============================================================================
583
+ CONTAINER USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
584
+ sudo root 375 0.0 0.0 2368 608 ? S Jun21 0:00 upstart-udev-bridge --daemon
585
+ sudo syslog 384 0.0 0.0 27296 1264 ? Sl Jun21 0:00 rsyslogd -c4
586
+ sudo root 396 0.0 0.0 2236 388 ? S<s Jun21 0:00 udevd --daemon
587
+ sudo root 406 0.0 0.0 1840 556 pts/19 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
588
+ sudo root 410 0.0 0.0 1840 560 pts/17 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
589
+ sudo root 412 0.0 0.0 1840 560 pts/18 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
590
+ sudo root 416 0.0 0.0 2428 812 ? Ss Jun21 0:00 cron
591
+ sudo root 453 0.0 0.0 1840 564 pts/16 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
592
+ sudo root 455 0.0 0.0 1840 556 pts/20 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
593
+ 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
594
+ sudo root 493 0.0 0.1 5600 2132 ? Ss Jun21 0:00 /usr/sbin/sshd -D
595
+ users root 20777 0.0 0.0 2720 1484 ? Ss Jun21 0:02 /sbin/init
596
+ users syslog 20876 0.0 0.0 27296 1172 ? Sl Jun21 0:02 rsyslogd -c4
597
+ users root 20877 0.0 0.0 2368 560 ? S Jun21 0:00 upstart-udev-bridge --daemon
598
+ users root 20883 0.0 0.0 2236 516 ? S<s Jun21 0:00 udevd --daemon
599
+ users root 20914 0.0 0.0 1840 544 pts/4 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
600
+ users root 20918 0.0 0.0 1840 540 pts/2 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
601
+ users root 20921 0.0 0.0 1840 544 pts/3 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
602
+ users root 20925 0.0 0.0 2428 788 ? Ss Jun21 0:00 cron
603
+ users root 20953 0.0 0.0 1840 544 pts/1 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
604
+ users root 20954 0.0 0.0 1840 544 pts/5 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
605
+ 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
606
+ users root 20987 0.0 0.1 5600 2128 ? Ss Jun21 0:01 /usr/sbin/sshd -D
607
+ users root 21308 0.0 0.0 1848 488 ? S Jun21 0:07 tail -n 250 -f client.log
608
+ users root 21519 0.0 0.0 1848 484 ? S 02:19 0:02 tail -n 250 -f /var/log/auth.log
609
+ users root 21851 0.0 0.0 1848 484 ? S 02:20 0:02 tail -n 250 -f /var/log/chef/client.log
610
+ chef-client root 27226 0.0 0.0 2728 1524 ? Ss Jun21 0:00 /sbin/init
611
+ chef-client syslog 27328 0.0 0.0 27296 1244 ? Sl Jun21 0:00 rsyslogd -c4
612
+ chef-client root 27329 0.0 0.0 2368 584 ? S Jun21 0:00 upstart-udev-bridge --daemon
613
+ chef-client root 27340 0.0 0.0 2236 520 ? S<s Jun21 0:00 udevd --daemon
614
+ chef-client root 27364 0.0 0.0 1840 548 pts/9 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
615
+ chef-client root 27368 0.0 0.0 1840 548 pts/7 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
616
+ chef-client root 27369 0.0 0.0 1840 548 pts/8 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
617
+ chef-client root 27371 0.0 0.0 2428 804 ? Ss Jun21 0:00 cron
618
+ chef-client root 27401 0.0 0.0 1840 548 pts/6 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
619
+ chef-client root 27402 0.0 0.0 1840 548 pts/10 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
620
+ 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
621
+ chef-client root 27437 0.0 0.1 5600 2128 ? Ss Jun21 0:00 /usr/sbin/sshd -D
622
+ 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
623
+ timezone root 28244 0.0 0.0 2724 1568 ? Ss Jun21 0:00 /sbin/init
624
+ timezone root 28355 0.0 0.0 2368 600 ? S Jun21 0:00 upstart-udev-bridge --daemon
625
+ timezone syslog 28356 0.0 0.0 27296 1268 ? Sl Jun21 0:00 rsyslogd -c4
626
+ timezone root 28366 0.0 0.0 2236 504 ? S<s Jun21 0:00 udevd --daemon
627
+ timezone root 28385 0.0 0.0 1840 556 pts/14 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty4
628
+ timezone root 28388 0.0 0.0 1840 560 pts/12 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty2
629
+ timezone root 28390 0.0 0.0 1840 556 pts/13 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty3
630
+ timezone root 28397 0.0 0.0 2428 812 ? Ss Jun21 0:00 cron
631
+ timezone root 28423 0.0 0.0 1840 564 pts/11 Ss+ Jun21 0:00 /sbin/getty -8 38400 tty1
632
+ timezone root 28426 0.0 0.0 1840 560 pts/15 Ss+ Jun21 0:00 /sbin/getty -8 38400 /dev/console
633
+ 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
634
+ timezone root 28466 0.0 0.1 5600 2124 ? Ss Jun21 0:00 /usr/sbin/sshd -D
635
+ sudo root 32737 0.0 0.0 2720 1580 ? Ss Jun21 0:00 /sbin/init
636
+ users root 32741 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
637
+ users root 32742 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
638
+ chef-client root 32745 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
639
+ chef-client root 32747 0.0 0.0 2232 280 ? S< Jun21 0:00 udevd --daemon
640
+ timezone root 32754 0.0 0.0 2232 272 ? S< Jun21 0:00 udevd --daemon
641
+ timezone root 32755 0.0 0.0 2232 272 ? S< Jun21 0:00 udevd --daemon
642
+
643
+ ### Example Test Run
644
+
645
+ 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.
646
+
647
+ Now upload the `chef-client` community cookbook to your Cucumber-Chef test lab.
648
+
649
+ $ cc-knife cookbook upload chef-client
650
+ Uploading chef-client [1.1.2]
651
+ Uploaded 1 cookbook.
652
+
653
+ Next create your `devopserver` feature.
654
+
655
+ $ cucumber-chef create devopserver
656
+
657
+ 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.
658
+
659
+ @devopserver @wip
660
+ Feature: Perform test driven infrastructure with Cucumber-Chef
661
+ In order to learn how to develop test driven infrastructure
662
+ As an infrastructure developer
663
+ I want to better understand how to use Cucumber-Chef
664
+
665
+ Background:
666
+ * I have a server called "devopserver"
667
+ * "devopserver" is running "ubuntu" "lucid"
668
+ * "devopserver" has been provisioned
669
+ * the "chef-client::service" recipe has been added to the "devopserver" run list
670
+ * the chef-client has been run on "devopserver"
671
+ * I ssh to "devopserver" with the following credentials:
672
+ | username | keyfile |
673
+ | root | ../.ssh/id_rsa |
674
+
675
+ Scenario: Can connect to the provisioned server via SSH password authentication
676
+ And I run "hostname"
677
+ Then I should see "devopserver" in the output
678
+
679
+ Scenario: Default root shell is bash
680
+ And I run "echo $SHELL"
681
+ Then I should see "bash" in the output
682
+
683
+ Scenario: Default gateway and resolver are using Cucumber-Chef Test Lab
684
+ And I run "route -n | grep 'UG'"
685
+ Then I should see "192.168.255.254" in the output
686
+ And I run "cat /etc/resolv.conf"
687
+ Then I should see "192.168.255.254" in the output
688
+ And I should see "8.8.8.8" in the output
689
+ And I should see "8.8.4.4" in the output
690
+
691
+ Scenario: Primary interface is configured with my IP address and MAC address
692
+ And I run "ifconfig eth0"
693
+ Then I should see the "IP" of "devopserver" in the output
694
+ And I should see the "MAC" of "devopserver" in the output
695
+
696
+ Scenario: Local interface is not configured with my IP address or MAC address
697
+ And I run "ifconfig lo"
698
+ Then I should see "127.0.0.1" in the output
699
+ And I should not see the "IP" of "devopserver" in the output
700
+ And I should not see the "MAC" of "devopserver" in the output
701
+
702
+ Scenario: Chef-Client is running as a daemon
703
+ When I run "ps aux | grep [c]hef-client"
704
+ Then I should see "chef-client" in the output
705
+ And I should see "-d" in the output
706
+ And I should see "-i 1800" in the output
707
+ And I should see "-s 20" in the output
708
+
709
+ 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.
710
+
711
+ $ cucumber --tags @devopserver
712
+ Using features directory: /home/couldbeyou/chef-repo/features
713
+ Cucumber-Chef Test Runner Initalized!
714
+ Cleaning up any previous test runs...done.
715
+ Uploading files required for this test run...done.
716
+ Executing Cucumber-Chef Test Runner
717
+ Using the default profile...
718
+ Code:
719
+ * ./support/env.rb
720
+ * ./devopserver/step_definitions/devopserver_steps.rb
721
+ * ./sample/step_definitions/sample_steps.rb
722
+
723
+ Features:
724
+ * ./devopserver/devopserver.feature
725
+ Parsing feature files took 0m0.076s
726
+
727
+ @devopserver @wip
728
+ Feature: Perform test driven infrastructure with Cucumber-Chef
729
+ In order to learn how to develop test driven infrastructure
730
+ As an infrastructure developer
731
+ I want to better understand how to use Cucumber-Chef
732
+
733
+ Background: # ./devopserver/devopserver.feature:7
734
+ * all servers are being destroyed
735
+ * I have a server called "devopserver" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:1
736
+ * "devopserver" is running "ubuntu" "lucid" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:5
737
+ * devopserver is being provisioned
738
+ * "devopserver" has been provisioned # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:25
739
+ * 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
740
+ * the chef-client has been run on "devopserver" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/provision_steps.rb:37
741
+ * I ssh to "devopserver" with the following credentials: # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:57
742
+ | username | keyfile |
743
+ | root | ../.ssh/id_rsa |
744
+
745
+ Scenario: Can connect to the provisioned server via SSH password authentication # ./devopserver/devopserver.feature:17
746
+ And I run "hostname" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
747
+ Then I should see "devopserver" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
748
+
749
+ Scenario: Default root shell is bash # ./devopserver/devopserver.feature:21
750
+ And I run "echo $SHELL" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
751
+ Then I should see "bash" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
752
+
753
+ Scenario: Default gateway and resolver are using Cucumber-Chef Test Lab # ./devopserver/devopserver.feature:25
754
+ And I run "route -n | grep 'UG'" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
755
+ 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
756
+ And I run "cat /etc/resolv.conf" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
757
+ 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
758
+ 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
759
+ 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
760
+
761
+ Scenario: Primary interface is configured with my IP address and MAC address # ./devopserver/devopserver.feature:33
762
+ And I run "ifconfig eth0" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
763
+ 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
764
+ 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
765
+
766
+ Scenario: Local interface is not configured with my IP address or MAC address # ./devopserver/devopserver.feature:38
767
+ And I run "ifconfig lo" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
768
+ 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
769
+ 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
770
+ 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
771
+
772
+ Scenario: Chef-Client is running as a daemon # ./devopserver/devopserver.feature:44
773
+ When I run "ps aux | grep [c]hef-client" # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:77
774
+ Then I should see "chef-client" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
775
+ And I should see "-d" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
776
+ And I should see "-i 1800" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
777
+ And I should see "-s 20" in the output # cucumber-chef-2.0.0.rc1/lib/cucumber/chef/steps/ssh_steps.rb:81
778
+
779
+ 6 scenarios (6 passed)
780
+ 58 steps (58 passed)
781
+ 2m45.515s
782
+
783
+ If all goes well you should see output similar to what's above! Enjoy and have fun!
784
+
785
+ # RESOURCES
786
+
787
+ Source:
788
+
789
+ * https://github.com/Atalanta/cucumber-chef
790
+
791
+ Issues:
792
+
793
+ * https://github.com/Atalanta/cucumber-chef/issues
794
+
795
+ Wiki:
796
+
797
+ * https://github.com/Atalanta/cucumber-chef/wiki
798
+
799
+ Chat:
800
+
801
+ * #cucumber-chef on irc.freenode.net
802
+
803
+ # LICENSE
804
+
805
+ Cucumber-Chef - A test driven infrastructure system
806
+
807
+ * Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
808
+ * Author: Zachary Patten <zachary@jovelabs.com>
809
+ * Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
810
+ * License: Apache License, Version 2.0
811
+
812
+ Licensed under the Apache License, Version 2.0 (the "License");
813
+ you may not use this file except in compliance with the License.
814
+ You may obtain a copy of the License at
815
+
816
+ http://www.apache.org/licenses/LICENSE-2.0
817
+
818
+ Unless required by applicable law or agreed to in writing, software
819
+ distributed under the License is distributed on an "AS IS" BASIS,
820
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
821
+ See the License for the specific language governing permissions and
822
+ limitations under the License.
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  s.add_dependency("rake", ">= 0.9.2")
50
50
  s.add_dependency("thor", ">= 0.15.2")
51
51
  s.add_dependency("ubuntu_ami", ">= 0.4.0")
52
- s.add_dependency("ztk", ">= 1.0.1")
52
+ s.add_dependency("ztk", ">= 1.0.2")
53
53
 
54
54
  s.add_development_dependency("simplecov", ">= 0.6.4")
55
55
  s.add_development_dependency("pry", ">= 0")
@@ -89,8 +89,7 @@ module Cucumber
89
89
  :persist => true,
90
90
  :distro => "ubuntu",
91
91
  :release => "lucid",
92
- :arch => detect_arch(attributes[:distro] || "ubuntu")
93
- }.merge(attributes)
92
+ }.merge(attributes).merge(:arch => detect_arch(attributes[:distro] || "ubuntu"))
94
93
 
95
94
  if running?(name)
96
95
  @ui.logger.info { "Container '#{name}' is already running." }
@@ -0,0 +1,49 @@
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::Chef::Helpers::Chef
23
+
24
+ ################################################################################
25
+
26
+ def create_data_bag(data_bag, data_bag_path)
27
+ $test_lab.knife_cli(%Q{data bag create "#{data_bag}"}, :silence => true)
28
+ $test_lab.knife_cli(%Q{data bag from file "#{data_bag}" "#{data_bag_path}"}, :silence => true)
29
+ end
30
+
31
+ def delete_data_bag(data_bag)
32
+ $test_lab.knife_cli(%Q{data bag delete "#{data_bag}" --yes}, :silence => true)
33
+ end
34
+
35
+ ################################################################################
36
+
37
+ def role_from_file(role, role_path)
38
+ if File.extname(role).empty?
39
+ Dir.glob(File.join(role_path, "#{role}.*")).each do |role_file|
40
+ $test_lab.knife_cli(%Q{role from file #{role_file}}, :silence => true)
41
+ end
42
+ else
43
+ $test_lab.knife_cli(%Q{role from file #{File.join(role_path, role)}}, :silence => true)
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ ################################################################################
@@ -0,0 +1,38 @@
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
+ # This module includes all of the helper methods meant to drive step
26
+ # definitions.
27
+ module Helpers
28
+
29
+ require 'cucumber/chef/helpers/chef'
30
+
31
+ def self.included(base)
32
+ base.send(:include, ::Cucumber::Chef::Helpers::Chef)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -21,17 +21,13 @@
21
21
 
22
22
  And /^the following (databag|databags) (has|have) been (updated|uploaded):$/ do |ignore0, ignore1, ignore2, table|
23
23
  table.hashes.each do |entry|
24
- data_bag = entry['databag']
25
- data_bag_path = entry['databag_path']
26
- $test_lab.knife_cli(%Q{data bag create "#{data_bag}"}, :silence => true)
27
- $test_lab.knife_cli(%Q{data bag from file "#{data_bag}" "#{data_bag_path}"}, :silence => true)
24
+ create_data_bag(entry['databag'], entry['databag_path'])
28
25
  end
29
26
  end
30
27
 
31
28
  And /^the following (databag|databags) (has|have) been (deleted|removed):$/ do |ignore0, ignore1, ignore2, table|
32
29
  table.hashes.each do |entry|
33
- data_bag = entry['databag']
34
- $test_lab.knife_cli(%Q{data bag delete "#{data_bag}" --yes}, :silence => true)
30
+ delete_data_bag(entry['databag'])
35
31
  end
36
32
  end
37
33
 
@@ -39,16 +35,7 @@ end
39
35
 
40
36
  And /^the following (role|roles) (has|have) been (updated|uploaded):$/ do |ignore0, ignore1, ignore2, table|
41
37
  table.hashes.each do |entry|
42
- role = entry['role']
43
- role_path = entry['role_path']
44
-
45
- if File.extname(role).empty?
46
- Dir.glob(File.join(role_path, "#{role}.*")).each do |role_file|
47
- $test_lab.knife_cli(%Q{role from file #{role_file}}, :silence => true)
48
- end
49
- else
50
- $test_lab.knife_cli(%Q{role from file #{File.join(role_path, role)}}, :silence => true)
51
- end
38
+ role_from_file(entry['role'], entry['role_path'])
52
39
  end
53
40
  end
54
41
 
@@ -91,14 +91,14 @@ Then /^(path|directory|file|symlink) "([^\"]*)" should exist$/ do |type, path|
91
91
  command = "ls %s" % [
92
92
  parent
93
93
  ]
94
- @output = @connection.exec(command).output
94
+ @output = @connection.exec(command, :silence => true).output
95
95
  @output.should =~ /#{child}/
96
96
 
97
97
  # if a specific type (directory|file) was specified, test for it
98
98
  command = "stat -c %%F %s" % [
99
99
  path
100
100
  ]
101
- @output = @connection.exec(command).output
101
+ @output = @connection.exec(command, :silence => true).output
102
102
  types = {
103
103
  "file" => /regular file/,
104
104
  "directory" => /directory/,
@@ -108,15 +108,6 @@ Then /^(path|directory|file|symlink) "([^\"]*)" should exist$/ do |type, path|
108
108
  if types.keys.include? type
109
109
  @output.should =~ types[type]
110
110
  end
111
- # if type == "file"
112
- # @output.should =~ /regular file/
113
- # end
114
- # if type == "directory"
115
- # @output.should =~ /directory/
116
- # end
117
- # if type == "symlink"
118
- # @output.should =~ /symbolic link/
119
- # end
120
111
  end
121
112
 
122
113
  Then /^(?:path|directory|file) "([^\"]*)" should be owned by "([^\"]*)"$/ do |path, owner|
@@ -170,15 +161,15 @@ end
170
161
 
171
162
  Then /^package "([^\"]*)" should be installed$/ do |package|
172
163
  command = ""
173
- if (dpkg = @connection.exec("which dpkg 2> /dev/null").output).length > 0
164
+ if (dpkg = @connection.exec("which dpkg 2> /dev/null", silence: true).output).length > 0
174
165
  command = "#{dpkg.chomp} --get-selections"
175
- elsif (yum = @connection.exec("which yum 2> /dev/null").output).length > 0
166
+ elsif (yum = @connection.exec("which yum 2> /dev/null", silence: true).output).length > 0
176
167
  command = "#{yum.chomp} -q list installed"
177
168
  # could easily add more cases here, if I knew what they were :)
178
169
  end
179
170
 
180
- @output = @connection.exec(command)
181
- @output.should =~ /#{package}/
171
+ @result = @connection.exec(command, :silence => true)
172
+ @result.output.should =~ /#{package}/
182
173
  end
183
174
 
184
175
  # This regex is a little ugly, but it's so we can accept any of these
@@ -23,30 +23,73 @@ puts(" * #{tag}")
23
23
  Cucumber::Chef.boot(tag)
24
24
 
25
25
  $ui = ZTK::UI.new(:logger => Cucumber::Chef.logger)
26
- if (($test_lab = Cucumber::Chef::TestLab.new($ui)) && $test_lab.alive?)
27
- $test_lab.cc_client.up
28
- else
26
+ if !(($test_lab = Cucumber::Chef::TestLab.new($ui)) && $test_lab.alive?)
29
27
  message = "No running cucumber-chef test labs to connect to!"
30
28
  $ui.logger.fatal { message }
31
29
  raise message
32
30
  end
33
31
 
32
+ if ENV['PURGE'] == 'YES'
33
+ $ui.logger.warn { "PURGING CONTAINERS! Container attributes will be reset!" }
34
+ $test_lab.containers.load
35
+
36
+ $test_lab.containers.to_a.each do |name, value|
37
+ $test_lab.containers.destroy(name)
38
+ end
39
+
40
+ File.exists?(Cucumber::Chef.containers_bin) && File.delete(Cucumber::Chef.containers_bin)
41
+ $test_lab.containers.load
42
+ else
43
+ $ui.logger.info { "Allowing existing containers to persist." }
44
+ end
45
+
46
+ if ENV['PUSH'] == 'YES'
47
+ # Upload all of the chef-repo environments
48
+ puts(" * Pushing chef-repo environments to test lab...")
49
+ $test_lab.knife_cli(%Q{environment from file ./environments/*.rb --yes}, :silence => true)
50
+
51
+ # Upload all of the chef-repo cookbooks
52
+ puts(" * Pushing chef-repo cookbooks to test lab...")
53
+ cookbook_paths = ["./cookbooks"]
54
+ cookbook_paths << "./site-cookbooks" if Cucumber::Chef::Config.librarian_chef
55
+ $test_lab.knife_cli(%Q{cookbook upload --all --cookbook-path #{cookbook_paths.join(':')} --force --yes}, :silence => true)
56
+
57
+ # Upload all of the chef-repo roles
58
+ puts(" * Pushing chef-repo roles to test lab...")
59
+ $test_lab.knife_cli(%Q{role from file ./roles/*.rb --yes}, :silence => true)
60
+
61
+ # Upload all of our chef-repo data bags
62
+ Dir.glob("./data_bags/*").each do |data_bag_path|
63
+ next if !File.directory?(data_bag_path)
64
+ puts(" * Pushing chef-repo data bag '#{File.basename(data_bag_path)}' to test lab...")
65
+ data_bag = File.basename(data_bag_path)
66
+ $test_lab.knife_cli(%Q{data bag create "#{data_bag}" --yes}, :silence => true)
67
+ $test_lab.knife_cli(%Q{data bag from file "#{data_bag}" "#{data_bag_path}" --yes}, :silence => true)
68
+ end
69
+ end
70
+
34
71
 
35
72
  ################################################################################
36
73
  # HOOKS
37
74
  ################################################################################
38
75
 
39
76
  Before do |scenario|
40
- $test_lab.cc_client.before(scenario)
77
+ $scenario = scenario
78
+
79
+ $test_lab.containers.load
80
+
81
+ $test_lab.containers.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
82
+ :validation_client_name => "chef-validator")
41
83
  end
42
84
 
43
85
  After do |scenario|
44
- @connection and @connection.ssh.shutdown!
45
- $test_lab.cc_client.after(scenario)
46
- end
86
+ $test_lab.containers.save
47
87
 
48
- Kernel.at_exit do
49
- $test_lab.cc_client.at_exit
88
+ $test_lab.containers.to_a.select{ |name, attributes| !attributes[:persist] }.each do |name, attributes|
89
+ server_destroy(name)
90
+ end
91
+
92
+ @connection and @connection.ssh.shutdown!
50
93
  end
51
94
 
52
95
  ################################################################################
@@ -24,7 +24,7 @@ module Cucumber
24
24
 
25
25
  ################################################################################
26
26
 
27
- VERSION = "2.1.0.rc.12" unless const_defined?(:VERSION)
27
+ VERSION = "2.1.0.rc.14" unless const_defined?(:VERSION)
28
28
 
29
29
  ################################################################################
30
30
 
@@ -2,23 +2,80 @@ require 'rubygems'
2
2
  require 'cucumber'
3
3
  require 'cucumber/rake/task'
4
4
 
5
- Cucumber::Rake::Task.new(:"cucumber-chef") do |t|
6
- feature_dirs = Array.new
5
+ namespace :cc do
7
6
 
8
- feature_dir_glob = File.join(Dir.pwd, "*cookbook*", "*", "*feature*")
9
- feature_dirs << Dir.glob(feature_dir_glob)
7
+ desc "Run features in a style suitable for Continuous Integration"
8
+ task :ci do |t|
9
+ pushed = false
10
+ exit_codes = Array.new
10
11
 
11
- feature_dir_glob = File.join(Dir.pwd, "*feature*")
12
- feature_dirs << Dir.glob(feature_dir_glob)
12
+ puts("Cleaning up...")
13
+ system(%Q{rm -rfv artifacts})
14
+ system(%Q{rm -rfv public})
15
+ system(%Q{mkdir -v public})
16
+ system(%Q{echo "<html><head><title>Cucumber-Chef Report</title></head><body>" | tee public/index.html})
17
+ system(%Q{echo "<h2>Cucumber-Chef Report</h2><ul>" | tee -a public/index.html})
13
18
 
14
- opts = [
15
- "--exclude support/cookbooks",
16
- "--exclude support/data_bags",
17
- "--exclude support/environments",
18
- "--exclude support/keys",
19
- "--exclude support/roles",
20
- feature_dirs
21
- ].flatten.compact.join(" ")
19
+ puts("Generating Cucumber-Chef html reports...")
20
+ Dir.glob("features/*").each do |feature_dir|
21
+ found_features = false
22
+ Dir.glob("#{feature_dir}/*.feature") do |feature|
23
+ if found_features == false
24
+ found_features = true
25
+ system(%Q{echo "<li /><p>#{File.basename(feature_dir)}<ul>" | tee -a public/index.html})
26
+ end
27
+ filename = feature.gsub(/(\w*).feature/, '\1.html')
28
+ puts("#{feature} -> public/#{filename}")
29
+
30
+ system(%Q{mkdir -pv #{File.dirname("public/#{filename}")}})
31
+
32
+ push = (pushed ? nil : %Q{PUSH="YES"})
33
+ command = [push, "bundle exec cucumber", "features/support", feature, ENV['EXTRA_CUCUMBER_ARGS'], "--format html", "--out public/#{filename}"].flatten.compact.join(" ")
34
+ pushed = true if !pushed
35
+ puts("command=#{command.inspect}")
36
+ system(command)
37
+ exit_codes << $?.exitstatus
38
+
39
+ passed = "<font style='font-weight: bold; color: green;'>PASSED</font>"
40
+ failed = "<font style='font-weight: bold; color: red;'>FAILED</font>"
41
+ status = ((exit_codes[-1] == 0) ? passed : failed)
42
+
43
+ system(%Q{echo "<li /><a href='#{filename}'>#{File.basename(filename.gsub('.html', ''))}</a> (#{status})" | tee -a public/index.html})
44
+ end
45
+
46
+ if found_features
47
+ system(%Q{echo "</p></ul>" | tee -a public/index.html})
48
+ end
49
+ end
50
+
51
+ system(%Q{echo "</ul></body></html>" | tee -a public/index.html})
52
+
53
+ system(%Q{/bin/bash -c '[[ -d $CUCUMBER_CHEF_HOME/aws/artifacts ]] && mv -v $CUCUMBER_CHEF_HOME/aws/artifacts .'})
54
+
55
+ # If we had a failure be sure to surface it
56
+ exit_code = (exit_codes.any?{ |ec| ec != 0 } ? 1 : 0)
57
+ exit(exit_code)
58
+ end
59
+
60
+ Cucumber::Rake::Task.new(:cucumber) do |t|
61
+ feature_dirs = Array.new
62
+
63
+ feature_dir_glob = File.join(Dir.pwd, "*cookbook*", "*", "*feature*")
64
+ feature_dirs << Dir.glob(feature_dir_glob)
65
+
66
+ feature_dir_glob = File.join(Dir.pwd, "*feature*")
67
+ feature_dirs << Dir.glob(feature_dir_glob)
68
+
69
+ opts = [
70
+ "--exclude support/cookbooks",
71
+ "--exclude support/data_bags",
72
+ "--exclude support/environments",
73
+ "--exclude support/keys",
74
+ "--exclude support/roles",
75
+ feature_dirs
76
+ ].flatten.compact.join(" ")
77
+
78
+ t.cucumber_opts = opts
79
+ end
22
80
 
23
- t.cucumber_opts = opts
24
81
  end
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: 2.1.0.rc.12
4
+ version: 2.1.0.rc.14
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-02-10 00:00:00.000000000 Z
13
+ date: 2013-02-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: chef
@@ -147,7 +147,7 @@ dependencies:
147
147
  requirements:
148
148
  - - ! '>='
149
149
  - !ruby/object:Gem::Version
150
- version: 1.0.1
150
+ version: 1.0.2
151
151
  type: :runtime
152
152
  prerelease: false
153
153
  version_requirements: !ruby/object:Gem::Requirement
@@ -155,7 +155,7 @@ dependencies:
155
155
  requirements:
156
156
  - - ! '>='
157
157
  - !ruby/object:Gem::Version
158
- version: 1.0.1
158
+ version: 1.0.2
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: simplecov
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -241,6 +241,7 @@ files:
241
241
  - README.md
242
242
  - Rakefile
243
243
  - TODO.md
244
+ - WIKI.md
244
245
  - bin/cc-console
245
246
  - bin/cc-knife
246
247
  - bin/cucumber-chef
@@ -280,6 +281,8 @@ files:
280
281
  - lib/cucumber/chef/client.rb
281
282
  - lib/cucumber/chef/config.rb
282
283
  - lib/cucumber/chef/containers.rb
284
+ - lib/cucumber/chef/helpers.rb
285
+ - lib/cucumber/chef/helpers/chef.rb
283
286
  - lib/cucumber/chef/provider.rb
284
287
  - lib/cucumber/chef/providers/aws.rb
285
288
  - lib/cucumber/chef/providers/vagrant.rb