Commit fc0d6136 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: Add alarm to deliver event from UpgradeDecisions

   Whenever the Upgrade Decision arrives at final state (Close, Reject, Cancel) all stopped events are delivered.
parent 01705015
...@@ -13,3 +13,6 @@ elif ticket.getPortalType() == 'Regularisation Request': ...@@ -13,3 +13,6 @@ elif ticket.getPortalType() == 'Regularisation Request':
elif ticket.getPortalType() == 'Subscription Request': elif ticket.getPortalType() == 'Subscription Request':
return event.Base_reindexAndSenseAlarm( return event.Base_reindexAndSenseAlarm(
['slapos_subscription_check_stopped_event_from_subscription_request_to_deliver']) ['slapos_subscription_check_stopped_event_from_subscription_request_to_deliver'])
elif ticket.getPortalType() == 'Upgrade Decision':
return event.Base_reindexAndSenseAlarm(
['slapos_pdm_check_stopped_event_from_upgrade_decision_to_deliver'])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_checkStoppedEventFromUpgradeDecisionToDeliver</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_pdm_check_stopped_event_from_upgrade_decision_to_deliver</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_frequency</string> </key>
<value> <int>12</int> </value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1288051200.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>sense_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Check stopped event from upgrade decision to deliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
activate_kw = {'tag': tag}
portal.portal_catalog.searchAndActivate(
portal_type=portal.getPortalEventTypeList(),
simulation_state='stopped',
follow_up__portal_type='Upgrade Decision',
method_id='Event_checkStoppedFromUpgradeDecisionToDeliver',
method_kw={'activate_kw': activate_kw},
activate_kw=activate_kw
)
context.activate(after_tag=tag).getId()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>tag, fixit, params</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_checkStoppedEventFromUpgradeDecisionToDeliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
event = context
if event.getSimulationState() != 'stopped':
return
ticket = event.getFollowUpValue(portal_type='Upgrade Decision')
if ticket is None:
# No ticket, don't try doing anything
return
simulation_state = ticket.getSimulationState()
if simulation_state not in ['delivered', 'rejected', 'cancelled']:
# Only deliver after ticket is closed.
return
comment = 'Ticket was %s' % simulation_state
event.deliver(comment=comment)
event.reindexObject(activate_kw=activate_kw)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>activate_kw=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Event_checkStoppedFromUpgradeDecisionToDeliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved.
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, TemporaryAlarmScript from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, \
TemporaryAlarmScript, SlapOSTestCaseMixinWithAbort
import time
class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin): class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin):
...@@ -81,4 +83,148 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin): ...@@ -81,4 +83,148 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin):
self.tic() self.tic()
self.assertEqual('Visited by SoftwareInstallation_destroyIfUnused', self.assertEqual('Visited by SoftwareInstallation_destroyIfUnused',
software_installation.workflow_history['edit_workflow'][-1]['comment']) software_installation.workflow_history['edit_workflow'][-1]['comment'])
\ No newline at end of file
class TestSlaposCrmCheckStoppedEventFromUpgradeDecisionToDeliver(SlapOSTestCaseMixinWithAbort):
event_portal_type = 'Web Message'
def _makeUpgradeDecision(self, confirm=True):
upgrade_decision = self.portal.\
upgrade_decision_module.newContent(
portal_type="Upgrade Decision",
title="TESTUPDE-%s" % self.generateNewId())
if confirm:
upgrade_decision.confirm()
return upgrade_decision
def _makeEvent(self, follow_up_value):
new_id = self.generateNewId()
return self.portal.event_module.newContent(
portal_type=self.event_portal_type,
title='Test %s %s' % (self.event_portal_type, new_id),
follow_up_value=follow_up_value
)
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_alarm_stopped(self):
upgrade_decision = self._makeUpgradeDecision()
event = self._makeEvent(upgrade_decision)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_pdm_check_stopped_event_from_upgrade_decision_to_deliver
self._test_alarm(alarm, event, "Event_checkStoppedFromUpgradeDecisionToDeliver")
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_alarm_delivered(self):
upgrade_decision = self._makeUpgradeDecision()
event = self._makeEvent(upgrade_decision)
event.stop()
event.deliver()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_pdm_check_stopped_event_from_upgrade_decision_to_deliver
self._test_alarm_not_visited(alarm, event,
"Event_checkStoppedFromUpgradeDecisionToDeliver")
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_alarm_invalidatedWithoutTicket(self):
upgrade_decision = self._makeUpgradeDecision()
event = self._makeEvent(upgrade_decision)
event.setFollowUp(None)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_pdm_check_stopped_event_from_upgrade_decision_to_deliver
self._test_alarm_not_visited(alarm, event,
"Event_checkStoppedFromUpgradeDecisionToDeliver")
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_script_deliveredTicket(self):
upgrade_decision = self._makeUpgradeDecision()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'"):
upgrade_decision.start()
upgrade_decision.deliver()
self.tic()
time.sleep(1)
event = self._makeEvent(upgrade_decision)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(upgrade_decision.getSimulationState(), "delivered")
event.Event_checkStoppedFromUpgradeDecisionToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(upgrade_decision.getSimulationState(), "delivered")
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_script_rejectTicket(self):
upgrade_decision = self._makeUpgradeDecision()
upgrade_decision.reject()
self.tic()
time.sleep(1)
event = self._makeEvent(upgrade_decision)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(upgrade_decision.getSimulationState(), "rejected")
event.Event_checkStoppedFromUpgradeDecisionToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(upgrade_decision.getSimulationState(), "rejected")
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_script_cancelTicket(self):
upgrade_decision = self._makeUpgradeDecision()
upgrade_decision.cancel()
self.tic()
time.sleep(1)
event = self._makeEvent(upgrade_decision)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(upgrade_decision.getSimulationState(), "cancelled")
event.Event_checkStoppedFromUpgradeDecisionToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(upgrade_decision.getSimulationState(), "cancelled")
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_script_startedTicket(self):
upgrade_decision = self._makeUpgradeDecision()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'"):
upgrade_decision.start()
self.tic()
time.sleep(1)
event = self._makeEvent(upgrade_decision)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(upgrade_decision.getSimulationState(), "started")
event.Event_checkStoppedFromUpgradeDecisionToDeliver()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(upgrade_decision.getSimulationState(), "started")
def test_Event_checkStoppedFromUpgradeDecisionToDeliver_script_stopTicket(self):
upgrade_decision = self._makeUpgradeDecision()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'"):
upgrade_decision.start()
upgrade_decision.stop()
self.tic()
time.sleep(1)
event = self._makeEvent(upgrade_decision)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(upgrade_decision.getSimulationState(), "stopped")
event.Event_checkStoppedFromUpgradeDecisionToDeliver()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(upgrade_decision.getSimulationState(), "stopped")
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Interaction Workflow Interaction" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>after_script/portal_workflow/slapos_pdm_interaction_workflow/script_UpgradeDecision_triggerCheckStoppedEventToDeliver</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interaction_UpgradeDecision_close</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Interaction Workflow Interaction</string> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<tuple>
<string>Upgrade Decision</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type_group_filter</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>trigger_method_id</string> </key>
<value>
<tuple>
<string>close</string>
<string>reject</string>
<string>cancel</string>
</tuple>
</value>
</item>
<item>
<key> <string>trigger_once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
return state_change['object'].Base_reindexAndSenseAlarm(
['slapos_pdm_check_stopped_event_from_upgrade_decision_to_deliver'])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>state_change</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_UpgradeDecision_triggerCheckStoppedEventToDeliver</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Script</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal_alarms/slapos_pdm_check_stopped_event_from_upgrade_decision_to_deliver
portal_alarms/slapos_pdm_destroy_unused_software_installation portal_alarms/slapos_pdm_destroy_unused_software_installation
portal_alarms/slapos_pdm_instance_tree_create_upgrade_decision portal_alarms/slapos_pdm_instance_tree_create_upgrade_decision
portal_alarms/slapos_pdm_upgrade_decision_process_started portal_alarms/slapos_pdm_upgrade_decision_process_started
\ No newline at end of file
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