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
Labels
Merge Requests
19
Merge Requests
19
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
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):
...
@@ -187,12 +187,32 @@ class Watchdog(object):
def
handle_process_state_change_event
(
self
,
headers
,
payload_dict
):
def
handle_process_state_change_event
(
self
,
headers
,
payload_dict
):
partition_id
=
payload_dict
[
'groupname'
]
partition_id
=
payload_dict
[
'groupname'
]
self
.
initialize_connection
(
partition_id
)
self
.
initialize_connection
(
partition_id
)
partition
=
slapos
.
slap
.
ComputerPartition
(
if
self
.
slap
.
jio_api_connector
:
computer_id
=
self
.
computer_id
,
instance_list
=
self
.
slap
.
jio_api_connector
.
allDocs
({
connection_helper
=
self
.
slap
.
_connection_helper
,
"portal_type"
:
"Software Instance"
,
partition_id
=
partition_id
)
"compute_node_id"
:
self
.
computer_id
,
partition
.
bang
(
"%s process in partition %s encountered a problem"
"compute_partition_id"
:
partition_id
,
%
(
payload_dict
[
'processname'
],
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'
])
self
.
create_partition_bang_timestamp_file
(
payload_dict
[
'groupname'
])
...
...
slapos/tests/test_slapgrid.py
View file @
54114ed5
...
@@ -441,16 +441,28 @@ class ComputerForTest(object):
...
@@ -441,16 +441,28 @@ class ComputerForTest(object):
})
})
if
content
[
"portal_type"
]
==
"Software Instance"
:
if
content
[
"portal_type"
]
==
"Software Instance"
:
if
"compute_node_id"
in
content
:
if
"compute_node_id"
in
content
:
return
json
.
dumps
({
if
"compute_partition_id"
in
content
:
"result_list"
:
[{
return
json
.
dumps
({
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"result_list"
:
[{
"reference"
:
x
.
name
,
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"title"
:
x
.
name
,
"reference"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"title"
:
x
.
name
,
"compute_partition_id"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"state"
:
x
.
requested_state
"compute_partition_id"
:
x
.
name
,
}
for
x
in
self
.
instance_list
]
"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
:
elif
"root_instance_title"
in
content
:
return
json
.
dumps
({
return
json
.
dumps
({
"result_list"
:
[{
"result_list"
:
[{
...
@@ -494,6 +506,8 @@ class ComputerForTest(object):
...
@@ -494,6 +506,8 @@ class ComputerForTest(object):
if
content
[
"reported_state"
]
==
"error"
:
if
content
[
"reported_state"
]
==
"error"
:
instance
.
error
=
True
instance
.
error
=
True
instance
.
error_log
=
content
[
"status_message"
]
instance
.
error_log
=
content
[
"status_message"
]
elif
content
[
"reported_state"
]
==
"bang"
:
instance
.
error_log
=
content
[
"status_message"
]
else
:
else
:
requested_instance
.
state
=
content
[
"reported_state"
]
requested_instance
.
state
=
content
[
"reported_state"
]
return
json
.
dumps
({
return
json
.
dumps
({
...
@@ -579,13 +593,11 @@ class ComputerForTest(object):
...
@@ -579,13 +593,11 @@ class ComputerForTest(object):
"message"
:
"No document found with parameters: %s"
%
reference
,
"message"
:
"No document found with parameters: %s"
%
reference
,
"name"
:
"NotFound"
,
"name"
:
"NotFound"
,
})
})
if
req
.
method
==
'GET'
:
if
req
.
method
==
'POST'
and
'computer_partition_id'
in
qs
:
if
url
.
path
==
"/getHateoasUrl"
:
instance
=
self
.
instance_list
[
int
(
qs
[
'computer_partition_id'
][
0
])]
return
""
instance
.
sequence
.
append
(
url
.
path
)
elif
url
.
path
==
"/getJIOAPIUrl"
:
instance
.
header_list
.
append
(
req
.
headers
)
return
"https://127.0.0.1/api/"
if
url
.
path
==
'/softwareInstanceBang'
:
return
{
'status_code'
:
200
}
raise
ValueError
(
"Unexcepted call to API. URL:%s Content:%s"
%
(
url
.
path
,
req
.
body
))
raise
ValueError
(
"Unexcepted call to API. URL:%s Content:%s"
%
(
url
.
path
,
req
.
body
))
...
@@ -1235,7 +1247,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1235,7 +1247,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
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
):
def
test_unwanted_events_will_not_bang
(
self
):
"""
"""
...
@@ -1311,7 +1323,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1311,7 +1323,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
partition
,
...
@@ -1346,7 +1358,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1346,7 +1358,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
partition
,
...
@@ -1381,7 +1393,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1381,7 +1393,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
# Second bang
# Second bang
event
=
watchdog
.
process_state_events
[
0
]
event
=
watchdog
.
process_state_events
[
0
]
...
@@ -1435,7 +1447,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1435,7 +1447,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
partition
,
...
@@ -1466,7 +1478,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1466,7 +1478,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
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