summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-09-16 10:14:50 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-09-16 10:14:50 -0700
commit8fa661058877d5b465f4969e8fef9475af8f96a8 (patch)
treecac594c74c66ec2aef5af10ccae4a57ac57e8f55
parentc7d8640e30f9d0d9063ff5fcedfb0183174d7e6c (diff)
parenta2e0493968d8bdec76b3ec99a34203d80485384c (diff)
downloadchef-8fa661058877d5b465f4969e8fef9475af8f96a8.tar.gz
Make Chef::Config resettable with mixlib-config 2.0 API
-rw-r--r--chef.gemspec2
-rw-r--r--lib/chef/config.rb152
-rw-r--r--spec/functional/knife/cookbook_delete_spec.rb7
-rw-r--r--spec/functional/knife/exec_spec.rb7
-rw-r--r--spec/functional/knife/ssh_spec.rb6
-rw-r--r--spec/functional/resource/package_spec.rb8
-rw-r--r--spec/support/shared/functional/file_resource.rb26
-rw-r--r--spec/support/shared/integration/integration_helper.rb13
-rw-r--r--spec/support/shared/integration/knife_support.rb4
-rw-r--r--spec/unit/config_spec.rb14
-rw-r--r--spec/unit/encrypted_data_bag_item_spec.rb12
-rw-r--r--spec/unit/knife/bootstrap_spec.rb8
-rw-r--r--spec/unit/knife/ssh_spec.rb6
-rw-r--r--spec/unit/knife_spec.rb3
-rw-r--r--spec/unit/mixin/securable_spec.rb10
-rw-r--r--spec/unit/provider/remote_file/ftp_spec.rb5
-rw-r--r--spec/unit/util/diff_spec.rb9
17 files changed, 149 insertions, 143 deletions
diff --git a/chef.gemspec b/chef.gemspec
index a21eae5982..5b3e7694f6 100644
--- a/chef.gemspec
+++ b/chef.gemspec
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.email = "adam@opscode.com"
s.homepage = "http://wiki.opscode.com/display/chef"
- s.add_dependency "mixlib-config", ">= 2.0.0.rc.1"
+ s.add_dependency "mixlib-config", ">= 2.0.0.rc.3"
s.add_dependency "mixlib-cli", "~> 1.3.0"
s.add_dependency "mixlib-log", ">= 1.3.0"
s.add_dependency "mixlib-authentication", ">= 1.3.0"
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index 6fcc5b9f7b..725815681a 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -202,25 +202,25 @@ class Chef
default(:user_path) { derive_path_from_chef_repo_path('users') }
# Turn on "path sanity" by default. See also: http://wiki.opscode.com/display/chef/User+Environment+PATH+Sanity
- enforce_path_sanity(true)
+ default :enforce_path_sanity, true
# Formatted Chef Client output is a beta feature, disabled by default:
- formatter "null"
+ default :formatter, "null"
# The number of times the client should retry when registering with the server
- client_registration_retries 5
+ default :client_registration_retries, 5
# An array of paths to search for knife exec scripts if they aren't in the current directory
- script_path []
+ default :script_path, []
# Where cookbook files are stored on the server (by content checksum)
- checksum_path '/var/chef/checksums'
+ default :checksum_path, '/var/chef/checksums'
# Where chef's cache files should be stored
- file_cache_path platform_specific_path('/var/chef/cache')
+ default :file_cache_path, platform_specific_path('/var/chef/cache')
# Where backups of chef-managed files should go
- file_backup_path platform_specific_path('/var/chef/backup')
+ default :file_backup_path, platform_specific_path('/var/chef/backup')
# By default, chef-client (or solo) creates a lockfile in
# `file_cache_path`/chef-client-running.pid
@@ -229,13 +229,13 @@ class Chef
# If your `file_cache_path` resides on a NFS (or non-flock()-supporting
# fs), it's recommended to set this to something like
# '/tmp/chef-client-running.pid'
- lockfile nil
+ default :lockfile, nil
## Daemonization Settings ##
# What user should Chef run as?
- user nil
- group nil
- umask 0022
+ default :user, nil
+ default :group, nil
+ default :umask, 0022
# Valid log_levels are:
# * :debug
@@ -248,50 +248,50 @@ class Chef
# in a console), the log level is set to :warn, and output formatters are
# used as the primary mode of output. When a tty is not available, the
# logger is the primary mode of output, and the log level is set to :info
- log_level :auto
+ default :log_level, :auto
# Using `force_formatter` causes chef to default to formatter output when STDOUT is not a tty
- force_formatter false
+ default :force_formatter, false
# Using `force_logger` causes chef to default to logger output when STDOUT is a tty
- force_logger false
+ default :force_logger, false
- http_retry_count 5
- http_retry_delay 5
- interval nil
- json_attribs nil
- log_location STDOUT
+ default :http_retry_count, 5
+ default :http_retry_delay, 5
+ default :interval, nil
+ default :json_attribs, nil
+ default :log_location, STDOUT
# toggle info level log items that can create a lot of output
- verbose_logging true
- node_name nil
- diff_disabled false
- diff_filesize_threshold 10000000
- diff_output_threshold 1000000
-
- pid_file nil
-
- chef_server_url "https://localhost:443"
-
- rest_timeout 300
- yum_timeout 900
- solo false
- splay nil
- why_run false
- color false
- client_fork true
- enable_reporting true
- enable_reporting_url_fatals false
+ default :verbose_logging, true
+ default :node_name, nil
+ default :diff_disabled, false
+ default :diff_filesize_threshold, 10000000
+ default :diff_output_threshold, 1000000
+
+ default :pid_file, nil
+
+ default :chef_server_url, "https://localhost:443"
+
+ default :rest_timeout, 300
+ default :yum_timeout, 900
+ default :solo, false
+ default :splay, nil
+ default :why_run, false
+ default :color, false
+ default :client_fork, true
+ default :enable_reporting, true
+ default :enable_reporting_url_fatals, false
# Set these to enable SSL authentication / mutual-authentication
# with the server
- ssl_client_cert nil
- ssl_client_key nil
- ssl_verify_mode :verify_none
- ssl_ca_path nil
- ssl_ca_file nil
+ default :ssl_client_cert, nil
+ default :ssl_client_key, nil
+ default :ssl_verify_mode, :verify_none
+ default :ssl_ca_path, nil
+ default :ssl_ca_file, nil
# Where should chef-solo download recipes from?
- recipe_url nil
+ default :recipe_url, nil
# Sets the version of the signed header authentication protocol to use (see
# the 'mixlib-authorization' project for more detail). Currently, versions
@@ -307,7 +307,7 @@ class Chef
#
# In the future, this configuration option may be replaced with an
# automatic negotiation scheme.
- authentication_protocol_version "1.0"
+ default :authentication_protocol_version, "1.0"
# This key will be used to sign requests to the Chef server. This location
# must be writable by Chef during initial setup when generating a client
@@ -315,17 +315,19 @@ class Chef
#
# The chef-server will look up the public key for the client using the
# `node_name` of the client.
- client_key platform_specific_path("/etc/chef/client.pem")
+ default :client_key, platform_specific_path("/etc/chef/client.pem")
# This secret is used to decrypt encrypted data bag items.
- encrypted_data_bag_secret platform_specific_path("/etc/chef/encrypted_data_bag_secret")
-
- # We have to check for the existence of the default file before setting it
- # since +Chef::Config[:encrypted_data_bag_secret]+ is read by older
- # bootstrap templates to determine if the local secret should be uploaded to
- # node being bootstrapped. This should be removed in Chef 12.
- unless File.exist?(platform_specific_path("/etc/chef/encrypted_data_bag_secret"))
- encrypted_data_bag_secret(nil)
+ default(:encrypted_data_bag_secret) do
+ # We have to check for the existence of the default file before setting it
+ # since +Chef::Config[:encrypted_data_bag_secret]+ is read by older
+ # bootstrap templates to determine if the local secret should be uploaded to
+ # node being bootstrapped. This should be removed in Chef 12.
+ if File.exist?(platform_specific_path("/etc/chef/encrypted_data_bag_secret"))
+ platform_specific_path("/etc/chef/encrypted_data_bag_secret")
+ else
+ nil
+ end
end
# As of Chef 11.0, version "1" is the default encrypted data bag item
@@ -333,7 +335,7 @@ class Chef
# To maintain compatibility, versions other than 1 must be opt-in.
#
# Set this to `2` if you have chef-client 11.6.0+ in your infrastructure:
- data_bag_encrypt_version 1
+ default :data_bag_encrypt_version, 1
# When reading data bag items, any supported version is accepted. However,
# if all encrypted data bags have been generated with the version 2 format,
@@ -341,7 +343,7 @@ class Chef
# security. For example, the version 2 format is identical to version 1
# except for the addition of an HMAC, so an attacker with MITM capability
# could downgrade an encrypted data bag to version 1 as part of an attack.
- data_bag_decrypt_minimum_version 0
+ default :data_bag_decrypt_minimum_version, 0
# If there is no file in the location given by `client_key`, chef-client
# will temporarily use the "validator" identity to generate one. If the
@@ -349,23 +351,23 @@ class Chef
# chef-client will not be able to authenticate to the server.
#
# The `validation_key` is never used if the `client_key` exists.
- validation_key platform_specific_path("/etc/chef/validation.pem")
- validation_client_name "chef-validator"
+ default :validation_key, platform_specific_path("/etc/chef/validation.pem")
+ default :validation_client_name, "chef-validator"
# Zypper package provider gpg checks. Set to true to enable package
# gpg signature checking. This will be default in the
# future. Setting to false disables the warnings.
# Leaving this set to nil or false is a security hazard!
- zypper_check_gpg nil
+ default :zypper_check_gpg, nil
# Report Handlers
- report_handlers []
+ default :report_handlers, []
# Exception Handlers
- exception_handlers []
+ default :exception_handlers, []
# Start handlers
- start_handlers []
+ default :start_handlers, []
# Syntax Check Cache. Knife keeps track of files that is has already syntax
# checked by storing files in this directory. `syntax_check_cache_path` is
@@ -376,16 +378,16 @@ class Chef
# by `knife configure`), the default for now is to *not* set
# syntax_check_cache_path, and thus fallback to cache_options[:path]. We
# leave that value to the same default as was previously set.
- syntax_check_cache_path nil
+ default :syntax_check_cache_path, nil
# Deprecated:
- cache_options({ :path => platform_specific_path("/var/chef/cache/checksums") })
+ default :cache_options, { :path => platform_specific_path("/var/chef/cache/checksums") }
# Set to false to silence Chef 11 deprecation warnings:
- chef11_deprecation_warnings true
+ default :chef11_deprecation_warnings, true
# Arbitrary knife configuration data
- knife Hash.new
+ config_context :knife
# Those lists of regular expressions define what chef considers a
# valid user and group name
@@ -393,31 +395,31 @@ class Chef
# From http://technet.microsoft.com/en-us/library/cc776019(WS.10).aspx
principal_valid_regex_part = '[^"\/\\\\\[\]\:;|=,+*?<>]+'
- user_valid_regex [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
- group_valid_regex [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
+ default :user_valid_regex, [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
+ default :group_valid_regex, [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
- fatal_windows_admin_check false
+ default :fatal_windows_admin_check, false
else
- user_valid_regex [ /^([-a-zA-Z0-9_.]+[\\@]?[-a-zA-Z0-9_.]+)$/, /^\d+$/ ]
- group_valid_regex [ /^([-a-zA-Z0-9_.\\@^ ]+)$/, /^\d+$/ ]
+ default :user_valid_regex, [ /^([-a-zA-Z0-9_.]+[\\@]?[-a-zA-Z0-9_.]+)$/, /^\d+$/ ]
+ default :group_valid_regex, [ /^([-a-zA-Z0-9_.\\@^ ]+)$/, /^\d+$/ ]
end
# returns a platform specific path to the user home dir
windows_home_path = ENV['SYSTEMDRIVE'] + ENV['HOMEPATH'] if ENV['SYSTEMDRIVE'] && ENV['HOMEPATH']
- user_home(ENV['HOME'] || windows_home_path || ENV['USERPROFILE'])
+ default :user_home, (ENV['HOME'] || windows_home_path || ENV['USERPROFILE'])
# Enable file permission fixup for selinux. Fixup will be done
# only if selinux is enabled in the system.
- enable_selinux_file_permission_fixup true
+ default :enable_selinux_file_permission_fixup, true
# Use atomic updates (i.e. move operation) while updating contents
# of the files resources. When set to false copy operation is
# used to update files.
- file_atomic_update true
+ default :file_atomic_update, true
# If false file staging is will be done via tempfiles that are
# created under ENV['TMP'] otherwise tempfiles will be created in
# the directory that files are going to reside.
- file_staging_uses_destdir false
+ default :file_staging_uses_destdir, false
end
end
diff --git a/spec/functional/knife/cookbook_delete_spec.rb b/spec/functional/knife/cookbook_delete_spec.rb
index a6dba9bc28..568e1a7bb4 100644
--- a/spec/functional/knife/cookbook_delete_spec.rb
+++ b/spec/functional/knife/cookbook_delete_spec.rb
@@ -21,13 +21,13 @@ require 'tiny_server'
describe Chef::Knife::CookbookDelete do
before(:all) do
- @original_config = Chef::Config.hash_dup
-
@server = TinyServer::Manager.new
@server.start
end
before(:each) do
+ Chef::Config.reset
+
@knife = Chef::Knife::CookbookDelete.new
@api = TinyServer::API.instance
@api.clear
@@ -38,7 +38,8 @@ describe Chef::Knife::CookbookDelete do
end
after(:all) do
- Chef::Config.configuration = @original_config
+ # Be a good citizen
+ Chef::Config.reset
@server.stop
end
diff --git a/spec/functional/knife/exec_spec.rb b/spec/functional/knife/exec_spec.rb
index 1bccbdeb7a..7b31bcebbf 100644
--- a/spec/functional/knife/exec_spec.rb
+++ b/spec/functional/knife/exec_spec.rb
@@ -21,13 +21,13 @@ require 'tiny_server'
describe Chef::Knife::Exec do
before(:all) do
- @original_config = Chef::Config.hash_dup
-
@server = TinyServer::Manager.new#(:debug => true)
@server.start
end
before(:each) do
+ Chef::Config.reset
+
@knife = Chef::Knife::Exec.new
@api = TinyServer::API.instance
@api.clear
@@ -40,7 +40,8 @@ describe Chef::Knife::Exec do
end
after(:all) do
- Chef::Config.configuration = @original_config
+ # Be a good citizen
+ Chef::Config.reset
@server.stop
end
diff --git a/spec/functional/knife/ssh_spec.rb b/spec/functional/knife/ssh_spec.rb
index a853e8de19..d4aa42af2c 100644
--- a/spec/functional/knife/ssh_spec.rb
+++ b/spec/functional/knife/ssh_spec.rb
@@ -22,16 +22,14 @@ require 'tiny_server'
describe Chef::Knife::Ssh do
before(:all) do
- @original_config = Chef::Config.hash_dup
- @original_knife_config = Chef::Config[:knife].dup
+ Chef::Config.reset
Chef::Knife::Ssh.load_deps
@server = TinyServer::Manager.new
@server.start
end
after(:all) do
- Chef::Config.configuration = @original_config
- Chef::Config[:knife] = @original_knife_config
+ Chef::Config.reset
@server.stop
end
diff --git a/spec/functional/resource/package_spec.rb b/spec/functional/resource/package_spec.rb
index 24ad96d135..cc416e9a23 100644
--- a/spec/functional/resource/package_spec.rb
+++ b/spec/functional/resource/package_spec.rb
@@ -202,7 +202,7 @@ describe Chef::Resource::Package, metadata do
let(:file_cache_path) { Dir.mktmpdir }
before do
- @old_config = Chef::Config.configuration.dup
+ Chef::Config.reset
Chef::Config[:file_cache_path] = file_cache_path
debconf_reset = 'chef-integration-test chef-integration-test/sample-var string "INVALID"'
shell_out!("echo #{debconf_reset} |debconf-set-selections")
@@ -210,7 +210,11 @@ describe Chef::Resource::Package, metadata do
after do
FileUtils.rm_rf(file_cache_path)
- Chef::Config.configuration = @old_config
+ end
+
+ after :all do
+ # Be a good citizen
+ Chef::Config.reset
end
context "with a preseed file" do
diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb
index 30f012bb0d..2f49966db0 100644
--- a/spec/support/shared/functional/file_resource.rb
+++ b/spec/support/shared/functional/file_resource.rb
@@ -18,45 +18,53 @@
shared_context "deploying with move" do
before do
- @original_atomic_update = Chef::Config[:file_atomic_update]
+ Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
Chef::Config[:file_atomic_update] = true
end
after do
- Chef::Config[:file_atomic_update] = @original_atomic_update
+ Chef::Config.delete(:file_staging_uses_destdir)
+ Chef::Config.delete(:file_backup_path)
+ Chef::Config.delete(:file_atomic_update)
end
end
shared_context "deploying with copy" do
before do
- @original_atomic_update = Chef::Config[:file_atomic_update]
+ Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
Chef::Config[:file_atomic_update] = false
end
after do
- Chef::Config[:file_atomic_update] = @original_atomic_update
+ Chef::Config.delete(:file_staging_uses_destdir)
+ Chef::Config.delete(:file_backup_path)
+ Chef::Config.delete(:file_atomic_update)
end
end
shared_context "deploying via tmpdir" do
before do
- @original_stage_via = Chef::Config[:file_staging_uses_destdir]
Chef::Config[:file_staging_uses_destdir] = false
+ Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
end
after do
- Chef::Config[:file_staging_uses_destdir] = @original_stage_via
+ Chef::Config.delete(:file_staging_uses_destdir)
+ Chef::Config.delete(:file_backup_path)
+ Chef::Config.delete(:file_atomic_update)
end
end
shared_context "deploying via destdir" do
before do
- @original_stage_via = Chef::Config[:file_staging_uses_destdir]
Chef::Config[:file_staging_uses_destdir] = true
+ Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
end
after do
- Chef::Config[:file_staging_uses_destdir] = @original_stage_via
+ Chef::Config.delete(:file_staging_uses_destdir)
+ Chef::Config.delete(:file_backup_path)
+ Chef::Config.delete(:file_atomic_update)
end
end
@@ -75,7 +83,6 @@ shared_examples_for "a file with the wrong content" do
context "when running action :create" do
context "with backups enabled" do
before do
- Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
resource.run_action(:create)
end
@@ -99,7 +106,6 @@ shared_examples_for "a file with the wrong content" do
context "with backups disabled" do
before do
- Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
resource.backup(0)
resource.run_action(:create)
end
diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb
index 359072a197..5a86abb45b 100644
--- a/spec/support/shared/integration/integration_helper.rb
+++ b/spec/support/shared/integration/integration_helper.rb
@@ -30,14 +30,10 @@ module IntegrationSupport
def self.extended(base)
base.before :each do
- # We mess with Chef::Config a lot. Save and restore it.
- @old_chef_config = Chef::Config.configuration
- Chef::Config.configuration = Chef::Config.configuration.dup
- Chef::Config.repo_mode = nil
- Chef::Config.versioned_cookbooks = nil
+ Chef::Config.reset
end
- base.after :each do
- Chef::Config.configuration = @old_chef_config
+ base.after :all do
+ Chef::Config.reset
end
end
@@ -145,7 +141,7 @@ module IntegrationSupport
_m = { :versioned_cookbooks => true }.merge(_metadata)
context 'with versioned cookbooks', _m do
before(:each) { Chef::Config[:versioned_cookbooks] = true }
- after(:each) { Chef::Config[:versioned_cookbooks] = false }
+ after(:each) { Chef::Config.delete(:versioned_cookbooks) }
instance_eval(&block)
end
end
@@ -155,6 +151,7 @@ module IntegrationSupport
context 'with versioned cookbooks', _m do
# Just make sure this goes back to default
before(:each) { Chef::Config[:versioned_cookbooks] = false }
+ after(:each) { Chef::Config.delete(:versioned_cookbooks) }
instance_eval(&block)
end
end
diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb
index d2aa153004..f84227d8e9 100644
--- a/spec/support/shared/integration/knife_support.rb
+++ b/spec/support/shared/integration/knife_support.rb
@@ -38,7 +38,6 @@ module KnifeSupport
# Work on machines where we can't access /var
checksums_cache_dir = Dir.mktmpdir('checksums') do |checksums_cache_dir|
- old_cache_options = Chef::Config[:cache_options]
Chef::Config[:cache_options] = {
:path => checksums_cache_dir,
:skip_expires => true
@@ -94,7 +93,8 @@ module KnifeSupport
ensure
Chef::Log.use_log_devices(old_loggers)
Chef::Log.level = old_log_level
- Chef::Config[:cache_options] = old_cache_options
+ Chef::Config.delete(:cache_options)
+ Chef::Config.delete(:concurrency)
end
KnifeResult.new(stdout.string, stderr.string, exit_code)
diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb
index 5d10b6927b..0460e4dc71 100644
--- a/spec/unit/config_spec.rb
+++ b/spec/unit/config_spec.rb
@@ -22,10 +22,18 @@ require 'chef/exceptions'
describe Chef::Config do
before(:all) do
- @original_config = Chef::Config.hash_dup
@original_env = { 'HOME' => ENV['HOME'], 'SYSTEMDRIVE' => ENV['SYSTEMDRIVE'], 'HOMEPATH' => ENV['HOMEPATH'], 'USERPROFILE' => ENV['USERPROFILE'] }
end
+ before :each do
+ Chef::Config.reset
+ end
+
+ after :all do
+ # Be a good citizen
+ Chef::Config.reset
+ end
+
describe "config attribute writer: chef_server_url" do
before do
Chef::Config.chef_server_url = "https://junglist.gen.nz"
@@ -278,8 +286,4 @@ describe Chef::Config do
expect{Chef::Config.log_location = missing_path}.to raise_error Chef::Exceptions::ConfigurationError
end
end
-
- after(:each) do
- Chef::Config.configuration = @original_config
- end
end
diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb
index 9eda1633ab..8b123d23a3 100644
--- a/spec/unit/encrypted_data_bag_item_spec.rb
+++ b/spec/unit/encrypted_data_bag_item_spec.rb
@@ -74,12 +74,12 @@ describe Chef::EncryptedDataBagItem::Encryptor do
describe "when using version 2 format" do
before do
- @original_config = Chef::Config.hash_dup
+ Chef::Config.reset
Chef::Config[:data_bag_encrypt_version] = 2
end
after do
- Chef::Config.configuration = @original_config
+ Chef::Config.reset
end
it "creates a version 2 encryptor" do
@@ -179,12 +179,12 @@ describe Chef::EncryptedDataBagItem::Decryptor do
context "and version 2 format is required" do
before do
- @original_config = Chef::Config.hash_dup
+ Chef::Config.reset
Chef::Config[:data_bag_decrypt_minimum_version] = 2
end
after do
- Chef::Config.configuration = @original_config
+ Chef::Config.reset
end
it "raises an error attempting to decrypt" do
@@ -210,12 +210,12 @@ describe Chef::EncryptedDataBagItem::Decryptor do
context "and version 1 format is required" do
before do
- @original_config = Chef::Config.hash_dup
+ Chef::Config.reset
Chef::Config[:data_bag_decrypt_minimum_version] = 1
end
after do
- Chef::Config.configuration = @original_config
+ Chef::Config.reset
end
it "raises an error attempting to decrypt" do
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index c716896302..fd12010508 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -23,13 +23,11 @@ require 'net/ssh'
describe Chef::Knife::Bootstrap do
before(:all) do
- @original_config = Chef::Config.hash_dup
- @original_knife_config = Chef::Config[:knife].dup
+ Chef::Config.reset
end
after(:all) do
- Chef::Config.configuration = @original_config
- Chef::Config[:knife] = @original_knife_config
+ Chef::Config.reset
end
before(:each) do
@@ -182,7 +180,7 @@ describe Chef::Knife::Bootstrap do
it "renders the client.rb with an encrypted_data_bag_secret entry" do
rendered_template.should match(%r{encrypted_data_bag_secret\s*"/etc/chef/encrypted_data_bag_secret"})
end
- after(:each) { Chef::Config.configuration = @original_config }
+ after(:each) { Chef::Config.reset }
end
end
diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb
index 7f1ed0e321..438e5acd3b 100644
--- a/spec/unit/knife/ssh_spec.rb
+++ b/spec/unit/knife/ssh_spec.rb
@@ -22,14 +22,12 @@ require 'net/ssh/multi'
describe Chef::Knife::Ssh do
before(:all) do
- @original_config = Chef::Config.hash_dup
- @original_knife_config = Chef::Config[:knife].dup
+ Chef::Config.reset
Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
end
after(:all) do
- Chef::Config.configuration = @original_config
- Chef::Config[:knife] = @original_knife_config
+ Chef::Config.reset
end
before do
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 4c5bb3e207..422466aae9 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -25,6 +25,7 @@ require 'spec_helper'
describe Chef::Knife do
before(:each) do
+ Chef::Config.reset
Chef::Log.logger = Logger.new(StringIO.new)
Chef::Config[:node_name] = "webmonkey.example.com"
@@ -203,7 +204,6 @@ describe Chef::Knife do
KnifeSpecs::TestYourself.option(:opt_with_default,
:short => "-D VALUE",
:default => "default-value")
- Chef::Config[:knife] = {}
end
it "prefers the default value if no config or command line value is present" do
@@ -227,7 +227,6 @@ describe Chef::Knife do
end
end
-
end
describe "when first created" do
diff --git a/spec/unit/mixin/securable_spec.rb b/spec/unit/mixin/securable_spec.rb
index 764da9b1d1..9531a85332 100644
--- a/spec/unit/mixin/securable_spec.rb
+++ b/spec/unit/mixin/securable_spec.rb
@@ -45,7 +45,7 @@ describe Chef::Mixin::Securable do
describe "unix-specific behavior" do
before(:each) do
platform_mock :unix do
- @original_config = Chef::Config.hash_dup
+ Chef::Config.reset
load File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "chef", "config.rb")
load File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "chef", "mixin", "securable.rb")
@securable = Object.new
@@ -55,7 +55,7 @@ describe Chef::Mixin::Securable do
end
after(:each) do
- Chef::Config.configuration = @original_config
+ Chef::Config.reset
end
it "should accept a group name or id for group with spaces and backslashes" do
@@ -120,12 +120,8 @@ describe Chef::Mixin::Securable do
end
end
- after(:all) do
- Chef::Config.configuration = @original_config if @original_config
- end
-
after(:each) do
- Chef::Config.configuration = @original_config if @original_config
+ Chef::Config.reset
end
it "should not accept a group name or id for group with spaces and multiple backslashes" do
diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb
index 4022fb25d3..63c950be9e 100644
--- a/spec/unit/provider/remote_file/ftp_spec.rb
+++ b/spec/unit/provider/remote_file/ftp_spec.rb
@@ -200,14 +200,15 @@ describe Chef::Provider::RemoteFile::FTP do
context "and proxying is enabled" do
before do
- @original_config = Chef::Config.hash_dup
+ Chef::Config.reset
Chef::Config[:ftp_proxy] = "socks5://socks.example.com:5000"
Chef::Config[:ftp_proxy_user] = "bill"
Chef::Config[:ftp_proxy_pass] = "ted"
end
after do
- Chef::Config.configuration = @original_config
+ # Be a good citizen
+ Chef::Config.reset
end
it "fetches the file via the proxy" do
diff --git a/spec/unit/util/diff_spec.rb b/spec/unit/util/diff_spec.rb
index ad1166f9fc..ad0ba627d3 100644
--- a/spec/unit/util/diff_spec.rb
+++ b/spec/unit/util/diff_spec.rb
@@ -21,12 +21,13 @@ require 'spec_helper'
require 'tmpdir'
describe Chef::Util::Diff, :uses_diff => true do
- before(:all) do
- @original_config = Chef::Config.hash_dup
+ before :each do
+ Chef::Config.reset
end
- after(:all) do
- Chef::Config.configuration = @original_config if @original_config
+ after :all do
+ # Be a good citizen
+ Chef::Config.reset
end
let!(:old_tempfile) { Tempfile.new("chef-util-diff-spec") }