diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-07-26 17:44:05 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-27 11:26:10 +0900 |
commit | 37800322eb5a0d0c3d95cf36926d49fd096d4172 (patch) | |
tree | 0c718f7d93be2e29afa01b507d990a0edbbcbd3c /test | |
parent | d9cbb32c3e917d5a208e58f49785da8fe3863e1c (diff) |
test: telnet to quagga from local network namespace
this is preparation for parallel execution of scenario tests
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'test')
-rw-r--r-- | test/scenario_test/lib/base.py | 6 | ||||
-rw-r--r-- | test/scenario_test/lib/quagga.py | 16 | ||||
-rw-r--r-- | test/scenario_test/pip-requires.txt | 1 |
3 files changed, 12 insertions, 11 deletions
diff --git a/test/scenario_test/lib/base.py b/test/scenario_test/lib/base.py index 66e610d9..721e1c1d 100644 --- a/test/scenario_test/lib/base.py +++ b/test/scenario_test/lib/base.py @@ -171,6 +171,12 @@ class Container(object): def local(self, cmd): return local("docker exec -it {0} {1}".format(self.name, cmd)) + def get_pid(self): + if self.is_running: + cmd = "docker inspect -f '{{.State.Pid}}' " + self.name + return int(local(cmd, capture=True)) + return -1 + class BGPContainer(Container): diff --git a/test/scenario_test/lib/quagga.py b/test/scenario_test/lib/quagga.py index 5141ff7d..0346768f 100644 --- a/test/scenario_test/lib/quagga.py +++ b/test/scenario_test/lib/quagga.py @@ -15,6 +15,7 @@ from base import * import telnetlib +from nsenter import Namespace class QuaggaTelnetDaemon(object): @@ -22,19 +23,11 @@ class QuaggaTelnetDaemon(object): TELNET_PORT = 2605 def __init__(self, ctn): - ip_addr = None - for _, ip_addr, br in ctn.ip_addrs: - if br.ip_addr: - break - - if not ip_addr: - Exception('quagga telnet daemon {0}' - ' is not ip reachable'.format(self.name)) - - self.host = ip_addr.split('/')[0] + self.ns = Namespace(ctn.get_pid(), 'net') def __enter__(self): - self.tn = telnetlib.Telnet(self.host, self.TELNET_PORT) + self.ns.__enter__() + self.tn = telnetlib.Telnet('127.0.0.1', self.TELNET_PORT) self.tn.read_until("Password: ") self.tn.write(self.TELNET_PASSWORD + "\n") self.tn.write("enable\n") @@ -43,6 +36,7 @@ class QuaggaTelnetDaemon(object): def __exit__(self, type, value, traceback): self.tn.close() + self.ns.__exit__(type, value, traceback) class QuaggaBGPContainer(BGPContainer): diff --git a/test/scenario_test/pip-requires.txt b/test/scenario_test/pip-requires.txt index b02d2c63..f8157aed 100644 --- a/test/scenario_test/pip-requires.txt +++ b/test/scenario_test/pip-requires.txt @@ -5,3 +5,4 @@ ecdsa pycrypto>=2.1 fabric netaddr +nsenter |