summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-05-10 17:09:57 +0100
committerThom May <thom@chef.io>2016-05-16 13:38:12 +0100
commit09ae18ee32b61e1b3c607dcc84c9d59d2c300428 (patch)
tree0add1084ac4642c5119dff102000075bf6d58321
parent9bd561b2fafe03444d690bef0b882a446b327cd6 (diff)
downloadchef-09ae18ee32b61e1b3c607dcc84c9d59d2c300428.tar.gz
Ensure that solo specific code is run at the proper time
ie, only when we're in OG mode and not in local mode. Signed-off-by: Thom May <thom@chef.io>
-rw-r--r--chef-config/lib/chef-config/config.rb6
-rw-r--r--lib/chef/application/apply.rb2
-rw-r--r--lib/chef/application/solo.rb8
-rw-r--r--lib/chef/client.rb6
-rw-r--r--lib/chef/cookbook/synchronizer.rb2
-rw-r--r--lib/chef/data_bag.rb4
-rw-r--r--lib/chef/data_bag_item.rb2
-rw-r--r--lib/chef/deprecation/provider/remote_file.rb2
-rw-r--r--lib/chef/environment.rb4
-rw-r--r--lib/chef/policy_builder/dynamic.rb2
-rw-r--r--lib/chef/policy_builder/expand_node_object.rb6
-rw-r--r--lib/chef/policy_builder/policyfile.rb2
-rw-r--r--lib/chef/shell/shell_session.rb6
-rw-r--r--spec/integration/solo/solo_spec.rb2
-rw-r--r--spec/unit/application/apply_spec.rb4
-rw-r--r--spec/unit/client_spec.rb2
-rw-r--r--spec/unit/cookbook/synchronizer_spec.rb2
-rw-r--r--spec/unit/data_bag_item_spec.rb4
-rw-r--r--spec/unit/data_bag_spec.rb4
-rw-r--r--spec/unit/environment_spec.rb8
-rw-r--r--spec/unit/policy_builder/dynamic_spec.rb2
-rw-r--r--spec/unit/policy_builder/policyfile_spec.rb2
22 files changed, 43 insertions, 39 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index e237f10412..502852b648 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -392,7 +392,11 @@ module ChefConfig
default :rest_timeout, 300
default :yum_timeout, 900
default :yum_lock_timeout, 30
- default :solo, false
+ default :solo, false
+
+ # Are we running in old Chef Solo legacy mode?
+ default :solo_legacy_mode, false
+
default :splay, nil
default :why_run, false
default :color, false
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index 03c86b86f2..37ddcb3164 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -150,7 +150,7 @@ class Chef::Application::Apply < Chef::Application
end
def get_recipe_and_run_context
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
@chef_client = Chef::Client.new(@json_attribs)
@chef_client.run_ohai
@chef_client.load_node
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index 9761a90d22..b3d2f61a52 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -201,7 +201,7 @@ class Chef::Application::Solo < Chef::Application
:description => "DANGEROUS: does what it says, only useful with --recipe-url",
:boolean => true
- option :og_chef_solo,
+ option :solo_legacy_mode,
:long => "--legacy-mode",
:description => "Run chef-solo in legacy mode",
:boolean => true
@@ -212,7 +212,7 @@ class Chef::Application::Solo < Chef::Application
def run
setup_signal_handlers
reconfigure
- if !Chef::Config[:og_chef_solo]
+ if !Chef::Config[:solo_legacy_mode]
Chef::Application::Client.new.run
else
setup_application
@@ -228,11 +228,11 @@ class Chef::Application::Solo < Chef::Application
set_specific_recipes
Chef::Config[:solo] = true
- # Chef::Config[:og_chef_solo] = true
+ # Chef::Config[:solo_legacy_mode] = true
Chef::Log.deprecation("-r MUST be changed to --recipe-url, the -r option will be changed in Chef 13.0") if ARGV.include?("-r")
- if !Chef::Config[:og_chef_solo]
+ if !Chef::Config[:solo_legacy_mode]
Chef::Config[:local_mode] = true
else
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 48d7c447cc..054b284bd5 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -262,7 +262,7 @@ class Chef
enforce_path_sanity
run_ohai
- register unless Chef::Config[:solo]
+ register unless Chef::Config[:solo_legacy_mode]
load_node
@@ -533,7 +533,7 @@ class Chef
# @api private
#
def save_updated_node
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
# nothing to do
elsif policy_builder.temporary_policy?
Chef::Log.warn("Skipping final node save because override_runlist was given")
@@ -936,7 +936,7 @@ class Chef
end
def assert_cookbook_path_not_empty(run_context)
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
# Check for cookbooks in the path given
# Chef::Config[:cookbook_path] can be a string or an array
# if it's an array, go through it and check each one, raise error at the last one if no files are found
diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb
index ec388746e9..1ee30bacc7 100644
--- a/lib/chef/cookbook/synchronizer.rb
+++ b/lib/chef/cookbook/synchronizer.rb
@@ -43,7 +43,7 @@ class Chef
end
def cleanup_file_cache
- unless Chef::Config[:solo] || skip_removal
+ unless Chef::Config[:solo_legacy_mode] || skip_removal
# Delete each file in the cache that we didn't encounter in the
# manifest.
cache.find(File.join(%w{cookbooks ** {*,.*}})).each do |cache_filename|
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb
index 0444e2abbe..f107f98f28 100644
--- a/lib/chef/data_bag.rb
+++ b/lib/chef/data_bag.rb
@@ -91,7 +91,7 @@ class Chef
end
def self.list(inflate = false)
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
paths = Array(Chef::Config[:data_bag_path])
names = []
paths.each do |path|
@@ -118,7 +118,7 @@ class Chef
# Load a Data Bag by name via either the RESTful API or local data_bag_path if run in solo mode
def self.load(name)
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
paths = Array(Chef::Config[:data_bag_path])
data_bag = {}
paths.each do |path|
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index d9ad771202..568c511c44 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -147,7 +147,7 @@ class Chef
# Load a Data Bag Item by name via either the RESTful API or local data_bag_path if run in solo mode
def self.load(data_bag, name)
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
bag = Chef::DataBag.load(data_bag)
raise Exceptions::InvalidDataBagItemID, "Item #{name} not found in data bag #{data_bag}. Other items found: #{bag.keys.join(", ")}" unless bag.include?(name)
item = bag[name]
diff --git a/lib/chef/deprecation/provider/remote_file.rb b/lib/chef/deprecation/provider/remote_file.rb
index b469609ffe..aefb04752e 100644
--- a/lib/chef/deprecation/provider/remote_file.rb
+++ b/lib/chef/deprecation/provider/remote_file.rb
@@ -56,7 +56,7 @@ class Chef
def source_file(source, current_checksum, &block)
if absolute_uri?(source)
fetch_from_uri(source, &block)
- elsif !Chef::Config[:solo]
+ elsif !Chef::Config[:solo_legacy_mode]
fetch_from_chef_server(source, current_checksum, &block)
else
fetch_from_local_cookbook(source, &block)
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index f6d22843d4..32ebde6f4f 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -244,7 +244,7 @@ class Chef
end
def self.load(name)
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
load_from_file(name)
else
self.from_hash(chef_server_rest.get("environments/#{name}"))
@@ -310,7 +310,7 @@ class Chef
def self.validate_cookbook_version(version)
begin
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
raise Chef::Exceptions::IllegalVersionConstraint,
"Environment cookbook version constraints not allowed in chef-solo"
else
diff --git a/lib/chef/policy_builder/dynamic.rb b/lib/chef/policy_builder/dynamic.rb
index 389f124f84..5b6bc40f9e 100644
--- a/lib/chef/policy_builder/dynamic.rb
+++ b/lib/chef/policy_builder/dynamic.rb
@@ -66,7 +66,7 @@ class Chef
Chef::Log.debug("Building node object for #{node_name}")
@node =
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
Chef::Node.build(node_name)
else
Chef::Node.find_or_create(node_name)
diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb
index 980de60dd5..df6956cc77 100644
--- a/lib/chef/policy_builder/expand_node_object.rb
+++ b/lib/chef/policy_builder/expand_node_object.rb
@@ -69,7 +69,7 @@ class Chef
end
def setup_run_context(specific_recipes = nil)
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
Chef::Cookbook::FileVendor.fetch_from_disk(Chef::Config[:cookbook_path])
cl = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
cl.load_cookbooks
@@ -118,7 +118,7 @@ class Chef
Chef::Log.debug("Building node object for #{node_name}")
@node =
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
Chef::Node.build(node_name)
else
Chef::Node.find_or_create(node_name)
@@ -167,7 +167,7 @@ class Chef
# Expands the node's run list. Stores the run_list_expansion object for later use.
def expand_run_list
- @run_list_expansion = if Chef::Config[:solo]
+ @run_list_expansion = if Chef::Config[:solo_legacy_mode]
node.expand!("disk")
else
node.expand!("server")
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index 05e5c2f3ef..8d2437fef5 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -68,7 +68,7 @@ class Chef
@node = nil
- if Chef::Config[:solo]
+ if Chef::Config[:solo_legacy_mode]
raise UnsupportedFeature, "Policyfile does not support chef-solo. Use chef-client local mode instead."
end
diff --git a/lib/chef/shell/shell_session.rb b/lib/chef/shell/shell_session.rb
index 6d8b6f14ae..0a8cba5be3 100644
--- a/lib/chef/shell/shell_session.rb
+++ b/lib/chef/shell/shell_session.rb
@@ -150,7 +150,7 @@ module Shell
private
def rebuild_node
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
@client = Chef::Client.new(nil, Chef::Config[:shell_config])
@client.run_ohai
@client.load_node
@@ -182,7 +182,7 @@ module Shell
def rebuild_node
# Tell the client we're chef solo so it won't try to contact the server
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
@client = Chef::Client.new(nil, Chef::Config[:shell_config])
@client.run_ohai
@client.load_node
@@ -213,7 +213,7 @@ module Shell
def rebuild_node
# Make sure the client knows this is not chef solo
- Chef::Config[:solo] = false
+ Chef::Config[:solo_legacy_mode] = false
@client = Chef::Client.new(nil, Chef::Config[:shell_config])
@client.run_ohai
@client.register
diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb
index 5add4849e9..f142798546 100644
--- a/spec/integration/solo/solo_spec.rb
+++ b/spec/integration/solo/solo_spec.rb
@@ -15,7 +15,7 @@ describe "chef-solo" do
let(:cookbook_ancient_100_metadata_rb) { cb_metadata("ancient", "1.0.0") }
- let(:chef_solo) { "ruby bin/chef-solo --minimal-ohai" }
+ let(:chef_solo) { "ruby bin/chef-solo --legacy-mode --minimal-ohai" }
when_the_repository "has a cookbook with a basic recipe" do
before do
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index d223d55d2b..6473666fbf 100644
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -24,13 +24,13 @@ describe Chef::Application::Apply do
allow(@app).to receive(:configure_logging).and_return(true)
allow(Chef::Log).to receive(:debug).with("FIPS mode is enabled.")
@recipe_text = "package 'nyancat'"
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
end
describe "configuring the application" do
it "should set solo mode to true" do
@app.reconfigure
- expect(Chef::Config[:solo]).to be_truthy
+ expect(Chef::Config[:solo_legacy_mode]).to be_truthy
end
end
describe "read_recipe_file" do
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index fe9b1afe01..ec3f70b9b0 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -462,7 +462,7 @@ describe Chef::Client do
describe "assert_cookbook_path_not_empty" do
before do
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
Chef::Config[:cookbook_path] = ["/path/to/invalid/cookbook_path"]
end
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb
index 97e7569cf4..3f5624f3b0 100644
--- a/spec/unit/cookbook/synchronizer_spec.rb
+++ b/spec/unit/cookbook/synchronizer_spec.rb
@@ -50,7 +50,7 @@ describe Chef::CookbookCacheCleaner do
end
it "does not remove anything on chef-solo" do
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
allow(cleaner.cache).to receive(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
expect(cleaner.cache).not_to receive(:delete)
cleaner.cleanup_file_cache
diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb
index 99bf89e583..2711fcae03 100644
--- a/spec/unit/data_bag_item_spec.rb
+++ b/spec/unit/data_bag_item_spec.rb
@@ -365,11 +365,11 @@ describe Chef::DataBagItem do
describe "in solo mode" do
before do
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
end
after do
- Chef::Config[:solo] = false
+ Chef::Config[:solo_legacy_mode] = false
end
it "converts the raw data to a data bag item" do
diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb
index 92da4cade1..84aa724927 100644
--- a/spec/unit/data_bag_spec.rb
+++ b/spec/unit/data_bag_spec.rb
@@ -143,13 +143,13 @@ describe Chef::DataBag do
shared_examples_for "data bag in solo mode" do |data_bag_path|
before do
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
Chef::Config[:data_bag_path] = data_bag_path
@paths = Array(data_bag_path)
end
after do
- Chef::Config[:solo] = false
+ Chef::Config[:solo_legacy_mode] = false
end
it "should get the data bag from the data_bag_path" do
diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb
index 4689c60b39..5557b5dc11 100644
--- a/spec/unit/environment_spec.rb
+++ b/spec/unit/environment_spec.rb
@@ -288,11 +288,11 @@ describe Chef::Environment do
describe "in solo mode" do
before do
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
end
after do
- Chef::Config[:solo] = false
+ Chef::Config[:solo_legacy_mode] = false
end
it "should raise and exception" do
@@ -392,12 +392,12 @@ describe Chef::Environment do
describe "when loading" do
describe "in solo mode" do
before do
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
Chef::Config[:environment_path] = "/var/chef/environments"
end
after do
- Chef::Config[:solo] = false
+ Chef::Config[:solo_legacy_mode] = false
end
it "should get the environment from the environment_path" do
diff --git a/spec/unit/policy_builder/dynamic_spec.rb b/spec/unit/policy_builder/dynamic_spec.rb
index f91b0ba7d2..d94b2a69a2 100644
--- a/spec/unit/policy_builder/dynamic_spec.rb
+++ b/spec/unit/policy_builder/dynamic_spec.rb
@@ -254,7 +254,7 @@ describe Chef::PolicyBuilder::Dynamic do
context "when running chef solo" do
before do
- Chef::Config[:solo] = true
+ Chef::Config[:solo_legacy_mode] = true
expect(Chef::Node).to receive(:build).with(node_name).and_return(node)
expect(policy_builder).to receive(:select_implementation).with(node)
expect(implementation).to receive(:finish_load_node).with(node)
diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb
index 0f345ee344..307bd45c18 100644
--- a/spec/unit/policy_builder/policyfile_spec.rb
+++ b/spec/unit/policy_builder/policyfile_spec.rb
@@ -115,7 +115,7 @@ describe Chef::PolicyBuilder::Policyfile do
end
context "chef-solo" do
- before { Chef::Config[:solo] = true }
+ before { Chef::Config[:solo_legacy_mode] = true }
it "errors on create" do
expect { initialize_pb }.to raise_error(err_namespace::UnsupportedFeature)