# 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
            '0000:00:00.1', pf_interface=True, switchdev=True)
        self.assertEqual(ifname, 'enp2s0f0_0')

    @mock.patch.object(os, 'listdir')
    def test_get_ifname_by_pci_address_exception(self, mock_listdir):
        mock_listdir.side_effect = OSError('No such file or directory')
        self.assertRaises(
            exception.PciDeviceNotFoundById,
            linux_net.get_ifname_by_pci_address,
            '0000:00:00.1'
        )

    @mock.patch.object(os, 'readlink')
    @mock.patch.object(glob, 'iglob')
    def test_vf_number_found(self, mock_iglob, mock_readlink):
        mock_iglob.return_value = [
            '/sys/bus/pci/devices/0000:00:00.1/physfn/virtfn3',
        ]
        mock_readlink.return_value = '../../0000:00:00.1'
        vf_num = linux_net.get_vf_num_by_pci_address('0000:00:00.1')
        self.assertEqual(vf_num, '3')

    @mock.patch.object(os, 'readlink')
    @mock.patch.object(glob, 'iglob')
    def test_vf_number_not_found(self, mock_iglob, mock_readlink):
        mock_iglob.return_value = [
            '/sys/bus/pci/devices/0000:00:00.1/physfn/virtfn3',
        ]
        mock_readlink.return_value = '../../0000:00:00.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

            '0000:00:00.1', pf_interface=True, switchdev=True)
        self.assertEqual(ifname, 'enp2s0f0_0')

    @mock.patch.object(os, 'listdir')
    def test_get_ifname_by_pci_address_exception(self, mock_listdir):
        mock_listdir.side_effect = OSError('No such file or directory')
        self.assertRaises(
            exception.PciDeviceNotFoundById,
            linux_net.get_ifname_by_pci_address,
            '0000:00:00.1'
        )

    @mock.patch.object(os, 'readlink')
    @mock.patch.object(glob, 'iglob')
    def test_vf_number_found(self, mock_iglob, mock_readlink):
        mock_iglob.return_value = [
            '/sys/bus/pci/devices/0000:00:00.1/physfn/virtfn3',
        ]
        mock_readlink.return_value = '../../0000:00:00.1'
        vf_num = linux_net.get_vf_num_by_pci_address('0000:00:00.1')
        self.assertEqual(vf_num, '3')

    @mock.patch.object(os, 'readlink')
    @mock.patch.object(glob, 'iglob')
    def test_vf_number_not_found(self, mock_iglob, mock_readlink):
        mock_iglob.return_value = [
            '/sys/bus/pci/devices/0000:00:00.1/physfn/virtfn3',
        ]
        mock_readlink.return_value = '../../0000:00:00.2'
        self.assertRaises(

            exception.PciDeviceNotFoundById,