diff options
author | Bryan McLellan <bryanm@widemile.com> | 2008-10-13 16:44:09 -0700 |
---|---|---|
committer | Bryan McLellan <bryanm@widemile.com> | 2008-10-13 16:44:09 -0700 |
commit | 49d2c20c81ce942955fbbf0ab3ff22373051f284 (patch) | |
tree | 6ba27f017158497f95d4d7600b9156de68531498 | |
parent | de1bc77f177f20b5d9a95cac546d1dadfd116bcb (diff) | |
parent | 0c99f89fcb2a74de5d8638f7f503e5aa8f52b72e (diff) | |
download | chef-49d2c20c81ce942955fbbf0ab3ff22373051f284.tar.gz |
Merge branch 'master' of git@github.com:hjkp/chef into hjk
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Manifest.txt | 85 | ||||
-rw-r--r-- | NOTICE | 2 | ||||
-rw-r--r-- | README.txt | 16 | ||||
-rw-r--r-- | Rakefile | 40 | ||||
-rw-r--r-- | chef-server/LICENSE | 201 | ||||
-rw-r--r-- | chef-server/NOTICE | 10 | ||||
-rw-r--r-- | chef-server/README.txt | 77 | ||||
-rw-r--r-- | chef-server/Rakefile | 48 | ||||
-rwxr-xr-x | chef-server/bin/chef-indexer (renamed from bin/chef-indexer) | 4 | ||||
-rwxr-xr-x | chef-server/bin/chef-server (renamed from bin/chef-server) | 14 | ||||
-rw-r--r-- | chef-server/lib/controllers/application.rb (renamed from lib/chef_server/controllers/application.rb) | 64 | ||||
-rw-r--r-- | chef-server/lib/controllers/cookbook_attributes.rb | 55 | ||||
-rw-r--r-- | chef-server/lib/controllers/cookbook_definitions.rb | 56 | ||||
-rw-r--r-- | chef-server/lib/controllers/cookbook_files.rb (renamed from lib/chef_server/controllers/cookbook_files.rb) | 3 | ||||
-rw-r--r-- | chef-server/lib/controllers/cookbook_libraries.rb | 55 | ||||
-rw-r--r-- | chef-server/lib/controllers/cookbook_recipes.rb | 56 | ||||
-rw-r--r-- | chef-server/lib/controllers/cookbook_templates.rb (renamed from lib/chef_server/controllers/cookbook_templates.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/controllers/cookbooks.rb (renamed from lib/chef_server/controllers/cookbooks.rb) | 28 | ||||
-rw-r--r-- | chef-server/lib/controllers/exceptions.rb (renamed from lib/chef_server/controllers/exceptions.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/controllers/nodes.rb (renamed from lib/chef_server/controllers/nodes.rb) | 14 | ||||
-rw-r--r-- | chef-server/lib/controllers/openid_consumer.rb (renamed from lib/chef_server/controllers/openid_consumer.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/controllers/openid_register.rb (renamed from lib/chef_server/controllers/openid_register.rb) | 7 | ||||
-rw-r--r-- | chef-server/lib/controllers/openid_server.rb (renamed from lib/chef_server/controllers/openid_server.rb) | 2 | ||||
-rw-r--r-- | chef-server/lib/controllers/search.rb (renamed from lib/chef_server/controllers/search.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/controllers/search_entries.rb (renamed from lib/chef_server/controllers/search_entries.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/helpers/cookbooks_helper.rb | 30 | ||||
-rw-r--r-- | chef-server/lib/helpers/global_helpers.rb (renamed from lib/chef_server/helpers/global_helpers.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/helpers/nodes_helper.rb (renamed from lib/chef_server/helpers/nodes_helper.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/helpers/openid_server_helpers.rb (renamed from lib/chef_server/helpers/openid_server_helpers.rb) | 0 | ||||
-rw-r--r-- | chef-server/lib/init.rb (renamed from lib/chef_server/init.rb) | 62 | ||||
-rw-r--r-- | chef-server/lib/public/images/merb.jpg (renamed from lib/chef_server/public/images/merb.jpg) | bin | 5815 -> 5815 bytes | |||
-rw-r--r-- | chef-server/lib/public/stylesheets/master.css | 173 | ||||
-rw-r--r-- | chef-server/lib/views/cookbook_templates/index.html.haml (renamed from lib/chef_server/views/cookbook_templates/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/cookbooks/_attribute_file.html.haml | 2 | ||||
-rw-r--r-- | chef-server/lib/views/cookbooks/_syntax_highlight.html.haml | 2 | ||||
-rw-r--r-- | chef-server/lib/views/cookbooks/attribute_files.html.haml (renamed from lib/chef_server/views/cookbooks/attribute_files.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/cookbooks/index.html.haml (renamed from lib/chef_server/views/cookbooks/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/cookbooks/show.html.haml | 29 | ||||
-rw-r--r-- | chef-server/lib/views/exceptions/bad_request.json.erb (renamed from lib/chef_server/views/exceptions/bad_request.json.erb) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/exceptions/internal_server_error.html.erb (renamed from lib/chef_server/views/exceptions/internal_server_error.html.erb) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/exceptions/not_acceptable.html.erb (renamed from lib/chef_server/views/exceptions/not_acceptable.html.erb) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/exceptions/not_found.html.erb (renamed from lib/chef_server/views/exceptions/not_found.html.erb) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/layout/application.html.haml (renamed from lib/chef_server/views/layout/application.html.haml) | 2 | ||||
-rw-r--r-- | chef-server/lib/views/nodes/_action.html.haml (renamed from lib/chef_server/views/nodes/_action.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/nodes/_node.html.haml (renamed from lib/chef_server/views/nodes/_node.html.haml) | 2 | ||||
-rw-r--r-- | chef-server/lib/views/nodes/_resource.html.haml (renamed from lib/chef_server/views/nodes/_resource.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/nodes/compile.html.haml (renamed from lib/chef_server/views/nodes/compile.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/nodes/index.html.haml (renamed from lib/chef_server/views/nodes/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/nodes/show.html.haml (renamed from lib/chef_server/views/nodes/show.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/openid_consumer/index.html.haml (renamed from lib/chef_server/views/openid_consumer/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/openid_consumer/start.html.haml (renamed from lib/chef_server/views/openid_consumer/start.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/openid_login/index.html.haml (renamed from lib/chef_server/views/openid_login/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/openid_register/index.html.haml (renamed from lib/chef_server/views/openid_register/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/openid_register/show.html.haml (renamed from lib/chef_server/views/openid_register/show.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/openid_server/decide.html.haml (renamed from lib/chef_server/views/openid_server/decide.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/search/_search_form.html.haml (renamed from lib/chef_server/views/search/_search_form.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/search/index.html.haml (renamed from lib/chef_server/views/search/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/search/show.html.haml (renamed from lib/chef_server/views/search/show.html.haml) | 2 | ||||
-rw-r--r-- | chef-server/lib/views/search_entries/index.html.haml (renamed from lib/chef_server/views/search_entries/index.html.haml) | 0 | ||||
-rw-r--r-- | chef-server/lib/views/search_entries/show.html.haml (renamed from lib/chef_server/views/search_entries/show.html.haml) | 0 | ||||
-rw-r--r-- | chef/History.txt (renamed from History.txt) | 0 | ||||
-rw-r--r-- | chef/LICENSE | 201 | ||||
-rw-r--r-- | chef/Manifest.txt | 115 | ||||
-rw-r--r-- | chef/NOTICE | 11 | ||||
-rw-r--r-- | chef/README.txt | 78 | ||||
-rw-r--r-- | chef/Rakefile | 48 | ||||
-rwxr-xr-x | chef/bin/chef-client (renamed from bin/chef-solo) | 52 | ||||
-rwxr-xr-x | chef/bin/chef-solo (renamed from bin/chef-client) | 4 | ||||
-rw-r--r-- | chef/config/server.rb (renamed from config/chef-server.rb) | 0 | ||||
-rw-r--r-- | chef/docs/design/HighLevel.graffle (renamed from docs/design/HighLevel.graffle) | bin | 1910 -> 1910 bytes | |||
-rw-r--r-- | chef/docs/recipe.rb (renamed from docs/recipe.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config.rb (renamed from examples/config.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/chef-solo.rb (renamed from examples/config/chef-solo.rb) | 1 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/attributes/first.rb (renamed from examples/config/cookbooks/fakefile/attributes/first.rb) | 2 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/definitions/test.rb | 13 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt (renamed from examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt (renamed from examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt (renamed from examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/files/default/the_park.txt (renamed from examples/config/cookbooks/fakefile/files/default/the_park.txt) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/libraries/test.rb | 7 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/recipes/default.rb (renamed from examples/config/cookbooks/fakefile/recipes/default.rb) | 78 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/fakefile/templates/default/monkey.erb (renamed from examples/config/cookbooks/fakefile/templates/default/monkey.erb) | 2 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/rubygems_server/attributes/first.rb (renamed from examples/config/cookbooks/rubygems_server/attributes/first.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem (renamed from examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem) | bin | 25600 -> 25600 bytes | |||
-rw-r--r-- | chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem (renamed from examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem) | bin | 61440 -> 61440 bytes | |||
-rw-r--r-- | chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem (renamed from examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem) | bin | 117248 -> 117248 bytes | |||
-rw-r--r-- | chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem (renamed from examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem) | bin | 18432 -> 18432 bytes | |||
-rw-r--r-- | chef/examples/config/cookbooks/rubygems_server/recipes/default.rb (renamed from examples/config/cookbooks/rubygems_server/recipes/default.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/servicetest/recipes/default.rb (renamed from examples/config/cookbooks/servicetest/recipes/default.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/tempfile/attributes/second.rb (renamed from examples/config/cookbooks/tempfile/attributes/second.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/cookbooks/tempfile/recipes/default.rb (renamed from examples/config/cookbooks/tempfile/recipes/default.rb) | 4 | ||||
-rw-r--r-- | chef/examples/config/nodes/adam.rb (renamed from examples/config/nodes/adam.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/nodes/default.rb (renamed from examples/config/nodes/default.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/nodes/junglist.gen.nz.rb (renamed from examples/config/nodes/junglist.gen.nz.rb) | 0 | ||||
-rw-r--r-- | chef/examples/config/nodes/latte.rb (renamed from examples/config/nodes/latte.rb) | 0 | ||||
-rw-r--r-- | chef/examples/mrepo/Rakefile (renamed from examples/mrepo/Rakefile) | 0 | ||||
-rw-r--r-- | chef/examples/node.rb (renamed from examples/node.rb) | 0 | ||||
-rw-r--r-- | chef/examples/node.yml (renamed from examples/node.yml) | 0 | ||||
-rw-r--r-- | chef/examples/sample_definition.rb (renamed from examples/sample_definition.rb) | 3 | ||||
-rw-r--r-- | chef/examples/sample_recipe.rb (renamed from examples/sample_recipe.rb) | 0 | ||||
-rw-r--r-- | chef/examples/search_index/segments | bin | 0 -> 16 bytes | |||
-rw-r--r-- | chef/examples/search_index/segments_0 | bin | 0 -> 25 bytes | |||
-rw-r--r-- | chef/examples/search_syntax.rb (renamed from examples/search_syntax.rb) | 0 | ||||
-rwxr-xr-x | chef/examples/user_index.pl (renamed from examples/user_index.pl) | 0 | ||||
-rwxr-xr-x | chef/examples/user_index.rb (renamed from examples/user_index.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef.rb (renamed from lib/chef.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/client.rb | 322 | ||||
-rw-r--r-- | chef/lib/chef/compile.rb (renamed from lib/chef/compile.rb) | 19 | ||||
-rw-r--r-- | chef/lib/chef/config.rb (renamed from lib/chef/config.rb) | 4 | ||||
-rw-r--r-- | chef/lib/chef/cookbook.rb (renamed from lib/chef/cookbook.rb) | 17 | ||||
-rw-r--r-- | chef/lib/chef/cookbook_loader.rb (renamed from lib/chef/cookbook_loader.rb) | 8 | ||||
-rw-r--r-- | chef/lib/chef/couchdb.rb (renamed from lib/chef/couchdb.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/exceptions.rb (renamed from lib/chef/exceptions.rb) | 2 | ||||
-rw-r--r-- | chef/lib/chef/file_cache.rb | 203 | ||||
-rw-r--r-- | chef/lib/chef/file_store.rb (renamed from lib/chef/file_store.rb) | 9 | ||||
-rw-r--r-- | chef/lib/chef/log.rb (renamed from lib/chef/log.rb) | 2 | ||||
-rw-r--r-- | chef/lib/chef/log/formatter.rb (renamed from lib/chef/log/formatter.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/mixin/check_helper.rb (renamed from lib/chef/mixin/check_helper.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/mixin/checksum.rb (renamed from lib/chef/mixin/checksum.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/mixin/command.rb (renamed from lib/chef/mixin/command.rb) | 41 | ||||
-rw-r--r-- | chef/lib/chef/mixin/create_path.rb | 56 | ||||
-rw-r--r-- | chef/lib/chef/mixin/from_file.rb (renamed from lib/chef/mixin/from_file.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/mixin/generate_url.rb | 46 | ||||
-rw-r--r-- | chef/lib/chef/mixin/params_validate.rb (renamed from lib/chef/mixin/params_validate.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/mixin/template.rb (renamed from lib/chef/mixin/template.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/node.rb (renamed from lib/chef/node.rb) | 20 | ||||
-rw-r--r-- | chef/lib/chef/openid_registration.rb (renamed from lib/chef/openid_registration.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/platform.rb (renamed from lib/chef/platform.rb) | 17 | ||||
-rw-r--r-- | chef/lib/chef/provider.rb (renamed from lib/chef/provider.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/provider/directory.rb (renamed from lib/chef/provider/directory.rb) | 2 | ||||
-rw-r--r-- | chef/lib/chef/provider/execute.rb (renamed from lib/chef/provider/execute.rb) | 4 | ||||
-rw-r--r-- | chef/lib/chef/provider/file.rb (renamed from lib/chef/provider/file.rb) | 24 | ||||
-rw-r--r-- | chef/lib/chef/provider/link.rb (renamed from lib/chef/provider/link.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/provider/package.rb (renamed from lib/chef/provider/package.rb) | 31 | ||||
-rw-r--r-- | chef/lib/chef/provider/package/apt.rb | 89 | ||||
-rw-r--r-- | chef/lib/chef/provider/package/portage.rb | 93 | ||||
-rw-r--r-- | chef/lib/chef/provider/package/rubygems.rb | 116 | ||||
-rw-r--r-- | chef/lib/chef/provider/remote_directory.rb (renamed from lib/chef/provider/remote_directory.rb) | 4 | ||||
-rw-r--r-- | chef/lib/chef/provider/remote_file.rb (renamed from lib/chef/provider/remote_file.rb) | 8 | ||||
-rw-r--r-- | chef/lib/chef/provider/script.rb (renamed from lib/chef/provider/script.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/provider/service.rb (renamed from lib/chef/provider/service.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/provider/service/debian.rb (renamed from lib/chef/provider/service/debian.rb) | 49 | ||||
-rw-r--r-- | chef/lib/chef/provider/service/init.rb | 95 | ||||
-rw-r--r-- | chef/lib/chef/provider/sysctl.rb (renamed from lib/chef/provider/sysctl.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/provider/template.rb (renamed from lib/chef/provider/template.rb) | 8 | ||||
-rw-r--r-- | chef/lib/chef/provider/user.rb | 179 | ||||
-rw-r--r-- | chef/lib/chef/provider/user/useradd.rb | 88 | ||||
-rw-r--r-- | chef/lib/chef/queue.rb (renamed from lib/chef/queue.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/recipe.rb (renamed from lib/chef/recipe.rb) | 20 | ||||
-rw-r--r-- | chef/lib/chef/resource.rb (renamed from lib/chef/resource.rb) | 33 | ||||
-rw-r--r-- | chef/lib/chef/resource/apt_package.rb | 33 | ||||
-rw-r--r-- | chef/lib/chef/resource/bash.rb (renamed from lib/chef/resource/bash.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/csh.rb (renamed from lib/chef/resource/csh.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/directory.rb (renamed from lib/chef/resource/directory.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/execute.rb (renamed from lib/chef/resource/execute.rb) | 30 | ||||
-rw-r--r-- | chef/lib/chef/resource/file.rb (renamed from lib/chef/resource/file.rb) | 2 | ||||
-rw-r--r-- | chef/lib/chef/resource/gem_package.rb | 33 | ||||
-rw-r--r-- | chef/lib/chef/resource/link.rb (renamed from lib/chef/resource/link.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/package.rb (renamed from lib/chef/resource/package.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/perl.rb (renamed from lib/chef/resource/perl.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/portage_package.rb | 33 | ||||
-rw-r--r-- | chef/lib/chef/resource/python.rb (renamed from lib/chef/resource/python.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/remote_directory.rb (renamed from lib/chef/resource/remote_directory.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/remote_file.rb (renamed from lib/chef/resource/remote_file.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/ruby.rb (renamed from lib/chef/resource/ruby.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/script.rb (renamed from lib/chef/resource/script.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/service.rb (renamed from lib/chef/resource/service.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/sysctl.rb (renamed from lib/chef/resource/sysctl.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/template.rb (renamed from lib/chef/resource/template.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/resource/user.rb | 96 | ||||
-rw-r--r-- | chef/lib/chef/resource_collection.rb (renamed from lib/chef/resource_collection.rb) | 3 | ||||
-rw-r--r-- | chef/lib/chef/resource_definition.rb (renamed from lib/chef/resource_definition.rb) | 3 | ||||
-rw-r--r-- | chef/lib/chef/rest.rb (renamed from lib/chef/rest.rb) | 59 | ||||
-rw-r--r-- | chef/lib/chef/runner.rb (renamed from lib/chef/runner.rb) | 42 | ||||
-rw-r--r-- | chef/lib/chef/search.rb (renamed from lib/chef/search.rb) | 0 | ||||
-rw-r--r-- | chef/lib/chef/search_index.rb (renamed from lib/chef/search_index.rb) | 0 | ||||
-rw-r--r-- | chef/spec/chef_server/controllers/log/merb_test.log (renamed from spec/chef_server/controllers/log/merb_test.log) | 0 | ||||
-rw-r--r-- | chef/spec/chef_server/controllers/nodes_spec.rb (renamed from spec/chef_server/controllers/nodes_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/chef_server/controllers/openid_consumer_spec.rb (renamed from spec/chef_server/controllers/openid_consumer_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/chef_server/controllers/openid_register_spec.rb (renamed from spec/chef_server/controllers/openid_register_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/chef_server/log/merb_test.log (renamed from spec/chef_server/log/merb_test.log) | 0 | ||||
-rw-r--r-- | chef/spec/chef_server/spec.opts (renamed from spec/chef_server/spec.opts) | 0 | ||||
-rw-r--r-- | chef/spec/chef_server/spec_helper.rb (renamed from spec/chef_server/spec_helper.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/bad-config.rb (renamed from spec/data/bad-config.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/compile/cookbooks/test/attributes/george.rb (renamed from spec/data/compile/cookbooks/test/attributes/george.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/compile/cookbooks/test/definitions/new_cat.rb (renamed from spec/data/compile/cookbooks/test/definitions/new_cat.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/compile/cookbooks/test/recipes/default.rb (renamed from spec/data/compile/cookbooks/test/recipes/default.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/compile/cookbooks/test/recipes/one.rb (renamed from spec/data/compile/cookbooks/test/recipes/one.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/compile/cookbooks/test/recipes/two.rb (renamed from spec/data/compile/cookbooks/test/recipes/two.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/compile/nodes/compile.rb (renamed from spec/data/compile/nodes/compile.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/config.rb (renamed from spec/data/config.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/apache2/recipes/default.rb | 3 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/attributes/default.rb (renamed from spec/data/cookbooks/openldap/attributes/default.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/attributes/smokey.rb (renamed from spec/data/cookbooks/openldap/attributes/smokey.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/definitions/client.rb (renamed from spec/data/cookbooks/openldap/definitions/client.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/definitions/server.rb (renamed from spec/data/cookbooks/openldap/definitions/server.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/ignore (renamed from spec/data/cookbooks/openldap/ignore) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/recipes/default.rb (renamed from spec/data/cookbooks/openldap/recipes/default.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/recipes/gigantor.rb (renamed from spec/data/cookbooks/openldap/recipes/gigantor.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/recipes/one.rb (renamed from spec/data/cookbooks/openldap/recipes/one.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/cookbooks/openldap/templates/default/test.erb (renamed from spec/data/cookbooks/openldap/templates/default/test.erb) | 0 | ||||
-rw-r--r-- | chef/spec/data/definitions/test.rb (renamed from spec/data/definitions/test.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/kitchen/openldap/attributes/default.rb (renamed from spec/data/kitchen/openldap/attributes/default.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/kitchen/openldap/attributes/robinson.rb (renamed from spec/data/kitchen/openldap/attributes/robinson.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/kitchen/openldap/definitions/client.rb (renamed from spec/data/kitchen/openldap/definitions/client.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/kitchen/openldap/definitions/drewbarrymore.rb (renamed from spec/data/kitchen/openldap/definitions/drewbarrymore.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/kitchen/openldap/recipes/gigantor.rb (renamed from spec/data/kitchen/openldap/recipes/gigantor.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/kitchen/openldap/recipes/ignoreme.rb (renamed from spec/data/kitchen/openldap/recipes/ignoreme.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/kitchen/openldap/recipes/woot.rb (renamed from spec/data/kitchen/openldap/recipes/woot.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/nodes/default.rb (renamed from spec/data/nodes/default.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/nodes/test.example.com.rb (renamed from spec/data/nodes/test.example.com.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/nodes/test.rb (renamed from spec/data/nodes/test.rb) | 0 | ||||
-rw-r--r-- | chef/spec/data/recipes/test.rb (renamed from spec/data/recipes/test.rb) | 2 | ||||
-rw-r--r-- | chef/spec/data/seattle.txt (renamed from spec/data/seattle.txt) | 0 | ||||
-rw-r--r-- | chef/spec/lib/chef/provider/easy.rb (renamed from spec/lib/chef/provider/easy.rb) | 0 | ||||
-rw-r--r-- | chef/spec/lib/chef/provider/snakeoil.rb (renamed from spec/lib/chef/provider/snakeoil.rb) | 0 | ||||
-rw-r--r-- | chef/spec/lib/chef/resource/cat.rb (renamed from spec/lib/chef/resource/cat.rb) | 0 | ||||
-rw-r--r-- | chef/spec/lib/chef/resource/zen_master.rb (renamed from spec/lib/chef/resource/zen_master.rb) | 0 | ||||
-rw-r--r-- | chef/spec/rcov.opts (renamed from spec/rcov.opts) | 0 | ||||
-rw-r--r-- | chef/spec/spec.opts (renamed from spec/spec.opts) | 0 | ||||
-rw-r--r-- | chef/spec/spec_helper.rb (renamed from spec/spec_helper.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/chef_spec.rb (renamed from spec/unit/chef_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/client_spec.rb | 179 | ||||
-rw-r--r-- | chef/spec/unit/compile_spec.rb (renamed from spec/unit/compile_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/config_spec.rb (renamed from spec/unit/config_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/cookbook_loader_spec.rb (renamed from spec/unit/cookbook_loader_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/cookbook_spec.rb (renamed from spec/unit/cookbook_spec.rb) | 8 | ||||
-rw-r--r-- | chef/spec/unit/couchdb_spec.rb (renamed from spec/unit/couchdb_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/file_cache_spec.rb | 124 | ||||
-rw-r--r-- | chef/spec/unit/file_store_spec.rb (renamed from spec/unit/file_store_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/log/formatter_spec.rb (renamed from spec/unit/log/formatter_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/log_spec.rb (renamed from spec/unit/log_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/mixin/params_validate_spec.rb (renamed from spec/unit/mixin/params_validate_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/mixin/template_spec.rb (renamed from spec/unit/mixin/template_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/node_spec.rb (renamed from spec/unit/node_spec.rb) | 10 | ||||
-rw-r--r-- | chef/spec/unit/openid_registration_spec.rb (renamed from spec/unit/openid_registration_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/platform_spec.rb (renamed from spec/unit/platform_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/provider/directory_spec.rb (renamed from spec/unit/provider/directory_spec.rb) | 2 | ||||
-rw-r--r-- | chef/spec/unit/provider/file_spec.rb (renamed from spec/unit/provider/file_spec.rb) | 15 | ||||
-rw-r--r-- | chef/spec/unit/provider/link_spec.rb (renamed from spec/unit/provider/link_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/provider/package/apt_spec.rb | 211 | ||||
-rw-r--r-- | chef/spec/unit/provider/package_spec.rb | 242 | ||||
-rw-r--r-- | chef/spec/unit/provider/remote_file_spec.rb (renamed from spec/unit/provider/remote_file_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/provider/template_spec.rb (renamed from spec/unit/provider/template_spec.rb) | 4 | ||||
-rw-r--r-- | chef/spec/unit/provider/user_spec.rb | 338 | ||||
-rw-r--r-- | chef/spec/unit/provider_spec.rb (renamed from spec/unit/provider_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/queue_spec.rb (renamed from spec/unit/queue_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/recipe_spec.rb (renamed from spec/unit/recipe_spec.rb) | 2 | ||||
-rw-r--r-- | chef/spec/unit/resource/bash_spec.rb (renamed from spec/unit/resource/bash_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/csh_spec.rb (renamed from spec/unit/resource/csh_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/directory_spec.rb (renamed from spec/unit/resource/directory_spec.rb) | 6 | ||||
-rw-r--r-- | chef/spec/unit/resource/execute_spec.rb (renamed from spec/unit/resource/execute_spec.rb) | 12 | ||||
-rw-r--r-- | chef/spec/unit/resource/file_spec.rb (renamed from spec/unit/resource/file_spec.rb) | 8 | ||||
-rw-r--r-- | chef/spec/unit/resource/link_spec.rb (renamed from spec/unit/resource/link_spec.rb) | 6 | ||||
-rw-r--r-- | chef/spec/unit/resource/package_spec.rb (renamed from spec/unit/resource/package_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/perl_spec.rb (renamed from spec/unit/resource/perl_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/python_spec.rb (renamed from spec/unit/resource/python_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/remote_directory_spec.rb (renamed from spec/unit/resource/remote_directory_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/remote_file_spec.rb (renamed from spec/unit/resource/remote_file_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/ruby_spec.rb (renamed from spec/unit/resource/ruby_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/script_spec.rb (renamed from spec/unit/resource/script_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/service_spec.rb (renamed from spec/unit/resource/service_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource/template_spec.rb (renamed from spec/unit/resource/template_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource_collection_spec.rb (renamed from spec/unit/resource_collection_spec.rb) | 15 | ||||
-rw-r--r-- | chef/spec/unit/resource_definition_spec.rb (renamed from spec/unit/resource_definition_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/resource_spec.rb (renamed from spec/unit/resource_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/rest_spec.rb (renamed from spec/unit/rest_spec.rb) | 41 | ||||
-rw-r--r-- | chef/spec/unit/runner_spec.rb (renamed from spec/unit/runner_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/search_index_spec.rb (renamed from spec/unit/search_index_spec.rb) | 0 | ||||
-rw-r--r-- | chef/spec/unit/search_spec.rb (renamed from spec/unit/search_spec.rb) | 0 | ||||
-rw-r--r-- | chef/stories/chef-client (renamed from stories/chef-client) | 0 | ||||
-rw-r--r-- | chef/stories/chef-client.rb (renamed from stories/chef-client.rb) | 0 | ||||
-rw-r--r-- | chef/stories/story_helper.rb (renamed from stories/story_helper.rb) | 0 | ||||
-rw-r--r-- | chef/tasks/rspec.rb (renamed from tasks/rspec.rb) | 0 | ||||
-rw-r--r-- | example-repository/Rakefile | 174 | ||||
-rw-r--r-- | example-repository/config/client.rb | 21 | ||||
-rw-r--r-- | example-repository/config/rake.rb | 54 | ||||
-rw-r--r-- | example-repository/config/server.rb | 25 | ||||
-rw-r--r-- | example-repository/config/solo.rb | 25 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/attributes/first.rb | 2 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/definitions/test.rb | 13 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt | 1 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/files/default/remote_test/another/window.txt | 1 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/files/default/remote_test/mycat.txt | 1 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/files/default/the_park.txt | 3 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/libraries/test.rb | 7 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/recipes/default.rb | 152 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/templates/default/monkey.erb | 5 | ||||
-rw-r--r-- | example-repository/cookbooks/rubygems_server/attributes/first.rb | 1 | ||||
-rw-r--r-- | example-repository/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem | bin | 0 -> 25600 bytes | |||
-rw-r--r-- | example-repository/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem | bin | 0 -> 61440 bytes | |||
-rw-r--r-- | example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem | bin | 0 -> 117248 bytes | |||
-rw-r--r-- | example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem | bin | 0 -> 18432 bytes | |||
-rw-r--r-- | example-repository/cookbooks/rubygems_server/recipes/default.rb | 8 | ||||
-rw-r--r-- | example-repository/cookbooks/servicetest/recipes/default.rb | 12 | ||||
-rw-r--r-- | example-repository/cookbooks/tempfile/attributes/second.rb | 1 | ||||
-rw-r--r-- | example-repository/cookbooks/tempfile/files/default/packages/blank | 0 | ||||
-rw-r--r-- | example-repository/cookbooks/tempfile/files/default/packages/test | 1 | ||||
-rw-r--r-- | example-repository/cookbooks/tempfile/recipes/default.rb | 24 | ||||
-rw-r--r-- | example-repository/log/merb.main.log | 2 | ||||
-rw-r--r-- | example-repository/log/merb.main.pid | 1 | ||||
-rw-r--r-- | lib/chef/client.rb | 162 | ||||
-rw-r--r-- | lib/chef/provider/apt.rb | 87 | ||||
-rw-r--r-- | lib/chef/provider/service/init.rb | 93 | ||||
-rw-r--r-- | lib/chef_server/public/stylesheets/master.css | 292 | ||||
-rw-r--r-- | lib/chef_server/views/cookbooks/_attribute_file.html.haml | 2 | ||||
-rw-r--r-- | lib/chef_server/views/cookbooks/show.html.haml | 24 | ||||
-rw-r--r-- | log/chef-server.log | 9 | ||||
-rw-r--r-- | log/merb_test.log | 7 | ||||
-rw-r--r-- | spec/unit/client_spec.rb | 61 |
311 files changed, 5015 insertions, 1191 deletions
diff --git a/.gitignore b/.gitignore index 7e2a22c7c6..98d5c33e2e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ examples/search_index examples/store examples/openid-cstore examples/openid-db +chef/pkg +chef-server/pkg +chef/log +chef-server/log *.swp diff --git a/Manifest.txt b/Manifest.txt deleted file mode 100644 index 38793f098b..0000000000 --- a/Manifest.txt +++ /dev/null @@ -1,85 +0,0 @@ -.gitignore -History.txt -Manifest.txt -README.txt -Rakefile -bin/chef-solo -examples/config.rb -examples/config/chef-solo.rb -examples/config/cookbooks/fakefile/recipes/default.rb -examples/config/cookbooks/tempfile/recipes/default.rb -examples/config/nodes/latte.rb -examples/mrepo/Rakefile -examples/node.rb -examples/node.yml -examples/sample_definition.rb -examples/sample_recipe.rb -lib/chef.rb -lib/chef/compile.rb -lib/chef/config.rb -lib/chef/cookbook.rb -lib/chef/cookbook_loader.rb -lib/chef/log.rb -lib/chef/log/formatter.rb -lib/chef/mixin/check_helper.rb -lib/chef/mixin/from_file.rb -lib/chef/mixin/params_validate.rb -lib/chef/node.rb -lib/chef/provider.rb -lib/chef/provider/file.rb -lib/chef/recipe.rb -lib/chef/resource.rb -lib/chef/resource/file.rb -lib/chef/resource_collection.rb -lib/chef/resource_definition.rb -spec/data/bad-config.rb -spec/data/compile/cookbooks/test/attributes/george.rb -spec/data/compile/cookbooks/test/definitions/new_cat.rb -spec/data/compile/cookbooks/test/recipes/default.rb -spec/data/compile/cookbooks/test/recipes/one.rb -spec/data/compile/cookbooks/test/recipes/two.rb -spec/data/compile/nodes/compile.rb -spec/data/config.rb -spec/data/cookbooks/openldap/attributes/default.rb -spec/data/cookbooks/openldap/attributes/smokey.rb -spec/data/cookbooks/openldap/definitions/client.rb -spec/data/cookbooks/openldap/definitions/server.rb -spec/data/cookbooks/openldap/ignore -spec/data/cookbooks/openldap/recipes/default.rb -spec/data/cookbooks/openldap/recipes/gigantor.rb -spec/data/cookbooks/openldap/recipes/one.rb -spec/data/definitions/test.rb -spec/data/kitchen/openldap/attributes/default.rb -spec/data/kitchen/openldap/attributes/robinson.rb -spec/data/kitchen/openldap/definitions/client.rb -spec/data/kitchen/openldap/definitions/drewbarrymore.rb -spec/data/kitchen/openldap/recipes/gigantor.rb -spec/data/kitchen/openldap/recipes/ignoreme.rb -spec/data/kitchen/openldap/recipes/woot.rb -spec/data/nodes/default.rb -spec/data/nodes/test.example.com.rb -spec/data/nodes/test.rb -spec/data/recipes/test.rb -spec/data/seattle.txt -spec/lib/chef/resource/cat.rb -spec/lib/chef/resource/zen_master.rb -spec/rcov.opts -spec/spec.opts -spec/spec_helper.rb -spec/unit/chef_spec.rb -spec/unit/compile_spec.rb -spec/unit/config_spec.rb -spec/unit/cookbook_loader_spec.rb -spec/unit/cookbook_spec.rb -spec/unit/log/formatter_spec.rb -spec/unit/log_spec.rb -spec/unit/mixin/params_validate_spec.rb -spec/unit/node_spec.rb -spec/unit/provider/file_spec.rb -spec/unit/provider_spec.rb -spec/unit/recipe_spec.rb -spec/unit/resource/file_spec.rb -spec/unit/resource_collection_spec.rb -spec/unit/resource_definition_spec.rb -spec/unit/resource_spec.rb -tasks/rspec.rb @@ -8,5 +8,5 @@ Contributors and Copyright holders: * Copyright 2008, Adam Jacob <adam@hjksolutions.com> * Copyright 2008, Arjuna Christensen <aj@hjksolutions.com> * Copyright 2008, Bryan McLellan <btm@loftninjas.org> + * Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com> - diff --git a/README.txt b/README.txt index 33536adcf2..81ced454ce 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ == DESCRIPTION: -Chef is a configuration management tool inspired by Puppet. +Chef is a configuration management tool. I'm in ur netwerk, cookin up yer servers. :) @@ -19,6 +19,8 @@ I'm in ur netwerk, cookin up yer servers. :) RubyGems: * stomp +* stompserver +* ultraviolet * facter * ferret * merb-core @@ -42,15 +44,11 @@ Install all of the above. To fire up a develpment environment, do the following * Start stompserver with 'stompserver' * Start chef-indexer with: - ./bin/chef-indexer -l debug -c ./config/chef-server.rb - - * Start chef-server on port 4000 with: + chef-indexer -l debug - ./bin/chef-server + * Start chef-server: - * Start chef-server on port 4001 to validate node openid with: - - ./bin/chef-server -p 4001 + chef-server -N -c 2 * Test run chef to begin node registration: @@ -64,7 +62,7 @@ Install all of the above. To fire up a develpment environment, do the following * Test run chef with: - sudo ./bin/chef-client -l debug -c ./examples/config/chef-solo.rb + chef-client -l debug == LICENSE: @@ -1,21 +1,25 @@ -# -*- ruby -*- +gems = %w[chef chef-server] -require 'rubygems' -require 'hoe' -require './lib/chef.rb' -require './tasks/rspec.rb' -# require Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rb')].sort.each do |lib| -# require lib -# end - -Hoe.new('chef', Chef::VERSION) do |p| - p.rubyforge_name = 'chef' - p.author = 'Adam Jacob' - p.email = 'adam@hjksolutions.com' - p.summary = 'A configuration management system.' - p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n") - p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1] - p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n") +desc "Build the chef gems" +task :build_gems do + gems.each do |dir| + Dir.chdir(dir) { sh "rake package" } + end +end + +desc "Install the chef gems" +task :install do + gems.each do |dir| + Dir.chdir(dir) { sh "rake install" } + end end -# vim: syntax=Ruby +namespace :dev do + desc "Install a Devel instance of Chef with the example-repository" + task :install do + gems.each do |dir| + Dir.chdir(dir) { sh "rake install" } + end + Dir.chdir("example-repository") { sh("rake install") } + end +end
\ No newline at end of file diff --git a/chef-server/LICENSE b/chef-server/LICENSE new file mode 100644 index 0000000000..11069edd79 --- /dev/null +++ b/chef-server/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/chef-server/NOTICE b/chef-server/NOTICE new file mode 100644 index 0000000000..856fdc82b0 --- /dev/null +++ b/chef-server/NOTICE @@ -0,0 +1,10 @@ +Chef NOTICE +=========== + +Developed at HJK Solutions (http://www.hjksolutions.com). + +Contributors and Copyright holders: + + * Copyright 2008, Adam Jacob <adam@hjksolutions.com> + * Copyright 2008, Arjuna Christensen <aj@hjksolutions.com> + * Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com> diff --git a/chef-server/README.txt b/chef-server/README.txt new file mode 100644 index 0000000000..08a0d31bf2 --- /dev/null +++ b/chef-server/README.txt @@ -0,0 +1,77 @@ += chef-server + +* http://oss.hjksolutions.com/chef + +== DESCRIPTION: + +Chef is a configuration management tool inspired by Puppet. + +I'm in ur netwerk, cookin up yer servers. :) + +== FEATURES/PROBLEMS: + + +== SYNOPSIS: + + +== REQUIREMENTS: + +RubyGems: + +* stomp +* stompserver +* ultraviolet +* facter +* ferret +* merb-core +* haml +* ruby-openid +* json + +External Servers: + +* stompserver (for easy stomp mq testing) +* CouchDB + +== INSTALL: + +Install all of the above. To fire up a develpment environment, do the following: + + * Start CouchDB with 'couchdb' + * Start stompserver with 'stompserver' + * Start chef-indexer with: + + ./bin/chef-indexer -l debug -c ./config/chef-server.rb + + * Start chef-server on port 4000 with: + + ./bin/chef-server + + * Start chef-server on port 4001 with: + + ./bin/chef-server -p 4001 + + * Test run chef with: + + sudo ./bin/chef-client -l debug -c ./examples/config/chef-solo.rb + +== LICENSE: + +Chef - A configuration management system + +Author:: Adam Jacob (<adam@hjksolutions.com>) +Copyright:: Copyright (c) 2008 HJK Solutions, LLC +License:: Apache License, Version 2.0 + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + diff --git a/chef-server/Rakefile b/chef-server/Rakefile new file mode 100644 index 0000000000..7dfdab5137 --- /dev/null +++ b/chef-server/Rakefile @@ -0,0 +1,48 @@ +# -*- ruby -*- +require 'rubygems' +require 'rake/gempackagetask' + +GEM = "chef-server" +VERSION = "0.0.1" +AUTHOR = "Adam Jacob" +EMAIL = "adam@hjksolutions.com" +HOMEPAGE = "http://hjksolutions.com" +SUMMARY = "A configuration management system server." + +spec = Gem::Specification.new do |s| + s.name = GEM + s.version = VERSION + s.platform = Gem::Platform::RUBY + s.has_rdoc = true + s.extra_rdoc_files = ["README.txt", "LICENSE", 'NOTICE'] + s.summary = SUMMARY + s.description = s.summary + s.author = AUTHOR + s.email = EMAIL + s.homepage = HOMEPAGE + + # Uncomment this to add a dependency + s.add_dependency "stomp" + s.add_dependency "stompserver" + s.add_dependency "ferret" + s.add_dependency "merb-core" + s.add_dependency "haml" + s.add_dependency "ruby-openid" + s.add_dependency "json" + s.add_dependency "syntax" + + s.bindir = "bin" + s.executables = %w( chef-indexer chef-server ) + + s.files = %w(LICENSE README.txt Rakefile) + Dir.glob("{lib}/**/*") +end + +Rake::GemPackageTask.new(spec) do |pkg| + pkg.gem_spec = spec +end + +task :install => [:package] do + sh %{sudo gem install pkg/#{GEM}-#{VERSION} --no-rdoc --no-ri} +end + +# vim: syntax=Ruby
\ No newline at end of file diff --git a/bin/chef-indexer b/chef-server/bin/chef-indexer index 76606e9219..02a02a8ad6 100755 --- a/bin/chef-indexer +++ b/chef-server/bin/chef-indexer @@ -18,15 +18,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -$: << File.join(File.dirname(__FILE__), "..", "lib") - require 'optparse' require 'chef' require 'rubygems' require 'facter' config = { - :config_file => "/etc/chef/config.rb", + :config_file => "/etc/chef/server.rb", :log_level => :info } opts = OptionParser.new do |opts| diff --git a/bin/chef-server b/chef-server/bin/chef-server index 1322fdd03f..75c7730844 100755 --- a/bin/chef-server +++ b/chef-server/bin/chef-server @@ -22,15 +22,25 @@ require "rubygems" require "merb-core" +require "chef" if ARGV[0] && ARGV[0] =~ /^[^-]/ ARGV.push "-H" end - unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) } ARGV.push *%w[-a mongrel] end +ARGV.push *[ "-I", File.join(File.dirname(__FILE__), "..", "lib", "init.rb") ] -ARGV.push *[ "-I", File.join(File.dirname(__FILE__), "..", "lib", "chef_server", "init.rb") ] +if index = ARGV.index("-C") + config = ARGV[index+1] + ARGV.delete("-C") + ARGV.delete(config) + Chef::Config.from_file(File.expand_path(config)) +else + Chef::Config.from_file( + File.join("/etc", "chef", "server.rb") + ) +end Merb.start diff --git a/lib/chef_server/controllers/application.rb b/chef-server/lib/controllers/application.rb index a288b87dba..815c284144 100644 --- a/lib/chef_server/controllers/application.rb +++ b/chef-server/lib/controllers/application.rb @@ -16,6 +16,8 @@ # limitations under the License. # +require "chef" / "mixin" / "checksum" + class Application < Merb::Controller def fix_up_node_id @@ -83,5 +85,67 @@ class Application < Merb::Controller raise Unauthorized, "You must authenticate first!" end end + + # Load a cookbook and return a hash with a list of all the files of a + # given segment (attributes, recipes, definitions, libraries) + # + # === Parameters + # cookbook_id<String>:: The cookbook to load + # segment<Symbol>:: :attributes, :recipes, :definitions, :libraries + # + # === Returns + # <Hash>:: A hash consisting of the short name of the file in :name, and the full path + # to the file in :file. + def load_cookbook_segment(cookbook_id, segment) + cl = Chef::CookbookLoader.new + cookbook = cl[cookbook_id] + raise NotFound unless cookbook + + files_list = segment_files(segment, cookbook) + + files = Hash.new + files_list.each do |f| + full = File.expand_path(f) + name = File.basename(full) + files[name] = { + :name => name, + :file => full, + } + end + files + end + + def segment_files(segment, cookbook) + files_list = nil + case segment + when :attributes + files_list = cookbook.attribute_files + when :recipes + files_list = cookbook.recipe_files + when :definitions + files_list = cookbook.definition_files + when :libraries + files_list = cookbook.lib_files + else + raise ArgumentError, "segment must be one of :attributes, :recipes, :definitions or :libraries" + end + files_list + end + + def load_all_files(segment) + cl = Chef::CookbookLoader.new + files = Array.new + cl.each do |cookbook| + segment_files(segment, cookbook).each do |sf| + mo = sf.match("cookbooks/#{cookbook.name}/#{segment}/(.+)") + file_name = mo[1] + files << { + :cookbook => cookbook.name, + :name => file_name + } + end + end + files + end end
\ No newline at end of file diff --git a/chef-server/lib/controllers/cookbook_attributes.rb b/chef-server/lib/controllers/cookbook_attributes.rb new file mode 100644 index 0000000000..803421b6f5 --- /dev/null +++ b/chef-server/lib/controllers/cookbook_attributes.rb @@ -0,0 +1,55 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +class CookbookAttributes < Application + + provides :html, :json + + include Chef::Mixin::Checksum + + def load_cookbook_attributes() + @attribute_files = load_cookbook_segment(params[:cookbook_id], :attributes) + end + + def index + if params[:id] + show + else + load_cookbook_attributes() + display @attribute_files + end + end + + def show + only_provides :json + load_cookbook_attributes + raise NotFound, "Cannot find a suitable attribute file!" unless @attribute_files.has_key?(params[:id]) + to_send = @attribute_files[params[:id]][:file] + current_checksum = checksum(to_send) + Chef::Log.debug("old sum: #{params[:checksum]}, new sum: #{current_checksum}") + if current_checksum == params[:checksum] + display "File #{to_send} has not changed", :status => 304 + else + send_file(to_send) + end + end + +end + + diff --git a/chef-server/lib/controllers/cookbook_definitions.rb b/chef-server/lib/controllers/cookbook_definitions.rb new file mode 100644 index 0000000000..dbfeeca4d7 --- /dev/null +++ b/chef-server/lib/controllers/cookbook_definitions.rb @@ -0,0 +1,56 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +class CookbookDefinitions < Application + + provides :html, :json + + include Chef::Mixin::Checksum + + def load_cookbook_definitions() + @definition_files = load_cookbook_segment(params[:cookbook_id], :definitions) + end + + def index + if params[:id] + show + else + load_cookbook_definitions() + display @definition_files + end + end + + def show + only_provides :json + load_cookbook_definitions + raise NotFound, "Cannot find a suitable definition file!" unless @definition_files.has_key?(params[:id]) + + to_send = @definition_files[params[:id]][:file] + current_checksum = checksum(to_send) + Chef::Log.debug("Old sum: #{params[:checksum]}, New sum: #{current_checksum}") + if current_checksum == params[:checksum] + display "File #{to_send} has not changed", :status => 304 + else + send_file(to_send) + end + end + +end + + diff --git a/lib/chef_server/controllers/cookbook_files.rb b/chef-server/lib/controllers/cookbook_files.rb index 30b0dead65..df332d5972 100644 --- a/lib/chef_server/controllers/cookbook_files.rb +++ b/chef-server/lib/controllers/cookbook_files.rb @@ -16,7 +16,6 @@ # limitations under the License. # -require File.join(File.dirname(__FILE__), "..", "..", "chef", "mixin", "checksum") class CookbookFiles < Application @@ -43,6 +42,7 @@ class CookbookFiles < Application :file => full, } end + Chef::Log.debug("Remote files found: #{@remote_files.inspect}") @remote_files end @@ -73,7 +73,6 @@ class CookbookFiles < Application end def show_directory - Chef::Log.info("totally rocking hte show_directory") dir_to_send = find_preferred_file unless (dir_to_send && File.directory?(dir_to_send)) raise NotFound, "Cannot find a suitable directory" diff --git a/chef-server/lib/controllers/cookbook_libraries.rb b/chef-server/lib/controllers/cookbook_libraries.rb new file mode 100644 index 0000000000..ae6b474261 --- /dev/null +++ b/chef-server/lib/controllers/cookbook_libraries.rb @@ -0,0 +1,55 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class CookbookLibraries < Application + + provides :html, :json + + include Chef::Mixin::Checksum + + def load_cookbook_libs() + @lib_files = load_cookbook_segment(params[:cookbook_id], :libraries) + end + + def index + if params[:id] + show + else + load_cookbook_libs() + display @lib_files + end + end + + def show + only_provides :json + load_cookbook_libs + raise NotFound, "Cannot find a suitable library file!" unless @lib_files.has_key?(params[:id]) + + to_send = @lib_files[params[:id]][:file] + current_checksum = checksum(to_send) + Chef::Log.debug("Old sum: #{params[:checksum]}, New sum: #{current_checksum}") + if current_checksum == params[:checksum] + display "File #{to_send} has not changed", :status => 304 + else + send_file(to_send) + end + end + +end + + diff --git a/chef-server/lib/controllers/cookbook_recipes.rb b/chef-server/lib/controllers/cookbook_recipes.rb new file mode 100644 index 0000000000..5081ddced1 --- /dev/null +++ b/chef-server/lib/controllers/cookbook_recipes.rb @@ -0,0 +1,56 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +class CookbookRecipes < Application + + provides :html, :json + + include Chef::Mixin::Checksum + + def load_cookbook_recipes() + @recipe_files = load_cookbook_segment(params[:cookbook_id], :recipes) + end + + def index + if params[:id] + show + else + load_cookbook_recipes() + display @recipe_files + end + end + + def show + only_provides :json + load_cookbook_recipes + raise NotFound, "Cannot find a suitable recipe file!" unless @recipe_files.has_key?(params[:id]) + + to_send = @recipe_files[params[:id]][:file] + current_checksum = checksum(to_send) + Chef::Log.debug("old sum: #{params[:checksum]}, new sum: #{current_checksum}") + if current_checksum == params[:checksum] + display "File #{to_send} has not changed", :status => 304 + else + send_file(to_send) + end + end + +end + + diff --git a/lib/chef_server/controllers/cookbook_templates.rb b/chef-server/lib/controllers/cookbook_templates.rb index 4cb5e4622c..4cb5e4622c 100644 --- a/lib/chef_server/controllers/cookbook_templates.rb +++ b/chef-server/lib/controllers/cookbook_templates.rb diff --git a/lib/chef_server/controllers/cookbooks.rb b/chef-server/lib/controllers/cookbooks.rb index 3e68d1f4bc..81a39e4edf 100644 --- a/lib/chef_server/controllers/cookbooks.rb +++ b/chef-server/lib/controllers/cookbooks.rb @@ -31,21 +31,25 @@ class Cookbooks < Application raise NotFound unless @cookbook display @cookbook end + + def recipe_files + @recipe_files = load_all_files(:recipes) + display @recipe_files + end def attribute_files - cl = Chef::CookbookLoader.new - @attribute_files = Array.new - cl.each do |cookbook| - cookbook.attribute_files.each do |af| - @attribute_files << { - :cookbook => cookbook.name, - :name => File.basename(af), - :path => af, - :contents => File.read(af) - } - end - end + @attribute_files = load_all_files(:attributes) display @attribute_files end + def definition_files + @definition_files = load_all_files(:definitions) + display @definition_files + end + + def library_files + @lib_files = load_all_files(:libraries) + display @lib_files + end + end diff --git a/lib/chef_server/controllers/exceptions.rb b/chef-server/lib/controllers/exceptions.rb index d8f7307637..d8f7307637 100644 --- a/lib/chef_server/controllers/exceptions.rb +++ b/chef-server/lib/controllers/exceptions.rb diff --git a/lib/chef_server/controllers/nodes.rb b/chef-server/lib/controllers/nodes.rb index a1ba1131ac..655b264862 100644 --- a/lib/chef_server/controllers/nodes.rb +++ b/chef-server/lib/controllers/nodes.rb @@ -75,18 +75,4 @@ class Nodes < Application end end - def compile - # Grab a Chef::Compile object - compile = Chef::Compile.new() - compile.load_node(params[:id]) - compile.node.save - compile.load_definitions - compile.load_recipes - @output = { - :node => compile.node, - :collection => compile.collection, - } - display @output - end - end diff --git a/lib/chef_server/controllers/openid_consumer.rb b/chef-server/lib/controllers/openid_consumer.rb index 4e3980ce3d..4e3980ce3d 100644 --- a/lib/chef_server/controllers/openid_consumer.rb +++ b/chef-server/lib/controllers/openid_consumer.rb diff --git a/lib/chef_server/controllers/openid_register.rb b/chef-server/lib/controllers/openid_register.rb index 34851bc517..43f4bc003d 100644 --- a/lib/chef_server/controllers/openid_register.rb +++ b/chef-server/lib/controllers/openid_register.rb @@ -25,7 +25,7 @@ class OpenidRegister < Application before :fix_up_node_id def index - @headers['X-XRDS-Location'] = absolute_url(:controller => "openid_server", :action => "idp_xrds") + @headers['X-XRDS-Location'] = Chef::Config[:openid_url] + "/openid/server/server/xrds" @registered_nodes = Chef::OpenIDRegistration.list(true) Chef::Log.debug(@registered_nodes.inspect) display @registered_nodes @@ -41,7 +41,7 @@ class OpenidRegister < Application raise e end end - Merb.logger.debug(@registered_node.inspect) + Chef::Log.debug(@registered_node.inspect) display @registered_node end @@ -54,6 +54,9 @@ class OpenidRegister < Application @registered_node = Chef::OpenIDRegistration.new @registered_node.name = params[:id] @registered_node.set_password(params[:password]) + if params[:validation_token] == Chef::Config[:validation_token] + @registered_node.validated = true + end @registered_node.save display @registered_node end diff --git a/lib/chef_server/controllers/openid_server.rb b/chef-server/lib/controllers/openid_server.rb index 4cdaf67adb..7461f6769c 100644 --- a/lib/chef_server/controllers/openid_server.rb +++ b/chef-server/lib/controllers/openid_server.rb @@ -141,7 +141,7 @@ EOS session[:last_oidreq] = nil if params.has_key?(:cancel) - Merb.logger.info("Cancelling OpenID Authentication") + Chef::Log.info("Cancelling OpenID Authentication") return(redirect(oidreq.cancel_url)) else identity = oidreq.identity diff --git a/lib/chef_server/controllers/search.rb b/chef-server/lib/controllers/search.rb index 0abbf352b8..0abbf352b8 100644 --- a/lib/chef_server/controllers/search.rb +++ b/chef-server/lib/controllers/search.rb diff --git a/lib/chef_server/controllers/search_entries.rb b/chef-server/lib/controllers/search_entries.rb index c93add3dc5..c93add3dc5 100644 --- a/lib/chef_server/controllers/search_entries.rb +++ b/chef-server/lib/controllers/search_entries.rb diff --git a/chef-server/lib/helpers/cookbooks_helper.rb b/chef-server/lib/helpers/cookbooks_helper.rb new file mode 100644 index 0000000000..995f2eb601 --- /dev/null +++ b/chef-server/lib/helpers/cookbooks_helper.rb @@ -0,0 +1,30 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module Merb + module CookbooksHelper + def syntax_highlight(code) + converter = Syntax::Convertors::HTML.for_syntax "ruby" + if File.exists?(code) + converter.convert(File.read(code)) + else + converter.convert(code) + end + end + end +end diff --git a/lib/chef_server/helpers/global_helpers.rb b/chef-server/lib/helpers/global_helpers.rb index f3b15129a8..f3b15129a8 100644 --- a/lib/chef_server/helpers/global_helpers.rb +++ b/chef-server/lib/helpers/global_helpers.rb diff --git a/lib/chef_server/helpers/nodes_helper.rb b/chef-server/lib/helpers/nodes_helper.rb index 44a190a7c6..44a190a7c6 100644 --- a/lib/chef_server/helpers/nodes_helper.rb +++ b/chef-server/lib/helpers/nodes_helper.rb diff --git a/lib/chef_server/helpers/openid_server_helpers.rb b/chef-server/lib/helpers/openid_server_helpers.rb index dc56d2742f..dc56d2742f 100644 --- a/lib/chef_server/helpers/openid_server_helpers.rb +++ b/chef-server/lib/helpers/openid_server_helpers.rb diff --git a/lib/chef_server/init.rb b/chef-server/lib/init.rb index 0445e9510b..4386361ca9 100644 --- a/lib/chef_server/init.rb +++ b/chef-server/lib/init.rb @@ -16,7 +16,9 @@ # limitations under the License. # -Merb.root = File.join(File.dirname(__FILE__)) +require 'chef' + +Merb.root = Chef::Config[:merb_root] # # ==== Structure of Merb initializer @@ -81,8 +83,6 @@ Merb.disable :json # OR # dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0" Merb::BootLoader.after_app_loads do - # Add dependencies here that must load after the application loads: - Chef::Config.from_file(File.join(File.dirname(__FILE__), "..", "..", "config", "chef-server.rb")) Chef::Queue.connect # create the couch design docs for nodes and openid registrations @@ -117,7 +117,7 @@ Merb.push_path(:helper, File.join(File.dirname(__FILE__), "helpers")) Merb.push_path(:public, File.join(File.dirname(__FILE__), "public")) require 'merb-haml' -require 'uv' +require 'syntax/convertors/html' # @@ -140,6 +140,7 @@ use_test :rspec # ==== Set up your basic configuration # Merb::Config.use do |c| + c[:fork_for_class_load] = false # Sets up a custom session id key, if you want to piggyback sessions of other applications # with the cookie session store. If not specified, defaults to '_session_id'. c[:session_id_key] = '_chef_server_session_id' @@ -148,10 +149,10 @@ Merb::Config.use do |c| c[:exception_details] = true c[:reload_classes] = true c[:log_level] = :debug - c[:log_file] = STDOUT + c[:log_stream] = STDOUT end -Merb.logger.info("Compiling routes...") +Chef::Log.info("Compiling routes...") Merb::Router.prepare do |r| # RESTful routes # r.resources :posts @@ -161,18 +162,26 @@ Merb::Router.prepare do |r| # routes, you may want to comment/remove this line to prevent # clients from calling your create or destroy actions with a GET - r.resources :nodes - r.resources :nodes, :member => { :compile => :get } - r.resources :search do |res| - res.resources :entries, :controller => "search_entries" + resources :nodes + resources :searches, :path => "search", :controller => "search" do + resources :entries, :controller => "search_entries" end - r.match("/cookbooks/_attribute_files").to(:controller => "cookbooks", :action => "attribute_files") + match("/cookbooks/_attribute_files").to(:controller => "cookbooks", :action => "attribute_files") + match("/cookbooks/_recipe_files").to(:controller => "cookbooks", :action => "recipe_files") + match("/cookbooks/_definition_files").to(:controller => "cookbooks", :action => "definition_files") + Chef::Log.info("Seriously, what the fuck") + match("/cookbooks/_library_files").to(:controller => "cookbooks", :action => "library_files") + # r.match("/cookbooks/:cookbook_id/templates").to(:controller => "cookbook_templates", :action => "index") - r.resources :cookbooks do |cookbooks| - cookbooks.resources :templates, :controller => "cookbook_templates" - cookbooks.resources :files, :controller => "cookbook_files" + resources :cookbooks do + resources :templates, :controller => "cookbook_templates" + resources :files, :controller => "cookbook_files" + resources :recipes, :controller => "cookbook_recipes" + resources :attributes, :controller => "cookbook_attributes" + resources :definitions, :controller => "cookbook_definitions" + resources :libraries, :controller => "cookbook_libraries" end #r.resources :openid do |res| @@ -180,24 +189,23 @@ Merb::Router.prepare do |r| # res.resources :server, :controller => "openid_server" #end - r.resources :registrations, :controller => "openid_register" - r.resources :registrations, :controller => "openid_register", :member => { :validate => :post } - r.match("/openid/server").to(:controller => "openid_server", :action => "index").name(:openid_server) - r.match("/openid/server/server/xrds"). + resources :registrations, :controller => "openid_register" + resources :registrations, :controller => "openid_register", :member => { :validate => :post } + match("/openid/server").to(:controller => "openid_server", :action => "index").name(:openid_server) + match("/openid/server/server/xrds"). to(:controller => "openid_server", :action => 'idp_xrds').name(:openid_server_xrds) - r.match("/openid/server/node/:id"). + match("/openid/server/node/:id"). to(:controller => "openid_server", :action => 'node_page').name(:openid_node) - r.match('/openid/server/node/:id/xrds'). + match('/openid/server/node/:id/xrds'). to(:controller => 'openid_server', :action => 'node_xrds').name(:openid_node_xrds) - r.match('/openid/server/decision').to(:controller => "openid_server", :action => "decision").name(:openid_server_decision) - r.match('/openid/consumer').to(:controller => 'openid_consumer', :action => 'index').name(:openid_consumer) - r.match('/openid/consumer/start').to(:controller => 'openid_consumer', :action => 'start').name(:openid_consumer_start) - r.match('/openid/consumer/complete').to(:controller => 'openid_consumer', :action => 'complete').name(:openid_consumer_complete) - r.match('/openid/consumer/logout').to(:controller => 'openid_consumer', :action => 'logout').name(:openid_consumer_logout) + match('/openid/server/decision').to(:controller => "openid_server", :action => "decision").name(:openid_server_decision) + match('/openid/consumer').to(:controller => 'openid_consumer', :action => 'index').name(:openid_consumer) + match('/openid/consumer/start').to(:controller => 'openid_consumer', :action => 'start').name(:openid_consumer_start) + match('/openid/consumer/complete').to(:controller => 'openid_consumer', :action => 'complete').name(:openid_consumer_complete) + match('/openid/consumer/logout').to(:controller => 'openid_consumer', :action => 'logout').name(:openid_consumer_logout) #r.default_routes # Change this for your home page to be available at / - r.match('/').to(:controller => 'nodes', :action =>'index').name(:top) + match('/').to(:controller => 'nodes', :action =>'index').name(:top) end - diff --git a/lib/chef_server/public/images/merb.jpg b/chef-server/lib/public/images/merb.jpg Binary files differindex a19dcf4048..a19dcf4048 100644 --- a/lib/chef_server/public/images/merb.jpg +++ b/chef-server/lib/public/images/merb.jpg diff --git a/chef-server/lib/public/stylesheets/master.css b/chef-server/lib/public/stylesheets/master.css new file mode 100644 index 0000000000..2f5b5782b4 --- /dev/null +++ b/chef-server/lib/public/stylesheets/master.css @@ -0,0 +1,173 @@ +/* body { + font-family: Arial, Verdana, sans-serif; + font-size: 12px; + background-color: #fff; + margin: ; +} +html { + height: 100%; + margin-bottom: 1px; +} +#container { + width: 80%; + text-align: left; + background-color: #fff; + margin-right: auto; + margin-left: auto; +} +#header-container { + width: 100%; + padding-top: 15px; +} +#header-container h1, #header-container h2 { + margin-left: 6px; + margin-bottom: 6px; +} +.spacer { + width: 100%; + height: 15px; +} +hr { + border: 0px; + color: #ccc; + background-color: #cdcdcd; + height: 1px; + width: 100%; + text-align: left; +} +h1 { + font-size: 28px; + color: #c55; + background-color: #fff; + font-family: Arial, Verdana, sans-serif; + font-weight: 300; +} +h2 { + font-size: 15px; + color: #999; + font-family: Arial, Verdana, sans-serif; + font-weight: 300; + background-color: #fff; +} +h3 { + color: #4d9b12; + font-size: 15px; + text-align: left; + font-weight: 300; + padding: 5px; + margin-top: 5px; +} + +#left-container { + float: left; + width: 250px; + background-color: #FFFFFF; + color: black; +} + +#left-container h3 { + color: #c55; +} + +#main-container { + margin: 5px 5px 5px 260px; + padding: 15px; + border-left: 1px solid silver; + min-height: 400px; +} +p { + color: #000; + background-color: #fff; + line-height: 20px; + padding: 5px; +} +a { + color: #4d9b12; + background-color: #fff; + text-decoration: none; +} +a:hover { + color: #4d9b12; + background-color: #fff; + text-decoration: underline; +} +#footer-container { + clear: both; + font-size: 12px; + font-family: Verdana, Arial, sans-serif; +} +.right { + float: right; + font-size: 100%; + margin-top: 5px; + color: #999; + background-color: #fff; +} +.left { + float: left; + font-size: 100%; + margin-top: 5px; + color: #999; + background-color: #fff; +} +#main-container ul { + margin-left: 3.0em; +} + +div.resource_collection { + border: 1px solid #999; + float: left; + clear: both; + margin: 10px; + padding: 5px; +} + +div.resource { + border-top: 1px solid #999; + float: left; + clear: both; +} + +div.attr_group { + float: left; + clear: both; +} + +td.attr_name { + font-weight: bold; + margin-right: 10px; + border-right: 1px solid #999; +} + +td.attr_value { + padding-left: 5px; + border-top: 1px solid #999; +} + +div.node { + float: left; + clear: both; + margin: 10px; + padding: 5px; + border: 1px solid #999; +} +*/ + +.ruby .normal {} +.ruby .comment { color: #005; font-style: italic; } +.ruby .keyword { color: #A00; font-weight: bold; } +.ruby .method { color: #077; } +.ruby .class { color: #074; } +.ruby .module { color: #050; } +.ruby .punct { color: #447; font-weight: bold; } +.ruby .symbol { color: #099; } +.ruby .string { color: #944; background: #FFE; } +.ruby .char { color: #F07; } +.ruby .ident { color: #004; } +.ruby .constant { color: #07F; } +.ruby .regex { color: #B66; background: #FEF; } +.ruby .number { color: #F99; } +.ruby .attribute { color: #7BB; } +.ruby .global { color: #7FB; } +.ruby .expr { color: #227; } +.ruby .escape { color: #277; } diff --git a/lib/chef_server/views/cookbook_templates/index.html.haml b/chef-server/lib/views/cookbook_templates/index.html.haml index 307aefd812..307aefd812 100644 --- a/lib/chef_server/views/cookbook_templates/index.html.haml +++ b/chef-server/lib/views/cookbook_templates/index.html.haml diff --git a/chef-server/lib/views/cookbooks/_attribute_file.html.haml b/chef-server/lib/views/cookbooks/_attribute_file.html.haml new file mode 100644 index 0000000000..eb91921bf0 --- /dev/null +++ b/chef-server/lib/views/cookbooks/_attribute_file.html.haml @@ -0,0 +1,2 @@ +%h3= name +%pre= contents
\ No newline at end of file diff --git a/chef-server/lib/views/cookbooks/_syntax_highlight.html.haml b/chef-server/lib/views/cookbooks/_syntax_highlight.html.haml new file mode 100644 index 0000000000..1f769d05f1 --- /dev/null +++ b/chef-server/lib/views/cookbooks/_syntax_highlight.html.haml @@ -0,0 +1,2 @@ +%h3= name +%div.ruby= syntax_highlight(contents)
\ No newline at end of file diff --git a/lib/chef_server/views/cookbooks/attribute_files.html.haml b/chef-server/lib/views/cookbooks/attribute_files.html.haml index 56fdcf7bee..56fdcf7bee 100644 --- a/lib/chef_server/views/cookbooks/attribute_files.html.haml +++ b/chef-server/lib/views/cookbooks/attribute_files.html.haml diff --git a/lib/chef_server/views/cookbooks/index.html.haml b/chef-server/lib/views/cookbooks/index.html.haml index 008f74765c..008f74765c 100644 --- a/lib/chef_server/views/cookbooks/index.html.haml +++ b/chef-server/lib/views/cookbooks/index.html.haml diff --git a/chef-server/lib/views/cookbooks/show.html.haml b/chef-server/lib/views/cookbooks/show.html.haml new file mode 100644 index 0000000000..1c409a3327 --- /dev/null +++ b/chef-server/lib/views/cookbooks/show.html.haml @@ -0,0 +1,29 @@ +%h1= "Cookbook #{h @cookbook.name}" +.cookbook +- if @cookbook.lib_files.length > 0 + %h2 Library Files + - @cookbook.lib_files.each do |f| + = partial(:syntax_highlight, :name => File.basename(f), :contents => f) + +- if @cookbook.attribute_files.length > 0 + %h2 Attribute Files + - @cookbook.attribute_files.each do |f| + = partial(:syntax_highlight, :name => File.basename(f), :contents => f) + +- if @cookbook.definition_files.length > 0 + %h2 Definition Files + - @cookbook.definition_files.each do |f| + = partial(:syntax_highlight, :name => File.basename(f), :contents => f) + +- if @cookbook.recipe_files.length > 0 + %h2 Recipe Files + - @cookbook.recipe_files.each do |f| + = partial(:syntax_highlight, :name => File.basename(f), :contents => f) + +- if @cookbook.template_files.length > 0 + %h2 Template Files + - @cookbook.template_files.each do |f| + %h3= name + %div= syntax_highlight(contents) + = partial(:syntax_highlight, :name => File.basename(f), :contents => f) +
\ No newline at end of file diff --git a/lib/chef_server/views/exceptions/bad_request.json.erb b/chef-server/lib/views/exceptions/bad_request.json.erb index f266cf99b9..f266cf99b9 100644 --- a/lib/chef_server/views/exceptions/bad_request.json.erb +++ b/chef-server/lib/views/exceptions/bad_request.json.erb diff --git a/lib/chef_server/views/exceptions/internal_server_error.html.erb b/chef-server/lib/views/exceptions/internal_server_error.html.erb index aadbfad350..aadbfad350 100644 --- a/lib/chef_server/views/exceptions/internal_server_error.html.erb +++ b/chef-server/lib/views/exceptions/internal_server_error.html.erb diff --git a/lib/chef_server/views/exceptions/not_acceptable.html.erb b/chef-server/lib/views/exceptions/not_acceptable.html.erb index f632712bb2..f632712bb2 100644 --- a/lib/chef_server/views/exceptions/not_acceptable.html.erb +++ b/chef-server/lib/views/exceptions/not_acceptable.html.erb diff --git a/lib/chef_server/views/exceptions/not_found.html.erb b/chef-server/lib/views/exceptions/not_found.html.erb index 388c72c31d..388c72c31d 100644 --- a/lib/chef_server/views/exceptions/not_found.html.erb +++ b/chef-server/lib/views/exceptions/not_found.html.erb diff --git a/lib/chef_server/views/layout/application.html.haml b/chef-server/lib/views/layout/application.html.haml index 8e84c09006..2be4097d29 100644 --- a/lib/chef_server/views/layout/application.html.haml +++ b/chef-server/lib/views/layout/application.html.haml @@ -7,7 +7,7 @@ %link{:rel => "stylesheet", :href => "/stylesheets/master.css", :type => "text/css", :media => "screen", :charset => "utf-8" } %body .header - %a{:href => url(:search) } Search + %a{:href => url(:searches) } Search | %a{:href => url(:nodes) } Nodes | diff --git a/lib/chef_server/views/nodes/_action.html.haml b/chef-server/lib/views/nodes/_action.html.haml index 8adb39338d..8adb39338d 100644 --- a/lib/chef_server/views/nodes/_action.html.haml +++ b/chef-server/lib/views/nodes/_action.html.haml diff --git a/lib/chef_server/views/nodes/_node.html.haml b/chef-server/lib/views/nodes/_node.html.haml index 7dce36488f..24b1f2816b 100644 --- a/lib/chef_server/views/nodes/_node.html.haml +++ b/chef-server/lib/views/nodes/_node.html.haml @@ -1,8 +1,6 @@ .node %h1 = "Node #{h node.name}" - %h2 Actions - %a{ :href => url(:compile_node, { :id => node_escape(node.name) }) } Compile Node %h2 Recipes %ol = recipe_list(node) diff --git a/lib/chef_server/views/nodes/_resource.html.haml b/chef-server/lib/views/nodes/_resource.html.haml index 7b9776b816..7b9776b816 100644 --- a/lib/chef_server/views/nodes/_resource.html.haml +++ b/chef-server/lib/views/nodes/_resource.html.haml diff --git a/lib/chef_server/views/nodes/compile.html.haml b/chef-server/lib/views/nodes/compile.html.haml index 5656447ea8..5656447ea8 100644 --- a/lib/chef_server/views/nodes/compile.html.haml +++ b/chef-server/lib/views/nodes/compile.html.haml diff --git a/lib/chef_server/views/nodes/index.html.haml b/chef-server/lib/views/nodes/index.html.haml index 667e1c7317..667e1c7317 100644 --- a/lib/chef_server/views/nodes/index.html.haml +++ b/chef-server/lib/views/nodes/index.html.haml diff --git a/lib/chef_server/views/nodes/show.html.haml b/chef-server/lib/views/nodes/show.html.haml index 94708af6d3..94708af6d3 100644 --- a/lib/chef_server/views/nodes/show.html.haml +++ b/chef-server/lib/views/nodes/show.html.haml diff --git a/lib/chef_server/views/openid_consumer/index.html.haml b/chef-server/lib/views/openid_consumer/index.html.haml index 576ef8d787..576ef8d787 100644 --- a/lib/chef_server/views/openid_consumer/index.html.haml +++ b/chef-server/lib/views/openid_consumer/index.html.haml diff --git a/lib/chef_server/views/openid_consumer/start.html.haml b/chef-server/lib/views/openid_consumer/start.html.haml index 75ed9a9257..75ed9a9257 100644 --- a/lib/chef_server/views/openid_consumer/start.html.haml +++ b/chef-server/lib/views/openid_consumer/start.html.haml diff --git a/lib/chef_server/views/openid_login/index.html.haml b/chef-server/lib/views/openid_login/index.html.haml index 17ae69017a..17ae69017a 100644 --- a/lib/chef_server/views/openid_login/index.html.haml +++ b/chef-server/lib/views/openid_login/index.html.haml diff --git a/lib/chef_server/views/openid_register/index.html.haml b/chef-server/lib/views/openid_register/index.html.haml index fe4798c59d..fe4798c59d 100644 --- a/lib/chef_server/views/openid_register/index.html.haml +++ b/chef-server/lib/views/openid_register/index.html.haml diff --git a/lib/chef_server/views/openid_register/show.html.haml b/chef-server/lib/views/openid_register/show.html.haml index cfd38e8963..cfd38e8963 100644 --- a/lib/chef_server/views/openid_register/show.html.haml +++ b/chef-server/lib/views/openid_register/show.html.haml diff --git a/lib/chef_server/views/openid_server/decide.html.haml b/chef-server/lib/views/openid_server/decide.html.haml index 8082a5068d..8082a5068d 100644 --- a/lib/chef_server/views/openid_server/decide.html.haml +++ b/chef-server/lib/views/openid_server/decide.html.haml diff --git a/lib/chef_server/views/search/_search_form.html.haml b/chef-server/lib/views/search/_search_form.html.haml index 99303e1714..99303e1714 100644 --- a/lib/chef_server/views/search/_search_form.html.haml +++ b/chef-server/lib/views/search/_search_form.html.haml diff --git a/lib/chef_server/views/search/index.html.haml b/chef-server/lib/views/search/index.html.haml index 742c1110b0..742c1110b0 100644 --- a/lib/chef_server/views/search/index.html.haml +++ b/chef-server/lib/views/search/index.html.haml diff --git a/lib/chef_server/views/search/show.html.haml b/chef-server/lib/views/search/show.html.haml index 5380a7477a..8620326a51 100644 --- a/lib/chef_server/views/search/show.html.haml +++ b/chef-server/lib/views/search/show.html.haml @@ -7,7 +7,7 @@ .search_result %h3= "#{h result[:index_name]} (#{h result[:id]})" %table - - result.each do |k, v| + - result.sort { |a,b| a[0] <=> b[0] }.each do |k, v| %tr.attr_group %td.attr_name= k %td.attr_value= v.kind_of?(Array) ? v.join(",") : v
\ No newline at end of file diff --git a/lib/chef_server/views/search_entries/index.html.haml b/chef-server/lib/views/search_entries/index.html.haml index 77d140242e..77d140242e 100644 --- a/lib/chef_server/views/search_entries/index.html.haml +++ b/chef-server/lib/views/search_entries/index.html.haml diff --git a/lib/chef_server/views/search_entries/show.html.haml b/chef-server/lib/views/search_entries/show.html.haml index 7ca34b32ab..7ca34b32ab 100644 --- a/lib/chef_server/views/search_entries/show.html.haml +++ b/chef-server/lib/views/search_entries/show.html.haml diff --git a/History.txt b/chef/History.txt index 02d903461e..02d903461e 100644 --- a/History.txt +++ b/chef/History.txt diff --git a/chef/LICENSE b/chef/LICENSE new file mode 100644 index 0000000000..11069edd79 --- /dev/null +++ b/chef/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/chef/Manifest.txt b/chef/Manifest.txt new file mode 100644 index 0000000000..79d961a738 --- /dev/null +++ b/chef/Manifest.txt @@ -0,0 +1,115 @@ +History.txt +LICENSE +Manifest.txt +README.txt +Rakefile +bin/chef-client +bin/chef-indexer +bin/chef-server +bin/chef-solo +config/chef-server.rb +examples/config.rb +examples/config/chef-solo.rb +examples/config/cookbooks/fakefile/attributes/first.rb +examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt +examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt +examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt +examples/config/cookbooks/fakefile/files/default/the_park.txt +examples/config/cookbooks/fakefile/recipes/default.rb +examples/config/cookbooks/fakefile/templates/default/monkey.erb +examples/config/cookbooks/tempfile/attributes/second.rb +examples/config/cookbooks/tempfile/recipes/default.rb +examples/config/nodes/adam.rb +examples/config/nodes/default.rb +examples/config/nodes/latte.rb +examples/log/stompserver.pid +examples/mrepo/Rakefile +examples/node.rb +examples/node.yml +examples/sample_definition.rb +examples/sample_recipe.rb +examples/search_index/_19.cfs +examples/search_index/_1k.cfs +examples/search_index/_1k_0.del +examples/search_index/_1l.cfs +examples/search_index/_c.cfs +examples/search_index/_c_0.del +examples/search_index/_n.cfs +examples/search_index/_y.cfs +examples/search_index/segments +examples/search_index/segments_1v +examples/search_syntax.rb +examples/user_index.pl +examples/user_index.rb +lib/chef.rb +lib/chef/client.rb +lib/chef/compile.rb +lib/chef/config.rb +lib/chef/cookbook.rb +lib/chef/cookbook_loader.rb +lib/chef/couchdb.rb +lib/chef/exceptions.rb +lib/chef/file_store.rb +lib/chef/log.rb +lib/chef/log/formatter.rb +lib/chef/mixin/check_helper.rb +lib/chef/mixin/checksum.rb +lib/chef/mixin/command.rb +lib/chef/mixin/from_file.rb +lib/chef/mixin/params_validate.rb +lib/chef/mixin/template.rb +lib/chef/node.rb +lib/chef/openid_registration.rb +lib/chef/platform.rb +lib/chef/provider.rb +lib/chef/provider/apt.rb +lib/chef/provider/directory.rb +lib/chef/provider/execute.rb +lib/chef/provider/file.rb +lib/chef/provider/link.rb +lib/chef/provider/package.rb +lib/chef/provider/remote_directory.rb +lib/chef/provider/remote_file.rb +lib/chef/provider/script.rb +lib/chef/provider/sysctl.rb +lib/chef/provider/template.rb +lib/chef/queue.rb +lib/chef/recipe.rb +lib/chef/resource.rb +lib/chef/resource/bash.rb +lib/chef/resource/csh.rb +lib/chef/resource/directory.rb +lib/chef/resource/execute.rb +lib/chef/resource/file.rb +lib/chef/resource/link.rb +lib/chef/resource/package.rb +lib/chef/resource/perl.rb +lib/chef/resource/python.rb +lib/chef/resource/remote_directory.rb +lib/chef/resource/remote_file.rb +lib/chef/resource/ruby.rb +lib/chef/resource/script.rb +lib/chef/resource/sysctl.rb +lib/chef/resource/template.rb +lib/chef/resource_collection.rb +lib/chef/resource_definition.rb +lib/chef/rest.rb +lib/chef/runner.rb +lib/chef/search.rb +lib/chef/search_index.rb +lib/chef_server/controllers/application.rb +lib/chef_server/controllers/cookbook_files.rb +lib/chef_server/controllers/cookbook_templates.rb +lib/chef_server/controllers/cookbooks.rb +lib/chef_server/controllers/exceptions.rb +lib/chef_server/controllers/nodes.rb +lib/chef_server/controllers/openid_consumer.rb +lib/chef_server/controllers/openid_register.rb +lib/chef_server/controllers/openid_server.rb +lib/chef_server/controllers/search.rb +lib/chef_server/controllers/search_entries.rb +lib/chef_server/helpers/global_helpers.rb +lib/chef_server/helpers/nodes_helper.rb +lib/chef_server/helpers/openid_server_helpers.rb +lib/chef_server/init.rb + diff --git a/chef/NOTICE b/chef/NOTICE new file mode 100644 index 0000000000..e2385f99a2 --- /dev/null +++ b/chef/NOTICE @@ -0,0 +1,11 @@ +Chef NOTICE +=========== + +Developed at HJK Solutions (http://www.hjksolutions.com). + +Contributors and Copyright holders: + + * Copyright 2008, Adam Jacob <adam@hjksolutions.com> + * Copyright 2008, Arjuna Christensen <aj@hjksolutions.com> + * Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com> +
\ No newline at end of file diff --git a/chef/README.txt b/chef/README.txt new file mode 100644 index 0000000000..70758161ae --- /dev/null +++ b/chef/README.txt @@ -0,0 +1,78 @@ += chef + +* http://oss.hjksolutions.com/chef + +== DESCRIPTION: + +Chef is a configuration management tool inspired by Puppet. + +I'm in ur netwerk, cookin up yer servers. :) + +== FEATURES/PROBLEMS: + + +== SYNOPSIS: + + +== REQUIREMENTS: + +RubyGems: + +* stomp +* stompserver +* ultraviolet +* +* facter +* ferret +* merb-core +* haml +* ruby-openid +* json + +External Servers: + +* stompserver (for easy stomp mq testing) +* CouchDB + +== INSTALL: + +Install all of the above. To fire up a develpment environment, do the following: + + * Start CouchDB with 'couchdb' + * Start stompserver with 'stompserver' + * Start chef-indexer with: + + ./bin/chef-indexer -l debug -c ./config/chef-server.rb + + * Start chef-server on port 4000 with: + + ./bin/chef-server + + * Start chef-server on port 4001 with: + + ./bin/chef-server -p 4001 + + * Test run chef with: + + sudo ./bin/chef-client -l debug -c ./examples/config/chef-solo.rb + +== LICENSE: + +Chef - A configuration management system + +Author:: Adam Jacob (<adam@hjksolutions.com>) +Copyright:: Copyright (c) 2008 HJK Solutions, LLC +License:: Apache License, Version 2.0 + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + diff --git a/chef/Rakefile b/chef/Rakefile new file mode 100644 index 0000000000..5343e66bcf --- /dev/null +++ b/chef/Rakefile @@ -0,0 +1,48 @@ +# -*- ruby -*- +require 'rubygems' +require 'rake/gempackagetask' +require './lib/chef.rb' +require './tasks/rspec.rb' + +GEM = "chef" +VERSION = "0.0.1" +AUTHOR = "Adam Jacob" +EMAIL = "adam@hjksolutions.com" +HOMEPAGE = "http://hjksolutions.com" +SUMMARY = "A configuration management system." + +spec = Gem::Specification.new do |s| + s.name = GEM + s.version = VERSION + s.platform = Gem::Platform::RUBY + s.has_rdoc = true + s.extra_rdoc_files = ["README.txt", "LICENSE", 'NOTICE'] + s.summary = SUMMARY + s.description = s.summary + s.author = AUTHOR + s.email = EMAIL + s.homepage = HOMEPAGE + + # Uncomment this to add a dependency + s.add_dependency "facter" + s.add_dependency "ruby-openid" + s.add_dependency "json" + s.add_dependency "erubis" + s.add_dependency "extlib" + + s.bindir = "bin" + s.executables = %w( chef-client chef-solo ) + + s.require_path = 'lib' + s.files = %w(LICENSE README.txt Rakefile) + Dir.glob("{lib,specs,config,examples}/**/*") +end + +Rake::GemPackageTask.new(spec) do |pkg| + pkg.gem_spec = spec +end + +task :install => [:package] do + sh %{sudo gem install pkg/#{GEM}-#{VERSION} --no-rdoc --no-ri} +end + +# vim: syntax=Ruby diff --git a/bin/chef-solo b/chef/bin/chef-client index ecc06afb79..210309de7a 100755 --- a/bin/chef-solo +++ b/chef/bin/chef-client @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # -# ./chef-solo - Build a meal with chef, sans-server! +# ./chef-client - Build a meal with chef # # Author:: Adam Jacob (<adam@hjksolutions.com>) # Copyright:: Copyright (c) 2008 HJK Solutions, LLC @@ -18,29 +18,37 @@ # See the License for the specific language governing permissions and # limitations under the License. -$: << File.join(File.dirname(__FILE__), "..", "lib") - require 'optparse' -require 'chef' require 'rubygems' +require 'chef' require 'facter' +require 'json' config = { - :config_file => "/etc/chef/config.rb", + :config_file => "/etc/chef/client.rb", :log_level => :info, - :noop => false + :json_attribs => nil, + :noop => false, + :validation_token => nil } opts = OptionParser.new do |opts| opts.banner = "Usage: #{$0} [-d DIR|-r FILE] (options)" opts.on("-c CONFIG", "--config CONFIG", "The Chef Config file to use") do |c| config[:config_file] = c end + opts.on("-j JSON_ATTRIBS", "--json-attributes JSON_ATTRIBS", "Load attributes from a JSON file") do |j| + config[:json_attribs] = j + end opts.on("-n", "--noop", "Print what you would do, but don't actually do it.") do config[:noop] = true end opts.on_tail("-l LEVEL", "--loglevel LEVEL", "Set the log level (debug, info, warn, error, fatal)") do |l| config[:log_level] = l.to_sym end + + opts.on_tail("-t TOKEN", "--token TOKEN", "Set the openid validation token") do |t| + config[:validation_token] = t + end opts.on_tail("-h", "--help", "Show this message") do puts opts exit @@ -51,28 +59,26 @@ opts.parse!(ARGV) unless File.exists?(config[:config_file]) && File.readable?(config[:config_file]) puts "I cannot find or read the config file: #{config[:config_file]}" puts opts - exit + exit 1 end +if config[:json_attribs] + unless File.exists?(config[:json_attribs]) + puts "I cannot find #{config[:json_attribs]}" + exit 2 + end + config[:json_attribs] = JSON.parse(IO.read(config[:json_attribs])) +end + + + # Load our config file Chef::Config.from_file(config[:config_file]) if config[:log_level] Chef::Log.level(config[:log_level].to_sym) end -# Find out our own hostname. -node_name = Facter["fqdn"].value -node_name ||= Facter["hostname"].value - -# Grab a Chef::Compile object -compile = Chef::Compile.new() - -# Load our Node, and then add all the Facter facts as attributes -compile.load_node(node_name) -Facter.each do |field, value| - compile.node[field.to_sym] = value -end -compile.load_definitions -compile.load_recipes -cr = Chef::Runner.new(compile.node, compile.collection) -cr.converge +c = Chef::Client.new +c.json_attribs = config[:json_attribs] +c.validation_token = config[:validation_token] +c.run diff --git a/bin/chef-client b/chef/bin/chef-solo index 7be305f5e6..3e08045a30 100755 --- a/bin/chef-client +++ b/chef/bin/chef-solo @@ -27,7 +27,7 @@ require 'rubygems' require 'facter' config = { - :config_file => "/etc/chef/config.rb", + :config_file => "/etc/chef/client.rb", :log_level => :info, :noop => false } @@ -62,4 +62,4 @@ if config[:log_level] end c = Chef::Client.new -c.run +c.run_solo
\ No newline at end of file diff --git a/config/chef-server.rb b/chef/config/server.rb index 74c12df403..74c12df403 100644 --- a/config/chef-server.rb +++ b/chef/config/server.rb diff --git a/docs/design/HighLevel.graffle b/chef/docs/design/HighLevel.graffle Binary files differindex e3a5aec187..e3a5aec187 100644 --- a/docs/design/HighLevel.graffle +++ b/chef/docs/design/HighLevel.graffle diff --git a/docs/recipe.rb b/chef/docs/recipe.rb index b132ff42ea..b132ff42ea 100644 --- a/docs/recipe.rb +++ b/chef/docs/recipe.rb diff --git a/examples/config.rb b/chef/examples/config.rb index 171554c416..171554c416 100644 --- a/examples/config.rb +++ b/chef/examples/config.rb diff --git a/examples/config/chef-solo.rb b/chef/examples/config/chef-solo.rb index 3445a99af7..2a85253b37 100644 --- a/examples/config/chef-solo.rb +++ b/chef/examples/config/chef-solo.rb @@ -6,5 +6,6 @@ node_path File.join(File.dirname(__FILE__), "nodes") search_index_path File.join(File.dirname(__FILE__), "..", "search_index") log_level :info file_store_path "/tmp/chef" +file_cache_path "/tmp/chef/cache" Chef::Log::Formatter.show_time = false diff --git a/examples/config/cookbooks/fakefile/attributes/first.rb b/chef/examples/config/cookbooks/fakefile/attributes/first.rb index e34a60b280..927dafe967 100644 --- a/examples/config/cookbooks/fakefile/attributes/first.rb +++ b/chef/examples/config/cookbooks/fakefile/attributes/first.rb @@ -1,2 +1,2 @@ Chef::Log.debug("You are the first of fakefile's attributes") -friends("you said we wuz visiting em")
\ No newline at end of file +friends("you said we wuz visiting em")
\ No newline at end of file diff --git a/chef/examples/config/cookbooks/fakefile/definitions/test.rb b/chef/examples/config/cookbooks/fakefile/definitions/test.rb new file mode 100644 index 0000000000..ce32293943 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/definitions/test.rb @@ -0,0 +1,13 @@ +define :monkey, :eats => "bananna" do + file "/tmp/monkeynews-#{params[:name]}" do + owner "root" + mode 0644 + action :create + end + + file "/tmp/monkeynews-#{params[:name]}-second-#{params[:eats]}" do + owner "root" + mode 0644 + notifies :touch, resources(:file => "/tmp/monkeynews-#{params[:name]}"), :immediately + end +end
\ No newline at end of file diff --git a/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt index 9664cb3e15..9664cb3e15 100644 --- a/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt +++ b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt diff --git a/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt index 68a3bf17e4..68a3bf17e4 100644 --- a/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt +++ b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt diff --git a/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt index d4d8511934..d4d8511934 100644 --- a/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt +++ b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt diff --git a/examples/config/cookbooks/fakefile/files/default/the_park.txt b/chef/examples/config/cookbooks/fakefile/files/default/the_park.txt index c71308a6ca..c71308a6ca 100644 --- a/examples/config/cookbooks/fakefile/files/default/the_park.txt +++ b/chef/examples/config/cookbooks/fakefile/files/default/the_park.txt diff --git a/chef/examples/config/cookbooks/fakefile/libraries/test.rb b/chef/examples/config/cookbooks/fakefile/libraries/test.rb new file mode 100644 index 0000000000..5a39a18aec --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/libraries/test.rb @@ -0,0 +1,7 @@ +class Chef + class Recipe + def bork + Chef::Log.debug("Bork bork bork") + end + end +end
\ No newline at end of file diff --git a/examples/config/cookbooks/fakefile/recipes/default.rb b/chef/examples/config/cookbooks/fakefile/recipes/default.rb index d71698fa88..709e51b6e3 100644 --- a/examples/config/cookbooks/fakefile/recipes/default.rb +++ b/chef/examples/config/cookbooks/fakefile/recipes/default.rb @@ -1,3 +1,5 @@ +bork + execute "write-foolio" do command <<-EOH echo 'monkeypants #{node[:ipaddress]} #{node[:friends]}' > /tmp/foolio @@ -21,27 +23,34 @@ print "Woot!\n"; } end -package "emacs" +unless @node[:operatingsystem] == "Darwin" + package "emacs" -package "remove-emacs" do - package_name "emacs" - action :remove -end + package "emacs" do + action :remove + end + + package "emacs" do + version "22.1-0ubuntu10" + action :install + end + + package "emacs" do + action :upgrade + end -package "install-old-emacs" do - package_name "emacs" - version "22.1-0ubuntu10" - action :install + package "emacs" do + action :purge + end end -package "upgrade-emacs" do - package_name "emacs" - action :upgrade +package "ruby-djbdns" do + action [ :install, :remove, :upgrade, :purge ] + provider Chef::Provider::Package::Rubygems end -package "purge-emacs" do - package_name "emacs" - action :purge +gem_package "ruby-djbdns" do + action [ :install, :remove, :upgrade, :purge ] end file "/tmp/foo" do @@ -77,8 +86,8 @@ template "/tmp/foo-template" do :el_che => 'rhymefest', :white => { :stripes => "are the best", - :at => "the sleazy rock thing" - }, + :at => "the sleazy rock thing", + } }) end @@ -102,13 +111,42 @@ directory "/tmp/home" do end search(:user, "*") do |u| - directory "/tmp/home/#{u[:name]}" do - if u[:name] == "nobody" && @node[:operatingsystem] == "Darwin" + directory "/tmp/home/#{u['name']}" do + if u['name'] == "nobody" && @node[:operatingsystem] == "Darwin" owner "root" else - owner "#{u[:name]}" + owner "#{u['name']}" end mode 0755 action :create end end + +monkey "snoopy" do + eats "vegetables" +end + +monkey "snack" + +# user "katie" do +# uid 9999 +# gid 100 +# home "/tmp/home/katie" +# shell "/bin/bash" +# comment "Katie Bethell" +# action :create +# end +# +# user "katie" do +# gid 101 +# action :modify +# end +# +# user "katie" do +# shell "/home/katie" +# action :manage +# end +# +# user "katie" do +# action [ :lock, :unlock, :remove ] +# end diff --git a/examples/config/cookbooks/fakefile/templates/default/monkey.erb b/chef/examples/config/cookbooks/fakefile/templates/default/monkey.erb index ad8d9080bf..29c2639381 100644 --- a/examples/config/cookbooks/fakefile/templates/default/monkey.erb +++ b/chef/examples/config/cookbooks/fakefile/templates/default/monkey.erb @@ -2,4 +2,4 @@ This is a <%= @one %> with <%= @el_che %> It was rendered on a system with the ipaddress of <%= @node[:ipaddress] %> -But it's all about the conquest, with <%= @node[:fqdn ] %>
\ No newline at end of file +But it's all about the conquest, with <%= @node[:fqdn ] %> diff --git a/examples/config/cookbooks/rubygems_server/attributes/first.rb b/chef/examples/config/cookbooks/rubygems_server/attributes/first.rb index d1b7bd6a23..d1b7bd6a23 100644 --- a/examples/config/cookbooks/rubygems_server/attributes/first.rb +++ b/chef/examples/config/cookbooks/rubygems_server/attributes/first.rb diff --git a/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem Binary files differindex d3eafbca10..d3eafbca10 100644 --- a/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem +++ b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem diff --git a/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem Binary files differindex e9bc3c2276..e9bc3c2276 100644 --- a/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem +++ b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem diff --git a/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem Binary files differindex b11cbe00cc..b11cbe00cc 100644 --- a/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem +++ b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem diff --git a/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem Binary files differindex 545f850a71..545f850a71 100644 --- a/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem +++ b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem diff --git a/examples/config/cookbooks/rubygems_server/recipes/default.rb b/chef/examples/config/cookbooks/rubygems_server/recipes/default.rb index 6b60456094..6b60456094 100644 --- a/examples/config/cookbooks/rubygems_server/recipes/default.rb +++ b/chef/examples/config/cookbooks/rubygems_server/recipes/default.rb diff --git a/examples/config/cookbooks/servicetest/recipes/default.rb b/chef/examples/config/cookbooks/servicetest/recipes/default.rb index 812b48e19d..812b48e19d 100644 --- a/examples/config/cookbooks/servicetest/recipes/default.rb +++ b/chef/examples/config/cookbooks/servicetest/recipes/default.rb diff --git a/examples/config/cookbooks/tempfile/attributes/second.rb b/chef/examples/config/cookbooks/tempfile/attributes/second.rb index df791b8429..df791b8429 100644 --- a/examples/config/cookbooks/tempfile/attributes/second.rb +++ b/chef/examples/config/cookbooks/tempfile/attributes/second.rb diff --git a/examples/config/cookbooks/tempfile/recipes/default.rb b/chef/examples/config/cookbooks/tempfile/recipes/default.rb index 1774cbcc3c..b4fa86ac32 100644 --- a/examples/config/cookbooks/tempfile/recipes/default.rb +++ b/chef/examples/config/cookbooks/tempfile/recipes/default.rb @@ -4,6 +4,10 @@ file "/tmp/glen" do action "create" end +file "/tmp/metallica" do + action [ :create, :touch, :delete ] +end + directory "/tmp/marginal" do owner "adam" mode 0755 diff --git a/examples/config/nodes/adam.rb b/chef/examples/config/nodes/adam.rb index c3e8e4bc16..c3e8e4bc16 100644 --- a/examples/config/nodes/adam.rb +++ b/chef/examples/config/nodes/adam.rb diff --git a/examples/config/nodes/default.rb b/chef/examples/config/nodes/default.rb index d365690c60..d365690c60 100644 --- a/examples/config/nodes/default.rb +++ b/chef/examples/config/nodes/default.rb diff --git a/examples/config/nodes/junglist.gen.nz.rb b/chef/examples/config/nodes/junglist.gen.nz.rb index 70ce7661b5..70ce7661b5 100644 --- a/examples/config/nodes/junglist.gen.nz.rb +++ b/chef/examples/config/nodes/junglist.gen.nz.rb diff --git a/examples/config/nodes/latte.rb b/chef/examples/config/nodes/latte.rb index 8987738151..8987738151 100644 --- a/examples/config/nodes/latte.rb +++ b/chef/examples/config/nodes/latte.rb diff --git a/examples/mrepo/Rakefile b/chef/examples/mrepo/Rakefile index e69de29bb2..e69de29bb2 100644 --- a/examples/mrepo/Rakefile +++ b/chef/examples/mrepo/Rakefile diff --git a/examples/node.rb b/chef/examples/node.rb index ef1e6a73fa..ef1e6a73fa 100644 --- a/examples/node.rb +++ b/chef/examples/node.rb diff --git a/examples/node.yml b/chef/examples/node.yml index d61a14875d..d61a14875d 100644 --- a/examples/node.yml +++ b/chef/examples/node.yml diff --git a/examples/sample_definition.rb b/chef/examples/sample_definition.rb index 77ce8916e5..f536369290 100644 --- a/examples/sample_definition.rb +++ b/chef/examples/sample_definition.rb @@ -56,8 +56,7 @@ define :runit_service, :directory => "/etc/sv", :downif => "/bin/false", :templa end service "#{param[:name]}" do - has_restart true - has_status true + supports :status => true, :restart => true end template_file "#{param[:directory]}/#{param[:name]}/log/run" do diff --git a/examples/sample_recipe.rb b/chef/examples/sample_recipe.rb index 6abb31bfcd..6abb31bfcd 100644 --- a/examples/sample_recipe.rb +++ b/chef/examples/sample_recipe.rb diff --git a/chef/examples/search_index/segments b/chef/examples/search_index/segments Binary files differnew file mode 100644 index 0000000000..01d633b27e --- /dev/null +++ b/chef/examples/search_index/segments diff --git a/chef/examples/search_index/segments_0 b/chef/examples/search_index/segments_0 Binary files differnew file mode 100644 index 0000000000..b642403384 --- /dev/null +++ b/chef/examples/search_index/segments_0 diff --git a/examples/search_syntax.rb b/chef/examples/search_syntax.rb index 4be57b7802..4be57b7802 100644 --- a/examples/search_syntax.rb +++ b/chef/examples/search_syntax.rb diff --git a/examples/user_index.pl b/chef/examples/user_index.pl index e78a8125f4..e78a8125f4 100755 --- a/examples/user_index.pl +++ b/chef/examples/user_index.pl diff --git a/examples/user_index.rb b/chef/examples/user_index.rb index 485cff81b8..485cff81b8 100755 --- a/examples/user_index.rb +++ b/chef/examples/user_index.rb diff --git a/lib/chef.rb b/chef/lib/chef.rb index ac7f43adef..ac7f43adef 100644 --- a/lib/chef.rb +++ b/chef/lib/chef.rb diff --git a/chef/lib/chef/client.rb b/chef/lib/chef/client.rb new file mode 100644 index 0000000000..4f962ed4c2 --- /dev/null +++ b/chef/lib/chef/client.rb @@ -0,0 +1,322 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require File.join(File.dirname(__FILE__), "mixin", "params_validate") +require File.join(File.dirname(__FILE__), "mixin", "generate_url") +require File.join(File.dirname(__FILE__), "mixin", "checksum") + +require 'rubygems' +require 'facter' + +class Chef + class Client + + include Chef::Mixin::GenerateURL + include Chef::Mixin::Checksum + + attr_accessor :node, :registration, :safe_name, :json_attribs, :validation_token + + # Creates a new Chef::Client. + def initialize() + @node = nil + @safe_name = nil + @validation_token = nil + @registration = nil + @json_attribs = nil + @rest = Chef::REST.new(Chef::Config[:registration_url]) + end + + # Do a full run for this Chef::Client. Calls: + # + # * build_node - Get the last known state, merge with local changes + # * register - Make sure we have an openid + # * authenticate - Authenticate with our openid + # * sync_definitions - Populate the local cache with all the definitions + # * sync_recipes - Populate the local cache with all the recipes + # * do_attribute_files - Populate the local cache with all attributes, and execute them + # * save_node - Store the new node configuration + # * converge - Bring this system up to date, based on the local cache + # * save_node - Store the node again, in case convergence altered future state + # + # === Returns + # true:: Always returns true. + def run + start_time = Time.now + Chef::Log.info("Starting Chef Run") + + build_node + register + authenticate + sync_library_files + sync_attribute_files + sync_definitions + sync_recipes + save_node + converge + save_node + + end_time = Time.now + Chef::Log.info("Chef Run complete in #{end_time - start_time} seconds") + true + end + + def run_solo + start_time = Time.now + Chef::Log.info("Starting Chef Solo Run") + + build_node + converge + + end_time = Time.now + Chef::Log.info("Chef Run complete in #{end_time - start_time} seconds") + true + end + + # Builds a new node object for this client. Starts with querying for the FQDN of the current + # host (unless it is supplied), then merges in the facts from Facter. + # + # === Parameters + # node_name<String>:: The name of the node to build - defaults to nil + # + # === Returns + # node:: Returns the created node object, also stored in @node + def build_node(node_name=nil) + node_name ||= Facter["fqdn"].value ? Facter["fqdn"].value : Facter["hostname"].value + @safe_name = node_name.gsub(/\./, '_') + Chef::Log.debug("Building node object for #{@safe_name}") + begin + @node = @rest.get_rest("nodes/#{@safe_name}") + rescue Net::HTTPServerException => e + unless e.message =~ /^404/ + raise e + end + end + unless @node + @node ||= Chef::Node.new + @node.name(node_name) + end + if @json_attribs + Chef::Log.debug("Adding JSON Attributes") + @json_attribs.each do |key, value| + if key == "recipes" + value.each do |recipe| + unless @node.recipes.detect { |r| r == recipe } + Chef::Log.debug("Adding recipe #{recipe}") + @node.recipes << recipe + end + end + else + Chef::Log.debug("JSON Attribute: #{key} - #{value.inspect}") + @node[key] = value + end + end + end + Facter.each do |field, value| + Chef::Log.debug("Facter Attribute: #{field} - #{value.inspect}") + @node[field] = value + end + @node + end + + # If this node has been registered before, this method will fetch the current registration + # data. + # + # If it has not, we register it by calling create_registration. + # + # === Returns + # true:: Always returns true + def register + Chef::Log.debug("Registering #{@safe_name} for an openid") + @registration = nil + begin + @registration = @rest.get_rest("registrations/#{@safe_name}") + rescue Net::HTTPServerException => e + unless e.message =~ /^404/ + raise e + end + end + + if @registration + reg = Chef::FileStore.load("registration", @safe_name) + @secret = reg["secret"] + else + create_registration + end + true + end + + # Generates a random secret, stores it in the Chef::Filestore with the "registration" key, + # and posts our nodes registration information to the server. + # + # === Returns + # true:: Always returns true + def create_registration + @secret = random_password(500) + Chef::FileStore.store("registration", @safe_name, { "secret" => @secret }) + @rest.post_rest("registrations", { :id => @safe_name, :password => @secret, :validation_token => @validation_token }) + true + end + + # Authenticates the node via OpenID. + # + # === Returns + # true:: Always returns true + def authenticate + Chef::Log.debug("Authenticating #{@safe_name} via openid") + response = @rest.post_rest('openid/consumer/start', { + "openid_identifier" => "#{Chef::Config[:openid_url]}/openid/server/node/#{@safe_name}", + "submit" => "Verify" + }) + @rest.post_rest( + "#{Chef::Config[:openid_url]}#{response["action"]}", + { "password" => @secret } + ) + end + + # Update the file caches for a given cache segment. Takes a segment name + # and a hash that matches one of the cookbooks/_attribute_files style + # remote file listings. + # + # === Parameters + # segment<String>:: The cache segment to update + # remote_list<Hash>:: A cookbooks/_attribute_files style remote file listing + def update_file_cache(segment, remote_list) + # We need the list of known good attribute files, so we can delete any that are + # just laying about. + file_canonical = Hash.new + + remote_list.each do |rf| + cache_file = File.join("cookbooks", rf['cookbook'], segment, rf['name']) + file_canonical[cache_file] = true + + current_checksum = nil + if Chef::FileCache.has_key?(cache_file) + current_checksum = checksum(Chef::FileCache.load(cache_file, false)) + end + + rf_url = generate_cookbook_url( + rf['name'], + rf['cookbook'], + segment, + @node, + current_checksum ? { 'checksum' => current_checksum } : nil + ) + Chef::Log.debug(rf_url) + + changed = true + begin + raw_file = @rest.get_rest(rf_url, true) + rescue Net::HTTPRetriableError => e + if e.response.kind_of?(Net::HTTPNotModified) + changed = false + Chef::Log.debug("Cache file #{cache_file} is unchanged") + else + raise e + end + end + + if changed + Chef::Log.info("Storing updated #{cache_file} in the cache.") + Chef::FileCache.move_to(raw_file.path, cache_file) + end + end + + Chef::FileCache.list.each do |cache_file| + if cache_file.match("cookbooks/.+?/#{segment}") + unless file_canonical[cache_file] + Chef::Log.info("Removing #{cache_file} from the cache; it is no longer on the server.") + Chef::FileCache.delete(cache_file) + end + end + end + + end + + # Gets all the attribute files included in all the cookbooks available on the server, + # and executes them. + # + # === Returns + # true:: Always returns true + def sync_attribute_files + Chef::Log.debug("Synchronizing attributes") + update_file_cache("attributes", @rest.get_rest('cookbooks/_attribute_files')) + true + end + + # Gets all the library files included in all the cookbooks available on the server, + # and loads them. + # + # === Returns + # true:: Always returns true + def sync_library_files + Chef::Log.debug("Synchronizing libraries") + update_file_cache("libraries", @rest.get_rest('cookbooks/_library_files')) + true + end + + def sync_definitions + Chef::Log.debug("Synchronizing definitions") + update_file_cache("definitions", @rest.get_rest('cookbooks/_definition_files')) + end + + def sync_recipes + Chef::Log.debug("Synchronizing attributes") + update_file_cache("recipes", @rest.get_rest('cookbooks/_recipe_files')) + end + + # Updates the current node configuration on the server. + # + # === Returns + # true:: Always returns true + def save_node + Chef::Log.debug("Saving the current state of node #{@safe_name}") + @node = @rest.put_rest("nodes/#{@safe_name}", @node) + true + end + + # Compiles the full list of recipes for the server, and passes it to an instance of + # Chef::Runner.converge. + # + # === Returns + # true:: Always returns true + def converge + Chef::Log.debug("Compiling recipes for node #{@safe_name}") + Chef::Config[:cookbook_path] = File.join(Chef::Config[:file_cache_path], "cookbooks") + compile = Chef::Compile.new() + compile.node = @node + compile.load_libraries + compile.load_attributes + compile.load_definitions + compile.load_recipes + + Chef::Log.debug("Converging node #{@safe_name}") + cr = Chef::Runner.new(@node, compile.collection) + cr.converge + true + end + + protected + # Generates a random password of "len" length. + def random_password(len) + chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a + newpass = "" + 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } + newpass + end + + end +end diff --git a/lib/chef/compile.rb b/chef/lib/chef/compile.rb index d5f38368ed..2f31566d7e 100644 --- a/lib/chef/compile.rb +++ b/chef/lib/chef/compile.rb @@ -41,6 +41,14 @@ class Chef @node end + # Load all the attributes, from every cookbook + def load_attributes() + @cookbook_loader.each do |cookbook| + cookbook.load_attributes(@node) + end + true + end + # Load all the definitions, from every cookbook, so they are available when we process # the recipes. # @@ -52,12 +60,23 @@ class Chef end end + # Load all the libraries, from every cookbook, so they are available when we process + # the recipes. + # + def load_libraries() + @cookbook_loader.each do |cookbook| + cookbook.load_libraries + end + true + end + # Load all the recipes specified in the node data (loaded via load_node, above.) # # The results are available via the collection accessor (which returns a Chef::ResourceCollection # object) def load_recipes @node.recipes.each do |recipe| + Chef::Log.debug("Loading Recipe #{recipe}") rmatch = recipe.match(/(.+?)::(.+)/) if rmatch cookbook = @cookbook_loader[rmatch[1]] diff --git a/lib/chef/config.rb b/chef/lib/chef/config.rb index ea1d8650f4..e79f02bf67 100644 --- a/lib/chef/config.rb +++ b/chef/lib/chef/config.rb @@ -35,6 +35,8 @@ class Chef @configuration = { :cookbook_path => [ "/etc/chef/site-cookbook", "/etc/chef/cookbook" ], + :validation_token => nil, + :merb_root => "/var/chef/merb", :node_path => "/etc/chef/node", :file_store_path => "/var/chef/store", :search_index_path => "/var/chef/search_index", @@ -49,9 +51,11 @@ class Chef :openid_url => "http://localhost:4001", :template_url => "http://localhost:4000", :remotefile_url => "http://localhost:4000", + :search_url => "http://localhost:4000", :couchdb_database => "chef", :openid_store_path => "/var/chef/openid/db", :openid_cstore_path => "/var/chef/openid/cstore", + :file_cache_path => "/var/chef/cache", :executable_path => ENV['PATH'] ? ENV['PATH'].split(File::PATH_SEPARATOR) : [] } diff --git a/lib/chef/cookbook.rb b/chef/lib/chef/cookbook.rb index 46fc956d83..b691a1e213 100644 --- a/lib/chef/cookbook.rb +++ b/chef/lib/chef/cookbook.rb @@ -18,7 +18,8 @@ class Chef class Cookbook - attr_accessor :attribute_files, :definition_files, :template_files, :remote_files, :name + attr_accessor :attribute_files, :definition_files, :template_files, :remote_files, + :lib_files, :name attr_reader :recipe_files def initialize(name) @@ -29,7 +30,14 @@ class Chef @remote_files = Array.new @recipe_files = Array.new @recipe_names = Hash.new - @loaded_attributes = false + @lib_files = Array.new + end + + def load_libraries + @lib_files.each do |file| + Chef::Log.debug("Loading cookbook #{name} library file: #{file}") + require file + end end def load_attributes(node) @@ -37,9 +45,9 @@ class Chef raise ArgumentError, "You must pass a Chef::Node to load_attributes!" end @attribute_files.each do |file| + Chef::Log.debug("Loading attributes from #{file}") node.from_file(file) end - @loaded_atributes = true node end @@ -98,9 +106,6 @@ class Chef raise ArgumentError, "Cannot find a recipe matching #{recipe_name} in cookbook #{@name}" end Chef::Log.debug("Found recipe #{recipe_name} in cookbook #{cookbook_name}") if Chef::Log.debug? - unless @loaded_attributes - load_attributes(node) - end recipe = Chef::Recipe.new(cookbook_name, recipe_name, node, collection, definitions, cookbook_loader) recipe.from_file(@recipe_files[@recipe_names[recipe_name]]) diff --git a/lib/chef/cookbook_loader.rb b/chef/lib/chef/cookbook_loader.rb index 6f6c8d8010..9b7649e75e 100644 --- a/lib/chef/cookbook_loader.rb +++ b/chef/lib/chef/cookbook_loader.rb @@ -41,6 +41,7 @@ class Chef :recipe_files => Array.new, :template_files => Array.new, :remote_files => Array.new, + :lib_files => Array.new } end ignore_regexes = load_ignore_file(File.join(cookbook, "ignore")) @@ -72,6 +73,12 @@ class Chef cookbook_settings[cookbook_name][:remote_files], cookbook_settings[cookbook_name][:ignore_regexes] ) + load_cascading_files( + File.join(cookbook, "libraries", "**", "*.rb"), + File.join(cookbook, "libraries"), + cookbook_settings[cookbook_name][:lib_files], + cookbook_settings[cookbook_name][:ignore_regexes] + ) end end cookbook_settings.each_key do |cookbook| @@ -81,6 +88,7 @@ class Chef @cookbook[cookbook].recipe_files = cookbook_settings[cookbook][:recipe_files] @cookbook[cookbook].template_files = cookbook_settings[cookbook][:template_files] @cookbook[cookbook].remote_files = cookbook_settings[cookbook][:remote_files] + @cookbook[cookbook].lib_files = cookbook_settings[cookbook][:lib_files] end end diff --git a/lib/chef/couchdb.rb b/chef/lib/chef/couchdb.rb index 8f73839d13..8f73839d13 100644 --- a/lib/chef/couchdb.rb +++ b/chef/lib/chef/couchdb.rb diff --git a/lib/chef/exceptions.rb b/chef/lib/chef/exceptions.rb index a70692b001..fa037a7f6c 100644 --- a/lib/chef/exceptions.rb +++ b/chef/lib/chef/exceptions.rb @@ -24,5 +24,7 @@ class Chef class SearchIndex < RuntimeError; end class Override < RuntimeError; end class UnsupportedAction < RuntimeError; end + class MissingLibrary < RuntimeError; end + class User < RuntimeError; end end end diff --git a/chef/lib/chef/file_cache.rb b/chef/lib/chef/file_cache.rb new file mode 100644 index 0000000000..ea9e17fbb7 --- /dev/null +++ b/chef/lib/chef/file_cache.rb @@ -0,0 +1,203 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require File.join(File.dirname(__FILE__), "mixin", "params_validate") +require File.join(File.dirname(__FILE__), "mixin", "create_path") +require 'json' + +class Chef + class FileCache + class << self + include Chef::Mixin::ParamsValidate + include Chef::Mixin::CreatePath + + # Write a file to the File Cache. + # + # === Parameters + # path<String>:: The path to the file you want to put in the cache - should + # be relative to Chef::Config[:file_cache_path] + # contents<String>:: A string with the contents you want written to the file + # + # === Returns + # true + def store(path, contents) + validate( + { + :path => path, + :contents => contents + }, + { + :path => { :kind_of => String }, + :contents => { :kind_of => String }, + } + ) + + file_path_array = File.split(path) + file_name = file_path_array.pop + cache_path = create_cache_path(File.join(file_path_array)) + io = File.open(File.join(cache_path, file_name), "w") + io.print(contents) + io.close + true + end + + # Move a file in to the cache. Useful with the REST raw file output. + # + # === Parameteres + # file<String>:: The path to the file you want in the cache + # path<String>:: The relative name you want the new file to use + def move_to(file, path) + validate( + { + :file => file, + :path => path + }, + { + :file => { :kind_of => String }, + :path => { :kind_of => String }, + } + ) + + file_path_array = File.split(path) + file_name = file_path_array.pop + if File.exists?(file) && File.writable?(file) + File.rename( + file, + File.join(create_cache_path(File.join(file_path_array), true), file_name) + ) + else + raise RuntimeError, "Cannot move #{file} to #{path}!" + end + end + + # Read a file from the File Cache + # + # === Parameters + # path<String>:: The path to the file you want to load - should + # be relative to Chef::Config[:file_cache_path] + # read<True/False>:: Whether to return the file contents, or the path. + # Defaults to true. + # + # === Returns + # String:: A string with the file contents. + # + # === Raises + # Chef::Exception::FileNotFound:: If it cannot find the file in the cache + def load(path, read=true) + validate( + { + :path => path + }, + { + :path => { :kind_of => String } + } + ) + cache_path = create_cache_path(path, false) + raise Chef::Exception::FileNotFound, "Cannot find #{cache_path} for #{path}!" unless File.exists?(cache_path) + if read + File.read(cache_path) + else + cache_path + end + end + + # Delete a file from the File Cache + # + # === Parameters + # path<String>:: The path to the file you want to delete - should + # be relative to Chef::Config[:file_cache_path] + # + # === Returns + # true + def delete(path) + validate( + { + :path => path + }, + { + :path => { :kind_of => String }, + } + ) + cache_path = create_cache_path(path, false) + if File.exists?(cache_path) + File.unlink(cache_path) + end + true + end + + # List all the files in the Cache + # + # === Returns + # Array:: An array of files in the cache, suitable for use with load, delete and store + def list() + keys = Array.new + Dir[File.join(Chef::Config[:file_cache_path], '**', '*')].each do |f| + if File.file?(f) + path = f.match("^#{Chef::Config[:file_cache_path]}\/(.+)")[1] + keys << path + end + end + keys + end + + # Whether or not this file exists in the Cache + # + # === Parameters + # path:: The path to the file you want to check - is relative + # to Chef::Config[:file_cache_path] + # + # === Returns + # True:: If the file exists + # False:: If it does not + def has_key?(path) + validate( + { + :path => path + }, + { + :path => { :kind_of => String }, + } + ) + full_path = create_cache_path(path, false) + if File.exists?(full_path) + true + else + false + end + end + + # Create a full path to a given file in the cache. By default, + # also creates the path if it does not exist. + # + # === Parameters + # path:: The path to create, relative to Chef::Config[:file_cache_path] + # create_if_missing:: True by default - whether to create the path if it does not exist + # + # === Returns + # String:: The fully expanded path + def create_cache_path(path, create_if_missing=true) + cache_dir = File.expand_path(File.join(Chef::Config[:file_cache_path], path)) + if create_if_missing + create_path(cache_dir) + else + cache_dir + end + end + + end + end +end
\ No newline at end of file diff --git a/lib/chef/file_store.rb b/chef/lib/chef/file_store.rb index 6f030784a1..6fe13e5ad6 100644 --- a/lib/chef/file_store.rb +++ b/chef/lib/chef/file_store.rb @@ -16,6 +16,7 @@ # limitations under the License. require File.join(File.dirname(__FILE__), "mixin", "params_validate") +require File.join(File.dirname(__FILE__), "mixin", "create_path") require 'digest/sha2' require 'json' @@ -23,6 +24,7 @@ class Chef class FileStore class << self include Chef::Mixin::ParamsValidate + include Chef::Mixin::CreatePath def store(obj_type, name, object) validate( @@ -125,12 +127,7 @@ class Chef shadigest[0,1], shadigest[1,3] ] - file_path.each_index do |i| - create_path = File.join(file_path[0, i + 1]) - Dir.mkdir(create_path) unless File.directory?(create_path) - end - file_path << key - File.join(*file_path) + File.join(create_path(file_path), key) end end diff --git a/lib/chef/log.rb b/chef/lib/chef/log.rb index ff98cc9dff..1f8ba2d8bf 100644 --- a/lib/chef/log.rb +++ b/chef/lib/chef/log.rb @@ -23,7 +23,7 @@ class Chef @logger = nil class << self - attr_reader :logger #:nodoc + attr_accessor :logger #:nodoc # Use Chef::Logger.init when you want to set up the logger manually. Arguments to this method # get passed directly to Logger.new, so check out the documentation for the standard Logger class diff --git a/lib/chef/log/formatter.rb b/chef/lib/chef/log/formatter.rb index 9f758178f5..9f758178f5 100644 --- a/lib/chef/log/formatter.rb +++ b/chef/lib/chef/log/formatter.rb diff --git a/lib/chef/mixin/check_helper.rb b/chef/lib/chef/mixin/check_helper.rb index 959b57cbb7..959b57cbb7 100644 --- a/lib/chef/mixin/check_helper.rb +++ b/chef/lib/chef/mixin/check_helper.rb diff --git a/lib/chef/mixin/checksum.rb b/chef/lib/chef/mixin/checksum.rb index 5a7eed4165..5a7eed4165 100644 --- a/lib/chef/mixin/checksum.rb +++ b/chef/lib/chef/mixin/checksum.rb diff --git a/lib/chef/mixin/command.rb b/chef/lib/chef/mixin/command.rb index 85e3c466eb..f42dbd35a5 100644 --- a/lib/chef/mixin/command.rb +++ b/chef/lib/chef/mixin/command.rb @@ -33,20 +33,37 @@ class Chef end end - if args.has_key?(:onlyif) - status = popen4(args[:onlyif]) { |p, i, o, e| } - if status.exitstatus != 0 - Chef::Log.debug("Skipping #{args[:command_string]} - onlyif #{args[:onlyif]} returned #{status.exitstatus}") - return false - end + if args.has_key?(:only_if) + if Proc === args[:only_if] + res = args[:only_if].call + unless res + Chef::Log.debug("Skipping #{args[:command_string]} - only_if #{args[:only_if]}") + return false + end + else + status = popen4(args[:only_if]) { |p, i, o, e| } + if status.exitstatus != 0 + Chef::Log.debug("Skipping #{args[:command_string]} - only_if #{args[:only_if]} returned #{status.exitstatus}") + return false + end + end end - if args.has_key?(:unless) - status = popen4(args[:unless]) { |p, i, o, e| } - if status.exitstatus == 0 - Chef::Log.debug("Skipping #{args[:command_string]} - unless #{args[:unless]} returned #{status.exitstatus}") - return false - end + if args.has_key?(:not_if) + if Proc === args[:not_if] + res = args[:not_if].call + unless res + Chef::Log.debug("Skipping #{args[:command_string]} - not_if #{args[:not_if]}") + return false + end + else + Chef::Log.debug("I should be running '#{args[:not_if]}'") + status = popen4(args[:not_if]) { |p, i, o, e| } + if status.exitstatus == 0 + Chef::Log.debug("Skipping #{args[:command_string]} - not_if #{args[:not_if]} returned #{status.exitstatus}") + return false + end + end end exec_processing_block = lambda do |pid, stdin, stdout, stderr| diff --git a/chef/lib/chef/mixin/create_path.rb b/chef/lib/chef/mixin/create_path.rb new file mode 100644 index 0000000000..dc9200eaf5 --- /dev/null +++ b/chef/lib/chef/mixin/create_path.rb @@ -0,0 +1,56 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Chef + module Mixin + module CreatePath + + # Creates a given path, including all directories that lead up to it. + # Like mkdir_p, but without the leaking. + # + # === Parameters + # file_path<String, Array>:: A string that represents the path to create, + # or an Array with the path-parts. + # + # === Returns + # The created file_path. + def create_path(file_path) + unless file_path.kind_of?(String) || file_path.kind_of?(Array) + raise ArgumentError, "file_path must be a string or an array!" + end + + if file_path.kind_of?(String) + file_path = File.expand_path(file_path).split(File::SEPARATOR) + file_path.shift if file_path[0] = '' + unless file_path[0].match("^#{File::SEPARATOR}") + file_path[0] = "#{File::SEPARATOR}#{file_path[0]}" + end + end + + file_path.each_index do |i| + create_path = File.join(file_path[0, i + 1]) + unless File.directory?(create_path) + Chef::Log.debug("Creating directory #{create_path}") + Dir.mkdir(create_path) + end + end + File.expand_path(File.join(file_path)) + end + + end + end +end
\ No newline at end of file diff --git a/lib/chef/mixin/from_file.rb b/chef/lib/chef/mixin/from_file.rb index 05f7fe8e8b..05f7fe8e8b 100644 --- a/lib/chef/mixin/from_file.rb +++ b/chef/lib/chef/mixin/from_file.rb diff --git a/chef/lib/chef/mixin/generate_url.rb b/chef/lib/chef/mixin/generate_url.rb new file mode 100644 index 0000000000..3eb8c4f70d --- /dev/null +++ b/chef/lib/chef/mixin/generate_url.rb @@ -0,0 +1,46 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class Chef + module Mixin + module GenerateURL + + def generate_cookbook_url(url, cookbook, type, node, args=nil) + new_url = nil + if url =~ /^http/ + new_url = url + else + new_url = "cookbooks/#{cookbook}/#{type}?" + new_url += "id=#{url}" + platform, version = Chef::Platform.find_platform_and_version(node) + if type == "files" || type == "templates" + new_url += "&platform=#{platform}&version=#{version}&fqdn=#{node[:fqdn]}" + end + if args + args.each do |key, value| + new_url += "&#{key}=#{value}" + end + end + end + + return new_url + end + + end + end +end diff --git a/lib/chef/mixin/params_validate.rb b/chef/lib/chef/mixin/params_validate.rb index 4d8ddb74c3..4d8ddb74c3 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/chef/lib/chef/mixin/params_validate.rb diff --git a/lib/chef/mixin/template.rb b/chef/lib/chef/mixin/template.rb index f3980922a1..f3980922a1 100644 --- a/lib/chef/mixin/template.rb +++ b/chef/lib/chef/mixin/template.rb diff --git a/lib/chef/node.rb b/chef/lib/chef/node.rb index 4eb72e1856..5b502fe141 100644 --- a/lib/chef/node.rb +++ b/chef/lib/chef/node.rb @@ -20,6 +20,7 @@ require File.join(File.dirname(__FILE__), "mixin", "check_helper") require File.join(File.dirname(__FILE__), "mixin", "params_validate") require File.join(File.dirname(__FILE__), "mixin", "from_file") +require 'extlib' require 'rubygems' require 'json' @@ -60,7 +61,7 @@ class Chef # Create a new Chef::Node object. def initialize() @name = nil - @attribute = Hash.new + @attribute = Mash.new @recipe_list = Array.new @couchdb_rev = nil @couchdb = Chef::CouchDB.new @@ -122,10 +123,17 @@ class Chef def []=(attrib, value) @attribute[attrib] = value end + + # Yield each key to the block + def each(&block) + @attribute.each_key do |k| + yield(k) + end + end # Iterates over each attribute, passing the attribute and value to the block. def each_attribute(&block) - @attribute.each do |k,v| + @attribute.sort {|a,b| a[0] <=> b[0] }.each do |k,v| yield(k, v) end end @@ -171,14 +179,14 @@ class Chef def to_index index_hash = { - :index_name => "node", - :id => "node_#{@name}", - :name => @name, + "index_name" => "node", + "id" => "node_#{@name}", + "name" => @name, } @attribute.each do |key, value| index_hash[key] = value end - index_hash[:recipe] = @recipe_list if @recipe_list.length > 0 + index_hash["recipe"] = @recipe_list if @recipe_list.length > 0 index_hash end diff --git a/lib/chef/openid_registration.rb b/chef/lib/chef/openid_registration.rb index 748c865097..748c865097 100644 --- a/lib/chef/openid_registration.rb +++ b/chef/lib/chef/openid_registration.rb diff --git a/lib/chef/platform.rb b/chef/lib/chef/platform.rb index c6c4a7580c..c7a7be1236 100644 --- a/lib/chef/platform.rb +++ b/chef/lib/chef/platform.rb @@ -26,13 +26,17 @@ class Chef :mac_os_x => {}, :ubuntu => { :default => { - :package => Chef::Provider::Apt, - :service => Chef::Provider::Debian, + :package => Chef::Provider::Package::Apt, + :service => Chef::Provider::Service::Debian, } }, :centos => {}, :redhat => {}, - :gentoo => {}, + :gentoo => { + :default => { + :package => Chef::Provider::Package::Portage + } + }, :solaris => {}, :default => { :file => Chef::Provider::File, @@ -44,12 +48,13 @@ class Chef :sysctl => Chef::Provider::Sysctl, :execute => Chef::Provider::Execute, :script => Chef::Provider::Script, - :service => Chef::Provider::Init, + :service => Chef::Provider::Service::Init, :perl => Chef::Provider::Script, :python => Chef::Provider::Script, :ruby => Chef::Provider::Script, :bash => Chef::Provider::Script, - :csh => Chef::Provider::Script + :csh => Chef::Provider::Script, + :user => Chef::Provider::User::Useradd, } } @@ -119,6 +124,8 @@ class Chef version = node[:macosx_productversion] elsif node.attribute?("operatingsystemversion") version = node[:operatingsystemversion] + elsif node.attribute?("operatingsystemrelease") + version = node[:operatingsystemrelease] end raise ArgumentError, "Cannot find a version for #{node}" unless version diff --git a/lib/chef/provider.rb b/chef/lib/chef/provider.rb index 3251693cb3..3251693cb3 100644 --- a/lib/chef/provider.rb +++ b/chef/lib/chef/provider.rb diff --git a/lib/chef/provider/directory.rb b/chef/lib/chef/provider/directory.rb index d042b6a8eb..87d25d7790 100644 --- a/lib/chef/provider/directory.rb +++ b/chef/lib/chef/provider/directory.rb @@ -50,7 +50,7 @@ class Chef end def action_delete - if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path) + if ::File.directory?(@new_resource.path) && ::File.writable?(@new_resource.path) if @new_resource.recursive == true Chef::Log.info("Deleting #{@new_resource} recursively at #{@new_resource.path}") FileUtils.rm_rf(@new_resource.path) diff --git a/lib/chef/provider/execute.rb b/chef/lib/chef/provider/execute.rb index 82603fe370..630de89e3e 100644 --- a/lib/chef/provider/execute.rb +++ b/chef/lib/chef/provider/execute.rb @@ -34,8 +34,8 @@ class Chef :command_string => @new_resource.to_s, } command_args[:creates] = @new_resource.creates if @new_resource.creates - command_args[:onlyif] = @new_resource.onlyif if @new_resource.onlyif - command_args[:unless] = @new_resource.unless if @new_resource.unless + command_args[:only_if] = @new_resource.only_if if @new_resource.only_if + command_args[:not_if] = @new_resource.not_if if @new_resource.not_if command_args[:timeout] = @new_resource.timeout if @new_resource.timeout command_args[:returns] = @new_resource.returns if @new_resource.returns command_args[:environment] = @new_resource.environment if @new_resource.environment diff --git a/lib/chef/provider/file.rb b/chef/lib/chef/provider/file.rb index bb3cf01fc5..bec2a2a307 100644 --- a/lib/chef/provider/file.rb +++ b/chef/lib/chef/provider/file.rb @@ -19,12 +19,13 @@ require 'etc' require 'fileutils' require File.join(File.dirname(__FILE__), "..", "mixin", "checksum") - +require File.join(File.dirname(__FILE__), "..", "mixin", "generate_url") class Chef class Provider class File < Chef::Provider include Chef::Mixin::Checksum + include Chef::Mixin::GenerateURL def load_current_resource @current_resource = Chef::Resource::File.new(@new_resource.name) @@ -117,6 +118,10 @@ class Chef set_mode if @new_resource.mode != nil end + def action_create_if_missing + action_create + end + def action_delete if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path) backup @@ -160,22 +165,7 @@ class Chef end def generate_url(url, type, args=nil) - new_url = nil - if url =~ /^http/ - new_url = url - else - new_url = "cookbooks/#{@new_resource.cookbook_name}/#{type}?" - new_url += "id=#{url}" - platform, version = Chef::Platform.find_platform_and_version(@node) - new_url += "&platform=#{platform}&version=#{version}&fqdn=#{@node[:fqdn]}" - if args - args.each do |key, value| - new_url += "&#{key}=#{value}" - end - end - end - - return new_url + generate_cookbook_url(url, @new_resource.cookbook_name, type, @node, args) end end diff --git a/lib/chef/provider/link.rb b/chef/lib/chef/provider/link.rb index 843a4ad009..843a4ad009 100644 --- a/lib/chef/provider/link.rb +++ b/chef/lib/chef/provider/link.rb diff --git a/lib/chef/provider/package.rb b/chef/lib/chef/provider/package.rb index 90eaa83cce..6bd447c470 100644 --- a/lib/chef/provider/package.rb +++ b/chef/lib/chef/provider/package.rb @@ -24,6 +24,8 @@ class Chef include Chef::Mixin::Command + attr_accessor :candidate_version + def initialize(node, new_resource) super(node, new_resource) @candidate_version = nil @@ -48,39 +50,52 @@ class Chef do_package = true end end - if do_package + Chef::Log.info("Installing #{@new_resource} version #{install_version}") status = install_package(@new_resource.package_name, install_version) if status @new_resource.updated = true - Chef::Log.info("Installed #{@new_resource} version #{install_version} successfully") end end end def action_upgrade if @current_resource.version != @candidate_version + Chef::Log.info("Upgrading #{@new_resource} version from #{@current_resource.version} to #{@candidate_version}") status = install_package(@new_resource.package_name, @candidate_version) if status @new_resource.updated = true - Chef::Log.info("Upgraded #{@new_resource} version from #{@current_resource.version} to #{@candidate_version} successfully") end end end - def action_remove - if @current_resource.version != nil + def action_remove + if should_remove_package(@current_resource.version, @new_resource.version) + Chef::Log.info("Removing #{@new_resource}") remove_package(@new_resource.package_name, @new_resource.version) @new_resource.updated = true - Chef::Log.info("Removed #{@new_resource} successfully") end end + def should_remove_package(current_version, new_version) + to_remove_package = false + if current_version != nil + if new_version != nil + if new_version == current_version + to_remove_package = true + end + else + to_remove_package = true + end + end + to_remove_package + end + def action_purge - if @current_resource.version != nil + if should_remove_package(@current_resource.version, @new_resource.version) + Chef::Log.info("Purging #{@new_resource}") purge_package(@new_resource.package_name, @new_resource.version) @new_resource.updated = true - Chef::Log.info("Purged #{@new_resource} successfully") end end diff --git a/chef/lib/chef/provider/package/apt.rb b/chef/lib/chef/provider/package/apt.rb new file mode 100644 index 0000000000..a2e9bd68a2 --- /dev/null +++ b/chef/lib/chef/provider/package/apt.rb @@ -0,0 +1,89 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "..", "package") +require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command") + +class Chef + class Provider + class Package + class Apt < Chef::Provider::Package + + def load_current_resource + @current_resource = Chef::Resource::Package.new(@new_resource.name) + @current_resource.package_name(@new_resource.package_name) + + status = popen4("apt-cache policy #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + case line + when /^\s{2}Installed: (.+)$/ + installed_version = $1 + if installed_version == '(none)' + @current_resource.version(nil) + else + @current_resource.version(installed_version) + end + when /^\s{2}Candidate: (.+)$/ + @candidate_version = $1 + end + end + end + + unless status.exitstatus == 0 + raise Chef::Exception::Package, "apt-cache failed - #{status.inspect}!" + end + + @current_resource + end + + def install_package(name, version) + run_command( + :command => "apt-get -q -y install #{name}=#{version}", + :environment => { + "DEBIAN_FRONTEND" => "noninteractive" + } + ) + end + + def upgrade_package(name, version) + install_package(name, version) + end + + def remove_package(name, version) + run_command( + :command => "apt-get -q -y remove #{@new_resource.package_name}", + :environment => { + "DEBIAN_FRONTEND" => "noninteractive" + } + ) + end + + def purge_package(name, version) + run_command( + :command => "apt-get -q -y purge #{@new_resource.package_name}", + :environment => { + "DEBIAN_FRONTEND" => "noninteractive" + } + ) + end + + end + end + end +end diff --git a/chef/lib/chef/provider/package/portage.rb b/chef/lib/chef/provider/package/portage.rb new file mode 100644 index 0000000000..8981a386bc --- /dev/null +++ b/chef/lib/chef/provider/package/portage.rb @@ -0,0 +1,93 @@ +# +# Author:: Ezra Zygmuntowicz (<ezra@engineyard.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "..", "package") +require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command") + +class Chef + class Provider + class Package + class Portage < Chef::Provider::Package + + def load_current_resource + @current_resource = Chef::Resource::Package.new(@new_resource.name) + @current_resource.package_name(@new_resource.package_name) + + status = popen4("emerge --color n --nospinner --search #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| + stdin.close + + available, installed = parse_emerge(@new_resource.package_name, stdout.read) + + if installed == "[ Not Installed ]" + @current_resource.version(nil) + else + @current_resource.version(installed) + end + @candidate_version = available + end + + unless status.exitstatus == 0 + raise Chef::Exception::Package, "emerge --search failed - #{status.inspect}!" + end + + @current_resource + end + + + def parse_emerge(package, txt) + available, installed, pkg = nil + txt.each do |line| + if line =~ /\*(.*)/ + pkg = $1.strip.split('/').last + end + if pkg == package + if line =~ /Latest version available: (.*)/ + available = $1 + elsif line =~ /Latest version installed: (.*)/ + installed = $1 + end + end + end + [available, installed] + end + + + def install_package(name, version) + run_command( + :command => "emerge -g --color n --nospinner --quiet =#{name}-#{version}" + ) + end + + def upgrade_package(name, version) + install_package(name, version) + end + + def remove_package(name, version) + run_command( + :command => "emerge --unmerge --color n --nospinner --quiet #{@new_resource.package_name}" + ) + end + + def purge_package(name, version) + remove_package(name, version) + end + + end + end + end +end
\ No newline at end of file diff --git a/chef/lib/chef/provider/package/rubygems.rb b/chef/lib/chef/provider/package/rubygems.rb new file mode 100644 index 0000000000..69459ffef4 --- /dev/null +++ b/chef/lib/chef/provider/package/rubygems.rb @@ -0,0 +1,116 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "..", "package") +require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command") + +class Chef + class Provider + class Package + class Rubygems < Chef::Provider::Package + + def gem_list_parse(line) + installed_versions = Array.new + if line.match("^#{@new_resource.package_name} \\((.+?)\\)$") + installed_versions = $1.split(/, /) + installed_versions + else + nil + end + end + + def load_current_resource + @current_resource = Chef::Resource::Package.new(@new_resource.name) + @current_resource.package_name(@new_resource.package_name) + @current_resource.version(nil) + + # First, we need to look up whether we have the local gem installed or not + status = popen4("gem list --local #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + installed_versions = gem_list_parse(line) + next unless installed_versions + # If the version we are asking for is installed, make that our current + # version. Otherwise, go ahead and use the highest one, which + # happens to come first in the array. + if installed_versions.detect { |v| v == @new_resource.version } + Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}") + @current_resource.version(@new_resource.version) + else + iv = installed_versions.first + Chef::Log.debug("#{@new_resource.package_name} at version #{iv}") + @current_resource.version(iv) + end + end + end + + unless status.exitstatus == 0 + raise Chef::Exception::Package, "gem list --local failed - #{status.inspect}!" + end + + status = popen4("gem list --remote #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + installed_versions = gem_list_parse(line) + next unless installed_versions + Chef::Log.debug("I have #{installed_versions.inspect}") + + if installed_versions.length >= 1 + Chef::Log.debug("Setting candidate version") + @candidate_version = installed_versions.first + end + end + end + + unless status.exitstatus == 0 + raise Chef::Exception::Package, "gem list --remote failed - #{status.inspect}!" + end + + @current_resource + end + + def install_package(name, version) + run_command( + :command => "gem install #{name} -q --no-rdoc --no-ri -v #{version}" + ) + end + + def upgrade_package(name, version) + install_package(name, version) + end + + def remove_package(name, version) + if version + run_command( + :command => "gem uninstall #{name} -q -v #{version}" + ) + else + run_command( + :command => "gem uninstall #{name} -q -a" + ) + end + end + + def purge_package(name, version) + remove_package(name, version) + end + + end + end + end +end diff --git a/lib/chef/provider/remote_directory.rb b/chef/lib/chef/provider/remote_directory.rb index 47d62b6308..f83e8e8a16 100644 --- a/lib/chef/provider/remote_directory.rb +++ b/chef/lib/chef/provider/remote_directory.rb @@ -32,6 +32,10 @@ class Chef do_recursive end + def action_create_if_missing + raise Chef::Exception::UnsupportedAction, "Remote Directories do not support create_if_missing." + end + def do_recursive Chef::Log.debug("Doing a recursive directory transfer for #{@new_resource}") diff --git a/lib/chef/provider/remote_file.rb b/chef/lib/chef/provider/remote_file.rb index cc0812346e..0e27bc5b7a 100644 --- a/lib/chef/provider/remote_file.rb +++ b/chef/lib/chef/provider/remote_file.rb @@ -29,6 +29,14 @@ class Chef Chef::Log.debug("Checking #{@new_resource} for changes") do_remote_file(@new_resource.source, @current_resource.path) end + + def action_create_if_missing + if ::File.exists?(@new_resource.path) + Chef::Log.debug("File #{@new_resource.path} exists, taking no action.") + else + action_create + end + end def do_remote_file(source, path) r = Chef::REST.new(Chef::Config[:remotefile_url]) diff --git a/lib/chef/provider/script.rb b/chef/lib/chef/provider/script.rb index 4669361142..4669361142 100644 --- a/lib/chef/provider/script.rb +++ b/chef/lib/chef/provider/script.rb diff --git a/lib/chef/provider/service.rb b/chef/lib/chef/provider/service.rb index 5ac53478e3..5ac53478e3 100644 --- a/lib/chef/provider/service.rb +++ b/chef/lib/chef/provider/service.rb diff --git a/lib/chef/provider/service/debian.rb b/chef/lib/chef/provider/service/debian.rb index 51597ff703..21f166ba6a 100644 --- a/lib/chef/provider/service/debian.rb +++ b/chef/lib/chef/provider/service/debian.rb @@ -22,40 +22,31 @@ require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command") class Chef class Provider - class Debian < Chef::Provider::Init - def load_current_resource - super + class Service + class Debian < Chef::Provider::Service::Init + def load_current_resource + super - status = popen4("update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr| - stdin.close - stdout.gets(nil) =~ /etc\/rc[\dS].d\/S|not installed/i ? @current_resource.enabled(true) : @current_resource.enabled(false) - end + status = popen4("update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr| + stdin.close + stdout.gets(nil) =~ /etc\/rc[\dS].d\/S|not installed/i ? @current_resource.enabled(true) : @current_resource.enabled(false) + end - unless status.exitstatus == 0 - raise Chef::Exception::Service, "update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}" - end - - @current_resource - end - - def enable_service(name) - run_command(:command => "update-rc.d #{name} defaults") - end - - def disable_service(name) - run_command(:command => "update-rc.d -f #{name} remove") - end + unless status.exitstatus == 0 + raise Chef::Exception::Service, "update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}" + end - def start_service(name) - super - end + @current_resource + end - def stop_service(name) - super - end + def enable_service(name) + run_command(:command => "update-rc.d #{name} defaults") + end - def restart_service(name) - super + def disable_service(name) + run_command(:command => "update-rc.d -f #{name} remove") + end + end end end diff --git a/chef/lib/chef/provider/service/init.rb b/chef/lib/chef/provider/service/init.rb new file mode 100644 index 0000000000..0ccfc232d8 --- /dev/null +++ b/chef/lib/chef/provider/service/init.rb @@ -0,0 +1,95 @@ +# +# Author:: AJ Christensen (<aj@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "..", "service") +require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command") + +class Chef + class Provider + class Service + class Init < Chef::Provider::Service + + def load_current_resource + @current_resource = Chef::Resource::Service.new(@new_resource.name) + @current_resource.service_name(@new_resource.service_name) + process_running = false + if @new_resource.supports[:status] + run_command(:command => "/etc/init.d/#{@current_resource.service_name} status") == 0 ? process_running = true : process_running = false + elsif @new_resource.status_command + run_command(:command => @new_resource.status_command) == 0 ? process_running = true : process_running = false + else + Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection") + if @new_resource.pattern == @new_resource.service_name + Chef::Log.debug("#{@new_resource} defaulting pattern to #{Regex.new(@new_resource.pattern)}") + elsif @node[:ps] == "" + raise Chef::Exception::Service, "#{@new_resource}: Facter could not determine how to call `ps` on your system (#{Facter["ps"].value})" + end + + process_pid = nil + status = popen4(@node[:ps]) do |pid, stdin, stdout, stderr| + stdin.close + r = Regexp.new(@new_resource.pattern) + Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table") + stdout.each_line do |line| + if r.match(line) + process_pid = line.sub(/^\s+/, '').split(/\s+/)[1] + end + end + end + unless status.exitstatus == 0 + raise Chef::Exception::Service, "Command #{@node[:ps]} failed" + else + process_pid ? process_running = true : process_running = false + Chef::Log.debug("#{@new_resource}: #{@node[:ps]} exited succesfully, process_running: #{process_running}") + end + end + @current_resource.running process_running + @current_resource + end + + def start_service(name) + if @new_resource.start_command + run_command(:command => @new_resource.start_command) + else + run_command(:command => "/etc/init.d/#{name} start") + end + end + + def stop_service(name) + if @new_resource.stop_command + run_command(:command => @new_resource.stop_command) + else + run_command(:command => "/etc/init.d/#{name} stop") + end + end + + def restart_service(name) + if @new_resource.supports[:restart] + run_command(:command => "/etc/init.d/#{name} restart") + elsif @new_resource.restart_command + run_command(:command => @new_resource.restart_command) + else + stop_service + start_service + end + end + + end + end + end +end diff --git a/lib/chef/provider/sysctl.rb b/chef/lib/chef/provider/sysctl.rb index 09b5942f5e..09b5942f5e 100644 --- a/lib/chef/provider/sysctl.rb +++ b/chef/lib/chef/provider/sysctl.rb diff --git a/lib/chef/provider/template.rb b/chef/lib/chef/provider/template.rb index 550a1388bf..7da947a69f 100644 --- a/lib/chef/provider/template.rb +++ b/chef/lib/chef/provider/template.rb @@ -64,6 +64,14 @@ class Chef set_mode if @new_resource.mode != nil end + def action_create_if_missing + if ::File.exists?(@new_resource.path) + Chef::Log.debug("File #{@new_resource.path} exists, taking no action.") + else + action_create + end + end + end end end
\ No newline at end of file diff --git a/chef/lib/chef/provider/user.rb b/chef/lib/chef/provider/user.rb new file mode 100644 index 0000000000..b03874d4f0 --- /dev/null +++ b/chef/lib/chef/provider/user.rb @@ -0,0 +1,179 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "..", "provider") +require File.join(File.dirname(__FILE__), "..", "mixin", "command") +require 'etc' + +class Chef + class Provider + class User < Chef::Provider + + include Chef::Mixin::Command + + attr_accessor :user_exists, :locked + + def initialize(node, new_resource) + super(node, new_resource) + @user_exists = true + @locked = nil + end + + def load_current_resource + @current_resource = Chef::Resource::User.new(@new_resource.name) + @current_resource.username(@new_resource.username) + + user_info = nil + begin + user_info = Etc.getpwnam(@new_resource.username) + rescue ArgumentError => e + @user_exists = false + Chef::Log.debug("User #{@new_resource.username} does not exist") + end + + if user_info + @current_resource.uid(user_info.uid) + @current_resource.gid(user_info.gid) + @current_resource.comment(user_info.gecos) + @current_resource.home(user_info.dir) + @current_resource.shell(user_info.shell) + + if @new_resource.password + begin + require 'shadow' + rescue Exception => e + Chef::Log.error("You must have ruby-shadow installed for password support!") + raise Chef::Exception::MissingLibrary, "You must have ruby-shadow installed for password support!" + end + shadow_info = Shadow::Passwd.getspnam(@new_resource.username) + @current_resource.password(shadow_info.sp_pwdp) + end + end + + @current_resource + end + + # Check to see if the user needs any changes + # + # === Returns + # <true>:: If a change is required + # <false>:: If the users are identical + def compare_user + change_required = false + change_required = true if @new_resource.uid != @current_resource.uid + change_required = true if @new_resource.gid != @current_resource.gid + change_required = true if @new_resource.comment != @current_resource.comment + change_required = true if @new_resource.home != @current_resource.home + change_required = true if @new_resource.shell != @current_resource.shell + change_required = true if @new_resource.password != @current_resource.password + change_required + end + + def action_create + case @user_exists + when false + create_user + Chef::Log.info("Created #{@new_resource}") + @new_resource.updated = true + else + if compare_user + manage_user + Chef::Log.info("Altered #{@new_resource}") + @new_resource.updated = true + end + end + end + + def action_remove + if @user_exists + remove_user + @new_resource.updated = true + Chef::Log.info("Removed #{@new_resource}") + end + end + + def action_manage + if @user_exists && compare_user + manage_user + @new_resource.updated = true + Chef::Log.info("Managed #{@new_resource}") + end + end + + def action_modify + if @user_exists && compare_user + manage_user + @new_resource.updated = true + Chef::Log.info("Modified #{@new_resource}") + else + raise Chef::Exception::User, "Cannot modify #{@new_resource} - user does not exist!" + end + end + + def check_lock + status = popen4("passwd -S #{@new_resource.username}") do |pid, stdin, stdout, stderr| + stdin.close + status_line = stdout.gets.split(' ') + case status_line[1] + when /^P/ + @locked = false + when /^N/ + @locked = false + when /^L/ + @locked = true + end + end + + unless status.exitstatus == 0 + raise Chef::Exception::User, "Cannot determine if #{@new_resource} is locked!" + end + + @locked + end + + def action_lock + if @user_exists + if check_lock() == false + lock_user + @new_resource.updated = true + Chef::Log.info("Locked #{@new_resource}") + else + Chef::Log.debug("No need to lock #{@new_resource}") + end + else + raise Chef::Exception::User, "Cannot lock #{@new_resource} - user does not exist!" + end + end + + def action_unlock + if @user_exists + if check_lock() == true + unlock_user + @new_resource.updated = true + Chef::Log.info("Unlocked #{@new_resource}") + else + Chef::Log.debug("No need to unlock #{@new_resource}") + end + else + raise Chef::Exception::User, "Cannot unlock #{@new_resource} - user does not exist!" + end + end + + end + end +end diff --git a/chef/lib/chef/provider/user/useradd.rb b/chef/lib/chef/provider/user/useradd.rb new file mode 100644 index 0000000000..96736a27a8 --- /dev/null +++ b/chef/lib/chef/provider/user/useradd.rb @@ -0,0 +1,88 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "..", "user") + +class Chef + class Provider + class User + class Useradd < Chef::Provider::User + def create_user + command = "useradd" + command << set_options + run_command(:command => command) + end + + def manage_user + command = "usermod" + command << set_options + run_command(:command => command) + end + + def remove_user + command = "userdel" + command << " -r" if @new_resource.supports[:manage_home] + command << " #{@new_resource.username}" + run_command(:command => command) + end + + def lock_user + run_command(:command => "usermod -L #{@new_resource.username}") + end + + def unlock_user + run_command(:command => "usermod -U #{@new_resource.username}") + end + + def set_options + opts = '' + + field_list = { + 'comment' => "-c", + 'home' => "-d", + 'gid' => "-g", + 'uid' => "-u", + 'shell' => "-s", + 'password' => "-p" + } + field_list.each do |field, option| + field_symbol = field.to_sym + if @current_resource.send(field_symbol) != @new_resource.send(field_symbol) + if @new_resource.send(field_symbol) + Chef::Log.debug("Setting #{@new_resource} #{field} to #{@new_resource.send(field_symbol)}") + opts << " #{option} '#{@new_resource.send(field_symbol)}'" + end + end + end + if @new_resource.supports[:manage_home] + Chef::Log.debug("Managing the home directory for #{@new_resource}") + case @node[:operatingsystem] + when "Fedora","RedHat","CentOS" + opts << " -M" + else + opts << " -m" + end + end + opts << " #{@new_resource.username}" + opts + end + + end + end + end +end
\ No newline at end of file diff --git a/lib/chef/queue.rb b/chef/lib/chef/queue.rb index 86eb7df257..86eb7df257 100644 --- a/lib/chef/queue.rb +++ b/chef/lib/chef/queue.rb diff --git a/lib/chef/recipe.rb b/chef/lib/chef/recipe.rb index d6b9afc474..d8baa10120 100644 --- a/lib/chef/recipe.rb +++ b/chef/lib/chef/recipe.rb @@ -50,10 +50,19 @@ class Chef end @params = Hash.new + + @@seen_recipes ||= Hash.new end def require_recipe(*args) args.flatten.each do |recipe| + if @@seen_recipes.has_key?(recipe) + Chef::Log.debug("I am not loading #{recipe}, because I have already seen it.") + next + end + Chef::Log.debug("#{@@seen_recipes.inspect}") + @@seen_recipes[recipe] = true + rmatch = recipe.match(/(.+?)::(.+)/) if rmatch cookbook = @cookbook_loader[rmatch[1]] @@ -70,8 +79,13 @@ class Chef end def search(type, query, &block) - s = Chef::Search.new - s.search(type, query, &block) + Chef::Log.debug("Searching #{type} index with #{query}") + r = Chef::REST.new(Chef::Config[:search_url]) + results = r.get_rest("search/#{type}?q=#{query}") + Chef::Log.debug("Searching #{type} index with #{query} returned #{results.length} entries") + results.each do |sr| + block.call(sr) + end end def method_missing(method_symbol, *args, &block) @@ -81,7 +95,7 @@ class Chef # to. if @definitions.has_key?(method_symbol) new_def = @definitions[method_symbol].dup - new_def.instance_eval(&block) + new_def.instance_eval(&block) if block new_recipe = Chef::Recipe.new(@cookbook_name, @recipe_name, @node, @collection, @definitions, @cookbook_loader) new_recipe.params = new_def.params new_recipe.params[:name] = args[0] diff --git a/lib/chef/resource.rb b/chef/lib/chef/resource.rb index e33b04061a..e22f8b21ef 100644 --- a/lib/chef/resource.rb +++ b/chef/lib/chef/resource.rb @@ -25,7 +25,7 @@ class Chef include Chef::Mixin::CheckHelper include Chef::Mixin::ParamsValidate - attr_accessor :actions, :params, :provider, :updated, :allowed_actions, :collection, :cookbook_name, :recipe_name, :supports + attr_accessor :actions, :params, :provider, :updated, :allowed_actions, :collection, :cookbook_name, :recipe_name attr_reader :resource_name, :source_line, :node def initialize(name, collection=nil, node=nil) @@ -49,15 +49,38 @@ class Chef @source_line = ::File.expand_path(@source_line) if @source_line end - def action(arg=nil) - arg = arg.to_sym if arg + def supports(args={}) + @supports = args + end + + def provider(arg=nil) set_or_return( - :action, + :provider, arg, - :equal_to => @allowed_actions + :kind_of => [ Class ] ) end + def action(arg=nil) + if arg + action_list = arg.kind_of?(Array) ? arg : [ arg ] + action_list = action_list.collect { |a| a.to_sym } + action_list.each do |action| + validate( + { + :action => action, + }, + { + :action => { :kind_of => Symbol, :equal_to => @allowed_actions }, + } + ) + end + @action = action_list + else + @action + end + end + def name(name=nil) set_if_args(@name, name) do raise ArgumentError, "name must be a string!" unless name.kind_of?(String) diff --git a/chef/lib/chef/resource/apt_package.rb b/chef/lib/chef/resource/apt_package.rb new file mode 100644 index 0000000000..58e8b14edc --- /dev/null +++ b/chef/lib/chef/resource/apt_package.rb @@ -0,0 +1,33 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "package") + +class Chef + class Resource + class AptPackage < Chef::Resource::Package + + def initialize(name, collection=nil, node=nil) + super(name, collection, node) + @resource_name = :apt_package + @provider = Chef::Provider::Package::Apt + end + + end + end +end
\ No newline at end of file diff --git a/lib/chef/resource/bash.rb b/chef/lib/chef/resource/bash.rb index 7af5f9756a..7af5f9756a 100644 --- a/lib/chef/resource/bash.rb +++ b/chef/lib/chef/resource/bash.rb diff --git a/lib/chef/resource/csh.rb b/chef/lib/chef/resource/csh.rb index 29de9777b9..29de9777b9 100644 --- a/lib/chef/resource/csh.rb +++ b/chef/lib/chef/resource/csh.rb diff --git a/lib/chef/resource/directory.rb b/chef/lib/chef/resource/directory.rb index 7e8944f5fc..7e8944f5fc 100644 --- a/lib/chef/resource/directory.rb +++ b/chef/lib/chef/resource/directory.rb diff --git a/lib/chef/resource/execute.rb b/chef/lib/chef/resource/execute.rb index 21f08e2a34..faa1cda429 100644 --- a/lib/chef/resource/execute.rb +++ b/chef/lib/chef/resource/execute.rb @@ -30,12 +30,12 @@ class Chef @cwd = nil @environment = nil @group = nil - @onlyif = nil + @only_if = nil @path = nil @notify_only = false @returns = 0 @timeout = nil - @unless = nil + @not_if = nil @user = nil @allowed_actions.push(:run) end @@ -80,12 +80,13 @@ class Chef ) end - def onlyif(arg=nil) - set_or_return( - :onlyif, - arg, - :kind_of => [ String ] - ) + def only_if(arg=nil, &blk) + if Kernel.block_given? + @only_if = blk + else + @only_if = arg if arg + end + @only_if end def path(arg=nil) @@ -112,12 +113,13 @@ class Chef ) end - def unless(arg=nil) - set_or_return( - :unless, - arg, - :kind_of => [ String ] - ) + def not_if(arg=nil, &blk) + if Kernel.block_given? + @not_if = blk + else + @not_if = arg if arg + end + @not_if end def user(arg=nil) diff --git a/lib/chef/resource/file.rb b/chef/lib/chef/resource/file.rb index 099bd76591..12cff1a7af 100644 --- a/lib/chef/resource/file.rb +++ b/chef/lib/chef/resource/file.rb @@ -26,7 +26,7 @@ class Chef @path = name @backup = 5 @action = "create" - @allowed_actions.push(:create, :delete, :touch) + @allowed_actions.push(:create, :delete, :touch, :create_if_missing) end def backup(arg=nil) diff --git a/chef/lib/chef/resource/gem_package.rb b/chef/lib/chef/resource/gem_package.rb new file mode 100644 index 0000000000..1ec9463337 --- /dev/null +++ b/chef/lib/chef/resource/gem_package.rb @@ -0,0 +1,33 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "package") + +class Chef + class Resource + class GemPackage < Chef::Resource::Package + + def initialize(name, collection=nil, node=nil) + super(name, collection, node) + @resource_name = :gem_package + @provider = Chef::Provider::Package::Rubygems + end + + end + end +end
\ No newline at end of file diff --git a/lib/chef/resource/link.rb b/chef/lib/chef/resource/link.rb index 46b5793b0f..46b5793b0f 100644 --- a/lib/chef/resource/link.rb +++ b/chef/lib/chef/resource/link.rb diff --git a/lib/chef/resource/package.rb b/chef/lib/chef/resource/package.rb index f5f1c8418e..f5f1c8418e 100644 --- a/lib/chef/resource/package.rb +++ b/chef/lib/chef/resource/package.rb diff --git a/lib/chef/resource/perl.rb b/chef/lib/chef/resource/perl.rb index a9b891ed5c..a9b891ed5c 100644 --- a/lib/chef/resource/perl.rb +++ b/chef/lib/chef/resource/perl.rb diff --git a/chef/lib/chef/resource/portage_package.rb b/chef/lib/chef/resource/portage_package.rb new file mode 100644 index 0000000000..0e300da7a3 --- /dev/null +++ b/chef/lib/chef/resource/portage_package.rb @@ -0,0 +1,33 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), "package") + +class Chef + class Resource + class PortagePackage < Chef::Resource::Package + + def initialize(name, collection=nil, node=nil) + super(name, collection, node) + @resource_name = :portage_package + @provider = Chef::Provider::Package::Apt + end + + end + end +end
\ No newline at end of file diff --git a/lib/chef/resource/python.rb b/chef/lib/chef/resource/python.rb index ac2b27c00f..ac2b27c00f 100644 --- a/lib/chef/resource/python.rb +++ b/chef/lib/chef/resource/python.rb diff --git a/lib/chef/resource/remote_directory.rb b/chef/lib/chef/resource/remote_directory.rb index a23b39d42c..a23b39d42c 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/chef/lib/chef/resource/remote_directory.rb diff --git a/lib/chef/resource/remote_file.rb b/chef/lib/chef/resource/remote_file.rb index dace234398..dace234398 100644 --- a/lib/chef/resource/remote_file.rb +++ b/chef/lib/chef/resource/remote_file.rb diff --git a/lib/chef/resource/ruby.rb b/chef/lib/chef/resource/ruby.rb index 591f1a658b..591f1a658b 100644 --- a/lib/chef/resource/ruby.rb +++ b/chef/lib/chef/resource/ruby.rb diff --git a/lib/chef/resource/script.rb b/chef/lib/chef/resource/script.rb index d59882ab9c..d59882ab9c 100644 --- a/lib/chef/resource/script.rb +++ b/chef/lib/chef/resource/script.rb diff --git a/lib/chef/resource/service.rb b/chef/lib/chef/resource/service.rb index 1c9a784745..1c9a784745 100644 --- a/lib/chef/resource/service.rb +++ b/chef/lib/chef/resource/service.rb diff --git a/lib/chef/resource/sysctl.rb b/chef/lib/chef/resource/sysctl.rb index 203ad72425..203ad72425 100644 --- a/lib/chef/resource/sysctl.rb +++ b/chef/lib/chef/resource/sysctl.rb diff --git a/lib/chef/resource/template.rb b/chef/lib/chef/resource/template.rb index 5f2512a274..5f2512a274 100644 --- a/lib/chef/resource/template.rb +++ b/chef/lib/chef/resource/template.rb diff --git a/chef/lib/chef/resource/user.rb b/chef/lib/chef/resource/user.rb new file mode 100644 index 0000000000..1702753408 --- /dev/null +++ b/chef/lib/chef/resource/user.rb @@ -0,0 +1,96 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class Chef + class Resource + class User < Chef::Resource + + def initialize(name, collection=nil, node=nil) + super(name, collection, node) + @resource_name = :user + @username = name + @comment = nil + @uid = nil + @gid = nil + @home = nil + @shell = nil + @password = nil + @action = :create + @supports = { :manage_home => false } + @allowed_actions.push(:create, :remove, :modify, :manage, :lock, :unlock) + end + + def username(arg=nil) + set_or_return( + :username, + arg, + :kind_of => [ String ] + ) + end + + def comment(arg=nil) + set_or_return( + :comment, + arg, + :kind_of => [ String ] + ) + end + + def uid(arg=nil) + set_or_return( + :uid, + arg, + :kind_of => [ String, Integer ] + ) + end + + def gid(arg=nil) + set_or_return( + :gid, + arg, + :kind_of => [ String, Integer ] + ) + end + + def home(arg=nil) + set_or_return( + :home, + arg, + :kind_of => [ String ] + ) + end + + def shell(arg=nil) + set_or_return( + :shell, + arg, + :kind_of => [ String ] + ) + end + + def password(arg=nil) + set_or_return( + :password, + arg, + :kind_of => [ String ] + ) + end + + end + end +end
\ No newline at end of file diff --git a/lib/chef/resource_collection.rb b/chef/lib/chef/resource_collection.rb index 874ea64378..5278b15c72 100644 --- a/lib/chef/resource_collection.rb +++ b/chef/lib/chef/resource_collection.rb @@ -31,7 +31,6 @@ class Chef def []=(index, arg) is_chef_resource(arg) - raise ArgumentError, "Already have a resource named #{arg.to_s}" if @resources_by_name.has_key?(arg.to_s) @resources[index] = arg @resources_by_name[arg.to_s] = index end @@ -39,7 +38,6 @@ class Chef def <<(*args) args.flatten.each do |a| is_chef_resource(a) - raise ArgumentError, "Already have a resource named #{a.to_s}" if @resources_by_name.has_key?(a.to_s) @resources << a @resources_by_name[a.to_s] = @resources.length - 1 end @@ -48,7 +46,6 @@ class Chef def push(*args) args.flatten.each do |a| is_chef_resource(a) - raise ArgumentError, "Already have a resource named #{a.to_s}" if @resources_by_name.has_key?(a.to_s) @resources.push(a) @resources_by_name[a.to_s] = @resources.length - 1 end diff --git a/lib/chef/resource_definition.rb b/chef/lib/chef/resource_definition.rb index 85466b8541..9a0a9cb09a 100644 --- a/lib/chef/resource_definition.rb +++ b/chef/lib/chef/resource_definition.rb @@ -60,5 +60,8 @@ class Chef @params[symbol] = args.length == 1 ? args[0] : args end + def to_s + "#{name.to_s}" + end end end
\ No newline at end of file diff --git a/lib/chef/rest.rb b/chef/lib/chef/rest.rb index 60d98dbc2a..7e2d453986 100644 --- a/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -31,6 +31,11 @@ class Chef end # Send an HTTP GET request to the path + # + # === Parameters + # path:: The path to GET + # raw:: Whether you want the raw body returned, or JSON inflated. Defaults + # to JSON inflated. def get_rest(path, raw=false) run_request(:GET, create_url(path), false, 10, raw) end @@ -108,25 +113,37 @@ class Chef else raise ArgumentError, "You must provide :GET, :PUT, :POST or :DELETE as the method" end - - begin - Chef::Log.debug("Sending HTTP Request to #{url.host}:#{url.port} via #{req.method} to #{req.path}") - res = http.request(req) - rescue Errno::ECONNREFUSED - Chef::Log.error("Connection refused connecting to #{url.host}:#{url.port} for #{req.path}") - exit(1) - rescue Timeout::Error - Chef::Log.error("Timeout connecting to #{url.host}:#{url.port} for #{req.path}") - exit(1) + + Chef::Log.debug("Sending HTTP Request via #{req.method} to #{req.path}") + res = nil + tf = nil + # TODO - Figure out how to test this block - I really have no idea how + # to do it wouthout actually calling http.request... + res = http.request(req) do |response| + if raw + tf = Tempfile.new("chef-rest") + # Stolen from http://www.ruby-forum.com/topic/166423 + # Kudos to _why! + size, total = 0, response.header['Content-Length'].to_i + response.read_body do |chunk| + tf.write(chunk) + size += chunk.size + if size == 0 + Chef::Log.debug("#{req.path} done (0 length file)") + elsif total == 0 + Chef::Log.debug("#{req.path} (zero content length)") + else + Chef::Log.debug("#{req.path} %d%% done (%d of %d)" % [(size * 100) / total, size, total]) + end + end + tf.close + tf + else + response.read_body + end + response end - - Chef::Log.debug("HTTP request headers: ") - req.each_header { |k,v| Chef::Log.debug("#{k}: #{v}") } - - Chef::Log.debug("HTTP response headers: ") - res.each_header { |k,v| Chef::Log.debug("#{k}: #{v}") } - - + if res.kind_of?(Net::HTTPSuccess) if res['set-cookie'] @cookies["#{url.host}:#{url.port}"] = res['set-cookie'] @@ -135,9 +152,6 @@ class Chef JSON.parse(res.body) else if raw - tf = Tempfile.new("chef-rest") - tf.print(res.body) - tf.close tf else res.body @@ -148,9 +162,6 @@ class Chef @cookies["#{url.host}:#{url.port}"] = res['set-cookie'] end run_request(:GET, create_url(res['location']), false, limit - 1, raw) - elsif res.kind_of?(Net::HTTPUnauthorized) - Chef::Log.error("Node openid registration is not validated") - exit(1) else res.error! end diff --git a/lib/chef/runner.rb b/chef/lib/chef/runner.rb index 09a77556c1..d00c35730d 100644 --- a/lib/chef/runner.rb +++ b/chef/lib/chef/runner.rb @@ -49,33 +49,36 @@ class Chef end Chef::Log.debug("#{resource} using #{provider_klass.to_s}") provider = provider_klass.new(@node, resource) + provider.load_current_resource + provider end def converge - start_time = Time.now - Chef::Log.info("Starting Chef Run") + delayed_actions = Array.new @collection.each do |resource| begin Chef::Log.debug("Processing #{resource}") - provider = build_provider(resource) - provider.load_current_resource - provider.send("action_#{resource.action}") - if resource.updated - resource.actions.each_key do |action| - if resource.actions[action].has_key?(:immediate) - resource.actions[action][:immediate].each do |r| - Chef::Log.info("#{resource} sending action #{action} to #{r} (immediate)") - build_provider(r).send("action_#{action}") + action_list = resource.action.kind_of?(Array) ? resource.action : [ resource.action ] + action_list.each do |ra| + provider = build_provider(resource) + provider.send("action_#{ra}") + if resource.updated + resource.actions.each_key do |action| + if resource.actions[action].has_key?(:immediate) + resource.actions[action][:immediate].each do |r| + Chef::Log.info("#{resource} sending #{action} action to #{r} (immediate)") + build_provider(r).send("action_#{action}") + end end - end - if resource.actions[action].has_key?(:delayed) - resource.actions[action][:delayed].each do |r| - delayed_actions << lambda { - Chef::Log.info("#{resource} sending action #{action} to #{r} (delayed)") - build_provider(r).send("action_#{action}") - } + if resource.actions[action].has_key?(:delayed) + resource.actions[action][:delayed].each do |r| + delayed_actions << lambda { + Chef::Log.info("#{resource} sending #{action} action to #{r} (delayed)") + build_provider(r).send("action_#{action}") + } + end end end end @@ -88,8 +91,7 @@ class Chef # Run all our :delayed actions delayed_actions.each { |da| da.call } - end_time = Time.now - Chef::Log.info("Chef Run complete in #{end_time - start_time} seconds") + true end end diff --git a/lib/chef/search.rb b/chef/lib/chef/search.rb index 229f738399..229f738399 100644 --- a/lib/chef/search.rb +++ b/chef/lib/chef/search.rb diff --git a/lib/chef/search_index.rb b/chef/lib/chef/search_index.rb index 932a451999..932a451999 100644 --- a/lib/chef/search_index.rb +++ b/chef/lib/chef/search_index.rb diff --git a/spec/chef_server/controllers/log/merb_test.log b/chef/spec/chef_server/controllers/log/merb_test.log index 86fbe4b9cb..86fbe4b9cb 100644 --- a/spec/chef_server/controllers/log/merb_test.log +++ b/chef/spec/chef_server/controllers/log/merb_test.log diff --git a/spec/chef_server/controllers/nodes_spec.rb b/chef/spec/chef_server/controllers/nodes_spec.rb index 65c2df301a..65c2df301a 100644 --- a/spec/chef_server/controllers/nodes_spec.rb +++ b/chef/spec/chef_server/controllers/nodes_spec.rb diff --git a/spec/chef_server/controllers/openid_consumer_spec.rb b/chef/spec/chef_server/controllers/openid_consumer_spec.rb index 0156fd8d49..0156fd8d49 100644 --- a/spec/chef_server/controllers/openid_consumer_spec.rb +++ b/chef/spec/chef_server/controllers/openid_consumer_spec.rb diff --git a/spec/chef_server/controllers/openid_register_spec.rb b/chef/spec/chef_server/controllers/openid_register_spec.rb index c883715fc6..c883715fc6 100644 --- a/spec/chef_server/controllers/openid_register_spec.rb +++ b/chef/spec/chef_server/controllers/openid_register_spec.rb diff --git a/spec/chef_server/log/merb_test.log b/chef/spec/chef_server/log/merb_test.log index b2aa15df9a..b2aa15df9a 100644 --- a/spec/chef_server/log/merb_test.log +++ b/chef/spec/chef_server/log/merb_test.log diff --git a/spec/chef_server/spec.opts b/chef/spec/chef_server/spec.opts index 3a2ff550a2..3a2ff550a2 100644 --- a/spec/chef_server/spec.opts +++ b/chef/spec/chef_server/spec.opts diff --git a/spec/chef_server/spec_helper.rb b/chef/spec/chef_server/spec_helper.rb index 90c1e0af7a..90c1e0af7a 100644 --- a/spec/chef_server/spec_helper.rb +++ b/chef/spec/chef_server/spec_helper.rb diff --git a/spec/data/bad-config.rb b/chef/spec/data/bad-config.rb index 5477a69366..5477a69366 100644 --- a/spec/data/bad-config.rb +++ b/chef/spec/data/bad-config.rb diff --git a/spec/data/compile/cookbooks/test/attributes/george.rb b/chef/spec/data/compile/cookbooks/test/attributes/george.rb index 5df9567761..5df9567761 100644 --- a/spec/data/compile/cookbooks/test/attributes/george.rb +++ b/chef/spec/data/compile/cookbooks/test/attributes/george.rb diff --git a/spec/data/compile/cookbooks/test/definitions/new_cat.rb b/chef/spec/data/compile/cookbooks/test/definitions/new_cat.rb index a49b53348c..a49b53348c 100644 --- a/spec/data/compile/cookbooks/test/definitions/new_cat.rb +++ b/chef/spec/data/compile/cookbooks/test/definitions/new_cat.rb diff --git a/spec/data/compile/cookbooks/test/recipes/default.rb b/chef/spec/data/compile/cookbooks/test/recipes/default.rb index d769dc826d..d769dc826d 100644 --- a/spec/data/compile/cookbooks/test/recipes/default.rb +++ b/chef/spec/data/compile/cookbooks/test/recipes/default.rb diff --git a/spec/data/compile/cookbooks/test/recipes/one.rb b/chef/spec/data/compile/cookbooks/test/recipes/one.rb index 7795cc1d4a..7795cc1d4a 100644 --- a/spec/data/compile/cookbooks/test/recipes/one.rb +++ b/chef/spec/data/compile/cookbooks/test/recipes/one.rb diff --git a/spec/data/compile/cookbooks/test/recipes/two.rb b/chef/spec/data/compile/cookbooks/test/recipes/two.rb index 01def1b2ac..01def1b2ac 100644 --- a/spec/data/compile/cookbooks/test/recipes/two.rb +++ b/chef/spec/data/compile/cookbooks/test/recipes/two.rb diff --git a/spec/data/compile/nodes/compile.rb b/chef/spec/data/compile/nodes/compile.rb index 84d52bb1cf..84d52bb1cf 100644 --- a/spec/data/compile/nodes/compile.rb +++ b/chef/spec/data/compile/nodes/compile.rb diff --git a/spec/data/config.rb b/chef/spec/data/config.rb index 0b3340ce57..0b3340ce57 100644 --- a/spec/data/config.rb +++ b/chef/spec/data/config.rb diff --git a/chef/spec/data/cookbooks/apache2/recipes/default.rb b/chef/spec/data/cookbooks/apache2/recipes/default.rb new file mode 100644 index 0000000000..c2fa53be32 --- /dev/null +++ b/chef/spec/data/cookbooks/apache2/recipes/default.rb @@ -0,0 +1,3 @@ +# +# Nothing ot see here +#
\ No newline at end of file diff --git a/spec/data/cookbooks/openldap/attributes/default.rb b/chef/spec/data/cookbooks/openldap/attributes/default.rb index 204ae9ed77..204ae9ed77 100644 --- a/spec/data/cookbooks/openldap/attributes/default.rb +++ b/chef/spec/data/cookbooks/openldap/attributes/default.rb diff --git a/spec/data/cookbooks/openldap/attributes/smokey.rb b/chef/spec/data/cookbooks/openldap/attributes/smokey.rb index 63f5b56c7f..63f5b56c7f 100644 --- a/spec/data/cookbooks/openldap/attributes/smokey.rb +++ b/chef/spec/data/cookbooks/openldap/attributes/smokey.rb diff --git a/spec/data/cookbooks/openldap/definitions/client.rb b/chef/spec/data/cookbooks/openldap/definitions/client.rb index ac81831d11..ac81831d11 100644 --- a/spec/data/cookbooks/openldap/definitions/client.rb +++ b/chef/spec/data/cookbooks/openldap/definitions/client.rb diff --git a/spec/data/cookbooks/openldap/definitions/server.rb b/chef/spec/data/cookbooks/openldap/definitions/server.rb index 2df437aa84..2df437aa84 100644 --- a/spec/data/cookbooks/openldap/definitions/server.rb +++ b/chef/spec/data/cookbooks/openldap/definitions/server.rb diff --git a/spec/data/cookbooks/openldap/ignore b/chef/spec/data/cookbooks/openldap/ignore index e96f4e7df4..e96f4e7df4 100644 --- a/spec/data/cookbooks/openldap/ignore +++ b/chef/spec/data/cookbooks/openldap/ignore diff --git a/spec/data/cookbooks/openldap/recipes/default.rb b/chef/spec/data/cookbooks/openldap/recipes/default.rb index 0ac8a9bb4b..0ac8a9bb4b 100644 --- a/spec/data/cookbooks/openldap/recipes/default.rb +++ b/chef/spec/data/cookbooks/openldap/recipes/default.rb diff --git a/spec/data/cookbooks/openldap/recipes/gigantor.rb b/chef/spec/data/cookbooks/openldap/recipes/gigantor.rb index b450eca7cd..b450eca7cd 100644 --- a/spec/data/cookbooks/openldap/recipes/gigantor.rb +++ b/chef/spec/data/cookbooks/openldap/recipes/gigantor.rb diff --git a/spec/data/cookbooks/openldap/recipes/one.rb b/chef/spec/data/cookbooks/openldap/recipes/one.rb index e1c3cff92e..e1c3cff92e 100644 --- a/spec/data/cookbooks/openldap/recipes/one.rb +++ b/chef/spec/data/cookbooks/openldap/recipes/one.rb diff --git a/spec/data/cookbooks/openldap/templates/default/test.erb b/chef/spec/data/cookbooks/openldap/templates/default/test.erb index f39fa7da89..f39fa7da89 100644 --- a/spec/data/cookbooks/openldap/templates/default/test.erb +++ b/chef/spec/data/cookbooks/openldap/templates/default/test.erb diff --git a/spec/data/definitions/test.rb b/chef/spec/data/definitions/test.rb index b0d0effc27..b0d0effc27 100644 --- a/spec/data/definitions/test.rb +++ b/chef/spec/data/definitions/test.rb diff --git a/spec/data/kitchen/openldap/attributes/default.rb b/chef/spec/data/kitchen/openldap/attributes/default.rb index d208959475..d208959475 100644 --- a/spec/data/kitchen/openldap/attributes/default.rb +++ b/chef/spec/data/kitchen/openldap/attributes/default.rb diff --git a/spec/data/kitchen/openldap/attributes/robinson.rb b/chef/spec/data/kitchen/openldap/attributes/robinson.rb index 9d6b44d464..9d6b44d464 100644 --- a/spec/data/kitchen/openldap/attributes/robinson.rb +++ b/chef/spec/data/kitchen/openldap/attributes/robinson.rb diff --git a/spec/data/kitchen/openldap/definitions/client.rb b/chef/spec/data/kitchen/openldap/definitions/client.rb index d4c2263b54..d4c2263b54 100644 --- a/spec/data/kitchen/openldap/definitions/client.rb +++ b/chef/spec/data/kitchen/openldap/definitions/client.rb diff --git a/spec/data/kitchen/openldap/definitions/drewbarrymore.rb b/chef/spec/data/kitchen/openldap/definitions/drewbarrymore.rb index 510f0c35da..510f0c35da 100644 --- a/spec/data/kitchen/openldap/definitions/drewbarrymore.rb +++ b/chef/spec/data/kitchen/openldap/definitions/drewbarrymore.rb diff --git a/spec/data/kitchen/openldap/recipes/gigantor.rb b/chef/spec/data/kitchen/openldap/recipes/gigantor.rb index 70a41960eb..70a41960eb 100644 --- a/spec/data/kitchen/openldap/recipes/gigantor.rb +++ b/chef/spec/data/kitchen/openldap/recipes/gigantor.rb diff --git a/spec/data/kitchen/openldap/recipes/ignoreme.rb b/chef/spec/data/kitchen/openldap/recipes/ignoreme.rb index 15095986c6..15095986c6 100644 --- a/spec/data/kitchen/openldap/recipes/ignoreme.rb +++ b/chef/spec/data/kitchen/openldap/recipes/ignoreme.rb diff --git a/spec/data/kitchen/openldap/recipes/woot.rb b/chef/spec/data/kitchen/openldap/recipes/woot.rb index 44893dae36..44893dae36 100644 --- a/spec/data/kitchen/openldap/recipes/woot.rb +++ b/chef/spec/data/kitchen/openldap/recipes/woot.rb diff --git a/spec/data/nodes/default.rb b/chef/spec/data/nodes/default.rb index e1c3cff92e..e1c3cff92e 100644 --- a/spec/data/nodes/default.rb +++ b/chef/spec/data/nodes/default.rb diff --git a/spec/data/nodes/test.example.com.rb b/chef/spec/data/nodes/test.example.com.rb index 9c374395bf..9c374395bf 100644 --- a/spec/data/nodes/test.example.com.rb +++ b/chef/spec/data/nodes/test.example.com.rb diff --git a/spec/data/nodes/test.rb b/chef/spec/data/nodes/test.rb index d968816d60..d968816d60 100644 --- a/spec/data/nodes/test.rb +++ b/chef/spec/data/nodes/test.rb diff --git a/spec/data/recipes/test.rb b/chef/spec/data/recipes/test.rb index 1c94b917f0..c33d714a2c 100644 --- a/spec/data/recipes/test.rb +++ b/chef/spec/data/recipes/test.rb @@ -1,6 +1,6 @@ file "/etc/nsswitch.conf" do - action "create" + action :create owner "root" group "root" mode 0644 diff --git a/spec/data/seattle.txt b/chef/spec/data/seattle.txt index 19f6290939..19f6290939 100644 --- a/spec/data/seattle.txt +++ b/chef/spec/data/seattle.txt diff --git a/spec/lib/chef/provider/easy.rb b/chef/spec/lib/chef/provider/easy.rb index b637efa768..b637efa768 100644 --- a/spec/lib/chef/provider/easy.rb +++ b/chef/spec/lib/chef/provider/easy.rb diff --git a/spec/lib/chef/provider/snakeoil.rb b/chef/spec/lib/chef/provider/snakeoil.rb index 0486402686..0486402686 100644 --- a/spec/lib/chef/provider/snakeoil.rb +++ b/chef/spec/lib/chef/provider/snakeoil.rb diff --git a/spec/lib/chef/resource/cat.rb b/chef/spec/lib/chef/resource/cat.rb index e651c44512..e651c44512 100644 --- a/spec/lib/chef/resource/cat.rb +++ b/chef/spec/lib/chef/resource/cat.rb diff --git a/spec/lib/chef/resource/zen_master.rb b/chef/spec/lib/chef/resource/zen_master.rb index 8b4225fbd4..8b4225fbd4 100644 --- a/spec/lib/chef/resource/zen_master.rb +++ b/chef/spec/lib/chef/resource/zen_master.rb diff --git a/spec/rcov.opts b/chef/spec/rcov.opts index 484626ea9c..484626ea9c 100644 --- a/spec/rcov.opts +++ b/chef/spec/rcov.opts diff --git a/spec/spec.opts b/chef/spec/spec.opts index c9c9b4ddf0..c9c9b4ddf0 100644 --- a/spec/spec.opts +++ b/chef/spec/spec.opts diff --git a/spec/spec_helper.rb b/chef/spec/spec_helper.rb index 9120b2876c..9120b2876c 100644 --- a/spec/spec_helper.rb +++ b/chef/spec/spec_helper.rb diff --git a/spec/unit/chef_spec.rb b/chef/spec/unit/chef_spec.rb index 7d2af6f88d..7d2af6f88d 100644 --- a/spec/unit/chef_spec.rb +++ b/chef/spec/unit/chef_spec.rb diff --git a/chef/spec/unit/client_spec.rb b/chef/spec/unit/client_spec.rb new file mode 100644 index 0000000000..8defd2e4a1 --- /dev/null +++ b/chef/spec/unit/client_spec.rb @@ -0,0 +1,179 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) + +describe Chef::Client, "initialize" do + it "should create a new Chef::Client object" do + Chef::Client.new.should be_kind_of(Chef::Client) + end +end + +describe Chef::Client, "run" do + before(:each) do + @client = Chef::Client.new + to_stub = [ + :build_node, + :register, + :authenticate, + :sync_library_files, + :sync_attribute_files, + :sync_definitions, + :sync_recipes, + :save_node, + :converge, + :save_node + ] + to_stub.each do |method| + @client.stub!(method).and_return(true) + end + time = Time.now + Time.stub!(:now).and_return(time) + end + + it "should start the run clock timer" do + time = Time.now + Time.should_receive(:now).twice.and_return(time) + @client.run + end + + it "should build the node" do + @client.should_receive(:build_node).and_return(true) + @client.run + end + + it "should register for an openid" do + @client.should_receive(:register).and_return(true) + @client.run + end + + it "should authenticate with the server" do + @client.should_receive(:authenticate).and_return(true) + @client.run + end + + it "should synchronize definitions from the server" do + @client.should_receive(:sync_definitions).and_return(true) + @client.run + end + + it "should synchronize recipes from the server" do + @client.should_receive(:sync_recipes).and_return(true) + @client.run + end + + it "should synchronize and load library files from the server" do + @client.should_receive(:sync_library_files).and_return(true) + @client.run + end + + it "should synchronize and load attribute files from the server" do + @client.should_receive(:sync_attribute_files).and_return(true) + @client.run + end + + it "should save the nodes state on the server (twice!)" do + @client.should_receive(:save_node).twice.and_return(true) + @client.run + end + + it "should converge the node to the proper state" do + @client.should_receive(:converge).and_return(true) + @client.run + end +end + +describe Chef::Client, "run_solo" do + before(:each) do + @client = Chef::Client.new + @client.stub!(:build_node).and_return(true) + @client.stub!(:converge).and_return(true) + end + + it "should start/top the run timer" do + time = Time.now + Time.should_receive(:now).twice.and_return(time) + @client.run_solo + end + + it "should build the node" do + @client.should_receive(:build_node).and_return(true) + @client.run_solo + end + + it "should converge the node to the proper state" do + @client.should_receive(:converge).and_return(true) + @client.run_solo + end +end + +describe Chef::Client, "build_node" do + before(:each) do + @mock_facter_fqdn = mock("Facter FQDN") + @mock_facter_fqdn.stub!(:value).and_return("foo.bar.com") + @mock_facter_hostname = mock("Facter Hostname") + @mock_facter_hostname.stub!(:value).and_return("foo") + Facter.stub!(:[]).with("fqdn").and_return(@mock_facter_fqdn) + Facter.stub!(:[]).with("hostname").and_return(@mock_facter_hostname) + Facter.stub!(:each).and_return(true) + @node = Chef::Node.new + @mock_rest.stub!(:get_rest).and_return(@node) + Chef::REST.stub!(:new).and_return(@mock_rest) + @client = Chef::Client.new + end + + it "should set the name equal to the FQDN" do + @mock_rest.stub!(:get_rest).and_return(nil) + @client.build_node + @client.node.name.should eql("foo.bar.com") + end + + it "should set the name equal to the hostname if FQDN is not available" do + @mock_facter_fqdn.stub!(:value).and_return(nil) + @mock_rest.stub!(:get_rest).and_return(nil) + @client.build_node + @client.node.name.should eql("foo") + end + + it "should add any json attributes to the node" do + @client.json_attribs = { "one" => "two", "three" => "four" } + @client.build_node + @client.node.one.should eql("two") + @client.node.three.should eql("four") + end + + it "should allow you to set recipes from the json attributes" do + @client.json_attribs = { "recipes" => [ "one", "two", "three" ]} + @client.build_node + @client.node.recipes.should eql([ "one", "two", "three" ]) + end + + it "should not add duplicate recipes from the json attributes" do + @client.node = Chef::Node.new + @client.node.recipes << "one" + @client.json_attribs = { "recipes" => [ "one", "two", "three" ]} + @client.build_node + @client.node.recipes.should eql([ "one", "two", "three" ]) + end +end + +describe Chef::Client, "register" do + before(:each) do + @mock_rest = mock("Chef::REST", :new => true) + end +end diff --git a/spec/unit/compile_spec.rb b/chef/spec/unit/compile_spec.rb index c7f76a4a58..c7f76a4a58 100644 --- a/spec/unit/compile_spec.rb +++ b/chef/spec/unit/compile_spec.rb diff --git a/spec/unit/config_spec.rb b/chef/spec/unit/config_spec.rb index 51e33401d8..51e33401d8 100644 --- a/spec/unit/config_spec.rb +++ b/chef/spec/unit/config_spec.rb diff --git a/spec/unit/cookbook_loader_spec.rb b/chef/spec/unit/cookbook_loader_spec.rb index 501329777b..501329777b 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/chef/spec/unit/cookbook_loader_spec.rb diff --git a/spec/unit/cookbook_spec.rb b/chef/spec/unit/cookbook_spec.rb index 85b4040771..0ae87ed04c 100644 --- a/spec/unit/cookbook_spec.rb +++ b/chef/spec/unit/cookbook_spec.rb @@ -131,12 +131,4 @@ describe Chef::Cookbook do lambda { @cookbook.load_recipe("smackdown", node) }.should raise_error(ArgumentError) end - it "should load the attributes if it has not already when a recipe is loaded" do - @cookbook.attribute_files = Dir[File.join(COOKBOOK_PATH, "attributes", "smokey.rb")] - @cookbook.recipe_files = Dir[File.join(COOKBOOK_PATH, "recipes", "**", "*.rb")] - node = Chef::Node.new - node.name "Julia Child" - recipe = @cookbook.load_recipe("openldap::gigantor", node) - node.smokey.should == "robinson" - end end
\ No newline at end of file diff --git a/spec/unit/couchdb_spec.rb b/chef/spec/unit/couchdb_spec.rb index 621439df51..621439df51 100644 --- a/spec/unit/couchdb_spec.rb +++ b/chef/spec/unit/couchdb_spec.rb diff --git a/chef/spec/unit/file_cache_spec.rb b/chef/spec/unit/file_cache_spec.rb new file mode 100644 index 0000000000..c84eea376e --- /dev/null +++ b/chef/spec/unit/file_cache_spec.rb @@ -0,0 +1,124 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) + +describe Chef::FileCache, "store method" do + before(:each) do + Chef::Config[:file_cache_path] = "/tmp/foo" + Dir.stub!(:mkdir).and_return(true) + File.stub!(:directory?).and_return(true) + @io = mock("IO", { :print => true, :close => true }) + File.stub!(:open).and_return(@io) + end + + it "should create the directories leading up to bang" do + File.stub!(:directory?).and_return(false) + Dir.should_receive(:mkdir).with("/tmp").and_return(true) + Dir.should_receive(:mkdir).with("/tmp/foo").and_return(true) + Dir.should_receive(:mkdir).with("/tmp/foo/whiz").and_return(true) + Dir.should_not_receive(:mkdir).with("/tmp/foo/whiz/bang").and_return(true) + Chef::FileCache.store("whiz/bang", "I found a poop") + end + + it "should create a file at /tmp/foo/whiz/bang" do + File.should_receive(:open).with("/tmp/foo/whiz/bang", "w").and_return(@io) + Chef::FileCache.store("whiz/bang", "I found a poop") + end + + it "should print the contents to the file" do + @io.should_receive(:print).with("I found a poop") + Chef::FileCache.store("whiz/bang", "I found a poop") + end + + it "should close the file" do + @io.should_receive(:close) + Chef::FileCache.store("whiz/bang", "I found a poop") + end + +end + +describe Chef::FileCache, "load method" do + before(:each) do + Chef::Config[:file_cache_path] = "/tmp/foo" + Dir.stub!(:mkdir).and_return(true) + File.stub!(:directory?).and_return(true) + File.stub!(:exists?).and_return(true) + File.stub!(:read).and_return("I found a poop") + end + + it "should find the full path to whiz/bang" do + File.should_receive(:read).with("/tmp/foo/whiz/bang").and_return(true) + Chef::FileCache.load('whiz/bang') + end + + it "should raise a Chef::Exception::FileNotFound if the file doesn't exist" do + File.stub!(:exists?).and_return(false) + lambda { Chef::FileCache.load('whiz/bang') }.should raise_error(Chef::Exception::FileNotFound) + end +end + +describe Chef::FileCache, "delete method" do + before(:each) do + Chef::Config[:file_cache_path] = "/tmp/foo" + Dir.stub!(:mkdir).and_return(true) + File.stub!(:directory?).and_return(true) + File.stub!(:exists?).and_return(true) + File.stub!(:unlink).and_return(true) + end + + it "should unlink the full path to whiz/bang" do + File.should_receive(:unlink).with("/tmp/foo/whiz/bang").and_return(true) + Chef::FileCache.delete("whiz/bang") + end + +end + +describe Chef::FileCache, "list method" do + before(:each) do + Chef::Config[:file_cache_path] = "/tmp/foo" + Dir.stub!(:[]).and_return(["/tmp/foo/whiz/bang", "/tmp/foo/snappy/patter"]) + File.stub!(:file?).and_return(true) + end + + it "should return the relative paths" do + Chef::FileCache.list.should eql([ "whiz/bang", "snappy/patter" ]) + end +end + +describe Chef::FileCache, "has_key? method" do + before(:each) do + Chef::Config[:file_cache_path] = "/tmp/foo" + end + + it "should check the full path to the file" do + File.should_receive(:exists?).with("/tmp/foo/whiz/bang") + Chef::FileCache.has_key?("whiz/bang") + end + + it "should return true if the file exists" do + File.stub!(:exists?).and_return(true) + Chef::FileCache.has_key?("whiz/bang").should eql(true) + end + + it "should return false if the file does not exist" do + File.stub!(:exists?).and_return(false) + Chef::FileCache.has_key?("whiz/bang").should eql(false) + end +end + diff --git a/spec/unit/file_store_spec.rb b/chef/spec/unit/file_store_spec.rb index 8addeb9e31..8addeb9e31 100644 --- a/spec/unit/file_store_spec.rb +++ b/chef/spec/unit/file_store_spec.rb diff --git a/spec/unit/log/formatter_spec.rb b/chef/spec/unit/log/formatter_spec.rb index e0d8bfd773..e0d8bfd773 100644 --- a/spec/unit/log/formatter_spec.rb +++ b/chef/spec/unit/log/formatter_spec.rb diff --git a/spec/unit/log_spec.rb b/chef/spec/unit/log_spec.rb index 14892b1af4..14892b1af4 100644 --- a/spec/unit/log_spec.rb +++ b/chef/spec/unit/log_spec.rb diff --git a/spec/unit/mixin/params_validate_spec.rb b/chef/spec/unit/mixin/params_validate_spec.rb index 937589b059..937589b059 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/chef/spec/unit/mixin/params_validate_spec.rb diff --git a/spec/unit/mixin/template_spec.rb b/chef/spec/unit/mixin/template_spec.rb index 0ff929e8f6..0ff929e8f6 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/chef/spec/unit/mixin/template_spec.rb diff --git a/spec/unit/node_spec.rb b/chef/spec/unit/node_spec.rb index 605bb8b628..971f57716c 100644 --- a/spec/unit/node_spec.rb +++ b/chef/spec/unit/node_spec.rb @@ -102,10 +102,10 @@ describe Chef::Node, "attributes" do @node.each_attribute do |a,v| seen_attributes[a] = v end - seen_attributes.should have_key(:sunshine) - seen_attributes.should have_key(:canada) - seen_attributes[:sunshine].should == "is bright" - seen_attributes[:canada].should == "is a nice place" + seen_attributes.should have_key("sunshine") + seen_attributes.should have_key("canada") + seen_attributes["sunshine"].should == "is bright" + seen_attributes["canada"].should == "is a nice place" end end @@ -225,7 +225,7 @@ describe Chef::Node, "to_index" do it "should return a hash with :index attributes" do @node.name("airplane") - @node.to_index.should == { :foo => "bar", :index_name => "node", :id => "node_airplane", :name => "airplane" } + @node.to_index.should == { "foo" => "bar", "index_name" => "node", "id" => "node_airplane", "name" => "airplane" } end end diff --git a/spec/unit/openid_registration_spec.rb b/chef/spec/unit/openid_registration_spec.rb index d849369796..d849369796 100644 --- a/spec/unit/openid_registration_spec.rb +++ b/chef/spec/unit/openid_registration_spec.rb diff --git a/spec/unit/platform_spec.rb b/chef/spec/unit/platform_spec.rb index 4eeeebed89..4eeeebed89 100644 --- a/spec/unit/platform_spec.rb +++ b/chef/spec/unit/platform_spec.rb diff --git a/spec/unit/provider/directory_spec.rb b/chef/spec/unit/provider/directory_spec.rb index 4978b27288..3e397b506f 100644 --- a/spec/unit/provider/directory_spec.rb +++ b/chef/spec/unit/provider/directory_spec.rb @@ -72,7 +72,7 @@ describe Chef::Provider::Directory do it "should delete the directory if it exists, and is writable with action_delete" do load_mock_provider - File.should_receive(:exists?).once.and_return(true) + File.should_receive(:directory?).once.and_return(true) File.should_receive(:writable?).once.and_return(true) Dir.should_receive(:delete).with(@new_resource.path).once.and_return(true) @directory.action_delete diff --git a/spec/unit/provider/file_spec.rb b/chef/spec/unit/provider/file_spec.rb index 9ea628a357..6c0a4059f3 100644 --- a/spec/unit/provider/file_spec.rb +++ b/chef/spec/unit/provider/file_spec.rb @@ -221,4 +221,19 @@ describe Chef::Provider::File do @provider.backup end +end + +describe Chef::Provider::File, "action_create_if_missing" do + before(:each) do + @resource = Chef::Resource::File.new("seattle") + @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) + @node = Chef::Node.new + @node.name "latte" + @provider = Chef::Provider::File.new(@node, @resource) + end + + it "should call action create, since File can only touch" do + @provider.should_receive(:action_create).and_return(true) + @provider.action_create_if_missing + end end
\ No newline at end of file diff --git a/spec/unit/provider/link_spec.rb b/chef/spec/unit/provider/link_spec.rb index 462ab9409b..462ab9409b 100644 --- a/spec/unit/provider/link_spec.rb +++ b/chef/spec/unit/provider/link_spec.rb diff --git a/chef/spec/unit/provider/package/apt_spec.rb b/chef/spec/unit/provider/package/apt_spec.rb new file mode 100644 index 0000000000..026d63b05a --- /dev/null +++ b/chef/spec/unit/provider/package/apt_spec.rb @@ -0,0 +1,211 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper")) + +describe Chef::Provider::Package::Apt, "load_current_resource" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs", + :updated => nil + ) + @current_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => nil, + :updated => nil + ) + @status = mock("Status", :exitstatus => 0) + @provider = Chef::Provider::Package::Apt.new(@node, @new_resource) + Chef::Resource::Package.stub!(:new).and_return(@current_resource) + @provider.stub!(:popen4).and_return(@status) + @stdin = mock("STDIN", :null_object => true) + @stdout = mock("STDOUT", :null_object => true) + @stdout.stub!(:each).and_yield("emacs:"). + and_yield(" Installed: (none)"). + and_yield(" Candidate: (none)"). + and_yield(" Version Table:") + @stderr = mock("STDERR", :null_object => true) + @pid = mock("PID", :null_object => true) + end + + it "should create a current resource with the name of the new_resource" do + Chef::Resource::Package.should_receive(:new).and_return(@current_resource) + @provider.load_current_resource + end + + it "should set the current resources package name to the new resources package name" do + @current_resource.should_receive(:package_name).with(@new_resource.package_name) + @provider.load_current_resource + end + + it "should run apt-cache policy with the package name" do + @provider.should_receive(:popen4).with("apt-cache policy #{@new_resource.package_name}").and_return(@status) + @provider.load_current_resource + end + + it "should close stdin on apt-cache policy" do + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @stdin.should_receive(:close).and_return(true) + @provider.load_current_resource + end + + it "should read stdout on apt-cache policy" do + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @stdout.should_receive(:each).and_return(true) + @provider.load_current_resource + end + + it "should set the installed version to nil on the current resource if apt-cache policy installed version is (none)" do + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @current_resource.should_receive(:version).with(nil).and_return(true) + @provider.load_current_resource + end + + it "should set the installed version if apt-cache policy has one" do + @stdout.stub!(:each).and_yield("emacs:"). + and_yield(" Installed: 0.1.1"). + and_yield(" Candidate: (none)"). + and_yield(" Version Table:") + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @current_resource.should_receive(:version).with("0.1.1").and_return(true) + @provider.load_current_resource + end + + it "should set the candidate version if apt-cache policy has one" do + @stdout.stub!(:each).and_yield("emacs:"). + and_yield(" Installed: 0.1.1"). + and_yield(" Candidate: 10"). + and_yield(" Version Table:") + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.load_current_resource + @provider.candidate_version.should eql("10") + end + + it "should raise an exception if apt-cache policy fails" do + @status.should_receive(:exitstatus).and_return(1) + lambda { @provider.load_current_resource }.should raise_error(Chef::Exception::Package) + end + + it "should not raise an exception if apt-cache policy succeeds" do + @status.should_receive(:exitstatus).and_return(0) + lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exception::Package) + end + + it "should return the current resouce" do + @provider.load_current_resource.should eql(@current_resource) + end +end + +describe Chef::Provider::Package::Apt, "install_package" do + + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs", + :updated => nil + ) + @provider = Chef::Provider::Package::Apt.new(@node, @new_resource) + end + + it "should run apt-get install with the package name and version" do + @provider.should_receive(:run_command).with({ + :command => "apt-get -q -y install emacs=1.0", + :environment => { + "DEBIAN_FRONTEND" => "noninteractive" + } + }) + @provider.install_package("emacs", "1.0") + end +end + +describe Chef::Provider::Package::Apt, "upgrade_package" do + + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs", + :updated => nil + ) + @provider = Chef::Provider::Package::Apt.new(@node, @new_resource) + end + + it "should run install_package with the name and version" do + @provider.should_receive(:install_package).with("emacs", "1.0") + @provider.upgrade_package("emacs", "1.0") + end +end + +describe Chef::Provider::Package::Apt, "remove_package" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs", + :updated => nil + ) + @provider = Chef::Provider::Package::Apt.new(@node, @new_resource) + end + + it "should run apt-get remove with the package name" do + @provider.should_receive(:run_command).with({ + :command => "apt-get -q -y remove emacs", + :environment => { + "DEBIAN_FRONTEND" => "noninteractive" + } + }) + @provider.remove_package("emacs", "1.0") + end +end + +describe Chef::Provider::Package::Apt, "purge_package" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs", + :updated => nil + ) + @provider = Chef::Provider::Package::Apt.new(@node, @new_resource) + end + + it "should run apt-get purge with the package name" do + @provider.should_receive(:run_command).with({ + :command => "apt-get -q -y purge emacs", + :environment => { + "DEBIAN_FRONTEND" => "noninteractive" + } + }) + @provider.purge_package("emacs", "1.0") + end +end
\ No newline at end of file diff --git a/chef/spec/unit/provider/package_spec.rb b/chef/spec/unit/provider/package_spec.rb new file mode 100644 index 0000000000..f60ed675e8 --- /dev/null +++ b/chef/spec/unit/provider/package_spec.rb @@ -0,0 +1,242 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) + +describe Chef::Provider::Package, "initialize" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource", :null_object => true) + end + + it "should return a Chef::Provider::Package object" do + provider = Chef::Provider::Package.new(@node, @new_resource) + provider.should be_a_kind_of(Chef::Provider::Package) + end +end + +describe Chef::Provider::Package, "action_install" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs", + :updated => nil + ) + @current_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs" + ) + @provider = Chef::Provider::Package.new(@node, @new_resource) + @provider.candidate_version = "1.0" + @provider.current_resource = @current_resource + @provider.stub!(:install_package).and_return(true) + end + + it "should raise a Chef::Exception::Package if no version is specified, and no candidate is available" do + @provider.candidate_version = nil + lambda { @provider.action_install }.should raise_error(Chef::Exception::Package) + end + + it "should install the package at the candidate_version if it is not already installed" do + @provider.should_receive(:install_package).with( + @new_resource.name, + @provider.candidate_version + ).and_return(true) + @provider.action_install + end + + it "should install the package at the version specified if it is not already installed" do + @new_resource.stub!(:version).and_return("1.0") + @provider.should_receive(:install_package).with( + @new_resource.name, + @new_resource.version + ).and_return(true) + @provider.action_install + end + + it "should install the package at the version specified if a different version is installed" do + @new_resource.stub!(:version).and_return("1.0") + @current_resource.stub!(:version).and_return("0.99") + @provider.should_receive(:install_package).with( + @new_resource.name, + @new_resource.version + ).and_return(true) + @provider.action_install + end + + it "should not install the package if it is already installed and no version is specified" do + @current_resource.stub!(:version).and_return("1.0") + @provider.should_not_receive(:install_package) + @provider.action_install + end + + it "should not install the package if it is already installed at the version specified" do + @current_resource.stub!(:version).and_return("1.0") + @new_resource.stub!(:version).and_return("1.0") + @provider.should_not_receive(:install_package) + @provider.action_install + end + + it "should set the resource to updated if it installs the package" do + @new_resource.should_recieve(:updated).with(true) + @provider.action_install + end + +end + +describe Chef::Provider::Package, "action_upgrade" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs" + ) + @current_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => "0.99", + :package_name => "emacs" + ) + @provider = Chef::Provider::Package.new(@node, @new_resource) + @provider.candidate_version = "1.0" + @provider.current_resource = @current_resource + @provider.stub!(:install_package).and_return(true) + end + + it "should install the package if the current version is not the candidate version" do + @provider.should_receive(:install_package).with( + @new_resource.name, + @provider.candidate_version + ).and_return(true) + @provider.action_upgrade + end + + it "should set the resource to updated if it installs the package" do + @new_resource.should_recieve(:updated).with(true) + @provider.action_upgrade + end + + it "should not install the package if the current version is the candidate version" do + @current_resource.stub!(:version).and_return("1.0") + @provider.should_not_receive(:install_package) + @provider.action_upgrade + end +end + +# Oh ruby, you are so nice. +# Remove is the same as purge, just with a different method. +%w{remove purge}.each do |act| + act_string = "action_#{act}" + act_symbol = "action_#{act}".to_sym + act_method = "#{act}_package".to_sym + + describe Chef::Provider::Package, act_string do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs" + ) + @current_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => "0.99", + :package_name => "emacs" + ) + @provider = Chef::Provider::Package.new(@node, @new_resource) + @provider.candidate_version = "1.0" + @provider.current_resource = @current_resource + @provider.stub!(act_method).and_return(true) + end + + it "should #{act} the package if it is installed" do + @provider.should_receive(act_method).with( + @new_resource.name, + @new_resource.version + ).and_return(true) + @provider.send(act_symbol) + end + + it "should #{act} the package at a specific version if it is installed at that version" do + @new_resource.stub!(:version).and_return("1.0") + @current_resource.stub!(:version).and_return("1.0") + @provider.should_receive(act_method).with( + @new_resource.name, + @new_resource.version + ).and_return(true) + @provider.send(act_symbol) + end + + it "should not #{act} the package at a specific version if it is not installed at that version" do + @new_resource.stub!(:version).and_return("1.0") + @current_resource.stub!(:version).and_return("1.2") + @provider.should_not_receive(act_method) + @provider.send(act_symbol) + end + + it "should not #{act} the package if it is not installed" do + @provider.should_not_receive(act_method) + @current_resource.stub!(:version).and_return(nil) + @provider.send(act_symbol) + end + + it "should set the resource to updated if it #{act}s the package" do + @new_resource.should_recieve(:updated).with(true) + @provider.send(act_symbol) + end + + end +end + +%w{install upgrade remove purge}.each do |act| + act_string = "#{act}_package" + + describe Chef::Provider::Package, act_string do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => nil, + :package_name => "emacs" + ) + @current_resource = mock("Chef::Resource::Package", + :null_object => true, + :name => "emacs", + :version => "0.99", + :package_name => "emacs" + ) + @provider = Chef::Provider::Package.new(@node, @new_resource) + @provider.candidate_version = "1.0" + @provider.current_resource = @current_resource + end + + it "should raise Chef::Exception::UnsupportedAction" do + lambda { @provider.send(act_string, @new_resource.name, @new_resource.version) }.should raise_error(Chef::Exception::UnsupportedAction) + end + end +end
\ No newline at end of file diff --git a/spec/unit/provider/remote_file_spec.rb b/chef/spec/unit/provider/remote_file_spec.rb index 51c48d0f9a..51c48d0f9a 100644 --- a/spec/unit/provider/remote_file_spec.rb +++ b/chef/spec/unit/provider/remote_file_spec.rb diff --git a/spec/unit/provider/template_spec.rb b/chef/spec/unit/provider/template_spec.rb index abc98e2ea3..9135bfb021 100644 --- a/spec/unit/provider/template_spec.rb +++ b/chef/spec/unit/provider/template_spec.rb @@ -21,7 +21,9 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_hel describe Chef::Provider::Template, "action_create" do before(:each) do @rest = mock(Chef::REST, { :get_rest => "/tmp/foobar" }) - @tempfile = mock(Tempfile, { :path => "/tmp/foo", }) + @tempfile = mock(Tempfile, { :path => "/tmp/foo", :print => true, :close => true }) + Tempfile.stub!(:new).and_return(@tempfile) + File.stub!(:read).and_return("monkeypoop") @rest.stub!(:get_rest).and_return(@tempfile) @resource = Chef::Resource::Template.new("seattle") @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) diff --git a/chef/spec/unit/provider/user_spec.rb b/chef/spec/unit/provider/user_spec.rb new file mode 100644 index 0000000000..9754688bed --- /dev/null +++ b/chef/spec/unit/provider/user_spec.rb @@ -0,0 +1,338 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) + +describe Chef::Provider::User, "initialize" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + + @provider = Chef::Provider::User.new(@node, @new_resource) + end + + it "should return a Chef::Provider::User" do + @provider.should be_a_kind_of(Chef::Provider::User) + end + + it "should assume the user exists by default" do + @provider.user_exists.should eql(true) + end + + it "should assume we do not know the locked state" do + @provider.locked.should eql(nil) + end +end + +describe Chef::Provider::User, "load_current_resource" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @current_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + Chef::Resource::User.stub!(:new).and_return(@current_resource) + @pw_user = mock("Etc::User", + :null_object => true, + :uid => "adam", + :gid => 1000, + :uid => 1000, + :comment => "Adam Jacob", + :home => "/home/adam", + :shell => "/usr/bin/zsh" + ) + Etc.stub!(:getpwnam).and_return(@pw_user) + + @provider = Chef::Provider::User.new(@node, @new_resource) + end + + it "should create a current resource with the same name as the new resource" do + Chef::Resource::User.should_receive(:new).with(@new_resource.name).and_return(@current_resource) + @provider.load_current_resource + end + + it "should set the username of the current resource to the username of the new resource" do + @current_resource.should_receive(:username).with(@new_resource.username) + @provider.load_current_resource + end + + it "should look up the user in /etc/passwd with getpwnam" do + Etc.should_receive(:getpwnam).with(@new_resource.username).and_return(@pw_user) + @provider.load_current_resource + end + + it "should set user_exists to false if the user is not found with getpwnam" do + Etc.should_receive(:getpwnam).and_raise(ArgumentError) + @provider.load_current_resource + @provider.user_exists.should eql(false) + end + + # The mapping between the Chef::Resource::User and Getpwnam struct + user_attrib_map = { + :uid => :uid, + :gid => :gid, + :comment => :gecos, + :home => :dir, + :shell => :shell + } + user_attrib_map.each do |user_attrib, getpwnam_attrib| + it "should set the current resources #{user_attrib} based on getpwnam #{getpwnam_attrib}" do + @current_resource.should_receive(user_attrib).with(@pw_user.send(getpwnam_attrib)) + @provider.load_current_resource + end + end + + it "should return the current resource" do + @provider.load_current_resource.should eql(@current_resource) + end +end + +describe Chef::Provider::User, "compare_user" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @current_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @provider = Chef::Provider::User.new(@node, @new_resource) + @provider.current_resource = @current_resource + end + + %w{uid gid comment home shell password}.each do |attribute| + it "should return true if #{attribute} doesn't match" do + @new_resource.should_receive(attribute).and_return(true) + @current_resource.should_receive(attribute).and_return(false) + @provider.compare_user.should eql(true) + end + end + + it "should return false if the objects are identical" do + @provider.compare_user.should eql(false) + end + +end + +describe Chef::Provider::User, "action_create" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @current_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @provider = Chef::Provider::User.new(@node, @new_resource) + @provider.current_resource = @current_resource + @provider.user_exists = false + @provider.stub!(:create_user).and_return(true) + @provider.stub!(:manage_user).and_return(true) + end + + it "should call create_user if the user does not exist" do + @provider.should_receive(:create_user).and_return(true) + @provider.action_create + end + + it "should set the the new_resources updated flag when it creates the user" do + @new_resource.should_receive(:updated=).with(true).and_return(true) + @provider.action_create + end + + it "should check to see if the user has mismatched attributes if the user exists" do + @provider.user_exists = true + @provider.should_receive(:compare_user).and_return(false) + @provider.action_create + end + + it "should call manage_user if the user exists and has mismatched attributes" do + @provider.user_exists = true + @provider.stub!(:compare_user).and_return(true) + @provider.should_receive(:manage_user).and_return(true) + @provider.action_create + end + + it "should set the the new_resources updated flag when it creates the user if we call manage_user" do + @provider.user_exists = true + @provider.stub!(:compare_user).and_return(true) + @provider.stub!(:manage_user).and_return(true) + @new_resource.should_receive(:updated=).with(true).and_return(true) + @provider.action_create + end + +end + +describe Chef::Provider::User, "action_remove" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @current_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @provider = Chef::Provider::User.new(@node, @new_resource) + @provider.current_resource = @current_resource + @provider.user_exists = false + @provider.stub!(:remove_user).and_return(true) + end + + it "should not call remove_user if the user does not exist" do + @provider.should_not_receive(:remove_user) + @provider.action_remove + end + + it "should call remove_user if the user exists" do + @provider.user_exists = true + @provider.should_receive(:remove_user) + @provider.action_remove + end + + it "should set the new_resources updated flag to true if the user is removed" do + @provider.user_exists = true + @new_resource.should_receive(:updated=).with(true).and_return(true) + @provider.action_remove + end +end + +describe Chef::Provider::User, "action_manage" do + before(:each) do + @node = mock("Chef::Node", :null_object => true) + @new_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @current_resource = mock("Chef::Resource::User", + :null_object => true, + :username => "adam", + :comment => "Adam Jacob", + :uid => 1000, + :gid => 1000, + :home => "/home/adam", + :shell => "/usr/bin/zsh", + :password => nil, + :updated => nil + ) + @provider = Chef::Provider::User.new(@node, @new_resource) + @provider.current_resource = @current_resource + @provider.user_exists = false + @provider.stub!(:remove_user).and_return(true) + end + + it "should not call remove_user if the user does not exist" do + @provider.should_not_receive(:remove_user) + @provider.action_remove + end + + it "should call remove_user if the user exists" do + @provider.user_exists = true + @provider.should_receive(:remove_user) + @provider.action_remove + end + + it "should set the new_resources updated flag to true if the user is removed" do + @provider.user_exists = true + @new_resource.should_receive(:updated=).with(true).and_return(true) + @provider.action_remove + end +end + diff --git a/spec/unit/provider_spec.rb b/chef/spec/unit/provider_spec.rb index 0512012598..0512012598 100644 --- a/spec/unit/provider_spec.rb +++ b/chef/spec/unit/provider_spec.rb diff --git a/spec/unit/queue_spec.rb b/chef/spec/unit/queue_spec.rb index e902f44631..e902f44631 100644 --- a/spec/unit/queue_spec.rb +++ b/chef/spec/unit/queue_spec.rb diff --git a/spec/unit/recipe_spec.rb b/chef/spec/unit/recipe_spec.rb index 77d5354993..011b944934 100644 --- a/spec/unit/recipe_spec.rb +++ b/chef/spec/unit/recipe_spec.rb @@ -112,7 +112,7 @@ CODE @recipe.from_file(File.join(File.dirname(__FILE__), "..", "data", "recipes", "test.rb")) res = @recipe.resources(:file => "/etc/nsswitch.conf") res.name.should eql("/etc/nsswitch.conf") - res.action.should eql(:create) + res.action.should eql([:create]) res.owner.should eql("root") res.group.should eql("root") res.mode.should eql(0644) diff --git a/spec/unit/resource/bash_spec.rb b/chef/spec/unit/resource/bash_spec.rb index f86e63d32e..f86e63d32e 100644 --- a/spec/unit/resource/bash_spec.rb +++ b/chef/spec/unit/resource/bash_spec.rb diff --git a/spec/unit/resource/csh_spec.rb b/chef/spec/unit/resource/csh_spec.rb index 67ba4499fa..67ba4499fa 100644 --- a/spec/unit/resource/csh_spec.rb +++ b/chef/spec/unit/resource/csh_spec.rb diff --git a/spec/unit/resource/directory_spec.rb b/chef/spec/unit/resource/directory_spec.rb index 98cc28fbc6..541472faca 100644 --- a/spec/unit/resource/directory_spec.rb +++ b/chef/spec/unit/resource/directory_spec.rb @@ -38,9 +38,9 @@ describe Chef::Resource::Directory do end it "should accept create or delete for action" do - lambda { @resource.action "create" }.should_not raise_error(ArgumentError) - lambda { @resource.action "delete" }.should_not raise_error(ArgumentError) - lambda { @resource.action "blues" }.should raise_error(ArgumentError) + lambda { @resource.action :create }.should_not raise_error(ArgumentError) + lambda { @resource.action :delete }.should_not raise_error(ArgumentError) + lambda { @resource.action :blues }.should raise_error(ArgumentError) end it "should accept a group name or id for group" do diff --git a/spec/unit/resource/execute_spec.rb b/chef/spec/unit/resource/execute_spec.rb index 94cb3d3d92..f2b7ab93f7 100644 --- a/spec/unit/resource/execute_spec.rb +++ b/chef/spec/unit/resource/execute_spec.rb @@ -59,9 +59,9 @@ describe Chef::Resource::Execute do @resource.group.should eql(1) end - it "should accept a string for onlyif" do - @resource.onlyif "woot" - @resource.onlyif.should eql("woot") + it "should accept a string for only_if" do + @resource.only_if "woot" + @resource.only_if.should eql("woot") end it "should accept an array for the execution path" do @@ -79,9 +79,9 @@ describe Chef::Resource::Execute do @resource.timeout.should eql(1) end - it "should accept a string for unless" do - @resource.unless "woot" - @resource.unless.should eql("woot") + it "should accept a string for not_if" do + @resource.not_if "woot" + @resource.not_if.should eql("woot") end it "should accept a string for the user" do diff --git a/spec/unit/resource/file_spec.rb b/chef/spec/unit/resource/file_spec.rb index b67598d738..a2ad122887 100644 --- a/spec/unit/resource/file_spec.rb +++ b/chef/spec/unit/resource/file_spec.rb @@ -54,10 +54,10 @@ describe Chef::Resource::File do end it "should accept create, delete or touch for action" do - lambda { @resource.action "create" }.should_not raise_error(ArgumentError) - lambda { @resource.action "delete" }.should_not raise_error(ArgumentError) - lambda { @resource.action "touch" }.should_not raise_error(ArgumentError) - lambda { @resource.action "blues" }.should raise_error(ArgumentError) + lambda { @resource.action :create }.should_not raise_error(ArgumentError) + lambda { @resource.action :delete }.should_not raise_error(ArgumentError) + lambda { @resource.action :touch }.should_not raise_error(ArgumentError) + lambda { @resource.action :blues }.should raise_error(ArgumentError) end it "should accept a group name or id for group" do diff --git a/spec/unit/resource/link_spec.rb b/chef/spec/unit/resource/link_spec.rb index fa0810cced..e2605e9bcf 100644 --- a/spec/unit/resource/link_spec.rb +++ b/chef/spec/unit/resource/link_spec.rb @@ -38,9 +38,9 @@ describe Chef::Resource::Link do end it "should accept create or delete for action" do - lambda { @resource.action "create" }.should_not raise_error(ArgumentError) - lambda { @resource.action "delete" }.should_not raise_error(ArgumentError) - lambda { @resource.action "blues" }.should raise_error(ArgumentError) + lambda { @resource.action :create }.should_not raise_error(ArgumentError) + lambda { @resource.action :delete }.should_not raise_error(ArgumentError) + lambda { @resource.action :blues }.should raise_error(ArgumentError) end it "should use the object name as the source_file by default" do diff --git a/spec/unit/resource/package_spec.rb b/chef/spec/unit/resource/package_spec.rb index 8756e4f603..8756e4f603 100644 --- a/spec/unit/resource/package_spec.rb +++ b/chef/spec/unit/resource/package_spec.rb diff --git a/spec/unit/resource/perl_spec.rb b/chef/spec/unit/resource/perl_spec.rb index 528bcef08c..528bcef08c 100644 --- a/spec/unit/resource/perl_spec.rb +++ b/chef/spec/unit/resource/perl_spec.rb diff --git a/spec/unit/resource/python_spec.rb b/chef/spec/unit/resource/python_spec.rb index 11c5b84d04..11c5b84d04 100644 --- a/spec/unit/resource/python_spec.rb +++ b/chef/spec/unit/resource/python_spec.rb diff --git a/spec/unit/resource/remote_directory_spec.rb b/chef/spec/unit/resource/remote_directory_spec.rb index 2d9ce122af..2d9ce122af 100644 --- a/spec/unit/resource/remote_directory_spec.rb +++ b/chef/spec/unit/resource/remote_directory_spec.rb diff --git a/spec/unit/resource/remote_file_spec.rb b/chef/spec/unit/resource/remote_file_spec.rb index 4c052e0260..4c052e0260 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/chef/spec/unit/resource/remote_file_spec.rb diff --git a/spec/unit/resource/ruby_spec.rb b/chef/spec/unit/resource/ruby_spec.rb index 5351462154..5351462154 100644 --- a/spec/unit/resource/ruby_spec.rb +++ b/chef/spec/unit/resource/ruby_spec.rb diff --git a/spec/unit/resource/script_spec.rb b/chef/spec/unit/resource/script_spec.rb index f003028fd6..f003028fd6 100644 --- a/spec/unit/resource/script_spec.rb +++ b/chef/spec/unit/resource/script_spec.rb diff --git a/spec/unit/resource/service_spec.rb b/chef/spec/unit/resource/service_spec.rb index f5941f89ae..f5941f89ae 100644 --- a/spec/unit/resource/service_spec.rb +++ b/chef/spec/unit/resource/service_spec.rb diff --git a/spec/unit/resource/template_spec.rb b/chef/spec/unit/resource/template_spec.rb index 106fe77bda..106fe77bda 100644 --- a/spec/unit/resource/template_spec.rb +++ b/chef/spec/unit/resource/template_spec.rb diff --git a/spec/unit/resource_collection_spec.rb b/chef/spec/unit/resource_collection_spec.rb index 37eeac18db..1b66e4793e 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/chef/spec/unit/resource_collection_spec.rb @@ -34,21 +34,11 @@ describe Chef::ResourceCollection do lambda { @rc[0] = "string" }.should raise_error end - it "should not accept duplicate resources [index]=" do - @rc[0] = @resource - lambda { @rc[1] = @resource }.should raise_error(ArgumentError) - end - it "should accept Chef::Resources through pushing" do lambda { @rc.push(@resource) }.should_not raise_error lambda { @rc.push("string") }.should raise_error end - it "should not accept duplicate resources through pushing" do - lambda { @rc.push(@resource) }.should_not raise_error - lambda { @rc.push(@resource) }.should raise_error(ArgumentError) - end - it "should allow you to fetch Chef::Resources by position" do @rc[0] = @resource @rc[0].should eql(@resource) @@ -58,11 +48,6 @@ describe Chef::ResourceCollection do lambda { @rc << @resource }.should_not raise_error end - it "should not accept duplicate resources through the << operator" do - lambda { @rc << @resource }.should_not raise_error - lambda { @rc << @resource }.should raise_error(ArgumentError) - end - it "should allow you to iterate over every resource in the collection" do load_up_resources results = Array.new diff --git a/spec/unit/resource_definition_spec.rb b/chef/spec/unit/resource_definition_spec.rb index 8ba7556b70..8ba7556b70 100644 --- a/spec/unit/resource_definition_spec.rb +++ b/chef/spec/unit/resource_definition_spec.rb diff --git a/spec/unit/resource_spec.rb b/chef/spec/unit/resource_spec.rb index 3ca48060fa..3ca48060fa 100644 --- a/spec/unit/resource_spec.rb +++ b/chef/spec/unit/resource_spec.rb diff --git a/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb index 56c2954a1a..471330189c 100644 --- a/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -103,6 +103,7 @@ describe Chef::REST, "run_request method" do @http_response_mock = mock("Net::HTTPSuccess", :null_object => true) @http_response_mock.stub!(:kind_of?).with(Net::HTTPSuccess).and_return(true) @http_response_mock.stub!(:body).and_return("ninja") + @http_response_mock.stub!(:error!).and_return(true) @http_mock = mock("Net::HTTP", :null_object => true) @http_mock.stub!(:verify_mode=).and_return(true) @http_mock.stub!(:read_timeout=).and_return(true) @@ -210,19 +211,31 @@ describe Chef::REST, "run_request method" do do_run_request(:GET, false, 10, true) end - it "should create a tempfile for the output of a raw request" do - Tempfile.should_receive(:new).with("chef-rest").and_return(@tf_mock) - do_run_request(:GET, false, 10, true).should eql(@tf_mock) - end - - it "should populate the tempfile with the value of the raw request" do - @tf_mock.should_receive(:print, "ninja").once.and_return(true) - do_run_request(:GET, false, 10, true) - end - - it "should close the tempfile if we're doing a raw request" do - @tf_mock.should_receive(:close).once.and_return(true) - do_run_request(:GET, false, 10, true) - end + ### + # TODO - Figure out how to test the http.request(foo) do |response| block + ### + # it "should create a tempfile for the output of a raw request" do + # fake_http = FakeHTTP.new + # fake_http.response_object = @http_response_mock + # Net::HTTP.stub!(:new).and_return(fake_http) + # Tempfile.should_receive(:new).with("chef-rest").and_return(@tf_mock) + # do_run_request(:GET, false, 10, true).should eql(@tf_mock) + # end + # + # it "should populate the tempfile with the value of the raw request" do + # fake_http = FakeHTTP.new + # fake_http.response_object = @http_response_mock + # Net::HTTP.stub!(:new).and_return(fake_http) + # @tf_mock.should_receive(:write, "ninja").once.and_return(true) + # do_run_request(:GET, false, 10, true) + # end + # + # it "should close the tempfile if we're doing a raw request" do + # fake_http = FakeHTTP.new + # fake_http.response_object = @http_response_mock + # Net::HTTP.stub!(:new).and_return(fake_http) + # @tf_mock.should_receive(:close).once.and_return(true) + # do_run_request(:GET, false, 10, true) + # end end diff --git a/spec/unit/runner_spec.rb b/chef/spec/unit/runner_spec.rb index f73d5efb22..f73d5efb22 100644 --- a/spec/unit/runner_spec.rb +++ b/chef/spec/unit/runner_spec.rb diff --git a/spec/unit/search_index_spec.rb b/chef/spec/unit/search_index_spec.rb index ff234c6a41..ff234c6a41 100644 --- a/spec/unit/search_index_spec.rb +++ b/chef/spec/unit/search_index_spec.rb diff --git a/spec/unit/search_spec.rb b/chef/spec/unit/search_spec.rb index 94e3560a23..94e3560a23 100644 --- a/spec/unit/search_spec.rb +++ b/chef/spec/unit/search_spec.rb diff --git a/stories/chef-client b/chef/stories/chef-client index 93b8656268..93b8656268 100644 --- a/stories/chef-client +++ b/chef/stories/chef-client diff --git a/stories/chef-client.rb b/chef/stories/chef-client.rb index 3e07b8a847..3e07b8a847 100644 --- a/stories/chef-client.rb +++ b/chef/stories/chef-client.rb diff --git a/stories/story_helper.rb b/chef/stories/story_helper.rb index cb0d1eb375..cb0d1eb375 100644 --- a/stories/story_helper.rb +++ b/chef/stories/story_helper.rb diff --git a/tasks/rspec.rb b/chef/tasks/rspec.rb index 80b0a79557..80b0a79557 100644 --- a/tasks/rspec.rb +++ b/chef/tasks/rspec.rb diff --git a/example-repository/Rakefile b/example-repository/Rakefile new file mode 100644 index 0000000000..0559eba641 --- /dev/null +++ b/example-repository/Rakefile @@ -0,0 +1,174 @@ +# +# Rakefile for Chef Server Repository +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.dirname(__FILE__), 'config', 'rake') + +require 'tempfile' + +$vcs = :svn +if File.directory?(File.join(TOPDIR, ".svn")) + $vcs = :svn +elsif File.directory?(File.join(TOPDIR, ".git")) + $vcs = :git +end + +desc "Update your repository from source control" +task :update do + puts "** Updating your repository" + + case $vcs + when :svn + sh %{svn up} + when :git + pull = false + pull = true if File.join(TOPDIR, ".git", "remotes", "origin") + IO.foreach(File.join(TOPDIR, ".git", "config")) do |line| + pull = true if line =~ /\[remote "origin"\]/ + end + if pull + sh %{git pull} + else + puts "* Skipping git pull, no origin specified" + end + end +end + +desc "Test your cookbooks for syntax errors" +task :test do + puts "** Testing your cookbooks for syntax errors" + Dir[ File.join(TOPDIR, "cookbooks", "**", "*.rb") ].each do |recipe| + sh %{ruby -c #{recipe}} do |ok, res| + if ! ok + raise "Syntax error in #{recipe}" + end + end + end +end + +desc "Install the latest copy of the repository on this Chef Server" +task :install => [ :update, :test ] do + puts "** Installing your cookbooks" + directories = [ + COOKBOOK_PATH, + SITE_COOKBOOK_PATH, + CHEF_CONFIG_PATH + ] + puts "* Creating Directories" + directories.each do |dir| + sh "sudo mkdir -p #{dir}" + sh "sudo chown root #{dir}" + end + puts "* Installing new Cookbooks" + sh "sudo rsync -rlP --delete --exclude '.svn' cookbooks/ #{COOKBOOK_PATH}" + puts "* Installing new Site Cookbooks" + sh "sudo rsync -rlP --delete --exclude '.svn' cookbooks/ #{COOKBOOK_PATH}" + puts "* Installing new Chef Server Config" + sh "sudo cp config/server.rb #{CHEF_SERVER_CONFIG}" + puts "* Installing new Chef Client Config" + sh "sudo cp config/client.rb #{CHEF_CLIENT_CONFIG}" +end + +desc "By default, run rake test" +task :default => [ :test ] + +desc "Create a new cookbook (with COOKBOOK=name)" +task :new_cookbook do + create_cookbook(File.join(TOPDIR, "cookbooks")) +end + +def create_cookbook(dir) + raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"] + puts "** Creating cookbook #{ENV["COOKBOOK"]}" + sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "attributes")}" + sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "recipes")}" + sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "definitions")}" + sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "libraries")}" + sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "files", "default")}" + sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "templates", "default")}" + unless File.exists?(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb")) + open(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb"), "w") do |file| + file.puts <<-EOH +# +# Cookbook Name:: #{ENV["COOKBOOK"]} +# Recipe:: default +# +# Copyright #{Time.now.year}, #{COMPANY_NAME} +# +EOH + case NEW_COOKBOOK_LICENSE + when :apachev2 + file.puts <<-EOH +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +EOH + when :none + file.puts <<-EOH +# All rights reserved - Do Not Redistribute +# +EOH + end + end + end +end + +desc "Create a new self-signed SSL certificate for FQDN=foo.example.com" +task :ssl_cert do + $expect_verbose = true + fqdn = ENV["FQDN"] + fqdn =~ /^(.+?)\.(.+)$/ + hostname = $1 + domain = $2 + raise "Must provide FQDN!" unless fqdn && hostname && domain + puts "** Creating self signed SSL Certificate for #{fqdn}" + sh("(cd #{CADIR} && openssl genrsa 2048 > #{fqdn}.key)") + sh("(cd #{CADIR} && chmod 644 #{fqdn}.key)") + puts "* Generating Self Signed Certificate Request" + tf = Tempfile.new("#{fqdn}.ssl-conf") + ssl_config = <<EOH +[ req ] +distinguished_name = req_distinguished_name +prompt = no + +[ req_distinguished_name ] +C = #{SSL_COUNTRY_NAME} +ST = #{SSL_STATE_NAME} +L = #{SSL_LOCALITY_NAME} +O = #{COMPANY_NAME} +OU = #{SSL_ORGANIZATIONAL_UNIT_NAME} +CN = #{fqdn} +emailAddress = #{SSL_EMAIL_ADDRESS} +EOH + tf.puts(ssl_config) + tf.close + sh("(cd #{CADIR} && openssl req -config '#{tf.path}' -new -x509 -nodes -sha1 -days 3650 -key #{fqdn}.key > #{fqdn}.crt)") + sh("(cd #{CADIR} && openssl x509 -noout -fingerprint -text < #{fqdn}.crt > #{fqdn}.info)") + sh("(cd #{CADIR} && cat #{fqdn}.crt #{fqdn}.key > #{fqdn}.pem)") + sh("(cd #{CADIR} && chmod 644 #{fqdn}.pem)") +end
\ No newline at end of file diff --git a/example-repository/config/client.rb b/example-repository/config/client.rb new file mode 100644 index 0000000000..3a6b5fde4a --- /dev/null +++ b/example-repository/config/client.rb @@ -0,0 +1,21 @@ +# +# Cookbook Name:: chef +# Attribute File:: client.rb +# +# Copyright 2008, Engine Yard, Inc. +# +# All rights reserved - Do Not Redistribute +# + +log_level :info +log_location STDOUT +file_store_path "/var/chef/file_store" +file_cache_path "/var/chef/cache" +ssl_verify_mode :verify_none +registration_url "http://127.0.0.1:4000" +openid_url "http://127.0.0.1:4001" +template_url "http://127.0.0.1:4000" +remotefile_url "http://127.0.0.1:4000" +search_url "http://127.0.0.1:4000" + + diff --git a/example-repository/config/rake.rb b/example-repository/config/rake.rb new file mode 100644 index 0000000000..3272a67b03 --- /dev/null +++ b/example-repository/config/rake.rb @@ -0,0 +1,54 @@ +### +# Company and SSL Details +### + +# The company name - used for SSL certificates, and in various other places +COMPANY_NAME = "Example Com" + +# The Country Name to use for SSL Certificates +SSL_COUNTRY_NAME = "US" + +# The State Name to use for SSL Certificates +SSL_STATE_NAME = "Washington" + +# The Locality Name for SSL - typically, the city +SSL_LOCALITY_NAME = "Seattle" + +# What department? +SSL_ORGANIZATIONAL_UNIT_NAME = "Operations" + +# The SSL contact email address +SSL_EMAIL_ADDRESS = "ops@example.com" + +# License for new Cookbooks +# Can be :apachev2 or :none +NEW_COOKBOOK_LICENSE = :apachev2 + +########################## +# Chef Repository Layout # +########################## + +# Where to find upstream cookbooks +COOKBOOK_PATH = "/var/chef/cookbooks" + +# Where to find site-local modifications to upstream cookbooks +SITE_COOKBOOK_PATH = "/var/chef/site-cookbooks" + +# Chef Config Path +CHEF_CONFIG_PATH = "/etc/chef" + +# The location of the Chef Server Config file (on the server) +CHEF_SERVER_CONFIG = File.join(CHEF_CONFIG_PATH, "server.rb") + +# The location of the Chef Client Config file (on the client) +CHEF_CLIENT_CONFIG = File.join(CHEF_CONFIG_PATH, "client.rb") + +### +# Useful Extras (which you probably don't need to change) +### + +# The top of the repository checkout +TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), "..")) + +# Where to store certificates generated with ssl_cert +CADIR = File.expand_path(File.join(TOPDIR, "certificates")) diff --git a/example-repository/config/server.rb b/example-repository/config/server.rb new file mode 100644 index 0000000000..f5557daa4a --- /dev/null +++ b/example-repository/config/server.rb @@ -0,0 +1,25 @@ +# +# Chef Server Config File +# +# Dynamically generated by Chef - local modifications will be replaced +# + + +log_level :info +log_location STDOUT +file_store_path "/var/chef/file_store" +file_cache_path "/var/chef/cache" +ssl_verify_mode :verify_none +registration_url "http://127.0.0.1:4000" +openid_url "http://127.0.0.1:4001" +template_url "http://127.0.0.1:4000" +remotefile_url "http://127.0.0.1:4000" +search_url "http://127.0.0.1:4000" +cookbook_path [ "/var/chef/site-cookbooks", "/var/chef/cookbooks" ] +node_path "/var/chef/nodes" +openid_store_path "/var/chef/openid/store" +openid_cstore_path "/var/chef/openid/cstore" +merb_log_path "/var/log/chef-server.log" +search_index_path "/var/chef/search_index" + +Chef::Log::Formatter.show_time = false diff --git a/example-repository/config/solo.rb b/example-repository/config/solo.rb new file mode 100644 index 0000000000..f5557daa4a --- /dev/null +++ b/example-repository/config/solo.rb @@ -0,0 +1,25 @@ +# +# Chef Server Config File +# +# Dynamically generated by Chef - local modifications will be replaced +# + + +log_level :info +log_location STDOUT +file_store_path "/var/chef/file_store" +file_cache_path "/var/chef/cache" +ssl_verify_mode :verify_none +registration_url "http://127.0.0.1:4000" +openid_url "http://127.0.0.1:4001" +template_url "http://127.0.0.1:4000" +remotefile_url "http://127.0.0.1:4000" +search_url "http://127.0.0.1:4000" +cookbook_path [ "/var/chef/site-cookbooks", "/var/chef/cookbooks" ] +node_path "/var/chef/nodes" +openid_store_path "/var/chef/openid/store" +openid_cstore_path "/var/chef/openid/cstore" +merb_log_path "/var/log/chef-server.log" +search_index_path "/var/chef/search_index" + +Chef::Log::Formatter.show_time = false diff --git a/example-repository/cookbooks/fakefile/attributes/first.rb b/example-repository/cookbooks/fakefile/attributes/first.rb new file mode 100644 index 0000000000..927dafe967 --- /dev/null +++ b/example-repository/cookbooks/fakefile/attributes/first.rb @@ -0,0 +1,2 @@ +Chef::Log.debug("You are the first of fakefile's attributes") +friends("you said we wuz visiting em")
\ No newline at end of file diff --git a/example-repository/cookbooks/fakefile/definitions/test.rb b/example-repository/cookbooks/fakefile/definitions/test.rb new file mode 100644 index 0000000000..ce32293943 --- /dev/null +++ b/example-repository/cookbooks/fakefile/definitions/test.rb @@ -0,0 +1,13 @@ +define :monkey, :eats => "bananna" do + file "/tmp/monkeynews-#{params[:name]}" do + owner "root" + mode 0644 + action :create + end + + file "/tmp/monkeynews-#{params[:name]}-second-#{params[:eats]}" do + owner "root" + mode 0644 + notifies :touch, resources(:file => "/tmp/monkeynews-#{params[:name]}"), :immediately + end +end
\ No newline at end of file diff --git a/example-repository/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt b/example-repository/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt new file mode 100644 index 0000000000..9664cb3e15 --- /dev/null +++ b/example-repository/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt @@ -0,0 +1 @@ +Classic rock is awesome. diff --git a/example-repository/cookbooks/fakefile/files/default/remote_test/another/window.txt b/example-repository/cookbooks/fakefile/files/default/remote_test/another/window.txt new file mode 100644 index 0000000000..68a3bf17e4 --- /dev/null +++ b/example-repository/cookbooks/fakefile/files/default/remote_test/another/window.txt @@ -0,0 +1 @@ +appleseed?
\ No newline at end of file diff --git a/example-repository/cookbooks/fakefile/files/default/remote_test/mycat.txt b/example-repository/cookbooks/fakefile/files/default/remote_test/mycat.txt new file mode 100644 index 0000000000..d4d8511934 --- /dev/null +++ b/example-repository/cookbooks/fakefile/files/default/remote_test/mycat.txt @@ -0,0 +1 @@ +is a very nice kitty
\ No newline at end of file diff --git a/example-repository/cookbooks/fakefile/files/default/the_park.txt b/example-repository/cookbooks/fakefile/files/default/the_park.txt new file mode 100644 index 0000000000..c71308a6ca --- /dev/null +++ b/example-repository/cookbooks/fakefile/files/default/the_park.txt @@ -0,0 +1,3 @@ +Is very pretty on a Saturday at 7:50 in August. Hottest day of the year so far in Seattle. + +something
\ No newline at end of file diff --git a/example-repository/cookbooks/fakefile/libraries/test.rb b/example-repository/cookbooks/fakefile/libraries/test.rb new file mode 100644 index 0000000000..5a39a18aec --- /dev/null +++ b/example-repository/cookbooks/fakefile/libraries/test.rb @@ -0,0 +1,7 @@ +class Chef + class Recipe + def bork + Chef::Log.debug("Bork bork bork") + end + end +end
\ No newline at end of file diff --git a/example-repository/cookbooks/fakefile/recipes/default.rb b/example-repository/cookbooks/fakefile/recipes/default.rb new file mode 100644 index 0000000000..709e51b6e3 --- /dev/null +++ b/example-repository/cookbooks/fakefile/recipes/default.rb @@ -0,0 +1,152 @@ +bork + +execute "write-foolio" do + command <<-EOH + echo 'monkeypants #{node[:ipaddress]} #{node[:friends]}' > /tmp/foolio + EOH + user "daemon" +end + +script "monkeylikesit" do + code %q{ +print "Woot!\n"; +open(FILE, ">", "/tmp/monkeylikesit") or die "Cannot open monkeylikesit"; +print FILE "You have some interesting hobbies #{node[:ipaddress]}"; +close(FILE); +} + interpreter "perl" +end + +perl "foobar" do + code %q{ +print "Woot!\n"; + } +end + +unless @node[:operatingsystem] == "Darwin" + package "emacs" + + package "emacs" do + action :remove + end + + package "emacs" do + version "22.1-0ubuntu10" + action :install + end + + package "emacs" do + action :upgrade + end + + package "emacs" do + action :purge + end +end + +package "ruby-djbdns" do + action [ :install, :remove, :upgrade, :purge ] + provider Chef::Provider::Package::Rubygems +end + +gem_package "ruby-djbdns" do + action [ :install, :remove, :upgrade, :purge ] +end + +file "/tmp/foo" do + owner "adam" + mode 0644 + action :create + notifies :delete, resources(:file => "/tmp/glen"), :delayed +end + +remote_file "/tmp/the_park.txt" do + owner "adam" + mode 0644 + source "the_park.txt" + action :create +end + +remote_directory "/tmp/remote_test" do + owner "adam" + mode 0755 + source "remote_test" + files_owner "root" + files_group(node[:operatingsystem] == "Debian" ? "root" : "wheel") + files_mode 0644 + files_backup false +end + +template "/tmp/foo-template" do + owner "adam" + mode 0644 + source "monkey.erb" + variables({ + :one => 'two', + :el_che => 'rhymefest', + :white => { + :stripes => "are the best", + :at => "the sleazy rock thing", + } + }) +end + +link "/tmp/foo" do + link_type :symbolic + target_file "/tmp/xmen" +end + +# 0.upto(1000) do |n| +# file "/tmp/somefile#{n}" do +# owner "adam" +# mode 0644 +# action :create +# end +# end + +directory "/tmp/home" do + owner "root" + mode 0755 + action :create +end + +search(:user, "*") do |u| + directory "/tmp/home/#{u['name']}" do + if u['name'] == "nobody" && @node[:operatingsystem] == "Darwin" + owner "root" + else + owner "#{u['name']}" + end + mode 0755 + action :create + end +end + +monkey "snoopy" do + eats "vegetables" +end + +monkey "snack" + +# user "katie" do +# uid 9999 +# gid 100 +# home "/tmp/home/katie" +# shell "/bin/bash" +# comment "Katie Bethell" +# action :create +# end +# +# user "katie" do +# gid 101 +# action :modify +# end +# +# user "katie" do +# shell "/home/katie" +# action :manage +# end +# +# user "katie" do +# action [ :lock, :unlock, :remove ] +# end diff --git a/example-repository/cookbooks/fakefile/templates/default/monkey.erb b/example-repository/cookbooks/fakefile/templates/default/monkey.erb new file mode 100644 index 0000000000..29c2639381 --- /dev/null +++ b/example-repository/cookbooks/fakefile/templates/default/monkey.erb @@ -0,0 +1,5 @@ +This is a <%= @one %> with <%= @el_che %> + +It was rendered on a system with the ipaddress of <%= @node[:ipaddress] %> + +But it's all about the conquest, with <%= @node[:fqdn ] %> diff --git a/example-repository/cookbooks/rubygems_server/attributes/first.rb b/example-repository/cookbooks/rubygems_server/attributes/first.rb new file mode 100644 index 0000000000..d1b7bd6a23 --- /dev/null +++ b/example-repository/cookbooks/rubygems_server/attributes/first.rb @@ -0,0 +1 @@ +rubygems("are awesome") diff --git a/example-repository/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem b/example-repository/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem Binary files differnew file mode 100644 index 0000000000..d3eafbca10 --- /dev/null +++ b/example-repository/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem diff --git a/example-repository/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem b/example-repository/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem Binary files differnew file mode 100644 index 0000000000..e9bc3c2276 --- /dev/null +++ b/example-repository/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem diff --git a/example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem b/example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem Binary files differnew file mode 100644 index 0000000000..b11cbe00cc --- /dev/null +++ b/example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem diff --git a/example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem b/example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem Binary files differnew file mode 100644 index 0000000000..545f850a71 --- /dev/null +++ b/example-repository/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem diff --git a/example-repository/cookbooks/rubygems_server/recipes/default.rb b/example-repository/cookbooks/rubygems_server/recipes/default.rb new file mode 100644 index 0000000000..6b60456094 --- /dev/null +++ b/example-repository/cookbooks/rubygems_server/recipes/default.rb @@ -0,0 +1,8 @@ +remote_directory "/srv/gems" do + owner "www-data" + mode 0755 + source "packages" + files_owner "www-data" + files_group "www-data" + files_mode 0644 +end diff --git a/example-repository/cookbooks/servicetest/recipes/default.rb b/example-repository/cookbooks/servicetest/recipes/default.rb new file mode 100644 index 0000000000..812b48e19d --- /dev/null +++ b/example-repository/cookbooks/servicetest/recipes/default.rb @@ -0,0 +1,12 @@ +service "puppet-client" do + service_name "puppet" + pattern "puppetd" + action :enable +end + +file "/tmp/foo" do + owner "aj" + mode 0644 + action :create + notifies :start, resources(:service => "puppet-client"), :immediate +end diff --git a/example-repository/cookbooks/tempfile/attributes/second.rb b/example-repository/cookbooks/tempfile/attributes/second.rb new file mode 100644 index 0000000000..df791b8429 --- /dev/null +++ b/example-repository/cookbooks/tempfile/attributes/second.rb @@ -0,0 +1 @@ +monkey "poots"
\ No newline at end of file diff --git a/example-repository/cookbooks/tempfile/files/default/packages/blank b/example-repository/cookbooks/tempfile/files/default/packages/blank new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/example-repository/cookbooks/tempfile/files/default/packages/blank diff --git a/example-repository/cookbooks/tempfile/files/default/packages/test b/example-repository/cookbooks/tempfile/files/default/packages/test new file mode 100644 index 0000000000..e84c65b247 --- /dev/null +++ b/example-repository/cookbooks/tempfile/files/default/packages/test @@ -0,0 +1 @@ +You would like that, wouldn't you?
\ No newline at end of file diff --git a/example-repository/cookbooks/tempfile/recipes/default.rb b/example-repository/cookbooks/tempfile/recipes/default.rb new file mode 100644 index 0000000000..b4fa86ac32 --- /dev/null +++ b/example-repository/cookbooks/tempfile/recipes/default.rb @@ -0,0 +1,24 @@ +file "/tmp/glen" do + owner "adam" + mode 0755 + action "create" +end + +file "/tmp/metallica" do + action [ :create, :touch, :delete ] +end + +directory "/tmp/marginal" do + owner "adam" + mode 0755 + action :create +end + +remote_directory "/tmp/rubygems" do + owner "adam" + mode 0755 + source "packages" + files_owner "adam" + files_group "adam" + files_mode 0755 +end diff --git a/example-repository/log/merb.main.log b/example-repository/log/merb.main.log new file mode 100644 index 0000000000..e8e8ec5320 --- /dev/null +++ b/example-repository/log/merb.main.log @@ -0,0 +1,2 @@ +Thu, 09 Oct 2008 21:27:28 GMT ~ info ~ Logfile created +Thu, 09 Oct 2008 21:27:28 GMT ~ info ~ Logfile created diff --git a/example-repository/log/merb.main.pid b/example-repository/log/merb.main.pid new file mode 100644 index 0000000000..94846e4488 --- /dev/null +++ b/example-repository/log/merb.main.pid @@ -0,0 +1 @@ +44404
\ No newline at end of file diff --git a/lib/chef/client.rb b/lib/chef/client.rb deleted file mode 100644 index 24f2ec7555..0000000000 --- a/lib/chef/client.rb +++ /dev/null @@ -1,162 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require File.join(File.dirname(__FILE__), "mixin", "params_validate") - -require 'rubygems' -require 'facter' - -class Chef - class Client - - attr_accessor :node, :registration, :safe_name - - # Creates a new Chef::Client. - def initialize() - @node = nil - @safe_name = nil - @registration = nil - @rest = Chef::REST.new(Chef::Config[:registration_url]) - end - - # Do a full run for this Chef::Client. Calls: - # - # * build_node - # * register - # * authenticate - # * do_attribute_files - # * save_node - # * converge - # - # In that order. - # - # === Returns - # true:: Always returns true. - def run - build_node - register - authenticate - do_attribute_files - save_node - converge - true - end - - # Builds a new node object for this client. Starts with querying for the FQDN of the current - # host (unless it is supplied), then merges in the facts from Facter. - # - # === Parameters - # node_name<String>:: The name of the node to build - defaults to nil - def build_node(node_name=nil) - node_name ||= Facter["fqdn"].value ? Facter["fqdn"].value : Facter["hostname"].value - @safe_name = node_name.gsub(/\./, '_') - begin - @node = @rest.get_rest("nodes/#{@safe_name}") - rescue Net::HTTPServerException => e - unless e.message =~ /^404/ - raise e - end - end - unless @node - @node ||= Chef::Node.new - @node.name(node_name) - end - Facter.each do |field, value| - @node[field] = value - end - @node - end - - # If this node has been registered before, this method will fetch the current registration - # data. - # - # If it has not, we register it by calling create_registration. - def register - @registration = nil - begin - @registration = @rest.get_rest("registrations/#{@safe_name}") - rescue Net::HTTPServerException => e - unless e.message =~ /^404/ - raise e - end - end - - if @registration - reg = Chef::FileStore.load("registration", @safe_name) - @secret = reg["secret"] - else - create_registration - end - end - - # Generates a random secret, stores it in the Chef::Filestore with the "registration" key, - # and posts our nodes registration information to the server. - def create_registration - @secret = random_password(500) - Chef::FileStore.store("registration", @safe_name, { "secret" => @secret }) - @rest.post_rest("registrations", { :id => @safe_name, :password => @secret }) - end - - # Authenticates the node via OpenID. - def authenticate - response = @rest.post_rest('openid/consumer/start', { - "openid_identifier" => "#{Chef::Config[:openid_url]}/openid/server/node/#{@safe_name}", - "submit" => "Verify" - }) - @rest.post_rest( - "#{Chef::Config[:openid_url]}#{response["action"]}", - { "password" => @secret } - ) - end - - # Gets all the attribute files included in all the cookbooks available on the server, - # and executes them. - def do_attribute_files - af_list = @rest.get_rest('cookbooks/_attribute_files') - af_list.each do |af| - @node.instance_eval(af["contents"], "#{af['cookbook']}/#{af['name']}", 1) - end - end - - # Updates the current node configuration on the server. - def save_node - @rest.put_rest("nodes/#{@safe_name}", @node) - end - - # Compiles the full list of recipes for the server, and passes it to an instance of - # Chef::Runner.converge. - def converge - results = @rest.get_rest("nodes/#{@safe_name}/compile") - results["collection"].resources.each do |r| - r.collection = results["collection"] - end - cr = Chef::Runner.new(results["node"], results["collection"]) - cr.converge - true - end - - protected - # Generates a random password of "len" length. - def random_password(len) - chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a - newpass = "" - 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } - newpass - end - - end -end
\ No newline at end of file diff --git a/lib/chef/provider/apt.rb b/lib/chef/provider/apt.rb deleted file mode 100644 index b0ea7d1d1d..0000000000 --- a/lib/chef/provider/apt.rb +++ /dev/null @@ -1,87 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.join(File.dirname(__FILE__), "package") -require File.join(File.dirname(__FILE__), "..", "mixin", "command") - -class Chef - class Provider - class Apt < Chef::Provider::Package - - def load_current_resource - @current_resource = Chef::Resource::Package.new(@new_resource.name) - @current_resource.package_name(@new_resource.package_name) - - status = popen4("apt-cache policy #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| - stdin.close - stdout.each do |line| - case line - when /^\s{2}Installed: (.+)$/ - installed_version = $1 - if installed_version == '(none)' - @current_resource.version(nil) - else - @current_resource.version(installed_version) - end - when /^\s{2}Candidate: (.+)$/ - @candidate_version = $1 - end - end - end - - unless status.exitstatus == 0 - raise Chef::Exception::Package, "apt-cache failed - #{status.inspect}!" - end - - @current_resource - end - - def install_package(name, version) - run_command( - :command => "apt-get -q -y install #{name}=#{version}", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - ) - end - - def upgrade_package(name, version) - install_package(name, version) - end - - def remove_package(name, version) - run_command( - :command => "apt-get -q -y remove #{@new_resource.package_name}", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - ) - end - - def purge_package(name, version) - run_command( - :command => "apt-get -q -y purge #{@new_resource.package_name}", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - ) - end - - end - end -end diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb deleted file mode 100644 index 3eb70e594e..0000000000 --- a/lib/chef/provider/service/init.rb +++ /dev/null @@ -1,93 +0,0 @@ -# -# Author:: AJ Christensen (<aj@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.join(File.dirname(__FILE__), "..", "service") -require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command") - -class Chef - class Provider - class Init < Chef::Provider::Service - - def load_current_resource - @current_resource = Chef::Resource::Service.new(@new_resource.name) - @current_resource.service_name(@new_resource.service_name) - process_running = false - if @new_resource.supports[:status] - run_command(:command => "/etc/init.d/#{@current_resource.service_name} status") == 0 ? process_running = true : process_running = false - elsif @new_resource.status_command - run_command(:command => @new_resource.status_command) == 0 ? process_running = true : process_running = false - else - Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection") - if @new_resource.pattern == @new_resource.service_name - Chef::Log.debug("#{@new_resource} defaulting pattern to #{Regex.new(@new_resource.pattern)}") - elsif Facter["ps"].value == "" - raise Chef::Exception::Service, "#{@new_resource}: Facter could not determine how to call `ps` on your system (#{Facter["ps"].value})" - end - - process_pid = nil - status = popen4(Facter["ps"].value) do |pid, stdin, stdout, stderr| - stdin.close - r = Regexp.new(@new_resource.pattern) - Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table") - stdout.each_line do |line| - if r.match(line) - process_pid = line.sub(/^\s+/, '').split(/\s+/)[1] - end - end - end - unless status.exitstatus == 0 - raise Chef::Exception::Service, "Command #{Facter["ps"].value} failed" - else - process_pid ? process_running = true : process_running = false - Chef::Log.debug("#{@new_resource}: #{Facter["ps"].value} exited succesfully, process_running: #{process_running}") - end - end - @current_resource.running process_running - @current_resource - end - - def start_service(name) - if @new_resource.start_command - run_command(:command => @new_resource.start_command) - else - run_command(:command => "/etc/init.d/#{name} start") - end - end - - def stop_service(name) - if @new_resource.stop_command - run_command(:command => @new_resource.stop_command) - else - run_command(:command => "/etc/init.d/#{name} stop") - end - end - - def restart_service(name) - if @new_resource.supports[:restart] - run_command(:command => "/etc/init.d/#{name} restart") - elsif @new_resource.restart_command - run_command(:command => @new_resource.restart_command) - else - stop_service - start_service - end - end - - end - end -end diff --git a/lib/chef_server/public/stylesheets/master.css b/lib/chef_server/public/stylesheets/master.css deleted file mode 100644 index 13bdffbe1b..0000000000 --- a/lib/chef_server/public/stylesheets/master.css +++ /dev/null @@ -1,292 +0,0 @@ -/* body { - font-family: Arial, Verdana, sans-serif; - font-size: 12px; - background-color: #fff; - margin: ; -} -html { - height: 100%; - margin-bottom: 1px; -} -#container { - width: 80%; - text-align: left; - background-color: #fff; - margin-right: auto; - margin-left: auto; -} -#header-container { - width: 100%; - padding-top: 15px; -} -#header-container h1, #header-container h2 { - margin-left: 6px; - margin-bottom: 6px; -} -.spacer { - width: 100%; - height: 15px; -} -hr { - border: 0px; - color: #ccc; - background-color: #cdcdcd; - height: 1px; - width: 100%; - text-align: left; -} -h1 { - font-size: 28px; - color: #c55; - background-color: #fff; - font-family: Arial, Verdana, sans-serif; - font-weight: 300; -} -h2 { - font-size: 15px; - color: #999; - font-family: Arial, Verdana, sans-serif; - font-weight: 300; - background-color: #fff; -} -h3 { - color: #4d9b12; - font-size: 15px; - text-align: left; - font-weight: 300; - padding: 5px; - margin-top: 5px; -} - -#left-container { - float: left; - width: 250px; - background-color: #FFFFFF; - color: black; -} - -#left-container h3 { - color: #c55; -} - -#main-container { - margin: 5px 5px 5px 260px; - padding: 15px; - border-left: 1px solid silver; - min-height: 400px; -} -p { - color: #000; - background-color: #fff; - line-height: 20px; - padding: 5px; -} -a { - color: #4d9b12; - background-color: #fff; - text-decoration: none; -} -a:hover { - color: #4d9b12; - background-color: #fff; - text-decoration: underline; -} -#footer-container { - clear: both; - font-size: 12px; - font-family: Verdana, Arial, sans-serif; -} -.right { - float: right; - font-size: 100%; - margin-top: 5px; - color: #999; - background-color: #fff; -} -.left { - float: left; - font-size: 100%; - margin-top: 5px; - color: #999; - background-color: #fff; -} -#main-container ul { - margin-left: 3.0em; -} - -div.resource_collection { - border: 1px solid #999; - float: left; - clear: both; - margin: 10px; - padding: 5px; -} - -div.resource { - border-top: 1px solid #999; - float: left; - clear: both; -} - -div.attr_group { - float: left; - clear: both; -} - -td.attr_name { - font-weight: bold; - margin-right: 10px; - border-right: 1px solid #999; -} - -td.attr_value { - padding-left: 5px; - border-top: 1px solid #999; -} - -div.node { - float: left; - clear: both; - margin: 10px; - padding: 5px; - border: 1px solid #999; -} -*/ - -pre.twilight .DiffInserted { - background-color: #253B22; - color: #F8F8F8; -} -pre.twilight .DiffHeader { - background-color: #0E2231; - color: #F8F8F8; - font-style: italic; -} -pre.twilight .CssPropertyValue { - color: #F9EE98; -} -pre.twilight .CCCPreprocessorDirective { - color: #AFC4DB; -} -pre.twilight .Constant { - color: #CF6A4C; -} -pre.twilight .DiffChanged { - background-color: #4A410D; - color: #F8F8F8; -} -pre.twilight .EmbeddedSource { - background-color: #A3A6AD; -} -pre.twilight .Support { - color: #9B859D; -} -pre.twilight .MarkupList { - color: #F9EE98; -} -pre.twilight .CssConstructorArgument { - color: #8F9D6A; -} -pre.twilight .Storage { - color: #F9EE98; -} -pre.twilight .line-numbers { - background-color: #DDF0FF; - color: #000000; -} -pre.twilight .CssClass { - color: #9B703F; -} -pre.twilight .StringConstant { - color: #DDF2A4; -} -pre.twilight .CssAtRule { - color: #8693A5; -} -pre.twilight .MetaTagInline { - color: #E0C589; -} -pre.twilight .MarkupHeading { - color: #CF6A4C; -} -pre.twilight .CssTagName { - color: #CDA869; -} -pre.twilight .SupportConstant { - color: #CF6A4C; -} -pre.twilight .DiffDeleted { - background-color: #420E09; - color: #F8F8F8; -} -pre.twilight .CCCPreprocessorLine { - color: #8996A8; -} -pre.twilight .StringRegexpSpecial { - color: #CF7D34; -} -pre.twilight .EmbeddedSourceBright { - background-color: #9C9EA4; -} -pre.twilight .InvalidIllegal { - background-color: #241A24; - color: #F8F8F8; -} -pre.twilight .SupportFunction { - color: #DAD085; -} -pre.twilight .CssAdditionalConstants { - color: #CA7840; -} -pre.twilight .MetaTagAll { - color: #AC885B; -} -pre.twilight .StringRegexp { - color: #E9C062; -} -pre.twilight .StringEmbeddedSource { - color: #DAEFA3; -} -pre.twilight .EntityInheritedClass { - color: #9B5C2E; - font-style: italic; -} -pre.twilight .CssId { - color: #8B98AB; -} -pre.twilight .CssPseudoClass { - color: #8F9D6A; -} -pre.twilight .StringVariable { - color: #8A9A95; -} -pre.twilight .String { - color: #8F9D6A; -} -pre.twilight .Keyword { - color: #CDA869; -} -pre.twilight { - background-color: #141414; - color: #F8F8F8; -} -pre.twilight .CssPropertyName { - color: #C5AF75; -} -pre.twilight .DoctypeXmlProcessing { - color: #494949; -} -pre.twilight .InvalidDeprecated { - color: #D2A8A1; - font-style: italic; -} -pre.twilight .Variable { - color: #7587A6; -} -pre.twilight .Entity { - color: #9B703F; -} -pre.twilight .Comment { - color: #5F5A60; - font-style: italic; -} diff --git a/lib/chef_server/views/cookbooks/_attribute_file.html.haml b/lib/chef_server/views/cookbooks/_attribute_file.html.haml deleted file mode 100644 index cfe773f3d1..0000000000 --- a/lib/chef_server/views/cookbooks/_attribute_file.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%h3= name -= Uv.parse(contents, "xhtml", "ruby", true, "twilight")
\ No newline at end of file diff --git a/lib/chef_server/views/cookbooks/show.html.haml b/lib/chef_server/views/cookbooks/show.html.haml deleted file mode 100644 index d97964f436..0000000000 --- a/lib/chef_server/views/cookbooks/show.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -%h1= "Cookbook #{h @cookbook.name}" -.cookbook -- if @cookbook.attribute_files.length > 0 - %h2 Attribute Files - - @cookbook.attribute_files.each do |af| - = partial(:attribute_file, :name => File.basename(af), :contents => File.read(af)) - -- if @cookbook.definition_files.length > 0 - - @cookbook.definition_files.each do |df| - %h2 Definition Files - %h3= File.basename(df) - = Uv.parse(File.read(df), "xhtml", "ruby", true, "twilight") - -- if @cookbook.recipe_files.length > 0 - - @cookbook.recipe_files.each do |rf| - %h2 Recipe Files - %h3= File.basename(rf) - = Uv.parse(File.read(rf), "xhtml", "ruby", true, "twilight") - -- if @cookbook.template_files.length > 0 - - @cookbook.template_files.each do |tf| - %h2 Template Files - %h3= File.basename(tf) - = Uv.parse(File.read(tf), "xhtml", "html_rails", true, "twilight") diff --git a/log/chef-server.log b/log/chef-server.log deleted file mode 100644 index eabfde15a0..0000000000 --- a/log/chef-server.log +++ /dev/null @@ -1,9 +0,0 @@ -Mon, 16 Jun 2008 01:13:56 GMT ~ info ~ Logfile created - ~ Compiling routes... - ~ Using 'share-nothing' cookie sessions (4kb limit per client) - ~ Using Mongrel adapter - ~ Compiling routes... - ~ Using 'share-nothing' cookie sessions (4kb limit per client) - ~ Using Mongrel adapter - ~ Using 'share-nothing' cookie sessions (4kb limit per client) - ~ Using Mongrel adapter diff --git a/log/merb_test.log b/log/merb_test.log deleted file mode 100644 index dae0e5d9dd..0000000000 --- a/log/merb_test.log +++ /dev/null @@ -1,7 +0,0 @@ -Tue, 03 Jun 2008 04:33:52 GMT ~ info ~ Logfile created - ~ Not Using Sessions - ~ Not Using Sessions - ~ Not Using Sessions - ~ Not Using Sessions - ~ Not Using Sessions - ~ Not Using Sessions diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb deleted file mode 100644 index a2732f28c3..0000000000 --- a/spec/unit/client_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Client, "initialize" do - it "should create a new Chef::Client object" do - Chef::Client.new.should be_kind_of(Chef::Client) - end -end - -describe Chef::Client, "build_node" do - before(:each) do - @mock_facter_fqdn = mock("Facter FQDN") - @mock_facter_fqdn.stub!(:value).and_return("foo.bar.com") - @mock_facter_hostname = mock("Facter Hostname") - @mock_facter_hostname.stub!(:value).and_return("foo") - Facter.stub!(:[]).with("fqdn").and_return(@mock_facter_fqdn) - Facter.stub!(:[]).with("hostname").and_return(@mock_facter_hostname) - Facter.stub!(:each).and_return(true) - @client = Chef::Client.new - end - - it "should set the name equal to the FQDN" do - @client.build_node - @client.node.name.should eql("foo.bar.com") - end - - it "should set the name equal to the hostname if FQDN is not available" do - @mock_facter_fqdn.stub!(:value).and_return(nil) - @client.build_node - @client.node.name.should eql("foo") - end -end - -describe Chef::Client, "register" do - before(:each) do - @client = Chef::Client.new - end - - it "should check to see if it's already registered" - - it "should create a new passphrase if not registered" - - it "should create a new registration if it has not registered" -end
\ No newline at end of file |