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
0
Merge Requests
0
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
Titouan Soulard
slapos.core
Commits
e39706bf
Commit
e39706bf
authored
Sep 19, 2023
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_crm: update ComputeNode_checkState to use new scripts
parent
655a3d5a
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
216 additions
and
270 deletions
+216
-270
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/ComputeNode_checkState.py
...tal_skins/slapos_crm_monitoring/ComputeNode_checkState.py
+20
-23
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
...ateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
+196
-1
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMSkins.py
...ateItem/portal_components/test.erp5.testSlapOSCRMSkins.py
+0
-246
No files found.
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/ComputeNode_checkState.py
View file @
e39706bf
...
...
@@ -81,34 +81,31 @@ if should_notify:
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
)
project
=
context
.
getFollowUpValue
()
support_request
=
project
.
Project_createSupportRequestWithCausality
(
ticket_title
,
description
,
causality
=
context
.
getRelativeUrl
(),
destination_decision
=
project
.
getDestination
()
)
if
support_request
is
None
:
return
# Send Notification message
notification_message
=
portal
.
portal_notifications
.
getDocumentValue
(
reference
=
notification_message_reference
)
if
notification_message
is
None
:
message
=
"""%s"""
%
description
else
:
mapping_dict
=
{
'compute_node_title'
:
context
.
getTitle
(),
'compute_node_id'
:
reference
,
'last_contact'
:
last_contact
}
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
)
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
=
{
'compute_node_title'
:
context
.
getTitle
(),
'compute_node_id'
:
reference
,
'last_contact'
:
last_contact
}
)
return
support_request
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
View file @
e39706bf
...
...
@@ -21,9 +21,10 @@
#
##############################################################################
from
erp5.component.test.SlapOSTestCaseMixin
import
\
SlapOSTestCaseMixin
,
SlapOSTestCaseMixinWithAbort
SlapOSTestCaseMixin
,
SlapOSTestCaseMixinWithAbort
,
simulate
from
DateTime
import
DateTime
class
TestSlapOSCRMCreateRegularisationRequestAlarm
(
SlapOSTestCaseMixin
):
def
createFinalInvoice
(
self
,
person
,
grouping_reference
=
None
,
ledger
=
"automated"
,
...
...
@@ -555,6 +556,200 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
self
.
_test_alarm_check_compute_node_state_selected
(
allocation_scope
=
'close/noallocation'
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
def
test_ComputeNode_checkState_script_oldAccessStatus
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
try
:
d
=
DateTime
()
-
1.1
self
.
pinDateTime
(
d
)
compute_node
.
setAccessStatus
(
""
)
finally
:
self
.
unpinDateTime
()
compute_node_support_request
=
compute_node
.
ComputeNode_checkState
()
self
.
assertNotEqual
(
compute_node_support_request
,
None
)
self
.
assertIn
(
"[MONITORING] Lost contact with compute_node"
,
compute_node_support_request
.
getTitle
())
self
.
assertIn
(
"has not contacted the server for more than 30 minutes"
,
compute_node_support_request
.
getDescription
())
self
.
assertIn
(
d
.
strftime
(
"%Y/%m/%d %H:%M:%S"
),
compute_node_support_request
.
getDescription
())
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
def
test_ComputeNode_checkState_script_noAccessStatus
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
compute_node_support_request
=
compute_node
.
ComputeNode_checkState
()
self
.
assertNotEqual
(
compute_node_support_request
,
None
)
self
.
assertIn
(
"[MONITORING] Lost contact with compute_node"
,
compute_node_support_request
.
getTitle
())
self
.
assertIn
(
"has not contacted the server (No Contact Information)"
,
compute_node_support_request
.
getDescription
())
def
_makeNotificationMessage
(
self
,
reference
):
notification_message
=
self
.
portal
.
notification_message_module
.
newContent
(
portal_type
=
"Notification Message"
,
title
=
'The Compute Node %s has not contacted the server for more than 24 hours'
%
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
):
support_request
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Support Request'
,
title
=
request_title
,
simulation_state
=
'validated'
,
causality__uid
=
compute_node_uid
)
return
support_request
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-compute_node_check_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkState_notify"])'
)
def
test_ComputeNode_checkState_script_notify
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
compute_node
.
setAccessStatus
(
""
)
finally
:
self
.
unpinDateTime
()
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkState_notify'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
compute_node
.
ComputeNode_checkState
()
self
.
tic
()
ticket_title
=
"[MONITORING] Lost contact with compute_node %s"
%
compute_node
.
getReference
()
ticket
=
self
.
_getGeneratedSupportRequest
(
compute_node
.
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
(
compute_node
.
getReference
(),
event
.
getTextContent
())
self
.
assertEqual
(
event
.
getFollowUp
(),
ticket
.
getRelativeUrl
())
self
.
assertEqual
(
event
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getCausality
(),
compute_node
.
getRelativeUrl
())
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-compute_node_check_state.notification"
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkState_empty_cache_notify"])'
)
def
test_ComputeNode_checkState_script_emptyCacheNotify
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkState_empty_cache_notify'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
compute_node
.
ComputeNode_checkState
()
self
.
tic
()
ticket_title
=
"[MONITORING] Lost contact with compute_node %s"
%
compute_node
.
getReference
()
ticket
=
self
.
_getGeneratedSupportRequest
(
compute_node
.
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
(
compute_node
.
getReference
(),
event
.
getTextContent
())
self
.
assertEqual
(
event
.
getFollowUp
(),
ticket
.
getRelativeUrl
())
self
.
assertEqual
(
event
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getCausality
(),
compute_node
.
getRelativeUrl
())
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-compute_node_check_stalled_instance_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkState_stalled_instance"])'
)
def
test_ComputeNode_checkState_script_stalledInstance
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
compute_node
=
self
.
compute_node
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkState_stalled_instance'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
# Computer is getting access
compute_node
.
setAccessStatus
(
""
)
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
self
.
start_requested_software_instance
.
setAccessStatus
(
""
)
finally
:
self
.
unpinDateTime
()
compute_node
.
ComputeNode_checkState
()
self
.
tic
()
ticket_title
=
"[MONITORING] Compute Node %s has a stalled instance process"
%
compute_node
.
getReference
()
ticket
=
self
.
_getGeneratedSupportRequest
(
compute_node
.
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
(
compute_node
.
getReference
(),
event
.
getTextContent
())
self
.
assertEqual
(
event
.
getFollowUp
(),
ticket
.
getRelativeUrl
())
self
.
assertEqual
(
event
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getCausality
(),
compute_node
.
getRelativeUrl
())
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-compute_node_check_stalled_instance_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkState_stalled_instance"])'
)
def
test_ComputeNode_checkState_script_stalledInstanceSingle
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
compute_node
=
self
.
compute_node
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkState_stalled_instance'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
# Computer is getting access
compute_node
.
setAccessStatus
(
""
)
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
self
.
start_requested_software_instance
.
setAccessStatus
(
""
)
self
.
start_requested_software_installation
.
setAccessStatus
(
""
)
finally
:
self
.
unpinDateTime
()
compute_node
.
ComputeNode_checkState
()
self
.
tic
()
ticket_title
=
"[MONITORING] Compute Node %s has a stalled instance process"
%
compute_node
.
getReference
()
ticket
=
self
.
_getGeneratedSupportRequest
(
compute_node
.
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
(
compute_node
.
getReference
(),
event
.
getTextContent
())
self
.
assertEqual
(
event
.
getFollowUp
(),
ticket
.
getRelativeUrl
())
self
.
assertEqual
(
event
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getSourceProject
(),
compute_node
.
getFollowUp
())
self
.
assertEqual
(
ticket
.
getCausality
(),
compute_node
.
getRelativeUrl
())
class
TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation
(
SlapOSTestCaseMixinWithAbort
):
...
...
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMSkins.py
View file @
e39706bf
This diff is collapsed.
Click to expand it.
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