1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 16:58:28 +00:00

Do not overwrite initial-config IOU if client send an empty

Fix #140
This commit is contained in:
Julien Duponchelle 2015-04-06 21:30:57 +02:00
parent d16a389d1f
commit 7efb7c2978
2 changed files with 18 additions and 1 deletions

View File

@ -952,8 +952,13 @@ class IOUVM(BaseVM):
try: try:
script_file = os.path.join(self.working_dir, "initial-config.cfg") script_file = os.path.join(self.working_dir, "initial-config.cfg")
# We disallow erasing the initial config file
if len(initial_config) == 0 and os.path.exists(script_file):
return
with open(script_file, 'w+') as f: with open(script_file, 'w+') as f:
if initial_config is None: if len(initial_config) == 0:
f.write('') f.write('')
else: else:
initial_config = initial_config.replace("%h", self._name) initial_config = initial_config.replace("%h", self._name)

View File

@ -265,6 +265,18 @@ def test_update_initial_config(vm):
assert f.read() == content assert f.read() == content
def test_update_initial_config_empty(vm):
content = "service timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption"
vm.initial_config = content
filepath = os.path.join(vm.working_dir, "initial-config.cfg")
assert os.path.exists(filepath)
with open(filepath) as f:
assert f.read() == content
vm.initial_config = ""
with open(filepath) as f:
assert f.read() == content
def test_update_initial_config_h(vm): def test_update_initial_config_h(vm):
content = "hostname %h\n" content = "hostname %h\n"
vm.name = "pc1" vm.name = "pc1"