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
97422397
Commit
97422397
authored
Sep 20, 2023
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_crm: test ComputeNode_checkSoftwareInstallationState
parent
e39706bf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
228 additions
and
27 deletions
+228
-27
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/ComputeNode_checkSoftwareInstallationState.py
..._monitoring/ComputeNode_checkSoftwareInstallationState.py
+28
-27
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
...ateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
+200
-0
No files found.
master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm_monitoring/ComputeNode_checkSoftwareInstallationState.py
View file @
97422397
...
@@ -7,7 +7,7 @@ if (context.getMonitorScope() == "disabled") or \
...
@@ -7,7 +7,7 @@ if (context.getMonitorScope() == "disabled") or \
software_installation_list
=
portal
.
portal_catalog
(
software_installation_list
=
portal
.
portal_catalog
(
portal_type
=
'Software Installation'
,
portal_type
=
'Software Installation'
,
default_aggregate
_uid
=
context
.
getUid
(),
aggregate_
_uid
=
context
.
getUid
(),
validation_state
=
'validated'
,
validation_state
=
'validated'
,
sort_on
=
((
'creation_date'
,
'DESC'
),)
sort_on
=
((
'creation_date'
,
'DESC'
),)
)
)
...
@@ -24,15 +24,20 @@ for software_installation in software_installation_list:
...
@@ -24,15 +24,20 @@ for software_installation in software_installation_list:
# Give it 12 hours to deploy.
# Give it 12 hours to deploy.
continue
continue
if
software_installation
.
getSlapState
()
!=
'start_requested'
:
continue
reference
=
software_installation
.
getReference
()
reference
=
software_installation
.
getReference
()
d
=
software_installation
.
getAccessStatus
()
d
=
software_installation
.
getAccessStatus
()
if
d
.
get
(
"no_data"
,
None
)
==
1
:
if
d
.
get
(
"no_data"
,
None
)
==
1
:
should_notify
=
True
last_contact
=
"No Contact Information"
ticket_title
=
"[MONITORING] No information for %s on %s"
%
(
reference
,
compute_node_reference
)
ticket_title
=
"[MONITORING] No information for %s on %s"
%
(
reference
,
compute_node_reference
)
description
=
"The software release %s did not started to build on %s since %s"
%
\
description
=
"The software release %s did not started to build on %s since %s"
%
\
(
software_installation
.
getUrlString
(),
compute_node_title
,
software_installation
.
getCreationDate
())
(
software_installation
.
getUrlString
(),
compute_node_title
,
software_installation
.
getCreationDate
())
else
:
else
:
last_contact
=
DateTime
(
d
.
get
(
'created_at'
))
last_contact
=
DateTime
(
d
.
get
(
'created_at'
))
if
d
.
get
(
"text"
).
startswith
(
"building"
):
if
d
.
get
(
"text"
).
startswith
(
"
#
building"
):
should_notify
=
True
should_notify
=
True
ticket_title
=
"[MONITORING] %s is building for too long on %s"
%
(
reference
,
compute_node_reference
)
ticket_title
=
"[MONITORING] %s is building for too long on %s"
%
(
reference
,
compute_node_reference
)
description
=
"The software release %s is building for mode them 12 hours on %s, started on %s"
%
\
description
=
"The software release %s is building for mode them 12 hours on %s, started on %s"
%
\
...
@@ -52,37 +57,33 @@ for software_installation in software_installation_list:
...
@@ -52,37 +57,33 @@ for software_installation in software_installation_list:
title
=
ticket_title
)
title
=
ticket_title
)
if
support_request
is
None
:
if
support_request
is
None
:
person
.
notify
(
support_request_title
=
ticket_title
,
project
=
context
.
getFollowUpValue
()
support_request_description
=
description
,
support_request
=
project
.
Project_createSupportRequestWithCausality
(
aggregate
=
context
.
getRelativeUrl
())
ticket_title
,
description
,
support_request_relative_url
=
context
.
REQUEST
.
get
(
"support_request_relative_url"
)
causality
=
context
.
getRelativeUrl
(),
if
support_request_relative_url
is
None
:
destination_decision
=
project
.
getDestination
()
return
)
support_request
=
portal
.
restrictedTraverse
(
support_request_relative_url
)
if
support_request
is
None
:
if
support_request
is
None
:
return
return
# Send Notification message
notification_message_reference
=
'slapos-crm-compute_node_software_installation_state.notification'
notification_reference
=
'slapos-crm-compute_node_software_installation_state.notification'
notification_message
=
portal
.
portal_notifications
.
getDocumentValue
(
reference
=
notification_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
)
event
=
support_request
.
SupportRequest_getLastEvent
(
ticket_title
)
if
event
is
None
:
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
}
)
support_request_list
.
append
(
support_request
)
support_request_list
.
append
(
support_request
)
...
...
master/bt5/slapos_crm/TestTemplateItem/portal_components/test.erp5.testSlapOSCRMAlarm.py
View file @
97422397
...
@@ -781,6 +781,206 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
...
@@ -781,6 +781,206 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
slapos_crm_check_software_installation_state
slapos_crm_check_software_installation_state
self
.
_test_alarm_not_visited
(
alarm
,
self
.
compute_node
,
"ComputeNode_checkSoftwareInstallationState"
)
self
.
_test_alarm_not_visited
(
alarm
,
self
.
compute_node
,
"ComputeNode_checkSoftwareInstallationState"
)
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'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkSoftwareInstallationState_notify"])'
)
def
test_ComputeNode_checkSoftwareInstallationState_script_notifyNoInformation
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
compute_node
=
self
.
compute_node
finally
:
self
.
unpinDateTime
()
self
.
tic
()
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkSoftwareInstallationState_notify'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
compute_node
.
ComputeNode_checkSoftwareInstallationState
()
self
.
tic
()
ticket_title
=
"[MONITORING] No information for %s on %s"
%
(
self
.
start_requested_software_installation
.
getReference
(),
compute_node
.
getReference
()
)
if
0
:
raise
NotImplementedError
(
ticket_title
)
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_software_installation_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkSoftwareInstallationState_notify"])'
)
def
test_ComputeNode_checkSoftwareInstallationState_script_notifySlow
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
compute_node
=
self
.
compute_node
finally
:
self
.
unpinDateTime
()
self
.
start_requested_software_installation
.
setBuildingStatus
(
"building"
)
self
.
tic
()
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkSoftwareInstallationState_notify'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
compute_node
.
ComputeNode_checkSoftwareInstallationState
()
self
.
tic
()
ticket_title
=
"[MONITORING] %s is building for too long on %s"
%
(
self
.
start_requested_software_installation
.
getReference
(),
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_software_installation_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkSoftwareInstallationState_notify"])'
)
def
test_ComputeNode_checkSoftwareInstallationState_script_recentBuild
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
compute_node
=
self
.
compute_node
self
.
start_requested_software_installation
.
setBuildingStatus
(
"building"
)
self
.
tic
()
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkSoftwareInstallationState_notify'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
compute_node
.
ComputeNode_checkSoftwareInstallationState
()
self
.
tic
()
ticket_title
=
"[MONITORING] %s is building for too long on %s"
%
(
self
.
start_requested_software_installation
.
getReference
(),
compute_node
.
getReference
()
)
ticket
=
self
.
_getGeneratedSupportRequest
(
compute_node
.
getUid
(),
ticket_title
)
self
.
assertEqual
(
ticket
,
None
)
@
simulate
(
'ERP5Site_isSupportRequestCreationClosed'
,
'*args, **kwargs'
,
'return 0'
)
@
simulate
(
'NotificationTool_getDocumentValue'
,
'reference=None, **kw'
,
'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkSoftwareInstallationState_notify"])'
)
def
test_ComputeNode_checkSoftwareInstallationState_script_notifyError
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
compute_node
=
self
.
compute_node
finally
:
self
.
unpinDateTime
()
self
.
start_requested_software_installation
.
setErrorStatus
(
""
)
self
.
tic
()
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkSoftwareInstallationState_notify'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
compute_node
.
ComputeNode_checkSoftwareInstallationState
()
self
.
tic
()
ticket_title
=
"[MONITORING] %s is failing to build on %s"
%
(
self
.
start_requested_software_installation
.
getReference
(),
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_software_installation_state.notification", reference
\
n
'
\
'return context.restrictedTraverse('
\
'context.REQUEST["test_ComputeNode_checkSoftwareInstallationState_notify"])'
)
def
test_ComputeNode_checkSoftwareInstallationState_script_oldBuild
(
self
):
try
:
self
.
pinDateTime
(
DateTime
()
-
1.1
)
compute_node
,
_
=
self
.
_makeComputeNode
(
self
.
addProject
())
self
.
_makeComplexComputeNode
(
self
.
addProject
())
compute_node
=
self
.
compute_node
finally
:
self
.
unpinDateTime
()
self
.
start_requested_software_installation
.
setAccessStatus
(
""
)
self
.
tic
()
self
.
portal
.
REQUEST
[
'test_ComputeNode_checkSoftwareInstallationState_notify'
]
=
\
self
.
_makeNotificationMessage
(
compute_node
.
getReference
())
compute_node
.
ComputeNode_checkSoftwareInstallationState
()
self
.
tic
()
ticket_title
=
"[MONITORING] %s is failing to build on %s"
%
(
self
.
start_requested_software_installation
.
getReference
(),
compute_node
.
getReference
()
)
ticket
=
self
.
_getGeneratedSupportRequest
(
compute_node
.
getUid
(),
ticket_title
)
self
.
assertEqual
(
ticket
,
None
)
class
TestSlapOSCrmMonitoringCheckInstanceInError
(
SlapOSTestCaseMixinWithAbort
):
class
TestSlapOSCrmMonitoringCheckInstanceInError
(
SlapOSTestCaseMixinWithAbort
):
...
...
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