Make InstanceInfoCache load base attributes

The InstanceInfoCache object is pretty bare-bones, previously needing
only the two main attributes. Since the virt/firewall module uses
the deleted flag, we need to load that now.

Related to blueprint compute-manager-objects
Related to blueprint virt-objects

Change-Id: I355a20b402c5581c1582cbe321c63bab58ee4815
This commit is contained in:
Dan Smith 2013-10-14 17:08:25 -07:00
parent dbfbbe7658
commit c54b9fc729
6 changed files with 37 additions and 11 deletions

View File

@ -30,7 +30,9 @@ class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject):
# Version 1.2: Added new() and update_cells kwarg to save().
# Version 1.3: Added delete()
# Version 1.4: String attributes updated to support unicode
VERSION = '1.4'
# Version 1.5: Actually set the deleted, created_at, updated_at, and
# deleted_at attributes
VERSION = '1.5'
fields = {
'instance_uuid': fields.UUIDField(),
@ -39,8 +41,8 @@ class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject):
@staticmethod
def _from_db_object(context, info_cache, db_obj):
info_cache.instance_uuid = db_obj['instance_uuid']
info_cache.network_info = db_obj['network_info']
for field in info_cache.fields:
info_cache[field] = db_obj[field]
info_cache.obj_reset_changes()
info_cache._context = context
return info_cache

View File

@ -417,7 +417,15 @@ def create_info_cache(nw_cache):
if not isinstance(nw_cache, basestring):
nw_cache = jsonutils.dumps(nw_cache)
return {"info_cache": {"network_info": nw_cache}}
return {
"info_cache": {
"network_info": nw_cache,
"deleted": False,
"created_at": None,
"deleted_at": None,
"updated_at": None,
}
}
def get_fake_uuid(token=0):

View File

@ -33,6 +33,7 @@ from nova.openstack.common import uuidutils
from nova import test
from nova.tests.compute import fake_resource_tracker
from nova.tests import fake_instance
from nova.tests.objects import test_instance_info_cache
from nova import utils
@ -146,8 +147,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
fake_context = 'fake-context'
inst = fake_instance.fake_db_instance(
vm_state=vm_states.ACTIVE,
info_cache={'instance_uuid': 'fake-uuid',
'network_info': None},
info_cache=dict(test_instance_info_cache.fake_info_cache,
network_info=None),
security_groups=None)
startup_instances = [inst, inst, inst]

View File

@ -30,6 +30,7 @@ from nova.network import rpcapi as network_rpcapi
from nova.objects import base as obj_base
from nova.objects import instance_info_cache
from nova.openstack.common import jsonutils
from nova.tests.objects import test_instance_info_cache
from nova.virt.libvirt import config as libvirt_config
@ -470,8 +471,9 @@ def _get_instances_with_cached_ips(orig_func, *args, **kwargs):
context = args[0]
def _info_cache_for(instance):
info_cache = {'network_info': _get_fake_cache(),
'instance_uuid': instance['uuid']}
info_cache = dict(test_instance_info_cache.fake_info_cache,
network_info=_get_fake_cache(),
instance_uuid=instance['uuid'])
if isinstance(instance, obj_base.NovaObject):
_info_cache = instance_info_cache.InstanceInfoCache()
instance_info_cache.InstanceInfoCache._from_db_object(context,

View File

@ -32,6 +32,7 @@ from nova import test
from nova.tests.api.openstack import fakes
from nova.tests import fake_instance
from nova.tests.objects import test_instance_fault
from nova.tests.objects import test_instance_info_cache
from nova.tests.objects import test_objects
from nova.tests.objects import test_security_group
@ -406,8 +407,10 @@ class _TestInstanceObject(object):
nwinfo2 = network_model.NetworkInfo.hydrate([{'address': 'bar'}])
nwinfo1_json = nwinfo1.json()
nwinfo2_json = nwinfo2.json()
fake_inst['info_cache'] = {'network_info': nwinfo1_json,
'instance_uuid': fake_uuid}
fake_inst['info_cache'] = dict(
test_instance_info_cache.fake_info_cache,
network_info=nwinfo1_json,
instance_uuid=fake_uuid)
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
self.mox.StubOutWithMock(db, 'instance_info_cache_update')

View File

@ -21,12 +21,22 @@ from nova.objects import instance_info_cache
from nova.tests.objects import test_objects
fake_info_cache = {
'created_at': None,
'updated_at': None,
'deleted_at': None,
'deleted': False,
'instance_uuid': 'fake-uuid',
'network_info': '[]',
}
class _TestInstanceInfoCacheObject(object):
def test_get_by_instance_uuid(self):
nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
self.mox.StubOutWithMock(db, 'instance_info_cache_get')
db.instance_info_cache_get(self.context, 'fake-uuid').AndReturn(
{'instance_uuid': 'fake-uuid', 'network_info': nwinfo.json()})
dict(fake_info_cache, network_info=nwinfo.json()))
self.mox.ReplayAll()
obj = instance_info_cache.InstanceInfoCache.get_by_instance_uuid(
self.context, 'fake-uuid')