1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-12 19:38:57 +00:00

Rename NVRAM to the correct application id before start the server

This commit is contained in:
Julien Duponchelle 2015-02-13 20:57:20 +01:00
parent a9a3bb1c38
commit 83edc649d2
2 changed files with 26 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import shutil
import argparse
import threading
import configparser
import glob
from pkg_resources import parse_version
from .iou_error import IOUError
@ -333,6 +334,8 @@ class IOUVM(BaseVM):
self._check_requirements()
if not self.is_running():
self._rename_nvram_file()
# TODO: ASYNC
# self._library_check()
@ -373,6 +376,15 @@ class IOUVM(BaseVM):
# connections support
self._start_iouyap()
def _rename_nvram_file(self):
"""
Before start the VM rename the nvram file to the correct application id
"""
destination = os.path.join(self.working_dir, "nvram_{:05d}".format(self.application_id))
for file_path in glob.glob(os.path.join(self.working_dir, "nvram_*")):
shutil.move(file_path, destination)
def _start_iouyap(self):
"""
Starts iouyap (handles connections to and from this IOU device).
@ -670,7 +682,7 @@ class IOUVM(BaseVM):
self._ethernet_adapters.clear()
for _ in range(0, ethernet_adapters):
self._ethernet_adapters.append(EthernetAdapter())
self._ethernet_adapters.append(EthernetAdapter(interfaces=4))
log.info("IOU {name} [id={id}]: number of Ethernet adapters changed to {adapters}".format(name=self._name,
id=self._id,
@ -696,7 +708,7 @@ class IOUVM(BaseVM):
self._serial_adapters.clear()
for _ in range(0, serial_adapters):
self._serial_adapters.append(SerialAdapter())
self._serial_adapters.append(SerialAdapter(interfaces=4))
log.info("IOU {name} [id={id}]: number of Serial adapters changed to {adapters}".format(name=self._name,
id=self._id,

View File

@ -85,6 +85,18 @@ def test_start(loop, vm, monkeypatch):
assert vm.is_running()
def test_rename_nvram_file(loop, vm, monkeypatch):
"""
It should rename the nvram file to the correct name before launching the VM
"""
with open(os.path.join(vm.working_dir, "nvram_0000{}".format(vm.application_id + 1)), 'w+') as f:
f.write("1")
vm._rename_nvram_file()
assert os.path.exists(os.path.join(vm.working_dir, "nvram_0000{}".format(vm.application_id)))
def test_stop(loop, vm):
process = MagicMock()