diff options
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/bagpipe.py | 10 | ||||
-rw-r--r-- | test/lib/base.py | 63 | ||||
-rw-r--r-- | test/lib/bird.py | 19 | ||||
-rw-r--r-- | test/lib/exabgp.py | 14 | ||||
-rw-r--r-- | test/lib/fabfile.py | 28 | ||||
-rw-r--r-- | test/lib/gobgp.py | 49 | ||||
-rw-r--r-- | test/lib/quagga.py | 45 | ||||
-rw-r--r-- | test/lib/yabgp.py | 23 | ||||
-rw-r--r-- | test/lib/yabgp_helper.py | 4 |
9 files changed, 134 insertions, 121 deletions
diff --git a/test/lib/bagpipe.py b/test/lib/bagpipe.py index efca1c4e..43e1dcc0 100644 --- a/test/lib/bagpipe.py +++ b/test/lib/bagpipe.py @@ -13,14 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import - -from fabric import colors -from fabric.api import local from lib.base import ( BGPContainer, CmdBuffer, + yellow, + local, ) @@ -49,7 +47,7 @@ class BagpipeContainer(BGPContainer): c << '[BGP]' if len(self.ip_addrs) > 0: c << 'local_address={0}'.format(self.ip_addrs[0][1].split('/')[0]) - for info in self.peers.values(): + for info in list(self.peers.values()): c << 'peers={0}'.format(info['neigh_addr'].split('/')[0]) c << 'my_as={0}'.format(self.asn) c << 'enable_rtc=True' @@ -62,7 +60,7 @@ class BagpipeContainer(BGPContainer): c << 'dataplane_driver = DummyDataplaneDriver' with open('{0}/bgp.conf'.format(self.config_dir), 'w') as f: - print colors.yellow(str(c)) + print(yellow(str(c))) f.writelines(str(c)) def reload_config(self): diff --git a/test/lib/base.py b/test/lib/base.py index 6ae99e4c..da0ff489 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -13,21 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import import os import time import itertools -from fabric.api import local, lcd -from fabric import colors -from fabric.state import env, output +from invoke import run + +import textwrap +from colored import fg, attr + try: from docker import Client except ImportError: from docker import APIClient as Client import netaddr + DEFAULT_TEST_PREFIX = '' DEFAULT_TEST_BASE_DIR = '/tmp/gobgp' TEST_PREFIX = DEFAULT_TEST_PREFIX @@ -82,8 +84,19 @@ FLOWSPEC_NAME_TO_TYPE = { TEST_CONTAINER_LABEL = 'gobgp-test' TEST_NETWORK_LABEL = TEST_CONTAINER_LABEL -env.abort_exception = RuntimeError -output.stderr = False + +def local(s, capture=False): + print('[localhost] local:', s) + _env = {'NOSE_NOLOGCAPTURE': '1' if capture else '0'} + return run(s, hide=True, env=_env).stdout.strip() + + +def yellow(s): + return fg('yellow') + str(s) + attr('reset') + + +def indent(s): + return textwrap.indent(str(s), ' '*4, lambda line: True) def community_str(i): @@ -158,27 +171,6 @@ class CmdBuffer(list): return self.delim.join(self) -def make_gobgp_ctn(tag='gobgp', local_gobgp_path='', from_image='osrg/quagga'): - if local_gobgp_path == '': - local_gobgp_path = os.getcwd() - - c = CmdBuffer() - c << 'FROM {0}'.format(from_image) - c << 'ENV GO111MODULE on' - c << 'ADD gobgp /tmp/gobgp' - c << 'RUN cd /tmp/gobgp && go install ./cmd/gobgpd ./cmd/gobgp' - - rindex = local_gobgp_path.rindex('gobgp') - if rindex < 0: - raise Exception('{0} seems not gobgp dir'.format(local_gobgp_path)) - - workdir = local_gobgp_path[:rindex] - with lcd(workdir): - local('echo \'{0}\' > Dockerfile'.format(str(c))) - local('docker build -t {0} .'.format(tag)) - local('rm Dockerfile') - - class Bridge(object): def __init__(self, name, subnet='', with_ip=True, self_ip=False): self.name = name @@ -222,7 +214,7 @@ class Bridge(object): capture=True) def next_ip_address(self): - return "{0}/{1}".format(self._ip_generator.next(), + return "{0}/{1}".format(next(self._ip_generator), self.subnet.prefixlen) def addif(self, ctn, ip_addr=''): @@ -234,7 +226,7 @@ class Bridge(object): if self.subnet.version == 6: ip = '--ip6 {0}'.format(ip_addr) local("docker network connect {0} {1} {2}".format(ip, self.name, ctn.docker_name())) - i = [x for x in Client(timeout=60, version='auto').inspect_network(self.id)['Containers'].values() if x['Name'] == ctn.docker_name()][0] + i = [x for x in list(Client(timeout=60, version='auto').inspect_network(self.id)['Containers'].values()) if x['Name'] == ctn.docker_name()][0] if self.subnet.version == 4: eth = 'eth{0}'.format(len(ctn.ip_addrs)) addr = i['IPv4Address'] @@ -302,7 +294,7 @@ class Container(object): def pipework(self, bridge, ip_addr, intf_name=""): if not self.is_running: - print colors.yellow('call run() before pipeworking') + print(yellow('call run() before pipeworking')) return c = CmdBuffer(' ') c << "pipework {0}".format(bridge.name) @@ -460,7 +452,7 @@ class BGPContainer(Container): def _extract_routes(self, families): routes = {} - for prefix, paths in self.routes.items(): + for prefix, paths in list(self.routes.items()): if paths and paths[0]['rf'] in families: routes[prefix] = paths return routes @@ -550,7 +542,7 @@ class BGPContainer(Container): count = 0 while True: res = self.local(cmd, capture=True) - print colors.yellow(res) + print(yellow(res)) if ('1 packets received' in res or '1 received' in res) and '0% packet loss' in res: break time.sleep(interval) @@ -564,10 +556,9 @@ class BGPContainer(Container): count = 0 while True: state = self.get_neighbor_state(peer) - y = colors.yellow - print y("{0}'s peer {1} state: {2}".format(self.router_id, - peer.router_id, - state)) + print(yellow("{0}'s peer {1} state: {2}".format(self.router_id, + peer.router_id, + state))) if state == expected_state: return diff --git a/test/lib/bird.py b/test/lib/bird.py index 9f210bcf..b2afb66a 100644 --- a/test/lib/bird.py +++ b/test/lib/bird.py @@ -13,19 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import -import time -from fabric import colors -from fabric.api import local -from fabric.utils import indent +import time from lib.base import ( BGPContainer, CmdBuffer, try_several_times, wait_for_completion, + yellow, + indent, + local, ) @@ -64,7 +63,7 @@ class BirdContainer(BGPContainer): def create_config(self): c = CmdBuffer() c << 'router id {0};'.format(self.router_id) - for peer, info in self.peers.iteritems(): + for peer, info in self.peers.items(): c << 'protocol bgp {' c << ' local as {0};'.format(self.asn) n_addr = info['neigh_addr'].split('/')[0] @@ -73,8 +72,8 @@ class BirdContainer(BGPContainer): c << '}' with open('{0}/bird.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new bird.conf]'.format(self.name)) - print colors.yellow(indent(str(c))) + print(yellow('[{0}\'s new bird.conf]'.format(self.name))) + print(yellow(indent(str(c)))) f.writelines(str(c)) def reload_config(self): @@ -122,6 +121,6 @@ class RawBirdContainer(BirdContainer): def create_config(self): with open('{0}/bird.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new bird.conf]'.format(self.name)) - print colors.yellow(indent(self.config)) + print(yellow('[{0}\'s new bird.conf]'.format(self.name))) + print(yellow(indent(self.config))) f.writelines(self.config) diff --git a/test/lib/exabgp.py b/test/lib/exabgp.py index 1326dd86..ad129e87 100644 --- a/test/lib/exabgp.py +++ b/test/lib/exabgp.py @@ -13,15 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import - -from fabric import colors from lib.base import ( BGPContainer, CmdBuffer, try_several_times, wait_for_completion, + yellow, ) @@ -68,7 +66,7 @@ class ExaBGPContainer(BGPContainer): # Manpage of exabgp.conf(5): # https://github.com/Exa-Networks/exabgp/blob/master/doc/man/exabgp.conf.5 cmd = CmdBuffer('\n') - for peer, info in self.peers.iteritems(): + for peer, info in self.peers.items(): cmd << 'neighbor {0} {{'.format(info['neigh_addr'].split('/')[0]) cmd << ' router-id {0};'.format(self.router_id) cmd << ' local-address {0};'.format(info['local_addr'].split('/')[0]) @@ -94,8 +92,8 @@ class ExaBGPContainer(BGPContainer): cmd << '}' with open('{0}/exabgpd.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new exabgpd.conf]'.format(self.name)) - print colors.yellow(str(cmd)) + print(yellow('[{0}\'s new exabgpd.conf]'.format(self.name))) + print(yellow(str(cmd))) f.write(str(cmd)) def _is_running(self): @@ -306,6 +304,6 @@ class RawExaBGPContainer(ExaBGPContainer): def create_config(self): with open('{0}/exabgpd.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new exabgpd.conf]'.format(self.name)) - print colors.yellow(self.config) + print(yellow('[{0}\'s new exabgpd.conf]'.format(self.name))) + print(yellow(self.config)) f.write(self.config) diff --git a/test/lib/fabfile.py b/test/lib/fabfile.py new file mode 100644 index 00000000..c50b7e22 --- /dev/null +++ b/test/lib/fabfile.py @@ -0,0 +1,28 @@ +import os +from fabric import task +from invoke import run as local +from base import CmdBuffer + + +@task +def make_gobgp_ctn(ctx, tag='gobgp', + local_gobgp_path='', + from_image='osrg/quagga'): + if local_gobgp_path == '': + local_gobgp_path = os.getcwd() + + c = CmdBuffer() + c << 'FROM {0}'.format(from_image) + c << 'ENV GO111MODULE on' + c << 'ADD gobgp /tmp/gobgp' + c << 'RUN cd /tmp/gobgp && go install ./cmd/gobgpd ./cmd/gobgp' + + rindex = local_gobgp_path.rindex('gobgp') + if rindex < 0: + raise Exception('{0} seems not gobgp dir'.format(local_gobgp_path)) + + workdir = local_gobgp_path[:rindex] + os.chdir(workdir) + local('echo \'{0}\' > Dockerfile'.format(str(c))) + local('docker build -t {0} .'.format(tag)) + local('rm Dockerfile') diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py index 9dbb4b90..9384fd2a 100644 --- a/test/lib/gobgp.py +++ b/test/lib/gobgp.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import + import collections import json @@ -22,9 +22,6 @@ from threading import Thread import subprocess import os -from fabric import colors -from fabric.api import local -from fabric.utils import indent import netaddr import toml import yaml @@ -45,6 +42,9 @@ from lib.base import ( BGP_FSM_IDLE, BGP_FSM_ACTIVE, BGP_FSM_ESTABLISHED, + yellow, + indent, + local, ) @@ -111,8 +111,7 @@ class GoBGPContainer(BGPContainer): c << '#!/bin/sh' c << '/go/bin/gobgpd -f {0}/gobgpd.conf -l {1} -p {2} -t {3} > ' \ '{0}/gobgpd.log 2>&1'.format(self.SHARED_VOLUME, self.log_level, '-r' if graceful_restart else '', self.config_format) - - cmd = 'echo "{0:s}" > {1}/start.sh'.format(c, self.config_dir) + cmd = 'echo "{0:s}" > {1}/start.sh'.format(str(c), self.config_dir) local(cmd, capture=True) cmd = "chmod 755 {0}/start.sh".format(self.config_dir) local(cmd, capture=True) @@ -212,7 +211,7 @@ class GoBGPContainer(BGPContainer): def _get_rib(self, dests_dict): dests = [] - for k, v in dests_dict.items(): + for k, v in list(dests_dict.items()): for p in v: p["nexthop"] = self._get_nexthop(p) p["aspath"] = self._get_as_path(p) @@ -282,7 +281,7 @@ class GoBGPContainer(BGPContainer): adj_type, prefix, rf) output = self.local(cmd, capture=True) - ret = [p[0] for p in json.loads(output).itervalues()] + ret = [p[0] for p in json.loads(output).values()] for p in ret: p["nexthop"] = self._get_nexthop(p) p["aspath"] = self._get_as_path(p) @@ -313,7 +312,7 @@ class GoBGPContainer(BGPContainer): def clear_policy(self): self.policies = {} - for info in self.peers.itervalues(): + for info in self.peers.values(): info['policies'] = {} self.prefix_set = [] self.neighbor_set = [] @@ -352,7 +351,7 @@ class GoBGPContainer(BGPContainer): self._create_config_ospfd() def _merge_dict(self, dct, merge_dct): - for k, v in merge_dct.iteritems(): + for k, v in merge_dct.items(): if (k in dct and isinstance(dct[k], dict) and isinstance(merge_dct[k], collections.Mapping)): self._merge_dict(dct[k], merge_dct[k]) @@ -380,7 +379,7 @@ class GoBGPContainer(BGPContainer): if self.zebra and self.zapi_version == 2: config['global']['use-multiple-paths'] = {'config': {'enabled': True}} - for peer, info in self.peers.iteritems(): + for peer, info in self.peers.items(): afi_safi_list = [] if info['interface'] != '': afi_safi_list.append({'config': {'afi-safi-name': 'ipv4-unicast'}}) @@ -481,7 +480,7 @@ class GoBGPContainer(BGPContainer): if len(info.get('default-policy', [])) + len(info.get('policies', [])) > 0: n['apply-policy'] = {'config': {}} - for typ, p in info.get('policies', {}).iteritems(): + for typ, p in info.get('policies', {}).items(): n['apply-policy']['config']['{0}-policy-list'.format(typ)] = [p['name']] def _f(v): @@ -491,7 +490,7 @@ class GoBGPContainer(BGPContainer): return 'accept-route' raise Exception('invalid default policy type {0}'.format(v)) - for typ, d in info.get('default-policy', {}).iteritems(): + for typ, d in info.get('default-policy', {}).items(): n['apply-policy']['config']['default-{0}-policy'.format(typ)] = _f(d) if info['treat_as_withdraw']: @@ -510,7 +509,7 @@ class GoBGPContainer(BGPContainer): config['defined-sets']['bgp-defined-sets'] = self.bgp_set policy_list = [] - for p in self.policies.itervalues(): + for p in self.policies.values(): policy = {'name': p['name']} if 'statements' in p: policy['statements'] = p['statements'] @@ -525,7 +524,7 @@ class GoBGPContainer(BGPContainer): 'version': self.zapi_version}} with open('{0}/gobgpd.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new gobgpd.conf]'.format(self.name)) + print(yellow('[{0}\'s new gobgpd.conf]'.format(self.name))) if self.config_format is 'toml': raw = toml.dumps(config) elif self.config_format is 'yaml': @@ -534,7 +533,8 @@ class GoBGPContainer(BGPContainer): raw = json.dumps(config) else: raise Exception('invalid config_format {0}'.format(self.config_format)) - print colors.yellow(indent(raw)) + raw = raw.strip() + print(yellow(indent(raw))) f.write(raw) def _create_config_zebra(self): @@ -549,9 +549,10 @@ class GoBGPContainer(BGPContainer): c << '' with open('{0}/zebra.conf'.format(self.quagga_config_dir), 'w') as f: - print colors.yellow('[{0}\'s new zebra.conf]'.format(self.name)) - print colors.yellow(indent(str(c))) - f.writelines(str(c)) + print(yellow('[{0}\'s new zebra.conf]'.format(self.name))) + c = str(c).strip() + print(yellow(indent(c))) + f.writelines(c) def _create_config_ospfd(self): c = CmdBuffer() @@ -560,14 +561,14 @@ class GoBGPContainer(BGPContainer): c << 'router ospf' for redistribute in self.ospfd_config.get('redistributes', []): c << ' redistribute {0}'.format(redistribute) - for network, area in self.ospfd_config.get('networks', {}).items(): + for network, area in list(self.ospfd_config.get('networks', {}).items()): c << ' network {0} area {1}'.format(network, area) c << 'log file {0}/ospfd.log'.format(self.QUAGGA_VOLUME) c << '' with open('{0}/ospfd.conf'.format(self.quagga_config_dir), 'w') as f: - print colors.yellow('[{0}\'s new ospfd.conf]'.format(self.name)) - print colors.yellow(indent(str(c))) + print(yellow('[{0}\'s new ospfd.conf]'.format(self.name))) + print(yellow(indent(str(c)))) f.writelines(str(c)) def reload_config(self): @@ -671,6 +672,6 @@ class RawGoBGPContainer(GoBGPContainer): def create_config(self): with open('{0}/gobgpd.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new gobgpd.conf]'.format(self.name)) - print colors.yellow(indent(self.config)) + print(yellow('[{0}\'s new gobgpd.conf]'.format(self.name))) + print(yellow(indent(self.config))) f.write(self.config) diff --git a/test/lib/quagga.py b/test/lib/quagga.py index 4f24c784..52ef8c33 100644 --- a/test/lib/quagga.py +++ b/test/lib/quagga.py @@ -13,12 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import -import re -from fabric import colors -from fabric.utils import indent +import re import netaddr from lib.base import ( @@ -31,6 +28,8 @@ from lib.base import ( BGP_FSM_ESTABLISHED, BGP_ATTR_TYPE_MULTI_EXIT_DISC, BGP_ATTR_TYPE_LOCAL_PREF, + yellow, + indent, ) @@ -188,7 +187,7 @@ class QuaggaBGPContainer(BGPContainer): c << 'password zebra' c << 'router bgp {0}'.format(self.asn) c << 'bgp router-id {0}'.format(self.router_id) - if any(info['graceful_restart'] for info in self.peers.itervalues()): + if any(info['graceful_restart'] for info in self.peers.values()): c << 'bgp graceful-restart' if 'global' in self.bgpd_config: @@ -198,7 +197,7 @@ class QuaggaBGPContainer(BGPContainer): c << 'bgp confederation peers {0}'.format(' '.join([str(i) for i in conf['member-as-list']])) version = 4 - for peer, info in self.peers.iteritems(): + for peer, info in self.peers.items(): version = netaddr.IPNetwork(info['neigh_addr']).version n_addr = info['neigh_addr'].split('/')[0] if version == 6: @@ -208,7 +207,7 @@ class QuaggaBGPContainer(BGPContainer): c << 'neighbor {0} advertisement-interval 1'.format(n_addr) if info['is_rs_client']: c << 'neighbor {0} route-server-client'.format(n_addr) - for typ, p in info['policies'].iteritems(): + for typ, p in info['policies'].items(): c << 'neighbor {0} route-map {1} {2}'.format(n_addr, p['name'], typ) if info['passwd']: @@ -228,7 +227,7 @@ class QuaggaBGPContainer(BGPContainer): else: c << 'redistribute connected' - for name, policy in self.policies.iteritems(): + for name, policy in self.policies.items(): c << 'access-list {0} {1} {2}'.format(name, policy['type'], policy['match']) c << 'route-map {0} permit 10'.format(name) @@ -242,8 +241,8 @@ class QuaggaBGPContainer(BGPContainer): c << 'log file {0}/bgpd.log'.format(self.SHARED_VOLUME) with open('{0}/bgpd.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new bgpd.conf]'.format(self.name)) - print colors.yellow(indent(str(c))) + print(yellow('[{0}\'s new bgpd.conf]'.format(self.name))) + print(yellow(indent(str(c)))) f.writelines(str(c)) def _create_config_zebra(self): @@ -258,9 +257,10 @@ class QuaggaBGPContainer(BGPContainer): c << '' with open('{0}/zebra.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new zebra.conf]'.format(self.name)) - print colors.yellow(indent(str(c))) - f.writelines(str(c)) + print(yellow('[{0}\'s new zebra.conf]'.format(self.name))) + c = str(c).strip() + print(yellow(indent(c))) + f.writelines(c) def vtysh(self, cmd, config=True): if not isinstance(cmd, list): @@ -420,8 +420,8 @@ class RawQuaggaBGPContainer(QuaggaBGPContainer): def create_config(self): with open('{0}/bgpd.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new bgpd.conf]'.format(self.name)) - print colors.yellow(indent(self.config)) + print(yellow('[{0}\'s new bgpd.conf]'.format(self.name))) + print(yellow(indent(self.config))) f.writelines(self.config) @@ -478,7 +478,7 @@ class QuaggaOSPFContainer(OSPFContainer): c = CmdBuffer() c << 'hostname zebra' c << 'password zebra' - for name, settings in self.zebra_config.get('interfaces', {}).items(): + for name, settings in list(self.zebra_config.get('interfaces', {}).items()): c << 'interface {0}'.format(name) for setting in settings: c << str(setting) @@ -492,9 +492,10 @@ class QuaggaOSPFContainer(OSPFContainer): c << '' with open('{0}/zebra.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new zebra.conf]'.format(self.name)) - print colors.yellow(indent(str(c))) - f.writelines(str(c)) + print(yellow('[{0}\'s new zebra.conf]'.format(self.name))) + c = str(c).strip() + print(yellow(indent(c))) + f.writelines(c) def _create_config_ospfd(self): c = CmdBuffer() @@ -503,15 +504,15 @@ class QuaggaOSPFContainer(OSPFContainer): c << 'router ospf' for redistribute in self.ospfd_config.get('redistributes', []): c << ' redistribute {0}'.format(redistribute) - for network, area in self.ospfd_config.get('networks', {}).items(): + for network, area in list(self.ospfd_config.get('networks', {}).items()): self.networks[network] = area # for superclass c << ' network {0} area {1}'.format(network, area) c << 'log file {0}/ospfd.log'.format(self.SHARED_VOLUME) c << '' with open('{0}/ospfd.conf'.format(self.config_dir), 'w') as f: - print colors.yellow('[{0}\'s new ospfd.conf]'.format(self.name)) - print colors.yellow(indent(str(c))) + print(yellow('[{0}\'s new ospfd.conf]'.format(self.name))) + print(yellow(indent(str(c)))) f.writelines(str(c)) def _start_zebra(self): diff --git a/test/lib/yabgp.py b/test/lib/yabgp.py index fb13620b..0f06c306 100644 --- a/test/lib/yabgp.py +++ b/test/lib/yabgp.py @@ -13,22 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import -from __future__ import print_function + + import json import os -from fabric import colors -from fabric.api import local -from fabric.utils import indent - from lib.base import ( FLOWSPEC_NAME_TO_TYPE, BGPContainer, CmdBuffer, try_several_times, wait_for_completion, + yellow, + indent, + local, ) @@ -47,7 +46,7 @@ class YABGPContainer(BGPContainer): import lib mod_dir = os.path.dirname(lib.__file__) local('docker cp {0}/yabgp_helper.py' - ' {1}:/root/'.format(mod_dir, self.name)) + ' {1}:/root/'.format(mod_dir, self.docker_name())) def _start_yabgp(self): self.local( @@ -80,7 +79,7 @@ class YABGPContainer(BGPContainer): c << 'format = json' if self.peers: - info = next(iter(self.peers.values())) + info = next(iter(list(self.peers.values()))) remote_as = info['remote_as'] neigh_addr = info['neigh_addr'].split('/')[0] local_as = info['local_as'] or self.asn @@ -93,8 +92,8 @@ class YABGPContainer(BGPContainer): c << 'local_addr = {0}'.format(local_addr) with open('{0}/yabgp.ini'.format(self.config_dir), 'w') as f: - print(colors.yellow('[{0}\'s new yabgp.ini]'.format(self.name))) - print(colors.yellow(indent(str(c)))) + print(yellow('[{0}\'s new yabgp.ini]'.format(self.name))) + print(yellow(indent(str(c)))) f.writelines(str(c)) def reload_config(self): @@ -401,7 +400,7 @@ class YABGPContainer(BGPContainer): local_pref=None, identifier=None, reload_config=True): self.routes.setdefault(route, []) - for info in self.peers.values(): + for info in list(self.peers.values()): peer = info['neigh_addr'].split('/')[0] if rf in ['ipv4', 'ipv6']: @@ -449,7 +448,7 @@ class YABGPContainer(BGPContainer): return rf = withdraw['rf'] - for info in self.peers.values(): + for info in list(self.peers.values()): peer = info['neigh_addr'].split('/')[0] if rf in ['ipv4', 'ipv6']: diff --git a/test/lib/yabgp_helper.py b/test/lib/yabgp_helper.py index 287daeaa..e13a312f 100644 --- a/test/lib/yabgp_helper.py +++ b/test/lib/yabgp_helper.py @@ -1,7 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -from __future__ import absolute_import -from __future__ import print_function import json import logging |