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

Commit cf0e0a0

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 cf0e0a0

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

crowbar_framework/app/models/deployer_service.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,32 @@ 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 |role|
137+
save = false
138+
["elements", "elements_expanded"].each do |element_key|
139+
next unless role.override_attributes[role.barclamp].key?(element_key)
140+
role.override_attributes[role.barclamp][element_key].each do |role_name, elements|
141+
next unless elements.include?(name)
142+
elements.delete(name)
143+
role.override_attributes[role.barclamp][element_key][role_name] = elements
144+
save = true
145+
end
146+
end
147+
role.save if save
148+
end
149+
150+
# Remove node from all proposals
151+
Proposal.all.each do |proposal|
152+
save = false
153+
proposal.elements.each do |role_name, elements|
154+
next unless elements.include?(name)
155+
elements.delete(name)
156+
proposal.elements[role_name] = elements
157+
save = true
158+
end
159+
proposal.save if save
160+
end
136161
end
137162

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

0 commit comments

Comments
 (0)