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

iourc_path is set from server settings file

This commit is contained in:
Julien Duponchelle 2015-02-17 16:40:45 +01:00
parent 0e98497a99
commit dd1833c4f0
5 changed files with 36 additions and 40 deletions

View File

@ -65,7 +65,6 @@ class IOUHandler:
initial_config=request.json.get("initial_config")
)
vm.path = request.json.get("path", vm.path)
vm.iourc_path = request.json.get("iourc_path", vm.iourc_path)
response.set_status(201)
response.json(vm)
@ -112,7 +111,6 @@ class IOUHandler:
vm.name = request.json.get("name", vm.name)
vm.console = request.json.get("console", vm.console)
vm.path = request.json.get("path", vm.path)
vm.iourc_path = request.json.get("iourc_path", vm.iourc_path)
vm.ethernet_adapters = request.json.get("ethernet_adapters", vm.ethernet_adapters)
vm.serial_adapters = request.json.get("serial_adapters", vm.serial_adapters)
vm.ram = request.json.get("ram", vm.ram)

View File

@ -86,12 +86,10 @@ class IOUVM(BaseVM):
self._iou_stdout_file = ""
self._started = False
self._path = None
self._iourc_path = None
self._ioucon_thread = None
self._console_host = console_host
# IOU settings
self._iourc = None
self._ethernet_adapters = []
self._serial_adapters = []
self.ethernet_adapters = 2 if ethernet_adapters is None else ethernet_adapters # one adapter = 4 interfaces
@ -154,26 +152,6 @@ class IOUVM(BaseVM):
if not os.access(self._path, os.X_OK):
raise IOUError("IOU image '{}' is not executable".format(self._path))
@property
def iourc_path(self):
"""
Returns the path to the iourc file.
:returns: path to the iourc file
"""
return self._iourc_path
@iourc_path.setter
def iourc_path(self, path):
"""
Set path to IOURC file
"""
self._iourc_path = path
log.info("IOU {name} [id={id}]: iourc file path set to {path}".format(name=self._name,
id=self._id,
path=self._iourc_path))
@property
def use_default_iou_values(self):
"""
@ -237,6 +215,16 @@ class IOUVM(BaseVM):
path = shutil.which("iouyap")
return path
@property
def iourc_path(self):
"""
Returns the IOURC path.
:returns: path to IOURC
"""
return self._manager.config.get_section_config("IOU").get("iourc_path")
@property
def console(self):
"""
@ -362,7 +350,8 @@ class IOUVM(BaseVM):
self._rename_nvram_file()
if self._iourc_path and not os.path.isfile(self._iourc_path):
iourc_path = self.iourc_path
if iourc_path and not os.path.isfile(iourc_path):
raise IOUError("A valid iourc file is necessary to start IOU")
iouyap_path = self.iouyap_path
@ -372,8 +361,9 @@ class IOUVM(BaseVM):
self._create_netmap_config()
# created a environment variable pointing to the iourc file.
env = os.environ.copy()
if self._iourc_path:
env["IOURC"] = self._iourc_path
if iourc_path:
env["IOURC"] = iourc_path
self._command = yield from self._build_command()
try:
log.info("Starting IOU: {}".format(self._command))
@ -832,7 +822,7 @@ class IOUVM(BaseVM):
"""
env = os.environ.copy()
env["IOURC"] = self._iourc
env["IOURC"] = self.iourc_path
try:
output = yield from gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, env=env)
if re.search("-l\s+Enable Layer 1 keepalive messages", output):

View File

@ -46,10 +46,6 @@ IOU_CREATE_SCHEMA = {
"description": "Path of iou binary",
"type": "string"
},
"iourc_path": {
"description": "Path of iourc",
"type": "string"
},
"serial_adapters": {
"description": "How many serial adapters are connected to the IOU",
"type": "integer"
@ -99,10 +95,6 @@ IOU_UPDATE_SCHEMA = {
"description": "Path of iou binary",
"type": ["string", "null"]
},
"iourc_path": {
"description": "Path of iourc",
"type": ["string", "null"]
},
"serial_adapters": {
"description": "How many serial adapters are connected to the IOU",
"type": ["integer", "null"]

View File

@ -36,7 +36,7 @@ def fake_iou_bin(tmpdir):
@pytest.fixture
def base_params(tmpdir, fake_iou_bin):
"""Return standard parameters"""
return {"name": "PC TEST 1", "path": fake_iou_bin, "iourc_path": str(tmpdir / "iourc")}
return {"name": "PC TEST 1", "path": fake_iou_bin}
@pytest.fixture

View File

@ -38,7 +38,7 @@ def manager(port_manager):
@pytest.fixture(scope="function")
def vm(project, manager, tmpdir, fake_iou_bin):
fake_file = str(tmpdir / "iourc")
fake_file = str(tmpdir / "iouyap")
with open(fake_file, "w+") as f:
f.write("1")
@ -48,7 +48,6 @@ def vm(project, manager, tmpdir, fake_iou_bin):
manager.config.set_section_config("IOU", config)
vm.path = fake_iou_bin
vm.iourc_path = fake_file
return vm
@ -92,6 +91,23 @@ def test_start(loop, vm, monkeypatch):
assert vm.is_running()
def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
fake_file = str(tmpdir / "iourc")
with open(fake_file, "w+") as f:
f.write("1")
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file, "iouyap_path": vm.iouyap_path}):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as exec_mock:
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running()
arsgs, kwargs = exec_mock.call_args
assert kwargs["env"]["IOURC"] == fake_file
def test_rename_nvram_file(loop, vm, monkeypatch):
"""
It should rename the nvram file to the correct name before launching the VM
@ -277,4 +293,4 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
loop.run_until_complete(vm.start_capture(0, 0, output_file))
assert vm._adapters[0].get_nio(0).capturing
loop.run_until_complete(asyncio.async(vm.stop_capture(0, 0)))
assert vm._adapters[0].get_nio(0).capturing == False
assert vm._adapters[0].get_nio(0).capturing is False