Commit 60948897 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: Drop useless duplication

parent 28838e29
document_list = []
for decision_line in context.contentValues():
document_list.extend(
decision_line.getAggregateValueList(portal_type=document_portal_type))
if len(document_list) > 1:
raise ValueError("It is only allowed to have more them 1 %s" % document_list)
if len(document_list) == 0:
return None
return document_list[0]
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>document_portal_type="Instance Tree"</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>UpgradeDecision_getComputeNode</string> </value> <value> <string>UpgradeDecision_getAggregateValue</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
compute_node_list = []
for decision_line in context.contentValues():
compute_node_list.extend(
decision_line.getAggregateValueList(portal_type="Compute Node"))
if len(compute_node_list) > 1:
raise ValueError("It is only allowed to have more them 1 Compute Node")
if len(compute_node_list) == 0:
return None
return compute_node_list[0]
instance_tree_list = []
for decision_line in context.contentValues():
instance_tree_list.extend(
decision_line.getAggregateValueList(portal_type="Instance Tree"))
if len(instance_tree_list) > 1:
raise ValueError("It is only allowed to have more them 1 Instance Tree")
if len(instance_tree_list) == 0:
return None
return instance_tree_list[0]
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>UpgradeDecision_getInstanceTree</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject() portal = context.getPortalObject()
instance_tree = context.UpgradeDecision_getInstanceTree() instance_tree = context.UpgradeDecision_getAggregateValue("Instance Tree")
compute_node = context.UpgradeDecision_getComputeNode() compute_node = context.UpgradeDecision_getAggregateValue("Compute Node")
software_release = context.UpgradeDecision_getSoftwareRelease() software_release = context.UpgradeDecision_getSoftwareRelease()
if instance_tree is not None: if instance_tree is not None:
......
...@@ -10,9 +10,9 @@ person = context.getDestinationDecisionValue(portal_type="Person") ...@@ -10,9 +10,9 @@ person = context.getDestinationDecisionValue(portal_type="Person")
if not person: if not person:
raise ValueError("Inconsistent Upgrade Decision, No Destination Decision") raise ValueError("Inconsistent Upgrade Decision, No Destination Decision")
instance_tree = context.UpgradeDecision_getInstanceTree() instance_tree = context.UpgradeDecision_getAggregateValue("Instance Tree")
compute_node = context.UpgradeDecision_getComputeNode() compute_node = context.UpgradeDecision_getAggregateValue("Compute Node")
software_release = context.UpgradeDecision_getSoftwareRelease() software_release = context.UpgradeDecision_getAggregateValue("Software Release")
software_product_title = software_release.getAggregateTitle( software_product_title = software_release.getAggregateTitle(
portal_type="Software Product") portal_type="Software Product")
......
...@@ -12,8 +12,9 @@ person = context.getDestinationDecisionValue(portal_type="Person") ...@@ -12,8 +12,9 @@ person = context.getDestinationDecisionValue(portal_type="Person")
if not person: if not person:
raise ValueError("Inconsistent Upgrade Decision, No Destination Decision") raise ValueError("Inconsistent Upgrade Decision, No Destination Decision")
instance_tree = context.UpgradeDecision_getInstanceTree()
compute_node = context.UpgradeDecision_getComputeNode() instance_tree = context.UpgradeDecision_getAggregateValue("Instance Tree")
compute_node = context.UpgradeDecision_getAggregateValue("Compute Node")
software_release = context.UpgradeDecision_getSoftwareRelease() software_release = context.UpgradeDecision_getSoftwareRelease()
software_product_title = software_release.getAggregateTitle( software_product_title = software_release.getAggregateTitle(
portal_type="Software Product") portal_type="Software Product")
......
...@@ -8,7 +8,7 @@ if simulation_state in require_state_list: ...@@ -8,7 +8,7 @@ if simulation_state in require_state_list:
if not current_release: if not current_release:
# This upgrade decision is not valid # This upgrade decision is not valid
return False return False
instance_tree = upgrade_decision.UpgradeDecision_getInstanceTree() instance_tree = context.UpgradeDecision_getAggregateValue("Instance Tree")
if instance_tree is not None: if instance_tree is not None:
current_instance_tree_release = instance_tree.getUrlString() current_instance_tree_release = instance_tree.getUrlString()
if current_instance_tree_release == new_url_string: if current_instance_tree_release == new_url_string:
......
...@@ -2,7 +2,7 @@ if context.getSimulationState() != 'started': ...@@ -2,7 +2,7 @@ if context.getSimulationState() != 'started':
# Update Decision is not on started state, Upgrade is not possible! # Update Decision is not on started state, Upgrade is not possible!
return False return False
compute_node = context.UpgradeDecision_getComputeNode() compute_node = context.UpgradeDecision_getAggregateValue("Compute Node")
software_release = context.UpgradeDecision_getSoftwareRelease() software_release = context.UpgradeDecision_getSoftwareRelease()
if compute_node is None: if compute_node is None:
...@@ -12,7 +12,6 @@ if software_release is None: ...@@ -12,7 +12,6 @@ if software_release is None:
return False return False
software_release_url = software_release.getUrlString() software_release_url = software_release.getUrlString()
compute_node.requestSoftwareRelease( compute_node.requestSoftwareRelease(
software_release_url=software_release_url, software_release_url=software_release_url,
state="available") state="available")
......
...@@ -2,7 +2,8 @@ if context.getSimulationState() != 'started': ...@@ -2,7 +2,8 @@ if context.getSimulationState() != 'started':
# Update Decision is not on started state, Upgrade is not possible! # Update Decision is not on started state, Upgrade is not possible!
return False return False
instance_tree = context.UpgradeDecision_getInstanceTree()
instance_tree = context.UpgradeDecision_getAggregateValue("Instance Tree")
software_release = context.UpgradeDecision_getSoftwareRelease() software_release = context.UpgradeDecision_getSoftwareRelease()
if instance_tree is None: if instance_tree is None:
......
...@@ -284,7 +284,7 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins): ...@@ -284,7 +284,7 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
self.assertNotEqual(up_decision, None) self.assertNotEqual(up_decision, None)
self.assertEqual(up_decision.getSimulationState(), 'planned') self.assertEqual(up_decision.getSimulationState(), 'planned')
self.assertEqual(up_decision.UpgradeDecision_getInstanceTree().\ self.assertEqual(up_decision.UpgradeDecision_getAggregateValue("Instance Tree").\
getReference(), instance_tree.getReference()) getReference(), instance_tree.getReference())
self.assertEqual(up_decision.UpgradeDecision_getSoftwareRelease().\ self.assertEqual(up_decision.UpgradeDecision_getSoftwareRelease().\
......
...@@ -338,7 +338,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -338,7 +338,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValue(compute_node) upgrade_decision_line.setAggregateValue(compute_node)
found_compute_node = upgrade_decision.UpgradeDecision_getComputeNode() found_compute_node = upgrade_decision.UpgradeDecision_getAggregateValue("Compute Node")
self.assertEqual(compute_node.getRelativeUrl(), self.assertEqual(compute_node.getRelativeUrl(),
found_compute_node.getRelativeUrl()) found_compute_node.getRelativeUrl())
...@@ -351,7 +351,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -351,7 +351,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
found_compute_node = upgrade_decision.UpgradeDecision_getComputeNode() found_compute_node = upgrade_decision.UpgradeDecision_getAggregateValue("Compute Node")
self.assertEqual(compute_node.getRelativeUrl(), self.assertEqual(compute_node.getRelativeUrl(),
found_compute_node.getRelativeUrl()) found_compute_node.getRelativeUrl())
...@@ -365,13 +365,14 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -365,13 +365,14 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValue(compute_node) upgrade_decision_line.setAggregateValue(compute_node)
self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getComputeNode) self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getAggregateValue,
document_portal_type="Compute Node")
def testUpgradeDecision_getComputeNode_O_compute_node(self): def testUpgradeDecision_getComputeNode_O_compute_node(self):
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
self._makeUpgradeDecisionLine(upgrade_decision) self._makeUpgradeDecisionLine(upgrade_decision)
found_compute_node = upgrade_decision.UpgradeDecision_getComputeNode() found_compute_node = upgrade_decision.UpgradeDecision_getAggregateValue("Compute Node")
self.assertEqual(None, found_compute_node) self.assertEqual(None, found_compute_node)
...@@ -382,7 +383,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -382,7 +383,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValue(instance_tree) upgrade_decision_line.setAggregateValue(instance_tree)
found_instance_tree = upgrade_decision.UpgradeDecision_getInstanceTree() found_instance_tree = upgrade_decision.UpgradeDecision_getAggregateValue("Instance Tree")
self.assertEqual(instance_tree.getRelativeUrl(), self.assertEqual(instance_tree.getRelativeUrl(),
found_instance_tree.getRelativeUrl()) found_instance_tree.getRelativeUrl())
...@@ -396,7 +397,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -396,7 +397,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
found_instance_tree = upgrade_decision.UpgradeDecision_getInstanceTree() found_instance_tree = upgrade_decision.UpgradeDecision_getAggregateValue("Instance Tree")
self.assertEqual(instance_tree.getRelativeUrl(), self.assertEqual(instance_tree.getRelativeUrl(),
found_instance_tree.getRelativeUrl()) found_instance_tree.getRelativeUrl())
...@@ -411,28 +412,29 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -411,28 +412,29 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValue(instance_tree) upgrade_decision_line.setAggregateValue(instance_tree)
self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getInstanceTree) self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getAggregateValue,
document_portal_type="Instance Tree")
def testUpgradeDecision_getInstanceTree_O_hosting(self): def testUpgradeDecision_getInstanceTree_O_hosting(self):
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
self._makeUpgradeDecisionLine(upgrade_decision) self._makeUpgradeDecisionLine(upgrade_decision)
found_instance_tree = upgrade_decision.UpgradeDecision_getInstanceTree() found_instance_tree = upgrade_decision.UpgradeDecision_getAggregateValue("Instance Tree")
self.assertEqual(None, found_instance_tree) self.assertEqual(None, found_instance_tree)
def testUpgradeDecision_getSoftwareRelease(self): def testUpgradeDecision_getAggregateValue_SoftwareRelease(self):
software_release = self._makeSoftwareRelease() software_release = self._makeSoftwareRelease()
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValue(software_release) upgrade_decision_line.setAggregateValue(software_release)
found_software_release = upgrade_decision.UpgradeDecision_getSoftwareRelease() found_software_release = upgrade_decision.UpgradeDecision_getAggregateValue("Software Release")
self.assertEqual(software_release.getRelativeUrl(), self.assertEqual(software_release.getRelativeUrl(),
found_software_release.getRelativeUrl()) found_software_release.getRelativeUrl())
def testUpgradeDecision_getSoftwareRelease_2_lines(self): def testUpgradeDecision_getAggregateValue_SoftwareRelease_2_lines(self):
software_release = self._makeSoftwareRelease() software_release = self._makeSoftwareRelease()
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
...@@ -441,11 +443,11 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -441,11 +443,11 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
found_software_release = upgrade_decision.UpgradeDecision_getSoftwareRelease() found_software_release = upgrade_decision.UpgradeDecision_getAggregateValue("Software Release")
self.assertEqual(software_release.getRelativeUrl(), self.assertEqual(software_release.getRelativeUrl(),
found_software_release.getRelativeUrl()) found_software_release.getRelativeUrl())
def testUpgradeDecision_getSoftwareRelease_2_sr(self): def testUpgradeDecision_getAggregateValue_SoftwareRelease_2_sr(self):
software_release = self._makeSoftwareRelease() software_release = self._makeSoftwareRelease()
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
...@@ -455,13 +457,14 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -455,13 +457,14 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision) upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValue(software_release) upgrade_decision_line.setAggregateValue(software_release)
self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getSoftwareRelease) self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getAggregateValue,
document_portal_type="Software Release")
def testUpgradeDecision_getSoftwareRelease_O_sr(self): def testUpgradeDecision_getAggregateValue_SoftwareRelease_O_sr(self):
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
self._makeUpgradeDecisionLine(upgrade_decision) self._makeUpgradeDecisionLine(upgrade_decision)
found_software_release = upgrade_decision.UpgradeDecision_getSoftwareRelease() found_software_release = upgrade_decision.UpgradeDecision_getAggregateValue("Software Release")
self.assertEqual(None, found_software_release) self.assertEqual(None, found_software_release)
@simulate('InstanceTree_isUpgradePossible', @simulate('InstanceTree_isUpgradePossible',
...@@ -966,10 +969,10 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -966,10 +969,10 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
self.assertEqual(len(upgrade_decision), 1) self.assertEqual(len(upgrade_decision), 1)
self.assertEqual(upgrade_decision[0].getSimulationState(), 'started') self.assertEqual(upgrade_decision[0].getSimulationState(), 'started')
compute_node_aggregate = upgrade_decision[0].UpgradeDecision_getComputeNode() compute_node_aggregate = upgrade_decision[0].UpgradeDecision_getAggregateValue("Compute Node")()
self.assertEqual(compute_node_aggregate.getReference(), self.assertEqual(compute_node_aggregate.getReference(),
compute_node.getReference()) compute_node.getReference())
release = upgrade_decision[0].UpgradeDecision_getSoftwareRelease() release = upgrade_decision[0].UpgradeDecision_getAggregateValue("Software Release")
self.assertEqual(release.getUrlString(), self.assertEqual(release.getUrlString(),
software_release2.getUrlString()) software_release2.getUrlString())
self.tic() self.tic()
...@@ -1001,7 +1004,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins): ...@@ -1001,7 +1004,7 @@ class TestSlapOSPDMSkins(TestSlapOSPDMMixinSkins):
self.assertEqual(upgrade_decision.getSimulationState(), 'cancelled') self.assertEqual(upgrade_decision.getSimulationState(), 'cancelled')
self.assertEqual(upgrade_decision2.getSimulationState(), 'planned') self.assertEqual(upgrade_decision2.getSimulationState(), 'planned')
release = upgrade_decision2.UpgradeDecision_getSoftwareRelease() release = upgrade_decision2.UpgradeDecision_getAggregateValue("Software Release")
self.assertEqual(release.getUrlString(), self.assertEqual(release.getUrlString(),
software_release3.getUrlString()) software_release3.getUrlString())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment