Delete both tunnel interfaces
We also clean things up a bit and check for error messages, which now can cause exceptions which should invoke cleanup.
This commit is contained in:
+16
-19
@@ -182,7 +182,7 @@ class RemoteMixin( object ):
|
|||||||
self.sshcmd += [ '-o', 'ControlPath=' + self.controlPath,
|
self.sshcmd += [ '-o', 'ControlPath=' + self.controlPath,
|
||||||
'-o', 'ControlMaster=auto',
|
'-o', 'ControlMaster=auto',
|
||||||
'-o', 'ControlPersist=' + '1' ]
|
'-o', 'ControlPersist=' + '1' ]
|
||||||
self.sshcmd = self.sshcmd + [ self.dest ]
|
self.sshcmd += [ self.dest ]
|
||||||
self.isRemote = True
|
self.isRemote = True
|
||||||
else:
|
else:
|
||||||
self.dest = None
|
self.dest = None
|
||||||
@@ -361,9 +361,12 @@ class RemoteLink( Link ):
|
|||||||
|
|
||||||
def stop( self ):
|
def stop( self ):
|
||||||
"Stop this link"
|
"Stop this link"
|
||||||
Link.stop( self )
|
|
||||||
if self.tunnel:
|
if self.tunnel:
|
||||||
self.tunnel.terminate()
|
self.tunnel.terminate()
|
||||||
|
self.intf1.delete()
|
||||||
|
self.intf2.delete()
|
||||||
|
else:
|
||||||
|
Link.stop( self )
|
||||||
self.tunnel = None
|
self.tunnel = None
|
||||||
|
|
||||||
def makeIntfPair( self, intfname1, intfname2, addr1=None, addr2=None,
|
def makeIntfPair( self, intfname1, intfname2, addr1=None, addr2=None,
|
||||||
@@ -417,12 +420,11 @@ class RemoteLink( Link ):
|
|||||||
# 1. Create tap interfaces
|
# 1. Create tap interfaces
|
||||||
for node in node1, node2:
|
for node in node1, node2:
|
||||||
# For now we are hard-wiring tap9, which we will rename
|
# For now we are hard-wiring tap9, which we will rename
|
||||||
node.rcmd( 'ip link delete tap9', stderr=PIPE )
|
|
||||||
cmd = 'ip tuntap add dev tap9 mode tap user ' + node.user
|
cmd = 'ip tuntap add dev tap9 mode tap user ' + node.user
|
||||||
node.rcmd( cmd )
|
result = node.rcmd( cmd )
|
||||||
links = node.rcmd( 'ip link show' )
|
if result:
|
||||||
# print 'after add, links =', links
|
raise Exception( 'error creating tap9 on %s: %s' %
|
||||||
assert 'tap9' in links
|
( node, result ) )
|
||||||
# 2. Create ssh tunnel between tap interfaces
|
# 2. Create ssh tunnel between tap interfaces
|
||||||
# -n: close stdin
|
# -n: close stdin
|
||||||
dest = '%s@%s' % ( node2.user, node2.serverIP )
|
dest = '%s@%s' % ( node2.user, node2.serverIP )
|
||||||
@@ -435,29 +437,24 @@ class RemoteLink( Link ):
|
|||||||
debug( 'Waiting for tunnel to come up...\n' )
|
debug( 'Waiting for tunnel to come up...\n' )
|
||||||
ch = tunnel.stdout.read( 1 )
|
ch = tunnel.stdout.read( 1 )
|
||||||
if ch != '@':
|
if ch != '@':
|
||||||
error( 'makeTunnel:\n',
|
raise Exception( 'makeTunnel:\n',
|
||||||
'Tunnel setup failed for',
|
'Tunnel setup failed for',
|
||||||
'%s:%s' % ( node1, node1.dest ), 'to',
|
'%s:%s' % ( node1, node1.dest ), 'to',
|
||||||
'%s:%s\n' % ( node2, node2.dest ),
|
'%s:%s\n' % ( node2, node2.dest ),
|
||||||
'command was:', cmd, '\n' )
|
'command was:', cmd, '\n' )
|
||||||
tunnel.terminate()
|
|
||||||
tunnel.wait()
|
|
||||||
error( ch + tunnel.stdout.read() )
|
|
||||||
error( tunnel.stderr.read() )
|
|
||||||
sys.exit( 1 )
|
|
||||||
# 3. Move interfaces if necessary
|
# 3. Move interfaces if necessary
|
||||||
for node in node1, node2:
|
for node in node1, node2:
|
||||||
if node.inNamespace:
|
if not self.moveIntf( 'tap9', node ):
|
||||||
retry( 3, .01, RemoteLink.moveIntf, 'tap9', node )
|
raise Exception( 'interface move failed on node %s' % node )
|
||||||
# 4. Rename tap interfaces to desired names
|
# 4. Rename tap interfaces to desired names
|
||||||
for node, intf, addr in ( ( node1, intfname1, addr1 ),
|
for node, intf, addr in ( ( node1, intfname1, addr1 ),
|
||||||
( node2, intfname2, addr2 ) ):
|
( node2, intfname2, addr2 ) ):
|
||||||
if not addr:
|
if not addr:
|
||||||
node.cmd( 'ip link set tap9 name', intf )
|
result = node.cmd( 'ip link set tap9 name', intf )
|
||||||
else:
|
else:
|
||||||
node.cmd( 'ip link set tap9 name', intf, 'address', addr )
|
result = node.cmd( 'ip link set tap9 name', intf, 'address', addr )
|
||||||
for node, intf in ( ( node1, intfname1 ), ( node2, intfname2 ) ):
|
if result:
|
||||||
assert intf in node.cmd( 'ip link show' )
|
raise Exception( 'error renaming %s: %s' % ( intf, result ) )
|
||||||
return tunnel
|
return tunnel
|
||||||
|
|
||||||
def status( self ):
|
def status( self ):
|
||||||
|
|||||||
Reference in New Issue
Block a user