Exemple #1
0
 def _buildRules(self):
     return [
         Rule(source=self._network, table=self._table),
         Rule(destination=self._network,
              table=self._table,
              srcDevice=self.device)
     ]
Exemple #2
0
    def _getRules(device):
        """
            32764:	from all to 10.35.0.0/23 iif ovirtmgmt lookup 170066094
            32765:	from 10.35.0.0/23 lookup 170066094

            The first rule we'll find directly via the interface name
            We'll then use that rule's destination network, and use it
            to find the second rule via its source network
        """
        allRules = []
        for entry in ruleList():
            try:
                rule = Rule.fromText(entry)
            except ValueError:
                logging.debug("Could not parse rule %s" % entry)
            else:
                allRules.append(rule)

        # Find the rule we put in place with 'device' as its 'srcDevice'
        rules = [rule for rule in allRules if rule.srcDevice == device]

        if not rules:
            logging.error("Routing rules not found for device %s" % device)
            return

        # Extract its destination network
        network = rules[0].destination

        # Find the other rule we put in place - It'll have 'network' as
        # its source
        rules += [rule for rule in allRules if rule.source == network]

        return rules
Exemple #3
0
    def testRuleFromText(self):
        _getRuleAttrs = lambda x: (x.table, x.source, x.destination, x.
                                   srcDevice, x.detached)
        good_rules = {
            '1:    from all lookup main': ('main', None, None, None, False),
            '2:    from 10.0.0.0/8 to 20.0.0.0/8 lookup table_100':
            ('table_100', '10.0.0.0/8', '20.0.0.0/8', None, False),
            '3:    from all to 8.8.8.8 lookup table_200':
            ('table_200', None, '8.8.8.8', None, False),
            '4:    from all to 5.0.0.0/8 iif dummy0 [detached] lookup 500':
            ('500', None, '5.0.0.0/8', 'dummy0', True),
            '5:    from all to 5.0.0.0/8 dev dummy0 lookup 500':
            ('500', None, '5.0.0.0/8', 'dummy0', False)
        }
        for text, attributes in good_rules.iteritems():
            rule = Rule.fromText(text)
            self.assertEqual(_getRuleAttrs(rule), attributes)

        bad_rules = [
            '32766:    from all lookup main foo', '2766:    lookup main',
            '276:    from 8.8.8.8'
            '32:    from 10.0.0.0/8 to 264.0.0.0/8 lookup table_100'
        ]
        for text in bad_rules:
            self.assertRaises(ValueError, Rule.fromText, text)
Exemple #4
0
    def testRuleFromText(self):
        _getRuleAttrs = lambda x: (x.table, x.source, x.destination, x.srcDevice, x.detached)
        good_rules = {
            "1:    from all lookup main": ("main", None, None, None, False),
            "2:    from 10.0.0.0/8 to 20.0.0.0/8 lookup table_100": (
                "table_100",
                "10.0.0.0/8",
                "20.0.0.0/8",
                None,
                False,
            ),
            "3:    from all to 8.8.8.8 lookup table_200": ("table_200", None, "8.8.8.8", None, False),
            "4:    from all to 5.0.0.0/8 iif dummy0 [detached] lookup 500": ("500", None, "5.0.0.0/8", "dummy0", True),
            "5:    from all to 5.0.0.0/8 dev dummy0 lookup 500": ("500", None, "5.0.0.0/8", "dummy0", False),
        }
        for text, attributes in good_rules.iteritems():
            rule = Rule.fromText(text)
            self.assertEqual(_getRuleAttrs(rule), attributes)

        bad_rules = [
            "32766:    from all lookup main foo",
            "2766:    lookup main",
            "276:    from 8.8.8.8" "32:    from 10.0.0.0/8 to 264.0.0.0/8 lookup table_100",
        ]
        for text in bad_rules:
            self.assertRaises(ValueError, Rule.fromText, text)
Exemple #5
0
    def _getRules(device):
        """
            32764:	from all to 10.35.0.0/23 iif ovirtmgmt lookup 170066094
            32765:	from 10.35.0.0/23 lookup 170066094

            The first rule we'll find directly via the interface name
            We'll then use that rule's destination network, and use it
            to find the second rule via its source network
        """
        allRules = []
        for entry in ruleList():
            try:
                rule = Rule.fromText(entry)
            except ValueError:
                logging.debug("Could not parse rule %s", entry)
            else:
                allRules.append(rule)

        # Find the rule we put in place with 'device' as its 'srcDevice'
        rules = [r for r in allRules if r.srcDevice == device]

        if not rules:
            logging.error("Routing rules not found for device %s", device)
            return

        # Extract its destination network
        network = rules[0].destination

        # Find the other rule we put in place - It'll have 'network' as
        # its source
        rules += [r for r in allRules if r.source == network]

        return rules
    def testRuleFromText(self):
        _getRuleAttrs = lambda x: (x.table, x.source, x.destination)
        good_rules = {
            '32766:    from all lookup main':
            ('main', None, None),
            '32767:    from 10.0.0.0/8 to 20.0.0.0/8 lookup table_100':
            ('table_100', '10.0.0.0/8', '20.0.0.0/8'),
            '32768:    from all to 8.8.8.8 lookup table_200':
            ('table_200', None, '8.8.8.8')}
        for text, attributes in good_rules.iteritems():
            rule = Rule.fromText(text)
            self.assertEqual(_getRuleAttrs(rule), attributes)

        bad_rules = ['32766:    from all lookup main foo',
                     '2766:    lookup main',
                     '276:    from 8.8.8.8'
                     '32:    from 10.0.0.0/8 to 264.0.0.0/8 lookup table_100']
        for text in bad_rules:
            self.assertRaises(ValueError, Rule.fromText, text)
Exemple #7
0
    def testRuleFromText(self):
        _getRuleAttrs = lambda x: (x.table, x.source, x.destination)
        good_rules = {
            '32766:    from all lookup main': ('main', None, None),
            '32767:    from 10.0.0.0/8 to 20.0.0.0/8 lookup table_100':
            ('table_100', '10.0.0.0/8', '20.0.0.0/8'),
            '32768:    from all to 8.8.8.8 lookup table_200':
            ('table_200', None, '8.8.8.8')
        }
        for text, attributes in good_rules.iteritems():
            rule = Rule.fromText(text)
            self.assertEqual(_getRuleAttrs(rule), attributes)

        bad_rules = [
            '32766:    from all lookup main foo', '2766:    lookup main',
            '276:    from 8.8.8.8'
            '32:    from 10.0.0.0/8 to 264.0.0.0/8 lookup table_100'
        ]
        for text in bad_rules:
            self.assertRaises(ValueError, Rule.fromText, text)
Exemple #8
0
    def testRuleFromText(self):
        _getRuleAttrs = lambda x: (x.table, x.source, x.destination,
                                   x.srcDevice, x.detached)
        good_rules = {
            '1:    from all lookup main':
            ('main', None, None, None, False),
            '2:    from 10.0.0.0/8 to 20.0.0.0/8 lookup table_100':
            ('table_100', '10.0.0.0/8', '20.0.0.0/8', None, False),
            '3:    from all to 8.8.8.8 lookup table_200':
            ('table_200', None, '8.8.8.8', None, False),
            '4:    from all to 5.0.0.0/8 iif dummy0 [detached] lookup 500':
            ('500', None, '5.0.0.0/8', 'dummy0', True),
            '5:    from all to 5.0.0.0/8 dev dummy0 lookup 500':
            ('500', None, '5.0.0.0/8', 'dummy0', False)}
        for text, attributes in good_rules.iteritems():
            rule = Rule.fromText(text)
            self.assertEqual(_getRuleAttrs(rule), attributes)

        bad_rules = ['32766:    from all lookup main foo',
                     '2766:    lookup main',
                     '276:    from 8.8.8.8'
                     '32:    from 10.0.0.0/8 to 264.0.0.0/8 lookup table_100']
        for text in bad_rules:
            self.assertRaises(ValueError, Rule.fromText, text)