diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index ee8cc1ed..1bfa2e6d 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -952,8 +952,13 @@ class IOUVM(BaseVM): try: 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: - if initial_config is None: + if len(initial_config) == 0: f.write('') else: initial_config = initial_config.replace("%h", self._name) diff --git a/tests/modules/iou/test_iou_vm.py b/tests/modules/iou/test_iou_vm.py index 9159f00b..7885fd6c 100644 --- a/tests/modules/iou/test_iou_vm.py +++ b/tests/modules/iou/test_iou_vm.py @@ -265,6 +265,18 @@ def test_update_initial_config(vm): 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): content = "hostname %h\n" vm.name = "pc1"