def test_neutron_to_osvif_vif(self, m_mgrs): vif_plugin = mock.sentinel.vif_plugin port = mock.sentinel.port subnets = mock.sentinel.subnets m_mgr = mock.Mock() m_mgrs.__getitem__.return_value = m_mgr ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) m_mgrs.__getitem__.assert_called_with(vif_plugin) m_mgr.driver.assert_called_with(vif_plugin, port, subnets)
def _recover_precreated_ports(self): if config.CONF.kubernetes.port_debug: available_ports = self._get_ports_by_attrs( name=constants.KURYR_PORT_NAME, device_owner=[kl_const.DEVICE_OWNER]) else: kuryr_ports = self._get_ports_by_attrs( device_owner=kl_const.DEVICE_OWNER) in_use_ports = self._get_in_use_ports() available_ports = [ port for port in kuryr_ports if port['id'] not in in_use_ports ] for port in available_ports: subnet_id = port['fixed_ips'][0]['subnet_id'] subnet = {subnet_id: default_subnet._get_subnet(subnet_id)} vif_plugin = self._drv_vif._get_vif_plugin(port) vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnet) net_obj = subnet[subnet_id] pool_key = self._get_pool_key(port['binding:host_id'], port['project_id'], port['security_groups'], net_obj.id, None) self._existing_vifs[port['id']] = vif self._available_ports_pools.setdefault(pool_key, []).append(port['id']) LOG.info("PORTS POOL: pools updated with pre-created ports") self._create_healthcheck_file()
def request_vifs(self, pod, project_id, subnets, security_groups, num_ports): neutron = clients.get_neutron_client() rq = self._get_port_request(pod, project_id, subnets, security_groups, unbound=True) bulk_port_rq = {'ports': [rq] * num_ports} try: ports = neutron.create_port(bulk_port_rq).get('ports') except n_exc.NeutronClientException: LOG.exception("Error creating bulk ports: %s", bulk_port_rq) raise utils.tag_neutron_resources('ports', [port['id'] for port in ports]) vif_plugin = self._get_vif_plugin(ports[0]) # NOTE(ltomasbo): Due to the bug (1696051) on neutron bulk port # creation request returning the port objects without binding # information, an additional port show is performed to get the binding # information if vif_plugin == 'unbound': port_info = neutron.show_port(ports[0]['id']).get('port') vif_plugin = self._get_vif_plugin(port_info) vifs = [] for port in ports: vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) vifs.append(vif) return vifs
def request_vif(self, pod, project_id, subnets, security_groups): pod_name = pod['metadata']['name'] os_net = clients.get_network_client() vif_plugin = 'sriov' subnet_id = next(iter(subnets)) physnet = self._get_physnet_for_subnet_id(subnet_id) LOG.debug("Pod {} handling {}".format(pod_name, physnet)) amount = self._get_remaining_sriov_vfs(pod, physnet) if not amount: LOG.error("SRIOV VIF request failed due to lack of " "available VFs for the current pod creation") return None rq = self._get_port_request(pod, project_id, subnets, security_groups) port = os_net.create_port(**rq) self._check_port_binding([port]) if not self._tag_on_creation: c_utils.tag_neutron_resources([port]) vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) vif.physnet = physnet vif.pod_name = pod_name vif.pod_link = pod['metadata']['selfLink'] LOG.debug("{} vifs are available for the pod {}".format( amount, pod_name)) self._reduce_remaining_sriov_vfs(pod, physnet) return vif
def request_vifs(self, pod, project_id, subnets, security_groups, num_ports): os_net = clients.get_network_client() rq = self._get_port_request(pod, project_id, subnets, security_groups, unbound=True) bulk_port_rq = {'ports': [rq] * num_ports} try: ports = list(os_net.create_ports(bulk_port_rq)) except os_exc.SDKException: LOG.exception("Error creating bulk ports: %s", bulk_port_rq) raise vif_plugin = ports[0].binding_vif_type # NOTE(ltomasbo): Due to the bug (1696051) on neutron bulk port # creation request returning the port objects without binding # information, an additional port show is performed to get the binding # information if vif_plugin == 'unbound': port_info = os_net.get_port(ports[0].id) vif_plugin = port_info.binding_vif_type self._check_port_binding(ports) if not self._tag_on_creation: utils.tag_neutron_resources(ports) vifs = [] for port in ports: vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) vifs.append(vif) return vifs
def request_vifs(self, pod, project_id, subnets, security_groups, num_ports): neutron = clients.get_neutron_client() rq = self._get_port_request(pod, project_id, subnets, security_groups, unbound=True) bulk_port_rq = {'ports': [rq for _ in range(num_ports)]} try: ports = neutron.create_port(bulk_port_rq).get('ports') except n_exc.NeutronClientException as ex: LOG.error("Error creating bulk ports: %s", bulk_port_rq) raise ex vif_plugin = self._get_vif_plugin(ports[0]) # NOTE(ltomasbo): Due to the bug (1696051) on neutron bulk port # creation request returning the port objects without binding # information, an additional (non-bulk) port creation is performed to # get the right vif binding information if vif_plugin == 'unbound': single_port = neutron.create_port(rq).get('port') vif_plugin = self._get_vif_plugin(single_port) ports.append(single_port) vifs = [] for port in ports: vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) vifs.append(vif) return vifs
def test_neutron_to_osvif_vif_load(self, m_mgrs, m_stv_drm): vif_plugin = mock.sentinel.vif_plugin port = mock.sentinel.port subnets = mock.sentinel.subnets m_mgr = mock.Mock() m_mgrs.__getitem__.side_effect = KeyError m_stv_drm.return_value = m_mgr ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) m_stv_drm.assert_called_once_with( namespace=ovu._VIF_TRANSLATOR_NAMESPACE, name=vif_plugin, invoke_on_load=False) m_mgrs.__setitem__.assert_called_once_with(vif_plugin, m_mgr) m_mgr.driver.assert_called_once_with(vif_plugin, port, subnets)
def request_vif(self, pod, project_id, subnets, security_groups): amount = self._get_remaining_sriov_vfs(pod) if not amount: LOG.error("SRIOV VIF request failed due to lack of " "available VFs for the current pod creation") return None pod_name = pod['metadata']['name'] neutron = clients.get_neutron_client() vif_plugin = 'sriov' subnet_id = next(iter(subnets)) physnet = self._get_physnet_for_subnet_id(subnet_id) LOG.debug("Pod {} handling {}".format(pod_name, physnet)) rq = self._get_port_request(pod, project_id, subnets, security_groups) port = neutron.create_port(rq).get('port') c_utils.tag_neutron_resources('ports', [port['id']]) vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) vif.physnet = physnet LOG.debug("{} vifs are available for the pod {}".format( amount, pod_name)) self._reduce_remaining_sriov_vfs(pod) return vif
def request_vif(self, pod, project_id, subnets, security_groups): neutron = clients.get_neutron_client() rq = self._get_port_request(pod, project_id, subnets, security_groups) port = neutron.create_port(rq).get('port') vif_plugin = self._get_vif_plugin(port) return ovu.neutron_to_osvif_vif(vif_plugin, port, subnets)
def request_vif(self, pod, project_id, subnets, security_groups): os_net = clients.get_network_client() rq = self._get_port_request(pod, project_id, subnets, security_groups) port = os_net.create_port(**rq) utils.tag_neutron_resources([port]) return ovu.neutron_to_osvif_vif(port.binding_vif_type, port, subnets)
def request_vif(self, pod, project_id, subnets, security_groups): neutron = clients.get_neutron_client() rq = self._get_port_request(pod, project_id, subnets, security_groups) LOG.error("Request BODY: %s\n", rq) port = neutron.create_port(rq).get('port') utils.tag_neutron_resources('ports', [port['id']]) LOG.error("Port ID: %s\n", port['id']) vif_plugin = self._get_vif_plugin(port) LOG.error("VIF: %s\n", vif_plugin) return ovu.neutron_to_osvif_vif(vif_plugin, port, subnets)
def request_vif(self, pod, project_id, subnets, security_groups): neutron = clients.get_neutron_client() parent_port = self._get_parent_port(neutron, pod) trunk_id = self._get_trunk_id(parent_port) rq = self._get_port_request(pod, project_id, subnets, security_groups) port = neutron.create_port(rq).get('port') vlan_id = self._add_subport(neutron, trunk_id, port['id']) vif_plugin = const.K8S_OS_VIF_NOOP_PLUGIN vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets) vif.vlan_id = vlan_id return vif
def _recover_precreated_ports(self): attrs = {'device_owner': kl_const.DEVICE_OWNER} tags = config.CONF.neutron_defaults.resource_tags if tags: attrs['tags'] = tags if config.CONF.kubernetes.port_debug: attrs['name'] = constants.KURYR_PORT_NAME available_ports = c_utils.get_ports_by_attrs(**attrs) else: kuryr_ports = c_utils.get_ports_by_attrs(**attrs) in_use_ports = self._get_in_use_ports() available_ports = [port for port in kuryr_ports if port['id'] not in in_use_ports] _, available_subports, _ = self._get_trunks_info() for port in available_ports: # NOTE(ltomasbo): ensure subports are not considered for # recovering in the case of multi pools if available_subports.get(port['id']): continue vif_plugin = self._drv_vif._get_vif_plugin(port) port_host = port['binding:host_id'] if not vif_plugin or not port_host: # NOTE(ltomasbo): kuryr-controller is running without the # rights to get the needed information to recover the ports. # Thus, removing the port instead neutron = clients.get_neutron_client() neutron.delete_port(port['id']) continue subnet_id = port['fixed_ips'][0]['subnet_id'] subnet = { subnet_id: utils.get_subnet(subnet_id)} vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnet) net_obj = subnet[subnet_id] pool_key = self._get_pool_key(port_host, port['project_id'], net_obj.id, None) self._existing_vifs[port['id']] = vif self._available_ports_pools.setdefault( pool_key, {}).setdefault( tuple(sorted(port['security_groups'])), []).append( port['id']) LOG.info("PORTS POOL: pools updated with pre-created ports") self._create_healthcheck_file()