mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-29 02:08:10 +00:00
Support %h in VPCS config file
This commit is contained in:
parent
a12f753136
commit
aeb83a7945
@ -189,10 +189,11 @@ class VPCSVM(BaseVM):
|
||||
if self._script_file is None:
|
||||
self._script_file = os.path.join(self.working_dir, 'startup.vpcs')
|
||||
try:
|
||||
with open(self._script_file, '+w') as f:
|
||||
with open(self._script_file, 'w+') as f:
|
||||
if startup_script is None:
|
||||
f.write('')
|
||||
else:
|
||||
startup_script = startup_script.replace("%h", self._name)
|
||||
f.write(startup_script)
|
||||
except OSError as e:
|
||||
raise VPCSError("Can't write VPCS startup file '{}'".format(self._script_file))
|
||||
@ -426,16 +427,3 @@ class VPCSVM(BaseVM):
|
||||
"""
|
||||
|
||||
return self._script_file
|
||||
|
||||
@script_file.setter
|
||||
def script_file(self, script_file):
|
||||
"""
|
||||
Sets the script-file for this VPCS instance.
|
||||
|
||||
:param script_file: path to base-script-file
|
||||
"""
|
||||
|
||||
self._script_file = script_file
|
||||
log.info("VPCS {name} [{uuid}]: script_file set to {config}".format(name=self._name,
|
||||
uuid=self.uuid,
|
||||
config=self._script_file))
|
||||
|
@ -149,6 +149,15 @@ def test_update_startup_script(vm):
|
||||
assert f.read() == content
|
||||
|
||||
|
||||
def test_update_startup_script_h(vm):
|
||||
content = "setname %h\n"
|
||||
vm.name = "pc1"
|
||||
vm.startup_script = content
|
||||
assert os.path.exists(vm.script_file)
|
||||
with open(vm.script_file) as f:
|
||||
assert f.read() == "setname pc1\n"
|
||||
|
||||
|
||||
def test_get_startup_script(vm):
|
||||
content = "echo GNS3 VPCS\nip 192.168.1.2\n"
|
||||
vm.startup_script = content
|
||||
@ -159,7 +168,7 @@ 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
|
||||
vm._script_file = None
|
||||
|
||||
filepath = os.path.join(vm.working_dir, 'startup.vpc')
|
||||
with open(filepath, 'w+') as f:
|
||||
@ -187,19 +196,13 @@ def test_change_name(vm, tmpdir):
|
||||
vm.name = "world"
|
||||
with open(path, 'w+') as f:
|
||||
f.write("name world")
|
||||
vm.script_file = path
|
||||
vm._script_file = path
|
||||
vm.name = "hello"
|
||||
assert vm.name == "hello"
|
||||
with open(path) as f:
|
||||
assert f.read() == "name hello"
|
||||
|
||||
|
||||
def test_change_script_file(vm, tmpdir):
|
||||
path = os.path.join(str(tmpdir), 'startup2.vpcs')
|
||||
vm.script_file = path
|
||||
assert vm.script_file == path
|
||||
|
||||
|
||||
def test_close(vm, port_manager):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
|
Loading…
Reference in New Issue
Block a user