Merge "Update self with db result in InstanceInfoCache.save"
This commit is contained in:
commit
8a688009c8
|
@ -93,6 +93,7 @@ class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject,
|
|||
rv = db.instance_info_cache_update(self._context,
|
||||
self.instance_uuid,
|
||||
{'network_info': nw_info_json})
|
||||
self._from_db_object(self._context, self, rv)
|
||||
if update_cells and rv:
|
||||
self._info_cache_cells_update(self._context, rv)
|
||||
self.obj_reset_changes()
|
||||
|
|
|
@ -301,7 +301,15 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
|
|||
return ips
|
||||
|
||||
def update_cache_fake(*args, **kwargs):
|
||||
pass
|
||||
fake_info_cache = {
|
||||
'created_at': None,
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'deleted': False,
|
||||
'instance_uuid': 'fake-uuid',
|
||||
'network_info': '[]',
|
||||
}
|
||||
return fake_info_cache
|
||||
|
||||
stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake)
|
||||
stubs.Set(db, 'instance_info_cache_update', update_cache_fake)
|
||||
|
|
|
@ -44,6 +44,15 @@ from nova import utils
|
|||
|
||||
FAKE_UUID = 'a47ae74e-ab08-547f-9eee-ffd23fc46c16'
|
||||
|
||||
fake_info_cache = {
|
||||
'created_at': None,
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'deleted': False,
|
||||
'instance_uuid': 'fake-uuid',
|
||||
'network_info': '[]',
|
||||
}
|
||||
|
||||
|
||||
class NetworkPolicyTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -215,6 +224,7 @@ class ApiTestCase(test.TestCase):
|
|||
def fake_instance_info_cache_update(context, instance_uuid, cache):
|
||||
self.assertEqual(instance_uuid,
|
||||
expected_updated_instances.pop())
|
||||
return fake_info_cache
|
||||
|
||||
self.stubs.Set(self.network_api.db, 'instance_info_cache_update',
|
||||
fake_instance_info_cache_update)
|
||||
|
@ -447,8 +457,9 @@ class ApiTestCase(test.TestCase):
|
|||
mock.patch.object(self.network_api.network_rpcapi,
|
||||
'get_instance_nw_info'),
|
||||
mock.patch.object(network_model.NetworkInfo, 'hydrate'),
|
||||
mock.patch.object(objects.InstanceInfoCache, 'save'),
|
||||
) as (
|
||||
method_mock, nwinfo_mock, hydrate_mock
|
||||
method_mock, nwinfo_mock, hydrate_mock, save_mock
|
||||
):
|
||||
nw_info = network_model.NetworkInfo([])
|
||||
method_mock.return_value = nw_info
|
||||
|
@ -539,7 +550,7 @@ class ApiTestCase(test.TestCase):
|
|||
|
||||
|
||||
@mock.patch('nova.network.api.API')
|
||||
@mock.patch('nova.db.instance_info_cache_update')
|
||||
@mock.patch('nova.db.instance_info_cache_update', return_value=fake_info_cache)
|
||||
class TestUpdateInstanceCache(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
super(TestUpdateInstanceCache, self).setUp()
|
||||
|
|
|
@ -50,6 +50,15 @@ CONF = cfg.CONF
|
|||
# exception class instead.
|
||||
NEUTRON_CLIENT_EXCEPTION = Exception
|
||||
|
||||
fake_info_cache = {
|
||||
'created_at': None,
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'deleted': False,
|
||||
'instance_uuid': 'fake-uuid',
|
||||
'network_info': '[]',
|
||||
}
|
||||
|
||||
|
||||
class MyComparator(mox.Comparator):
|
||||
def __init__(self, lhs):
|
||||
|
@ -570,7 +579,8 @@ class TestNeutronv2Base(test.TestCase):
|
|||
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
|
||||
api.db.instance_info_cache_update(mox.IgnoreArg(),
|
||||
self.instance['uuid'],
|
||||
mox.IgnoreArg())
|
||||
mox.IgnoreArg()).AndReturn(
|
||||
fake_info_cache)
|
||||
port_data = number == 1 and self.port_data1 or self.port_data2
|
||||
nets = number == 1 and self.nets1 or self.nets2
|
||||
net_info_cache = []
|
||||
|
@ -726,7 +736,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
|
||||
api.db.instance_info_cache_update(
|
||||
mox.IgnoreArg(),
|
||||
self.instance['uuid'], mox.IgnoreArg())
|
||||
self.instance['uuid'], mox.IgnoreArg()).AndReturn(fake_info_cache)
|
||||
neutronapi.get_client(mox.IgnoreArg(),
|
||||
admin=True).MultipleTimes().AndReturn(
|
||||
self.moxed_client)
|
||||
|
@ -802,7 +812,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
|
||||
api.db.instance_info_cache_update(
|
||||
mox.IgnoreArg(),
|
||||
self.instance['uuid'], mox.IgnoreArg())
|
||||
self.instance['uuid'], mox.IgnoreArg()).AndReturn(fake_info_cache)
|
||||
self.moxed_client.list_ports(
|
||||
tenant_id=self.instance['project_id'],
|
||||
device_id=self.instance['uuid']).AndReturn(
|
||||
|
@ -1298,7 +1308,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
|
||||
api.db.instance_info_cache_update(self.context,
|
||||
self.instance.uuid,
|
||||
{'network_info': '[]'})
|
||||
{'network_info': '[]'}).AndReturn(
|
||||
fake_info_cache)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
api = neutronapi.API()
|
||||
|
@ -2209,7 +2220,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
AndReturn(nw_info)
|
||||
api.db.instance_info_cache_update(mox.IgnoreArg(),
|
||||
instance['uuid'],
|
||||
mox.IgnoreArg())
|
||||
mox.IgnoreArg()).AndReturn(
|
||||
fake_info_cache)
|
||||
|
||||
def test_associate_floating_ip(self):
|
||||
api = neutronapi.API()
|
||||
|
|
|
@ -542,8 +542,9 @@ class _TestInstanceObject(object):
|
|||
nwinfo2 = network_model.NetworkInfo.hydrate([{'address': 'bar'}])
|
||||
nwinfo1_json = nwinfo1.json()
|
||||
nwinfo2_json = nwinfo2.json()
|
||||
fake_info_cache = test_instance_info_cache.fake_info_cache
|
||||
fake_inst['info_cache'] = dict(
|
||||
test_instance_info_cache.fake_info_cache,
|
||||
fake_info_cache,
|
||||
network_info=nwinfo1_json,
|
||||
instance_uuid=fake_uuid)
|
||||
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
|
||||
|
@ -555,7 +556,7 @@ class _TestInstanceObject(object):
|
|||
use_slave=False
|
||||
).AndReturn(fake_inst)
|
||||
db.instance_info_cache_update(self.context, fake_uuid,
|
||||
{'network_info': nwinfo2_json})
|
||||
{'network_info': nwinfo2_json}).AndReturn(fake_info_cache)
|
||||
self.mox.ReplayAll()
|
||||
inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
|
||||
self.assertEqual(inst.info_cache.network_info, nwinfo1)
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
|
||||
import mock
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova.cells import opts as cells_opts
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova import db
|
||||
|
@ -72,9 +77,11 @@ class _TestInstanceInfoCacheObject(object):
|
|||
self.mox.StubOutWithMock(cells_api,
|
||||
'instance_info_cache_update_at_top')
|
||||
nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
|
||||
new_info_cache = fake_info_cache.copy()
|
||||
new_info_cache['network_info'] = nwinfo.json()
|
||||
db.instance_info_cache_update(
|
||||
self.context, 'fake-uuid',
|
||||
{'network_info': nwinfo.json()}).AndReturn('foo')
|
||||
{'network_info': nwinfo.json()}).AndReturn(new_info_cache)
|
||||
if update_cells:
|
||||
cells_opts.get_cell_type().AndReturn(cell_type)
|
||||
if cell_type == 'compute':
|
||||
|
@ -96,6 +103,25 @@ class _TestInstanceInfoCacheObject(object):
|
|||
def test_save_without_update_cells(self):
|
||||
self._save_helper(None, False)
|
||||
|
||||
@mock.patch.object(db, 'instance_info_cache_update')
|
||||
def test_save_updates_self(self, mock_update):
|
||||
fake_updated_at = datetime.datetime(2015, 1, 1)
|
||||
nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
|
||||
nwinfo_json = nwinfo.json()
|
||||
new_info_cache = fake_info_cache.copy()
|
||||
new_info_cache['id'] = 1
|
||||
new_info_cache['updated_at'] = fake_updated_at
|
||||
new_info_cache['network_info'] = nwinfo_json
|
||||
mock_update.return_value = new_info_cache
|
||||
obj = instance_info_cache.InstanceInfoCache(context=self.context)
|
||||
obj.instance_uuid = 'fake-uuid'
|
||||
obj.network_info = nwinfo_json
|
||||
obj.save()
|
||||
mock_update.assert_called_once_with(self.context, 'fake-uuid',
|
||||
{'network_info': nwinfo_json})
|
||||
self.assertEqual(timeutils.normalize_time(fake_updated_at),
|
||||
timeutils.normalize_time(obj.updated_at))
|
||||
|
||||
def test_refresh(self):
|
||||
obj = instance_info_cache.InstanceInfoCache.new(self.context,
|
||||
'fake-uuid1')
|
||||
|
|
Loading…
Reference in New Issue