Merge "Move resource provider objects into placement hierarchy"

This commit is contained in:
Zuul 2018-03-13 19:14:29 +00:00 committed by Gerrit Code Review
commit 66951fe50e
19 changed files with 49 additions and 48 deletions

View File

@ -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':

View File

@ -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):

View File

@ -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__)

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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])

View File

@ -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

View File

@ -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