Commit ae15060e authored by Julien Muchembled's avatar Julien Muchembled

slapos.format: cleanup

parent 8a67dc7c
...@@ -1416,7 +1416,7 @@ class FormatConfig(object): ...@@ -1416,7 +1416,7 @@ class FormatConfig(object):
def checkRequiredBinary(binary_list): def checkRequiredBinary(binary_list):
missing_binary_list = [] missing_binary_list = []
for b in binary_list: for b in binary_list:
if type(b) != type([]): if type(b) is not list:
b = [b] b = [b]
try: try:
callAndRead(b) callAndRead(b)
...@@ -1435,13 +1435,10 @@ class FormatConfig(object): ...@@ -1435,13 +1435,10 @@ class FormatConfig(object):
""" """
# First, the configuration file options erase the default class options # First, the configuration file options erase the default class options
for section in ("slapformat", "slapos"): for section in ("slapformat", "slapos"):
configuration_dict = dict(configp.items(section)) self.__dict__.update(configp.items(section))
for key in configuration_dict:
setattr(self, key, configuration_dict[key])
# Second, the command line arguments erase the configuration file options # Second, the command line arguments erase the configuration file options
for key, value in args.__dict__.items(): self.__dict__.update(args.__dict__)
setattr(self, key, value)
def setConfig(self): def setConfig(self):
# deprecated options raise an error # deprecated options raise an error
......
...@@ -293,7 +293,6 @@ class SlapformatMixin(unittest.TestCase): ...@@ -293,7 +293,6 @@ class SlapformatMixin(unittest.TestCase):
self.patchPwd() self.patchPwd()
self.patchNetifaces() self.patchNetifaces()
self.patchSlaposUtil() self.patchSlaposUtil()
self.app = SlapOSApp()
def tearDown(self): def tearDown(self):
self.restoreOs() self.restoreOs()
...@@ -893,8 +892,9 @@ class TestSlapformatManagerLifecycle(SlapformatMixin): ...@@ -893,8 +892,9 @@ class TestSlapformatManagerLifecycle(SlapformatMixin):
class TestFormatConfig(SlapformatMixin): class TestFormatConfig(SlapformatMixin):
def fake_take_action(self, args): def fake_take_action(self, *args):
format_command = FormatCommand(self.app, Namespace()) app = SlapOSApp()
format_command = FormatCommand(app, Namespace())
parsed_args = format_command.get_parser("slapos node format fake").parse_args(args) parsed_args = format_command.get_parser("slapos node format fake").parse_args(args)
configp = format_command.fetch_config(parsed_args) configp = format_command.fetch_config(parsed_args)
conf = slapos.format.FormatConfig(logger=self.logger) conf = slapos.format.FormatConfig(logger=self.logger)
...@@ -903,14 +903,15 @@ class TestFormatConfig(SlapformatMixin): ...@@ -903,14 +903,15 @@ class TestFormatConfig(SlapformatMixin):
return conf return conf
def test_empty_cmdline_options(self): def test_empty_cmdline_options(self):
conf = self.fake_take_action("") conf = self.fake_take_action()
self.assertEqual(conf.alter_network, True) self.assertTrue(conf.alter_network)
self.assertEqual(conf.alter_user, True) self.assertTrue(conf.alter_user)
def test_cmdline1_options(self): def test_cmdline1_options(self):
conf = self.fake_take_action(["--alter_network", "False", "--alter_user", "True"]) conf = self.fake_take_action(
self.assertEqual(conf.alter_network, False) "--alter_network", "False", "--alter_user", "True")
self.assertEqual(conf.alter_user, True) self.assertFalse(conf.alter_network)
self.assertTrue(conf.alter_user)
# TODO add more tests with config file # TODO add more tests with config file
......
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