From 83edc649d2be5c6c2374262a41ffbc0a582a6231 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 13 Feb 2015 20:57:20 +0100 Subject: [PATCH] Rename NVRAM to the correct application id before start the server --- gns3server/modules/iou/iou_vm.py | 16 ++++++++++++++-- tests/modules/iou/test_iou_vm.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index d0fb4f60..6c6bc02f 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -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, diff --git a/tests/modules/iou/test_iou_vm.py b/tests/modules/iou/test_iou_vm.py index 8f8a0181..55ad02a3 100644 --- a/tests/modules/iou/test_iou_vm.py +++ b/tests/modules/iou/test_iou_vm.py @@ -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()