diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index 11df55b3..3aff87bd 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -23,6 +23,7 @@ import json import uuid import sys import io +from operator import itemgetter from ..utils import parse_version from ..utils.images import list_images @@ -602,7 +603,7 @@ class Compute: images.append(local_image) except OSError as e: raise ComputeError("Can't list images: {}".format(str(e))) - images.sort() + images = sorted(images, key=itemgetter('filename')) return images @asyncio.coroutine diff --git a/tests/controller/test_compute.py b/tests/controller/test_compute.py index c8b90c09..07b926cb 100644 --- a/tests/controller/test_compute.py +++ b/tests/controller/test_compute.py @@ -360,8 +360,10 @@ def test_images(compute, async_run, images_dir): 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=False, timeout=None) - assert images == [{"filename": "linux.qcow2", "path": "linux.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0}, - {"filename": "asa.qcow2", "path": "asa.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0}] + assert images == [ + {"filename": "asa.qcow2", "path": "asa.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0}, + {"filename": "linux.qcow2", "path": "linux.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0} + ] def test_list_files(project, async_run, compute):