Skip to content

Commit

Permalink
crowbar: Remove forgotten nodes from proposals
Browse files Browse the repository at this point in the history
Forgotten nodes are not removed from existing proposals (applied and
non-applied). While the webui removes non-existing nodes when displaying
a proposal, if only the API is used, applying a proposal with such
non-existing nodes may result in failures.

Closes sap-oc#8
  • Loading branch information
vuntz committed Feb 20, 2017
1 parent 20cc7f4 commit cf0e0a0
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion crowbar_framework/app/models/deployer_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,32 @@ def transition(inst, name, state)
end

if state == "delete"
# Do more work here - one day.
# Remove node from all applied proposals
RoleObject.all.select(&:proposal?).each do |role|
save = false
["elements", "elements_expanded"].each do |element_key|
next unless role.override_attributes[role.barclamp].key?(element_key)
role.override_attributes[role.barclamp][element_key].each do |role_name, elements|
next unless elements.include?(name)
elements.delete(name)
role.override_attributes[role.barclamp][element_key][role_name] = elements
save = true
end
end
role.save if save
end

# Remove node from all proposals
Proposal.all.each do |proposal|
save = false
proposal.elements.each do |role_name, elements|
next unless elements.include?(name)
elements.delete(name)
proposal.elements[role_name] = elements
save = true
end
proposal.save if save
end
end

@logger.debug("Deployer transition: exiting: #{name} for #{state}")
Expand Down

0 comments on commit cf0e0a0

Please sign in to comment.