Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit a31a710

Browse files
committed
crowbar: Remove forgotten nodes from proposals
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
1 parent 20cc7f4 commit a31a710

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

crowbar_framework/app/models/deployer_service.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,33 @@ def transition(inst, name, state)
132132
end
133133

134134
if state == "delete"
135-
# Do more work here - one day.
135+
# Remove node from all applied proposals
136+
RoleObject.all.select(&:proposal?).each do |applied_proposal|
137+
save = false
138+
attributes = applied_proposal.override_attributes[applied_proposal.barclamp]
139+
["elements", "elements_expanded"].each do |element_key|
140+
next unless attributes.key?(element_key)
141+
attributes[element_key].each do |role_name, elements|
142+
next unless elements.include?(name)
143+
elements.delete(name)
144+
attributes[element_key][role_name] = elements
145+
save = true
146+
end
147+
end
148+
applied_proposal.save if save
149+
end
150+
151+
# Remove node from all proposals
152+
Proposal.all.each do |proposal|
153+
save = false
154+
proposal.elements.each do |role_name, elements|
155+
next unless elements.include?(name)
156+
elements.delete(name)
157+
proposal.elements[role_name] = elements
158+
save = true
159+
end
160+
proposal.save if save
161+
end
136162
end
137163

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

0 commit comments

Comments
 (0)