Commit c602883e authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: drop _simulateScript and add more tests

parent d4216bd4
# Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved. # -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (c) 2002-2013 Nexedi SA and Contributors. All Rights Reserved.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin): class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin):
...@@ -32,132 +51,83 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin): ...@@ -32,132 +51,83 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin):
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
upgrade_decision.start() upgrade_decision.start()
self.tic() self.tic()
self._test_alarm(
self._simulateScript('UpgradeDecision_processUpgrade', 'True') self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_started,
try: upgrade_decision,
self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_started.activeSense() 'UpgradeDecision_processUpgrade')
self.tic()
finally:
self._dropScript('UpgradeDecision_processUpgrade')
self.assertEqual(
'Visited by UpgradeDecision_processUpgrade',
upgrade_decision.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_upgrade_decision_process_planned(self): def test_alarm_upgrade_decision_process_planned(self):
upgrade_decision = self._makeUpgradeDecision(confirm=0) upgrade_decision = self._makeUpgradeDecision(confirm=0)
upgrade_decision.plan() upgrade_decision.plan()
self.tic() self._test_alarm(
self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_planned,
self._simulateScript('UpgradeDecision_notify', 'True') upgrade_decision,
try: 'UpgradeDecision_notify')
self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_planned.\
activeSense()
self.tic()
finally:
self._dropScript('UpgradeDecision_notify')
self.assertEqual('Visited by UpgradeDecision_notify',
upgrade_decision.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_upgrade_decision_process_stopped(self): def test_alarm_upgrade_decision_process_stopped(self):
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
upgrade_decision.start() upgrade_decision.start()
upgrade_decision.stop() upgrade_decision.stop()
self.tic() self.tic()
self._test_alarm(
self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_stopped,
upgrade_decision,
'UpgradeDecision_notifyDelivered')
def _test_alarm_compute_node_create_upgrade_decision(self, allocation_scope, upgrade_scope):
compute_node = self._makeComputeNode(allocation_scope=allocation_scope)[0]
compute_node.setUpgradeScope(upgrade_scope)
self._test_alarm(
self.portal.portal_alarms.slapos_pdm_compute_node_create_upgrade_decision,
compute_node,
'ComputeNode_checkAndCreateUpgradeDecision')
def _test_alarm_compute_node_create_upgrade_decision_not_visited(self, allocation_scope, upgrade_scope):
compute_node = self._makeComputeNode(allocation_scope=allocation_scope)[0]
compute_node.setUpgradeScope(upgrade_scope)
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_pdm_compute_node_create_upgrade_decision,
compute_node,
'ComputeNode_checkAndCreateUpgradeDecision')
def test_alarm_compute_node_create_upgrade_decision_auto(self):
self._test_alarm_compute_node_create_upgrade_decision('open/public', 'auto')
self._test_alarm_compute_node_create_upgrade_decision('open/personal', 'auto')
self._test_alarm_compute_node_create_upgrade_decision('open/friend', 'auto')
self._test_alarm_compute_node_create_upgrade_decision('open/subscription', 'auto')
self._test_alarm_compute_node_create_upgrade_decision('close/outdated', 'auto')
self._test_alarm_compute_node_create_upgrade_decision('close/maintanance', 'auto')
self._test_alarm_compute_node_create_upgrade_decision('close/termination', 'auto')
def test_alarm_compute_node_create_upgrade_decision_ask_confirmation(self):
self._test_alarm_compute_node_create_upgrade_decision('open/public', 'confirmation')
self._test_alarm_compute_node_create_upgrade_decision('open/personal', 'confirmation')
self._test_alarm_compute_node_create_upgrade_decision('open/friend', 'confirmation')
self._test_alarm_compute_node_create_upgrade_decision('open/subscription', 'confirmation')
self._test_alarm_compute_node_create_upgrade_decision('close/outdated', 'confirmation')
self._test_alarm_compute_node_create_upgrade_decision('close/maintanance', 'confirmation')
self._test_alarm_compute_node_create_upgrade_decision('close/termination', 'confirmation')
def test_alarm_compute_node_create_upgrade_decision_never(self):
self._test_alarm_compute_node_create_upgrade_decision_not_visited('open/public', 'never')
self._test_alarm_compute_node_create_upgrade_decision_not_visited('open/personal', 'never')
self._test_alarm_compute_node_create_upgrade_decision_not_visited('open/friend', 'never')
self._test_alarm_compute_node_create_upgrade_decision_not_visited('open/subscription', 'never')
self._test_alarm_compute_node_create_upgrade_decision_not_visited('close/outdated', 'never')
self._test_alarm_compute_node_create_upgrade_decision_not_visited('close/maintanance', 'never')
self._test_alarm_compute_node_create_upgrade_decision_not_visited('close/termination', 'never')
self._simulateScript('UpgradeDecision_notifyDelivered', 'True')
try:
self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_stopped.\
activeSense()
self.tic()
finally:
self._dropScript('UpgradeDecision_notifyDelivered')
self.assertEqual('Visited by UpgradeDecision_notifyDelivered',
upgrade_decision.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_compute_node_create_upgrade_decision(self):
compute_node = self._makeComputeNode(allocation_scope = 'open/public')[0]
compute_node2 = self._makeComputeNode(allocation_scope = 'open/personal')[0]
compute_node3 = self._makeComputeNode(allocation_scope = 'open/friend')[0]
self.tic()
self._simulateScript('ComputeNode_checkAndCreateUpgradeDecision', 'True')
try:
self.portal.portal_alarms.slapos_pdm_compute_node_create_upgrade_decision.\
activeSense()
self.tic()
finally:
self._dropScript('ComputeNode_checkAndCreateUpgradeDecision')
self.assertEqual('Visited by ComputeNode_checkAndCreateUpgradeDecision',
compute_node.workflow_history['edit_workflow'][-1]['comment'])
self.assertEqual('Visited by ComputeNode_checkAndCreateUpgradeDecision',
compute_node2.workflow_history['edit_workflow'][-1]['comment'])
self.assertEqual('Visited by ComputeNode_checkAndCreateUpgradeDecision',
compute_node3.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_instance_tree_create_upgrade_decision(self): def test_alarm_instance_tree_create_upgrade_decision(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
instance_tree2 = self._makeInstanceTree() self._test_alarm(
instance_tree3 = self._makeInstanceTree() self.portal.portal_alarms.slapos_pdm_instance_tree_create_upgrade_decision,
instance_tree,
self.tic() 'InstanceTree_createUpgradeDecision')
self._simulateScript('InstanceTree_createUpgradeDecision', 'True')
try:
self.portal.portal_alarms.slapos_pdm_instance_tree_create_upgrade_decision.\
activeSense()
self.tic()
finally:
self._dropScript('InstanceTree_createUpgradeDecision')
self.assertEqual('Visited by InstanceTree_createUpgradeDecision',
instance_tree.workflow_history['edit_workflow'][-1]['comment'])
self.assertEqual('Visited by InstanceTree_createUpgradeDecision',
instance_tree2.workflow_history['edit_workflow'][-1]['comment'])
self.assertEqual('Visited by InstanceTree_createUpgradeDecision',
instance_tree3.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_create_upgrade_decision_destroyed_instance_tree(self): def test_alarm_create_upgrade_decision_destroyed_instance_tree(self):
instance_tree = self._makeInstanceTree(slap_state="destroy_requested") instance_tree = self._makeInstanceTree(slap_state="destroy_requested")
instance_tree2 = self._makeInstanceTree(slap_state="destroy_requested") self._test_alarm_not_visited(
self.tic() self.portal.portal_alarms.slapos_pdm_instance_tree_create_upgrade_decision,
instance_tree,
self._simulateScript('InstanceTree_createUpgradeDecision', 'True') 'InstanceTree_createUpgradeDecision')
try:
self.portal.portal_alarms.slapos_pdm_instance_tree_create_upgrade_decision.\
activeSense()
self.tic()
finally:
self._dropScript('InstanceTree_createUpgradeDecision')
self.assertNotEqual('Visited by InstanceTree_createUpgradeDecision',
instance_tree.workflow_history['edit_workflow'][-1]['comment'])
self.assertNotEqual('Visited by InstanceTree_createUpgradeDecision',
instance_tree2.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_create_upgrade_decision_closed_compute_node(self):
compute_node = self._makeComputeNode(allocation_scope='close/oudtated')[0]
compute_node2 = self._makeComputeNode(allocation_scope='close/maintenance')[0]
self.tic()
self._simulateScript('ComputeNode_checkAndCreateUpgradeDecision', 'True')
try:
self.portal.portal_alarms.slapos_pdm_compute_node_create_upgrade_decision.\
activeSense()
self.tic()
finally:
self._dropScript('ComputeNode_checkAndCreateUpgradeDecision')
self.assertNotEqual('Visited by ComputeNode_checkAndCreateUpgradeDecision',
compute_node.workflow_history['edit_workflow'][-1]['comment'])
self.assertNotEqual('Visited by ComputeNode_checkAndCreateUpgradeDecision',
compute_node2.workflow_history['edit_workflow'][-1]['comment'])
...@@ -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>testSlapOSPDMAlarm</string> </value> <value> <string>testSlapOSPDMAlarm</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>
......
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