diff --git a/gns3server/config.py b/gns3server/config.py index ef36dee4..072785a4 100644 --- a/gns3server/config.py +++ b/gns3server/config.py @@ -41,8 +41,13 @@ class Config(object): def __init__(self, files=None): self._files = files + + # Monitor configuration files for changes self._watched_files = {} + # Override config from commande even if modify the config file and live reload it. + self._override_config = {} + if sys.platform.startswith("win"): appname = "GNS3" @@ -106,7 +111,8 @@ class Config(object): changed = True if changed: self.read_config() - # TODO: Support command line override + for section in self._override_config: + self.set_section_config(section, self._override_config[section]) self._watch_config_file() def list_cloud_config_file(self): @@ -167,6 +173,7 @@ class Config(object): self._config.add_section(section) for key in content: self._config.set(section, key, content[key]) + self._override_config[section] = content @staticmethod def instance(): diff --git a/tests/test_config.py b/tests/test_config.py index 4b7e5063..d12683b1 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -95,3 +95,26 @@ def test_check_config_file_change(tmpdir): config._check_config_file_change() assert dict(config.get_section_config("Server")) == {"host": "192.168.1.1"} + + +def test_check_config_file_change_override_cmdline(tmpdir): + + config = load_config(tmpdir, { + "Server": { + "host": "127.0.0.1" + } + }) + assert dict(config.get_section_config("Server")) == {"host": "127.0.0.1"} + + config.set_section_config("Server", {"host": "192.168.1.1"}) + assert dict(config.get_section_config("Server")) == {"host": "192.168.1.1"} + + path = write_config(tmpdir, { + "Server": { + "host": "192.168.1.2" + } + }) + os.utime(path, (time.time() + 1, time.time() + 1)) + + config._check_config_file_change() + assert dict(config.get_section_config("Server")) == {"host": "192.168.1.1"}