Skip to content

Commit

Permalink
crowbar: Avoid duplicated code for adding node role on node
Browse files Browse the repository at this point in the history
  • Loading branch information
vuntz committed Apr 26, 2018
1 parent 0d8c5b5 commit a805abb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions crowbar_framework/app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ def initialize(node, role = nil)
raise Crowbar::Error::NotFound.new
end
end
unless node.run_list.run_list_items.include?("role[#{@role.name}]")
node.run_list.run_list_items << "role[#{@role.name}]"
node.save
end
Node.ensure_node_role(node, @role.name)
# deep clone of @role.default_attributes, used when saving node
@attrs_last_saved = @role.default_attributes.deep_dup
@node = node
Expand Down Expand Up @@ -1705,13 +1702,20 @@ def create_new_role(new_name, machine)
role.default_attributes["crowbar"]["network"] = {}
role.save

# This run_list call is to add the crowbar tracking role to the node. (SAFE)
machine.run_list.run_list_items << "role[#{role.name}]"
machine.save
Node.ensure_node_role(machine, role.name)

role
end

def ensure_node_role(node, role_name = nil)
role_name = make_role_name(node.name) if role_name.nil?
unless node.run_list.run_list_items.include?("role[#{role_name}]")
# This run_list call is to add the crowbar tracking role to the node. (SAFE)
node.run_list.run_list_items << "role[#{role_name}]"
node.save
end
end

def create_new(new_name)
machine = Chef::Node.new
machine.name "#{new_name}"
Expand Down

0 comments on commit a805abb

Please sign in to comment.