Commit 960a4068 authored by Vivien Alger's avatar Vivien Alger

Support Request generation: Alarm_checkCloudIsFull refactoring

parent 06c32a51
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Person" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>__translation_dict</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>allocation_tester</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>first_name</string> </key>
<value> <string>Member</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>allocation_tester</string> </value>
</item>
<item>
<key> <string>last_name</string> </key>
<value> <string>Template</string> </value>
</item>
<item>
<key> <string>password</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Person</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Allocation tester</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string>{SSHA}f1gAG3A53rfwjkLB/+Ex89MtocZz/4V9K4TZ</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Support Request" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<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>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>source_section/organisation_module/slapos</string>
<string>source_trade/organisation_module/slapos</string>
<string>source/organisation_module/slapos</string>
<string>resource/service_module/slapos_crm_monitoring</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>SR-282</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_crm_support_request_template_for_monitoring</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Support Request</string> </value>
</item>
<item>
<key> <string>price</string> </key>
<value> <float>0.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Template Support Request For Monitoring</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>preferred_software_release_to_test_for_space_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>preference</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python:\'\'</string> </value>
</item>
<item>
<key> <string>write_permission</string> </key>
<value> <string>Manage properties</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>preferred_support_request_resource_for_monitoring_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>preference</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python:\'\'</string> </value>
</item>
<item>
<key> <string>write_permission</string> </key>
<value> <string>Manage properties</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -52,23 +52,25 @@ ...@@ -52,23 +52,25 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n <value> <string>portal = context.getPortalObject()\n
\n \n
computer_list = portal.portal_catalog(\n software_release_preference = portal.portal_preferences.getPreferredSoftwareReleaseToTestForSpace()\n
portal_type=\'Computer\',\n
validation_state = \'validated\',\n
capacity_scope = \'open\',\n
limit = 1\n
)\n
\n \n
if len(computer_list) == 0:\n if software_release_preference != \'\':\n
context.activate(tag=tag).Base_generateSupportRequestForSlapOS(\n software_release_list = software_release_preference.split("\\n")\n
"VIFIB public cloud is full",\n \n
"No more computer with open capacity scope, add more ASAP"\n portal.portal_catalog.searchAndActivate(\n
portal_type = \'Software Release\',\n
url_string = software_release_list,\n
\n
method_id = \'SoftwareRelease_testForAllocation\',\n
activate_kw = {\'tag\':tag} \n
)\n )\n
\n
context.activate(after_tag=tag).getId()\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value> <value> <string>tag, fixit, params</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
<?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>from DateTime import DateTime\n
\n
portal = context.getPortalObject()\n
\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_value = source_relative_url\n
)\n
\n
if support_request_in_progress is None:\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
title = title,\n
description = description,\n
start_date = DateTime(),\n
source_project_value = source_relative_url\n
)\n
support_request.validate()\n
\n
return support_request.getRelativeUrl()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>title, description, source_relative_url</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_generateSupportRequestForSlapOS</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -58,7 +58,7 @@ partition_list = portal.portal_catalog(portal_type = \'Computer Partition\',\n ...@@ -58,7 +58,7 @@ partition_list = portal.portal_catalog(portal_type = \'Computer Partition\',\n
)\n )\n
\n \n
for partition in partition_list:\n for partition in partition_list:\n
instance = partition.getAggregateRelatedValue()\n instance = partition.getAggregateRelatedValue(portal_type=\'Software Instance\')\n
if instance is not None:\n if instance is not None:\n
instance.activate().SoftwareInstance_checkState()\n instance.activate().SoftwareInstance_checkState()\n
</string> </value> </string> </value>
......
...@@ -53,18 +53,28 @@ ...@@ -53,18 +53,28 @@
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\n from DateTime import DateTime\n
import json\n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
last_contact = context.Computer_getLastestContactedDate()\n
reference = context.getReference()\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
\n
try:\n
d = memcached_dict[reference]\n
except KeyError:\n
return\n
\n \n
if last_contact != "Computer didn\'t contact the server":\n d = json.loads(d)\n
if (DateTime() - last_contact) > 1:\n last_contact = DateTime(d.get(\'created_at\'))\n
tag = "Support Request generation for %s" % reference\n \n
context.activate(tag=tag).Base_generateSupportRequestForSlapOS(\n if (DateTime() - last_contact) > 1:\n
"Support Request for %s" % reference,\n return context.Base_generateSupportRequestForSlapOS(\n
"%s has not contacted the server for more than 24 hours" % reference\n "Lost contact with %s" % reference,\n
"%s has not contacted the server for more than 24 hours (last contact date: %s)" % (reference, last_contact),\n
context.getRelativeUrl()\n
)\n )\n
......
...@@ -69,23 +69,27 @@ d = json.loads(d)\n ...@@ -69,23 +69,27 @@ d = json.loads(d)\n
result = d[\'text\']\n result = d[\'text\']\n
last_contact = DateTime(d.get(\'created_at\'))\n last_contact = DateTime(d.get(\'created_at\'))\n
now = DateTime()\n now = DateTime()\n
title = ""\n
\n \n
if result.startswith(\'#error \'):\n if result.startswith(\'#error \'):\n
# If no change in the last 2 hours generate a support request\n # If no change in the last 2 hours generate a support request\n
if (now - last_contact) > 0.08:\n if (now - last_contact) > 0.08:\n
tag = "Support Request generation for %s" % reference\n tag = "Support Request generation for %s" % reference\n
context.activate(tag=tag).Base_generateSupportRequestForSlapOS(\n title = "Instance %s in error state" % reference\n
"Support Request for %s" % reference,\n description = "%s has been in error state for more than 2 hours (last contact date: %s)" % (reference, last_contact)\n
"%s has been in error state for more than 2 hours" % reference\n
)\n
\n \n
elif result.startswith(\'#access \'):\n elif result.startswith(\'#access \'):\n
# If there was no contact for more than one day generate a support request\n # If there was no contact for more than one day generate a support request\n
if (now - last_contact) > 1:\n if (now - last_contact) > 1:\n
tag = "Support Request generation for %s" % reference\n tag = "Support Request generation for %s" % reference\n
context.activate(tag=tag).Base_generateSupportRequestForSlapOS(\n title = "Instance %s in unknown state" % reference\n
"Support Request for %s" % reference,\n description = "%s has not contacted the server for more than 24 hours (last contact date: %s)" % (reference, last_contact)\n
"%s has not contacted the server for more than 24 hours" % reference\n \n
if title != "":\n
return context.Base_generateSupportRequestForSlapOS(\n
title,\n
description,\n
context.getRelativeUrl()\n
)\n )\n
......
<?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>portal = context.getPortalObject()\n
software_release = context\n
software_release_url = software_release.getUrlString()\n
\n
user = portal.person_module.allocation_tester\n
\n
result = user.Person_restrictMethodAsShadowUser(\n
shadow_document=user,\n
callable_object=user.Person_findPartition,\n
argument_list=[\n
software_release_url,\n
\'\',\n
\'Software Instance\',\n
{}\n
],\n
argument_dict={\n
\'test_mode\': True})\n
\n
if not result:\n
title = "Can\'t allocate new instances for software release %s" % software_release_url\n
description = "Need more public computers that can instanciate the software release %s" % software_release_url\n
\n
return software_release.Base_generateSupportRequestForSlapOS(\n
title,\n
description,\n
software_release.getRelativeUrl()\n
)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareRelease_testForAllocation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
<string>my_preferred_support_request_template</string> <string>my_preferred_support_request_template</string>
<string>my_preferred_web_message_template</string> <string>my_preferred_web_message_template</string>
<string>my_preferred_slapos_web_site_url</string> <string>my_preferred_slapos_web_site_url</string>
<string>my_preferred_support_request_resource_for_monitoring</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -106,6 +107,7 @@ ...@@ -106,6 +107,7 @@
<list> <list>
<string>my_preferred_regularisation_request_use_list</string> <string>my_preferred_regularisation_request_use_list</string>
<string>my_preferred_regularisation_request_resource</string> <string>my_preferred_regularisation_request_resource</string>
<string>my_preferred_software_release_to_test_for_space</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_preferred_software_release_to_test_for_space</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_text_area_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Software Release To Test For Space</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_preferred_support_request_resource_for_monitoring</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Resource For Monitoring Support Request</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -63,6 +63,33 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -63,6 +63,33 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
p.markFree() p.markFree()
p.validate() p.validate()
def _makeSoftwareRelease(self, new_id, software_release_url=None):
software_release = self.portal.software_release_module\
.template_software_release.Base_createCloneDocument(batch_mode=1)
software_release.edit(
url_string=software_release_url or self.generateNewSoftwareReleaseUrl(),
reference='TESTSOFTRELS-%s' % new_id,
title='Start requested for %s' % new_id
)
software_release.release()
return software_release
def _makeSoftwareInstallation(self, new_id, computer, software_release_url):
software_installation = self.portal\
.software_installation_module.template_software_installation\
.Base_createCloneDocument(batch_mode=1)
software_installation.edit(
url_string=software_release_url,
aggregate=computer.getRelativeUrl(),
reference='TESTSOFTINSTS-%s' % new_id,
title='Start requested for %s' % computer.getUid()
)
software_installation.validate()
software_installation.requestStart()
return software_installation
def _makeHostingSubscription(self, new_id): def _makeHostingSubscription(self, new_id):
hosting_subscription = self.portal\ hosting_subscription = self.portal\
.hosting_subscription_module.template_hosting_subscription\ .hosting_subscription_module.template_hosting_subscription\
...@@ -92,64 +119,45 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -92,64 +119,45 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
def test_Base_generateSupportRequestForSlapOS(self): def test_Base_generateSupportRequestForSlapOS(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(title,title) support_request = computer.Base_generateSupportRequestForSlapOS(
self.tic() title, title, computer.getRelativeUrl()
support_request = self.portal.portal_catalog.getResultValue(
portal_type = 'Support Request',
title = title,
simulation_state = ["validated","submitted","suspended"]
) )
self.tic()
self.assertNotEqual(support_request,None) self.assertNotEqual(support_request,None)
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(title,title) computer.Base_generateSupportRequestForSlapOS(
self.tic() title, title, computer.getRelativeUrl()
)
computer.Base_generateSupportRequestForSlapOS(title,title)
self.tic() self.tic()
support_request_list = self.portal.portal_catalog( support_request = computer.Base_generateSupportRequestForSlapOS(
portal_type = 'Support Request', title, title, computer.getRelativeUrl()
title = title,
simulation_state = ["validated","submitted","suspended"]
) )
self.tic()
self.assertEqual(len(support_request_list),1) self.assertEqual(support_request, None)
def test_Base_generateSupportRequestForSlapOS_recreate_if_closed(self): def test_Base_generateSupportRequestForSlapOS_recreate_if_closed(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(title,title) support_request = computer.Base_generateSupportRequestForSlapOS(
self.tic() title, title, computer.getRelativeUrl()
support_request = self.portal.portal_catalog.getResultValue(
portal_type = 'Support Request',
title = title,
simulation_state = ["validated","submitted","suspended"]
) )
support_request.invalidate()
self.tic() self.tic()
computer.Base_generateSupportRequestForSlapOS(title,title) self.portal.restrictedTraverse(support_request).invalidate()
self.tic() self.tic()
support_request_list = self.portal.portal_catalog( support_request = computer.Base_generateSupportRequestForSlapOS(
portal_type = 'Support Request', title, title, computer.getRelativeUrl()
title = title
)
self.assertEqual(len(support_request_list),2)
support_request_list = self.portal.portal_catalog(
portal_type = 'Support Request',
title = title,
simulation_state = ["validated","submitted","suspended"]
) )
self.tic()
self.assertEqual(len(support_request_list),1) self.assertNotEqual(support_request,None)
def _simulateBase_generateSupportRequestForSlapOS(self): def _simulateBase_generateSupportRequestForSlapOS(self):
script_name = 'Base_generateSupportRequestForSlapOS' script_name = 'Base_generateSupportRequestForSlapOS'
...@@ -159,8 +167,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -159,8 +167,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
script_name, script_name,
'*args, **kw', '*args, **kw',
'# Script body\n' '# Script body\n'
"""portal_workflow = context.portal_workflow """return 'Visited Base_generateSupportRequestForSlapOS'""")
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by Base_generateSupportRequestForSlapOS') """ )
transaction.commit() transaction.commit()
def _dropBase_generateSupportRequestForSlapOS(self): def _dropBase_generateSupportRequestForSlapOS(self):
...@@ -169,39 +176,6 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by B ...@@ -169,39 +176,6 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by B
self.portal.portal_skins.custom.manage_delObjects(script_name) self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit() transaction.commit()
def _simulateComputer_getLastestContactedDate(self):
script_name = 'Computer_getLastestContactedDate'
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'
"""from DateTime import DateTime
import json
portal = context.getPortalObject()
# Check if computer has error reported
memcached_dict = portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
try:
d = memcached_dict[context.getReference()]
except KeyError:
return "Computer didn't contact the server"
log_dict = json.loads(d)
return DateTime(log_dict.get('created_at'))""")
transaction.commit()
def _dropComputer_getLastestContactedDate(self):
script_name = 'Computer_getLastestContactedDate'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_Computer_checkState(self): def test_Computer_checkState(self):
computer = self._makeComputer(self.new_id) computer = self._makeComputer(self.new_id)
memcached_dict = self.portal.portal_memcached.getMemcachedDict( memcached_dict = self.portal.portal_memcached.getMemcachedDict(
...@@ -213,33 +187,27 @@ return DateTime(log_dict.get('created_at'))""") ...@@ -213,33 +187,27 @@ return DateTime(log_dict.get('created_at'))""")
) )
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
self._simulateComputer_getLastestContactedDate()
try: try:
computer.Computer_checkState() result = computer.Computer_checkState()
self.tic()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self._dropComputer_getLastestContactedDate()
self.assertEqual('Visited by Base_generateSupportRequestForSlapOS', self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
computer.workflow_history['edit_workflow'][-1]['comment']) result)
def test_Computer_checkState_empty_cache(self): def test_Computer_checkState_empty_cache(self):
computer = self._makeComputer(self.new_id) computer = self._makeComputer(self.new_id)
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
self._simulateComputer_getLastestContactedDate()
try: try:
computer.Computer_checkState() result = computer.Computer_checkState()
self.tic()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self._dropComputer_getLastestContactedDate()
self.assertNotEqual('Visited by Base_generateSupportRequestForSlapOS', self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
computer.workflow_history['edit_workflow'][-1]['comment']) result)
def test_SoftwareInstance_checkState_error_out_time(self): def test_SoftwareInstance_checkState_error_out_time(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
...@@ -257,13 +225,12 @@ return DateTime(log_dict.get('created_at'))""") ...@@ -257,13 +225,12 @@ return DateTime(log_dict.get('created_at'))""")
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
try: try:
instance.SoftwareInstance_checkState() result = instance.SoftwareInstance_checkState()
self.tic()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited by Base_generateSupportRequestForSlapOS', self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
instance.workflow_history['edit_workflow'][-1]['comment']) result)
def test_SoftwareInstance_checkState_error_in_time(self): def test_SoftwareInstance_checkState_error_in_time(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
...@@ -281,13 +248,12 @@ return DateTime(log_dict.get('created_at'))""") ...@@ -281,13 +248,12 @@ return DateTime(log_dict.get('created_at'))""")
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
try: try:
instance.SoftwareInstance_checkState() result = instance.SoftwareInstance_checkState()
self.tic()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited by Base_generateSupportRequestForSlapOS', self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
instance.workflow_history['edit_workflow'][-1]['comment']) result)
def test_SoftwareInstance_checkState_access_out_time(self): def test_SoftwareInstance_checkState_access_out_time(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
...@@ -305,13 +271,12 @@ return DateTime(log_dict.get('created_at'))""") ...@@ -305,13 +271,12 @@ return DateTime(log_dict.get('created_at'))""")
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
try: try:
instance.SoftwareInstance_checkState() result = instance.SoftwareInstance_checkState()
self.tic()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited by Base_generateSupportRequestForSlapOS', self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
instance.workflow_history['edit_workflow'][-1]['comment']) result)
def test_SoftwareInstance_checkState_access_in_time(self): def test_SoftwareInstance_checkState_access_in_time(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
...@@ -329,13 +294,12 @@ return DateTime(log_dict.get('created_at'))""") ...@@ -329,13 +294,12 @@ return DateTime(log_dict.get('created_at'))""")
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
try: try:
instance.SoftwareInstance_checkState() result = instance.SoftwareInstance_checkState()
self.tic()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited by Base_generateSupportRequestForSlapOS', self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
instance.workflow_history['edit_workflow'][-1]['comment']) result)
def test_SoftwareInstance_checkState_empty_cache(self): def test_SoftwareInstance_checkState_empty_cache(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
...@@ -345,13 +309,98 @@ return DateTime(log_dict.get('created_at'))""") ...@@ -345,13 +309,98 @@ return DateTime(log_dict.get('created_at'))""")
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
try: try:
instance.SoftwareInstance_checkState() 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._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):
software_release = self._makeSoftwareRelease(self.new_id)
computer = self._makeComputer(self.new_id)
computer.edit(capacity_scope = 'open')
self._makeComputerPartitions(computer)
self._makeSoftwareInstallation(
self.new_id, computer, software_release.getUrlString()
)
self.tic()
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = software_release.SoftwareRelease_testForAllocation()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def test_SoftwareRelease_testForAllocation_no_open_computer(self):
software_release = self._makeSoftwareRelease(self.new_id)
computer = self._makeComputer(self.new_id)
computer.edit(allocation_scope = 'open/public')
self._makeComputerPartitions(computer)
self._makeSoftwareInstallation(
self.new_id, computer, software_release.getUrlString()
)
self.tic() self.tic()
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = software_release.SoftwareRelease_testForAllocation()
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited by Base_generateSupportRequestForSlapOS', self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
instance.workflow_history['edit_workflow'][-1]['comment']) 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(
self.new_id, computer, software_release.getUrlString()
)
self.tic()
self._simulateBase_generateSupportRequestForSlapOS()
try:
result = software_release.SoftwareRelease_testForAllocation()
finally:
self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result)
def _simulateSoftwareInstance_checkState(self): def _simulateSoftwareInstance_checkState(self):
script_name = 'SoftwareInstance_checkState' script_name = 'SoftwareInstance_checkState'
...@@ -501,3 +550,41 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by C ...@@ -501,3 +550,41 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by C
self.assertNotEqual('Visited by Computer_checkSoftwareInstanceState', self.assertNotEqual('Visited by Computer_checkSoftwareInstanceState',
computer.workflow_history['edit_workflow'][-1]['comment']) 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'])
22 23
\ No newline at end of file \ No newline at end of file
event_module/slapos_crm_web_message_template event_module/slapos_crm_web_message_template
person_module/allocation_tester
portal_alarms/slapos_check_cloud_is_full portal_alarms/slapos_check_cloud_is_full
portal_alarms/slapos_check_computer_state portal_alarms/slapos_check_computer_state
portal_alarms/slapos_check_software_instance_state portal_alarms/slapos_check_software_instance_state
...@@ -22,3 +23,4 @@ service_module/slapos_crm_spam ...@@ -22,3 +23,4 @@ service_module/slapos_crm_spam
service_module/slapos_crm_stop_acknowledgement service_module/slapos_crm_stop_acknowledgement
service_module/slapos_crm_stop_reminder service_module/slapos_crm_stop_reminder
support_request_module/slapos_crm_support_request_template support_request_module/slapos_crm_support_request_template
support_request_module/slapos_crm_support_request_template_for_monitoring
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment