Commit ae02e2d6 authored by Antoine Catton's avatar Antoine Catton

Minor: fix on promises

parent 0737bcf0
...@@ -282,6 +282,10 @@ class Slapgrid(object): ...@@ -282,6 +282,10 @@ class Slapgrid(object):
""" Main class for SlapGrid. Fetches and processes informations from master """ Main class for SlapGrid. Fetches and processes informations from master
server and pushes usage information to master server. server and pushes usage information to master server.
""" """
class PromiseError(Exception):
pass
def __init__(self, def __init__(self,
software_root, software_root,
instance_root, instance_root,
...@@ -422,6 +426,49 @@ class Slapgrid(object): ...@@ -422,6 +426,49 @@ class Slapgrid(object):
launchSupervisord(self.supervisord_socket, launchSupervisord(self.supervisord_socket,
self.supervisord_configuration_path) self.supervisord_configuration_path)
def _checkPromises(self, computer_partition):
instance_path = os.path.join(self.instance_root,
computer_partition.getId())
uid, gid = None, None
stat_info = os.stat(instance_path)
#stat sys call to get statistics informations
uid = stat_info.st_uid
gid = stat_info.st_gid
# Get the list of promises
promise_dir = os.path.join(instance_path, 'etc', 'promise')
if os.path.exists(promise_dir) and os.path.isdir(promise_dir):
cwd = instance_path
promises_list = os.listdir(promise_dir)
# Check whether every promise is kept
for promise in promises_list:
command = os.path.join(promise_dir, promise)
kw = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process_handler = SlapPopen(command,
preexec_fn=lambda: dropPrivileges(uid, gid),
cwd=cwd,
env=None, **kw)
time.sleep(self.promise_timeout)
promise = os.path.basename(command)
if process_handler.poll() is None:
process_handler.kill()
raise Slapgrid.PromiseError("The promise %r timed out" % promise)
elif process_handler.poll() != 0:
stderr = process_handler.communicate()[1]
if stderr is None:
stderr = 'No error output from %r.' % promise
raise Slapgrid.PromiseError(stderr)
def processComputerPartitionList(self): def processComputerPartitionList(self):
"""Will start supervisord and process each Computer Partition. """Will start supervisord and process each Computer Partition.
""" """
...@@ -462,6 +509,7 @@ class Slapgrid(object): ...@@ -462,6 +509,7 @@ class Slapgrid(object):
local_partition.install() local_partition.install()
computer_partition.available() computer_partition.available()
local_partition.start() local_partition.start()
self._checkPromises(computer_partition)
computer_partition.started() computer_partition.started()
elif computer_partition_state == "stopped": elif computer_partition_state == "stopped":
local_partition.install() local_partition.install()
...@@ -504,52 +552,6 @@ class Slapgrid(object): ...@@ -504,52 +552,6 @@ class Slapgrid(object):
logger.error(exception) logger.error(exception)
computer_partition.error(exception) computer_partition.error(exception)
# Promises
instance_path = os.path.join(self.instance_root,
computer_partition.getId())
uid, gid = None, None
stat_info = os.stat(instance_path)
#stat sys call to get statistics informations
uid = stat_info.st_uid
gid = stat_info.st_gid
# Get the list of promises
promise_dir = os.path.join(instance_path, 'etc', 'promise')
if os.path.exists(promise_dir) and os.path.isdir(promise_dir):
cwd = instance_path
promises_list = os.listdir(promise_dir)
# Check whether every promise is kept
for promise in promises_list:
command = os.path.join(promise_dir, promise)
kw = dict()
if not self.console:
kw.update(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process_handler = SlapPopen(command,
preexec_fn=lambda: dropPrivileges(uid, gid),
cwd=cwd,
env=None, **kw)
time.sleep(self.promise_timeout)
promise = os.path.basename(command)
if process_handler.poll() is None:
process_handler.kill()
computer_partition.error("The promise %r timed out" % promise)
elif process_handler.poll() != 0:
stderr = process_handler.communicate()[1]
if stderr is None:
stderr = 'No error output from %r.' % promise
computer_partition.error(stderr)
logger.info("Finished computer partitions...") logger.info("Finished computer partitions...")
return clean_run return clean_run
......
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