mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-30 01:28:56 +00:00
Merge pull request #2055 from GNS3/remove-qemu-binaries-requirement
Remove Qemu binary requirement
This commit is contained in:
commit
3b7dfe5929
@ -121,20 +121,6 @@ def compute_statistics() -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/qemu/binaries")
|
|
||||||
async def get_qemu_binaries(
|
|
||||||
archs: Optional[List[str]] = Body(None, embed=True)
|
|
||||||
) -> List[str]:
|
|
||||||
|
|
||||||
return await Qemu.binary_list(archs)
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/qemu/img-binaries")
|
|
||||||
async def get_image_binaries() -> List[str]:
|
|
||||||
|
|
||||||
return await Qemu.img_binary_list()
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/qemu/capabilities")
|
@router.get("/qemu/capabilities")
|
||||||
async def get_qemu_capabilities() -> dict:
|
async def get_qemu_capabilities() -> dict:
|
||||||
capabilities = {"kvm": []}
|
capabilities = {"kvm": []}
|
||||||
|
@ -160,8 +160,8 @@ async def forward_put(compute_id: Union[str, UUID], emulator: str, endpoint_path
|
|||||||
return await compute.forward("PUT", emulator, endpoint_path, data=compute_data)
|
return await compute.forward("PUT", emulator, endpoint_path, data=compute_data)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{compute_id}/auto_idlepc")
|
@router.post("/{compute_id}/dynamips/auto_idlepc")
|
||||||
async def autoidlepc(compute_id: Union[str, UUID], auto_idle_pc: schemas.AutoIdlePC) -> str:
|
async def dynamips_autoidlepc(compute_id: Union[str, UUID], auto_idle_pc: schemas.AutoIdlePC) -> str:
|
||||||
"""
|
"""
|
||||||
Find a suitable Idle-PC value for a given IOS image. This may take a few minutes.
|
Find a suitable Idle-PC value for a given IOS image. This may take a few minutes.
|
||||||
"""
|
"""
|
||||||
|
@ -159,30 +159,6 @@ class Qemu(BaseManager):
|
|||||||
|
|
||||||
return qemus
|
return qemus
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
async def img_binary_list():
|
|
||||||
"""
|
|
||||||
Gets QEMU-img binaries list available on the host.
|
|
||||||
|
|
||||||
:returns: Array of dictionary {"path": Qemu-img binary path, "version": version of Qemu-img}
|
|
||||||
"""
|
|
||||||
qemu_imgs = []
|
|
||||||
for path in Qemu.paths_list():
|
|
||||||
try:
|
|
||||||
for f in os.listdir(path):
|
|
||||||
if (
|
|
||||||
(f == "qemu-img" or f == "qemu-img.exe")
|
|
||||||
and os.access(os.path.join(path, f), os.X_OK)
|
|
||||||
and os.path.isfile(os.path.join(path, f))
|
|
||||||
):
|
|
||||||
qemu_path = os.path.join(path, f)
|
|
||||||
version = await Qemu._get_qemu_img_version(qemu_path)
|
|
||||||
qemu_imgs.append({"path": qemu_path, "version": version})
|
|
||||||
except OSError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
return qemu_imgs
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_qemu_version(qemu_path):
|
async def get_qemu_version(qemu_path):
|
||||||
"""
|
"""
|
||||||
|
@ -95,10 +95,8 @@ class ApplianceToTemplate:
|
|||||||
new_config["options"] = options.strip()
|
new_config["options"] = options.strip()
|
||||||
new_config.update(version.get("images"))
|
new_config.update(version.get("images"))
|
||||||
|
|
||||||
if "path" in appliance_config["qemu"]:
|
if "arch" in appliance_config["qemu"]:
|
||||||
new_config["qemu_path"] = appliance_config["qemu"]["path"]
|
new_config["platform"] = appliance_config["qemu"]["arch"]
|
||||||
else:
|
|
||||||
new_config["qemu_path"] = "qemu-system-{}".format(appliance_config["qemu"]["arch"])
|
|
||||||
|
|
||||||
if "first_port_name" in appliance_config:
|
if "first_port_name" in appliance_config:
|
||||||
new_config["first_port_name"] = appliance_config["first_port_name"]
|
new_config["first_port_name"] = appliance_config["first_port_name"]
|
||||||
|
@ -351,34 +351,6 @@ async def test_qemu_delete_nio(app: FastAPI, compute_client: AsyncClient, qemu_v
|
|||||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
async def test_qemu_list_binaries(app: FastAPI, compute_client: AsyncClient) -> None:
|
|
||||||
|
|
||||||
ret = [{"path": "/tmp/1", "version": "2.2.0"},
|
|
||||||
{"path": "/tmp/2", "version": "2.1.0"}]
|
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.qemu.Qemu.binary_list", return_value=ret) as mock:
|
|
||||||
response = await compute_client.get(app.url_path_for("compute:get_qemu_binaries"))
|
|
||||||
assert mock.called_with(None)
|
|
||||||
assert response.status_code == status.HTTP_200_OK
|
|
||||||
assert response.json() == ret
|
|
||||||
|
|
||||||
|
|
||||||
# async def test_qemu_list_binaries_filter(app: FastAPI, compute_client: AsyncClient, vm: dict) -> None:
|
|
||||||
#
|
|
||||||
# ret = [
|
|
||||||
# {"path": "/tmp/x86_64", "version": "2.2.0"},
|
|
||||||
# {"path": "/tmp/alpha", "version": "2.1.0"},
|
|
||||||
# {"path": "/tmp/i386", "version": "2.1.0"}
|
|
||||||
# ]
|
|
||||||
#
|
|
||||||
# with asyncio_patch("gns3server.compute.qemu.Qemu.binary_list", return_value=ret) as mock:
|
|
||||||
# response = await compute_client.get(app.url_path_for("compute:get_qemu_binaries"),
|
|
||||||
# json={"archs": ["i386"]})
|
|
||||||
# assert response.status_code == status.HTTP_200_OK
|
|
||||||
# assert mock.called_with(["i386"])
|
|
||||||
# assert response.json() == ret
|
|
||||||
|
|
||||||
|
|
||||||
async def test_images(app: FastAPI, compute_client: AsyncClient, fake_qemu_vm) -> None:
|
async def test_images(app: FastAPI, compute_client: AsyncClient, fake_qemu_vm) -> None:
|
||||||
|
|
||||||
response = await compute_client.get(app.url_path_for("compute:get_qemu_images"))
|
response = await compute_client.get(app.url_path_for("compute:get_qemu_images"))
|
||||||
|
@ -82,29 +82,29 @@ async def test_binary_list(monkeypatch, tmpdir):
|
|||||||
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
# @pytest.mark.asyncio
|
||||||
async def test_img_binary_list(monkeypatch, tmpdir):
|
# async def test_img_binary_list(monkeypatch, tmpdir):
|
||||||
|
#
|
||||||
monkeypatch.setenv("PATH", str(tmpdir))
|
# monkeypatch.setenv("PATH", str(tmpdir))
|
||||||
files_to_create = ["qemu-img", "qemu-io", "qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello"]
|
# files_to_create = ["qemu-img", "qemu-io", "qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello"]
|
||||||
|
#
|
||||||
for file_to_create in files_to_create:
|
# for file_to_create in files_to_create:
|
||||||
path = os.path.join(os.environ["PATH"], file_to_create)
|
# path = os.path.join(os.environ["PATH"], file_to_create)
|
||||||
with open(path, "w+") as f:
|
# with open(path, "w+") as f:
|
||||||
f.write("1")
|
# f.write("1")
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
# os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
|
#
|
||||||
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock:
|
# with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock:
|
||||||
qemus = await Qemu.img_binary_list()
|
# qemus = await Qemu.img_binary_list()
|
||||||
|
#
|
||||||
version = "2.2.0"
|
# version = "2.2.0"
|
||||||
|
#
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-img"), "version": version} in qemus
|
# assert {"path": os.path.join(os.environ["PATH"], "qemu-img"), "version": version} in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-io"), "version": version} not in qemus
|
# assert {"path": os.path.join(os.environ["PATH"], "qemu-io"), "version": version} not in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} not in qemus
|
# assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} not in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
|
# assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} not in qemus
|
# assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} not in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
# assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
||||||
|
|
||||||
|
|
||||||
def test_get_legacy_vm_workdir():
|
def test_get_legacy_vm_workdir():
|
||||||
|
Loading…
Reference in New Issue
Block a user