Commit 52819fe2 authored by Alain Takoudjou's avatar Alain Takoudjou

pre-delete pluging: update to naming conventions, add more tests

parent 9cee999d
......@@ -354,6 +354,7 @@ class Partition(object):
self.instance_path = instance_path
self.run_path = os.path.join(self.instance_path, 'etc', 'run')
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 = \
supervisord_partition_configuration_path
self.supervisord_socket = supervisord_socket
......@@ -453,16 +454,18 @@ class Partition(object):
'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"""
group_partition_template = pkg_resources.resource_stream(__name__,
'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,
'program_list': ','.join(['_'.join([group_id, runner])
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):
if os.path.lexists(sr_symlink):
......@@ -612,7 +615,7 @@ class Partition(object):
runner_list = []
service_list = []
self.partition_supervisor_configuration = ""
self.supervisor_configuration_groups = ""
self.supervisor_configuration_group = ""
if os.path.exists(self.run_path):
if os.path.isdir(self.run_path):
runner_list = os.listdir(self.run_path)
......@@ -628,7 +631,7 @@ class Partition(object):
partition_id = self.computer_partition.getId()
group_partition_template = pkg_resources.resource_stream(__name__,
'templates/group_partition_supervisord.conf.in').read()
self.supervisor_configuration_groups = group_partition_template % {
self.supervisor_configuration_group = group_partition_template % {
'instance_id': partition_id,
'program_list': ','.join(['_'.join([partition_id, runner])
for runner in runner_list + service_list])
......@@ -642,10 +645,10 @@ class Partition(object):
"""
Write supervisord configuration file and update supervisord
"""
if self.supervisor_configuration_groups and \
if self.supervisor_configuration_group and \
self.partition_supervisor_configuration:
updateFile(self.supervisord_partition_configuration_path,
self.supervisor_configuration_groups +
self.supervisor_configuration_group +
self.partition_supervisor_configuration)
self.updateSupervisor()
......
......@@ -80,7 +80,7 @@ PROMISE_TIMEOUT = 3
COMPUTER_PARTITION_TIMESTAMP_FILENAME = '.timestamp'
COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME = '.slapos_latest_bang_timestamp'
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
WATCHDOG_PATH = '/opt/slapos/bin/slapos-watchdog'
......@@ -1273,7 +1273,7 @@ stderr_logfile_backups=1
if os.path.exists(wait_file) and os.path.isfile(wait_file):
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 partition.checkProcessesFromStateList(processes_list,
state_list)
......
......@@ -9,7 +9,6 @@ from slapos.manager import interface
from slapos.grid.slapgrid import COMPUTER_PARTITION_WAIT_LIST_FILENAME
logger = logging.getLogger(__name__)
WIPE_WRAPPER_BASE_PATH = "var/run/slapos/pre-destroy/"
class Manager(object):
"""Manager is called in every step of preparation of the computer."""
......@@ -45,32 +44,31 @@ class Manager(object):
wait_filepath = os.path.join(partition.instance_path,
COMPUTER_PARTITION_WAIT_LIST_FILENAME)
wipe_base_folder = os.path.join(partition.instance_path,
WIPE_WRAPPER_BASE_PATH)
if not os.path.exists(wipe_base_folder):
if not os.path.exists(partition.prerm_path):
return
wipe_wrapper_list = [f for f in os.listdir(wipe_base_folder)
if os.path.isfile(os.path.join(wipe_base_folder, f))]
if len(wipe_wrapper_list) > 0:
group_name = partition.partition_id + '-' + "destroy"
logger.info("Adding pre-destroy scripts to supervisord...")
partition_id = partition.partition_id
wrapper_list = [f for f in os.listdir(partition.prerm_path)
if os.path.isfile(os.path.join(partition.prerm_path, f))]
if len(wrapper_list) > 0:
group_suffix = "prerm"
logger.info("Adding pre-delete scripts to supervisord...")
partition.generateSupervisorConfiguration()
partition.addServiceToCustomGroup(group_name,
wipe_wrapper_list,
wipe_base_folder)
partition.addServiceToCustomGroup(group_suffix,
partition_id,
wrapper_list,
partition.prerm_path)
partition.writeSupervisorConfigurationFile()
# check the state of all process, if the process is not started yes, start it
supervisord = partition.getSupervisorRPC()
process_list_string = ""
for name in wipe_wrapper_list:
process_name = group_name + ':' + name
process_list_string += process_name + '\n'
for name in wrapper_list:
process_name = '-'.join([partition_id, group_suffix]) + ':' + name
process_list_string += '%s\n' % process_name
status = supervisord.getProcessInfo(process_name)
if status['start'] == 0:
# process is not started yet
logger.info("Starting pre-destroy process %r..." % name)
logger.info("Starting pre-delete process %r..." % name)
supervisord.startProcess(process_name, False)
# ask to slapgrid to check theses scripts before destroy partition
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment