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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
c4382cab
Commit
c4382cab
authored
Aug 11, 2022
by
Cédric Le Ninivin
Committed by
Romain Courteaud
Dec 16, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos: Watchdog use jio api for software instance bang
parent
e2e4b46d
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 @
c4382cab
...
@@ -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 @
c4382cab
...
@@ -445,16 +445,28 @@ class ComputerForTest(object):
...
@@ -445,16 +445,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"
:
[{
...
@@ -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