diff --git a/nova/api/openstack/compute/legacy_v2/contrib/flavormanage.py b/nova/api/openstack/compute/legacy_v2/contrib/flavormanage.py index 4c3ee0be90c1..a91048de103f 100644 --- a/nova/api/openstack/compute/legacy_v2/contrib/flavormanage.py +++ b/nova/api/openstack/compute/legacy_v2/contrib/flavormanage.py @@ -88,6 +88,9 @@ class FlavorManageController(wsgi.Controller): except (exception.FlavorExists, exception.FlavorIdExists) as err: raise webob.exc.HTTPConflict(explanation=err.format_message()) + except exception.ObjectActionError: + raise webob.exc.HTTPConflict(explanation=_( + 'Not all flavors have been migrated to the API database')) except exception.InvalidInput as exc: raise webob.exc.HTTPBadRequest(explanation=exc.format_message()) except exception.FlavorCreateFailed as exc: diff --git a/nova/tests/functional/wsgi/test_flavor_manage.py b/nova/tests/functional/wsgi/test_flavor_manage.py index b259113592a9..73e5d2b92ae4 100644 --- a/nova/tests/functional/wsgi/test_flavor_manage.py +++ b/nova/tests/functional/wsgi/test_flavor_manage.py @@ -16,12 +16,15 @@ import six +import testscenarios + from nova import context from nova import db from nova import exception as ex from nova import objects from nova import test from nova.tests import fixtures as nova_fixtures +from nova.tests.functional import api_paste_fixture from nova.tests.functional import integrated_helpers as helper from nova.tests.unit import policy_fixture @@ -38,7 +41,7 @@ def rand_flavor(**kwargs): return flav -class FlavorManageFullstack(test.TestCase): +class FlavorManageFullstack(testscenarios.WithScenarios, test.TestCase): """Tests for flavors manage administrative command. Extension: os-flavors-manage @@ -74,10 +77,31 @@ class FlavorManageFullstack(test.TestCase): the database. """ + + _additional_fixtures = [] + + scenarios = [ + # test v2.1 base microversion + ('v2_1', { + 'api_major_version': 'v2.1'}), + # test v2 with the v2 legacy code + ('v2legacy', { + 'api_major_version': 'v2', + '_additional_fixtures': [ + api_paste_fixture.ApiPasteLegacyV2Fixture]}) + ] + def setUp(self): super(FlavorManageFullstack, self).setUp() + + # load any additional fixtures specified by the scenario + for fix in self._additional_fixtures: + self.useFixture(fix()) + self.useFixture(policy_fixture.RealPolicyFixture()) - api_fixture = self.useFixture(nova_fixtures.OSAPIFixture()) + api_fixture = self.useFixture( + nova_fixtures.OSAPIFixture( + api_version=self.api_major_version)) # NOTE(sdague): because this test is primarily an admin API # test default self.api to the admin api.