示例#1
0
 def test_update_nw_info_none(self):
     self.impl._get_instance_nw_info(self.context, self.instance)\
              .AndReturn(self.nw_info)
     self.expect_cache_update(self.is_nw_info)
     self.mox.ReplayAll()
     api.update_instance_cache_with_nw_info(self.impl, self.context,
                                            self.instance, None)
示例#2
0
 def test_update_nw_info_none(self):
     self.impl._get_instance_nw_info(self.context, self.instance)\
              .AndReturn(self.nw_info)
     self.expect_cache_update(self.is_nw_info)
     self.mox.ReplayAll()
     api.update_instance_cache_with_nw_info(self.impl, self.context,
                                            self.instance, None)
示例#3
0
    def _update_instance_nw_cache(self, instance, context):
        """
        This method will update the network cache for the instance by gathering
        data from neutron. This method should be only called when the network
        cache is empty for the instance
        :param instance: The instance object passed from the DB
        :param context: The context object
        :return nw_info: This contains the network
        """
        LOG.info(_("The network cache for this instance with uuid: %(uuid)s "
                   "is empty. Will update the information "
                   "from neutron") % {'uuid': instance['uuid']})
        nw_info = network_model.NetworkInfo()
        search_opts = {'tenant_id': instance['project_id'],
                       'device_id': instance['uuid']}
        client = neutron.get_client(context, admin=True)
        data = client.list_ports(**search_opts)
        ports = data.get('ports', [])

        networks = self._get_available_networks(context,
                                                instance['project_id'])
        for port in ports:
            network_IPs = self._nw_info_get_ips(client, port)
            subnets = self._nw_info_get_subnets(context, port, network_IPs)

            devname = "tap" + port['id']
            devname = devname[:network_model.NIC_NAME_LEN]

            network, ovs_interfaceid = self._nw_info_build_network(port,
                                                                   networks,
                                                                   subnets)

            nw_info.append(network_model.VIF(id=port['id'],
                                             address=port['mac_address'],
                                             network=network,
                                             type=port.get('binding:vif_type'),
                                             ovs_interfaceid=ovs_interfaceid,
                                             devname=devname))

            nova_net.update_instance_cache_with_nw_info(self, context,
                                                        instance, nw_info)
        return nw_info
示例#4
0
 def test_update_nw_info_empty_list(self):
     self.expect_cache_update({'network_info': '[]'})
     self.mox.ReplayAll()
     api.update_instance_cache_with_nw_info(self.impl, self.context,
                                            self.instance, NetworkInfo([]))
示例#5
0
 def test_update_nw_info_one_network(self):
     self.expect_cache_update(self.is_nw_info)
     self.mox.ReplayAll()
     api.update_instance_cache_with_nw_info(self.impl, self.context,
                                            self.instance, self.nw_info)
示例#6
0
 def test_update_nw_info_empty_list(self):
     self.expect_cache_update({'network_info': '[]'})
     self.mox.ReplayAll()
     api.update_instance_cache_with_nw_info(self.impl, self.context,
                                            self.instance,
                                            network_model.NetworkInfo([]))
示例#7
0
 def test_update_nw_info_one_network(self):
     self.expect_cache_update(self.is_nw_info)
     self.mox.ReplayAll()
     api.update_instance_cache_with_nw_info(self.impl, self.context,
                                            self.instance, self.nw_info)