# Path: os_vif/internal/ip/api.py
# LOG = logging.getLogger(__name__)
# 
# Path: vif_plug_ovs/exception.py
# class AgentError(osv_exception.ExceptionBase):
# class MissingPortProfile(osv_exception.ExceptionBase):
# class WrongPortProfile(osv_exception.ExceptionBase):
# class RepresentorNotFound(osv_exception.ExceptionBase):
# class PciDeviceNotFoundById(osv_exception.ExceptionBase):
# 
# Path: vif_plug_ovs/linux_net.py
# LOG = logging.getLogger(__name__)
# VIRTFN_RE = re.compile(r"virtfn(\d+)")
# INT_RE = re.compile(r"^(\d+)$")
# VF_RE = re.compile(r"vf(\d+)", re.IGNORECASE)
# PF_RE = re.compile(r"pf(\d+)", re.IGNORECASE)
# PF_FUNC_RE = re.compile(r"\.(\d+)", 0)
# UPLINK_PORT_RE = re.compile(r"p(\d+)", re.IGNORECASE)
# _SRIOV_TOTALVFS = "sriov_totalvfs"
# NIC_NAME_LEN = 14
# def _update_device_mtu(dev, mtu):
# def delete_net_dev(dev):
# def create_veth_pair(dev1_name, dev2_name, mtu):
# def update_veth_pair(dev1_name, dev2_name, mtu):
# def _disable_ipv6(bridge):
# def _arp_filtering(bridge):
# def ensure_bridge(bridge):
# def delete_bridge(bridge, dev):
# def add_bridge_port(bridge, dev):
# def set_device_mtu(dev, mtu):
# def set_interface_state(interface_name, port_state):
# def _parse_vf_number(phys_port_name):
# def _parse_pf_number(phys_port_name):
# def get_function_by_ifname(ifname):
# def _get_pf_func(pf_ifname):
# def get_representor_port(pf_ifname, vf_num):
# def _get_sysfs_netdev_path(pci_addr, pf_interface):
# def _is_switchdev(netdev):
# def get_ifname_by_pci_address(pci_addr, pf_interface=False, switchdev=False):
# def get_vf_num_by_pci_address(pci_addr):
# def get_dpdk_representor_port_name(port_id):
# def get_pf_pci_from_vf(vf_pci):
# def _get_phys_port_name(ifname):
# def _get_phys_switch_id(ifname):
# 
# Path: vif_plug_ovs/privsep.py



import glob
import os.path
import testtools
from unittest import mock
from os_vif.internal.ip.api import ip as ip_lib
from vif_plug_ovs import exception
from vif_plug_ovs import linux_net
from vif_plug_ovs import privsep
    @mock.patch.object(linux_net, "_get_phys_switch_id")
    def test_get_representor_port_2_pfs(
            self, mock__get_phys_switch_id, mock__get_phys_port_name,
            mock__get_pf_func, mock_listdir):
        mock_listdir.return_value = [
            'pf_ifname1', 'pf_ifname2', 'rep_pf1_vf_1', 'rep_pf1_vf_2',
            'rep_pf2_vf_1', 'rep_pf2_vf_2',
        ]
        mock__get_phys_switch_id.return_value = 'pf_sw_id'
        mock__get_pf_func.return_value = "2"
        mock__get_phys_port_name.side_effect = (
            ["p1", "p2", "VF1@PF1", "pf2vf1", "vf2@pf1", "pf2vf2"])
        ifname = linux_net.get_representor_port('pf_ifname2', '2')
        self.assertEqual('rep_pf2_vf_2', ifname)

    @mock.patch.object(os, 'listdir')
    @mock.patch.object(linux_net, "_get_pf_func")
    @mock.patch.object(linux_net, "_get_phys_switch_id")
    @mock.patch.object(linux_net, "_get_phys_port_name")
    def test_get_representor_port_not_found(
            self, mock__get_phys_port_name, mock__get_phys_switch_id,
            mock__get_pf_func, mock_listdir):
        mock_listdir.return_value = [
            'pf_ifname', 'rep_vf_1', 'rep_vf_2'
        ]
        mock__get_phys_switch_id.return_value = 'pf_sw_id'
        mock__get_pf_func.return_value = "0"
        mock__get_phys_port_name.side_effect = (
            ["p0", "1", "2"])
        self.assertRaises(

# Path: os_vif/internal/ip/api.py
# LOG = logging.getLogger(__name__)
# 
# Path: vif_plug_ovs/exception.py
# class AgentError(osv_exception.ExceptionBase):
# class MissingPortProfile(osv_exception.ExceptionBase):
# class WrongPortProfile(osv_exception.ExceptionBase):
# class RepresentorNotFound(osv_exception.ExceptionBase):
# class PciDeviceNotFoundById(osv_exception.ExceptionBase):
# 
# Path: vif_plug_ovs/linux_net.py
# LOG = logging.getLogger(__name__)
# VIRTFN_RE = re.compile(r"virtfn(\d+)")
# INT_RE = re.compile(r"^(\d+)$")
# VF_RE = re.compile(r"vf(\d+)", re.IGNORECASE)
# PF_RE = re.compile(r"pf(\d+)", re.IGNORECASE)
# PF_FUNC_RE = re.compile(r"\.(\d+)", 0)
# UPLINK_PORT_RE = re.compile(r"p(\d+)", re.IGNORECASE)
# _SRIOV_TOTALVFS = "sriov_totalvfs"
# NIC_NAME_LEN = 14
# def _update_device_mtu(dev, mtu):
# def delete_net_dev(dev):
# def create_veth_pair(dev1_name, dev2_name, mtu):
# def update_veth_pair(dev1_name, dev2_name, mtu):
# def _disable_ipv6(bridge):
# def _arp_filtering(bridge):
# def ensure_bridge(bridge):
# def delete_bridge(bridge, dev):
# def add_bridge_port(bridge, dev):
# def set_device_mtu(dev, mtu):
# def set_interface_state(interface_name, port_state):
# def _parse_vf_number(phys_port_name):
# def _parse_pf_number(phys_port_name):
# def get_function_by_ifname(ifname):
# def _get_pf_func(pf_ifname):
# def get_representor_port(pf_ifname, vf_num):
# def _get_sysfs_netdev_path(pci_addr, pf_interface):
# def _is_switchdev(netdev):
# def get_ifname_by_pci_address(pci_addr, pf_interface=False, switchdev=False):
# def get_vf_num_by_pci_address(pci_addr):
# def get_dpdk_representor_port_name(port_id):
# def get_pf_pci_from_vf(vf_pci):
# def _get_phys_port_name(ifname):
# def _get_phys_switch_id(ifname):
# 
# Path: vif_plug_ovs/privsep.py



# Path: vif_plug_ovs/tests/unit/test_linux_net.py
import glob
import os.path
import testtools
from unittest import mock
from os_vif.internal.ip.api import ip as ip_lib
from vif_plug_ovs import exception
from vif_plug_ovs import linux_net
from vif_plug_ovs import privsep

    @mock.patch.object(linux_net, "_get_phys_switch_id")
    def test_get_representor_port_2_pfs(
            self, mock__get_phys_switch_id, mock__get_phys_port_name,
            mock__get_pf_func, mock_listdir):
        mock_listdir.return_value = [
            'pf_ifname1', 'pf_ifname2', 'rep_pf1_vf_1', 'rep_pf1_vf_2',
            'rep_pf2_vf_1', 'rep_pf2_vf_2',
        ]
        mock__get_phys_switch_id.return_value = 'pf_sw_id'
        mock__get_pf_func.return_value = "2"
        mock__get_phys_port_name.side_effect = (
            ["p1", "p2", "VF1@PF1", "pf2vf1", "vf2@pf1", "pf2vf2"])
        ifname = linux_net.get_representor_port('pf_ifname2', '2')
        self.assertEqual('rep_pf2_vf_2', ifname)

    @mock.patch.object(os, 'listdir')
    @mock.patch.object(linux_net, "_get_pf_func")
    @mock.patch.object(linux_net, "_get_phys_switch_id")
    @mock.patch.object(linux_net, "_get_phys_port_name")
    def test_get_representor_port_not_found(
            self, mock__get_phys_port_name, mock__get_phys_switch_id,
            mock__get_pf_func, mock_listdir):
        mock_listdir.return_value = [
            'pf_ifname', 'rep_vf_1', 'rep_vf_2'
        ]
        mock__get_phys_switch_id.return_value = 'pf_sw_id'
        mock__get_pf_func.return_value = "0"
        mock__get_phys_port_name.side_effect = (
            ["p0", "1", "2"])
        self.assertRaises(

            exception.RepresentorNotFound,