Пример #1
0
    def test_single_host(self):
        from pillar.api.organizations import ip_ranges

        # A host is a valid range by itself.
        db_org = self._patch({'ip_ranges': ['192.168.3.5', '3abe:0412:0000::f00d']})
        self.assertEqual([
            ip_ranges.doc('192.168.3.5/32'),
            ip_ranges.doc('3abe:0412:0000::f00d/128'),
        ], db_org['ip_ranges'])
Пример #2
0
    def test_patch_set_ip_ranges_happy(self):
        from pillar.api.organizations import ip_ranges

        # IP ranges should be saved as integers for fast matching.
        db_org = self._patch({'ip_ranges': [
            '192.168.3.0/24',
            ' 192.168.3.1/32 \r\n ',  # Whitespace should be ignored
            '2a03:b0c0:0:1010::8fe:6ef1/120',
        ]})

        self.assertEqual([
            ip_ranges.doc('192.168.3.0/24'),
            ip_ranges.doc('192.168.3.1/32'),
            ip_ranges.doc('2a03:b0c0:0:1010::8fe:6ef1/120'),
        ], db_org['ip_ranges'])
Пример #3
0
    def test_ipranges_doc(self):
        from pillar.api.organizations import ip_ranges

        doc = ip_ranges.doc('2a03:b0c0:0:1010::8fe:6ef1/120')
        self.assertEqual(0x2a03b0c0000010100000000008fe6e00.to_bytes(16, 'big'), doc['start'])
        self.assertEqual(0x2a03b0c0000010100000000008fe6eff.to_bytes(16, 'big'), doc['end'])
        self.assertEqual('2a03:b0c0:0:1010::8fe:6e00/120', doc['human'])
        self.assertEqual(120, doc['prefix'])
        self.assertEqual({'prefix', 'human', 'start', 'end'}, set(doc.keys()))