Commit fe342cb8 authored by Xavier Thompson's avatar Xavier Thompson

standalone: Avoid overwriting slapformat config

Some configuration in `slapos.cfg` and `slapformat-definition.cfg`
is updated by calling the `format` method, but was initialised to
hardcoded and even invalid values in the constructor. This meant
that calling the constructor again would overwrite the valid config.
parent 3ed62713
......@@ -37,6 +37,7 @@ import pwd
from six.moves import urllib
from six.moves import http_client
from six.moves import configparser
try:
import subprocess32 as subprocess
......@@ -410,7 +411,6 @@ class StandaloneSlapOS(object):
self._base_directory = base_directory
self._shared_part_list = list(shared_part_list)
self._partition_forward_configuration = list(partition_forward_configuration)
self._partition_count = 0
self._partition_base_name = 'slappart'
self._ipv4_address = None
self._ipv6_address = None
......@@ -529,9 +529,16 @@ class StandaloneSlapOS(object):
self._supervisor_socket = os.path.join(run_directory, 'sv.sock')
slapos_configp = configparser.SafeConfigParser()
slapos_configp.read(self._slapos_config)
try:
self._partition_count = slapos_configp.get('slapformat', 'partition_amount')
except configparser.Error:
self._partition_count = 0
SupervisorConfigWriter(self).writeConfig(self._supervisor_config)
SlapOSConfigWriter(self).writeConfig(self._slapos_config)
SlapformatDefinitionWriter(self).writeConfig(self._slapformat_definition)
# SlapformatDefinitionWriter(self).writeConfig(self._slapformat_definition)
SlapOSCommandWriter(self).writeConfig(self._slapos_wrapper)
SlapOSNodeAutoWriter(self).writeConfig(self._slapos_node_auto_bin)
......
......@@ -181,6 +181,8 @@ class TestSlapOSStandaloneSetup(unittest.TestCase):
self.assertEqual(partition_count, len(partitions))
for path in partitions:
shutil.rmtree(path)
# call constructor again to see if it breaks the configuration
StandaloneSlapOS(working_dir, SLAPOS_TEST_IPV4, SLAPOS_TEST_PORT)
subprocess.check_call(format_command)
self.assertEqual(partition_count, len(glob.glob(glob_pattern)))
......
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