# 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_arp_filtering):
        linux_net.ensure_bridge("br0")

        mock_dev_exists.assert_called_once_with("br0")
        mock_add.assert_not_called()
        mock_disable_ipv6.assert_called_once_with("br0")
        mock_set_state.assert_called_once_with("br0", "up")
        mock_arp_filtering.assert_called_once_with("br0")

    @mock.patch('builtins.open')
    @mock.patch("os.path.exists")
    def test__disable_ipv6(self, mock_exists, mock_open):

        exists_path = "/proc/sys/net/ipv6/conf/br0/disable_ipv6"
        mock_exists.return_value = False

        linux_net._disable_ipv6("br0")
        mock_exists.assert_called_once_with(exists_path)
        mock_open.assert_not_called()

        mock_exists.reset_mock()
        mock_exists.return_value = True
        linux_net._disable_ipv6("br0")
        mock_exists.assert_called_once_with(exists_path)
        mock_open.assert_called_once_with(exists_path, 'w')

    @mock.patch.object(os.path, 'exists', return_value=True)
    @mock.patch('builtins.open')
    def test__arp_filtering(self, mock_open, *args):
        mock_open.side_effect = mock.mock_open()

# 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_arp_filtering):
        linux_net.ensure_bridge("br0")

        mock_dev_exists.assert_called_once_with("br0")
        mock_add.assert_not_called()
        mock_disable_ipv6.assert_called_once_with("br0")
        mock_set_state.assert_called_once_with("br0", "up")
        mock_arp_filtering.assert_called_once_with("br0")

    @mock.patch('builtins.open')
    @mock.patch("os.path.exists")
    def test__disable_ipv6(self, mock_exists, mock_open):

        exists_path = "/proc/sys/net/ipv6/conf/br0/disable_ipv6"
        mock_exists.return_value = False

        linux_net._disable_ipv6("br0")
        mock_exists.assert_called_once_with(exists_path)
        mock_open.assert_not_called()

        mock_exists.reset_mock()
        mock_exists.return_value = True
        linux_net._disable_ipv6("br0")
        mock_exists.assert_called_once_with(exists_path)
        mock_open.assert_called_once_with(exists_path, 'w')

    @mock.patch.object(os.path, 'exists', return_value=True)
    @mock.patch('builtins.open')
    def test__arp_filtering(self, mock_open, *args):
        mock_open.side_effect = mock.mock_open()

        linux_net._arp_filtering("br0")