summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/node.rb27
-rw-r--r--lib/chef/policy_builder/expand_node_object.rb9
-rw-r--r--spec/unit/node_spec.rb9
-rw-r--r--spec/unit/policy_builder/expand_node_object_spec.rb2
4 files changed, 36 insertions, 11 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index a7fc033080..4992ec2430 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -42,7 +42,7 @@ class Chef
def_delegators :attributes, :keys, :each_key, :each_value, :key?, :has_key?
- attr_accessor :recipe_list, :run_state, :run_list
+ attr_accessor :recipe_list, :run_state, :override_runlist
# RunContext will set itself as run_context via this setter when
# initialized. This is needed so DSL::IncludeAttribute (in particular,
@@ -63,7 +63,8 @@ class Chef
@name = nil
@chef_environment = '_default'
- @run_list = Chef::RunList.new
+ @primary_runlist = Chef::RunList.new
+ @override_runlist = Chef::RunList.new
@attributes = Chef::Node::Attribute.new({}, {}, {}, {})
@@ -259,10 +260,28 @@ class Chef
run_list.include?("role[#{role_name}]")
end
+ def primary_runlist
+ @primary_runlist
+ end
+
+ def override_runlist(*args)
+ args.length > 0 ? @override_runlist.reset!(args) : @override_runlist
+ end
+
+ def select_run_list
+ @override_runlist.empty? ? @primary_runlist : @override_runlist
+ end
+
# Returns an Array of roles and recipes, in the order they will be applied.
# If you call it with arguments, they will become the new list of roles and recipes.
def run_list(*args)
- args.length > 0 ? @run_list.reset!(args) : @run_list
+ rl = select_run_list
+ args.length > 0 ? rl.reset!(args) : rl
+ end
+
+ def run_list=(list)
+ rl = select_run_list
+ rl = list
end
# Returns true if this Node expects a given role, false if not.
@@ -410,7 +429,7 @@ class Chef
"default" => attributes.combined_default,
"override" => attributes.combined_override,
#Render correctly for run_list items so malformed json does not result
- "run_list" => run_list.run_list.map { |item| item.to_s }
+ "run_list" => @primary_runlist.run_list.map { |item| item.to_s }
}
result
end
diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb
index 38b8b7551b..269e722797 100644
--- a/lib/chef/policy_builder/expand_node_object.rb
+++ b/lib/chef/policy_builder/expand_node_object.rb
@@ -40,7 +40,6 @@ class Chef
attr_reader :ohai_data
attr_reader :json_attribs
attr_reader :override_runlist
- attr_reader :original_runlist
attr_reader :run_context
attr_reader :run_list_expansion
@@ -52,7 +51,6 @@ class Chef
@events = events
@node = nil
- @original_runlist = nil
@run_list_expansion = nil
end
@@ -190,7 +188,7 @@ class Chef
# override_runlist was provided. Chef::Client uses this to decide whether
# to do the final node save at the end of the run or not.
def temporary_policy?
- !!@original_runlist
+ !node.override_runlist.empty?
end
########################################
@@ -200,10 +198,9 @@ class Chef
def setup_run_list_override
runlist_override_sanity_check!
unless(override_runlist.empty?)
- @original_runlist = node.run_list.run_list_items.dup
- node.run_list(*override_runlist)
+ node.override_runlist(*override_runlist)
Chef::Log.warn "Run List override has been provided."
- Chef::Log.warn "Original Run List: [#{original_runlist.join(', ')}]"
+ Chef::Log.warn "Original Run List: [#{node.primary_runlist}]"
Chef::Log.warn "Overridden Run List: [#{node.run_list}]"
end
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index f2a78f87cd..832e10f645 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -724,6 +724,15 @@ describe Chef::Node do
json.should =~ /\"run_list\":\[\"role\[Cthulu\]\",\"role\[Hastur\]\"\]/
end
+ it "should serialize the correct run list", :json => true do
+ node.run_list << "role[marxist]"
+ node.run_list << "role[leninist]"
+ node.override_runlist << "role[stalinist]"
+ node.run_list.should be_include("role[stalinist]")
+ json = Chef::JSONCompat.to_json(node)
+ json.should =~ /\"run_list\":\[\"role\[marxist\]\",\"role\[leninist\]\"\]/
+ end
+
it "merges the override components into a combined override object" do
node.attributes.role_override["role override"] = "role override"
node.attributes.env_override["env override"] = "env override"
diff --git a/spec/unit/policy_builder/expand_node_object_spec.rb b/spec/unit/policy_builder/expand_node_object_spec.rb
index 5c6f39d28c..a1e0b881d5 100644
--- a/spec/unit/policy_builder/expand_node_object_spec.rb
+++ b/spec/unit/policy_builder/expand_node_object_spec.rb
@@ -244,7 +244,7 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
it "sets the override run_list on the node" do
expect(node.run_list).to eq([override_runlist])
- expect(policy_builder.original_runlist).to eq(primary_runlist)
+ expect(node.primary_runlist).to eq(primary_runlist)
end
it "reports that a temporary policy is being used" do