Merge "Make resource provider objects not remotable"
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
# NOTE(cdent): The resource provider objects are designed to never be
|
||||
# used over RPC. Remote manipulation is done with the placement HTTP
|
||||
# API. The 'remotable' decorators should not be used.
|
||||
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_log import log as logging
|
||||
@@ -310,7 +313,8 @@ class ResourceProvider(base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: Add destroy()
|
||||
# Version 1.2: Add get_aggregates(), set_aggregates()
|
||||
VERSION = '1.2'
|
||||
# Version 1.3: Turn off remotable
|
||||
VERSION = '1.3'
|
||||
|
||||
fields = {
|
||||
'id': fields.IntegerField(read_only=True),
|
||||
@@ -319,7 +323,6 @@ class ResourceProvider(base.NovaObject):
|
||||
'generation': fields.IntegerField(nullable=False),
|
||||
}
|
||||
|
||||
@base.remotable
|
||||
def create(self):
|
||||
if 'id' in self:
|
||||
raise exception.ObjectActionError(action='create',
|
||||
@@ -334,11 +337,9 @@ class ResourceProvider(base.NovaObject):
|
||||
db_rp = self._create_in_db(self._context, updates)
|
||||
self._from_db_object(self._context, self, db_rp)
|
||||
|
||||
@base.remotable
|
||||
def destroy(self):
|
||||
self._delete(self._context, self.id)
|
||||
|
||||
@base.remotable
|
||||
def save(self):
|
||||
updates = self.obj_get_changes()
|
||||
if updates and updates.keys() != ['name']:
|
||||
@@ -347,12 +348,11 @@ class ResourceProvider(base.NovaObject):
|
||||
reason='Immutable fields changed')
|
||||
self._update_in_db(self._context, self.id, updates)
|
||||
|
||||
@base.remotable_classmethod
|
||||
@classmethod
|
||||
def get_by_uuid(cls, context, uuid):
|
||||
db_resource_provider = cls._get_by_uuid_from_db(context, uuid)
|
||||
return cls._from_db_object(context, cls(), db_resource_provider)
|
||||
|
||||
@base.remotable
|
||||
def add_inventory(self, inventory):
|
||||
"""Add one new Inventory to the resource provider.
|
||||
|
||||
@@ -362,13 +362,11 @@ class ResourceProvider(base.NovaObject):
|
||||
_add_inventory(self._context, self, inventory)
|
||||
self.obj_reset_changes()
|
||||
|
||||
@base.remotable
|
||||
def delete_inventory(self, resource_class):
|
||||
"""Delete Inventory of provided resource_class."""
|
||||
_delete_inventory(self._context, self, resource_class)
|
||||
self.obj_reset_changes()
|
||||
|
||||
@base.remotable
|
||||
def set_inventory(self, inv_list):
|
||||
"""Set all resource provider Inventory to be the provided list."""
|
||||
exceeded = _set_inventory(self._context, self, inv_list)
|
||||
@@ -378,7 +376,6 @@ class ResourceProvider(base.NovaObject):
|
||||
{'uuid': uuid, 'resource': rclass})
|
||||
self.obj_reset_changes()
|
||||
|
||||
@base.remotable
|
||||
def update_inventory(self, inventory):
|
||||
"""Update one existing Inventory of the same resource class.
|
||||
|
||||
@@ -529,7 +526,8 @@ class ResourceProvider(base.NovaObject):
|
||||
@base.NovaObjectRegistry.register
|
||||
class ResourceProviderList(base.ObjectListBase, base.NovaObject):
|
||||
# Version 1.0: Initial Version
|
||||
VERSION = '1.0'
|
||||
# Version 1.1: Turn off remotable
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
'objects': fields.ListOfObjectsField('ResourceProvider'),
|
||||
@@ -655,7 +653,7 @@ class ResourceProviderList(base.ObjectListBase, base.NovaObject):
|
||||
|
||||
return query.all()
|
||||
|
||||
@base.remotable_classmethod
|
||||
@classmethod
|
||||
def get_all_by_filters(cls, context, filters=None):
|
||||
"""Returns a list of `ResourceProvider` objects that have sufficient
|
||||
resources in their inventories to satisfy the amounts specified in the
|
||||
@@ -743,7 +741,8 @@ def _update_inventory_in_db(context, id_, updates):
|
||||
class Inventory(_HasAResourceProvider):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: Changed resource_class to allow custom strings
|
||||
VERSION = '1.1'
|
||||
# Version 1.2: Turn off remotable
|
||||
VERSION = '1.2'
|
||||
|
||||
fields = {
|
||||
'id': fields.IntegerField(read_only=True),
|
||||
@@ -769,7 +768,6 @@ class Inventory(_HasAResourceProvider):
|
||||
"""Inventory capacity, adjusted by allocation_ratio."""
|
||||
return int((self.total - self.reserved) * self.allocation_ratio)
|
||||
|
||||
@base.remotable
|
||||
def create(self):
|
||||
if 'id' in self:
|
||||
raise exception.ObjectActionError(action='create',
|
||||
@@ -779,7 +777,6 @@ class Inventory(_HasAResourceProvider):
|
||||
db_inventory = self._create_in_db(self._context, updates)
|
||||
self._from_db_object(self._context, self, db_inventory)
|
||||
|
||||
@base.remotable
|
||||
def save(self):
|
||||
if 'id' not in self:
|
||||
raise exception.ObjectActionError(action='save',
|
||||
@@ -801,7 +798,8 @@ class Inventory(_HasAResourceProvider):
|
||||
@base.NovaObjectRegistry.register
|
||||
class InventoryList(base.ObjectListBase, base.NovaObject):
|
||||
# Version 1.0: Initial Version
|
||||
VERSION = '1.0'
|
||||
# Version 1.1: Turn off remotable
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
'objects': fields.ListOfObjectsField('Inventory'),
|
||||
@@ -831,7 +829,7 @@ class InventoryList(base.ObjectListBase, base.NovaObject):
|
||||
options(contains_eager('resource_provider')).\
|
||||
filter(models.ResourceProvider.uuid == rp_uuid).all()
|
||||
|
||||
@base.remotable_classmethod
|
||||
@classmethod
|
||||
def get_all_by_resource_provider_uuid(cls, context, rp_uuid):
|
||||
db_inventory_list = cls._get_all_by_resource_provider(context,
|
||||
rp_uuid)
|
||||
@@ -843,7 +841,8 @@ class InventoryList(base.ObjectListBase, base.NovaObject):
|
||||
class Allocation(_HasAResourceProvider):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: Changed resource_class to allow custom strings
|
||||
VERSION = '1.1'
|
||||
# Version 1.2: Turn off remotable
|
||||
VERSION = '1.2'
|
||||
|
||||
fields = {
|
||||
'id': fields.IntegerField(),
|
||||
@@ -879,7 +878,6 @@ class Allocation(_HasAResourceProvider):
|
||||
if not result:
|
||||
raise exception.NotFound()
|
||||
|
||||
@base.remotable
|
||||
def create(self):
|
||||
if 'id' in self:
|
||||
raise exception.ObjectActionError(action='create',
|
||||
@@ -889,7 +887,6 @@ class Allocation(_HasAResourceProvider):
|
||||
db_allocation = self._create_in_db(self._context, updates)
|
||||
self._from_db_object(self._context, self, db_allocation)
|
||||
|
||||
@base.remotable
|
||||
def destroy(self):
|
||||
self._destroy(self._context, self.id)
|
||||
|
||||
@@ -1066,7 +1063,8 @@ def _check_capacity_exceeded(conn, allocs):
|
||||
class AllocationList(base.ObjectListBase, base.NovaObject):
|
||||
# Version 1.0: Initial Version
|
||||
# Version 1.1: Add create_all() and delete_all()
|
||||
VERSION = '1.1'
|
||||
# Version 1.2: Turn off remotable
|
||||
VERSION = '1.2'
|
||||
|
||||
fields = {
|
||||
'objects': fields.ListOfObjectsField('Allocation'),
|
||||
@@ -1147,28 +1145,26 @@ class AllocationList(base.ObjectListBase, base.NovaObject):
|
||||
for rp in before_gens:
|
||||
_increment_provider_generation(conn, rp)
|
||||
|
||||
@base.remotable_classmethod
|
||||
@classmethod
|
||||
def get_all_by_resource_provider_uuid(cls, context, rp_uuid):
|
||||
db_allocation_list = cls._get_allocations_from_db(
|
||||
context, resource_provider_uuid=rp_uuid)
|
||||
return base.obj_make_list(
|
||||
context, cls(context), objects.Allocation, db_allocation_list)
|
||||
|
||||
@base.remotable_classmethod
|
||||
@classmethod
|
||||
def get_all_by_consumer_id(cls, context, consumer_id):
|
||||
db_allocation_list = cls._get_allocations_from_db(
|
||||
context, consumer_id=consumer_id)
|
||||
return base.obj_make_list(
|
||||
context, cls(context), objects.Allocation, db_allocation_list)
|
||||
|
||||
@base.remotable
|
||||
def create_all(self):
|
||||
"""Create the supplied allocations."""
|
||||
# TODO(jaypipes): Retry the allocation writes on
|
||||
# ConcurrentUpdateDetected
|
||||
self._set_allocations(self._context, self.objects)
|
||||
|
||||
@base.remotable
|
||||
def delete_all(self):
|
||||
self._delete_allocations(self._context, self.objects)
|
||||
|
||||
@@ -1213,7 +1209,8 @@ class Usage(base.NovaObject):
|
||||
@base.NovaObjectRegistry.register
|
||||
class UsageList(base.ObjectListBase, base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
# Version 1.1: Turn off remotable
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
'objects': fields.ListOfObjectsField('Usage'),
|
||||
@@ -1238,7 +1235,7 @@ class UsageList(base.ObjectListBase, base.NovaObject):
|
||||
for item in query.all()]
|
||||
return result
|
||||
|
||||
@base.remotable_classmethod
|
||||
@classmethod
|
||||
def get_all_by_resource_provider_uuid(cls, context, rp_uuid):
|
||||
usage_list = cls._get_all_by_resource_provider_uuid(context, rp_uuid)
|
||||
return base.obj_make_list(context, cls(context), Usage, usage_list)
|
||||
@@ -1420,7 +1417,8 @@ class ResourceClass(base.NovaObject):
|
||||
@base.NovaObjectRegistry.register
|
||||
class ResourceClassList(base.ObjectListBase, base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
# Version 1.1: Turn off remotable
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
'objects': fields.ListOfObjectsField('ResourceClass'),
|
||||
@@ -1433,7 +1431,7 @@ class ResourceClassList(base.ObjectListBase, base.NovaObject):
|
||||
customs = list(context.session.query(models.ResourceClass).all())
|
||||
return _RC_CACHE.STANDARDS + customs
|
||||
|
||||
@base.remotable_classmethod
|
||||
@classmethod
|
||||
def get_all(cls, context):
|
||||
resource_classes = cls._get_all(context)
|
||||
return base.obj_make_list(context, cls(context),
|
||||
|
||||
@@ -1062,8 +1062,8 @@ object_data = {
|
||||
'AgentList': '1.0-5a7380d02c3aaf2a32fc8115ae7ca98c',
|
||||
'Aggregate': '1.3-f315cb68906307ca2d1cca84d4753585',
|
||||
'AggregateList': '1.2-fb6e19f3c3a3186b04eceb98b5dadbfa',
|
||||
'Allocation': '1.1-27814e4c0cf1fd5ffaa3bcbc8f9734e5',
|
||||
'AllocationList': '1.1-e43fe4a9c9cbbda7438b0e48332f099e',
|
||||
'Allocation': '1.2-54f99dfa9651922219c205a7fba69e2f',
|
||||
'AllocationList': '1.2-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'BandwidthUsage': '1.2-c6e4c779c7f40f2407e3d70022e3cd1c',
|
||||
'BandwidthUsageList': '1.2-5fe7475ada6fe62413cbfcc06ec70746',
|
||||
'BlockDeviceMapping': '1.17-5e094927f1251770dcada6ab05adfcdb',
|
||||
@@ -1115,8 +1115,8 @@ object_data = {
|
||||
'InstanceNUMATopology': '1.2-d944a7d6c21e1c773ffdf09c6d025954',
|
||||
'InstancePCIRequest': '1.1-b1d75ebc716cb12906d9d513890092bf',
|
||||
'InstancePCIRequests': '1.1-65e38083177726d806684cb1cc0136d2',
|
||||
'Inventory': '1.1-a2f8c7214829d623c2a7a32714d84eba',
|
||||
'InventoryList': '1.0-de53f0fd078c27cc1d43400f4e8bcef8',
|
||||
'Inventory': '1.2-7f681fb6fb7b75fabceab3c4d0f8ce0c',
|
||||
'InventoryList': '1.1-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'LibvirtLiveMigrateBDMInfo': '1.0-252aabb723ca79d5469fa56f64b57811',
|
||||
'LibvirtLiveMigrateData': '1.3-2795e5646ee21e8c7f1c3e64fb6c80a3',
|
||||
'KeyPair': '1.4-1244e8d1b103cc69d038ed78ab3a8cc6',
|
||||
@@ -1145,9 +1145,9 @@ object_data = {
|
||||
'QuotasNoOp': '1.2-e041ddeb7dc8188ca71706f78aad41c1',
|
||||
'RequestSpec': '1.8-35033ecef47a880f9a5e46e2269e2b97',
|
||||
'ResourceClass': '1.0-e6b367e2cf1733c5f3526f20a3286fe9',
|
||||
'ResourceClassList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
|
||||
'ResourceProvider': '1.2-7bbcd5ea1c51782692f55489ab08dea6',
|
||||
'ResourceProviderList': '1.0-82bd48d8d0f7913bbe7266f3835c81bf',
|
||||
'ResourceClassList': '1.1-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'ResourceProvider': '1.3-3539494ee3fa84930418fa6cc8eec0a9',
|
||||
'ResourceProviderList': '1.1-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'S3ImageMapping': '1.0-7dd7366a890d82660ed121de9092276e',
|
||||
'SchedulerLimits': '1.0-249c4bd8e62a9b327b7026b7f19cc641',
|
||||
'SchedulerRetries': '1.1-3c9c8b16143ebbb6ad7030e999d14cc0',
|
||||
@@ -1163,7 +1163,7 @@ object_data = {
|
||||
'Tag': '1.1-8b8d7d5b48887651a0e01241672e2963',
|
||||
'TagList': '1.1-55231bdb671ecf7641d6a2e9109b5d8e',
|
||||
'Usage': '1.1-b738dbebeb20e3199fc0ebca6e292a47',
|
||||
'UsageList': '1.0-de53f0fd078c27cc1d43400f4e8bcef8',
|
||||
'UsageList': '1.1-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'USBDeviceBus': '1.0-e4c7dd6032e46cd74b027df5eb2d4750',
|
||||
'VirtCPUFeature': '1.0-ea2464bdd09084bd388e5f61d5d4fc86',
|
||||
'VirtCPUModel': '1.0-5e1864af9227f698326203d7249796b5',
|
||||
|
||||
@@ -67,7 +67,8 @@ def _fake_ensure_cache(ctxt):
|
||||
cache.id_from_string.return_value = _RESOURCE_CLASS_ID
|
||||
|
||||
|
||||
class _TestResourceProviderNoDB(object):
|
||||
class TestResourceProviderNoDB(test_objects._LocalTest):
|
||||
USES_DB = False
|
||||
|
||||
@mock.patch('nova.objects.ResourceProvider._get_by_uuid_from_db',
|
||||
return_value=_RESOURCE_PROVIDER_DB)
|
||||
@@ -104,16 +105,6 @@ class _TestResourceProviderNoDB(object):
|
||||
obj.create)
|
||||
|
||||
|
||||
class TestResourceProviderNoDB(test_objects._LocalTest,
|
||||
_TestResourceProviderNoDB):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class TestRemoteResourceProviderNoDB(test_objects._RemoteTest,
|
||||
_TestResourceProviderNoDB):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class TestResourceProvider(test_objects._LocalTest):
|
||||
|
||||
def test_create_in_db(self):
|
||||
@@ -149,7 +140,9 @@ class TestResourceProvider(test_objects._LocalTest):
|
||||
self.context, uuids.missing)
|
||||
|
||||
|
||||
class _TestInventoryNoDB(object):
|
||||
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.Inventory._create_in_db',
|
||||
@@ -249,16 +242,6 @@ class _TestInventoryNoDB(object):
|
||||
self.assertEqual(2, inv.capacity)
|
||||
|
||||
|
||||
class TestInventoryNoDB(test_objects._LocalTest,
|
||||
_TestInventoryNoDB):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class TestRemoteInventoryNoDB(test_objects._RemoteTest,
|
||||
_TestInventoryNoDB):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class TestInventory(test_objects._LocalTest):
|
||||
|
||||
def _make_inventory(self, rp_uuid=None):
|
||||
@@ -474,7 +457,9 @@ class TestInventory(test_objects._LocalTest):
|
||||
target_version='1.0')
|
||||
|
||||
|
||||
class _TestAllocationNoDB(object):
|
||||
class TestAllocationNoDB(test_objects._LocalTest):
|
||||
USES_DB = False
|
||||
|
||||
@mock.patch('nova.objects.resource_provider._ensure_rc_cache',
|
||||
side_effect=_fake_ensure_cache)
|
||||
@mock.patch('nova.objects.Allocation._create_in_db',
|
||||
@@ -523,18 +508,9 @@ class _TestAllocationNoDB(object):
|
||||
target_version='1.0')
|
||||
|
||||
|
||||
class TestAllocationNoDB(test_objects._LocalTest,
|
||||
_TestAllocationNoDB):
|
||||
class TestAllocationListNoDB(test_objects._LocalTest):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class TestRemoteAllocationNoDB(test_objects._RemoteTest,
|
||||
_TestAllocationNoDB):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class _TestAllocationListNoDB(object):
|
||||
|
||||
@mock.patch('nova.objects.resource_provider._ensure_rc_cache',
|
||||
side_effect=_fake_ensure_cache)
|
||||
@mock.patch('nova.objects.AllocationList._get_allocations_from_db',
|
||||
@@ -552,16 +528,6 @@ class _TestAllocationListNoDB(object):
|
||||
self.assertEqual(_ALLOCATION_DB['used'], allocations[0].used)
|
||||
|
||||
|
||||
class TestAllocationListNoDB(test_objects._LocalTest,
|
||||
_TestAllocationListNoDB):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class TestRemoteAllocationListNoDB(test_objects._RemoteTest,
|
||||
_TestAllocationListNoDB):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
class TestUsageNoDB(test_objects._LocalTest):
|
||||
USES_DB = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user