1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-30 20:28:08 +00:00

Override configuration from command line even in case of config reload

This commit is contained in:
Julien Duponchelle 2015-02-02 15:08:46 +01:00
parent 6abf420ce1
commit 0ae8d8031a
2 changed files with 31 additions and 1 deletions

View File

@ -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():

View File

@ -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"}