# Path: os_vif/internal/ip/api.py
# LOG = logging.getLogger(__name__)
# 
# Path: vif_plug_linux_bridge/linux_net.py
# LOG = logging.getLogger(__name__)
# _IPTABLES_MANAGER = None
#     _IPTABLES_MANAGER = iptables_mgr
# def _set_device_mtu(dev, mtu):
# def _ip_bridge_cmd(action, params, device):
# def ensure_vlan_bridge(vlan_num, bridge, bridge_interface,
#                        net_attrs=None, mac_address=None,
#                        mtu=None):
# def _ensure_vlan_privileged(vlan_num, bridge_interface, mac_address, mtu):
# def ensure_bridge(bridge, interface, net_attrs=None, gateway=True,
#                   filtering=True, mtu=None):
# def _disable_ipv6(bridge):
# def _arp_filtering(bridge):
# def _update_bridge_routes(interface, bridge):
# def _ensure_bridge_privileged(bridge, interface, net_attrs, gateway,
#                               filtering=True, mtu=None):
# def _ensure_bridge_filtering(bridge, gateway):
# def configure(iptables_mgr):
# 
# Path: vif_plug_linux_bridge/privsep.py



from unittest import mock
from oslo_concurrency import lockutils
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_log.fixture import logging_error as log_fixture
from os_vif.internal.ip.api import ip as ip_lib
from vif_plug_linux_bridge import linux_net
from vif_plug_linux_bridge import privsep
import fixtures
import testtools

    @mock.patch.object(ip_lib, "set")
    def test_set_device_mtu(self, mock_ip_set):
        linux_net._set_device_mtu(dev='fakedev', mtu=1500)
        mock_ip_set.assert_called_once_with('fakedev', mtu=1500,
                                            check_exit_code=[0, 2, 254])

    @mock.patch.object(processutils, "execute")
    def test_set_device_invalid_mtu(self, mock_exec):
        linux_net._set_device_mtu(dev='fakedev', mtu=None)
        mock_exec.assert_not_called()

    @mock.patch.object(ip_lib, "add")
    @mock.patch.object(ip_lib, "set")
    @mock.patch.object(ip_lib, "exists", return_value=False)
    @mock.patch.object(linux_net, "_set_device_mtu")
    def test_ensure_vlan(self, mock_set_mtu, mock_dev_exists, mock_ip_set,
                         mock_ip_add):
        linux_net._ensure_vlan_privileged(123, 'fake-bridge',
                                          mac_address='fake-mac',
                                          mtu=1500)
        self.assertTrue(mock_dev_exists.called)
        set_calls = [mock.call('vlan123', address='fake-mac',
                               check_exit_code=[0, 2, 254]),
                     mock.call('vlan123', state='up',
                               check_exit_code=[0, 2, 254])]
        mock_ip_add.assert_called_once_with(
            'vlan123', 'vlan', link='fake-bridge', vlan_id=123,
            check_exit_code=[0, 2, 254])
        mock_ip_set.assert_has_calls(set_calls)

# Path: os_vif/internal/ip/api.py
# LOG = logging.getLogger(__name__)
# 
# Path: vif_plug_linux_bridge/linux_net.py
# LOG = logging.getLogger(__name__)
# _IPTABLES_MANAGER = None
#     _IPTABLES_MANAGER = iptables_mgr
# def _set_device_mtu(dev, mtu):
# def _ip_bridge_cmd(action, params, device):
# def ensure_vlan_bridge(vlan_num, bridge, bridge_interface,
#                        net_attrs=None, mac_address=None,
#                        mtu=None):
# def _ensure_vlan_privileged(vlan_num, bridge_interface, mac_address, mtu):
# def ensure_bridge(bridge, interface, net_attrs=None, gateway=True,
#                   filtering=True, mtu=None):
# def _disable_ipv6(bridge):
# def _arp_filtering(bridge):
# def _update_bridge_routes(interface, bridge):
# def _ensure_bridge_privileged(bridge, interface, net_attrs, gateway,
#                               filtering=True, mtu=None):
# def _ensure_bridge_filtering(bridge, gateway):
# def configure(iptables_mgr):
# 
# Path: vif_plug_linux_bridge/privsep.py



# Path: vif_plug_linux_bridge/tests/unit/test_linux_net.py
from unittest import mock
from oslo_concurrency import lockutils
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_log.fixture import logging_error as log_fixture
from os_vif.internal.ip.api import ip as ip_lib
from vif_plug_linux_bridge import linux_net
from vif_plug_linux_bridge import privsep
import fixtures
import testtools


    @mock.patch.object(ip_lib, "set")
    def test_set_device_mtu(self, mock_ip_set):
        linux_net._set_device_mtu(dev='fakedev', mtu=1500)
        mock_ip_set.assert_called_once_with('fakedev', mtu=1500,
                                            check_exit_code=[0, 2, 254])

    @mock.patch.object(processutils, "execute")
    def test_set_device_invalid_mtu(self, mock_exec):
        linux_net._set_device_mtu(dev='fakedev', mtu=None)
        mock_exec.assert_not_called()

    @mock.patch.object(ip_lib, "add")
    @mock.patch.object(ip_lib, "set")
    @mock.patch.object(ip_lib, "exists", return_value=False)
    @mock.patch.object(linux_net, "_set_device_mtu")
    def test_ensure_vlan(self, mock_set_mtu, mock_dev_exists, mock_ip_set,
                         mock_ip_add):
        linux_net._ensure_vlan_privileged(123, 'fake-bridge',
                                          mac_address='fake-mac',
                                          mtu=1500)
        self.assertTrue(mock_dev_exists.called)
        set_calls = [mock.call('vlan123', address='fake-mac',
                               check_exit_code=[0, 2, 254]),
                     mock.call('vlan123', state='up',
                               check_exit_code=[0, 2, 254])]
        mock_ip_add.assert_called_once_with(
            'vlan123', 'vlan', link='fake-bridge', vlan_id=123,
            check_exit_code=[0, 2, 254])
        mock_ip_set.assert_has_calls(set_calls)

        mock_set_mtu.assert_called_once_with('vlan123', 1500)