Commit ae15060e authored by Julien Muchembled's avatar Julien Muchembled

slapos.format: cleanup

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