From a19d64808f3c4ab1cc3306ac3678701d0fff3e87 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 20 Nov 2012 01:24:48 +0000 Subject: Return an error response if the specified flavor does not exists. (v4) 'nova list --flavor ' command outputs empty list, if there is not any instance or flavor. A user cannot know the reason of empty list easily. This patch changes a response to error if the specified flavor-id does not exist instead of empty list. Example: $ nova flavor-list +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+ | ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | extra_specs | +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+ | 1 | m1.tiny | 512 | 0 | 0 | | 1 | 1.0 | True | {} | | 2 | m1.small | 2048 | 20 | 0 | | 1 | 1.0 | True | {} | | 3 | m1.medium | 4096 | 40 | 0 | | 2 | 1.0 | True | {} | | 4 | m1.large | 8192 | 80 | 0 | | 4 | 1.0 | True | {} | | 5 | m1.xlarge | 16384 | 160 | 0 | | 8 | 1.0 | True | {} | +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+ Before applying this patch: $ nova list --flavor 10 $ After applying this patch: $ nova list --flavor 10 ERROR: Flavor could not be found (HTTP 422) (Request-ID: req-003d4bbc-f338-4361-9eeb-1cf18073a5a8) $ Changelog of v4: * Change a response code of NotFoundFlavor from 404 to 422. Changelog of v3: * Merge patchset2(change a response of test_get_all_by_flavor) into one patch. * Change a response code of NotFoundFlavor from 400 to 404. Fixes bug 1076863 Change-Id: I45f35ae6a4bf1de734c258ef819fb9b4d7f9681e --- nova/compute/api.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index 6da04c97b..948cf3fea 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1122,11 +1122,8 @@ class API(base.Base): filters = {} def _remap_flavor_filter(flavor_id): - try: - instance_type = instance_types.get_instance_type_by_flavor_id( - flavor_id) - except exception.FlavorNotFound: - raise ValueError() + instance_type = instance_types.get_instance_type_by_flavor_id( + flavor_id) filters['instance_type_id'] = instance_type['id'] -- cgit