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 a31a710
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 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,33 @@ 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 |applied_proposal|
save = false
attributes = applied_proposal.override_attributes[applied_proposal.barclamp]
["elements", "elements_expanded"].each do |element_key|
next unless attributes.key?(element_key)
attributes[element_key].each do |role_name, elements|
next unless elements.include?(name)
elements.delete(name)
attributes[element_key][role_name] = elements
save = true
end
end
applied_proposal.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 a31a710

Please sign in to comment.