示例#1
0
 def test_deferred_unset_apply_ran(self):
     manager = linux_net.IptablesManager()
     manager.iptables_apply_deferred = True
     self.mox.StubOutWithMock(manager, '_apply')
     manager._apply()
     self.mox.ReplayAll()
     manager.defer_apply_off()
     self.assertFalse(manager.iptables_apply_deferred)
示例#2
0
 def test_apply_ran(self):
     manager = linux_net.IptablesManager()
     manager.iptables_apply_deferred = False
     self.mox.StubOutWithMock(manager, '_apply')
     manager._apply()
     self.mox.ReplayAll()
     empty_ret = manager.apply()
     self.assertIsNone(empty_ret)
示例#3
0
 def __init__(self, virtapi, xenapi_session=None, **kwargs):
     from nova.network import linux_net
     super(Dom0IptablesFirewallDriver, self).__init__(virtapi, **kwargs)
     self._session = xenapi_session
     # Create IpTablesManager with executor through plugin
     self.iptables = linux_net.IptablesManager(self._plugin_execute)
     self.iptables.ipv4['filter'].add_chain('sg-fallback')
     self.iptables.ipv4['filter'].add_rule('sg-fallback', '-j DROP')
     self.iptables.ipv6['filter'].add_chain('sg-fallback')
     self.iptables.ipv6['filter'].add_rule('sg-fallback', '-j DROP')
示例#4
0
 def setUp(self):
     super(IptablesManagerTestCase, self).setUp()
     self.manager = linux_net.IptablesManager()
示例#5
0
    def test_isolated_host(self):
        self.flags(fake_network=False, share_dhcp_address=True)
        # NOTE(vish): use a fresh copy of the manager for each test
        self.stubs.Set(linux_net, 'iptables_manager',
                       linux_net.IptablesManager())
        self.stubs.Set(linux_net, 'binary_name', 'test')
        executes = []

        def fake_execute(*args, **kwargs):
            executes.append(args)
            return "", ""

        self.stubs.Set(utils, 'execute', fake_execute)

        driver = linux_net.LinuxBridgeInterfaceDriver()

        @staticmethod
        def fake_ensure(bridge, interface, network, gateway):
            return bridge

        self.stubs.Set(linux_net.LinuxBridgeInterfaceDriver, 'ensure_bridge',
                       fake_ensure)

        iface = 'eth0'
        dhcp = '192.168.1.1'
        network = {
            'dhcp_server': dhcp,
            'share_address': False,
            'bridge': 'br100',
            'bridge_interface': iface
        }
        driver.plug(network, 'fakemac')
        expected = [
            ('ebtables', '-t', 'filter', '-D', 'INPUT', '-p', 'ARP', '-i',
             iface, '--arp-ip-dst', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-I', 'INPUT', '-p', 'ARP', '-i',
             iface, '--arp-ip-dst', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'OUTPUT', '-p', 'ARP', '-o',
             iface, '--arp-ip-src', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-I', 'OUTPUT', '-p', 'ARP', '-o',
             iface, '--arp-ip-src', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'FORWARD', '-p', 'IPv4', '-i',
             iface, '--ip-protocol', 'udp', '--ip-destination-port', '67:68',
             '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-I', 'FORWARD', '-p', 'IPv4', '-i',
             iface, '--ip-protocol', 'udp', '--ip-destination-port', '67:68',
             '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'FORWARD', '-p', 'IPv4', '-o',
             iface, '--ip-protocol', 'udp', '--ip-destination-port', '67:68',
             '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-I', 'FORWARD', '-p', 'IPv4', '-o',
             iface, '--ip-protocol', 'udp', '--ip-destination-port', '67:68',
             '-j', 'DROP'),
            ('iptables-save', '-c'),
            ('iptables-restore', '-c'),
            ('ip6tables-save', '-c'),
            ('ip6tables-restore', '-c'),
        ]
        self.assertEqual(executes, expected)

        executes = []

        @staticmethod
        def fake_remove(bridge, gateway):
            return

        self.stubs.Set(linux_net.LinuxBridgeInterfaceDriver, 'remove_bridge',
                       fake_remove)

        driver.unplug(network)
        expected = [
            ('ebtables', '-t', 'filter', '-D', 'INPUT', '-p', 'ARP', '-i',
             iface, '--arp-ip-dst', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'OUTPUT', '-p', 'ARP', '-o',
             iface, '--arp-ip-src', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'FORWARD', '-p', 'IPv4', '-i',
             iface, '--ip-protocol', 'udp', '--ip-destination-port', '67:68',
             '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'FORWARD', '-p', 'IPv4', '-o',
             iface, '--ip-protocol', 'udp', '--ip-destination-port', '67:68',
             '-j', 'DROP'),
        ]
        self.assertEqual(executes, expected)
示例#6
0
 def test_apply_not_run(self):
     manager = linux_net.IptablesManager()
     manager.iptables_apply_deferred = True
     self.mox.StubOutWithMock(manager, '_apply')
     self.mox.ReplayAll()
     manager.apply()
    def test_isolated_host_iptables_logdrop(self):
        # Ensure that a different drop action for iptables doesn't change
        # the drop action for ebtables.
        self.flags(fake_network=False,
                   share_dhcp_address=True,
                   iptables_drop_action='LOGDROP')

        # NOTE(vish): use a fresh copy of the manager for each test
        self.stubs.Set(linux_net, 'iptables_manager',
                       linux_net.IptablesManager())
        self.stubs.Set(linux_net, 'binary_name', 'test')
        executes = []
        inputs = []

        def fake_execute(*args, **kwargs):
            executes.append(args)
            process_input = kwargs.get('process_input')
            if process_input:
                inputs.append(process_input)
            return "", ""

        self.stubs.Set(utils, 'execute', fake_execute)

        driver = linux_net.LinuxBridgeInterfaceDriver()

        @staticmethod
        def fake_ensure(bridge, interface, network, gateway):
            return bridge

        self.stubs.Set(linux_net.LinuxBridgeInterfaceDriver, 'ensure_bridge',
                       fake_ensure)

        iface = 'eth0'
        dhcp = '192.168.1.1'
        network = {
            'dhcp_server': dhcp,
            'bridge': 'br100',
            'bridge_interface': iface
        }
        driver.plug(network, 'fakemac')
        expected = [
            ('ebtables', '-t', 'filter', '-D', 'INPUT', '-p', 'ARP', '-i',
             iface, '--arp-ip-dst', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-I', 'INPUT', '-p', 'ARP', '-i',
             iface, '--arp-ip-dst', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'OUTPUT', '-p', 'ARP', '-o',
             iface, '--arp-ip-src', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-I', 'OUTPUT', '-p', 'ARP', '-o',
             iface, '--arp-ip-src', dhcp, '-j', 'DROP'),
            ('iptables-save', '-c'),
            ('iptables-restore', '-c'),
            ('ip6tables-save', '-c'),
            ('ip6tables-restore', '-c'),
        ]
        self.assertEqual(executes, expected)
        expected_inputs = [
            ('-A test-FORWARD -m physdev --physdev-in %s '
             '-d 255.255.255.255 -p udp --dport 67 -j LOGDROP' % iface),
            ('-A test-FORWARD -m physdev --physdev-out %s '
             '-d 255.255.255.255 -p udp --dport 67 -j LOGDROP' % iface),
            ('-A test-FORWARD -m physdev --physdev-in %s '
             '-d 192.168.1.1 -j LOGDROP' % iface),
            ('-A test-FORWARD -m physdev --physdev-out %s '
             '-s 192.168.1.1 -j LOGDROP' % iface),
        ]
        for inp in expected_inputs:
            self.assertIn(inp, inputs[0])

        executes = []
        inputs = []

        @staticmethod
        def fake_remove(bridge, gateway):
            return

        self.stubs.Set(linux_net.LinuxBridgeInterfaceDriver, 'remove_bridge',
                       fake_remove)

        driver.unplug(network)
        expected = [
            ('ebtables', '-t', 'filter', '-D', 'INPUT', '-p', 'ARP', '-i',
             iface, '--arp-ip-dst', dhcp, '-j', 'DROP'),
            ('ebtables', '-t', 'filter', '-D', 'OUTPUT', '-p', 'ARP', '-o',
             iface, '--arp-ip-src', dhcp, '-j', 'DROP'),
            ('iptables-save', '-c'),
            ('iptables-restore', '-c'),
            ('ip6tables-save', '-c'),
            ('ip6tables-restore', '-c'),
        ]
        self.assertEqual(executes, expected)
        for inp in expected_inputs:
            self.assertNotIn(inp, inputs[0])