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
Carlos Ramos Carreño
slapos.core
Commits
f48b2d51
Commit
f48b2d51
authored
Nov 24, 2023
by
Thomas Gambier
🚴🏼
Browse files
Options
Browse Files
Download
Plain Diff
grid: fix supervisord configuration generation
See merge request
nexedi/slapos.core!583
parents
514de5fe
91335049
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
14 deletions
+68
-14
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+9
-8
slapos/tests/test_object.py
slapos/tests/test_object.py
+59
-6
No files found.
slapos/grid/SlapObject.py
View file @
f48b2d51
...
@@ -721,14 +721,18 @@ class Partition(object):
...
@@ -721,14 +721,18 @@ class Partition(object):
self
.
addServicesToGroup
(
self
.
addServicesToGroup
(
service_list
,
self
.
service_path
,
extension
=
WATCHDOG_MARK
)
service_list
,
self
.
service_path
,
extension
=
WATCHDOG_MARK
)
def
getSupervisorConfigurationFiles
(
self
):
for
f
in
os
.
listdir
(
self
.
supervisord_partition_configuration_dir
):
if
os
.
path
.
splitext
(
f
)[
0
]
==
self
.
partition_id
:
# partition
yield
f
elif
f
.
startswith
(
self
.
partition_id
+
'-'
):
# manager
yield
f
def
writeSupervisorConfigurationFiles
(
self
):
def
writeSupervisorConfigurationFiles
(
self
):
"""
"""
Write supervisord configuration files and update supervisord
Write supervisord configuration files and update supervisord
"""
"""
remaining
=
set
(
remaining
=
set
(
self
.
getSupervisorConfigurationFiles
())
f
for
f
in
os
.
listdir
(
self
.
supervisord_partition_configuration_dir
)
if
f
.
startswith
(
self
.
partition_id
)
)
for
group
,
programs
in
self
.
supervisor_conf
.
items
():
for
group
,
programs
in
self
.
supervisor_conf
.
items
():
filename
=
'%s.conf'
%
group
filename
=
'%s.conf'
%
group
filepath
=
os
.
path
.
join
(
filepath
=
os
.
path
.
join
(
...
@@ -765,10 +769,7 @@ class Partition(object):
...
@@ -765,10 +769,7 @@ class Partition(object):
"""
"""
Remove supervisord configuration files if any exist and update supervisord
Remove supervisord configuration files if any exist and update supervisord
"""
"""
filenames
=
[
filenames
=
list
(
self
.
getSupervisorConfigurationFiles
())
f
for
f
in
os
.
listdir
(
self
.
supervisord_partition_configuration_dir
)
if
f
.
startswith
(
self
.
partition_id
)
]
for
filename
in
filenames
:
for
filename
in
filenames
:
filepath
=
os
.
path
.
join
(
filepath
=
os
.
path
.
join
(
self
.
supervisord_partition_configuration_dir
,
filename
)
self
.
supervisord_partition_configuration_dir
,
filename
)
...
...
slapos/tests/test_object.py
View file @
f48b2d51
...
@@ -40,6 +40,8 @@ from slapos.slap import ComputerPartition as SlapComputerPartition
...
@@ -40,6 +40,8 @@ from slapos.slap import ComputerPartition as SlapComputerPartition
from
slapos.grid.SlapObject
import
Partition
,
Software
from
slapos.grid.SlapObject
import
Partition
,
Software
from
slapos.grid
import
utils
from
slapos.grid
import
utils
from
slapos.grid
import
networkcache
from
slapos.grid
import
networkcache
from
slapos.grid
import
svcbackend
# XXX: BasicMixin should be in a separated module, not in slapgrid test module.
# XXX: BasicMixin should be in a separated module, not in slapgrid test module.
from
slapos.tests.test_slapgrid
import
BasicMixin
from
slapos.tests.test_slapgrid
import
BasicMixin
...
@@ -98,7 +100,15 @@ class MasterMixin(BasicMixin, unittest.TestCase):
...
@@ -98,7 +100,15 @@ class MasterMixin(BasicMixin, unittest.TestCase):
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
os
.
mkdir
(
self
.
instance_root
)
logger
=
logging
.
getLogger
(
self
.
id
())
svcbackend
.
createSupervisordConfiguration
(
self
.
instance_root
,
logger
)
svcbackend
.
launchSupervisord
(
self
.
instance_root
,
logger
)
self
.
supervisord_socket
=
svcbackend
.
_getSupervisordSocketPath
(
self
.
instance_root
,
logger
)
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
supervisord_socket
))
def
tearDown
(
self
):
def
tearDown
(
self
):
with
self
.
supervisor
as
s
:
s
.
shutdown
()
BasicMixin
.
tearDown
(
self
)
BasicMixin
.
tearDown
(
self
)
# Un-monkey patch possible modules
# Un-monkey patch possible modules
...
@@ -107,6 +117,10 @@ class MasterMixin(BasicMixin, unittest.TestCase):
...
@@ -107,6 +117,10 @@ class MasterMixin(BasicMixin, unittest.TestCase):
utils
.
bootstrapBuildout
=
originalBootstrapBuildout
utils
.
bootstrapBuildout
=
originalBootstrapBuildout
utils
.
launchBuildout
=
originalLaunchBuildout
utils
.
launchBuildout
=
originalLaunchBuildout
@
property
def
supervisor
(
self
):
return
svcbackend
.
getSupervisorRPC
(
self
.
supervisord_socket
)
# Helper functions
# Helper functions
def
createSoftware
(
self
,
url
=
None
,
empty
=
False
):
def
createSoftware
(
self
,
url
=
None
,
empty
=
False
):
"""
"""
...
@@ -162,17 +176,16 @@ class MasterMixin(BasicMixin, unittest.TestCase):
...
@@ -162,17 +176,16 @@ class MasterMixin(BasicMixin, unittest.TestCase):
os
.
mkdir
(
instance_path
)
os
.
mkdir
(
instance_path
)
os
.
chmod
(
instance_path
,
0o750
)
os
.
chmod
(
instance_path
,
0o750
)
supervisor_configuration_path
=
os
.
path
.
join
(
supervisor_configuration_path
=
svcbackend
.
_getSupervisordConfigurationDirectory
(
self
.
instance_root
,
'supervisor'
)
self
.
instance_root
)
os
.
mkdir
(
supervisor_configuration_path
)
partition
=
Partition
(
partition
=
Partition
(
software_path
=
software_path
,
software_path
=
software_path
,
instance_path
=
instance_path
,
instance_path
=
instance_path
,
shared_part_list
=
shared_part_list
,
shared_part_list
=
shared_part_list
,
supervisord_partition_configuration_dir
=
supervisor_configuration_path
,
supervisord_partition_configuration_dir
=
supervisor_configuration_path
,
supervisord_socket
=
os
.
path
.
join
(
supervisord_socket
=
svcbackend
.
_getSupervisordSocketPath
(
supervisor_configuration_path
,
'supervisor.sock'
),
self
.
instance_root
,
logging
.
getLogger
(
self
.
id
())
),
computer_partition
=
slap_computer_partition
,
computer_partition
=
slap_computer_partition
,
computer_id
=
'bidon'
,
computer_id
=
'bidon'
,
partition_id
=
partition_id
,
partition_id
=
partition_id
,
...
@@ -183,7 +196,6 @@ class MasterMixin(BasicMixin, unittest.TestCase):
...
@@ -183,7 +196,6 @@ class MasterMixin(BasicMixin, unittest.TestCase):
partition_timeout
=
partition_timeout
,
partition_timeout
=
partition_timeout
,
)
)
partition
.
updateSupervisor
=
FakeCallAndNoop
if
retention_delay
:
if
retention_delay
:
partition
.
retention_delay
=
retention_delay
partition
.
retention_delay
=
retention_delay
...
@@ -529,6 +541,47 @@ class TestPartitionSupervisorConfig(MasterMixin, unittest.TestCase):
...
@@ -529,6 +541,47 @@ class TestPartitionSupervisorConfig(MasterMixin, unittest.TestCase):
for
i
in
range
(
3
):
for
i
in
range
(
3
):
self
.
assertIn
(
'program:%s_runner-%s'
%
(
group_id
,
i
),
supervisor_conf
)
self
.
assertIn
(
'program:%s_runner-%s'
%
(
group_id
,
i
),
supervisor_conf
)
def
test_partition_independence
(
self
):
partition1a
=
self
.
createPartition
(
self
.
software
.
url
,
partition_id
=
'part1a'
)
partition1a_service_path
=
os
.
path
.
join
(
partition1a
.
instance_path
,
'etc'
,
'service'
)
os
.
makedirs
(
partition1a_service_path
)
with
open
(
os
.
path
.
join
(
partition1a_service_path
,
'test'
),
'w'
)
as
f
:
f
.
write
(
'#!/bin/sh
\
n
sleep 30'
)
os
.
fchmod
(
f
.
fileno
(),
0o750
)
partition1a
.
start
()
with
self
.
supervisor
as
s
:
part1a_pid
=
s
.
getProcessInfo
(
'part1a:test-on-watch'
)[
'pid'
]
self
.
assertTrue
(
part1a_pid
)
partition1
=
self
.
createPartition
(
self
.
software
.
url
,
partition_id
=
'part1'
)
partition1_service_path
=
os
.
path
.
join
(
partition1
.
instance_path
,
'etc'
,
'service'
)
os
.
makedirs
(
partition1_service_path
)
with
open
(
os
.
path
.
join
(
partition1_service_path
,
'test'
),
'w'
)
as
f
:
f
.
write
(
'#!/bin/sh
\
n
sleep 30'
)
os
.
fchmod
(
f
.
fileno
(),
0o750
)
partition1
.
start
()
# process is still running (it was not restarted)
with
self
.
supervisor
as
s
:
self
.
assertEqual
(
s
.
getProcessInfo
(
'part1a:test-on-watch'
)[
'pid'
],
part1a_pid
)
partition1
.
stop
()
with
self
.
supervisor
as
s
:
self
.
assertEqual
(
s
.
getProcessInfo
(
'part1a:test-on-watch'
)[
'pid'
],
part1a_pid
)
partition1
.
destroy
()
with
self
.
supervisor
as
s
:
self
.
assertEqual
(
s
.
getProcessInfo
(
'part1a:test-on-watch'
)[
'pid'
],
part1a_pid
)
class
TestPartitionDestructionLock
(
MasterMixin
,
unittest
.
TestCase
):
class
TestPartitionDestructionLock
(
MasterMixin
,
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
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