Commit 69fd89f7 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Merge too similar alarms

    slapos_crm_check_suspended_support_request_to_reopen is not required since the Event_checkStoppedToDeliver already trigger over events once they are stopped.

    Update Event_checkStoppedToDeliver to re-open suspended tickets like it does for invalidated ones.
    Fix up Event_checkStoppedToDeliver to deliver also Events from Suspended tickets (after re-open them).
parent ff8cd707
<?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_checkSuspendedSupportRequestToReopen</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_suspended_support_request_to_reopen</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 suspended support request to reopen</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
activate_kw = {'tag': tag}
portal.portal_catalog.searchAndActivate(
portal_type='Support Request',
simulation_state='suspended',
method_id='SupportRequest_checkSuspendedToReopen',
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_checkSuspendedSupportRequestToReopen</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -11,35 +11,26 @@ if support_request is None: ...@@ -11,35 +11,26 @@ if support_request is None:
is_event_older_than_ticket_modification = (event.getCreationDate() <= support_request.getModificationDate()) is_event_older_than_ticket_modification = (event.getCreationDate() <= support_request.getModificationDate())
if is_event_older_than_ticket_modification: if is_event_older_than_ticket_modification:
if support_request.getSimulationState() == 'invalidated': if support_request.getSimulationState() in ['invalidated', 'validated', 'suspended']:
# Ticket reach final state # If invalidated, Ticket reach final state close all previous events
# close all previous events # If validated or suspended, close events w/o edit the ticket.
event.deliver(comment='Ticket was invalidated') event.deliver(comment='Ticket was %s' % support_request.getSimulationState())
event.reindexObject(activate_kw=activate_kw) event.reindexObject(activate_kw=activate_kw)
return 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': if support_request.getSimulationState() in 'validated':
# Event is more recent than the ticket # Event is more recent than the ticket
# Touch the ticket, to allow manager to see it as recent # Touch the ticket, to allow manager to see it as recent
# and deliver the event # and deliver the event
support_request.edit(activate_kw=activate_kw) support_request.edit(activate_kw=activate_kw)
event.deliver(comment='Ticket has been modified') event.deliver(comment='Ticket has been modified')
event.reindexObject(activate_kw=activate_kw) event.reindexObject(activate_kw=activate_kw)
return return
if support_request.getSimulationState() == 'invalidated': if support_request.getSimulationState() in ['invalidated', 'suspended']:
# Event is more recent than the ticket # Event is more recent than the ticket reopen the ticket
# reopen the ticket # and deliver the event.
# and deliver the event support_request.validate(activate_kw=activate_kw)
support_request.validate(activate_kw=activate_kw) event.deliver(comment='Ticket has been revalidated')
event.deliver(comment='Ticket has been revalidated') event.reindexObject(activate_kw=activate_kw)
event.reindexObject(activate_kw=activate_kw) return
return
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
portal = context.getPortalObject()
support_request = context
any_recent_event = portal.portal_catalog.getResultValue(
portal_type=portal.getPortalEventTypeList(),
follow_up__uid=support_request.getUid(),
creation_date=SimpleQuery(creation_date=support_request.getModificationDate(), comparison_operator='>')
)
if any_recent_event is not None:
support_request.validate(comment='Reopened because %s is newer' % any_recent_event.getRelativeUrl())
support_request.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>SupportRequest_checkSuspendedToReopen</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -1174,8 +1174,9 @@ class TestSlaposCrmCheckStoppedEventToDeliver(SlapOSTestCaseMixinWithAbort): ...@@ -1174,8 +1174,9 @@ class TestSlaposCrmCheckStoppedEventToDeliver(SlapOSTestCaseMixinWithAbort):
self.assertEqual(event.getSimulationState(), "stopped") self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "suspended") self.assertEqual(support_request.getSimulationState(), "suspended")
event.Event_checkStoppedToDeliver() event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "stopped") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(support_request.getSimulationState(), "suspended") self.assertEqual(support_request.getSimulationState(), "validated")
self.assertTrue(event.getCreationDate() < support_request.getModificationDate())
def test_Event_checkStoppedEventToDeliver_script_oldEventInvalidatedTicket(self): def test_Event_checkStoppedEventToDeliver_script_oldEventInvalidatedTicket(self):
support_request = self._makeSupportRequest() support_request = self._makeSupportRequest()
...@@ -1221,77 +1222,5 @@ class TestSlaposCrmCheckStoppedEventToDeliver(SlapOSTestCaseMixinWithAbort): ...@@ -1221,77 +1222,5 @@ class TestSlaposCrmCheckStoppedEventToDeliver(SlapOSTestCaseMixinWithAbort):
self.assertEqual(event.getSimulationState(), "stopped") self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(support_request.getSimulationState(), "suspended") self.assertEqual(support_request.getSimulationState(), "suspended")
event.Event_checkStoppedToDeliver() event.Event_checkStoppedToDeliver()
self.assertEqual(event.getSimulationState(), "stopped") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(support_request.getSimulationState(), "suspended")
class TestSlaposCrmCheckSuspendedSupportRequestToReopen(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 test_SupportRequest_checkSuspendedSupportRequestToReopen_alarm_suspended(self):
support_request = self._makeSupportRequest()
support_request.validate()
support_request.suspend()
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_check_suspended_support_request_to_reopen
self._test_alarm(alarm, support_request, "SupportRequest_checkSuspendedToReopen")
def test_SupportRequest_checkSuspendedSupportRequestToReopen_alarm_notSuspended(self):
support_request = self._makeSupportRequest()
support_request.validate()
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_check_suspended_support_request_to_reopen
self._test_alarm_not_visited(alarm, support_request, "SupportRequest_checkSuspendedToReopen")
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_SupportRequest_checkSuspendedSupportRequestToReopen_script_noEvent(self):
support_request = self._makeSupportRequest()
support_request.validate()
support_request.suspend()
self.tic()
support_request.SupportRequest_checkSuspendedToReopen()
self.assertEqual(support_request.getSimulationState(), "suspended")
def test_SupportRequest_checkSuspendedSupportRequestToReopen_script_recentEvent(self):
support_request = self._makeSupportRequest()
support_request.validate()
support_request.suspend()
self.tic()
time.sleep(1)
self._makeEvent(support_request)
self.tic()
support_request.SupportRequest_checkSuspendedToReopen()
self.assertEqual(support_request.getSimulationState(), "validated")
def test_SupportRequest_checkSuspendedSupportRequestToReopen_script_oldEvent(self):
support_request = self._makeSupportRequest()
self._makeEvent(support_request)
self.tic()
time.sleep(1)
support_request.validate()
support_request.suspend()
self.tic()
support_request.SupportRequest_checkSuspendedToReopen()
self.assertEqual(support_request.getSimulationState(), "suspended") 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_triggerCheckSuspendedSupportRequestToReopen</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interaction_Event_setFollowUp</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>_setFollowUp.*</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']
support_request = event.getFollowUpValue()
if (support_request is not None) and (support_request.getSimulationState() == 'suspended'):
return state_change['object'].Base_reindexAndSenseAlarm(['slapos_crm_check_suspended_support_request_to_reopen'])
<?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_triggerCheckSuspendedSupportRequestToReopen</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>
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