Commit ffb5e1b3 authored by Rafael Monnerat's avatar Rafael Monnerat

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

parent 55ed4b48
...@@ -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,6 +608,23 @@ class Slapgrid(object): ...@@ -606,6 +608,23 @@ class Slapgrid(object):
os.remove(timestamp_path) os.remove(timestamp_path)
self.logger.exception('') self.logger.exception('')
# Include Partition Logging
log_folder_path = "%s/.slapgrid/log" % instance_path
mkdir_p(log_folder_path)
partition_file_handler = logging.FileHandler(
filename="%s/instance.log" % (log_folder_path)
)
stat_info = os.stat(instance_path)
chownDirectory("%s/.slapgrid" % instance_path,
uid=stat_info.st_uid,
gid=stat_info.st_gid)
formatter = logging.Formatter(
'[%(asctime)s] %(levelname)-8s %(name)s %(message)s')
partition_file_handler.setFormatter(formatter)
self.logger.addHandler(partition_file_handler)
try:
self.logger.info('Processing Computer Partition %s.' % computer_partition_id) self.logger.info('Processing Computer Partition %s.' % computer_partition_id)
self.logger.info(' Software URL: %s' % software_url) self.logger.info(' Software URL: %s' % software_url)
self.logger.info(' Software path: %s' % software_path) self.logger.info(' Software path: %s' % software_path)
...@@ -626,7 +645,6 @@ class Slapgrid(object): ...@@ -626,7 +645,6 @@ class Slapgrid(object):
certificate_repository_path=self.certificate_repository_path, certificate_repository_path=self.certificate_repository_path,
buildout=self.buildout, buildout=self.buildout,
logger=self.logger) logger=self.logger)
computer_partition_state = computer_partition.getState() computer_partition_state = computer_partition.getState()
# XXX this line breaks 37 tests # XXX this line breaks 37 tests
...@@ -663,6 +681,8 @@ class Slapgrid(object): ...@@ -663,6 +681,8 @@ class Slapgrid(object):
(computer_partition_id, computer_partition_state) (computer_partition_id, computer_partition_state)
computer_partition.error(error_string, logger=self.logger) computer_partition.error(error_string, logger=self.logger)
raise NotImplementedError(error_string) 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