pci: Deprecate is_new from pci requests

Patch https://review.openstack.org/#/c/307124/
stash the the old/new pci requests in the
migration context same as we do for NUMA.

This patch is a cleanup patch to deprecate the is_new field
in pci request. The is_new was horrible hack to get the
newer pci request on resize/migration and since the
pci_requests are now stashed in the migration context we
can deprecate it.

Change-Id: Ie36a74fb2aad9a14a2dc0e0b53649ee770fb2f9d
This commit is contained in:
Moshe Levi 2016-04-29 02:27:09 +03:00
parent cdfa50599c
commit 3ea6f089bf
2 changed files with 5 additions and 41 deletions

View File

@ -30,7 +30,8 @@ class InstancePCIRequest(base.NovaObject,
'count': fields.IntegerField(),
'spec': fields.ListOfDictOfNullableStringsField(),
'alias_name': fields.StringField(nullable=True),
# A stashed request related to a resize, not current
# Note(moshele): is_new is deprecated and should be removed
# on major version bump
'is_new': fields.BooleanField(default=False),
'request_id': fields.UUIDField(nullable=True),
}
@ -38,14 +39,6 @@ class InstancePCIRequest(base.NovaObject,
def obj_load_attr(self, attr):
setattr(self, attr, None)
# NOTE(danms): The dict that this object replaces uses a key of 'new'
# so we translate it here to our more appropropriately-named 'is_new'.
# This is not something that affects the object version, so we could
# remove this later when all dependent code is fixed.
@property
def new(self):
return self.is_new
def obj_make_compatible(self, primitive, target_version):
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'request_id' in primitive:
@ -82,9 +75,11 @@ class InstancePCIRequests(base.NovaObject,
else:
requests = []
for request in requests:
# Note(moshele): is_new is deprecated and therefore we load it
# with default value of False
request_obj = InstancePCIRequest(
count=request['count'], spec=request['spec'],
alias_name=request['alias_name'], is_new=request['is_new'],
alias_name=request['alias_name'], is_new=False,
request_id=request['request_id'])
request_obj.obj_reset_changes()
self.requests.append(request_obj)
@ -99,13 +94,6 @@ class InstancePCIRequests(base.NovaObject,
db_pci_requests = db_pci_requests['pci_requests']
return cls.obj_from_db(context, instance_uuid, db_pci_requests)
@classmethod
def get_by_instance_uuid_and_newness(cls, context, instance_uuid, is_new):
requests = cls.get_by_instance_uuid(context, instance_uuid)
requests.requests = [x for x in requests.requests
if x.new == is_new]
return requests
@staticmethod
def _load_legacy_requests(sysmeta_value, is_new=False):
if sysmeta_value is None:

View File

@ -69,26 +69,6 @@ class _TestInstancePCIRequests(object):
self.assertEqual(fake_pci_requests[index]['spec'],
[dict(x.items()) for x in request.spec])
@mock.patch('nova.objects.InstancePCIRequests.get_by_instance_uuid')
def test_get_by_instance_uuid_and_newness(self, mock_get):
pcir = objects.InstancePCIRequests
mock_get.return_value = objects.InstancePCIRequests(
instance_uuid=uuids.instance,
requests=[objects.InstancePCIRequest(count=1, is_new=False),
objects.InstancePCIRequest(count=2, is_new=True)])
old_req = pcir.get_by_instance_uuid_and_newness(self.context,
uuids.instance,
False)
mock_get.return_value = objects.InstancePCIRequests(
instance_uuid=uuids.instance,
requests=[objects.InstancePCIRequest(count=1, is_new=False),
objects.InstancePCIRequest(count=2, is_new=True)])
new_req = pcir.get_by_instance_uuid_and_newness(self.context,
uuids.instance,
True)
self.assertEqual(1, old_req.requests[0].count)
self.assertEqual(2, new_req.requests[0].count)
@mock.patch('nova.objects.InstancePCIRequests.get_by_instance_uuid')
def test_get_by_instance_current(self, mock_get):
instance = objects.Instance(uuid=uuids.instance,
@ -112,10 +92,6 @@ class _TestInstancePCIRequests(object):
self.assertEqual('alias_2', requests.requests[1].alias_name)
self.assertTrue(requests.requests[1].is_new)
def test_new_compatibility(self):
request = objects.InstancePCIRequest(is_new=False)
self.assertFalse(request.new)
def test_backport_1_0(self):
requests = objects.InstancePCIRequests(
requests=[objects.InstancePCIRequest(count=1,