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
Léo-Paul Géneau
slapos.core
Commits
54114ed5
Commit
54114ed5
authored
Aug 11, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos: Watchdog use jio api for software instance bang
parent
d7cf0323
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
29 deletions
+61
-29
slapos/grid/watchdog.py
slapos/grid/watchdog.py
+26
-6
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+35
-23
No files found.
slapos/grid/watchdog.py
View file @
54114ed5
...
...
@@ -187,12 +187,32 @@ class Watchdog(object):
def
handle_process_state_change_event
(
self
,
headers
,
payload_dict
):
partition_id
=
payload_dict
[
'groupname'
]
self
.
initialize_connection
(
partition_id
)
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
=
self
.
computer_id
,
connection_helper
=
self
.
slap
.
_connection_helper
,
partition_id
=
partition_id
)
partition
.
bang
(
"%s process in partition %s encountered a problem"
%
(
payload_dict
[
'processname'
],
partition_id
))
if
self
.
slap
.
jio_api_connector
:
instance_list
=
self
.
slap
.
jio_api_connector
.
allDocs
({
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
self
.
computer_id
,
"compute_partition_id"
:
partition_id
,
}).
get
(
"result_list"
,
[])
if
len
(
instance_list
)
!=
1
:
raise
ValueError
(
"No instance found for %s %s %s"
%
(
self
.
computer_id
,
partition_id
,
instance_list
,
))
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reported_state"
:
"bang"
,
"status_message"
:
"%s process in partition %s encountered a problem"
%
(
payload_dict
[
'processname'
],
partition_id
),
"reference"
:
instance_list
[
0
][
"reference"
]
})
else
:
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
=
self
.
computer_id
,
connection_helper
=
self
.
slap
.
_connection_helper
,
partition_id
=
partition_id
)
partition
.
bang
(
"%s process in partition %s encountered a problem"
%
(
payload_dict
[
'processname'
],
partition_id
))
self
.
create_partition_bang_timestamp_file
(
payload_dict
[
'groupname'
])
...
...
slapos/tests/test_slapgrid.py
View file @
54114ed5
...
...
@@ -441,16 +441,28 @@ class ComputerForTest(object):
})
if
content
[
"portal_type"
]
==
"Software Instance"
:
if
"compute_node_id"
in
content
:
return
json
.
dumps
({
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"reference"
:
x
.
name
,
"title"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
x
.
name
,
"state"
:
x
.
requested_state
}
for
x
in
self
.
instance_list
]
})
if
"compute_partition_id"
in
content
:
return
json
.
dumps
({
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"reference"
:
x
.
name
,
"title"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
x
.
name
,
"state"
:
x
.
requested_state
}
for
x
in
self
.
instance_list
if
x
.
name
==
content
[
"compute_partition_id"
]]
})
else
:
return
json
.
dumps
({
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"reference"
:
x
.
name
,
"title"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
x
.
name
,
"state"
:
x
.
requested_state
}
for
x
in
self
.
instance_list
]
})
elif
"root_instance_title"
in
content
:
return
json
.
dumps
({
"result_list"
:
[{
...
...
@@ -494,6 +506,8 @@ class ComputerForTest(object):
if
content
[
"reported_state"
]
==
"error"
:
instance
.
error
=
True
instance
.
error_log
=
content
[
"status_message"
]
elif
content
[
"reported_state"
]
==
"bang"
:
instance
.
error_log
=
content
[
"status_message"
]
else
:
requested_instance
.
state
=
content
[
"reported_state"
]
return
json
.
dumps
({
...
...
@@ -579,13 +593,11 @@ class ComputerForTest(object):
"message"
:
"No document found with parameters: %s"
%
reference
,
"name"
:
"NotFound"
,
})
if
req
.
method
==
'POST'
and
'computer_partition_id'
in
qs
:
instance
=
self
.
instance_list
[
int
(
qs
[
'computer_partition_id'
][
0
])]
instance
.
sequence
.
append
(
url
.
path
)
instance
.
header_list
.
append
(
req
.
headers
)
if
url
.
path
==
'/softwareInstanceBang'
:
return
{
'status_code'
:
200
}
if
req
.
method
==
'GET'
:
if
url
.
path
==
"/getHateoasUrl"
:
return
""
elif
url
.
path
==
"/getJIOAPIUrl"
:
return
"https://127.0.0.1/api/"
raise
ValueError
(
"Unexcepted call to API. URL:%s Content:%s"
%
(
url
.
path
,
req
.
body
))
...
...
@@ -1235,7 +1247,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
def
test_unwanted_events_will_not_bang
(
self
):
"""
...
...
@@ -1311,7 +1323,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
partition
,
...
...
@@ -1346,7 +1358,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
partition
,
...
...
@@ -1381,7 +1393,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
# Second bang
event
=
watchdog
.
process_state_events
[
0
]
...
...
@@ -1435,7 +1447,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
partition
,
...
...
@@ -1466,7 +1478,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
partition
,
...
...
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