PageRenderTime 87ms CodeModel.GetById 36ms RepoModel.GetById 7ms app.codeStats 0ms

/website/website.html

https://github.com/PetResQ911/cucumber-chef
HTML | 385 lines | 282 code | 101 blank | 2 comment | 0 complexity | 4c61604a0eecd02ad594ae3a4541e9d1 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>Cucumber-chef</title>
  7. <!-- Typekit service section -->
  8. <script type="text/javascript"
  9. src="http://use.typekit.com/jmb0kkz.js"></script>
  10. <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
  11. <!-- End of typekit service section -->
  12. <!-- Framework CSS --> <link rel="stylesheet" href="style/style.css"
  13. type="text/css" media="screen, projection"> </head>
  14. <body> <div class="container">
  15. <div id="nav">
  16. <ul>
  17. <li class="selected">Main</li>
  18. <li>Docs</li>
  19. </ul>
  20. </div>
  21. <div id="header">
  22. <img src="images/cucumber-chef-logo.png" width="380" height="46"
  23. alt="Cucumber Chef Logo"/>
  24. <h3>A library of tools to enable test driven development</h3>
  25. </div>
  26. <div class="page">
  27. <div id="panel">
  28. <a href="https://github.com/Atalanta/cucumber-chef"><img
  29. src="images/large-button.png" width="252" height="52" class="imgpad"
  30. alt="Git Hub" /></a>
  31. <a href="http://oreilly.com/catalog/0636920020042"><img
  32. src="images/book-cover.png" width="252" height="330" alt="Book
  33. Cover"/></a>
  34. <p class="book-description">Test-Driven Infrastructure with
  35. Chef<br/>by Stephen Nelson-Smith<br/>Published by OReilly</p>
  36. <a href="http://oreilly.com/catalog/0636920020042"><img
  37. src="images/buy-button.png" width="62" height="27" alt="Buy
  38. Button"/></a>
  39. </div>
  40. <h2>Overview</h2>
  41. <p><strong>Cucumber-chef</strong>is a library of tools to enable the
  42. emerging discipline of infrastructure as code to practice test driven
  43. development. It provides a testing platform within which cucumber
  44. tests can be run which provision lightweight virtual machines,
  45. configure them by applying the appriporaite Chef roles to them, and
  46. then run acceptance and integration tests against the environment.</p>
  47. <p>It begins with a very simple premise. with a very simple
  48. premise. If we are framing our infratructure as code - if we're
  49. writing cookbooks, recipes and other pieces of automation in a high
  50. level programming language, such as Ruby, then it makes sense to
  51. follow the current wisdom across the software development world to
  52. maximise the quality, maintainability and reusability of our code,
  53. providing maximum chance that we'll deliver value with it. One
  54. area which has been shown to have a very positive effect is the
  55. practive of 'test-driven' development. In this paradigm, the
  56. developer begins by writing a test that captures the intended
  57. behaviour of the code they are going to write. This test will
  58. start out by failing. The developer then writes code to make the
  59. test pass, and iterates thereafter.</p>
  60. <strong>Cucumber-Chef</strong> provides a framework to make it easier
  61. to do test-driven development for infrastructure. It does this by
  62. providing a test infrastructure, in the cloud, which provides a very
  63. fast, lightweight and cheap way to fire up virtual machines for
  64. testing. We call this the "test lab".</p>
  65. <p>As you might have guessed from the name, we're going to write high
  66. level acceptance tests using Cucumber. Cucumber-Chef provides step
  67. definitions and helper methods to make it easy to provision and manage
  68. machines with Chef, and then build end-to-end tests.</p>
  69. <ul> <li><strong>Test Lab:</strong> An environment made up (at
  70. present) of an EC2 instance, configured to be an LXC host. This
  71. machine does nothing other than provide space in which Linux
  72. containers can be created and destroyed.</li>
  73. <li><strong>Controller:</strong> One special Linux container which
  74. acts as the central point from which tests are run. This machine is
  75. where the tests run, and has connectivity and credentials to connect
  76. to the machines that are created as part of a test run.</li>
  77. <li><strong>Container:</strong> A container is a lightweight virtual
  78. machine - it is entirely self-contained, with its own process tree,
  79. resource constraints, filesystem and network stack. It shares a
  80. kernel with the Test Lab host server.</li> </ul>
  81. <h3>Getting Started</h3>
  82. <p>Getting started with <strong>Cucumber-Chef</strong> is a simple,
  83. three step process:</p>
  84. <ul>
  85. <li>1) Install Cucumber-Chef</li>
  86. <li>2) Integrate with Hosted Chef and Amazon EC2</li>
  87. <li>3) Run cucumber-chef setup</li>
  88. </ul>
  89. <h3>Installing Cucumber-Chef</h3>
  90. <p>Installing Cucumber-Chef is simple. It's distributed as a
  91. RubyGem, so you can simply run:</p>
  92. <div class="inset-box">
  93. <pre><code>$ gem install cucumber-chef
  94. </code></pre>
  95. </div>
  96. <p>Once installed, you can run cucumber-chef on the command line to
  97. get an overview of the tasks it can carry out.</p>
  98. <div class="inset-box">
  99. <pre><code>$ cucumber-chef
  100. Tasks:
  101. cucumber-chef connect # Connect to a container in your test lab
  102. cucumber-chef destroy # Destroy running test labs
  103. cucumber-chef displayconfig # Display the current config from knife.rb
  104. cucumber-chef help [TASK] # Describe available tasks or one specific task
  105. cucumber-chef info # Display information about the current test lab
  106. cucumber-chef project &lt;project name&gt; # Create a project template for testing an infrastructure
  107. cucumber-chef setup # Set up a cucumber-chef test lab in Amazon EC2
  108. cucumber-chef test # Run a cucumber-chef test suite from a workstation.
  109. cucumber-chef upload &lt;project name&gt; # Upload a cucumber-chef test
  110. </code></pre>
  111. </div>
  112. <h3>Integrate with Hosted Chef and Amazon EC2</h3>
  113. <p>In it's current incarnation, Cucumber-Chef makes two important
  114. assumptions. Firstly, it assumes you're using Opscode Hosted Chef
  115. rather than your own Chef server. Secondly, it assume that you are
  116. comfortable with using Amazon's EC2 service for providing the 'bare
  117. metal' on which we set up the test lab. </p>
  118. <p><strong>Cucumber-chef</strong> is tightly integrated with Chef - it
  119. uses your knife.rb for credentials, and any cucumber-chef-specific
  120. configuration goes in knife.rb under the cucumber-chef namespace.</p>
  121. <p>On installation, the first thing you should do is run:</p>
  122. <div class="inset-box">
  123. <pre>
  124. $ cucumber-chef displayconfig
  125. </pre>
  126. </div>
  127. <p>This will look for your knife.rb, and extract the relevant
  128. sections, check them, and display them on the screen. If any entries
  129. are missing, it will alert you.</p>
  130. <p>The recommended best practice for Chef is to keep your knife.rb
  131. inside your organisation's Chef repository, inside the .chef
  132. directory, and use environment variables to specify username,
  133. organisation name and cloud provider credentials. Cucumber-chef
  134. supports and encourages this approach. It will search for a
  135. directory called .chef in your current directory, and then carry on
  136. going up the directory tree until it finds one. In practice this
  137. means that if you stay within the chef-repo directory for the
  138. organisation on which you're working, cucumber-chef will use the
  139. knife.rb; if your elsewhere in the filesystem rooted in your home
  140. directory, and have .chef in your home directory, cucumber-chef
  141. will use that. Otherwise you'll need to either change into a
  142. directory where a .chef can be found, or copy, creatre or link
  143. accordingly. In most cases we anticipate that you'll be inside the
  144. chef-repo of your organisation, and the documentation is written
  145. from this perspective.</p>
  146. <p>If you haven't already, refactor your knife.rb to look like this:</p>
  147. <div class="inset-box">
  148. <pre><code>current_dir = File.dirname(__FILE__)
  149. user = ENV['OPSCODE_USER'] || ENV['USER']
  150. log_level :info
  151. log_location STDOUT
  152. node_name user
  153. client_key "#{ENV['HOME']}/.chef/#{user}.pem"
  154. validation_client_name "#{ENV['ORGNAME']}-validator"
  155. validation_key "#{ENV['HOME']}/.chef/#{ENV['ORGNAME']}-validator.pem"
  156. chef_server_url "https://api.opscode.com/organizations/#{ENV['ORGNAME']}"
  157. cache_type 'BasicFile'
  158. cache_options( :path =&gt; "#{ENV['HOME']}/.chef/checksums" )
  159. cookbook_path ["#{current_dir}/../cookbooks"]
  160. </code></pre>
  161. </div>
  162. <p>Now set your Hosted Chef username and organization name using
  163. environment variables:</p>
  164. <div class="inset-box">
  165. <pre><code>$ export OPSCODE_USER=platform_user_name
  166. $ export ORGNAME=platform_organisation
  167. </code></pre>
  168. </div>
  169. <p>Now put your validator and client keys in $HOME/.chef. Verify that
  170. everything still works:</p>
  171. <div class="inset-box">
  172. <pre><code>$ knife client list
  173. </code></pre>
  174. </div>
  175. <p>If you get results back, we're in business.</p>
  176. <p>Now add the EC2 configuration:</p>
  177. <div class="inset-box">
  178. <pre><code>knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
  179. knife[:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
  180. knife[:aws_ssh_key_id] = ENV['AWS_SSH_KEY_ID']
  181. knife[:identity_file] = "/path/to/aws_ssh_key.pem"
  182. knife[:availability_zone] = "eu-west-1a"
  183. knife[:region] = "eu-west-1"
  184. knife[:aws_image_id] = "ami-339ca947"
  185. </code></pre>
  186. </div>
  187. <p>Note that right now Cucumber-Chef only supports Ubuntu-based test
  188. labs.</p>
  189. <p>And set your environment variables:</p>
  190. <div class="inset-box">
  191. <pre><code>$ export AWS_ACCESS_KEY_ID=SEKRITKEY
  192. $ export AWS_SECRET_ACCESS_KEY=REELYSEKRITKEY
  193. $ export AWS_SSH_KEY_ID
  194. </code></pre>
  195. </div>
  196. <p>And then ensure your AWS ssh key is in place.</p>
  197. <p>Now check your config again, with cucumber-chef display config. If
  198. you get no complaints, you're ready to set up a test lab.</p>
  199. <h3>Run cucumber-chef setup</h3>
  200. <div class="inset-box">
  201. <pre><code>$ cucumber-chef setup
  202. </code></pre>
  203. </div>
  204. <p>This command will set up a complete test lab environment, As long
  205. as you've provided valid AWS and Opscode credentials, it will do this
  206. automatically. The process takes about 15 minutes, after which you'll
  207. have a fully funtioning platform available for you to use. Let's just
  208. quickly review what that means. You will have an EC2 machine, fully
  209. managed by Chef, and providing the following:</p>
  210. <ul>
  211. <li>The ability to provision LXC containers</li>
  212. <li>The ability to run tests against LXC containers</li>
  213. <li>A dedicated container for certain kinds of testing scenarios</li>
  214. </ul>
  215. <p>The next stage is to set up a project. A project is simply a
  216. directory structure for containing your cucumber features and steps,
  217. already set up with an appropriate environment to make use of the
  218. step definitions provided with cucumber-chef. We think it makes
  219. most sense to have this in your organisation's chef repo.
  220. Cucumber-chef provides a task which will create a the directory for
  221. you, and populate it with a README and an example feature and
  222. step.</p>
  223. <div class="inset-box">
  224. <pre><code>$ cd /path/to/chef-repo
  225. $ cucumber-chef project example
  226. </code></pre>
  227. </div>
  228. <p>This will create a directory, cucumber-chef, and a subdirectory, example.</p>
  229. <div class="inset-box">
  230. <pre><code> example
  231. README
  232. features
  233. example.feature
  234. step_definitions
  235. example_step.rb
  236. support
  237. env.rb
  238. </code></pre>
  239. </div>
  240. <h2>Writing tests</h2>
  241. <p>Once you've got your test lab set up, and you've generated a
  242. project, it's time to crack on with writing a test. The basic idea is
  243. this:</p>
  244. <p>
  245. <ul>
  246. <li>1) An infrastructure requirement is established</li>
  247. <li>2) Write a cucumber feature that expresses the required
  248. behaviour of the infrastructure requirement</li>
  249. <li>3) Write steps that will build this infrastructure environment
  250. on the test lab, using the step definitions provided - these include
  251. the ability to create a container, apply roles to it, and destroy it
  252. again.</li>
  253. <li>4) Write cookbooks and recipes and supporting code to make
  254. the test pass</li>
  255. </ul></p>
  256. <h2>Running tests</h2>
  257. <p>You can write the tests and Chef code wherever you like. We're
  258. assuming you prefer working on your local machine, and checking into
  259. version control. But we don't really care. When it's time to run
  260. tests, cucumber-chef provides a task which handles this:</p>
  261. <div class="inset-box">
  262. <pre><code>$ cucumber-chef test myproject
  263. </code></pre>
  264. </div>
  265. <p>At the moment cucumber-chef doesn't pass though clever filtering
  266. and tagging options that cucumber supports - you run all the tests.
  267. We're going to improve that soon, again, patches and pull requests
  268. very welcome.</p>
  269. <p>Running the test task will upload your current project to the test
  270. lab, and run the tests, reporting the results back to the screen.
  271. Cucumber-chef also provides an upload task, so you can push the
  272. current project to the test lab, and then connect to test lab yourself
  273. to run tests in a more granular way. To do this, you need to know the
  274. IP of the test lab. You can find this out by running:</p>
  275. <div class="inset-box">
  276. <pre><code>$ cucumber-chef info
  277. </code></pre>
  278. </div>
  279. <p>At present, Cucumber-Chef only allows one test lab per AWS account
  280. and Opscode Hosted Chef account.</p>
  281. </div>
  282. </div>
  283. </body>
  284. </html>