def test_prefixlist_append(): pfx0 = PrefixList(prefixes0) pfx1 = PrefixList() for each in prefixes0: pfx1.append(each) print pfx0 print pfx1 assert pfx0 == pfx1
def test_aggregate_single(): prefixlist = [ '10.0.1.0/24', ] expected = [ '10.0.1.0/24', ] pfx = PrefixList(prefixlist) assert expected == pfx.aggregate().str_list() assert PrefixList(prefixlist) == pfx
def test_aggregate_combine_multi(): prefixlist = [ '10.0.0.0/24', '10.0.1.0/24', '10.0.2.0/23', ] expected = [ '10.0.0.0/22', ] pfx = PrefixList(prefixlist) assert expected == pfx.aggregate().str_list() assert PrefixList(prefixlist) == pfx
def test_prefixlist_eq(): pfx0 = PrefixList(prefixes0) pfx1 = PrefixList(prefixes0) assert pfx0 == pfx1 pfx1.pop() assert pfx0 != pfx1 with pytest.raises(TypeError) as e: pfx0 != "string" assert "object not PrefixList type" == e.value.message with pytest.raises(TypeError) as e: pfx0 != "string" assert "object not PrefixList type" == e.value.message
def test_aggregate_super(): prefixlist = [ '10.0.1.0/24', '10.0.0.0/20', '2001:db8::/32', '2001:db8:1::/64', ] expected = [ '10.0.0.0/20', '2001:db8::/32', ] pfx = PrefixList(prefixlist) assert expected == pfx.aggregate().str_list() assert PrefixList(prefixlist) == pfx
def prefixlist(ctx, as_set, output, output_format, proto, **kwargs): """ get prefix list for specified as-sets """ if kwargs.get('debug', False): logging.basicConfig(level=logging.DEBUG) prefixes = PrefixList() bgpfuc = bgpfu.client.IRRClient() with bgpfuc as c: if kwargs.get('sources', False): c.set_sources(kwargs['sources']) # prefixes = c.get_prefixes(as_set, proto) for chunk in c.iter_prefixes(as_set, proto): prefixes.add_iter(chunk) if kwargs.get('aggregate', True): prefixes = prefixes.aggregate() with click.open_file(output, 'w') as fobj: outfmt.write(output_format, fobj, prefixes.str_list()) print("LEN {}".format(len(prefixes)))
def test_prefixlist_str_list(): pfx0 = PrefixList(prefixes0) assert prefixes0 == pfx0.str_list()