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
b435c9f0
Commit
b435c9f0
authored
Aug 11, 2022
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Oct 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos: Watchdog use jio api for software instance bang
parent
b13e5fcc
Changes
2
Show 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 @
b435c9f0
...
@@ -187,6 +187,26 @@ class Watchdog(object):
...
@@ -187,6 +187,26 @@ 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
)
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
(
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
=
self
.
computer_id
,
computer_id
=
self
.
computer_id
,
connection_helper
=
self
.
slap
.
_connection_helper
,
connection_helper
=
self
.
slap
.
_connection_helper
,
...
...
slapos/tests/test_slapgrid.py
View file @
b435c9f0
...
@@ -445,6 +445,18 @@ class ComputerForTest(object):
...
@@ -445,6 +445,18 @@ 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
:
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
({
return
json
.
dumps
({
"result_list"
:
[{
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
...
@@ -498,6 +510,8 @@ class ComputerForTest(object):
...
@@ -498,6 +510,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
({
...
@@ -583,13 +597,11 @@ class ComputerForTest(object):
...
@@ -583,13 +597,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
))
def
getTestSoftwareClass
(
self
):
def
getTestSoftwareClass
(
self
):
...
@@ -1366,7 +1378,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1366,7 +1378,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
):
"""
"""
...
@@ -1442,7 +1454,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1442,7 +1454,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
,
...
@@ -1477,7 +1489,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1477,7 +1489,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
,
...
@@ -1512,7 +1524,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1512,7 +1524,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
]
...
@@ -1566,7 +1578,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1566,7 +1578,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
,
...
@@ -1597,7 +1609,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1597,7 +1609,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