Commit a2b4afb0 authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: add an alarm to deliver stopped event

Interact with the support request if possible.
parent c0a786fa
<?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_checkStoppedEventToDeliver</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Check if a public or a friend compute_node contacted master recently and create a ticket if the compute_node stops to contact master after some time.</string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_crm_check_stopped_event_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 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='Support Request',
method_id='Event_checkStoppedToDeliver',
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_checkStoppedEventToDeliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
event = context
if event.getSimulationState() != 'stopped':
return
support_request = event.getFollowUpValue(portal_type='Support Request')
if support_request is None:
# No ticket, don't try doing anything
return
is_event_older_than_ticket_modification = (event.getCreationDate() <= support_request.getModificationDate())
if is_event_older_than_ticket_modification:
if support_request.getSimulationState() == 'invalidated':
# Ticket reach final state
# close all previous events
event.deliver(comment='Ticket was invalidated')
event.reindexObject(activate_kw=activate_kw)
return
if support_request.getSimulationState() == 'validated':
# Ticket is ongoing. No need to update it.
event.deliver(comment='Ticket was validated')
event.reindexObject(activate_kw=activate_kw)
return
else:
if support_request.getSimulationState() == 'validated':
# Event is more recent than the ticket
# Touch the ticket, to allow manager to see it as recent
# and deliver the event
support_request.edit(activate_kw=activate_kw)
event.deliver(comment='Ticket has been modified')
event.reindexObject(activate_kw=activate_kw)
return
if support_request.getSimulationState() == 'invalidated':
# Event is more recent than the ticket
# reopen the ticket
# and deliver the event
support_request.validate(activate_kw=activate_kw)
event.deliver(comment='Ticket has been revalidated')
event.reindexObject(activate_kw=activate_kw)
return
<?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_checkStoppedToDeliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -2236,3 +2236,152 @@ class TestSlaposCrmCheckSuspendedSupportRequestToReopen(SlapOSTestCaseMixinWithA
support_request.SupportRequest_checkSuspendedToReopen()
self.assertEqual(support_request.getSimulationState(), "suspended")
class TestSlaposCrmCheckStoppedEventToDeliver(SlapOSTestCaseMixinWithAbort):
def _makeSupportRequest(self):
support_request = self.portal.support_request_module.newContent(
portal_type="Support Request"
)
support_request.submit()
new_id = self.generateNewId()
support_request.edit(
title= "Support Request éçà %s" % new_id, #pylint: disable=invalid-encoded-data
reference="TESTSRQ-%s" % new_id
)
return support_request
def _makeEvent(self, ticket):
new_id = self.generateNewId()
return self.portal.event_module.newContent(
portal_type="Web Message",
title='Test Event %s' % new_id,
follow_up_value=ticket
)
def test_Event_checkStoppedEventToDeliver_alarm_stopped(self):
support_request = self._makeSupportRequest()
event = self._makeEvent(support_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_check_stopped_event_to_deliver
self._test_alarm(alarm, event, "Event_checkStoppedToDeliver")
def test_Event_checkStoppedEventToDeliver_alarm_delivered(self):
support_request = self._makeSupportRequest()
event = self._makeEvent(support_request)
event.stop()
event.deliver()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_check_stopped_event_to_deliver
self._test_alarm_not_visited(alarm, event, "Event_checkStoppedToDeliver")
def test_Event_checkStoppedEventToDeliver_alarm_stoppedWithoutTicket(self):
support_request = self._makeSupportRequest()
event = self._makeEvent(support_request)
event.setFollowUp(None)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_check_stopped_event_to_deliver
self._test_alarm_not_visited(alarm, event, "Event_checkStoppedToDeliver")
def test_Event_checkStoppedEventToDeliver_script_recentEventInvalidatedTicket(self):
support_request = self._makeSupportRequest()
support_request.validate()
support_request.invalidate()
self.tic()
time.sleep(1)
event = self._makeEvent(support_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "invalidated")
event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(support_request.getSimulationState(), "validated")
def test_Event_checkStoppedEventToDeliver_script_recentEventValidatedTicket(self):
support_request = self._makeSupportRequest()
support_request.validate()
self.tic()
time.sleep(1)
event = self._makeEvent(support_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "validated")
event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertTrue(event.getCreationDate() < support_request.getModificationDate())
def test_Event_checkStoppedEventToDeliver_script_recentEventSuspendedTicket(self):
support_request = self._makeSupportRequest()
support_request.validate()
support_request.suspend()
self.tic()
time.sleep(1)
event = self._makeEvent(support_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "suspended")
event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "suspended")
def test_Event_checkStoppedEventToDeliver_script_oldEventInvalidatedTicket(self):
support_request = self._makeSupportRequest()
event = self._makeEvent(support_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
time.sleep(1)
support_request.validate()
support_request.invalidate()
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "invalidated")
event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(support_request.getSimulationState(), "invalidated")
def test_Event_checkStoppedEventToDeliver_script_oldEventValidatedTicket(self):
support_request = self._makeSupportRequest()
event = self._makeEvent(support_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
time.sleep(1)
support_request.validate()
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "validated")
event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(support_request.getSimulationState(), "validated")
def test_Event_checkStoppedEventToDeliver_script_oldEventSuspendedTicket(self):
support_request = self._makeSupportRequest()
event = self._makeEvent(support_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm', "'disabled'", attribute='comment'):
self.tic()
time.sleep(1)
support_request.validate()
support_request.suspend()
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "suspended")
event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "suspended")
<?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_crm_interaction_workflow/script_Base_triggerCheckStoppedEventToDeliver</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interaction_Event_stop</string> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<tuple>
<string>Web Message</string>
</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>stop</string>
</tuple>
</value>
</item>
<item>
<key> <string>trigger_once_per_transaction</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
event = state_change['object']
return event.Base_reindexAndSenseAlarm(['slapos_crm_check_stopped_event_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_Base_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>
......@@ -123,6 +123,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_crm_monitoring/SupportRequest_getMonitorUrl',
'slapos_crm_monitoring/SupportRequest_recheckMonitoring',
'slapos_crm_monitoring/Event_checkCustomerAsSourceOrDestinationConsistency',
'slapos_crm_monitoring/Event_checkStoppedToDeliver',
'slapos_crm_monitoring/Project_createSupportRequestWithCausality',
'slapos_crm/RegularisationRequest_afterClone',
'slapos_crm/RegularisationRequest_getResourceItemList',
......
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