Commit 515476f9 authored by Rafael Monnerat's avatar Rafael Monnerat

Rafael Backup of WIP CRM changes.

parent a48a9c75
<?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_checkSoftwareInstanceState</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Vefity the state of the instances which are hosted on public servers.</string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_check_software_instance_state</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value> <int>1</int> </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_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1377608640.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 instances\' state</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -12,9 +12,7 @@
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
<value> <string>Check if a public or a friend computer contacted master recently and create a ticket if the computer stops to contact master after some time.</string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
......@@ -22,7 +20,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_check_computer_state</string> </value>
<value> <string>slapos_crm_check_computer_state</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
......
......@@ -2,85 +2,42 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
<global name="Role Information" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
<key> <string>id</string> </key>
<value> <string>6</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<key> <string>role_base_category</string> </key>
<value>
<tuple>
<string>action_type/object_button</string>
<string>role</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<key> <string>role_category</string> </key>
<value>
<none/>
<tuple>
<string>role/member</string>
</tuple>
</value>
</item>
<item>
<key> <string>float_index</string> </key>
<value> <float>30.0</float> </value>
</item>
<item>
<key> <string>icon</string> </key>
<key> <string>role_name</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<tuple>
<string>Auditor</string>
<string>Author</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>6</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>rss_view</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>RSS Monitoring Support Request List</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/SupportRequestModule_viewMonitoringSupportRequestList?portal_skin=RSS</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:rss_feed_image</string> </value>
<value> <string>Member</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -12,8 +12,10 @@
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -21,10 +23,7 @@
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -34,8 +33,10 @@
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......
......@@ -51,14 +51,18 @@
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
category_uid = portal.restrictedTraverse(\n
public_category_uid = portal.restrictedTraverse(\n
"portal_categories/allocation_scope/open/public", None).getUid()\n
\n
friend_category_uid = portal.restrictedTraverse(\n
"portal_categories/allocation_scope/open/friend", None).getUid()\n
\n
\n
if category_uid is not None:\n
portal.portal_catalog.searchAndActivate(\n
portal_type = \'Computer\',\n
validation_state = \'validated\',\n
default_allocation_scope_uid = category_uid,\n
default_allocation_scope_uid = [public_category_uid, friend_category_uid],\n
method_id = \'Computer_checkState\',\n
activate_kw = {\'tag\':tag} \n
)\n
......
......@@ -77,7 +77,7 @@ if len(hs_reference_list) > 0:\n
portal_type=\'Hosting Subscription\',\n
validation_state=\'validated\',\n
reference=hs_reference_list,\n
method_id=\'HostingSubscription_checkSofwareInstanceAllocationState\',\n
method_id=\'HostingSubscription_checkSofwareInstanceState\',\n
activate_kw = {\'tag\':tag}\n
)\n
\n
......
......@@ -61,6 +61,8 @@ elif source_project_value.getPortalType() == "Software Instance":\n
destination_decision = source_project_value.getSpecialiseValue().getDestinationSection()\n
elif source_project_value.getPortalType() == "Hosting Subscription":\n
destination_decision = source_project_value.getDestinationSection()\n
elif source_project_value.getPortalType() == "Software Installation":\n
destination_decision = source_project_value.getDestinationSection()\n
else:\n
destination_decision = None\n
\n
......@@ -73,28 +75,38 @@ if not title.startswith(\'[MONITORING]\'):\n
support_request_in_progress = portal.portal_catalog.getResultValue(\n
portal_type = \'Support Request\',\n
title = title,\n
simulation_state = ["validated","submitted","suspended"],\n
source_project_uid = source_project_value.getUid()\n
simulation_state = ["validated", "submitted", "suspended"],\n
source_project_uid = source_project_value.getUid(),\n
)\n
\n
if support_request_in_progress is None:\n
ressource = portal.service_module.\\\n
if support_request_in_progress is not None:\n
return support_request_in_progress\n
\n
support_request_in_progress = context.REQUEST.get("support_request_in_progress", None)\n
\n
if support_request_in_progress is not None:\n
return portal.restrictedTraverse(support_request_in_progress)\n
\n
resource = portal.service_module.\\\n
slapos_crm_monitoring.getRelativeUrl()\n
support_request = portal.\\\n
\n
support_request = portal.\\\n
support_request_module.\\\n
slapos_crm_support_request_template_for_monitoring.\\\n
Base_createCloneDocument(batch_mode=1)\n
support_request.edit(\n
support_request.edit(\n
title = title,\n
description = description,\n
start_date = DateTime(),\n
destination_decision=destination_decision,\n
source_project_value = source_relative_url,\n
ressource=ressource\n
resource=resource\n
)\n
support_request.validate()\n
support_request.validate()\n
\n
context.REQUEST.set("support_request_in_progress", support_request.getRelativeUrl())\n
\n
return support_request.getRelativeUrl()\n
return support_request\n
</string> </value>
</item>
<item>
......
......@@ -79,28 +79,17 @@ if not person.Person_isServiceProvider():\n
request_description = \'Allocation scope has been changed to \' \\\n
\'%s for %s\' % (target_allocation_scope, computer_reference)\n
\n
support_request_url = context.Base_generateSupportRequestForSlapOS(\n
support_request = context.Base_generateSupportRequestForSlapOS(\n
request_title,\n
request_description,\n
computer.getRelativeUrl()\n
)\n
if support_request_url:\n
support_request = portal.restrictedTraverse(support_request_url)\n
support_request.suspend()\n
else:\n
# XXX - Base_generateSupportRequestForSlapOS return None if the \n
# support_request already exist, but we want to use it again so...\n
support_request = portal.portal_catalog.getResultValue(\n
portal_type = \'Support Request\',\n
title = request_title,\n
simulation_state = [\'suspended\', \'open\'],\n
source_project_uid = computer.getUid()\n
)\n
if support_request is None:\n
# Existing ticket not found, can not create event for the moment\n
return\n
\n
if support_request.getSimulationState() != "validated":\n
support_request.validate()\n
\n
# Send notification message\n
message = request_description\n
notification_message = portal.portal_notifications.getDocumentValue(\n
reference=notification_message_reference)\n
\n
......@@ -108,13 +97,12 @@ if not person.Person_isServiceProvider():\n
mapping_dict = {\'computer_title\':computer.getTitle(),\n
\'computer_id\':computer_reference,\n
\'allocation_scope\':allocation_scope}\n
\n
message = notification_message.asText(\n
substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
else:\n
message = request_description\n
substitution_method_parameter_dict={\'mapping_dict\': mapping_dict})\n
\n
event = support_request.SupportRequest_trySendNotificationMessage(request_title,\n
message, person.getRelativeUrl())\n
event = support_request.SupportRequest_trySendNotificationMessage(\n
request_title, message, person.getRelativeUrl())\n
\n
if event is not None:\n
computer.edit(**edit_kw)\n
......
......@@ -76,8 +76,8 @@ try:\n
d = memcached_dict[reference]\n
d = json.loads(d)\n
last_contact = DateTime(d.get(\'created_at\'))\n
if (DateTime() - last_contact) > 1:\n
description = "The Computer %s (%s) has not contacted the server for more than 24 hours" \\\n
if (DateTime() - last_contact) > 0.02:\n
description = "The Computer %s (%s) has not contacted the server for more than 30 hours" \\\n
"(last contact date: %s)" % (computer_title, reference, last_contact)\n
else:\n
should_notify = False\n
......@@ -86,45 +86,24 @@ except KeyError:\n
description = "The Computer %s (%s) has not contacted the server (No Contact Information)" % (\n
computer_title, reference)\n
\n
\n
if should_notify:\n
support_request_url = context.Base_generateSupportRequestForSlapOS(\n
support_request = context.Base_generateSupportRequestForSlapOS(\n
ticket_title,\n
description,\n
context.getRelativeUrl()\n
)\n
\n
support_request = None\n
\n
person = context.getSourceAdministrationValue(portal_type="Person")\n
if not person:\n
return support_request_url\n
\n
if support_request_url:\n
support_request = portal.restrictedTraverse(support_request_url, None)\n
else:\n
# XXX - the support request might already exists\n
support_request = portal.portal_catalog.getResultValue(\n
portal_type = \'Support Request\',\n
title = ticket_title,\n
simulation_state = \'validated\',\n
source_project_uid = context.getUid()\n
)\n
if support_request is None:\n
# Existing ticket not found, can not create event for the moment\n
return support_request_url\n
\n
return support_request\n
\n
# Send Notification message\n
notification_reference = \'slapos-crm-computer_check_state.notification\'\n
notification_message = portal.portal_notifications.getDocumentValue(\n
reference=notification_reference)\n
if notification_message is None:\n
message = """Dear user,\n
%s.\n
Do not hesitate to visit the web forum (http://community.slapos.org/forum) in case of question.\n
\n
Regards,\n
\n
The slapos team""" % description\n
if notification_message is None:\n
message = """%s""" % description\n
else:\n
mapping_dict = {\'computer_title\':context.getTitle(),\n
\'computer_id\':reference,\n
......@@ -133,10 +112,10 @@ The slapos team""" % description\n
substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
\n
support_request.SupportRequest_trySendNotificationMessage(\n
ticket_title.replace(\'[MONITORING] \', \'\'),\n
message, person.getRelativeUrl(), 5)\n
ticket_title,\n
message, person.getRelativeUrl())\n
\n
return support_request_url\n
return support_request\n
]]></string> </value>
......
......@@ -62,38 +62,41 @@ if portal.ERP5Site_isSupportRequestCreationClosed():\n
# Stop ticket creation\n
return\n
\n
hs_title = hosting_subscription.getTitle()\n
date_check_limit = addToDate(DateTime(), to_add={\'hour\': -4})\n
has_newest_allocated_instance = False\n
has_unallocated_instance = False\n
source_instance = hosting_subscription.getPredecessorValue()\n
failing_instance = None\n
date_check_limit = addToDate(DateTime(), to_add={\'hour\': -1})\n
\n
if (hosting_subscription.getCreationDate() - date_check_limit) < 0:\n
# Too early to check\n
return\n
\n
if not source_instance:\n
return\n
software_instance_list = [source_instance]\n
predecessors_instance = source_instance.getPredecessorValueList()\n
if len(predecessors_instance) > 0:\n
software_instance_list.extend(predecessors_instance)\n
\n
software_instance_list = hosting_subscription.getSpecialiseRelatedValueList(\n
portal_type=["Software Instance", "Slave Instance"])\n
\n
has_newest_allocated_instance = False\n
has_unallocated_instance = False\n
failing_instance = None\n
\n
# Check if at least one software Instance is Allocated\n
for instance in software_instance_list:\n
if instance.getAggregate("") != "":\n
if instance.getSlapState() not in ["start_requested", "stop_requested"]:\n
continue\n
\n
if (instance.getCreationDate() - date_check_limit) < 0:\n
# This instance is created for more than 4 hours\n
continue\n
\n
if instance.getAggregateValue() is not None:\n
has_newest_allocated_instance = True\n
else:\n
has_unallocated_instance = True\n
failing_instance = instance\n
\n
if has_unallocated_instance and has_newest_allocated_instance:\n
return context.Base_generateSupportRequestForSlapOS(\n
"Hosting Subscription %s is partially allocated" % hs_title,\n
"%s has allocated instance(s) but, the instance %s (%s) has been unallocated for more than 4 hours." % (\n
hs_title, failing_instance.getTitle(), failing_instance.getAbsoluteUrl()),\n
hosting_subscription.getRelativeUrl())\n
else:\n
return\n
if has_unallocated_instance and has_newest_allocated_instance:\n
return context.HostingSubscription_createSupportRequestEvent(\n
failing_instance, \'slapos-crm-hosting-subscription-instance-allocation.notification\')\n
\n
return\n
]]></string> </value>
......
......@@ -53,73 +53,44 @@
<value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\n
import json\n
from Products.ERP5Type.DateUtils import addToDate\n
\n
hosting_subscription = context\n
portal = context.getPortalObject()\n
\n
if portal.ERP5Site_isSupportRequestCreationClosed():\n
# Stop ticket creation\n
return\n
\n
if (DateTime() - context.getCreationDate()) < 2:\n
# Ignore recently created instances.\n
return\n
date_check_limit = addToDate(DateTime(), to_add={\'hour\': -1})\n
\n
reference = context.getReference()\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
if (hosting_subscription.getCreationDate() - date_check_limit) < 0:\n
# Too early to check\n
return\n
\n
try:\n
d = memcached_dict[reference]\n
except KeyError:\n
if not source_instance:\n
return\n
\n
d = json.loads(d)\n
result = d[\'text\']\n
last_contact = DateTime(d.get(\'created_at\'))\n
software_instance_list = hosting_subscription.getSpecialiseRelatedValueList(\n
portal_type=["Software Instance"])\n
\n
# Optimise by checking memcache information first.\n
if result.startswith(\'#error \'):\n
service = context.getSpecialiseValue(portal_type=\'Hosting Subscription\')\n
hosting_title = service.getTitle()\n
ticket_title = "Service %s in error state" % service.getReference()\n
description = "The instance %s of service %s has been in error state (last contact date: %s)" % (\n
reference, hosting_title, last_contact)\n
support_request_url = context.Base_generateSupportRequestForSlapOS(\n
ticket_title, description, service.getRelativeUrl())\n
\n
if not support_request_url:\n
return\n
\n
support_request = portal.restrictedTraverse(support_request_url, None)\n
person_url = service.getDestinationSection()\n
\n
if support_request is None or not person_url:\n
return support_request_url\n
\n
notification_message = portal.portal_notifications.getDocumentValue(\n
reference=\'slapos-crm-hosting_subscription_state.notification\')\n
if notification_message is None:\n
message = """Dear user,\n
%s.\n
Do not hesitate to visit the web forum (http://community.slapos.org/forum) in case of question.\n
has_newest_allocated_instance = False\n
has_unallocated_instance = False\n
failing_instance = None\n
\n
# Check if at least one software Instance is Allocated\n
for instance in software_instance_list:\n
if instance.getSlapState() not in ["start_requested", "stop_requested"]:\n
continue\n
\n
if (instance.getCreationDate() - date_check_limit) < 0:\n
continue\n
\n
Regards,\n
if instance.SoftwareInstance_hasReportedError():\n
return context.HostingSubscription_createSupportRequestEvent(\n
instance, \'slapos-crm-hosting-subscription-instance-allocation.notification\')\n
\n
The slapos team""" % description\n
else:\n
mapping_dict = {\'hosting_title\':hosting_title,\n
\'hosting_url\':service.getRelativeUrl(),\n
\'instance_title\':context.getTitle(),\n
\'last_contact\':last_contact}\n
message = notification_message.asText(\n
substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
\n
support_request.SupportRequest_trySendNotificationMessage(\n
ticket_title, message, person_url, 0)\n
\n
return support_request_url\n
return\n
]]></string> </value>
......@@ -130,7 +101,7 @@ The slapos team""" % description\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstance_checkState</string> </value>
<value> <string>HostingSubscription_checkSofwareInstanceError</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -50,20 +50,14 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>hosting_subscription = context\n
<value> <string>"""\n
Create only one event per time, otherwise it will generate too \n
much messages. \n
"""\n
if context.HostingSubscription_checkSofwareInstanceAllocationState() is not None:\n
context.HostingSubscription_checkSofwareInstanceError()\n
\n
instance = hosting_subscription.getPredecessorValue()\n
if instance is None:\n
return\n
instance_list = [instance]\n
instance_list.extend(instance.getPredecessorValueList())\n
\n
for sub_instance in instance_list:\n
if sub_instance and \\\n
sub_instance.activate().SoftwareInstance_checkState():\n
# This instance is in failing state\n
# One notification per hosting subscription\n
break\n
return\n
</string> </value>
</item>
<item>
......@@ -72,7 +66,7 @@ for sub_instance in instance_list:\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_CheckInstanceState</string> </value>
<value> <string>HostingSubscription_checkSofwareInstanceState</string> </value>
</item>
</dictionary>
</pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<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>_body</string> </key>
<value> <string>ticket_title = "Hosting Subscription %s is failing." % context.getTitle()\n
\n
description = "%s contains software instances which are unallocated or reporting errors." % (\n
hosting_subscription_title)\n
\n
support_request = context.Base_generateSupportRequestForSlapOS(\n
ticket_title,\n
description,\n
hosting_subscription.getRelativeUrl())\n
\n
person = context.getSourceAdministrationValue(portal_type="Person")\n
if not person:\n
return support_request\n
\n
if support_request.getSimulationState() != "validated":\n
support_request.validate()\n
\n
# Send Notification message\n
message = description\n
\n
notification_reference = notification_message_reference\n
notification_message = portal.portal_notifications.getDocumentValue(\n
reference=notification_reference)\n
if notification_message is not None:\n
mapping_dict = {\'hosting_subscription_title\':context.getTitle(),\n
\'instance\': instance.getTitle()}\n
\n
message = notification_message.asText(\n
substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
\n
return support_request.SupportRequest_trySendNotificationMessage(\n
ticket_title, message, person.getRelativeUrl())\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>instance, notification_message_reference</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_createSupportRequestEvent</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -50,29 +50,37 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
category_uid = portal.restrictedTraverse(\n
"portal_categories/allocation_scope/open/public", None).getUid()\n
<value> <string>from DateTime import DateTime\n
import json\n
\n
if category_uid is not None:\n
portal.portal_catalog.searchAndActivate(\n
portal_type = \'Computer\',\n
validation_state = \'validated\',\n
default_allocation_scope_uid = category_uid,\n
method_id = \'Computer_checkSoftwareInstanceState\',\n
activate_kw = {\'tag\':tag} \n
)\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
\n
context.activate(after_tag=tag).getId()\n
try:\n
d = memcached_dict[context.getReference()]\n
except KeyError:\n
return \n
\n
d = json.loads(d)\n
result = d[\'text\']\n
last_contact = DateTime(d.get(\'created_at\'))\n
now = DateTime()\n
\n
# Optimise by checking memcache information first.\n
if result.startswith(\'#error \'):\n
return last_contact\n
\n
return None\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_checkSoftwareInstanceState</string> </value>
<value> <string>SoftwareInstallation_hasReportedError</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -50,25 +50,29 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
<value> <string>from DateTime import DateTime\n
import json\n
\n
partition_list = portal.portal_catalog(portal_type = \'Computer Partition\',\n
free_for_request = 0,\n
parent_uid = context.getUid()\n
)\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
\n
hosting_subscription_list = []\n
for partition in partition_list:\n
software_instance = partition.getAggregateRelatedValue(\n
portal_type=\'Software Instance\')\n
if software_instance:\n
hosting = software_instance.getSpecialiseValue(\n
portal_type=\'Hosting Subscription\')\n
if hosting and not hosting in hosting_subscription_list:\n
hosting_subscription_list.append(hosting)\n
hosting.HostingSubscription_CheckInstanceState()\n
\n
return len(hosting_subscription_list)\n
if context.getAggregateValue(portal_type="Computer Partition") is not None:\n
try:\n
d = memcached_dict[context.getReference()]\n
except KeyError:\n
return \n
\n
d = json.loads(d)\n
result = d[\'text\']\n
last_contact = DateTime(d.get(\'created_at\'))\n
now = DateTime()\n
\n
# Optimise by checking memcache information first.\n
if result.startswith(\'#error \'):\n
return last_contact\n
\n
return None\n
</string> </value>
</item>
<item>
......@@ -77,7 +81,7 @@ return len(hosting_subscription_list)\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_checkSoftwareInstanceState</string> </value>
<value> <string>SoftwareInstance_hasReportedError</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -50,20 +50,18 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
support_request = context\n
<value> <string>support_request = context\n
portal = context.getPortalObject()\n
\n
resource = portal.service_module.slapos_crm_information.getRelativeUrl()\n
# create Web message if needed for this ticket\n
last_event = context.portal_catalog.getResultValue(\n
title=message_title,\n
follow_up_uid=support_request.getUid(), \n
sort_on=[(\'delivery.start_date\', \'DESC\')],\n
)\n
if last_event and (interval_of_day > 0) and \\\n
(DateTime() - last_event.getStartDate() < interval_of_day):\n
# User has already been notified this last 24h.\n
if last_event:\n
# User has already been notified for this problem.\n
return\n
event = portal.event_module.slapos_crm_web_message_template.\\\n
Base_createCloneDocument(batch_mode=1)\n
......@@ -79,13 +77,11 @@ event.stop()\n
event.deliver()\n
\n
return event\n
]]></string> </value>
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>message_title, message, source_relative_url, interval_of_day=1</string> </value>
<value> <string>message_title, message, source_relative_url</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -756,3 +756,213 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by R
self.assertNotEqual(
'Visited by RegularisationRequest_deleteHostingSubscriptionList',
ticket.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSCrmMonitoringCheckComputerState(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def _simulateComputer_checkState(self):
script_name = 'Computer_checkState'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kw',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by Computer_checkState') """ )
transaction.commit()
def _dropComputer_checkState(self):
script_name = 'Computer_checkState'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_check_computer_state(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/public')
self._simulateComputer_checkState()
try:
self.portal.portal_alarms.slapos_crm_check_computer_state.activeSense()
self.tic()
finally:
self._dropComputer_checkState()
self.assertEqual('Visited by Computer_checkState',
computer.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_check_computer_state_no_public_computer(self):
computer = self._makeComputer(self.new_id)
self._simulateComputer_checkState()
try:
self.portal.portal_alarms.slapos_crm_check_computer_state.activeSense()
self.tic()
finally:
self._dropComputer_checkState()
self.assertNotEqual('Visited by Computer_checkState',
computer.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSCrmMonitoringCheckComputerAllocationScope(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def _simulateComputer_checkAndUpdateAllocationScope(self):
script_name = 'Computer_checkAndUpdateAllocationScope'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kw',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by Computer_checkAndUpdateAllocationScope') """ )
transaction.commit()
def _dropComputer_checkAndUpdateAllocationScope(self):
script_name = 'Computer_checkAndUpdateAllocationScope'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_not_allowed_allocation_scope_OpenPublic(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/public')
self._simulateComputer_checkAndUpdateAllocationScope()
try:
self.portal.portal_alarms.slapos_crm_check_update_allocation_scope.activeSense()
self.tic()
finally:
self._dropComputer_checkAndUpdateAllocationScope()
self.assertEqual('Visited by Computer_checkAndUpdateAllocationScope',
computer.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_allowed_allocation_scope_OpenFriend(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/friend')
self._simulateComputer_checkAndUpdateAllocationScope()
try:
self.portal.portal_alarms.slapos_crm_check_update_allocation_scope.activeSense()
self.tic()
finally:
self._dropComputer_checkAndUpdateAllocationScope()
self.assertEqual('Visited by Computer_checkAndUpdateAllocationScope',
computer.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_allowed_allocationScope_open_personal(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/personal')
self._simulateComputer_checkAndUpdateAllocationScope()
try:
self.portal.portal_alarms.slapos_crm_check_update_allocation_scope.activeSense()
self.tic()
finally:
self._dropComputer_checkAndUpdateAllocationScope()
self.assertNotEqual('Visited by Computer_checkAndUpdateAllocationScope',
computer.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_allowed_allocation_scope_OpenPersonal_old_computer(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/personal')
def getModificationDate(self):
return DateTime() - 50
from Products.ERP5Type.Base import Base
self._simulateComputer_checkAndUpdateAllocationScope()
original_get_modification = Base.getModificationDate
Base.getModificationDate = getModificationDate
try:
self.portal.portal_alarms.slapos_crm_check_update_allocation_scope.activeSense()
self.tic()
finally:
Base.getModificationDate = original_get_modification
self._dropComputer_checkAndUpdateAllocationScope()
self.assertEqual('Visited by Computer_checkAndUpdateAllocationScope',
computer.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_allowed_allocation_scope_OpenPersonalWithSoftwareInstallation(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/personal')
software_installation = self._makeSoftwareInstallation(
self.new_id, computer, "http://...")
def getModificationDate(self):
return DateTime() - 50
from Products.ERP5Type.Base import Base
self._simulateComputer_checkAndUpdateAllocationScope()
original_get_modification = Base.getModificationDate
Base.getModificationDate = getModificationDate
try:
self.portal.portal_alarms.slapos_crm_check_update_allocation_scope.activeSense()
self.tic()
finally:
Base.getModificationDate = original_get_modification
self._dropComputer_checkAndUpdateAllocationScope()
self.assertNotEqual('Visited by Computer_checkAndUpdateAllocationScope',
computer.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSCrmMonitoringCheckHostingSubscriptionAllocation(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def _simulateHostingSubscription_checkSofwareInstanceState(self):
script_name = 'HostingSubscription_checkSofwareInstanceAllocationState'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kw',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by HostingSubscription_checkSofwareInstanceAllocationState') """ )
transaction.commit()
def _dropHostingSubscription_checkSofwareInstanceState(self):
script_name = 'HostingSubscription_checkSofwareInstanceAllocationState'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_Alarm_findAndNofitiyUnallocatedSoftwareInstance(self):
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub, self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
self.assertEqual(instance.getAggregate(""), "")
self._simulateHostingSubscription_checkSofwareInstanceState()
try:
self.portal.portal_alarms.slapos_crm_check_partially_allocated_instance.activeSense()
self.tic()
finally:
self._dropHostingSubscription_checkSofwareInstanceState()
self.assertEqual('Visited by HostingSubscription_checkSofwareInstanceAllocationState',
host_sub.workflow_history['edit_workflow'][-1]['comment'])
......@@ -2024,12 +2024,12 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin):
return notification_message.getRelativeUrl()
def _getGeneratedSupportRequest(self, source_uid, request_title):
def _getGeneratedSupportRequest(self, computer_uid, request_title):
support_request = self.portal.portal_catalog.getResultValue(
portal_type = 'Support Request',
title = request_title,
simulation_state = 'validated',
source_project_uid = source_uid
source_project_uid = computer_uid
)
return support_request
......@@ -2047,35 +2047,6 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin):
computer.validate()
return computer
def _makeHostingSubscription(self, new_id):
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
hosting_subscription = self.portal\
.hosting_subscription_module.template_hosting_subscription\
.Base_createCloneDocument(batch_mode=1)
hosting_subscription.validate()
hosting_subscription.edit(
title= "Test hosting sub ticket %s" % new_id,
reference="TESTHST-%s" % new_id,
destination_section_value=person
)
return hosting_subscription
def _makeSoftwareInstance(self, hosting_subscription, software_url):
kw = dict(
software_release=software_url,
software_type=self.generateNewSoftwareType(),
instance_xml=self.generateSafeXml(),
sla_xml=self.generateSafeXml(),
shared=False,
software_title=hosting_subscription.getTitle(),
state='started'
)
hosting_subscription.requestStart(**kw)
hosting_subscription.requestInstance(**kw)
def _simulateBase_generateSupportRequestForSlapOS(self):
script_name = 'Base_generateSupportRequestForSlapOS'
if script_name in self.portal.portal_skins.custom.objectIds():
......@@ -2200,57 +2171,3 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin):
'Test NM content\n%s\n' % computer.getReference(),
person.getRelativeUrl(), message_interval_per_day),
ticket.workflow_history['edit_workflow'][-1]['comment'])
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-crm-hosting_subscription_state.notification"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_SoftwareInstance_checkState"])')
@simulate('SupportRequest_trySendNotificationMessage',
'message_title, message, source_relative_url, interval_of_day=1',
'context.portal_workflow.doActionFor(' \
'context, action="edit_action", ' \
'comment="Visited by SupportRequest_trySendNotificationMessage ' \
'%s %s %s %s" % (message_title, message, source_relative_url, interval_of_day))')
def test_SoftwareInstance_checkState(self):
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
person_url = host_sub.getDestinationSection()
instance.workflow_history['edit_workflow'] = [{
'comment':'edit',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'state': 'current',
'time': DateTime('2012/11/30 11:11'),
'action': 'edit'
}]
memcached_dict = self.portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[instance.getReference()] = json.dumps(
{"created_at":"%s" % DateTime(), "text":"#error "}
)
message_interval_per_day = 0
self.portal.REQUEST['test_SoftwareInstance_checkState'] = \
self._makeNotificationMessage(instance.getReference())
self.tic()
ticket_url = instance.SoftwareInstance_checkState()
self.tic()
self.assertNotEqual(ticket_url, None)
ticket_title = "[MONITORING] Service %s in error state" % host_sub.getReference()
ticket = self._getGeneratedSupportRequest(host_sub.getUid(), ticket_title)
self.assertNotEqual(ticket, None)
self.assertEqual('Visited by SupportRequest_trySendNotificationMessage ' \
'%s %s %s %s' % ( \
ticket_title.replace('[MONITORING] ', ''),
'Test NM content\n%s\n' % instance.getReference(),
person_url, message_interval_per_day),
ticket.workflow_history['edit_workflow'][-1]['comment'])
event_module/slapos_crm_web_message_template
person_module/allocation_tester
portal_alarms/slapos_check_computer_state
portal_alarms/slapos_check_software_instance_state
portal_alarms/slapos_crm_cancel_invoice
portal_alarms/slapos_crm_check_computer_state
portal_alarms/slapos_crm_check_partially_allocated_instance
portal_alarms/slapos_crm_check_update_allocation_scope
portal_alarms/slapos_crm_create_regularisation_request
......
......@@ -18,7 +18,7 @@
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -18,7 +18,7 @@
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......
......@@ -55,7 +55,7 @@
if context.getSimulationState() != \'stopped\':\n
return \n
\n
if context.UpgradeDecision_isUpgradeFinished():\n
if not context.UpgradeDecision_isUpgradeFinished():\n
return \n
\n
portal = context.getPortalObject()\n
......@@ -109,6 +109,7 @@ event = context.SupportRequest_trySendNotificationMessage(title,\n
message, person.getRelativeUrl())\n
\n
if event is not None:\n
context.setStopDate(DateTime())\n
context.deliver()\n
</string> </value>
</item>
......
......@@ -9,7 +9,9 @@
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
<list>
<string>portal_type</string>
</list>
</value>
</item>
<item>
......@@ -77,6 +79,17 @@
<key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value>
<list>
<tuple>
<string>Service</string>
<string>Service</string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......
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