diff options
author | John Keiser <jkeiser@opscode.com> | 2014-08-29 10:39:00 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-08-29 22:01:17 -0700 |
commit | b3be31b52cc0aabb86526edcc705c6166d34acaa (patch) | |
tree | 2fc577eb5f0e3042ed23c9e16dd02b72f66947c3 | |
parent | d1350f296095ff70baafbd4f5fa1e3737a4924d2 (diff) | |
download | chef-b3be31b52cc0aabb86526edcc705c6166d34acaa.tar.gz |
Switch back to ChefZero::RSpec version 3jk/rspec_zero_3
And add some Enterprise tests (fix an acl delete issue)
-rw-r--r-- | chef.gemspec | 2 | ||||
-rw-r--r-- | lib/chef/chef_fs/file_system/acl_entry.rb | 2 | ||||
-rw-r--r-- | lib/chef/config.rb | 2 | ||||
-rw-r--r-- | spec/integration/knife/delete_spec.rb | 14 | ||||
-rw-r--r-- | spec/integration/knife/deps_spec.rb | 50 | ||||
-rw-r--r-- | spec/integration/knife/download_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/knife/list_spec.rb | 114 | ||||
-rw-r--r-- | spec/integration/knife/raw_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/knife/show_spec.rb | 4 | ||||
-rw-r--r-- | spec/integration/knife/upload_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/shared/integration/chef_zero_support.rb | 130 | ||||
-rw-r--r-- | spec/support/shared/integration/integration_helper.rb | 20 |
12 files changed, 171 insertions, 173 deletions
diff --git a/chef.gemspec b/chef.gemspec index a1e4bfc2aa..33fb9dce06 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |s| s.add_dependency "erubis", "~> 2.7" s.add_dependency "diff-lcs", "~> 1.2", ">= 1.2.4" - s.add_dependency "chef-zero", "~> 3.0" + s.add_dependency "chef-zero", "~> 3.1" s.add_dependency "pry", "~> 0.9" s.add_dependency 'plist', '~> 3.1.0' diff --git a/lib/chef/chef_fs/file_system/acl_entry.rb b/lib/chef/chef_fs/file_system/acl_entry.rb index 1bd03a6095..b2545af5ae 100644 --- a/lib/chef/chef_fs/file_system/acl_entry.rb +++ b/lib/chef/chef_fs/file_system/acl_entry.rb @@ -32,7 +32,7 @@ class Chef end def delete(recurse) - raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self, e), "ACLs cannot be deleted." + raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self), "ACLs cannot be deleted." end def write(file_contents) diff --git a/lib/chef/config.rb b/lib/chef/config.rb index 08a377ca12..0cf13b79da 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -119,7 +119,7 @@ class Chef # === Parameters # url<String>:: String to be set for all of the chef-server-api URL's # - configurable(:chef_server_url).writes_value { |url| url.strip } + configurable(:chef_server_url).writes_value { |url| url.to_s.strip } # When you are using ActiveSupport, they monkey-patch 'daemonize' into Kernel. # So while this is basically identical to what method_missing would do, we pull diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb index efbfa1004b..dc52cc71a4 100644 --- a/spec/integration/knife/delete_spec.rb +++ b/spec/integration/knife/delete_spec.rb @@ -961,4 +961,18 @@ EOM end end end + + when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do + before do + organization 'foo' + end + + before :each do + Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') + end + + it 'knife delete /acls/containers/environments.json fails with a reasonable error' do + knife('delete /acls/containers/environments.json').should_fail "ERROR: /acls/containers/environments.json (remote) cannot be deleted.\n" + end + end end diff --git a/spec/integration/knife/deps_spec.rb b/spec/integration/knife/deps_spec.rb index 7ee6138739..2cbb7b8f74 100644 --- a/spec/integration/knife/deps_spec.rb +++ b/spec/integration/knife/deps_spec.rb @@ -114,7 +114,8 @@ EOM when_the_repository 'has a cookbook with dependencies' do before do file 'cookbooks/kettle/metadata.rb', 'name "kettle"' - file 'cookbooks/quiche/metadata.rb', "name 'quiche'\ndepends 'kettle'\n" + file 'cookbooks/quiche/metadata.rb', 'name "quiche" +depends "kettle"' file 'cookbooks/quiche/recipes/default.rb', '' end it 'knife deps reports just the cookbook' do @@ -204,10 +205,14 @@ EOM context 'circular dependencies' do when_the_repository 'has cookbooks with circular dependencies' do before do - file 'cookbooks/foo/metadata.rb', "name 'foo'\ndepends 'bar'\n" - file 'cookbooks/bar/metadata.rb', "name 'bar'\ndepends 'baz'\n" - file 'cookbooks/baz/metadata.rb', "name 'baz'\ndepends 'foo'\n" - file 'cookbooks/self/metadata.rb', "name 'self'\ndepends 'self'\n" + file 'cookbooks/foo/metadata.rb', 'name "foo" +depends "bar"' + file 'cookbooks/bar/metadata.rb', 'name "bar" +depends "baz"' + file 'cookbooks/baz/metadata.rb', 'name "baz" +depends "foo"' + file 'cookbooks/self/metadata.rb', 'name "self" +depends "self"' end it 'knife deps prints each once' do @@ -379,8 +384,8 @@ EOM before do role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } role 'minor', {} - cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } + cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } + cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{name "soup"\nversion "1.0.0"\n}, 'recipes' => { 'chicken.rb' => '' } } end it 'knife deps reports all dependencies' do knife('deps --remote /roles/starring.json').should_succeed <<EOM @@ -396,8 +401,8 @@ EOM before do role 'starring', { 'env_run_lists' => { 'desert' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } } role 'minor', {} - cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } + cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } + cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{name "soup"\nversion "1.0.0"\n}, 'recipes' => { 'chicken.rb' => '' } } end it 'knife deps reports all dependencies' do knife('deps --remote /roles/starring.json').should_succeed <<EOM @@ -427,8 +432,8 @@ EOM when_the_chef_server 'has a node with roles and recipes in its run_list' do before do role 'minor', {} - cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } + cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } + cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{name "soup"\nversion "1.0.0"\n}, 'recipes' => { 'chicken.rb' => '' } } node 'mort', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } end it 'knife deps reports just the node' do @@ -442,7 +447,7 @@ EOM end when_the_chef_server 'has a cookbook with no dependencies' do before do - cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } + cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } end it 'knife deps reports just the cookbook' do knife('deps --remote /cookbooks/quiche').should_succeed "/cookbooks/quiche\n" @@ -450,8 +455,9 @@ EOM end when_the_chef_server 'has a cookbook with dependencies' do before do - cookbook 'kettle', '1.0.0', { 'metadata.rb' => "name 'kettle'\nversion '1.0.0'\n" } - cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\ndepends 'kettle'\n", 'recipes' => { 'default.rb' => '' } } + cookbook 'kettle', '1.0.0', { 'metadata.rb' => %Q{name "kettle"\nversion "1.0.0"\n} } + cookbook 'quiche', '1.0.0', { 'metadata.rb' => 'name "quiche" +depends "kettle"', 'recipes' => { 'default.rb' => '' } } end it 'knife deps reports the cookbook and its dependencies' do knife('deps --remote /cookbooks/quiche').should_succeed "/cookbooks/kettle\n/cookbooks/quiche\n" @@ -473,8 +479,8 @@ EOM before do role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } role 'minor', {} - cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } } + cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } + cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{name "soup"\nversion "1.0.0"\n}, 'recipes' => { 'chicken.rb' => '' } } environment 'desert', {} node 'mort', { 'chef_environment' => 'desert', 'run_list' => [ 'role[starring]' ] } node 'bart', { 'run_list' => [ 'role[minor]' ] } @@ -538,10 +544,14 @@ EOM context 'circular dependencies' do when_the_chef_server 'has cookbooks with circular dependencies' do before do - cookbook 'foo', '1.0.0', { 'metadata.rb' => "name 'foo'\ndepends 'bar'\n" } - cookbook 'bar', '1.0.0', { 'metadata.rb' => "name 'bar'\ndepends 'baz'\n" } - cookbook 'baz', '1.0.0', { 'metadata.rb' => "name 'baz'\ndepends 'foo'\n" } - cookbook 'self', '1.0.0', { 'metadata.rb' => "name 'self'\ndepends 'self'\n" } + cookbook 'foo', '1.0.0', { 'metadata.rb' => 'name "foo" +depends "bar"' } + cookbook 'bar', '1.0.0', { 'metadata.rb' => 'name "bar" +depends "baz"' } + cookbook 'baz', '1.0.0', { 'metadata.rb' => 'name "baz" +depends "foo"' } + cookbook 'self', '1.0.0', { 'metadata.rb' => 'name "self" +depends "self"' } end it 'knife deps prints each once' do knife('deps --remote /cookbooks/foo /cookbooks/self').should_succeed <<EOM diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb index 2ef5dc03c1..4126acc9fc 100644 --- a/spec/integration/knife/download_spec.rb +++ b/spec/integration/knife/download_spec.rb @@ -903,7 +903,7 @@ EOM when_the_repository 'has a cookbook' do before do - file 'cookbooks/x-1.0.0/metadata.rb', 'name "x"; version "1.0.0"' + file 'cookbooks/x-1.0.0/metadata.rb', 'name "x"; version "1.0.0"#unmodified' file 'cookbooks/x-1.0.0/z.rb', '' end diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb index 31dba2407d..1f70d3bc3d 100644 --- a/spec/integration/knife/list_spec.rb +++ b/spec/integration/knife/list_spec.rb @@ -641,4 +641,118 @@ EOM end end end + + when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do + before do + organization 'foo' + end + + before :each do + Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') + end + + context 'and has plenty of stuff in it' do + it "knife list / returns all top level directories" do + knife('list /').should_succeed <<EOM +/acls +/clients +/containers +/cookbooks +/data_bags +/environments +/groups +/nodes +/roles +EOM + end + + it "knife list -R / returns everything" do + knife('list -R /').should_succeed <<EOM +/: +acls +clients +containers +cookbooks +data_bags +environments +groups +nodes +roles + +/acls: +clients +containers +cookbooks +data_bags +environments +groups +nodes +organization.json +roles + +/acls/clients: +foo-validator.json + +/acls/containers: +clients.json +containers.json +cookbooks.json +data.json +environments.json +groups.json +nodes.json +roles.json +sandboxes.json + +/acls/cookbooks: + +/acls/data_bags: + +/acls/environments: +_default.json + +/acls/groups: +admins.json +billing-admins.json +clients.json +users.json + +/acls/nodes: + +/acls/roles: + +/clients: +foo-validator.json + +/containers: +clients.json +containers.json +cookbooks.json +data.json +environments.json +groups.json +nodes.json +roles.json +sandboxes.json + +/cookbooks: + +/data_bags: + +/environments: +_default.json + +/groups: +admins.json +billing-admins.json +clients.json +users.json + +/nodes: + +/roles: +EOM + end + end + end end diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb index 080ea0f21b..fad69e4e11 100644 --- a/spec/integration/knife/raw_spec.rb +++ b/spec/integration/knife/raw_spec.rb @@ -169,7 +169,7 @@ EOM knife("raw -m POST -i #{file.path} /roles").should_succeed <<EOM { - "uri": "#{ChefZeroSupport::Server.server.url}/roles/y" + "uri": "#{Chef::Config.chef_server_url}/roles/y" } EOM knife('show /roles/y.json').should_succeed <<EOM diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb index 3a20f96a11..4a71499e87 100644 --- a/spec/integration/knife/show_spec.rb +++ b/spec/integration/knife/show_spec.rb @@ -51,13 +51,13 @@ describe 'knife show' do it 'knife show /cookbooks/x/metadata.rb shows the remote version' do knife('show /cookbooks/x/metadata.rb').should_succeed <<EOM /cookbooks/x/metadata.rb: -name 'x'; version '1.0.0' +name "x"; version "1.0.0" EOM end it 'knife show --local /cookbooks/x/metadata.rb shows the local version' do knife('show --local /cookbooks/x/metadata.rb').should_succeed <<EOM /cookbooks/x/metadata.rb: -name 'x'; version '1.0.0' +name "x"; version "1.0.0" EOM end it 'knife show /data_bags/x/y.json shows the remote version' do diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index d8db27f73b..4e447589f3 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -487,7 +487,7 @@ EOM Updated /cookbooks/x EOM # Modify a file and attempt to upload - file 'cookbooks/x/metadata.rb', "name 'x'; version '1.0.0'#different" + file 'cookbooks/x/metadata.rb', 'name "x"; version "1.0.0"#different' knife('upload /cookbooks/x').should_fail "ERROR: /cookbooks failed to write: Cookbook x is frozen\n" end end diff --git a/spec/support/shared/integration/chef_zero_support.rb b/spec/support/shared/integration/chef_zero_support.rb deleted file mode 100644 index 6505f0d066..0000000000 --- a/spec/support/shared/integration/chef_zero_support.rb +++ /dev/null @@ -1,130 +0,0 @@ -require 'tempfile' -require 'chef_zero/server' -require 'chef_zero/rest_request' - -# This is a copy of chef_zero/rspec, modified to implement contextual -# helpers as instance_methods rather than class methods. This makes it -# possible to use them with let bindings and other RSpec code reuse -# mechanisms. -# -# Unfortunately, at the time of this writing, chef-zero master doesn't -# work for our rspec tests, so in the interests of making forward -# progress, we're using a modified version of the chef_zero/rspec code -# here. -# -# This file should be entirely replaced by chef_zero/rspec once these -# issues are fixed. -module ChefZeroSupport - module Server - - def self.server - @server - end - def self.server=(value) - @server = value - end - def self.client_key - @client_key - end - def self.client_key=(value) - @client_key = value - end - def self.request_log - @request_log ||= [] - end - def self.clear_request_log - @request_log = [] - end - - end - - def client(name, client) - ChefZeroSupport::Server.server.load_data({ 'clients' => { name => client }}) - end - - def cookbook(name, version, cookbook = {}, options = {}) - - auto_metadata = "name '#{name}'; version '#{version}'" - - cookbook["metadata.rb"] ||= auto_metadata - - ChefZeroSupport::Server.server.load_data({ 'cookbooks' => { "#{name}-#{version}" => cookbook.merge(options) }}) - end - - def data_bag(name, data_bag) - ChefZeroSupport::Server.server.load_data({ 'data' => { name => data_bag }}) - end - - def environment(name, environment) - ChefZeroSupport::Server.server.load_data({ 'environments' => { name => environment }}) - end - - def node(name, node) - ChefZeroSupport::Server.server.load_data({ 'nodes' => { name => node }}) - end - - def role(name, role) - ChefZeroSupport::Server.server.load_data({ 'roles' => { name => role }}) - end - - def user(name, user) - ChefZeroSupport::Server.server.load_data({ 'users' => { name => user }}) - end - - RSpec.shared_context "With chef-zero running" do - before :each do - - default_opts = {:port => 8900, :signals => false, :log_requests => true} - server_opts = if self.respond_to?(:chef_zero_opts) - default_opts.merge(chef_zero_opts) - else - default_opts - end - - if ChefZeroSupport::Server.server && server_opts.any? { |opt, value| ChefZeroSupport::Server.server.options[opt] != value } - ChefZeroSupport::Server.server.stop - ChefZeroSupport::Server.server = nil - end - - unless ChefZeroSupport::Server.server - # TODO: can this be logged easily? - # pp :zero_opts => server_opts - - # Set up configuration so that clients will point to the server - ChefZeroSupport::Server.server = ChefZero::Server.new(server_opts) - ChefZeroSupport::Server.client_key = Tempfile.new(['chef_zero_client_key', '.pem']) - ChefZeroSupport::Server.client_key.write(ChefZero::PRIVATE_KEY) - ChefZeroSupport::Server.client_key.close - # Start the server - ChefZeroSupport::Server.server.start_background - ChefZeroSupport::Server.server.on_response do |request, response| - ChefZeroSupport::Server.request_log << [ request, response ] - end - else - ChefZeroSupport::Server.server.clear_data - end - ChefZeroSupport::Server.clear_request_log - - if defined?(Chef::Config) - @old_chef_server_url = Chef::Config.chef_server_url - @old_node_name = Chef::Config.node_name - @old_client_key = Chef::Config.client_key - Chef::Config.chef_server_url = ChefZeroSupport::Server.server.url - Chef::Config.node_name = 'admin' - Chef::Config.client_key = ChefZeroSupport::Server.client_key.path - Chef::Config.http_retry_count = 0 - end - end - - if defined?(Chef::Config) - after :each do - Chef::Config.chef_server_url = @old_chef_server_url - Chef::Config.node_name = @old_node_name - Chef::Config.client_key = @old_client_key - end - end - - end - -end - diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb index 5369b56f5b..a6595e778d 100644 --- a/spec/support/shared/integration/integration_helper.rb +++ b/spec/support/shared/integration/integration_helper.rb @@ -20,11 +20,7 @@ require 'tmpdir' require 'fileutils' require 'chef/config' - -# Temporarily use our own copy of chef-zero rspec integration. -# See support/shared/integration/chef_zero_support for details -#require 'chef_zero/rspec' -require 'support/shared/integration/chef_zero_support' +require 'chef_zero/rspec' require 'chef/json_compat' require 'support/shared/integration/knife_support' @@ -32,21 +28,15 @@ require 'support/shared/integration/app_server_support' require 'spec_helper' module IntegrationSupport - include ChefZeroSupport + include ChefZero::RSpec module ClassMethods - - def when_the_chef_server(desc, *tags, &block) - context("when the chef server #{desc}", *tags) do - #include ChefZero::RSpec::Fixtures - include_context "With chef-zero running" - module_eval(&block) - end - end + include ChefZero::RSpec def when_the_repository(desc, *tags, &block) context("when the chef repo #{desc}", *tags) do include_context "with a chef repo" + module_eval(&block) end end @@ -101,7 +91,7 @@ module IntegrationSupport end def cb_metadata(name, version, extra_text="") - "name '#{name}'; version '#{version}'#{extra_text}" + "name #{name.inspect}; version #{version.inspect}#{extra_text}" end def cwd(relative_path) |