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
Hardik Juneja
slapos.core
Commits
52819fe2
Commit
52819fe2
authored
Sep 14, 2017
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pre-delete pluging: update to naming conventions, add more tests
parent
9cee999d
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
206 additions
and
58 deletions
+206
-58
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+10
-7
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+2
-2
slapos/manager/prerm.py
slapos/manager/prerm.py
+15
-17
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+179
-32
No files found.
slapos/grid/SlapObject.py
View file @
52819fe2
...
@@ -354,6 +354,7 @@ class Partition(object):
...
@@ -354,6 +354,7 @@ class Partition(object):
self
.
instance_path
=
instance_path
self
.
instance_path
=
instance_path
self
.
run_path
=
os
.
path
.
join
(
self
.
instance_path
,
'etc'
,
'run'
)
self
.
run_path
=
os
.
path
.
join
(
self
.
instance_path
,
'etc'
,
'run'
)
self
.
service_path
=
os
.
path
.
join
(
self
.
instance_path
,
'etc'
,
'service'
)
self
.
service_path
=
os
.
path
.
join
(
self
.
instance_path
,
'etc'
,
'service'
)
self
.
prerm_path
=
os
.
path
.
join
(
self
.
instance_path
,
'etc'
,
'prerm'
)
self
.
supervisord_partition_configuration_path
=
\
self
.
supervisord_partition_configuration_path
=
\
supervisord_partition_configuration_path
supervisord_partition_configuration_path
self
.
supervisord_socket
=
supervisord_socket
self
.
supervisord_socket
=
supervisord_socket
...
@@ -453,16 +454,18 @@ class Partition(object):
...
@@ -453,16 +454,18 @@ class Partition(object):
'USER'
:
pwd
.
getpwuid
(
uid
).
pw_name
,
'USER'
:
pwd
.
getpwuid
(
uid
).
pw_name
,
}
}
def
addServiceToCustomGroup
(
self
,
group_id
,
runner_list
,
path
):
def
addServiceToCustomGroup
(
self
,
group_suffix
,
partition_id
,
runner_list
,
path
,
extension
=
''
):
"""Add new services to supervisord that belong to specific group"""
"""Add new services to supervisord that belong to specific group"""
group_partition_template
=
pkg_resources
.
resource_stream
(
__name__
,
group_partition_template
=
pkg_resources
.
resource_stream
(
__name__
,
'templates/group_partition_supervisord.conf.in'
).
read
()
'templates/group_partition_supervisord.conf.in'
).
read
()
self
.
supervisor_configuration_groups
+=
group_partition_template
%
{
group_id
=
'-'
.
join
([
partition_id
,
group_suffix
])
self
.
supervisor_configuration_group
+=
group_partition_template
%
{
'instance_id'
:
group_id
,
'instance_id'
:
group_id
,
'program_list'
:
','
.
join
([
'_'
.
join
([
group_id
,
runner
])
'program_list'
:
','
.
join
([
'_'
.
join
([
group_id
,
runner
])
for
runner
in
runner_list
])
for
runner
in
runner_list
])
}
}
return
self
.
addServiceToGroup
(
group_id
,
runner_list
,
path
)
return
self
.
addServiceToGroup
(
group_id
,
runner_list
,
path
,
extension
)
def
updateSymlink
(
self
,
sr_symlink
,
software_path
):
def
updateSymlink
(
self
,
sr_symlink
,
software_path
):
if
os
.
path
.
lexists
(
sr_symlink
):
if
os
.
path
.
lexists
(
sr_symlink
):
...
@@ -612,7 +615,7 @@ class Partition(object):
...
@@ -612,7 +615,7 @@ class Partition(object):
runner_list
=
[]
runner_list
=
[]
service_list
=
[]
service_list
=
[]
self
.
partition_supervisor_configuration
=
""
self
.
partition_supervisor_configuration
=
""
self
.
supervisor_configuration_group
s
=
""
self
.
supervisor_configuration_group
=
""
if
os
.
path
.
exists
(
self
.
run_path
):
if
os
.
path
.
exists
(
self
.
run_path
):
if
os
.
path
.
isdir
(
self
.
run_path
):
if
os
.
path
.
isdir
(
self
.
run_path
):
runner_list
=
os
.
listdir
(
self
.
run_path
)
runner_list
=
os
.
listdir
(
self
.
run_path
)
...
@@ -628,7 +631,7 @@ class Partition(object):
...
@@ -628,7 +631,7 @@ class Partition(object):
partition_id
=
self
.
computer_partition
.
getId
()
partition_id
=
self
.
computer_partition
.
getId
()
group_partition_template
=
pkg_resources
.
resource_stream
(
__name__
,
group_partition_template
=
pkg_resources
.
resource_stream
(
__name__
,
'templates/group_partition_supervisord.conf.in'
).
read
()
'templates/group_partition_supervisord.conf.in'
).
read
()
self
.
supervisor_configuration_group
s
=
group_partition_template
%
{
self
.
supervisor_configuration_group
=
group_partition_template
%
{
'instance_id'
:
partition_id
,
'instance_id'
:
partition_id
,
'program_list'
:
','
.
join
([
'_'
.
join
([
partition_id
,
runner
])
'program_list'
:
','
.
join
([
'_'
.
join
([
partition_id
,
runner
])
for
runner
in
runner_list
+
service_list
])
for
runner
in
runner_list
+
service_list
])
...
@@ -642,10 +645,10 @@ class Partition(object):
...
@@ -642,10 +645,10 @@ class Partition(object):
"""
"""
Write supervisord configuration file and update supervisord
Write supervisord configuration file and update supervisord
"""
"""
if
self
.
supervisor_configuration_group
s
and
\
if
self
.
supervisor_configuration_group
and
\
self
.
partition_supervisor_configuration
:
self
.
partition_supervisor_configuration
:
updateFile
(
self
.
supervisord_partition_configuration_path
,
updateFile
(
self
.
supervisord_partition_configuration_path
,
self
.
supervisor_configuration_group
s
+
self
.
supervisor_configuration_group
+
self
.
partition_supervisor_configuration
)
self
.
partition_supervisor_configuration
)
self
.
updateSupervisor
()
self
.
updateSupervisor
()
...
...
slapos/grid/slapgrid.py
View file @
52819fe2
...
@@ -80,7 +80,7 @@ PROMISE_TIMEOUT = 3
...
@@ -80,7 +80,7 @@ PROMISE_TIMEOUT = 3
COMPUTER_PARTITION_TIMESTAMP_FILENAME
=
'.timestamp'
COMPUTER_PARTITION_TIMESTAMP_FILENAME
=
'.timestamp'
COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME
=
'.slapos_latest_bang_timestamp'
COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME
=
'.slapos_latest_bang_timestamp'
COMPUTER_PARTITION_INSTALL_ERROR_FILENAME
=
'.slapgrid-%s-error.log'
COMPUTER_PARTITION_INSTALL_ERROR_FILENAME
=
'.slapgrid-%s-error.log'
COMPUTER_PARTITION_WAIT_LIST_FILENAME
=
'.slapos-
wait-services
'
COMPUTER_PARTITION_WAIT_LIST_FILENAME
=
'.slapos-
report-wait-service-list
'
# XXX hardcoded watchdog_path
# XXX hardcoded watchdog_path
WATCHDOG_PATH
=
'/opt/slapos/bin/slapos-watchdog'
WATCHDOG_PATH
=
'/opt/slapos/bin/slapos-watchdog'
...
@@ -1273,7 +1273,7 @@ stderr_logfile_backups=1
...
@@ -1273,7 +1273,7 @@ stderr_logfile_backups=1
if
os
.
path
.
exists
(
wait_file
)
and
os
.
path
.
isfile
(
wait_file
):
if
os
.
path
.
exists
(
wait_file
)
and
os
.
path
.
isfile
(
wait_file
):
with
open
(
wait_file
)
as
wait_f
:
with
open
(
wait_file
)
as
wait_f
:
processes_list
=
[
name
.
strip
()
for
name
in
wait_f
.
readlines
()
if
name
]
processes_list
=
[
name
.
strip
()
for
name
in
wait_f
if
name
]
# return True if one of process in the list is running
# return True if one of process in the list is running
return
partition
.
checkProcessesFromStateList
(
processes_list
,
return
partition
.
checkProcessesFromStateList
(
processes_list
,
state_list
)
state_list
)
...
...
slapos/manager/pre
destroy
.py
→
slapos/manager/pre
rm
.py
View file @
52819fe2
...
@@ -9,7 +9,6 @@ from slapos.manager import interface
...
@@ -9,7 +9,6 @@ from slapos.manager import interface
from
slapos.grid.slapgrid
import
COMPUTER_PARTITION_WAIT_LIST_FILENAME
from
slapos.grid.slapgrid
import
COMPUTER_PARTITION_WAIT_LIST_FILENAME
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
WIPE_WRAPPER_BASE_PATH
=
"var/run/slapos/pre-destroy/"
class
Manager
(
object
):
class
Manager
(
object
):
"""Manager is called in every step of preparation of the computer."""
"""Manager is called in every step of preparation of the computer."""
...
@@ -45,32 +44,31 @@ class Manager(object):
...
@@ -45,32 +44,31 @@ class Manager(object):
wait_filepath
=
os
.
path
.
join
(
partition
.
instance_path
,
wait_filepath
=
os
.
path
.
join
(
partition
.
instance_path
,
COMPUTER_PARTITION_WAIT_LIST_FILENAME
)
COMPUTER_PARTITION_WAIT_LIST_FILENAME
)
wipe_base_folder
=
os
.
path
.
join
(
partition
.
instance_path
,
if
not
os
.
path
.
exists
(
partition
.
prerm_path
):
WIPE_WRAPPER_BASE_PATH
)
if
not
os
.
path
.
exists
(
wipe_base_folder
):
return
return
wipe_wrapper_list
=
[
f
for
f
in
os
.
listdir
(
wipe_base_folder
)
partition_id
=
partition
.
partition_id
if
os
.
path
.
isfile
(
os
.
path
.
join
(
wipe_base_folder
,
f
))]
wrapper_list
=
[
f
for
f
in
os
.
listdir
(
partition
.
prerm_path
)
if
len
(
wipe_wrapper_list
)
>
0
:
if
os
.
path
.
isfile
(
os
.
path
.
join
(
partition
.
prerm_path
,
f
))]
group_name
=
partition
.
partition_id
+
'-'
+
"destroy"
if
len
(
wrapper_list
)
>
0
:
logger
.
info
(
"Adding pre-destroy scripts to supervisord..."
)
group_suffix
=
"prerm"
logger
.
info
(
"Adding pre-delete scripts to supervisord..."
)
partition
.
generateSupervisorConfiguration
()
partition
.
generateSupervisorConfiguration
()
partition
.
addServiceToCustomGroup
(
group_
name
,
partition
.
addServiceToCustomGroup
(
group_
suffix
,
wipe_wrapper_list
,
partition_id
,
w
ipe_base_folder
)
w
rapper_list
,
partition
.
prerm_path
)
partition
.
writeSupervisorConfigurationFile
()
partition
.
writeSupervisorConfigurationFile
()
# check the state of all process, if the process is not started yes, start it
# check the state of all process, if the process is not started yes, start it
supervisord
=
partition
.
getSupervisorRPC
()
supervisord
=
partition
.
getSupervisorRPC
()
process_list_string
=
""
process_list_string
=
""
for
name
in
w
ipe_w
rapper_list
:
for
name
in
wrapper_list
:
process_name
=
group_name
+
':'
+
name
process_name
=
'-'
.
join
([
partition_id
,
group_suffix
])
+
':'
+
name
process_list_string
+=
process_name
+
'
\
n
'
process_list_string
+=
'%s
\
n
'
%
process_name
status
=
supervisord
.
getProcessInfo
(
process_name
)
status
=
supervisord
.
getProcessInfo
(
process_name
)
if
status
[
'start'
]
==
0
:
if
status
[
'start'
]
==
0
:
# process is not started yet
# process is not started yet
logger
.
info
(
"Starting pre-de
stroy
process %r..."
%
name
)
logger
.
info
(
"Starting pre-de
lete
process %r..."
%
name
)
supervisord
.
startProcess
(
process_name
,
False
)
supervisord
.
startProcess
(
process_name
,
False
)
# ask to slapgrid to check theses scripts before destroy partition
# ask to slapgrid to check theses scripts before destroy partition
...
...
slapos/tests/slapgrid.py
View file @
52819fe2
This diff is collapsed.
Click to expand it.
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