From 23ac6ebb861a725273c6b663dc484becef55087c Mon Sep 17 00:00:00 2001 From: Nasato Goto <7310510@gmail.com> Date: Mon, 27 Aug 2018 23:31:14 +0900 Subject: test/lib: Enable static IP address This patch enable us to give test containers a static IP address by passing 'ip_addr' argument to addif method. In addition, 'v6=True' argument is needed when we specify static IPv6 address. Usage: br01 = Bridge(name='br01', subnet='192.168.0.0/24', self_ip=False) g1 = GoBGPContainer(name='g1', asn=64512 router_id='10.0.0.1') br01.addif(g1, ip_addr='192.168.0.11') --- test/lib/base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/lib/base.py b/test/lib/base.py index 22ffcdee..f37c695d 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -226,10 +226,15 @@ class Bridge(object): return "{0}/{1}".format(self._ip_generator.next(), self.subnet.prefixlen) - def addif(self, ctn): + def addif(self, ctn, ip_addr=''): _name = ctn.next_if_name() self.ctns.append(ctn) - local("docker network connect {0} {1}".format(self.name, ctn.docker_name())) + ip = '' + if not ip_addr == '': + ip = '--ip {0}'.format(ip_addr) + 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] if self.subnet.version == 4: eth = 'eth{0}'.format(len(ctn.ip_addrs)) -- cgit v1.2.3