Skip to content

Commit

Permalink
Make netns exec call easier in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darkk committed Apr 12, 2016
1 parent 6375a4f commit e6bfa73
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def net_br(self):
self.net_br_gw()

def net_noext(self):
self.call('sudo ip netns exec {name} ip link set dev eth0 down')
self.call('sudo ip netns exec {name} ip route replace unreachable {dns}/32')
self.netcall('ip link set dev eth0 down')
self.netcall('ip route replace unreachable {dns}/32')

def net_br_gw(self):
self.call('sudo {pipework} br-{br} -i {intif} -l {vethif} {name} {ip4}/24@{gw4}')
Expand Down Expand Up @@ -96,6 +96,8 @@ def call(self, cmd):
check_call(self.fmt(cmd))
def do(self, cmd):
return self.output('sudo docker exec {sha} ' + cmd)
def netcall(self, cmd):
return self.output('sudo ip netns exec {name} ' + cmd)

class WebVM(VM):
def __init__(self):
Expand All @@ -112,15 +114,15 @@ def __init__(self, no):
cmd='/etc/squid3/squid-%d.conf' % no)
def net(self):
self.net_br_nogw()
self.call('sudo ip netns exec {name} ip route replace 10.0.0.0/16 via 10.0.1.1')
self.netcall('ip route replace 10.0.0.0/16 via 10.0.1.1')

class DanteVM(VM):
def __init__(self, no):
VM.__init__(self, 'dante-%d' % no, 'redsocks/dante', '10.0.1.%d' % (180 + no),
cmd='/etc/danted-%d.conf' % (1080 + no))
def net(self):
self.net_br_nogw()
self.call('sudo ip netns exec {name} ip route replace 10.0.0.0/16 via 10.0.1.1')
self.netcall('ip route replace 10.0.0.0/16 via 10.0.1.1')


class GwVM(VM):
Expand All @@ -132,7 +134,7 @@ def net_br(self):
self.ip4 = '10.0.8.1'
self.net_br_nogw()
del self.ip4
self.call('sudo ip netns exec {name} ip route replace unreachable 10.0.2.0/24')
self.netcall('ip route replace unreachable 10.0.2.0/24')

class TankVM(VM):
def __init__(self, no):
Expand All @@ -154,7 +156,7 @@ def net_br(self):
self.net_br_gw()
del self.ip4
for t in TANKS.values():
self.call('sudo ip netns exec {name} iptables -t nat -A PREROUTING --source 10.0.2.%d/32 --dest 10.0.1.0/24 -p tcp -j REDIRECT --to-port %d' % (t, 12340 + t - TANKS_BASE))
self.netcall('iptables -t nat -A PREROUTING --source 10.0.2.%d/32 --dest 10.0.1.0/24 -p tcp -j REDIRECT --to-port %d' % (t, 12340 + t - TANKS_BASE))

def pmap(l):
#return map(lambda x: x(), l)
Expand Down

0 comments on commit e6bfa73

Please sign in to comment.