Commit edc9d216 authored by Rafael Monnerat's avatar Rafael Monnerat

[slapos.grid] Place instance logs on instance side.

parent e468b364
...@@ -39,6 +39,7 @@ import tempfile ...@@ -39,6 +39,7 @@ import tempfile
import time import time
import traceback import traceback
import warnings import warnings
import logging
if sys.version_info < (2, 6): if sys.version_info < (2, 6):
warnings.warn('Used python version (%s) is old and has problems with' warnings.warn('Used python version (%s) is old and has problems with'
...@@ -48,6 +49,7 @@ from lxml import etree ...@@ -48,6 +49,7 @@ from lxml import etree
from slapos.slap.slap import NotFoundError from slapos.slap.slap import NotFoundError
from slapos.slap.slap import ServerError from slapos.slap.slap import ServerError
from slapos.util import mkdir_p, chownDirectory
from slapos.grid.exception import BuildoutFailedError from slapos.grid.exception import BuildoutFailedError
from slapos.grid.SlapObject import Software, Partition from slapos.grid.SlapObject import Software, Partition
from slapos.grid.svcbackend import launchSupervisord from slapos.grid.svcbackend import launchSupervisord
...@@ -606,63 +608,81 @@ class Slapgrid(object): ...@@ -606,63 +608,81 @@ class Slapgrid(object):
os.remove(timestamp_path) os.remove(timestamp_path)
self.logger.exception('') self.logger.exception('')
self.logger.info('Processing Computer Partition %s.' % computer_partition_id) # Include Partition Logging
self.logger.info(' Software URL: %s' % software_url) log_folder_path = "%s/.slapgrid/log" % instance_path
self.logger.info(' Software path: %s' % software_path) mkdir_p(log_folder_path)
self.logger.info(' Instance path: %s' % instance_path) partition_file_handler = logging.FileHandler(
filename="%s/instance.log" % (log_folder_path)
local_partition = Partition( )
software_path=software_path, stat_info = os.stat(instance_path)
instance_path=instance_path, chownDirectory("%s/.slapgrid" % instance_path,
supervisord_partition_configuration_path=os.path.join( uid=stat_info.st_uid,
self.supervisord_configuration_directory, '%s.conf' % gid=stat_info.st_gid)
computer_partition_id),
supervisord_socket=self.supervisord_socket, formatter = logging.Formatter(
computer_partition=computer_partition, '[%(asctime)s] %(levelname)-8s %(name)s %(message)s')
computer_id=self.computer_id, partition_file_handler.setFormatter(formatter)
partition_id=computer_partition_id, self.logger.addHandler(partition_file_handler)
server_url=self.master_url,
software_release_url=software_url, try:
certificate_repository_path=self.certificate_repository_path, self.logger.info('Processing Computer Partition %s.' % computer_partition_id)
buildout=self.buildout, self.logger.info(' Software URL: %s' % software_url)
logger=self.logger) self.logger.info(' Software path: %s' % software_path)
self.logger.info(' Instance path: %s' % instance_path)
computer_partition_state = computer_partition.getState()
local_partition = Partition(
# XXX this line breaks 37 tests software_path=software_path,
# self.logger.info(' Instance type: %s' % computer_partition.getType()) instance_path=instance_path,
self.logger.info(' Instance status: %s' % computer_partition_state) supervisord_partition_configuration_path=os.path.join(
self.supervisord_configuration_directory, '%s.conf' %
if computer_partition_state == COMPUTER_PARTITION_STARTED_STATE: computer_partition_id),
local_partition.install() supervisord_socket=self.supervisord_socket,
computer_partition.available() computer_partition=computer_partition,
local_partition.start() computer_id=self.computer_id,
self._checkPromises(computer_partition) partition_id=computer_partition_id,
computer_partition.started() server_url=self.master_url,
elif computer_partition_state == COMPUTER_PARTITION_STOPPED_STATE: software_release_url=software_url,
try: certificate_repository_path=self.certificate_repository_path,
# We want to process the partition, even if stopped, because it should buildout=self.buildout,
# propagate the state to children if any. logger=self.logger)
computer_partition_state = computer_partition.getState()
# XXX this line breaks 37 tests
# self.logger.info(' Instance type: %s' % computer_partition.getType())
self.logger.info(' Instance status: %s' % computer_partition_state)
if computer_partition_state == COMPUTER_PARTITION_STARTED_STATE:
local_partition.install() local_partition.install()
computer_partition.available() computer_partition.available()
finally: local_partition.start()
# Instance has to be stopped even if buildout/reporting is wrong. self._checkPromises(computer_partition)
local_partition.stop() computer_partition.started()
computer_partition.stopped() elif computer_partition_state == COMPUTER_PARTITION_STOPPED_STATE:
elif computer_partition_state == COMPUTER_PARTITION_DESTROYED_STATE: try:
local_partition.stop() # We want to process the partition, even if stopped, because it should
try: # propagate the state to children if any.
local_partition.install()
computer_partition.available()
finally:
# Instance has to be stopped even if buildout/reporting is wrong.
local_partition.stop()
computer_partition.stopped() computer_partition.stopped()
except (SystemExit, KeyboardInterrupt): elif computer_partition_state == COMPUTER_PARTITION_DESTROYED_STATE:
computer_partition.error(traceback.format_exc(), logger=self.logger) local_partition.stop()
raise try:
except Exception: computer_partition.stopped()
pass except (SystemExit, KeyboardInterrupt):
else: computer_partition.error(traceback.format_exc(), logger=self.logger)
error_string = "Computer Partition %r has unsupported state: %s" % \ raise
(computer_partition_id, computer_partition_state) except Exception:
computer_partition.error(error_string, logger=self.logger) pass
raise NotImplementedError(error_string) else:
error_string = "Computer Partition %r has unsupported state: %s" % \
(computer_partition_id, computer_partition_state)
computer_partition.error(error_string, logger=self.logger)
raise NotImplementedError(error_string)
finally:
self.logger.removeHandler(partition_file_handler)
# If partition has been successfully processed, write timestamp # If partition has been successfully processed, write timestamp
if timestamp: if timestamp:
......
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