From 8bc26420b702503dc657b29c5c8be56a28c87394 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 30 Jan 2015 14:57:25 +0100 Subject: [PATCH] If not script file is setted we use the default from VPCS --- gns3server/modules/vpcs/vpcs_vm.py | 9 ++++++++- tests/modules/vpcs/test_vpcs_vm.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/modules/vpcs/vpcs_vm.py index 1872da3e..a3852e88 100644 --- a/gns3server/modules/vpcs/vpcs_vm.py +++ b/gns3server/modules/vpcs/vpcs_vm.py @@ -165,8 +165,15 @@ class VPCSVM(BaseVM): @property def startup_script(self): """Return the content of the current startup script""" + if self._script_file is None: - return None + # If the default VPCS file exist we use it + path = os.path.join(self.working_dir, 'startup.vpc') + if os.path.exists(path): + self._script_file = path + else: + return None + try: with open(self._script_file) as f: return f.read() diff --git a/tests/modules/vpcs/test_vpcs_vm.py b/tests/modules/vpcs/test_vpcs_vm.py index 231bf0ae..f87882b3 100644 --- a/tests/modules/vpcs/test_vpcs_vm.py +++ b/tests/modules/vpcs/test_vpcs_vm.py @@ -155,6 +155,20 @@ def test_get_startup_script(vm): assert vm.startup_script == content +def test_get_startup_script_using_default_script(vm): + content = "echo GNS3 VPCS\nip 192.168.1.2\n" + + # Reset script file location + vm.script_file = None + + filepath = os.path.join(vm.working_dir, 'startup.vpc') + with open(filepath, 'w+') as f: + assert f.write(content) + + assert vm.startup_script == content + assert vm.script_file == filepath + + def test_change_console_port(vm, port_manager): port1 = port_manager.get_free_console_port() port2 = port_manager.get_free_console_port()