Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
3c8ae81c
Commit
3c8ae81c
authored
Sep 20, 2023
by
Romain Courteaud
🐸
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_crm: test InstanceTree_checkSoftwareInstanceState
parent
1046c5f2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
237 additions
and
428 deletions
+237
-428
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/InstanceTree_checkSoftwareInstanceState.py
...crm_monitoring/InstanceTree_checkSoftwareInstanceState.py
+47
-25
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/InstanceTree_createSupportRequestEvent.py
..._crm_monitoring/InstanceTree_createSupportRequestEvent.py
+0
-55
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/InstanceTree_createSupportRequestEvent.xml
...crm_monitoring/InstanceTree_createSupportRequestEvent.xml
+0
-62
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
...ateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
+189
-0
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMSkins.py
...ateItem/portal_components/test.erp5.testSlapOSCRMSkins.py
+1
-286
No files found.
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/InstanceTree_checkSoftwareInstanceState.py
View file @
3c8ae81c
...
...
@@ -4,10 +4,6 @@ from erp5.component.module.DateUtils import addToDate
instance_tree
=
context
portal
=
context
.
getPortalObject
()
if
instance_tree
.
getMonitorScope
()
==
"disabled"
:
# Don't generate ticket if Monitor Scope is marked to disable
return
if
portal
.
ERP5Site_isSupportRequestCreationClosed
():
# Stop ticket creation
return
...
...
@@ -20,14 +16,11 @@ if (date_check_limit - instance_tree.getCreationDate()) < 0:
software_instance_list
=
context
.
portal_catalog
(
portal_type
=
[
"Software Instance"
,
"Slave Instance"
],
specialise_uid
=
instance_tree
.
getUid
(),
specialise_
_
uid
=
instance_tree
.
getUid
(),
**
{
"slapos_item.slap_state"
:
[
"start_requested"
]})
has_newest_allocated_instance
=
False
has_unallocated_instance
=
False
failing_instance
=
None
# Check if at least one software Instance is Allocated
notification_message_reference
=
None
for
instance
in
software_instance_list
:
if
(
date_check_limit
-
instance
.
getCreationDate
())
<
0
:
continue
...
...
@@ -36,19 +29,48 @@ for instance in software_instance_list:
continue
compute_partition
=
instance
.
getAggregateValue
()
if
compute_partition
is
not
None
:
has_newest_allocated_instance
=
True
if
instance
.
getPortalType
()
==
"Software Instance"
and
\
compute_partition
.
getParentValue
().
getMonitorScope
()
==
"enabled"
and
\
if
compute_partition
is
None
:
notification_message_reference
=
'slapos-crm-instance-tree-instance-allocation.notification'
elif
(
instance
.
getPortalType
()
==
"Software Instance"
)
and
\
(
compute_partition
.
getParentValue
().
getMonitorScope
()
==
"enabled"
)
and
\
instance
.
SoftwareInstance_hasReportedError
(
tolerance
=
30
):
return
context
.
InstanceTree_createSupportRequestEvent
(
instance
,
'slapos-crm-instance-tree-instance-state.notification'
)
notification_message_reference
=
'slapos-crm-instance-tree-instance-state.notification'
if
notification_message_reference
is
not
None
:
ticket_title
=
"Instance Tree %s is failing."
%
context
.
getTitle
()
error_message
=
instance
.
SoftwareInstance_hasReportedError
(
include_message
=
True
)
description
=
"%s contains software instances which are unallocated or reporting errors."
%
(
context
.
getTitle
())
if
error_message
:
description
+=
"
\
n
\
n
Message: %s"
%
str
(
error_message
)
else
:
has_unallocated_instance
=
True
failing_instance
=
instance
error_message
=
"No message!"
if
has_unallocated_instance
and
has_newest_allocated_instance
:
return
context
.
InstanceTree_createSupportRequestEvent
(
failing_instance
,
'slapos-crm-instance-tree-instance-allocation.notification'
)
project
=
context
.
getFollowUpValue
()
support_request
=
project
.
Project_createSupportRequestWithCausality
(
ticket_title
,
description
,
causality
=
context
.
getRelativeUrl
(),
destination_decision
=
context
.
getDestinationSectionValue
()
)
if
support_request
is
None
:
return
return
event
=
support_request
.
SupportRequest_getLastEvent
(
ticket_title
)
if
event
is
None
:
support_request
.
Ticket_createProjectEvent
(
ticket_title
,
'outgoing'
,
'Web Message'
,
portal
.
service_module
.
slapos_crm_information
.
getRelativeUrl
(),
text_content
=
description
,
content_type
=
'text/plain'
,
notification_message
=
notification_message_reference
,
#language=XXX,
substitution_method_parameter_dict
=
{
'instance_tree_title'
:
context
.
getTitle
(),
'instance'
:
instance
.
getTitle
(),
'error_text'
:
error_message
}
)
return
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/InstanceTree_createSupportRequestEvent.py
deleted
100644 → 0
View file @
1046c5f2
portal
=
context
.
getPortalObject
()
person
=
context
.
getDestinationSectionValue
()
if
person
is
None
or
portal
.
ERP5Site_isSupportRequestCreationClosed
(
person
.
getRelativeUrl
()):
# Stop ticket creation
return
ticket_title
=
"Instance Tree %s is failing."
%
context
.
getTitle
()
error_message
=
instance
.
SoftwareInstance_hasReportedError
(
include_message
=
True
)
description
=
"%s contains software instances which are unallocated or reporting errors."
%
(
context
.
getTitle
())
if
error_message
:
description
+=
"
\
n
\
n
Message: %s"
%
error_message
else
:
error_message
=
"No message!"
support_request
=
context
.
Base_getSupportRequestInProgress
(
title
=
ticket_title
)
if
support_request
is
None
:
person
.
notify
(
support_request_title
=
ticket_title
,
support_request_description
=
description
,
aggregate
=
context
.
getRelativeUrl
())
support_request_relative_url
=
context
.
REQUEST
.
get
(
"support_request_relative_url"
)
if
support_request_relative_url
is
None
:
return
support_request
=
portal
.
restrictedTraverse
(
support_request_relative_url
)
if
support_request
is
None
:
return
if
support_request
.
getSimulationState
()
not
in
[
"validated"
,
"suspended"
]:
support_request
.
validate
()
# Send Notification message
message
=
description
notification_message
=
portal
.
portal_notifications
.
getDocumentValue
(
reference
=
notification_message_reference
)
if
notification_message
is
not
None
:
mapping_dict
=
{
'instance_tree_title'
:
context
.
getTitle
(),
'instance'
:
instance
.
getTitle
(),
'error_text'
:
error_message
}
message
=
notification_message
.
asText
(
substitution_method_parameter_dict
=
{
'mapping_dict'
:
mapping_dict
})
event
=
support_request
.
SupportRequest_getLastEvent
(
ticket_title
)
if
event
is
None
:
support_request
.
notify
(
message_title
=
ticket_title
,
message
=
message
)
return
context
.
REQUEST
.
get
(
"ticket_notified_item"
)
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/InstanceTree_createSupportRequestEvent.xml
deleted
100644 → 0
View file @
1046c5f2
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"_reconstructor"
module=
"copy_reg"
/>
</klass>
<tuple>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
<global
name=
"object"
module=
"__builtin__"
/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
instance, notification_message_reference
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
InstanceTree_createSupportRequestEvent
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
View file @
3c8ae81c
...
...
@@ -1037,6 +1037,195 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
slapos_crm_check_instance_in_error
self
.
_test_alarm_not_visited
(
alarm
,
host_sub
,
"InstanceTree_checkSoftwareInstanceState"
)
def
_makeNotificationMessage
(
self
,
reference
):
notification_message
=
self
.
portal
.
notification_message_module
.
newContent
(
portal_type
=
"Notification Message"
,
title
=
'The Compute Node %s is building for too long'
%
reference
,
text_content
=
'Test NM content<br/>%s<br/>'
%
reference
,
content_type
=
'text/html'
,
)
return
notification_message
.
getRelativeUrl
()
def
_getGeneratedSupportRequest
(
self
,
compute_node_uid
,
request_title
):
return
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Support Request'
,
title
=
request_title
,
simulation_state
=
'validated'
,
causality__uid
=
compute_node_uid
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-instance-tree-instance-state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_InstanceTree_checkSoftwareInstanceState_notify"])'
)
def
test_InstanceTree_checkSoftwareInstanceState_script_notifyError
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
software_instance
=
self
.
start_requested_software_instance
instance_tree
=
software_instance
.
getSpecialiseValue
()
software_instance
.
setErrorStatus
(
""
)
finally
:
self
.
unpinDateTime
()
self
.
portal
.
REQUEST
[
'test_InstanceTree_checkSoftwareInstanceState_notify'
]
=
\
self
.
_makeNotificationMessage
(
instance_tree
.
getReference
())
self
.
tic
()
instance_tree
.
InstanceTree_checkSoftwareInstanceState
()
self
.
tic
()
ticket_title
=
"Instance Tree %s is failing."
%
(
instance_tree
.
getTitle
()
)
ticket
=
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
(),
ticket_title
)
self
.
assertNotEqual
(
ticket
,
None
)
event_list
=
ticket
.
getFollowUpRelatedValueList
()
self
.
assertEqual
(
len
(
event_list
),
1
)
event
=
event_list
[
0
]
self
.
assertEqual
(
event
.
getTitle
(),
ticket
.
getTitle
())
self
.
assertIn
(
instance_tree
.
getReference
(),
event
.
getTextContent
())
self
.
assertEqual
(
event
.
getFollowUp
(),
ticket
.
getRelativeUrl
())
self
.
assertEqual
(
event
.
getSourceProject
(),
instance_tree
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getSourceProject
(),
instance_tree
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getCausality
(),
instance_tree
.
getRelativeUrl
())
self
.
assertEqual
(
ticket
.
getSimulationState
(),
"validated"
)
self
.
assertEqual
(
event
.
getSimulationState
(),
"delivered"
)
self
.
assertEqual
(
event
.
getPortalType
(),
"Web Message"
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
def
test_InstanceTree_checkSoftwareInstanceState_script_notifyErrorTolerance
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
software_instance
=
self
.
start_requested_software_instance
instance_tree
=
software_instance
.
getSpecialiseValue
()
finally
:
self
.
unpinDateTime
()
software_instance
.
setErrorStatus
(
""
)
self
.
portal
.
REQUEST
[
'test_InstanceTree_checkSoftwareInstanceState_notify'
]
=
\
self
.
_makeNotificationMessage
(
instance_tree
.
getReference
())
self
.
tic
()
instance_tree
.
InstanceTree_checkSoftwareInstanceState
()
self
.
tic
()
ticket_title
=
"Instance Tree %s is failing."
%
(
instance_tree
.
getTitle
()
)
ticket
=
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
(),
ticket_title
)
self
.
assertEqual
(
ticket
,
None
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-instance-tree-instance-allocation.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_InstanceTree_checkSoftwareInstanceState_notify"])'
)
def
test_InstanceTree_checkSoftwareInstanceState_script_notifyNotAllocated
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
software_instance
=
self
.
start_requested_software_instance
instance_tree
=
software_instance
.
getSpecialiseValue
()
finally
:
self
.
unpinDateTime
()
self
.
portal
.
REQUEST
[
'test_InstanceTree_checkSoftwareInstanceState_notify'
]
=
\
self
.
_makeNotificationMessage
(
instance_tree
.
getReference
())
self
.
tic
()
software_instance
.
edit
(
aggregate
=
None
)
instance_tree
.
InstanceTree_checkSoftwareInstanceState
()
self
.
tic
()
ticket_title
=
"Instance Tree %s is failing."
%
(
instance_tree
.
getTitle
()
)
ticket
=
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
(),
ticket_title
)
self
.
assertNotEqual
(
ticket
,
None
)
event_list
=
ticket
.
getFollowUpRelatedValueList
()
self
.
assertEqual
(
len
(
event_list
),
1
)
event
=
event_list
[
0
]
self
.
assertEqual
(
event
.
getTitle
(),
ticket
.
getTitle
())
self
.
assertIn
(
instance_tree
.
getReference
(),
event
.
getTextContent
())
self
.
assertEqual
(
event
.
getFollowUp
(),
ticket
.
getRelativeUrl
())
self
.
assertEqual
(
event
.
getSourceProject
(),
instance_tree
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getSourceProject
(),
instance_tree
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getCausality
(),
instance_tree
.
getRelativeUrl
())
self
.
assertEqual
(
ticket
.
getSimulationState
(),
"validated"
)
self
.
assertEqual
(
event
.
getSimulationState
(),
"delivered"
)
self
.
assertEqual
(
event
.
getPortalType
(),
"Web Message"
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
def
test_InstanceTree_checkSoftwareInstanceState_script_tooEarly
(
self
):
try
:
self
.
pinDateTime
(
DateTime
())
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
software_instance
=
self
.
start_requested_software_instance
instance_tree
=
software_instance
.
getSpecialiseValue
()
software_instance
.
setErrorStatus
(
""
)
finally
:
self
.
unpinDateTime
()
self
.
portal
.
REQUEST
[
'test_InstanceTree_checkSoftwareInstanceState_notify'
]
=
\
self
.
_makeNotificationMessage
(
instance_tree
.
getReference
())
self
.
tic
()
instance_tree
.
InstanceTree_checkSoftwareInstanceState
()
self
.
tic
()
ticket_title
=
"Instance Tree %s is failing."
%
(
instance_tree
.
getTitle
()
)
ticket
=
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
(),
ticket_title
)
self
.
assertEqual
(
ticket
,
None
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 1'
)
def
test_InstanceTree_checkSoftwareInstanceState_script_closed
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1
)
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
software_instance
=
self
.
start_requested_software_instance
instance_tree
=
software_instance
.
getSpecialiseValue
()
software_instance
.
setErrorStatus
(
""
)
finally
:
self
.
unpinDateTime
()
self
.
portal
.
REQUEST
[
'test_InstanceTree_checkSoftwareInstanceState_notify'
]
=
\
self
.
_makeNotificationMessage
(
instance_tree
.
getReference
())
self
.
tic
()
instance_tree
.
InstanceTree_checkSoftwareInstanceState
()
self
.
tic
()
ticket_title
=
"Instance Tree %s is failing."
%
(
instance_tree
.
getTitle
()
)
ticket
=
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
(),
ticket_title
)
self
.
assertEqual
(
ticket
,
None
)
class
TestSlaposCrmUpdateSupportRequestState
(
SlapOSTestCaseMixinWithAbort
):
...
...
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMSkins.py
View file @
3c8ae81c
...
...
@@ -26,8 +26,7 @@ from erp5.component.test.SlapOSTestCaseMixin import \
SlapOSTestCaseMixin
,
SlapOSTestCaseMixinWithAbort
,
simulate
from
DateTime
import
DateTime
from
App.Common
import
rfc1123_date
from
Products.ERP5Type.Cache
import
DEFAULT_CACHE_SCOPE
import
json
def
getFakeSlapState
():
return
"destroy_requested"
...
...
@@ -967,105 +966,6 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
self
.
assertFalse
(
self
.
portal
.
ERP5Site_isSupportRequestCreationClosed
())
class
TestSlapOSInstanceTree_createSupportRequestEvent
(
SlapOSTestCaseMixin
):
def
_makeNotificationMessage
(
self
,
reference
):
notification_message
=
self
.
portal
.
notification_message_module
.
newContent
(
portal_type
=
"Notification Message"
,
title
=
'%s created an event'
%
reference
,
text_content
=
'Test NM content<br/>%s<br/>'
%
reference
,
content_type
=
'text/html'
,
)
return
notification_message
.
getRelativeUrl
()
def
_makeInstanceTree
(
self
):
person
=
self
.
makePerson
(
self
.
project
,
user
=
1
)
instance_tree
=
self
.
portal
\
.
instance_tree_module
.
template_instance_tree
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
instance_tree
.
validate
()
new_id
=
self
.
generateNewId
()
instance_tree
.
edit
(
title
=
"Test hosting sub ticket %s"
%
new_id
,
reference
=
"TESTHST-%s"
%
new_id
,
destination_section_value
=
person
)
return
instance_tree
def
_getGeneratedSupportRequest
(
self
,
instance_tree_uid
):
support_request
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Support Request'
,
simulation_state
=
"validated"
,
default_aggregate_uid
=
instance_tree_uid
)
return
support_request
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'SoftwareInstance_hasReportedError'
,
'*args, **kwargs'
,
'return "MSG"'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None'
,
'assert reference == "test-slapos-crm-check.notification"
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["testInstanceTree_createSupportRequestEvent"])'
)
def
testInstanceTree_createSupportRequestEvent
(
self
):
instance_tree
=
self
.
_makeInstanceTree
()
person
=
instance_tree
.
getDestinationSectionValue
()
self
.
portal
.
REQUEST
[
'testInstanceTree_createSupportRequestEvent'
]
=
\
self
.
_makeNotificationMessage
(
instance_tree
.
getReference
())
instance_tree
.
InstanceTree_createSupportRequestEvent
(
instance_tree
,
"test-slapos-crm-check.notification"
)
self
.
tic
()
ticket_title
=
"Instance Tree %s is failing."
%
instance_tree
.
getTitle
()
ticket
=
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
())
self
.
assertNotEqual
(
ticket
,
None
)
self
.
assertEqual
(
ticket
.
getSimulationState
(),
"validated"
)
self
.
assertNotEqual
(
ticket
,
None
)
event_list
=
ticket
.
getFollowUpRelatedValueList
()
self
.
assertEqual
(
len
(
event_list
),
1
)
event
=
event_list
[
0
]
self
.
assertEqual
(
event
.
getTitle
(),
ticket_title
)
self
.
assertIn
(
instance_tree
.
getReference
(),
event
.
getTextContent
())
self
.
assertEqual
(
event
.
getSource
(),
person
.
getRelativeUrl
())
self
.
assertEqual
(
event
.
getDestination
(),
ticket
.
getSourceSection
())
ticket
.
suspend
()
self
.
tic
()
self
.
assertEqual
(
None
,
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
()))
instance_tree
.
InstanceTree_createSupportRequestEvent
(
instance_tree
,
"test-slapos-crm-check.notification"
)
self
.
tic
()
ticket
=
self
.
_getGeneratedSupportRequest
(
instance_tree
.
getUid
())
# Do not reopen the ticket if it is suspended
self
.
assertEqual
(
None
,
ticket
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 1'
)
@
simulate
(
'SoftwareInstance_hasReportedError'
,
'*args, **kwargs'
,
'return "MSG"'
)
def
testInstanceTree_createSupportRequestEvent_closed
(
self
):
instance_tree
=
self
.
_makeInstanceTree
()
self
.
assertEqual
(
None
,
instance_tree
.
InstanceTree_createSupportRequestEvent
(
instance_tree
,
"test-slapos-crm-check.notification"
))
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'SoftwareInstance_hasReportedError'
,
'*args, **kwargs'
,
'return "MSG"'
)
def
testInstanceTree_createSupportRequestEvent_no_person
(
self
):
instance_tree
=
self
.
_makeInstanceTree
()
instance_tree
.
setDestinationSectionValue
(
None
)
self
.
assertEqual
(
None
,
instance_tree
.
InstanceTree_createSupportRequestEvent
(
instance_tree
,
"test-slapos-crm-check.notification"
))
class
TestSlapOSHasError
(
SlapOSTestCaseMixin
):
def
makeSoftwareRelease
(
self
,
software_release_url
=
None
):
...
...
@@ -1184,191 +1084,6 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self
.
assertEqual
(
installation
.
SoftwareInstallation_hasReportedError
(),
None
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
@
simulate
(
'InstanceTree_createSupportRequestEvent'
,
'instance, notification_message_reference'
,
'return "Visited by InstanceTree_createSupportRequestEvent '
\
'%s %s" % (instance.getUid(), notification_message_reference)'
)
def
testInstanceTree_checkSoftwareInstanceState
(
self
):
date
=
DateTime
()
def
getCreationDate
(
*
args
,
**
kwargs
):
return
date
-
2
from
Products.ERP5Type.Base
import
Base
original_get_creation
=
Base
.
getCreationDate
Base
.
getCreationDate
=
getCreationDate
try
:
instance_tree
=
self
.
_makeInstanceTree
()
self
.
assertEqual
(
instance_tree
.
getCreationDate
(),
date
-
2
)
self
.
_makeSoftwareInstance
(
instance_tree
,
self
.
generateNewSoftwareReleaseUrl
())
instance
=
instance_tree
.
getSuccessorValue
()
self
.
assertEqual
(
instance
.
getCreationDate
(),
date
-
2
)
self
.
_makeComputeNode
(
self
.
project
)
self
.
_makeComputePartitionList
()
instance
.
setAggregateValue
(
self
.
compute_node
.
partition1
)
error_date
=
DateTime
()
value
=
json
.
dumps
(
{
"created_at"
:
"%s"
%
error_date
,
"text"
:
"#error "
,
"since"
:
"%s"
%
(
error_date
-
2
)}
)
cache_duration
=
instance
.
_getAccessStatusCacheFactory
().
cache_duration
instance
.
_getAccessStatusPlugin
().
set
(
instance
.
_getAccessStatusCacheKey
(),
DEFAULT_CACHE_SCOPE
,
value
,
cache_duration
=
cache_duration
)
self
.
assertEqual
(
'Visited by InstanceTree_createSupportRequestEvent %s %s'
%
\
(
instance
.
getUid
(),
"slapos-crm-instance-tree-instance-state.notification"
),
instance_tree
.
InstanceTree_checkSoftwareInstanceState
())
instance
.
setAccessStatus
(
""
)
self
.
assertEqual
(
None
,
instance_tree
.
InstanceTree_checkSoftwareInstanceState
())
finally
:
Base
.
getCreationDate
=
original_get_creation
self
.
portal
.
portal_types
.
resetDynamicDocumentsOnceAtTransactionBoundary
()
transaction
.
commit
()
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
@
simulate
(
'InstanceTree_createSupportRequestEvent'
,
'instance, notification_message_reference'
,
'return "Visited by InstanceTree_createSupportRequestEvent '
\
'%s %s" % (instance.getUid(), notification_message_reference)'
)
def
testInstanceTree_checkSoftwareInstanceState_tolerance
(
self
):
date
=
DateTime
()
def
getCreationDate
(
*
args
,
**
kwargs
):
return
date
-
2
from
Products.ERP5Type.Base
import
Base
original_get_creation
=
Base
.
getCreationDate
Base
.
getCreationDate
=
getCreationDate
try
:
instance_tree
=
self
.
_makeInstanceTree
()
self
.
assertEqual
(
instance_tree
.
getCreationDate
(),
date
-
2
)
self
.
_makeSoftwareInstance
(
instance_tree
,
self
.
generateNewSoftwareReleaseUrl
())
instance
=
instance_tree
.
getSuccessorValue
()
self
.
assertEqual
(
instance
.
getCreationDate
(),
date
-
2
)
self
.
_makeComputeNode
(
self
.
project
)
self
.
_makeComputePartitionList
()
instance
.
setAggregateValue
(
self
.
compute_node
.
partition1
)
memcached_dict
=
self
.
portal
.
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
error_date
=
DateTime
()
memcached_dict
[
instance
.
getReference
()]
=
json
.
dumps
(
{
"created_at"
:
"%s"
%
error_date
,
"text"
:
"#error "
,
"since"
:
"%s"
%
error_date
}
)
# With tolerance of 30 min this should create SupportRequests immediately
self
.
assertEqual
(
None
,
instance_tree
.
InstanceTree_checkSoftwareInstanceState
())
finally
:
Base
.
getCreationDate
=
original_get_creation
self
.
portal
.
portal_types
.
resetDynamicDocumentsOnceAtTransactionBoundary
()
transaction
.
commit
()
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
@
simulate
(
'InstanceTree_createSupportRequestEvent'
,
'instance, notification_message_reference'
,
'return "Visited by InstanceTree_createSupportRequestEvent '
\
'%s %s" % (instance.getRelativeUrl(), notification_message_reference)'
)
def
testInstanceTree_checkSoftwareInstanceState_partially_allocation
(
self
):
date
=
DateTime
()
def
getCreationDate
(
*
args
,
**
kwargs
):
return
date
-
2
from
Products.ERP5Type.Base
import
Base
original_get_creation
=
Base
.
getCreationDate
Base
.
getCreationDate
=
getCreationDate
try
:
instance_tree
=
self
.
_makeInstanceTree
()
self
.
assertEqual
(
instance_tree
.
getCreationDate
(),
date
-
2
)
self
.
_makeSoftwareInstance
(
instance_tree
,
self
.
generateNewSoftwareReleaseUrl
())
instance
=
instance_tree
.
getSuccessorValue
()
self
.
assertEqual
(
instance
.
getCreationDate
(),
date
-
2
)
self
.
_makeComputeNode
(
self
.
project
)
self
.
_makeComputePartitionList
()
instance
.
setAggregateValue
(
self
.
compute_node
.
partition1
)
kw
=
dict
(
software_release
=
instance_tree
.
getUrlString
(),
software_type
=
self
.
generateNewSoftwareType
(),
instance_xml
=
self
.
generateSafeXml
(),
sla_xml
=
self
.
generateSafeXml
(),
shared
=
False
,
software_title
=
"Another INstance %s"
%
self
.
generateNewId
(),
state
=
'started'
)
instance
.
requestInstance
(
**
kw
)
self
.
tic
()
instance
.
setAccessStatus
(
""
)
self
.
assertEqual
(
'Visited by InstanceTree_createSupportRequestEvent %s %s'
%
\
(
instance
.
getSuccessor
(
portal_type
=
"Software Instance"
),
"slapos-crm-instance-tree-instance-allocation.notification"
),
instance_tree
.
InstanceTree_checkSoftwareInstanceState
())
kw
[
"state"
]
=
"destroyed"
instance
.
requestInstance
(
**
kw
)
self
.
tic
()
self
.
assertEqual
(
None
,
instance_tree
.
InstanceTree_checkSoftwareInstanceState
())
finally
:
Base
.
getCreationDate
=
original_get_creation
self
.
portal
.
portal_types
.
resetDynamicDocumentsOnceAtTransactionBoundary
()
transaction
.
commit
()
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
''
,
'return 0'
)
def
testInstanceTree_checkSoftwareInstanceState_too_early
(
self
):
instance_tree
=
self
.
_makeInstanceTree
()
self
.
_makeSoftwareInstance
(
instance_tree
,
self
.
generateNewSoftwareReleaseUrl
())
instance
=
instance_tree
.
getSuccessorValue
()
self
.
_makeComputeNode
(
self
.
project
)
self
.
_makeComputePartitionList
()
instance
.
setAggregateValue
(
self
.
compute_node
.
partition1
)
instance
.
setErrorStatus
(
""
)
self
.
assertEqual
(
None
,
instance_tree
.
InstanceTree_checkSoftwareInstanceState
())
class
TestCRMPropertySheetConstraint
(
SlapOSTestCaseMixin
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment