Esempio n. 1
0
    def _save_helper(self, cell_type, update_cells):
        obj = instance_info_cache.InstanceInfoCache()
        cells_api = cells_rpcapi.CellsAPI()

        self.mox.StubOutWithMock(db, 'instance_info_cache_update')
        self.mox.StubOutWithMock(cells_opts, 'get_cell_type')
        self.mox.StubOutWithMock(cells_rpcapi, 'CellsAPI',
                                 use_mock_anything=True)
        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(new_info_cache)
        if update_cells:
            cells_opts.get_cell_type().AndReturn(cell_type)
            if cell_type == 'compute':
                cells_rpcapi.CellsAPI().AndReturn(cells_api)
                cells_api.instance_info_cache_update_at_top(
                    self.context, 'foo')
        self.mox.ReplayAll()
        obj._context = self.context
        obj.instance_uuid = 'fake-uuid'
        obj.network_info = nwinfo
        obj.save(update_cells=update_cells)
Esempio n. 2
0
 def test_instance_info_cache_update(self):
     fake_values = {"key1": "val1", "key2": "val2"}
     fake_instance = {"uuid": "fake-uuid"}
     self.mox.StubOutWithMock(db, "instance_info_cache_update")
     db.instance_info_cache_update(self.context, "fake-uuid", fake_values)
     self.mox.ReplayAll()
     self.conductor.instance_info_cache_update(self.context, fake_instance, fake_values)
Esempio n. 3
0
 def test_with_info_cache(self):
     ctxt = context.get_admin_context()
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst['uuid']
     nwinfo1 = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
     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
     }
     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,
                             columns_to_join=[]).AndReturn(fake_inst)
     db.instance_info_cache_update(ctxt, fake_uuid,
                                   {'network_info': nwinfo2_json})
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(ctxt, fake_uuid)
     self.assertEqual(inst.info_cache.network_info, nwinfo1)
     self.assertEqual(inst.info_cache.instance_uuid, fake_uuid)
     inst.info_cache.network_info = nwinfo2
     inst.save()
Esempio n. 4
0
 def test_with_info_cache(self):
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst['uuid']
     nwinfo1 = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
     nwinfo2 = network_model.NetworkInfo.hydrate([{'address': 'bar'}])
     nwinfo1_json = nwinfo1.json()
     nwinfo2_json = nwinfo2.json()
     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')
     db.instance_get_by_uuid(self.context, fake_uuid,
                             columns_to_join=['info_cache',
                                              'security_groups'],
                             use_slave=False
                             ).AndReturn(fake_inst)
     db.instance_info_cache_update(self.context, fake_uuid,
                                   {'network_info': nwinfo2_json})
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
     self.assertEqual(inst.info_cache.network_info, nwinfo1)
     self.assertEqual(inst.info_cache.instance_uuid, fake_uuid)
     inst.info_cache.network_info = nwinfo2
     inst.save()
    def _save_helper(self, cell_type, update_cells):
        obj = instance_info_cache.InstanceInfoCache()
        cells_api = cells_rpcapi.CellsAPI()

        self.mox.StubOutWithMock(db, 'instance_info_cache_update')
        self.mox.StubOutWithMock(cells_opts, 'get_cell_type')
        self.mox.StubOutWithMock(cells_rpcapi,
                                 'CellsAPI',
                                 use_mock_anything=True)
        self.mox.StubOutWithMock(cells_api,
                                 'instance_info_cache_update_at_top')
        nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
        db.instance_info_cache_update(self.context, 'fake-uuid', {
            'network_info': nwinfo.json()
        }).AndReturn('foo')
        if update_cells:
            cells_opts.get_cell_type().AndReturn(cell_type)
            if cell_type == 'compute':
                cells_rpcapi.CellsAPI().AndReturn(cells_api)
                cells_api.instance_info_cache_update_at_top(
                    self.context, 'foo')
        self.mox.ReplayAll()
        obj._context = self.context
        obj.instance_uuid = 'fake-uuid'
        obj.network_info = nwinfo
        obj.save(update_cells=update_cells)
 def test_with_info_cache(self):
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst['uuid']
     nwinfo1 = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
     nwinfo2 = network_model.NetworkInfo.hydrate([{'address': 'bar'}])
     nwinfo1_json = nwinfo1.json()
     nwinfo2_json = nwinfo2.json()
     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')
     db.instance_get_by_uuid(
         self.context,
         fake_uuid,
         columns_to_join=['info_cache', 'security_groups'],
         use_slave=False).AndReturn(fake_inst)
     db.instance_info_cache_update(self.context, fake_uuid,
                                   {'network_info': nwinfo2_json})
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
     self.assertEqual(inst.info_cache.network_info, nwinfo1)
     self.assertEqual(inst.info_cache.instance_uuid, fake_uuid)
     inst.info_cache.network_info = nwinfo2
     inst.save()
Esempio n. 7
0
 def test_instance_info_cache_update(self):
     fake_values = {'key1': 'val1', 'key2': 'val2'}
     fake_instance = {'uuid': 'fake-uuid'}
     self.mox.StubOutWithMock(db, 'instance_info_cache_update')
     db.instance_info_cache_update(self.context, 'fake-uuid', fake_values)
     self.mox.ReplayAll()
     self.conductor.instance_info_cache_update(self.context, fake_instance,
                                               fake_values)
Esempio n. 8
0
def _create_instances_with_cached_ips(orig_func, *args, **kwargs):
    """Kludge the above kludge so that the database doesn't get out
    of sync with the actual instance.
    """
    instances, reservation_id = orig_func(*args, **kwargs)
    fake_cache = _get_fake_cache()
    for instance in instances:
        instance["info_cache"]["network_info"] = fake_cache
        db.instance_info_cache_update(args[1], instance["uuid"], {"network_info": fake_cache})
    return (instances, reservation_id)
Esempio n. 9
0
 def test_instance_info_cache_update(self):
     fake_values = {'key1': 'val1', 'key2': 'val2'}
     fake_instance = {'uuid': 'fake-uuid'}
     self.mox.StubOutWithMock(db, 'instance_info_cache_update')
     db.instance_info_cache_update(self.context, 'fake-uuid',
                                   fake_values)
     self.mox.ReplayAll()
     self.conductor.instance_info_cache_update(self.context,
                                               fake_instance,
                                               fake_values)
Esempio n. 10
0
def _create_instances_with_cached_ips(orig_func, *args, **kwargs):
    """Kludge the above kludge so that the database doesn't get out
    of sync with the actual instance.
    """
    instances, reservation_id = orig_func(*args, **kwargs)
    fake_cache = _get_fake_cache()
    for instance in instances:
        instance['info_cache']['network_info'] = fake_cache
        db.instance_info_cache_update(args[1], instance['uuid'],
                                      {'network_info': fake_cache})
    return (instances, reservation_id)
 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()
Esempio n. 12
0
 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()
Esempio n. 13
0
 def save(self, context, update_cells=True):
     if 'network_info' in self.obj_what_changed():
         nw_info_json = self._attr_network_info_to_primitive()
         rv = db.instance_info_cache_update(context, self.instance_uuid,
                                            {'network_info': nw_info_json})
         if update_cells and rv:
             self._info_cache_cells_update(context, rv)
     self.obj_reset_changes()
Esempio n. 14
0
 def save(self, context, update_cells=True):
     if 'network_info' in self.obj_what_changed():
         nw_info_json = self._attr_network_info_to_primitive()
         rv = db.instance_info_cache_update(context, self.instance_uuid,
                                            {'network_info': nw_info_json})
         if update_cells and rv:
             self._info_cache_cells_update(context, rv)
     self.obj_reset_changes()
Esempio n. 15
0
 def save(self, update_cells=True):
     if "network_info" in self.obj_what_changed():
         nw_info_json = self.fields["network_info"].to_primitive(self, "network_info", self.network_info)
         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()
Esempio n. 16
0
    def get_instance_nw_info(self, context, instance_id, instance_uuid,
                                            instance_type_id, host):
        """This method is used by compute to fetch all network data
           that should be used when creating the VM.

           The method simply loops through all virtual interfaces
           stored in the nova DB and queries the IPAM lib to get
           the associated IP data.

           The format of returned data is 'defined' by the initial
           set of NetworkManagers found in nova/network/manager.py .
           Ideally this 'interface' will be more formally defined
           in the future.
        """
        admin_context = context.elevated()
        project_id = context.project_id
        vifs = db.virtual_interface_get_by_instance(context, instance_id)
        instance_type = instance_types.get_instance_type(instance_type_id)

        net_tenant_dict = dict((net_id, tenant_id)
                               for (net_id, tenant_id)
                               in self.ipam.get_project_and_global_net_ids(
                                                          context, project_id))
        networks = {}
        for vif in vifs:
            if vif.get('network_id') is not None:
                network = db.network_get(admin_context, vif['network_id'])
                net_tenant_id = net_tenant_dict[network['uuid']]
                if net_tenant_id is None:
                    net_tenant_id = FLAGS.quantum_default_tenant_id
                network = {'id': network['id'],
                           'uuid': network['uuid'],
                           'bridge': 'ovs_flag',
                           'label': self.q_conn.get_network_name(net_tenant_id,
                                                              network['uuid']),
                           'project_id': net_tenant_id}
                networks[vif['uuid']] = network

        # update instance network cache and return network_info
        nw_info = self.build_network_info_model(context, vifs, networks,
                                                     instance_type, host)
        db.instance_info_cache_update(context, instance_uuid,
                                      {'network_info': nw_info.as_cache()})

        return nw_info
Esempio n. 17
0
    def get_instance_nw_info(self, context, instance_id, instance_uuid,
                             rxtx_factor, host, **kwargs):
        """This method is used by compute to fetch all network data
           that should be used when creating the VM.

           The method simply loops through all virtual interfaces
           stored in the nova DB and queries the IPAM lib to get
           the associated IP data.

           The format of returned data is 'defined' by the initial
           set of NetworkManagers found in nova/network/manager.py .
           Ideally this 'interface' will be more formally defined
           in the future.
        """
        project_id = kwargs['project_id']
        vifs = db.virtual_interface_get_by_instance(context, instance_id)

        net_tenant_dict = dict(
            (net_id, tenant_id) for (net_id, tenant_id) in
            self.ipam.get_project_and_global_net_ids(context, project_id))
        networks = {}
        for vif in vifs:
            if vif.get('network_id') is not None:
                network = db.network_get(context.elevated(), vif['network_id'])
                net_tenant_id = net_tenant_dict[network['uuid']]
                if net_tenant_id is None:
                    net_tenant_id = FLAGS.quantum_default_tenant_id
                network = {
                    'id': network['id'],
                    'uuid': network['uuid'],
                    'bridge': '',  # Quantum ignores this field
                    'label': network['label'],
                    'injected': FLAGS.flat_injected,
                    'project_id': net_tenant_id
                }
                networks[vif['uuid']] = network

        # update instance network cache and return network_info
        nw_info = self.build_network_info_model(context, vifs, networks,
                                                rxtx_factor, host)
        db.instance_info_cache_update(context, instance_uuid,
                                      {'network_info': nw_info.as_cache()})

        return nw_info
Esempio n. 18
0
 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()
Esempio n. 19
0
    def _save_helper(self, cell_type, update_cells):
        obj = instance_info_cache.InstanceInfoCache()
        cells_api = cells_rpcapi.CellsAPI()

        self.mox.StubOutWithMock(db, "instance_info_cache_update")
        self.mox.StubOutWithMock(cells_opts, "get_cell_type")
        self.mox.StubOutWithMock(cells_rpcapi, "CellsAPI", use_mock_anything=True)
        self.mox.StubOutWithMock(cells_api, "instance_info_cache_update_at_top")
        nwinfo = network_model.NetworkInfo.hydrate([{"address": "foo"}])
        db.instance_info_cache_update(self.context, "fake-uuid", {"network_info": nwinfo.json()}).AndReturn("foo")
        if update_cells:
            cells_opts.get_cell_type().AndReturn(cell_type)
            if cell_type == "compute":
                cells_rpcapi.CellsAPI().AndReturn(cells_api)
                cells_api.instance_info_cache_update_at_top(self.context, "foo")
        self.mox.ReplayAll()
        obj._context = self.context
        obj.instance_uuid = "fake-uuid"
        obj.network_info = nwinfo
        obj.save(update_cells=update_cells)
Esempio n. 20
0
 def test_with_info_cache(self):
     ctxt = context.get_admin_context()
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst["uuid"]
     nwinfo1 = network_model.NetworkInfo.hydrate([{"address": "foo"}])
     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}
     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, columns_to_join=[]).AndReturn(fake_inst)
     db.instance_info_cache_update(ctxt, fake_uuid, {"network_info": nwinfo2_json})
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(ctxt, fake_uuid)
     self.assertEqual(inst.info_cache.network_info, nwinfo1)
     self.assertEqual(inst.info_cache.instance_uuid, fake_uuid)
     inst.info_cache.network_info = nwinfo2
     inst.save()
Esempio n. 21
0
 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()
Esempio n. 22
0
 def save(self, update_cells=True):
     if 'network_info' in self.obj_what_changed():
         nw_info_json = self.fields['network_info'].to_primitive(
             self, 'network_info', self.network_info)
         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()
Esempio n. 23
0
    def get_instance_nw_info(self, context, instance_id, instance_uuid, rxtx_factor, host):
        """This method is used by compute to fetch all network data
           that should be used when creating the VM.

           The method simply loops through all virtual interfaces
           stored in the nova DB and queries the IPAM lib to get
           the associated IP data.

           The format of returned data is 'defined' by the initial
           set of NetworkManagers found in nova/network/manager.py .
           Ideally this 'interface' will be more formally defined
           in the future.
        """
        admin_context = context.elevated()
        project_id = context.project_id
        vifs = db.virtual_interface_get_by_instance(context, instance_id)

        net_tenant_dict = dict(
            (net_id, tenant_id) for (net_id, tenant_id) in self.ipam.get_project_and_global_net_ids(context, project_id)
        )
        networks = {}
        for vif in vifs:
            if vif.get("network_id") is not None:
                network = db.network_get(admin_context, vif["network_id"])
                net_tenant_id = net_tenant_dict[network["uuid"]]
                if net_tenant_id is None:
                    net_tenant_id = FLAGS.quantum_default_tenant_id
                network = {
                    "id": network["id"],
                    "uuid": network["uuid"],
                    "bridge": "",  # Quantum ignores this field
                    "label": network["label"],
                    "project_id": net_tenant_id,
                }
                networks[vif["uuid"]] = network

        # update instance network cache and return network_info
        nw_info = self.build_network_info_model(context, vifs, networks, rxtx_factor, host)
        db.instance_info_cache_update(context, instance_uuid, {"network_info": nw_info.as_cache()})

        return nw_info
Esempio n. 24
0
 def save(self, update_cells=True):
     if "network_info" in self.obj_what_changed():
         if update_cells:
             stale_instance = self.obj_clone()
         nw_info_json = self.fields["network_info"].to_primitive(self, "network_info", self.network_info)
         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:
             # Send a copy of ourselves before updates are applied so
             # that cells can tell what changed.
             self._info_cache_cells_update(self._context, stale_instance)
     self.obj_reset_changes()
Esempio n. 25
0
 def test_with_info_cache(self):
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst["uuid"]
     nwinfo1 = network_model.NetworkInfo.hydrate([{"address": "foo"}])
     nwinfo2 = network_model.NetworkInfo.hydrate([{"address": "bar"}])
     nwinfo1_json = nwinfo1.json()
     nwinfo2_json = nwinfo2.json()
     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")
     db.instance_get_by_uuid(
         self.context, fake_uuid, columns_to_join=["info_cache", "security_groups"], use_slave=False
     ).AndReturn(fake_inst)
     db.instance_info_cache_update(self.context, fake_uuid, {"network_info": nwinfo2_json})
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
     self.assertEqual(inst.info_cache.network_info, nwinfo1)
     self.assertEqual(inst.info_cache.instance_uuid, fake_uuid)
     inst.info_cache.network_info = nwinfo2
     inst.save()
Esempio n. 26
0
 def test_with_info_cache(self):
     ctxt = context.get_admin_context()
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst['uuid']
     nwinfo1 = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
     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}
     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, columns_to_join=[]
                             ).AndReturn(fake_inst)
     db.instance_info_cache_update(ctxt, fake_uuid,
                                   {'network_info': nwinfo2_json})
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(ctxt, fake_uuid)
     self.assertEqual(inst.info_cache.network_info, nwinfo1)
     self.assertEqual(inst.info_cache.instance_uuid, fake_uuid)
     inst.info_cache.network_info = nwinfo2
     inst.save()
 def save(self, update_cells=True):
     if 'network_info' in self.obj_what_changed():
         if update_cells:
             stale_instance = self.obj_clone()
         nw_info_json = self.fields['network_info'].to_primitive(
             self, 'network_info', self.network_info)
         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:
             # Send a copy of ourselves before updates are applied so
             # that cells can tell what changed.
             self._info_cache_cells_update(self._context, stale_instance)
     self.obj_reset_changes()
Esempio n. 28
0
 def expect_cache_update(self, nw_info):
     self.mox.StubOutWithMock(db, 'instance_info_cache_update')
     db.instance_info_cache_update(self.context,
                                   self.instance['uuid'],
                                   nw_info)
Esempio n. 29
0
 def save(self, context):
     if 'network_info' in self.obj_what_changed():
         db.instance_info_cache_update(context, self.instance_uuid,
                                       {'network_info': self.network_info})
         self.obj_reset_changes()
Esempio n. 30
0
 def expect_cache_update(self, nw_info):
     self.mox.StubOutWithMock(db, 'instance_info_cache_update')
     db.instance_info_cache_update(self.context, self.instance['uuid'],
                                   nw_info)
Esempio n. 31
0
 def save(self, context):
     if 'network_info' in self.obj_what_changed():
         db.instance_info_cache_update(context, self.instance_uuid,
                                       {'network_info': self.network_info})
         self.obj_reset_changes()