mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-31 13:23:48 +02:00
Fix issue when images are not uploaded from appliance wizard. Ref https://github.com/GNS3/gns3-gui/issues/2738
This commit is contained in:
parent
4e396ac690
commit
03401a477e
@ -27,7 +27,6 @@ import io
|
|||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
from ..utils import parse_version
|
from ..utils import parse_version
|
||||||
from ..utils.images import list_images
|
|
||||||
from ..utils.asyncio import locking
|
from ..utils.asyncio import locking
|
||||||
from ..controller.controller_error import ControllerError
|
from ..controller.controller_error import ControllerError
|
||||||
from ..version import __version__, __version_info__
|
from ..version import __version__, __version_info__
|
||||||
@ -571,8 +570,7 @@ class Compute:
|
|||||||
|
|
||||||
async def images(self, type):
|
async def images(self, type):
|
||||||
"""
|
"""
|
||||||
Return the list of images available for this type on controller
|
Return the list of images available for this type on the compute node.
|
||||||
and on the compute node.
|
|
||||||
"""
|
"""
|
||||||
images = []
|
images = []
|
||||||
|
|
||||||
@ -581,9 +579,9 @@ class Compute:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if type in ["qemu", "dynamips", "iou"]:
|
if type in ["qemu", "dynamips", "iou"]:
|
||||||
for local_image in list_images(type):
|
#for local_image in list_images(type):
|
||||||
if local_image['filename'] not in [i['filename'] for i in images]:
|
# if local_image['filename'] not in [i['filename'] for i in images]:
|
||||||
images.append(local_image)
|
# images.append(local_image)
|
||||||
images = sorted(images, key=itemgetter('filename'))
|
images = sorted(images, key=itemgetter('filename'))
|
||||||
else:
|
else:
|
||||||
images = sorted(images, key=itemgetter('image'))
|
images = sorted(images, key=itemgetter('image'))
|
||||||
|
@ -82,13 +82,14 @@ class ComputeHandler:
|
|||||||
@Route.get(
|
@Route.get(
|
||||||
r"/computes/{compute_id}/{emulator}/images",
|
r"/computes/{compute_id}/{emulator}/images",
|
||||||
parameters={
|
parameters={
|
||||||
"compute_id": "Compute UUID"
|
"compute_id": "Compute UUID",
|
||||||
|
"emulator": "Emulator type"
|
||||||
},
|
},
|
||||||
status_codes={
|
status_codes={
|
||||||
200: "OK",
|
200: "OK",
|
||||||
404: "Instance doesn't exist"
|
404: "Instance doesn't exist"
|
||||||
},
|
},
|
||||||
description="Return the list of images available on compute and controller for this emulator type")
|
description="Return the list of images available on compute for this emulator type")
|
||||||
async def images(request, response):
|
async def images(request, response):
|
||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
compute = controller.get_compute(request.match_info["compute_id"])
|
compute = controller.get_compute(request.match_info["compute_id"])
|
||||||
|
@ -139,7 +139,7 @@ def images_directories(type):
|
|||||||
paths.append(directory)
|
paths.append(directory)
|
||||||
# Compatibility with old topologies we look in parent directory
|
# Compatibility with old topologies we look in parent directory
|
||||||
paths.append(img_dir)
|
paths.append(img_dir)
|
||||||
# Return only the existings paths
|
# Return only the existing paths
|
||||||
return [force_unix_path(p) for p in paths if os.path.exists(p)]
|
return [force_unix_path(p) for p in paths if os.path.exists(p)]
|
||||||
|
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ def test_forward_post(compute, async_run):
|
|||||||
|
|
||||||
def test_images(compute, async_run, images_dir):
|
def test_images(compute, async_run, images_dir):
|
||||||
"""
|
"""
|
||||||
Will return image on compute and on controller
|
Will return image on compute
|
||||||
"""
|
"""
|
||||||
response = MagicMock()
|
response = MagicMock()
|
||||||
response.status = 200
|
response.status = 200
|
||||||
@ -357,14 +357,12 @@ def test_images(compute, async_run, images_dir):
|
|||||||
"path": "linux.qcow2",
|
"path": "linux.qcow2",
|
||||||
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
|
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
|
||||||
"filesize": 0}]).encode())
|
"filesize": 0}]).encode())
|
||||||
open(os.path.join(images_dir, "QEMU", "asa.qcow2"), "w+").close()
|
|
||||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||||
images = async_run(compute.images("qemu"))
|
images = async_run(compute.images("qemu"))
|
||||||
mock.assert_called_with("GET", "https://example.com:84/v2/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
mock.assert_called_with("GET", "https://example.com:84/v2/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||||
async_run(compute.close())
|
async_run(compute.close())
|
||||||
|
|
||||||
assert images == [
|
assert images == [
|
||||||
{"filename": "asa.qcow2", "path": "asa.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0},
|
|
||||||
{"filename": "linux.qcow2", "path": "linux.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0}
|
{"filename": "linux.qcow2", "path": "linux.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user