Commit 4e55049c authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Change how allocation scope change updates monitor and capacity scope

   Whenever allocation scope changes, the capacity is close, and the proper alarm will re-open it later a moment after. This prevents when you change from close to open, to get a miss-updated window, and something is allocated before it capacity is calculated.

     Do not touch on monitor scope, except when it is None or allocation is "Close Forever", this allow the user to keep monitoring closed computers (Maintenance, termination...), since ONLY allocation is closed, and the computer is supposed to work normally with whatever is inside.
parent c2a73196
...@@ -147,6 +147,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin): ...@@ -147,6 +147,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
server.edit( server.edit(
allocation_scope='open/public') allocation_scope='open/public')
self.assertEqual('open/public', server.getAllocationScope()) self.assertEqual('open/public', server.getAllocationScope())
# Called by alarm
server.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', server.getCapacityScope()) self.assertEqual('open', server.getCapacityScope())
self.tic() self.tic()
...@@ -155,6 +157,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin): ...@@ -155,6 +157,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
server.edit( server.edit(
allocation_scope='open/subscription') allocation_scope='open/subscription')
self.assertEqual('open/subscription', server.getAllocationScope()) self.assertEqual('open/subscription', server.getAllocationScope())
# Called by alarm
server.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', server.getCapacityScope()) self.assertEqual('open', server.getCapacityScope())
self.tic() self.tic()
...@@ -163,6 +167,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin): ...@@ -163,6 +167,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
server.edit( server.edit(
allocation_scope='open/personal', subject_list=[]) allocation_scope='open/personal', subject_list=[])
self.assertEqual('open/personal', server.getAllocationScope()) self.assertEqual('open/personal', server.getAllocationScope())
# Called by alarm
server.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', server.getCapacityScope()) self.assertEqual('open', server.getCapacityScope())
self.tic() self.tic()
...@@ -173,6 +179,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin): ...@@ -173,6 +179,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
server.edit( server.edit(
allocation_scope='open/friend', subject_list=friend_list) allocation_scope='open/friend', subject_list=friend_list)
self.assertEqual('open/friend', server.getAllocationScope()) self.assertEqual('open/friend', server.getAllocationScope())
# Called by alarm
server.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', server.getCapacityScope()) self.assertEqual('open', server.getCapacityScope())
self.assertSameSet(friend_list, server.getSubjectList()) self.assertSameSet(friend_list, server.getSubjectList())
self.tic() self.tic()
......
...@@ -209,6 +209,10 @@ return True""" ) ...@@ -209,6 +209,10 @@ return True""" )
self.software_instance.getUrlString()) self.software_instance.getUrlString())
self.compute_node.edit(allocation_scope='open/personal', self.compute_node.edit(allocation_scope='open/personal',
source_administration=self.person_user.getRelativeUrl()) source_administration=self.person_user.getRelativeUrl())
self.compute_node.setAccessStatus("#access ok")
self.tic()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual(self.compute_node.getCapacityScope(), 'open')
self.tic() self.tic()
self.assertEqual(None, self.software_instance.getAggregateValue( self.assertEqual(None, self.software_instance.getAggregateValue(
...@@ -226,6 +230,10 @@ return True""" ) ...@@ -226,6 +230,10 @@ return True""" )
self.partition) self.partition)
self.compute_node.edit(allocation_scope='open/personal', self.compute_node.edit(allocation_scope='open/personal',
source_administration=self.person_user.getRelativeUrl()) source_administration=self.person_user.getRelativeUrl())
self.compute_node.setAccessStatus("#access ok")
self.tic()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual(self.compute_node.getCapacityScope(), 'open')
self.tic() self.tic()
self.assertEqual(None, self.software_instance.getAggregateValue( self.assertEqual(None, self.software_instance.getAggregateValue(
...@@ -259,6 +267,10 @@ return True""" ) ...@@ -259,6 +267,10 @@ return True""" )
source_administration=person_user.getRelativeUrl(), source_administration=person_user.getRelativeUrl(),
destination_section=self.person_user.getRelativeUrl(), destination_section=self.person_user.getRelativeUrl(),
allocation_scope='open/friend') allocation_scope='open/friend')
self.compute_node.setAccessStatus("#access ok")
self.tic()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual(self.compute_node.getCapacityScope(), 'open')
self.tic() self.tic()
self.assertEqual(None, self.software_instance.getAggregateValue( self.assertEqual(None, self.software_instance.getAggregateValue(
...@@ -292,6 +304,10 @@ return True""" ) ...@@ -292,6 +304,10 @@ return True""" )
source_administration=person_user.getRelativeUrl(), source_administration=person_user.getRelativeUrl(),
destination_section=self.person_user.getRelativeUrl(), destination_section=self.person_user.getRelativeUrl(),
allocation_scope='open/friend') allocation_scope='open/friend')
self.compute_node.setAccessStatus("#access ok")
self.tic()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual(self.compute_node.getCapacityScope(), 'open')
self.tic() self.tic()
self.assertEqual(None, self.software_instance.getAggregateValue( self.assertEqual(None, self.software_instance.getAggregateValue(
......
...@@ -6,12 +6,6 @@ ...@@ -6,12 +6,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testSlapOSCloudAllocationAlarm</string> </value> <value> <string>testSlapOSCloudAllocationAlarm</string> </value>
...@@ -55,28 +49,13 @@ ...@@ -55,28 +49,13 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -89,7 +68,7 @@ ...@@ -89,7 +68,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -98,7 +77,7 @@ ...@@ -98,7 +77,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
...@@ -641,7 +641,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin): ...@@ -641,7 +641,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference()) self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference())
self.assertEqual('validated', compute_node.getValidationState()) self.assertEqual('validated', compute_node.getValidationState())
self.assertEqual('open/personal', compute_node.getAllocationScope()) self.assertEqual('open/personal', compute_node.getAllocationScope())
self.assertEqual('open', compute_node.getCapacityScope()) self.assertEqual('close', compute_node.getCapacityScope())
def test_request_notReindexedCompute(self): def test_request_notReindexedCompute(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue() person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
...@@ -682,7 +682,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin): ...@@ -682,7 +682,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference()) self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference())
self.assertEqual('validated', compute_node.getValidationState()) self.assertEqual('validated', compute_node.getValidationState())
self.assertEqual('open/personal', compute_node.getAllocationScope()) self.assertEqual('open/personal', compute_node.getAllocationScope())
self.assertEqual('open', compute_node.getCapacityScope()) self.assertEqual('close', compute_node.getCapacityScope())
self.tic() self.tic()
...@@ -708,7 +708,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin): ...@@ -708,7 +708,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference()) self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference())
self.assertEqual('validated', compute_node.getValidationState()) self.assertEqual('validated', compute_node.getValidationState())
self.assertEqual('open/personal', compute_node.getAllocationScope()) self.assertEqual('open/personal', compute_node.getAllocationScope())
self.assertEqual('open', compute_node.getCapacityScope()) self.assertEqual('close', compute_node.getCapacityScope())
# and now another one # and now another one
person.requestComputeNode(compute_node_title=compute_node_title2) person.requestComputeNode(compute_node_title=compute_node_title2)
...@@ -735,7 +735,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin): ...@@ -735,7 +735,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual('COMP-%s' % (previous_id + 2), compute_node2.getReference()) self.assertEqual('COMP-%s' % (previous_id + 2), compute_node2.getReference())
self.assertEqual('validated', compute_node2.getValidationState()) self.assertEqual('validated', compute_node2.getValidationState())
self.assertEqual('open/personal', compute_node2.getAllocationScope()) self.assertEqual('open/personal', compute_node2.getAllocationScope())
self.assertEqual('open', compute_node2.getCapacityScope()) self.assertEqual('close', compute_node2.getCapacityScope())
def test_request_duplicatedComputeNode(self): def test_request_duplicatedComputeNode(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue() person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
......
...@@ -6,12 +6,6 @@ ...@@ -6,12 +6,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testSlapOSCloudPersonSlapInterfaceWorkflow</string> </value> <value> <string>testSlapOSCloudPersonSlapInterfaceWorkflow</string> </value>
...@@ -61,28 +55,13 @@ ...@@ -61,28 +55,13 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -95,7 +74,7 @@ ...@@ -95,7 +74,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -104,7 +83,7 @@ ...@@ -104,7 +83,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
...@@ -47,7 +47,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -47,7 +47,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
compute_node.edit(allocation_scope=allocation_scope) compute_node.edit(allocation_scope=allocation_scope)
self.commit() self.commit()
self.assertEqual(compute_node.getCapacityScope(), 'open') self.assertEqual(compute_node.getCapacityScope(), 'close')
self.assertEqual(compute_node.getMonitorScope(), 'enabled') self.assertEqual(compute_node.getMonitorScope(), 'enabled')
return compute_node return compute_node
...@@ -96,7 +96,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -96,7 +96,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
self.commit() self.commit()
self.assertEqual(compute_node.getCapacityScope(), 'close') self.assertEqual(compute_node.getCapacityScope(), 'close')
self.assertEqual(compute_node.getMonitorScope(), 'disabled') self.assertEqual(compute_node.getMonitorScope(), 'enabled')
self.commit() self.commit()
compute_node.edit(allocation_scope=None) compute_node.edit(allocation_scope=None)
self.commit() self.commit()
...@@ -107,8 +107,8 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -107,8 +107,8 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
compute_node.edit(allocation_scope='open/personal') compute_node.edit(allocation_scope='open/personal')
self.commit() self.commit()
self.assertEqual(compute_node.getCapacityScope(), 'open') self.assertEqual(compute_node.getCapacityScope(), 'close')
self.assertEqual(compute_node.getMonitorScope(), 'disabled') self.assertEqual(compute_node.getMonitorScope(), 'enabled')
return compute_node return compute_node
def test_ComputeNode_setAllocationScope_personal(self): def test_ComputeNode_setAllocationScope_personal(self):
...@@ -169,7 +169,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -169,7 +169,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
compute_node.edit(allocation_scope='open/friend') compute_node.edit(allocation_scope='open/friend')
self.commit() self.commit()
self.assertEqual(compute_node.getCapacityScope(), 'open') self.assertEqual(compute_node.getCapacityScope(), 'close')
self.assertEqual(compute_node.getMonitorScope(), 'enabled') self.assertEqual(compute_node.getMonitorScope(), 'enabled')
return compute_node return compute_node
...@@ -205,7 +205,8 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -205,7 +205,8 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
def _test_ComputeNode_setAllocationScope_closed(self, def _test_ComputeNode_setAllocationScope_closed(self,
source_administration=None, source_administration=None,
allocation_scope="close/forever", allocation_scope="close/forever",
subject_list=None): subject_list=None,
monitor_scope='enabled'):
compute_node = self.portal.compute_node_module.newContent(portal_type='Compute Node', compute_node = self.portal.compute_node_module.newContent(portal_type='Compute Node',
capacity_scope=None, capacity_scope=None,
monitor_scope=None, monitor_scope=None,
...@@ -217,7 +218,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -217,7 +218,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
self.commit() self.commit()
self.assertEqual(compute_node.getCapacityScope(), 'close') self.assertEqual(compute_node.getCapacityScope(), 'close')
self.assertEqual(compute_node.getMonitorScope(), 'disabled') self.assertEqual(compute_node.getMonitorScope(), monitor_scope)
self.commit() self.commit()
compute_node.edit(allocation_scope=None) compute_node.edit(allocation_scope=None)
...@@ -230,12 +231,12 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -230,12 +231,12 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
self.commit() self.commit()
self.assertEqual(compute_node.getCapacityScope(), 'close') self.assertEqual(compute_node.getCapacityScope(), 'close')
self.assertEqual(compute_node.getMonitorScope(), 'disabled') self.assertEqual(compute_node.getMonitorScope(), monitor_scope)
return compute_node return compute_node
def test_ComputeNode_setAllocationScope_closed_forever_no_source_adm(self): def test_ComputeNode_setAllocationScope_closed_forever_no_source_adm(self):
self._test_ComputeNode_setAllocationScope_closed() self._test_ComputeNode_setAllocationScope_closed(monitor_scope='disabled')
def test_ComputeNode_setAllocationScope_closed_forever_with_source_adm(self): def test_ComputeNode_setAllocationScope_closed_forever_with_source_adm(self):
person = self.makePerson() person = self.makePerson()
...@@ -243,7 +244,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope( ...@@ -243,7 +244,7 @@ class TestSlapOSERP5InteractionWorkflowComputeNodeSetAllocationScope(
self.assertNotIn(person.getDefaultEmailCoordinateText(), [None, ""]) self.assertNotIn(person.getDefaultEmailCoordinateText(), [None, ""])
compute_node = self._test_ComputeNode_setAllocationScope_closed( compute_node = self._test_ComputeNode_setAllocationScope_closed(
source_administration=person.getRelativeUrl()) source_administration=person.getRelativeUrl(), monitor_scope='disabled')
self.assertEqual(compute_node.getSubjectList(), [person.getDefaultEmailCoordinateText()]) self.assertEqual(compute_node.getSubjectList(), [person.getDefaultEmailCoordinateText()])
self.assertEqual(compute_node.getDestinationSectionList(), self.assertEqual(compute_node.getDestinationSectionList(),
......
...@@ -3,18 +3,17 @@ allocation_scope = compute_node.getAllocationScope() ...@@ -3,18 +3,17 @@ allocation_scope = compute_node.getAllocationScope()
edit_kw = {} edit_kw = {}
if compute_node.getCapacityScope() is None: # Automatically close the capacity whenever the allocation scope
# changes, and let the alarm update it later, whenever the
# allocation scope is open.
if compute_node.getCapacityScope() != "close":
edit_kw['capacity_scope'] = 'close' edit_kw['capacity_scope'] = 'close'
if allocation_scope in ['open/public', 'open/subscription', 'open/friend']: if compute_node.getMonitorScope() is None:
monitor_scope = 'enabled' edit_kw['monitor_scope'] = 'enabled'
elif allocation_scope == 'open/personal':
monitor_scope = compute_node.getMonitorScope("disabled")
else:
monitor_scope = 'disabled'
edit_kw['capacity_scope'] = 'close'
edit_kw['monitor_scope'] = monitor_scope if allocation_scope == "close/forever":
edit_kw['monitor_scope'] = 'disabled'
self_person = compute_node.getSourceAdministrationValue(portal_type="Person") self_person = compute_node.getSourceAdministrationValue(portal_type="Person")
if self_person is None: if self_person is None:
......
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