Commit 5f3a0128 authored by Tomáš Peterka's avatar Tomáš Peterka

Resolve the local-binding of logger

parent e186fa8f
format SlapOS Format
====== =============
slapformat is an application to prepare SlapOS ready node (machine). slap.format is an application to prepare SlapOS-ready node (machine). SlapOS-ready
means that SlapOS package was installed and you edited `/etc/opt/slapos/slapos.cfg`
where you define for example SlapOS master URL, certificates and networking.
It "formats" the machine by: It "formats" the machine by:
- creating users and groups - creating users and groups
- creating bridge interface - creating and bridging TAP and TUN interfaces
- creating needed tap interfaces
- creating needed directories with proper ownership and permissions - creating needed directories with proper ownership and permissions
- creating custom cgroup groups for better resource controlling
In the end special report is generated and information are posted to In the end, a report is posted to SlapOS Master and files `.slapos-resources` are
configured SlapOS server. created per-partition so each partition knows what interfaces, network ranges and
other computer resources are assigned to it.
This program shall be only run by root. This program shall be only run by root.
Requirements Requirements
------------ ------------
...@@ -25,5 +29,4 @@ Binaries: ...@@ -25,5 +29,4 @@ Binaries:
* brctl * brctl
* groupadd * groupadd
* ip * ip
* tunctl
* useradd * useradd
...@@ -58,7 +58,7 @@ class FormatCommand(ConfigCommand): ...@@ -58,7 +58,7 @@ class FormatCommand(ConfigCommand):
ap.add_argument('-o', '--output_definition_file', ap.add_argument('-o', '--output_definition_file',
help="Path to file to write definition of computer from " help="Path to file to write definition of computer from "
"declaration.") "declaration (obsolete: will be written to .slapos-resources)")
ap.add_argument('--alter_user', ap.add_argument('--alter_user',
choices=['True', 'False'], choices=['True', 'False'],
...@@ -89,8 +89,7 @@ class FormatCommand(ConfigCommand): ...@@ -89,8 +89,7 @@ class FormatCommand(ConfigCommand):
def take_action(self, args): def take_action(self, args):
configp = self.fetch_config(args) configp = self.fetch_config(args)
conf = FormatConfig(logger=self.app.log) conf = FormatConfig()
conf.mergeConfig(args, configp) conf.mergeConfig(args, configp)
# Parse if we have to check if running from root # Parse if we have to check if running from root
...@@ -98,6 +97,9 @@ class FormatCommand(ConfigCommand): ...@@ -98,6 +97,9 @@ class FormatCommand(ConfigCommand):
if string_to_boolean(getattr(conf, 'root_check', 'True').lower()): if string_to_boolean(getattr(conf, 'root_check', 'True').lower()):
check_root_user(self) check_root_user(self)
# Configuring locally-bound logger is obsolete - use standard logging module
app_logger = self.app.log # backup original logger
self.app.log = logging.getLogger('slapos.format') # and replace it with module logger
if len(self.app.log.handlers) == 0 and not self.app.options.log_file and conf.log_file: if len(self.app.log.handlers) == 0 and not self.app.options.log_file and conf.log_file:
# This block is called again if "slapos node boot" failed. # This block is called again if "slapos node boot" failed.
# Don't add a handler again, otherwise the output becomes double. # Don't add a handler again, otherwise the output becomes double.
...@@ -119,3 +121,6 @@ class FormatCommand(ConfigCommand): ...@@ -119,3 +121,6 @@ class FormatCommand(ConfigCommand):
tracing_monkeypatch(conf) tracing_monkeypatch(conf)
do_format(conf=conf) do_format(conf=conf)
# restore original logger
self.app.log = app_logger
...@@ -234,11 +234,19 @@ class SlapformatMixin(unittest.TestCase): ...@@ -234,11 +234,19 @@ class SlapformatMixin(unittest.TestCase):
config = FakeConfig() config = FakeConfig()
config.dry_run = True config.dry_run = True
config.verbose = True config.verbose = True
# XXX: we shouldn't use global singleton locally
logger = logging.getLogger('testcatch') logger = logging.getLogger('testcatch')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
self.test_result = TestLoggerHandler() self.test_result = TestLoggerHandler()
logger.addHandler(self.test_result) logger.addHandler(self.test_result)
# XXX: and we shouldn't pass references to it
config.logger = logger config.logger = logger
# This is the logger used in slapformat
logger = logging.getLogger('slapos.format')
# Set it up for test purposes
logger.setLevel(logging.DEBUG)
self.test_result = TestLoggerHandler()
logger.addHandler(self.test_result)
self.partition = slapos.format.Partition('partition', '/part_path', self.partition = slapos.format.Partition('partition', '/part_path',
slapos.format.User('testuser'), [], None) slapos.format.User('testuser'), [], None)
global USER_LIST global USER_LIST
......
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