diff options
-rw-r--r-- | test/lib/base.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/test/lib/base.py b/test/lib/base.py index 5cc08c0c..5ccf952e 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -60,7 +60,7 @@ def try_several_times(f, t=3, s=1): def get_bridges(): - return try_several_times(lambda : local("brctl show | awk 'NR > 1{print $1}'", capture=True)).split('\n') + return try_several_times(lambda : local("docker network ls | awk 'NR > 1{print $2}'", capture=True)).split('\n') def get_containers(): @@ -121,9 +121,11 @@ class Bridge(object): def f(): if self.name in get_bridges(): self.delete() - local("ip link add {0} type bridge".format(self.name)) + v6 = '' + if self.subnet.version == 6: + v6 = '--ipv6' + self.id = local('docker network create --driver bridge {0} --subnet {1} {2}'.format(v6, subnet, self.name), capture=True) try_several_times(f) - try_several_times(lambda : local("ip link set up dev {0}".format(self.name))) self.self_ip = self_ip if self_ip: @@ -138,15 +140,16 @@ class Bridge(object): def addif(self, ctn): name = ctn.next_if_name() self.ctns.append(ctn) - if self.with_ip: - - ctn.pipework(self, self.next_ip_address(), name) + local("docker network connect {0} {1}".format(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: + addr = i['IPv4Address'] else: - ctn.pipework(self, '0/0', name) + addr = i['IPv6Address'] + ctn.ip_addrs.append(('eth1', addr, self.name)) def delete(self): - try_several_times(lambda : local("ip link set down dev {0}".format(self.name))) - try_several_times(lambda : local("ip link delete {0} type bridge".format(self.name))) + try_several_times(lambda : local("docker network rm {0}".format(self.name))) class Container(object): |