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 @@ ...@@ -12,9 +12,7 @@
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
<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>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
...@@ -22,7 +20,7 @@ ...@@ -22,7 +20,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>slapos_check_computer_state</string> </value> <value> <string>slapos_crm_check_computer_state</string> </value>
</item> </item>
<item> <item>
<key> <string>periodicity_hour</string> </key> <key> <string>periodicity_hour</string> </key>
......
...@@ -2,85 +2,42 @@ ...@@ -2,85 +2,42 @@
<ZopeData> <ZopeData>
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<global name="Action Information" module="erp5.portal_type"/> <global name="Role Information" module="erp5.portal_type"/>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item> <item>
<key> <string>action</string> </key> <key> <string>id</string> </key>
<value> <value> <string>6</string> </value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item> </item>
<item> <item>
<key> <string>categories</string> </key> <key> <string>role_base_category</string> </key>
<value> <value>
<tuple> <tuple>
<string>action_type/object_button</string> <string>role</string>
</tuple> </tuple>
</value> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>role_category</string> </key>
<value> <value>
<none/> <tuple>
<string>role/member</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
<key> <string>float_index</string> </key> <key> <string>role_name</string> </key>
<value> <float>30.0</float> </value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <tuple>
<string>Auditor</string>
<string>Author</string>
</tuple>
</value> </value>
</item> </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> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>RSS Monitoring Support Request List</string> </value> <value> <string>Member</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>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -12,8 +12,10 @@ ...@@ -12,8 +12,10 @@
<tuple> <tuple>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string> <string>Manager</string>
<string>Owner</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -21,10 +23,7 @@ ...@@ -21,10 +23,7 @@
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string> <string>Manager</string>
<string>Owner</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -34,8 +33,10 @@ ...@@ -34,8 +33,10 @@
<tuple> <tuple>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string> <string>Manager</string>
<string>Owner</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -51,14 +51,18 @@ ...@@ -51,14 +51,18 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n <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 "portal_categories/allocation_scope/open/public", None).getUid()\n
\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 if category_uid is not None:\n
portal.portal_catalog.searchAndActivate(\n portal.portal_catalog.searchAndActivate(\n
portal_type = \'Computer\',\n portal_type = \'Computer\',\n
validation_state = \'validated\',\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 method_id = \'Computer_checkState\',\n
activate_kw = {\'tag\':tag} \n activate_kw = {\'tag\':tag} \n
)\n )\n
......
...@@ -77,7 +77,7 @@ if len(hs_reference_list) > 0:\n ...@@ -77,7 +77,7 @@ if len(hs_reference_list) > 0:\n
portal_type=\'Hosting Subscription\',\n portal_type=\'Hosting Subscription\',\n
validation_state=\'validated\',\n validation_state=\'validated\',\n
reference=hs_reference_list,\n reference=hs_reference_list,\n
method_id=\'HostingSubscription_checkSofwareInstanceAllocationState\',\n method_id=\'HostingSubscription_checkSofwareInstanceState\',\n
activate_kw = {\'tag\':tag}\n activate_kw = {\'tag\':tag}\n
)\n )\n
\n \n
......
...@@ -61,6 +61,8 @@ elif source_project_value.getPortalType() == "Software Instance":\n ...@@ -61,6 +61,8 @@ elif source_project_value.getPortalType() == "Software Instance":\n
destination_decision = source_project_value.getSpecialiseValue().getDestinationSection()\n destination_decision = source_project_value.getSpecialiseValue().getDestinationSection()\n
elif source_project_value.getPortalType() == "Hosting Subscription":\n elif source_project_value.getPortalType() == "Hosting Subscription":\n
destination_decision = source_project_value.getDestinationSection()\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 else:\n
destination_decision = None\n destination_decision = None\n
\n \n
...@@ -73,28 +75,38 @@ if not title.startswith(\'[MONITORING]\'):\n ...@@ -73,28 +75,38 @@ if not title.startswith(\'[MONITORING]\'):\n
support_request_in_progress = portal.portal_catalog.getResultValue(\n support_request_in_progress = portal.portal_catalog.getResultValue(\n
portal_type = \'Support Request\',\n portal_type = \'Support Request\',\n
title = title,\n title = title,\n
simulation_state = ["validated","submitted","suspended"],\n simulation_state = ["validated", "submitted", "suspended"],\n
source_project_uid = source_project_value.getUid()\n source_project_uid = source_project_value.getUid(),\n
)\n )\n
\n \n
if support_request_in_progress is None:\n if support_request_in_progress is not None:\n
ressource = portal.service_module.\\\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 slapos_crm_monitoring.getRelativeUrl()\n
support_request = portal.\\\n \n
support_request = portal.\\\n
support_request_module.\\\n support_request_module.\\\n
slapos_crm_support_request_template_for_monitoring.\\\n slapos_crm_support_request_template_for_monitoring.\\\n
Base_createCloneDocument(batch_mode=1)\n Base_createCloneDocument(batch_mode=1)\n
support_request.edit(\n support_request.edit(\n
title = title,\n title = title,\n
description = description,\n description = description,\n
start_date = DateTime(),\n start_date = DateTime(),\n
destination_decision=destination_decision,\n destination_decision=destination_decision,\n
source_project_value = source_relative_url,\n source_project_value = source_relative_url,\n
ressource=ressource\n resource=resource\n
)\n )\n
support_request.validate()\n support_request.validate()\n
\n
context.REQUEST.set("support_request_in_progress", support_request.getRelativeUrl())\n
\n \n
return support_request.getRelativeUrl()\n return support_request\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -79,28 +79,17 @@ if not person.Person_isServiceProvider():\n ...@@ -79,28 +79,17 @@ if not person.Person_isServiceProvider():\n
request_description = \'Allocation scope has been changed to \' \\\n request_description = \'Allocation scope has been changed to \' \\\n
\'%s for %s\' % (target_allocation_scope, computer_reference)\n \'%s for %s\' % (target_allocation_scope, computer_reference)\n
\n \n
support_request_url = context.Base_generateSupportRequestForSlapOS(\n support_request = context.Base_generateSupportRequestForSlapOS(\n
request_title,\n request_title,\n
request_description,\n request_description,\n
computer.getRelativeUrl()\n computer.getRelativeUrl()\n
)\n )\n
if support_request_url:\n \n
support_request = portal.restrictedTraverse(support_request_url)\n if support_request.getSimulationState() != "validated":\n
support_request.suspend()\n support_request.validate()\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 \n
# Send notification message\n # Send notification message\n
message = request_description\n
notification_message = portal.portal_notifications.getDocumentValue(\n notification_message = portal.portal_notifications.getDocumentValue(\n
reference=notification_message_reference)\n reference=notification_message_reference)\n
\n \n
...@@ -108,13 +97,12 @@ if not person.Person_isServiceProvider():\n ...@@ -108,13 +97,12 @@ if not person.Person_isServiceProvider():\n
mapping_dict = {\'computer_title\':computer.getTitle(),\n mapping_dict = {\'computer_title\':computer.getTitle(),\n
\'computer_id\':computer_reference,\n \'computer_id\':computer_reference,\n
\'allocation_scope\':allocation_scope}\n \'allocation_scope\':allocation_scope}\n
\n
message = notification_message.asText(\n message = notification_message.asText(\n
substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n substitution_method_parameter_dict={\'mapping_dict\': mapping_dict})\n
else:\n
message = request_description\n
\n \n
event = support_request.SupportRequest_trySendNotificationMessage(request_title,\n event = support_request.SupportRequest_trySendNotificationMessage(\n
message, person.getRelativeUrl())\n request_title, message, person.getRelativeUrl())\n
\n \n
if event is not None:\n if event is not None:\n
computer.edit(**edit_kw)\n computer.edit(**edit_kw)\n
......
...@@ -76,8 +76,8 @@ try:\n ...@@ -76,8 +76,8 @@ try:\n
d = memcached_dict[reference]\n d = memcached_dict[reference]\n
d = json.loads(d)\n d = json.loads(d)\n
last_contact = DateTime(d.get(\'created_at\'))\n last_contact = DateTime(d.get(\'created_at\'))\n
if (DateTime() - last_contact) > 1:\n if (DateTime() - last_contact) > 0.02:\n
description = "The Computer %s (%s) has not contacted the server for more than 24 hours" \\\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 "(last contact date: %s)" % (computer_title, reference, last_contact)\n
else:\n else:\n
should_notify = False\n should_notify = False\n
...@@ -86,45 +86,24 @@ except KeyError:\n ...@@ -86,45 +86,24 @@ except KeyError:\n
description = "The Computer %s (%s) has not contacted the server (No Contact Information)" % (\n description = "The Computer %s (%s) has not contacted the server (No Contact Information)" % (\n
computer_title, reference)\n computer_title, reference)\n
\n \n
\n
if should_notify:\n if should_notify:\n
support_request_url = context.Base_generateSupportRequestForSlapOS(\n support_request = context.Base_generateSupportRequestForSlapOS(\n
ticket_title,\n ticket_title,\n
description,\n description,\n
context.getRelativeUrl()\n context.getRelativeUrl()\n
)\n )\n
\n \n
support_request = None\n
person = context.getSourceAdministrationValue(portal_type="Person")\n person = context.getSourceAdministrationValue(portal_type="Person")\n
if not person:\n if not person:\n
return support_request_url\n return support_request\n
\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
# Send Notification message\n # Send Notification message\n
notification_reference = \'slapos-crm-computer_check_state.notification\'\n notification_reference = \'slapos-crm-computer_check_state.notification\'\n
notification_message = portal.portal_notifications.getDocumentValue(\n notification_message = portal.portal_notifications.getDocumentValue(\n
reference=notification_reference)\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 \n
Regards,\n if notification_message is None:\n
\n message = """%s""" % description\n
The slapos team""" % description\n
else:\n else:\n
mapping_dict = {\'computer_title\':context.getTitle(),\n mapping_dict = {\'computer_title\':context.getTitle(),\n
\'computer_id\':reference,\n \'computer_id\':reference,\n
...@@ -133,10 +112,10 @@ The slapos team""" % description\n ...@@ -133,10 +112,10 @@ The slapos team""" % description\n
substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
\n \n
support_request.SupportRequest_trySendNotificationMessage(\n support_request.SupportRequest_trySendNotificationMessage(\n
ticket_title.replace(\'[MONITORING] \', \'\'),\n ticket_title,\n
message, person.getRelativeUrl(), 5)\n message, person.getRelativeUrl())\n
\n \n
return support_request_url\n return support_request\n
]]></string> </value> ]]></string> </value>
......
...@@ -62,38 +62,41 @@ if portal.ERP5Site_isSupportRequestCreationClosed():\n ...@@ -62,38 +62,41 @@ if portal.ERP5Site_isSupportRequestCreationClosed():\n
# Stop ticket creation\n # Stop ticket creation\n
return\n return\n
\n \n
hs_title = hosting_subscription.getTitle()\n date_check_limit = addToDate(DateTime(), to_add={\'hour\': -1})\n
date_check_limit = addToDate(DateTime(), to_add={\'hour\': -4})\n \n
has_newest_allocated_instance = False\n if (hosting_subscription.getCreationDate() - date_check_limit) < 0:\n
has_unallocated_instance = False\n # Too early to check\n
source_instance = hosting_subscription.getPredecessorValue()\n return\n
failing_instance = None\n
\n \n
if not source_instance:\n if not source_instance:\n
return\n return\n
software_instance_list = [source_instance]\n \n
predecessors_instance = source_instance.getPredecessorValueList()\n software_instance_list = hosting_subscription.getSpecialiseRelatedValueList(\n
if len(predecessors_instance) > 0:\n portal_type=["Software Instance", "Slave Instance"])\n
software_instance_list.extend(predecessors_instance)\n \n
has_newest_allocated_instance = False\n
has_unallocated_instance = False\n
failing_instance = None\n
\n \n
# Check if at least one software Instance is Allocated\n # Check if at least one software Instance is Allocated\n
for instance in software_instance_list:\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 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 has_newest_allocated_instance = True\n
else:\n else:\n
has_unallocated_instance = True\n has_unallocated_instance = True\n
failing_instance = instance\n failing_instance = instance\n
\n \n
if has_unallocated_instance and has_newest_allocated_instance:\n if has_unallocated_instance and has_newest_allocated_instance:\n
return context.Base_generateSupportRequestForSlapOS(\n return context.HostingSubscription_createSupportRequestEvent(\n
"Hosting Subscription %s is partially allocated" % hs_title,\n failing_instance, \'slapos-crm-hosting-subscription-instance-allocation.notification\')\n
"%s has allocated instance(s) but, the instance %s (%s) has been unallocated for more than 4 hours." % (\n \n
hs_title, failing_instance.getTitle(), failing_instance.getAbsoluteUrl()),\n return\n
hosting_subscription.getRelativeUrl())\n
else:\n
return\n
]]></string> </value> ]]></string> </value>
......
...@@ -53,73 +53,44 @@ ...@@ -53,73 +53,44 @@
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\n from DateTime import DateTime\n
import json\n from Products.ERP5Type.DateUtils import addToDate\n
\n \n
hosting_subscription = context\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
if portal.ERP5Site_isSupportRequestCreationClosed():\n if portal.ERP5Site_isSupportRequestCreationClosed():\n
# Stop ticket creation\n # Stop ticket creation\n
return\n return\n
\n \n
if (DateTime() - context.getCreationDate()) < 2:\n date_check_limit = addToDate(DateTime(), to_add={\'hour\': -1})\n
# Ignore recently created instances.\n
return\n
\n \n
reference = context.getReference()\n if (hosting_subscription.getCreationDate() - date_check_limit) < 0:\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n # Too early to check\n
key_prefix=\'slap_tool\',\n return\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
\n \n
try:\n if not source_instance:\n
d = memcached_dict[reference]\n
except KeyError:\n
return\n return\n
\n \n
d = json.loads(d)\n software_instance_list = hosting_subscription.getSpecialiseRelatedValueList(\n
result = d[\'text\']\n portal_type=["Software Instance"])\n
last_contact = DateTime(d.get(\'created_at\'))\n
\n \n
# Optimise by checking memcache information first.\n has_newest_allocated_instance = False\n
if result.startswith(\'#error \'):\n has_unallocated_instance = False\n
service = context.getSpecialiseValue(portal_type=\'Hosting Subscription\')\n failing_instance = None\n
hosting_title = service.getTitle()\n \n
ticket_title = "Service %s in error state" % service.getReference()\n # Check if at least one software Instance is Allocated\n
description = "The instance %s of service %s has been in error state (last contact date: %s)" % (\n for instance in software_instance_list:\n
reference, hosting_title, last_contact)\n if instance.getSlapState() not in ["start_requested", "stop_requested"]:\n
support_request_url = context.Base_generateSupportRequestForSlapOS(\n continue\n
ticket_title, description, service.getRelativeUrl())\n \n
\n if (instance.getCreationDate() - date_check_limit) < 0:\n
if not support_request_url:\n continue\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
\n \n
Regards,\n if instance.SoftwareInstance_hasReportedError():\n
return context.HostingSubscription_createSupportRequestEvent(\n
instance, \'slapos-crm-hosting-subscription-instance-allocation.notification\')\n
\n \n
The slapos team""" % description\n return\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
]]></string> </value> ]]></string> </value>
...@@ -130,7 +101,7 @@ The slapos team""" % description\n ...@@ -130,7 +101,7 @@ The slapos team""" % description\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>SoftwareInstance_checkState</string> </value> <value> <string>HostingSubscription_checkSofwareInstanceError</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -50,20 +50,14 @@ ...@@ -50,20 +50,14 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <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 \n
instance = hosting_subscription.getPredecessorValue()\n return\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
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -72,7 +66,7 @@ for sub_instance in instance_list:\n ...@@ -72,7 +66,7 @@ for sub_instance in instance_list:\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>HostingSubscription_CheckInstanceState</string> </value> <value> <string>HostingSubscription_checkSofwareInstanceState</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </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 @@ ...@@ -50,29 +50,37 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n <value> <string>from DateTime import DateTime\n
category_uid = portal.restrictedTraverse(\n import json\n
"portal_categories/allocation_scope/open/public", None).getUid()\n
\n \n
if category_uid is not None:\n memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
portal.portal_catalog.searchAndActivate(\n key_prefix=\'slap_tool\',\n
portal_type = \'Computer\',\n plugin_path=\'portal_memcached/default_memcached_plugin\')\n
validation_state = \'validated\',\n
default_allocation_scope_uid = category_uid,\n
method_id = \'Computer_checkSoftwareInstanceState\',\n
activate_kw = {\'tag\':tag} \n
)\n
\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> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value> <value> <string></string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Alarm_checkSoftwareInstanceState</string> </value> <value> <string>SoftwareInstallation_hasReportedError</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -50,25 +50,29 @@ ...@@ -50,25 +50,29 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n <value> <string>from DateTime import DateTime\n
import json\n
\n \n
partition_list = portal.portal_catalog(portal_type = \'Computer Partition\',\n memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
free_for_request = 0,\n key_prefix=\'slap_tool\',\n
parent_uid = context.getUid()\n plugin_path=\'portal_memcached/default_memcached_plugin\')\n
)\n
\n \n
hosting_subscription_list = []\n if context.getAggregateValue(portal_type="Computer Partition") is not None:\n
for partition in partition_list:\n try:\n
software_instance = partition.getAggregateRelatedValue(\n d = memcached_dict[context.getReference()]\n
portal_type=\'Software Instance\')\n except KeyError:\n
if software_instance:\n return \n
hosting = software_instance.getSpecialiseValue(\n \n
portal_type=\'Hosting Subscription\')\n d = json.loads(d)\n
if hosting and not hosting in hosting_subscription_list:\n result = d[\'text\']\n
hosting_subscription_list.append(hosting)\n last_contact = DateTime(d.get(\'created_at\'))\n
hosting.HostingSubscription_CheckInstanceState()\n now = DateTime()\n
\n \n
return len(hosting_subscription_list)\n # Optimise by checking memcache information first.\n
if result.startswith(\'#error \'):\n
return last_contact\n
\n
return None\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -77,7 +81,7 @@ return len(hosting_subscription_list)\n ...@@ -77,7 +81,7 @@ return len(hosting_subscription_list)\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Computer_checkSoftwareInstanceState</string> </value> <value> <string>SoftwareInstance_hasReportedError</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -50,20 +50,18 @@ ...@@ -50,20 +50,18 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>support_request = context\n
support_request = context\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
resource = portal.service_module.slapos_crm_information.getRelativeUrl()\n resource = portal.service_module.slapos_crm_information.getRelativeUrl()\n
# create Web message if needed for this ticket\n # create Web message if needed for this ticket\n
last_event = context.portal_catalog.getResultValue(\n last_event = context.portal_catalog.getResultValue(\n
title=message_title,\n
follow_up_uid=support_request.getUid(), \n follow_up_uid=support_request.getUid(), \n
sort_on=[(\'delivery.start_date\', \'DESC\')],\n sort_on=[(\'delivery.start_date\', \'DESC\')],\n
)\n )\n
if last_event and (interval_of_day > 0) and \\\n if last_event:\n
(DateTime() - last_event.getStartDate() < interval_of_day):\n # User has already been notified for this problem.\n
# User has already been notified this last 24h.\n
return\n return\n
event = portal.event_module.slapos_crm_web_message_template.\\\n event = portal.event_module.slapos_crm_web_message_template.\\\n
Base_createCloneDocument(batch_mode=1)\n Base_createCloneDocument(batch_mode=1)\n
...@@ -79,13 +77,11 @@ event.stop()\n ...@@ -79,13 +77,11 @@ event.stop()\n
event.deliver()\n event.deliver()\n
\n \n
return event\n return event\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <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>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -756,3 +756,213 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by R ...@@ -756,3 +756,213 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by R
self.assertNotEqual( self.assertNotEqual(
'Visited by RegularisationRequest_deleteHostingSubscriptionList', 'Visited by RegularisationRequest_deleteHostingSubscriptionList',
ticket.workflow_history['edit_workflow'][-1]['comment']) 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): ...@@ -2024,12 +2024,12 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin):
return notification_message.getRelativeUrl() 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( support_request = self.portal.portal_catalog.getResultValue(
portal_type = 'Support Request', portal_type = 'Support Request',
title = request_title, title = request_title,
simulation_state = 'validated', simulation_state = 'validated',
source_project_uid = source_uid source_project_uid = computer_uid
) )
return support_request return support_request
...@@ -2047,35 +2047,6 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin): ...@@ -2047,35 +2047,6 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin):
computer.validate() computer.validate()
return computer 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): def _simulateBase_generateSupportRequestForSlapOS(self):
script_name = 'Base_generateSupportRequestForSlapOS' script_name = 'Base_generateSupportRequestForSlapOS'
if script_name in self.portal.portal_skins.custom.objectIds(): if script_name in self.portal.portal_skins.custom.objectIds():
...@@ -2200,57 +2171,3 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin): ...@@ -2200,57 +2171,3 @@ class TestSlapOSComputer_CheckState(testSlapOSMixin):
'Test NM content\n%s\n' % computer.getReference(), 'Test NM content\n%s\n' % computer.getReference(),
person.getRelativeUrl(), message_interval_per_day), person.getRelativeUrl(), message_interval_per_day),
ticket.workflow_history['edit_workflow'][-1]['comment']) 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'])
...@@ -39,6 +39,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -39,6 +39,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
super(TestSlapOSCloudSupportRequestGeneration, self).afterSetUp() super(TestSlapOSCloudSupportRequestGeneration, self).afterSetUp()
self.new_id = self.generateNewId() self.new_id = self.generateNewId()
self._cancelTestSupportRequestList() self._cancelTestSupportRequestList()
self.portal.REQUEST.set("support_request_in_progress", None)
def _cancelTestSupportRequestList(self): def _cancelTestSupportRequestList(self):
for support_request in self.portal.portal_catalog( for support_request in self.portal.portal_catalog(
...@@ -65,6 +66,14 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -65,6 +66,14 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
person.immediateReindexObject() person.immediateReindexObject()
return person return person
def _makeSupportRequest(self, new_id):
support_request = self.portal.\
support_request_module.\
slapos_crm_support_request_template_for_monitoring.\
Base_createCloneDocument(batch_mode=1)
return support_request
def _makeComputer(self,new_id): def _makeComputer(self,new_id):
# Clone computer document # Clone computer document
person = self.portal.person_module.template_member\ person = self.portal.person_module.template_member\
...@@ -159,8 +168,6 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -159,8 +168,6 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
self.assertNotEqual(support_request, None) self.assertNotEqual(support_request, None)
support_request = self.portal.restrictedTraverse(support_request)
# The support request is added to computer owner. # The support request is added to computer owner.
self.assertEquals(support_request.getDestinationDecision(), self.assertEquals(support_request.getDestinationDecision(),
computer.getSourceAdministration()) computer.getSourceAdministration())
...@@ -178,8 +185,6 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -178,8 +185,6 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
self.assertNotEqual(support_request, None) self.assertNotEqual(support_request, None)
support_request = self.portal.restrictedTraverse(support_request)
# The support request is added to computer owner. # The support request is added to computer owner.
self.assertEquals(support_request.getDestinationDecision(), self.assertEquals(support_request.getDestinationDecision(),
host_sub.getDestinationSection()) host_sub.getDestinationSection())
...@@ -195,8 +200,6 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -195,8 +200,6 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
self.assertNotEqual(support_request, None) self.assertNotEqual(support_request, None)
support_request = self.portal.restrictedTraverse(support_request)
# The support request is added to computer owner. # The support request is added to computer owner.
self.assertEquals(support_request.getDestinationDecision(), self.assertEquals(support_request.getDestinationDecision(),
host_sub.getDestinationSection()) host_sub.getDestinationSection())
...@@ -204,17 +207,37 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -204,17 +207,37 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
def test_Base_generateSupportRequestForSlapOS_do_not_recreate_if_open(self): def test_Base_generateSupportRequestForSlapOS_do_not_recreate_if_open(self):
title = "Test Support Request %s" % self.new_id title = "Test Support Request %s" % self.new_id
computer = self._makeComputer(self.new_id) computer = self._makeComputer(self.new_id)
computer.Base_generateSupportRequestForSlapOS( support_request = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl() title, title, computer.getRelativeUrl()
) )
self.tic() self.tic()
self.portal.REQUEST.set("support_request_in_progress", None)
same_support_request = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl()
)
self.assertEqual(support_request, same_support_request)
def test_Base_generateSupportRequestForSlapOS_do_not_recreate_if_suspended(self):
title = "Test Support Request %s" % self.new_id
computer = self._makeComputer(self.new_id)
support_request = computer.Base_generateSupportRequestForSlapOS( support_request = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl() title, title, computer.getRelativeUrl()
) )
support_request.suspend()
self.tic() self.tic()
self.portal.REQUEST.set("support_request_in_progress", None)
same_support_request = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl()
)
self.assertEqual(support_request, same_support_request)
self.assertEqual(support_request, None)
def test_ERP5Site_isSupportRequestCreationClosed(self): def test_ERP5Site_isSupportRequestCreationClosed(self):
...@@ -278,9 +301,11 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -278,9 +301,11 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
) )
self.tic() self.tic()
self.portal.restrictedTraverse(support_request).invalidate() support_request.invalidate()
self.tic() self.tic()
self.portal.REQUEST.set("support_request_in_progress", None)
support_request = computer.Base_generateSupportRequestForSlapOS( support_request = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl() title, title, computer.getRelativeUrl()
) )
...@@ -288,6 +313,19 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -288,6 +313,19 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
self.assertNotEqual(support_request,None) self.assertNotEqual(support_request,None)
def test_Base_generateSupportRequestForSlapOS_recreate(self):
title = "Test Support Request %s" % self.new_id
computer = self._makeComputer(self.new_id)
support_request = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl()
)
same_support_request = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl()
)
self.assertEqual(support_request, same_support_request)
def _simulateBase_generateSupportRequestForSlapOS(self): def _simulateBase_generateSupportRequestForSlapOS(self):
script_name = 'Base_generateSupportRequestForSlapOS' script_name = 'Base_generateSupportRequestForSlapOS'
if script_name in self.portal.portal_skins.custom.objectIds(): if script_name in self.portal.portal_skins.custom.objectIds():
...@@ -296,7 +334,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -296,7 +334,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
script_name, script_name,
'*args, **kw', '*args, **kw',
'# Script body\n' '# Script body\n'
"""return 'Visited Base_generateSupportRequestForSlapOS'""") """return context.getPortalObject().REQUEST['_simulateBase_generateSupportRequestForSlapOS']""")
transaction.commit() transaction.commit()
def _dropBase_generateSupportRequestForSlapOS(self): def _dropBase_generateSupportRequestForSlapOS(self):
...@@ -316,15 +354,36 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -316,15 +354,36 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
{"created_at":"%s" % (DateTime() - 1.1)} {"created_at":"%s" % (DateTime() - 1.1)}
) )
support_request = self._makeSupportRequest(self.new_id)
self.portal.REQUEST.set('_simulateBase_generateSupportRequestForSlapOS',
support_request)
self._simulateBase_generateSupportRequestForSlapOS()
try:
computer_support_request = computer.Computer_checkState()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual(support_request,
computer_support_request)
def test_Computer_checkState_empty_cache(self):
computer = self._makeComputer(self.new_id)
support_request = self._makeSupportRequest(self.new_id)
self.portal.REQUEST.set('_simulateBase_generateSupportRequestForSlapOS',
support_request)
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
try: try:
result = computer.Computer_checkState() computer_support_request = computer.Computer_checkState()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS', self.assertEqual(support_request,
result) computer_support_request)
def test_SupportRequest_trySendNotificationMessage(self): def test_SupportRequest_trySendNotificationMessage(self):
computer = self._makeComputer(self.new_id) computer = self._makeComputer(self.new_id)
...@@ -337,13 +396,11 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -337,13 +396,11 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
destination_decision=computer.getSourceAdministration(), destination_decision=computer.getSourceAdministration(),
source_project_value=computer.getRelativeUrl()) source_project_value=computer.getRelativeUrl())
support_request.validate() support_request.validate()
time_before_next = 2
self.tic() self.tic()
first_event = support_request.SupportRequest_trySendNotificationMessage( first_event = support_request.SupportRequest_trySendNotificationMessage(
message_title=title, message=text_content, message_title=title, message=text_content,
source_relative_url=person.getRelativeUrl(), source_relative_url=person.getRelativeUrl()
interval_of_day=time_before_next
) )
self.assertNotEqual(first_event, None) self.assertNotEqual(first_event, None)
...@@ -352,599 +409,70 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -352,599 +409,70 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
event = support_request.SupportRequest_trySendNotificationMessage( event = support_request.SupportRequest_trySendNotificationMessage(
message_title=title, message=text_content, message_title=title, message=text_content,
source_relative_url=person.getRelativeUrl(), source_relative_url=person.getRelativeUrl()
interval_of_day=time_before_next
) )
self.assertEqual(event, None) self.assertEqual(event, None)
time_before_next = 1 title += "__zz"
event = support_request.SupportRequest_trySendNotificationMessage( event = support_request.SupportRequest_trySendNotificationMessage(
message_title=title, message=text_content, message_title=title, message=text_content,
source_relative_url=person.getRelativeUrl(), source_relative_url=person.getRelativeUrl(),
interval_of_day=time_before_next
) )
self.assertEqual(event.getTitle(), title)
def test_Computer_checkState_empty_cache(self): self.assertEqual(event.getTitle(), title)
computer = self._makeComputer(self.new_id)
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = computer.Computer_checkState()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareInstance_checkState_error_new_instance(self):
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
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 "}
)
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = instance.SoftwareInstance_checkState()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareInstance_checkState_error_out_time(self): def test_SoftwareInstance_hasReportedError(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl()) self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue() instance = host_sub.getPredecessorValue()
instance.workflow_history['edit_workflow'] = [{ computer = self._makeComputer(self.new_id)
'comment':'edit', self._makeComputerPartitions(computer)
'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 "}
)
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = instance.SoftwareInstance_checkState()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareInstance_checkState_error_in_time(self):
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
memcached_dict = self.portal.portal_memcached.getMemcachedDict( memcached_dict = self.portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool', key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin') plugin_path='portal_memcached/default_memcached_plugin')
error_date = DateTime()
memcached_dict[instance.getReference()] = json.dumps( memcached_dict[instance.getReference()] = json.dumps(
{"created_at":"%s" % (DateTime()), "text":"#error "} {"created_at":"%s" % error_date, "text": "#error "}
) )
self._simulateBase_generateSupportRequestForSlapOS() self.assertEquals(instance.SoftwareInstance_hasReportedError(), None)
try:
result = instance.SoftwareInstance_checkState()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareInstance_checkState_access_in_time(self): instance.setAggregateValue(computer.partition1)
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
memcached_dict = self.portal.portal_memcached.getMemcachedDict( self.assertEquals(instance.SoftwareInstance_hasReportedError(), error_date)
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[instance.getReference()] = json.dumps( memcached_dict[instance.getReference()] = json.dumps(
{"created_at":"%s" % (DateTime()), "text":"#access "} {"created_at":"%s" % error_date, "text": "#access "}
)
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = instance.SoftwareInstance_checkState()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareInstance_checkState_empty_cache(self):
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = instance.SoftwareInstance_checkState()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareRelease_testForAllocation(self):
software_release = self._makeSoftwareRelease(self.new_id)
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/public', capacity_scope = 'open')
self._makeComputerPartitions(computer)
self._makeSoftwareInstallation(
self.new_id, computer, software_release.getUrlString()
) )
self.tic() self.assertEquals(instance.SoftwareInstance_hasReportedError(), None)
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = software_release.SoftwareRelease_testForAllocation()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareRelease_testForAllocation_no_public_computer(self): def test_SoftwareInstallation_hasReportedError(self):
software_release = self._makeSoftwareRelease(self.new_id) software_release = self._makeSoftwareRelease(self.new_id)
computer = self._makeComputer(self.new_id) computer = self._makeComputer(self.new_id)
computer.edit(capacity_scope = 'open') installation = self._makeSoftwareInstallation(
self._makeComputerPartitions(computer)
self._makeSoftwareInstallation(
self.new_id, computer, software_release.getUrlString() self.new_id, computer, software_release.getUrlString()
) )
self.tic() memcached_dict = self.portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
self._simulateBase_generateSupportRequestForSlapOS() plugin_path='portal_memcached/default_memcached_plugin')
try:
result = software_release.SoftwareRelease_testForAllocation()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS', self.assertEquals(installation.SoftwareInstance_hasReportedError(), None)
result)
def test_SoftwareRelease_testForAllocation_no_open_computer(self): error_date = DateTime()
software_release = self._makeSoftwareRelease(self.new_id) memcached_dict[installation.getReference()] = json.dumps(
computer = self._makeComputer(self.new_id) {"created_at":"%s" % error_date, "text": "#error "}
computer.edit(allocation_scope = 'open/public')
self._makeComputerPartitions(computer)
self._makeSoftwareInstallation(
self.new_id, computer, software_release.getUrlString()
) )
self.tic() self.assertEquals(installation.SoftwareInstallation_hasReportedError(), error_date)
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = software_release.SoftwareRelease_testForAllocation()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareRelease_testForAllocation_no_free_partitions(self):
software_release = self._makeSoftwareRelease(self.new_id)
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/public', capacity_scope = 'open')
self._makeComputerPartitions(computer)
computer.partition1.markBusy()
computer.partition2.markBusy()
computer.partition3.markBusy()
computer.partition4.markBusy()
self._makeSoftwareInstallation( memcached_dict[installation.getReference()] = json.dumps(
self.new_id, computer, software_release.getUrlString() {"created_at":"%s" % error_date, "text": "#building "}
) )
self.tic() self.assertEquals(installation.SoftwareInstallation_hasReportedError(), None)
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = software_release.SoftwareRelease_testForAllocation()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def _simulateSoftwareInstance_checkState(self):
script_name = 'SoftwareInstance_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 SoftwareInstance_checkState') """ )
transaction.commit()
def _dropSoftwareInstance_checkState(self):
script_name = 'SoftwareInstance_checkState'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def testHostingSubscription_CheckInstanceState(self):
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub, self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
self._simulateSoftwareInstance_checkState()
try:
host_sub.HostingSubscription_CheckInstanceState()
self.tic()
finally:
self._dropSoftwareInstance_checkState()
self.assertEqual('Visited by SoftwareInstance_checkState',
instance.workflow_history['edit_workflow'][-1]['comment'])
def _simulateHostingSubscription_CheckInstanceState(self):
script_name = 'HostingSubscription_CheckInstanceState'
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_CheckInstanceState') """ )
transaction.commit()
def _dropHostingSubscription_CheckInstanceState(self):
script_name = 'HostingSubscription_CheckInstanceState'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_Computer_checkSoftwareInstanceState(self):
computer = self._makeComputer(self.new_id)
self._makeComputerPartitions(computer)
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub, self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
instance.edit(aggregate_value = computer.partition1.getRelativeUrl())
computer.partition1.markBusy()
self.tic()
self._simulateHostingSubscription_CheckInstanceState()
try:
computer.Computer_checkSoftwareInstanceState()
self.tic()
finally:
self._dropHostingSubscription_CheckInstanceState()
self.assertEqual('Visited by HostingSubscription_CheckInstanceState',
host_sub.workflow_history['edit_workflow'][-1]['comment'])
def test_Computer_checkSoftwareInstanceState_instance_not_allocated(self):
computer = self._makeComputer(self.new_id)
host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub, self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue()
self.tic()
self._simulateHostingSubscription_CheckInstanceState()
try:
computer.Computer_checkSoftwareInstanceState()
self.tic()
finally:
self._dropHostingSubscription_CheckInstanceState()
self.assertNotEqual('Visited by HostingSubscription_CheckInstanceState',
instance.workflow_history['edit_workflow'][-1]['comment'])
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_checkComputerState(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/public')
self._simulateComputer_checkState()
try:
self.portal.portal_alarms.slapos_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_checkComputerState_no_public_computer(self):
computer = self._makeComputer(self.new_id)
self._simulateComputer_checkState()
try:
self.portal.portal_alarms.slapos_check_computer_state.activeSense()
self.tic()
finally:
self._dropComputer_checkState()
self.assertNotEqual('Visited by Computer_checkState',
computer.workflow_history['edit_workflow'][-1]['comment'])
def _simulateComputer_checkSoftwareInstanceState(self):
script_name = 'Computer_checkSoftwareInstanceState'
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_checkSoftwareInstanceState') """ )
transaction.commit()
def _dropComputer_checkSoftwareInstanceState(self):
script_name = 'Computer_checkSoftwareInstanceState'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_Alarm_checkSoftwareInstanceState(self):
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/public')
self._simulateComputer_checkSoftwareInstanceState()
try:
self.portal.portal_alarms.slapos_check_software_instance_state.activeSense()
self.tic()
finally:
self._dropComputer_checkSoftwareInstanceState()
self.assertEqual('Visited by Computer_checkSoftwareInstanceState',
computer.workflow_history['edit_workflow'][-1]['comment'])
def test_Alarm_checkSoftwareInstanceState_no_public_computer(self):
computer = self._makeComputer(self.new_id)
self._simulateComputer_checkSoftwareInstanceState()
try:
self.portal.portal_alarms.slapos_check_software_instance_state.activeSense()
self.tic()
finally:
self._dropComputer_checkSoftwareInstanceState()
self.assertNotEqual('Visited by Computer_checkSoftwareInstanceState',
computer.workflow_history['edit_workflow'][-1]['comment'])
def _simulateSoftwareRelease_testForAllocation(self):
script_name = 'SoftwareRelease_testForAllocation'
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 SoftwareRelease_testForAllocation') """ )
transaction.commit()
def _dropSoftwareRelease_testForAllocation(self):
script_name = 'SoftwareRelease_testForAllocation'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_Alarm_checkCloudIsFull(self):
software_release_preference = self.portal.portal_preferences.getPreferredSoftwareReleaseToTestForSpace()
if software_release_preference != '':
software_release_list = software_release_preference.split("\n")
software_release = self._makeSoftwareRelease(
self.new_id, software_release_list[0])
self._simulateSoftwareRelease_testForAllocation()
try:
self.portal.portal_alarms.slapos_check_cloud_is_full.activeSense()
self.tic()
finally:
self._dropSoftwareRelease_testForAllocation()
self.assertEqual('Visited by SoftwareRelease_testForAllocation',
software_release.workflow_history['edit_workflow'][-1]['comment'])
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_notAllowedAllocationScope_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_notAllowedAllocationScope_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_notAllowedAllocationScope_OpenPersonal(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_AllowedAllocationScope_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_AllowedAllocationScope_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'])
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'])
event_module/slapos_crm_web_message_template event_module/slapos_crm_web_message_template
person_module/allocation_tester 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_cancel_invoice
portal_alarms/slapos_crm_check_computer_state
portal_alarms/slapos_crm_check_partially_allocated_instance portal_alarms/slapos_crm_check_partially_allocated_instance
portal_alarms/slapos_crm_check_update_allocation_scope portal_alarms/slapos_crm_check_update_allocation_scope
portal_alarms/slapos_crm_create_regularisation_request portal_alarms/slapos_crm_create_regularisation_request
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</item> </item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
<value> <int>1</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</item> </item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
<value> <int>1</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<ZopeData> <ZopeData>
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/> <global name="ERP5 Form" module="erp5.portal_type"/>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
if context.getSimulationState() != \'stopped\':\n if context.getSimulationState() != \'stopped\':\n
return \n return \n
\n \n
if context.UpgradeDecision_isUpgradeFinished():\n if not context.UpgradeDecision_isUpgradeFinished():\n
return \n return \n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
...@@ -109,6 +109,7 @@ event = context.SupportRequest_trySendNotificationMessage(title,\n ...@@ -109,6 +109,7 @@ event = context.SupportRequest_trySendNotificationMessage(title,\n
message, person.getRelativeUrl())\n message, person.getRelativeUrl())\n
\n \n
if event is not None:\n if event is not None:\n
context.setStopDate(DateTime())\n
context.deliver()\n context.deliver()\n
</string> </value> </string> </value>
</item> </item>
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
<item> <item>
<key> <string>delegated_list</string> </key> <key> <string>delegated_list</string> </key>
<value> <value>
<list/> <list>
<string>portal_type</string>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -77,6 +79,17 @@ ...@@ -77,6 +79,17 @@
<key> <string>form_id</string> </key> <key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</string> </value> <value> <string>Base_viewTradeFieldLibrary</string> </value>
</item> </item>
<item>
<key> <string>portal_type</string> </key>
<value>
<list>
<tuple>
<string>Service</string>
<string>Service</string>
</tuple>
</list>
</value>
</item>
<item> <item>
<key> <string>target</string> </key> <key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value> <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