summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-06-04 16:49:40 -0700
committerDan Smith <danms@us.ibm.com>2013-06-07 11:43:37 -0700
commite95807e8cda4463d7c9a2aab918bd2bda3d3cf9e (patch)
tree83959867726d347e15774d7f5c5be8901c73ad2a /nova/tests
parent6fcf4133b49cfefa77151937dec4db097a85c349 (diff)
Add Instance.info_cache
This adds our first nested object: the InstanceInfoCache at Instance.info_cache. Related to blueprint unified-object-model Change-Id: I2dd8727bbe38eadd080e9ea1ef9feabc2fa50520
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_server_start_stop.py2
-rw-r--r--nova/tests/objects/test_instance.py37
-rw-r--r--nova/tests/objects/test_instance_info_cache.py54
3 files changed, 87 insertions, 6 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py b/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py
index 31b832084..05b83131c 100644
--- a/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py
+++ b/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py
@@ -29,6 +29,8 @@ def fake_instance_get(self, context, instance_id):
result['deleted_at'] = None
result['updated_at'] = None
result['deleted'] = 0
+ result['info_cache'] = {'network_info': 'foo',
+ 'instance_uuid': result['uuid']}
return result
diff --git a/nova/tests/objects/test_instance.py b/nova/tests/objects/test_instance.py
index 54e010a8a..a9238a924 100644
--- a/nova/tests/objects/test_instance.py
+++ b/nova/tests/objects/test_instance.py
@@ -18,6 +18,7 @@ import netaddr
from nova import context
from nova import db
+from nova.objects import base
from nova.objects import instance
from nova.openstack.common import timeutils
from nova.tests.api.openstack import fakes
@@ -39,6 +40,7 @@ class _TestInstanceObject(object):
fake_instance['launched_at'].replace(
tzinfo=iso8601.iso8601.Utc(), microsecond=0))
fake_instance['deleted'] = False
+ fake_instance['info_cache']['instance_uuid'] = fake_instance['uuid']
return fake_instance
def test_datetime_deserialization(self):
@@ -90,8 +92,9 @@ class _TestInstanceObject(object):
self.mox.ReplayAll()
inst = instance.Instance.get_by_uuid(ctxt, uuid='uuid')
# Make sure these weren't loaded
- self.assertFalse(hasattr(inst, '_metadata'))
- self.assertFalse(hasattr(inst, '_system_metadata'))
+ for attr in instance.INSTANCE_OPTIONAL_FIELDS:
+ attrname = base.get_attrname(attr)
+ self.assertFalse(hasattr(inst, attrname))
self.assertRemotes()
def test_get_with_expected(self):
@@ -99,12 +102,13 @@ class _TestInstanceObject(object):
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
db.instance_get_by_uuid(
ctxt, 'uuid',
- ['metadata', 'system_metadata']).AndReturn(self.fake_instance)
+ instance.INSTANCE_OPTIONAL_FIELDS).AndReturn(self.fake_instance)
self.mox.ReplayAll()
inst = instance.Instance.get_by_uuid(
- ctxt, 'uuid', expected_attrs=['metadata', 'system_metadata'])
- self.assertTrue(hasattr(inst, '_metadata'))
- self.assertTrue(hasattr(inst, '_system_metadata'))
+ ctxt, 'uuid', expected_attrs=instance.INSTANCE_OPTIONAL_FIELDS)
+ for attr in instance.INSTANCE_OPTIONAL_FIELDS:
+ attrname = base.get_attrname(attr)
+ self.assertTrue(hasattr(inst, attrname))
self.assertRemotes()
def test_load(self):
@@ -166,6 +170,7 @@ class _TestInstanceObject(object):
fake_uuid = fake_inst['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')
db.instance_get_by_uuid(ctxt, fake_uuid, []).AndReturn(fake_inst)
db.instance_update_and_get_original(
ctxt, fake_uuid, {'user_data': 'foo'}).AndReturn(
@@ -187,6 +192,26 @@ class _TestInstanceObject(object):
# NOTE(danms): Make sure it's actually a bool
self.assertEqual(inst.deleted, True)
+ def test_with_info_cache(self):
+ ctxt = context.get_admin_context()
+ fake_inst = dict(self.fake_instance)
+ fake_uuid = fake_inst['uuid']
+ fake_inst['info_cache'] = {'network_info': 'foo',
+ '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')
+ db.instance_get_by_uuid(ctxt, fake_uuid, []).AndReturn(fake_inst)
+ db.instance_info_cache_update(ctxt, fake_uuid,
+ {'network_info': 'bar'})
+ self.mox.ReplayAll()
+ inst = instance.Instance.get_by_uuid(ctxt, fake_uuid)
+ self.assertEqual(inst.info_cache.network_info,
+ fake_inst['info_cache']['network_info'])
+ self.assertEqual(inst.info_cache.instance_uuid, fake_uuid)
+ inst.info_cache.network_info = 'bar'
+ inst.save()
+
class TestInstanceObject(test_objects._LocalTest,
_TestInstanceObject):
diff --git a/nova/tests/objects/test_instance_info_cache.py b/nova/tests/objects/test_instance_info_cache.py
new file mode 100644
index 000000000..74362d178
--- /dev/null
+++ b/nova/tests/objects/test_instance_info_cache.py
@@ -0,0 +1,54 @@
+# Copyright 2013 IBM Corp.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from nova import context
+from nova import db
+from nova.objects import instance_info_cache
+from nova.tests.objects import test_objects
+
+
+class _TestInstanceInfoCacheObject(object):
+ def test_get_by_instance_uuid(self):
+ ctxt = context.get_admin_context()
+ self.mox.StubOutWithMock(db, 'instance_info_cache_get')
+ db.instance_info_cache_get(ctxt, 'fake-uuid').AndReturn(
+ {'instance_uuid': 'fake-uuid', 'network_info': 'foo'})
+ self.mox.ReplayAll()
+ obj = instance_info_cache.InstanceInfoCache.get_by_instance_uuid(
+ ctxt, 'fake-uuid')
+ self.assertEqual(obj.instance_uuid, 'fake-uuid')
+ self.assertEqual(obj.network_info, 'foo')
+ self.assertRemotes()
+
+ def test_save(self):
+ ctxt = context.get_admin_context()
+ self.mox.StubOutWithMock(db, 'instance_info_cache_update')
+ db.instance_info_cache_update(ctxt, 'fake-uuid',
+ {'network_info': 'foo'})
+ self.mox.ReplayAll()
+ obj = instance_info_cache.InstanceInfoCache()
+ obj._context = ctxt
+ obj.instance_uuid = 'fake-uuid'
+ obj.network_info = 'foo'
+ obj.save()
+
+
+class TestInstanceInfoCacheObject(test_objects._LocalTest,
+ _TestInstanceInfoCacheObject):
+ pass
+
+
+class TestInstanceInfoCacheObjectRemote(test_objects._RemoteTest,
+ _TestInstanceInfoCacheObject):
+ pass