log server is also usefull for cdist config

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2020-01-11 01:59:18 +01:00 committed by Darko Poljak
parent 831bfc822b
commit 57e352cd1e
3 changed files with 19 additions and 10 deletions

View file

@ -250,6 +250,12 @@ def get_parsers():
'-S', '--disable-saving-output-streams', '-S', '--disable-saving-output-streams',
help='Disable saving output streams.', help='Disable saving output streams.',
action='store_false', dest='save_output_streams', default=True) action='store_false', dest='save_output_streams', default=True)
parser['config_main'].add_argument(
'--log-server',
action='store_true',
help=('Start a log server for sub processes to use.'
'This is mainly usefull when running cdist nested'
'from a code-local script.'))
# Config # Config
parser['config_args'] = argparse.ArgumentParser(add_help=False) parser['config_args'] = argparse.ArgumentParser(add_help=False)

View file

@ -385,6 +385,16 @@ class Config(object):
log = logging.getLogger(host) log = logging.getLogger(host)
if args.log_server:
# Start a log server so that nested `cdist config` runs have a place
# to send their logs to.
log_server_socket_dir = tempfile.mkdtemp()
log_server_socket = os.path.join(log_server_socket_dir, 'log-server')
cls._register_path_for_removal(log_server_socket_dir)
log.debug('Starting logging server on: %s', log_server_socket)
os.environ['__cdist_log_server_socket_to_export'] = log_server_socket
cdist.log.setupLogServer(log_server_socket)
try: try:
remote_exec, remote_copy, cleanup_cmd = cls._resolve_remote_cmds( remote_exec, remote_copy, cleanup_cmd = cls._resolve_remote_cmds(
args) args)

View file

@ -33,16 +33,9 @@ class Install(cdist.config.Config):
@classmethod @classmethod
def onehost(cls, host, host_tags, host_base_path, host_dir_name, args, def onehost(cls, host, host_tags, host_base_path, host_dir_name, args,
parallel, configuration, remove_remote_files_dirs=False): parallel, configuration, remove_remote_files_dirs=False):
# Start a log server so nested `cdist config` runs have a place to # Always start log server during cdist install so that nested
# send their logs to. # `cdist config` runs have a place to send their logs to.
log_server_socket_dir = tempfile.mkdtemp() args.log_server = True
log_server_socket = os.path.join(log_server_socket_dir, 'log-server')
cls._register_path_for_removal(log_server_socket_dir)
log = logging.getLogger(host)
log.debug('Starting logging server on: %s', log_server_socket)
os.environ['__cdist_log_server_socket_to_export'] = log_server_socket
cdist.log.setupLogServer(log_server_socket)
super().onehost(host, host_tags, host_base_path, host_dir_name, args, super().onehost(host, host_tags, host_base_path, host_dir_name, args,
parallel, configuration, remove_remote_files_dirs=False) parallel, configuration, remove_remote_files_dirs=False)