diff options
-rw-r--r-- | test/scenario_test/bgp_router_test.py | 2 | ||||
-rw-r--r-- | test/scenario_test/ibgp_router_test.py | 2 | ||||
-rw-r--r-- | test/scenario_test/lib/base.py | 27 | ||||
-rw-r--r-- | test/scenario_test/lib/gobgp.py | 51 | ||||
-rw-r--r-- | test/scenario_test/lib/quagga.py | 4 | ||||
-rw-r--r-- | test/scenario_test/noseplugin.py | 1 |
6 files changed, 43 insertions, 44 deletions
diff --git a/test/scenario_test/bgp_router_test.py b/test/scenario_test/bgp_router_test.py index 521c6af5..dbbc2c2b 100644 --- a/test/scenario_test/bgp_router_test.py +++ b/test/scenario_test/bgp_router_test.py @@ -15,6 +15,7 @@ import unittest from fabric.api import local +from lib import base from lib.gobgp import * from lib.quagga import * import sys @@ -30,6 +31,7 @@ class GoBGPTestBase(unittest.TestCase): @classmethod def setUpClass(cls): gobgp_ctn_image_name = parser_option.gobgp_image + base.TEST_PREFIX = parser_option.test_prefix g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1', ctn_image_name=gobgp_ctn_image_name, diff --git a/test/scenario_test/ibgp_router_test.py b/test/scenario_test/ibgp_router_test.py index 567d8687..9cdd850a 100644 --- a/test/scenario_test/ibgp_router_test.py +++ b/test/scenario_test/ibgp_router_test.py @@ -15,6 +15,7 @@ import unittest from fabric.api import local +from lib import base from lib.gobgp import * from lib.quagga import * import sys @@ -30,6 +31,7 @@ class GoBGPTestBase(unittest.TestCase): @classmethod def setUpClass(cls): gobgp_ctn_image_name = parser_option.gobgp_image + base.TEST_PREFIX = parser_option.test_prefix g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1', ctn_image_name=gobgp_ctn_image_name, diff --git a/test/scenario_test/lib/base.py b/test/scenario_test/lib/base.py index 26a17834..11b77ca5 100644 --- a/test/scenario_test/lib/base.py +++ b/test/scenario_test/lib/base.py @@ -22,7 +22,9 @@ import os import time import itertools +DEFAULT_TEST_PREFIX = '' DEFAULT_TEST_BASE_DIR = '/tmp/gobgp' +TEST_PREFIX = DEFAULT_TEST_PREFIX TEST_BASE_DIR = DEFAULT_TEST_BASE_DIR BGP_FSM_IDLE = 'BGP_FSM_IDLE' @@ -83,7 +85,7 @@ def make_gobgp_ctn(tag='gobgp', local_gobgp_path=''): class Bridge(object): def __init__(self, name, subnet='', with_ip=True, self_ip=False): - self.name = name + self.name = '{0}_{1}'.format(TEST_PREFIX, name) self.with_ip = with_ip if with_ip: self.subnet = netaddr.IPNetwork(subnet) @@ -135,22 +137,27 @@ class Container(object): self.ip_addrs = [] self.is_running = False - if self.name in get_containers(): + if self.docker_name() in get_containers(): self.stop() + def docker_name(self): + if TEST_PREFIX == DEFAULT_TEST_PREFIX: + return self.name + return '{0}_{1}'.format(TEST_PREFIX, self.name) + def run(self): c = CmdBuffer(' ') c << "docker run --privileged=true" for sv in self.shared_volumes: c << "-v {0}:{1}".format(sv[0], sv[1]) - c << "--name {0} -id {1}".format(self.name, self.image) + c << "--name {0} -id {1}".format(self.docker_name(), self.image) self.id = local(str(c), capture=True) self.is_running = True self.local("ip li set up dev lo") return 0 def stop(self): - ret = local("docker rm -f " + self.name, capture=True) + ret = local("docker rm -f " + self.docker_name(), capture=True) self.is_running = False return ret @@ -165,16 +172,18 @@ class Container(object): c << "-i {0}".format(intf_name) else: intf_name = "eth1" - c << "{0} {1}".format(self.name, ip_addr) + c << "{0} {1}".format(self.docker_name(), ip_addr) self.ip_addrs.append((intf_name, ip_addr, bridge)) return local(str(c), capture=True) - def local(self, cmd): - return local("docker exec -it {0} {1}".format(self.name, cmd)) + def local(self, cmd, capture=False, flag=''): + return local("docker exec {0} {1} {2}".format(flag, + self.docker_name(), + cmd), capture) def get_pid(self): if self.is_running: - cmd = "docker inspect -f '{{.State.Pid}}' " + self.name + cmd = "docker inspect -f '{{.State.Pid}}' " + self.docker_name() return int(local(cmd, capture=True)) return -1 @@ -185,7 +194,7 @@ class BGPContainer(Container): RETRY_INTERVAL = 5 def __init__(self, name, asn, router_id, ctn_image_name): - self.config_dir = "{0}/{1}".format(TEST_BASE_DIR, name) + self.config_dir = '/'.join((TEST_BASE_DIR, TEST_PREFIX, name)) local('if [ -e {0} ]; then rm -r {0}; fi'.format(self.config_dir)) local('mkdir -p {0}'.format(self.config_dir)) self.asn = asn diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py index c56337cd..433d779e 100644 --- a/test/scenario_test/lib/gobgp.py +++ b/test/scenario_test/lib/gobgp.py @@ -42,9 +42,7 @@ class GoBGPContainer(BGPContainer): local(cmd, capture=True) cmd = "chmod 755 {0}/start.sh".format(self.config_dir) local(cmd, capture=True) - cmd = 'docker exec -d {0} {1}/start.sh'.format(self.name, - self.SHARED_VOLUME) - local(cmd, capture=True) + self.local("{0}/start.sh".format(self.SHARED_VOLUME), flag='-d') def run(self): super(GoBGPContainer, self).run() @@ -62,10 +60,8 @@ class GoBGPContainer(BGPContainer): if peer not in self.peers: raise Exception('not found peer {0}'.format(peer.router_id)) peer_addr = self.peers[peer]['neigh_addr'].split('/')[0] - cmd = "docker exec {0} gobgp neighbor {1} {2}".format(self.name, - peer_addr, - cmd) - local(str(cmd), capture=True) + cmd = 'gobgp neighbor {0} {1}'.format(peer_addr, cmd) + self.local(cmd) def disable_peer(self, peer): self._trigger_peer_cmd('disable', peer) @@ -77,32 +73,24 @@ class GoBGPContainer(BGPContainer): if peer not in self.peers: raise Exception('not found peer {0}'.format(peer.router_id)) peer_addr = self.peers[peer]['neigh_addr'].split('/')[0] - gobgp = '/go/bin/gobgp' - cmd = CmdBuffer(' ') - cmd << "docker exec {0} {1}".format(self.name, gobgp) - cmd << "-j neighbor {0} local -a {1}".format(peer_addr, rf) - output = local(str(cmd), capture=True) + cmd = 'gobgp -j neighbor {0} local -a {1}'.format(peer_addr, rf) + output = self.local(cmd, capture=True) n = json.loads(output) return n def get_global_rib(self, prefix='', rf='ipv4'): - gobgp = '/go/bin/gobgp' - cmd = 'docker exec {0} {1} -j global rib {2} -a {3}'.format(self.name, - gobgp, - prefix, - rf) - output = local(cmd, capture=True) + cmd = 'gobgp -j global rib {0} -a {1}'.format(prefix, rf) + output = self.local(cmd, capture=True) return json.loads(output) def _get_adj_rib(self, adj_type, peer, prefix='', rf='ipv4'): if peer not in self.peers: raise Exception('not found peer {0}'.format(peer.router_id)) peer_addr = self.peers[peer]['neigh_addr'].split('/')[0] - gobgp = '/go/bin/gobgp' - cmd = 'docker exec {0} {1} neighbor {2}'\ - ' adj-{3} {4} -a {5} -j'.format(self.name, gobgp, peer_addr, - adj_type, prefix, rf) - output = local(cmd, capture=True) + cmd = 'gobgp neighbor {0} adj-{1} {2} -a {3} -j'.format(peer_addr, + adj_type, + prefix, rf) + output = self.local(cmd, capture=True) return json.loads(output) def get_adj_rib_in(self, peer, prefix='', rf='ipv4'): @@ -115,11 +103,8 @@ class GoBGPContainer(BGPContainer): if peer not in self.peers: raise Exception('not found peer {0}'.format(peer.router_id)) peer_addr = self.peers[peer]['neigh_addr'].split('/')[0] - gobgp = '/go/bin/gobgp' - cmd = 'docker exec {0} {1} -j neighbor {2}'.format(self.name, - gobgp, - peer_addr) - output = local(cmd, capture=True) + cmd = 'gobgp -j neighbor {0}'.format(peer_addr) + output = self.local(cmd, capture=True) return json.loads(output)['info']['bgp_state'] def create_config(self): @@ -172,9 +157,9 @@ class GoBGPContainer(BGPContainer): f.write(toml.dumps(config)) def reload_config(self): - cmd = 'docker exec {0} /usr/bin/pkill gobgpd -SIGHUP'.format(self.name) - local(cmd, capture=True) + cmd = '/usr/bin/pkill gobgpd -SIGHUP' + self.local(cmd) for v in self.routes.itervalues(): - cmd = 'docker exec {0} gobgp global '\ - 'rib add {1} -a {2}'.format(self.name, v['prefix'], v['rf']) - local(cmd, capture=True) + cmd = 'gobgp global '\ + 'rib add {0} -a {1}'.format(v['prefix'], v['rf']) + self.local(cmd) diff --git a/test/scenario_test/lib/quagga.py b/test/scenario_test/lib/quagga.py index 0346768f..1099866a 100644 --- a/test/scenario_test/lib/quagga.py +++ b/test/scenario_test/lib/quagga.py @@ -189,5 +189,5 @@ class QuaggaBGPContainer(BGPContainer): f.writelines(str(c)) def reload_config(self): - cmd = 'docker exec {0} /usr/bin/pkill bgpd -SIGHUP'.format(self.name) - local(cmd, capture=True) + cmd = '/usr/bin/pkill bgpd -SIGHUP' + self.local(cmd) diff --git a/test/scenario_test/noseplugin.py b/test/scenario_test/noseplugin.py index 39929645..9da21e8a 100644 --- a/test/scenario_test/noseplugin.py +++ b/test/scenario_test/noseplugin.py @@ -8,6 +8,7 @@ class OptionParser(Plugin): def options(self, parser, env=os.environ): super(OptionParser, self).options(parser, env=env) + parser.add_option('--test-prefix', action="store", dest="test_prefix", default="") parser.add_option('--gobgp-image', action="store", dest="gobgp_image", default="osrg/gobgp") parser.add_option('--exabgp-path', action="store", dest="exabgp_path", default="") parser.add_option('--go-path', action="store", dest="go_path", default="") |