summaryrefslogtreecommitdiffhomepage
path: root/test/lib
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-09-12 23:07:44 -0700
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-09-12 23:07:44 -0700
commite8da11a5c45dd03da19d3358e2e6ff88f4046e14 (patch)
tree1362e423738a514d8ccbba2500255c4a9a6cf9a9 /test/lib
parent990ddcf304c2dbb766a612fd6b045f45abb2784a (diff)
test: use Docker's native network feature instead of pipework
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/base.py21
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):