From cf0e0a06ba9dd9fd211ed8ad5310803f0d76d76b Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Mon, 20 Feb 2017 16:56:56 +0100 Subject: [PATCH] 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 https://github.com/sap-oc/crowbar-core/issues/8 --- .../app/models/deployer_service.rb | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crowbar_framework/app/models/deployer_service.rb b/crowbar_framework/app/models/deployer_service.rb index 52415abb56..567f362222 100644 --- a/crowbar_framework/app/models/deployer_service.rb +++ b/crowbar_framework/app/models/deployer_service.rb @@ -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}")