From 8b19d5b7355cc10832fa1492fb46aa0e1b647c17 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Sat, 10 Mar 2018 12:54:42 +0000 Subject: [PATCH] Move resource provider objects into placement hierarchy This is so we don't have all the other objects imported into the the placement process, which happens by virtue of being in the nova.objects package. It also eases the eventual extraction of placement. That extraction will involve lifting and shifting the nova/api/openstack/placement directory (plus any tests) to a new repository. .../placement will become the roo placement directory in the repo, since a) placement is (for now) only an API, b) it eases extraction. Subsequent patches will do things like move exceptions and the wsgi application. Change-Id: I3e5144217c194f2571526311ddae6661cfed2ea9 --- nova/api/openstack/placement/deploy.py | 6 --- .../openstack/placement/handlers/aggregate.py | 2 +- .../placement/handlers/allocation.py | 2 +- .../handlers/allocation_candidate.py | 2 +- .../openstack/placement/handlers/inventory.py | 2 +- .../placement/handlers/resource_class.py | 2 +- .../placement/handlers/resource_provider.py | 2 +- .../api/openstack/placement/handlers/trait.py | 2 +- .../api/openstack/placement/handlers/usage.py | 2 +- .../openstack/placement/objects/__init__.py | 0 .../placement}/objects/resource_provider.py | 0 nova/test.py | 5 ++- .../api/openstack/placement/fixtures.py | 7 ++-- .../db/test_allocation_candidates.py | 2 +- .../functional/db/test_resource_provider.py | 20 +++++----- .../openstack/placement/objects/__init__.py | 0 .../objects/test_resource_provider.py | 37 +++++++++++-------- .../unit/api/openstack/placement/test_util.py | 2 +- nova/tests/unit/cmd/test_status.py | 2 +- 19 files changed, 49 insertions(+), 48 deletions(-) create mode 100644 nova/api/openstack/placement/objects/__init__.py rename nova/{ => api/openstack/placement}/objects/resource_provider.py (100%) create mode 100644 nova/tests/unit/api/openstack/placement/objects/__init__.py rename nova/tests/unit/{ => api/openstack/placement}/objects/test_resource_provider.py (94%) diff --git a/nova/api/openstack/placement/deploy.py b/nova/api/openstack/placement/deploy.py index bbd4d24eb56b..fb3f18d224ce 100644 --- a/nova/api/openstack/placement/deploy.py +++ b/nova/api/openstack/placement/deploy.py @@ -19,7 +19,6 @@ from nova.api.openstack.placement import fault_wrap from nova.api.openstack.placement import handler from nova.api.openstack.placement import microversion from nova.api.openstack.placement import requestlog -from nova import objects # TODO(cdent): NAME points to the config project being used, so for @@ -27,11 +26,6 @@ from nova import objects NAME = "nova" -# Make sure that objects are registered for this running of the -# placement API. -objects.register_all() - - def deploy(conf): """Assemble the middleware pipeline leading to the placement app.""" if conf.api.auth_strategy == 'noauth2': diff --git a/nova/api/openstack/placement/handlers/aggregate.py b/nova/api/openstack/placement/handlers/aggregate.py index 07e445e42d43..fdd73cb52d1e 100644 --- a/nova/api/openstack/placement/handlers/aggregate.py +++ b/nova/api/openstack/placement/handlers/aggregate.py @@ -16,10 +16,10 @@ from oslo_utils import encodeutils from oslo_utils import timeutils from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import aggregate as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper -from nova.objects import resource_provider as rp_obj def _send_aggregates(req, aggregate_uuids): diff --git a/nova/api/openstack/placement/handlers/allocation.py b/nova/api/openstack/placement/handlers/allocation.py index cef212cfc309..61d733adbda6 100644 --- a/nova/api/openstack/placement/handlers/allocation.py +++ b/nova/api/openstack/placement/handlers/allocation.py @@ -20,12 +20,12 @@ from oslo_utils import timeutils import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import allocation as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova import exception from nova.i18n import _ -from nova.objects import resource_provider as rp_obj LOG = logging.getLogger(__name__) diff --git a/nova/api/openstack/placement/handlers/allocation_candidate.py b/nova/api/openstack/placement/handlers/allocation_candidate.py index 7ee87f8e4317..d5511827712e 100644 --- a/nova/api/openstack/placement/handlers/allocation_candidate.py +++ b/nova/api/openstack/placement/handlers/allocation_candidate.py @@ -21,12 +21,12 @@ import six import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import allocation_candidate as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova import exception from nova.i18n import _ -from nova.objects import resource_provider as rp_obj def _transform_allocation_requests_dict(alloc_reqs): diff --git a/nova/api/openstack/placement/handlers/inventory.py b/nova/api/openstack/placement/handlers/inventory.py index ad3a8ba7c7c9..f3f22e45be04 100644 --- a/nova/api/openstack/placement/handlers/inventory.py +++ b/nova/api/openstack/placement/handlers/inventory.py @@ -19,13 +19,13 @@ from oslo_utils import encodeutils import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import inventory as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova.db import constants as db_const from nova import exception from nova.i18n import _ -from nova.objects import resource_provider as rp_obj # NOTE(cdent): We keep our own representation of inventory defaults diff --git a/nova/api/openstack/placement/handlers/resource_class.py b/nova/api/openstack/placement/handlers/resource_class.py index 72576cd5c5cf..5268131eae31 100644 --- a/nova/api/openstack/placement/handlers/resource_class.py +++ b/nova/api/openstack/placement/handlers/resource_class.py @@ -17,12 +17,12 @@ from oslo_utils import timeutils import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import resource_class as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova import exception from nova.i18n import _ -from nova.objects import resource_provider as rp_obj def _serialize_links(environ, rc): diff --git a/nova/api/openstack/placement/handlers/resource_provider.py b/nova/api/openstack/placement/handlers/resource_provider.py index 0312fc16cb42..f30ad602c269 100644 --- a/nova/api/openstack/placement/handlers/resource_provider.py +++ b/nova/api/openstack/placement/handlers/resource_provider.py @@ -19,12 +19,12 @@ from oslo_utils import uuidutils import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import resource_provider as rp_schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova import exception from nova.i18n import _ -from nova.objects import resource_provider as rp_obj def _serialize_links(environ, resource_provider): diff --git a/nova/api/openstack/placement/handlers/trait.py b/nova/api/openstack/placement/handlers/trait.py index 558020100c63..c48d9cdda4ed 100644 --- a/nova/api/openstack/placement/handlers/trait.py +++ b/nova/api/openstack/placement/handlers/trait.py @@ -18,12 +18,12 @@ from oslo_utils import timeutils import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import trait as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova import exception from nova.i18n import _ -from nova.objects import resource_provider as rp_obj def _normalize_traits_qs_param(qs): diff --git a/nova/api/openstack/placement/handlers/usage.py b/nova/api/openstack/placement/handlers/usage.py index fe5e869ca16f..b9acb7bb46a8 100644 --- a/nova/api/openstack/placement/handlers/usage.py +++ b/nova/api/openstack/placement/handlers/usage.py @@ -17,12 +17,12 @@ from oslo_utils import timeutils import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement.schemas import usage as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova import exception from nova.i18n import _ -from nova.objects import resource_provider as rp_obj def _serialize_usages(resource_provider, usage): diff --git a/nova/api/openstack/placement/objects/__init__.py b/nova/api/openstack/placement/objects/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/objects/resource_provider.py b/nova/api/openstack/placement/objects/resource_provider.py similarity index 100% rename from nova/objects/resource_provider.py rename to nova/api/openstack/placement/objects/resource_provider.py diff --git a/nova/test.py b/nova/test.py index 1294d90198c0..36187ddec53e 100644 --- a/nova/test.py +++ b/nova/test.py @@ -49,6 +49,7 @@ from oslotest import moxstubout import six import testtools +from nova.api.openstack.placement.objects import resource_provider from nova import context from nova import db from nova import exception @@ -309,8 +310,8 @@ class TestCase(testtools.TestCase): utils._IS_NEUTRON = None # Reset the traits sync and rc cache flags - objects.resource_provider._TRAITS_SYNCED = False - objects.resource_provider._RC_CACHE = None + resource_provider._TRAITS_SYNCED = False + resource_provider._RC_CACHE = None # Reset the global QEMU version flag. images.QEMU_VERSION = None diff --git a/nova/tests/functional/api/openstack/placement/fixtures.py b/nova/tests/functional/api/openstack/placement/fixtures.py index 549643c5dcc1..741b39b47a30 100644 --- a/nova/tests/functional/api/openstack/placement/fixtures.py +++ b/nova/tests/functional/api/openstack/placement/fixtures.py @@ -17,11 +17,10 @@ from oslo_middleware import cors from oslo_utils import uuidutils from nova.api.openstack.placement import deploy +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova import conf from nova import config from nova import context -from nova import objects -from nova.objects import resource_provider as rp_obj from nova.tests import fixtures @@ -96,8 +95,8 @@ class APIFixture(fixture.GabbiFixture): # flag to make sure the next run will recreate the traits and # reset the _RC_CACHE so that any cached resource classes # are flushed. - objects.resource_provider._TRAITS_SYNCED = False - objects.resource_provider._RC_CACHE = None + rp_obj._TRAITS_SYNCED = False + rp_obj._RC_CACHE = None self.output_stream_fixture.cleanUp() self.standard_logging_fixture.cleanUp() diff --git a/nova/tests/functional/db/test_allocation_candidates.py b/nova/tests/functional/db/test_allocation_candidates.py index 7ea0886870ac..08942de00c5e 100644 --- a/nova/tests/functional/db/test_allocation_candidates.py +++ b/nova/tests/functional/db/test_allocation_candidates.py @@ -14,9 +14,9 @@ from oslo_utils import uuidutils import sqlalchemy as sa from nova.api.openstack.placement import lib as placement_lib +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova import context from nova import exception -from nova.objects import resource_provider as rp_obj from nova import rc_fields as fields from nova import test from nova.tests import fixtures diff --git a/nova/tests/functional/db/test_resource_provider.py b/nova/tests/functional/db/test_resource_provider.py index f59171955d9f..375de7c0ad40 100644 --- a/nova/tests/functional/db/test_resource_provider.py +++ b/nova/tests/functional/db/test_resource_provider.py @@ -17,9 +17,9 @@ from oslo_db import exception as db_exc import sqlalchemy as sa import nova +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova import context from nova import exception -from nova.objects import resource_provider as rp_obj from nova import rc_fields as fields from nova import test from nova.tests import fixtures @@ -504,8 +504,8 @@ class ResourceProviderTestCase(ResourceProviderBaseCase): # NOTE(jaypipes): This is just disabling the online data migration that # occurs in _from_db_object() that sets root provider ID to ensure we # don't have any migrations messing with the end result. - with mock.patch('nova.objects.resource_provider.' - '_set_root_provider_id'): + with mock.patch('nova.api.openstack.placement.objects.' + 'resource_provider._set_root_provider_id'): rps = rp_obj.ResourceProviderList.get_all_by_filters( self.ctx, filters={ @@ -658,7 +658,7 @@ class ResourceProviderTestCase(ResourceProviderBaseCase): rp.set_inventory, inv_list) - @mock.patch('nova.objects.resource_provider.LOG') + @mock.patch('nova.api.openstack.placement.objects.resource_provider.LOG') def test_set_inventory_over_capacity(self, mock_log): rp = rp_obj.ResourceProvider(context=self.ctx, uuid=uuidsentinel.rp_uuid, @@ -875,7 +875,7 @@ class ResourceProviderTestCase(ResourceProviderBaseCase): self.assertIn('No inventory of class DISK_GB found', str(error)) - @mock.patch('nova.objects.resource_provider.LOG') + @mock.patch('nova.api.openstack.placement.objects.resource_provider.LOG') def test_update_inventory_violates_allocation(self, mock_log): # Compute nodes that are reconfigured have to be able to set # their inventory to something that violates allocations so @@ -2027,8 +2027,9 @@ class ResourceClassTestCase(ResourceProviderBaseCase): rc.create() self.assertEqual(min_id + 1, rc.id) - @mock.patch.object(nova.objects.resource_provider.ResourceClass, - "_get_next_id") + @mock.patch.object( + nova.api.openstack.placement.objects.resource_provider.ResourceClass, + "_get_next_id") def test_create_duplicate_id_retry(self, mock_get): # This order of ID generation will create rc1 with an ID of 42, try to # create rc2 with the same ID, and then return 43 in the retry loop. @@ -2046,8 +2047,9 @@ class ResourceClassTestCase(ResourceProviderBaseCase): self.assertEqual(rc1.id, 42) self.assertEqual(rc2.id, 43) - @mock.patch.object(nova.objects.resource_provider.ResourceClass, - "_get_next_id") + @mock.patch.object( + nova.api.openstack.placement.objects.resource_provider.ResourceClass, + "_get_next_id") def test_create_duplicate_id_retry_failing(self, mock_get): """negative case for test_create_duplicate_id_retry""" # This order of ID generation will create rc1 with an ID of 44, try to diff --git a/nova/tests/unit/api/openstack/placement/objects/__init__.py b/nova/tests/unit/api/openstack/placement/objects/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/tests/unit/objects/test_resource_provider.py b/nova/tests/unit/api/openstack/placement/objects/test_resource_provider.py similarity index 94% rename from nova/tests/unit/objects/test_resource_provider.py rename to nova/tests/unit/api/openstack/placement/objects/test_resource_provider.py index ff2d9205b29c..c721e2d7cd71 100644 --- a/nova/tests/unit/objects/test_resource_provider.py +++ b/nova/tests/unit/api/openstack/placement/objects/test_resource_provider.py @@ -16,10 +16,10 @@ import six from oslo_utils import timeutils import nova +from nova.api.openstack.placement.objects import resource_provider from nova import context from nova.db.sqlalchemy import api_models as models from nova import exception -from nova.objects import resource_provider from nova import rc_fields as fields from nova import test from nova.tests.unit.objects import test_objects @@ -247,9 +247,10 @@ class TestResourceProvider(test_objects._LocalTest): class TestInventoryNoDB(test_objects._LocalTest): USES_DB = False - @mock.patch('nova.objects.resource_provider._ensure_rc_cache', - side_effect=_fake_ensure_cache) - @mock.patch('nova.objects.resource_provider._get_inventory_by_provider_id') + @mock.patch('nova.api.openstack.placement.objects.resource_provider.' + '_ensure_rc_cache', side_effect=_fake_ensure_cache) + @mock.patch('nova.api.openstack.placement.objects.resource_provider.' + '_get_inventory_by_provider_id') def test_get_all_by_resource_provider(self, mock_get, mock_ensure_cache): expected = [dict(_INVENTORY_DB, resource_provider_id=_RESOURCE_PROVIDER_ID), @@ -350,8 +351,8 @@ class TestInventoryList(test_objects._LocalTest): class TestAllocation(test_objects._LocalTest): USES_DB = True - @mock.patch('nova.objects.resource_provider._ensure_rc_cache', - side_effect=_fake_ensure_cache) + @mock.patch('nova.api.openstack.placement.objects.resource_provider.' + '_ensure_rc_cache', side_effect=_fake_ensure_cache) def test_create(self, mock_ensure_cache): rp = resource_provider.ResourceProvider(context=self.context, uuid=_RESOURCE_PROVIDER_UUID, @@ -415,9 +416,10 @@ class TestAllocation(test_objects._LocalTest): class TestAllocationListNoDB(test_objects._LocalTest): USES_DB = False - @mock.patch('nova.objects.resource_provider._ensure_rc_cache', - side_effect=_fake_ensure_cache) - @mock.patch('nova.objects.resource_provider.' + @mock.patch('nova.api.openstack.placement.objects.resource_provider.' + '_ensure_rc_cache', + side_effect=_fake_ensure_cache) + @mock.patch('nova.api.openstack.placement.objects.resource_provider.' '_get_allocations_by_provider_id', return_value=[_ALLOCATION_DB]) def test_get_allocations(self, mock_get_allocations_from_db, @@ -462,18 +464,21 @@ class TestTraits(test.NoDBTestCase): self.project_id = 'fake-project' self.context = context.RequestContext(self.user_id, self.project_id) - @mock.patch("nova.objects.resource_provider._trait_sync") + @mock.patch("nova.api.openstack.placement.objects.resource_provider." + "_trait_sync") def test_sync_flag(self, mock_sync): - synced = nova.objects.resource_provider._TRAITS_SYNCED + rp_obj = nova.api.openstack.placement.objects.resource_provider + synced = rp_obj._TRAITS_SYNCED self.assertFalse(synced) # Sync the traits - nova.objects.resource_provider._ensure_trait_sync(self.context) - synced = nova.objects.resource_provider._TRAITS_SYNCED + rp_obj._ensure_trait_sync(self.context) + synced = rp_obj._TRAITS_SYNCED self.assertTrue(synced) - @mock.patch('nova.objects.resource_provider.ResourceProvider.' - 'obj_reset_changes') - @mock.patch('nova.objects.resource_provider._set_traits') + @mock.patch('nova.api.openstack.placement.objects.resource_provider.' + 'ResourceProvider.obj_reset_changes') + @mock.patch('nova.api.openstack.placement.objects.resource_provider.' + '_set_traits') def test_set_traits_resets_changes(self, mock_set_traits, mock_reset): trait = resource_provider.Trait(name="HW_CPU_X86_AVX2") traits = resource_provider.TraitList(objects=[trait]) diff --git a/nova/tests/unit/api/openstack/placement/test_util.py b/nova/tests/unit/api/openstack/placement/test_util.py index 0dea037bb231..df74e79d7888 100644 --- a/nova/tests/unit/api/openstack/placement/test_util.py +++ b/nova/tests/unit/api/openstack/placement/test_util.py @@ -26,8 +26,8 @@ import six.moves.urllib.parse as urlparse from nova.api.openstack.placement import lib as pl from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.api.openstack.placement import util -from nova.objects import resource_provider as rp_obj from nova import test from nova.tests import uuidsentinel diff --git a/nova/tests/unit/cmd/test_status.py b/nova/tests/unit/cmd/test_status.py index 9aee8e49da85..552362af39ee 100644 --- a/nova/tests/unit/cmd/test_status.py +++ b/nova/tests/unit/cmd/test_status.py @@ -25,13 +25,13 @@ from keystoneauth1 import loading as keystone from keystoneauth1 import session from oslo_utils import uuidutils +from nova.api.openstack.placement.objects import resource_provider as rp_obj from nova.cmd import status import nova.conf from nova import context # NOTE(mriedem): We only use objects as a convenience to populate the database # in the tests, we don't use them in the actual CLI. from nova import objects -from nova.objects import resource_provider as rp_obj from nova import rc_fields as fields from nova import test from nova.tests import fixtures as nova_fixtures