Esempio n. 1
0
    def test_ebtables_input_parse_commit(self):
        # COMMIT without first starting a table should result in nothing,
        test_input = "COMMIT"
        res = eb._process_ebtables_input(test_input)
        self.assertEqual(list(), res)

        test_input = "*filter\nCOMMIT"
        res = eb._process_ebtables_input(test_input)
        self.assertEqual([('filter', ['--atomic-init']),
                          ('filter', ['--atomic-commit'])],
                         res)
Esempio n. 2
0
 def test_ebtables_input_parse_comment(self):
     # Comments and empty lines are stripped, nothing should be left.
     test_input = ("# Here is a comment\n"
                   "\n"
                   "# We just had an empty line.\n")
     res = eb._process_ebtables_input(test_input)
     self.assertEqual(list(), res)
Esempio n. 3
0
    def test_ebtables_input_parse_all_together(self):
        test_input = \
            ("*filter\n"
             ":INPUT ACCEPT\n"
             ":FORWARD ACCEPT\n"
             ":OUTPUT ACCEPT\n"
             ":neutron-nwfilter-spoofing-fallb ACCEPT\n"
             ":neutron-nwfilter-OUTPUT ACCEPT\n"
             ":neutron-nwfilter-INPUT ACCEPT\n"
             ":neutron-nwfilter-FORWARD ACCEPT\n"
             "[0:0] -A INPUT -j neutron-nwfilter-INPUT\n"
             "[0:0] -A OUTPUT -j neutron-nwfilter-OUTPUT\n"
             "[0:0] -A FORWARD -j neutron-nwfilter-FORWARD\n"
             "[0:0] -A neutron-nwfilter-spoofing-fallb -j DROP\n"
             "COMMIT")
        observed_res = eb._process_ebtables_input(test_input)
        TNAME = 'filter'
        expected_res = [
            (TNAME, ['--atomic-init']),
            (TNAME, ['-P', 'INPUT', 'ACCEPT']),
            (TNAME, ['-P', 'FORWARD', 'ACCEPT']),
            (TNAME, ['-P', 'OUTPUT', 'ACCEPT']),
            (TNAME, ['-N', 'neutron-nwfilter-spoofing-fallb', '-P', 'ACCEPT']),
            (TNAME, ['-N', 'neutron-nwfilter-OUTPUT', '-P', 'ACCEPT']),
            (TNAME, ['-N', 'neutron-nwfilter-INPUT', '-P', 'ACCEPT']),
            (TNAME, ['-N', 'neutron-nwfilter-FORWARD', '-P', 'ACCEPT']),
            (TNAME, ['-A', 'INPUT', '-j', 'neutron-nwfilter-INPUT']),
            (TNAME, ['-A', 'OUTPUT', '-j', 'neutron-nwfilter-OUTPUT']),
            (TNAME, ['-A', 'FORWARD', '-j', 'neutron-nwfilter-FORWARD']),
            (TNAME, ['-A', 'neutron-nwfilter-spoofing-fallb', '-j', 'DROP']),
            (TNAME, ['--atomic-commit'])]

        self.assertEqual(expected_res, observed_res)
Esempio n. 4
0
 def test_ebtables_input_parse_rule(self):
     test_input = "*filter\n[0:0] -A INPUT -j neutron-nwfilter-INPUT"
     res = eb._process_ebtables_input(test_input)
     self.assertEqual([('filter', ['--atomic-init']),
                       ('filter',
                        ['-A', 'INPUT', '-j', 'neutron-nwfilter-INPUT'])],
                      res)
Esempio n. 5
0
 def test_ebtables_input_parse_start(self):
     # Starting
     test_input = "*filter"
     res = eb._process_ebtables_input(test_input)
     self.assertEqual([('filter', ['--atomic-init'])], res)
Esempio n. 6
0
 def test_ebtables_input_parse_chain(self):
     test_input = "*filter\n:foobar ACCEPT"
     res = eb._process_ebtables_input(test_input)
     self.assertEqual([('filter', ['--atomic-init']),
                       ('filter', ['-N', 'foobar', '-P', 'ACCEPT'])],
                      res)