commit cc8de6a5b26158dcc1d99cbc5c23f64ddaf533f1
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Mon Sep 29 16:08:28 2014 +0200
InterfaceManager: keep information about peered interfaces
Device object now know when they're paired with another interface (veth)
this is needed to properly deconfigure them when deconfiguration is not
coordinated by the controller.
This patch also adds the get_id_by_if_index method to the
InterfaceManager which is a helper function that implements the reverse
mapping of if_index to if_id.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Slave/InterfaceManager.py | 16 ++++++++++++++++
lnst/Slave/NetTestSlave.py | 11 +++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py
index fb191b0..81347a6 100644
--- a/lnst/Slave/InterfaceManager.py
+++ b/lnst/Slave/InterfaceManager.py
@@ -53,6 +53,12 @@ class InterfaceManager(object):
def clear_if_mapping(self):
self._id_mapping = {}
+ def get_id_by_if_index(self, if_index):
+ for if_id, index in self._id_mapping.iteritems():
+ if if_index == index:
+ return if_id
+ return None
+
def reconnect_netlink(self):
if self._nl_socket != None:
self._nl_socket.close()
@@ -173,6 +179,9 @@ class InterfaceManager(object):
device2.set_configuration(config2)
device1.create()
+ device1.set_peer(device2)
+ device2.set_peer(device1)
+
self._tmp_mapping[if_id1] = device1
self._tmp_mapping[if_id2] = device2
return name1, name2
@@ -248,6 +257,7 @@ class Device(object):
self._master = {"primary": None, "other": []}
self._slaves = []
self._netns = None
+ self._peer = None
self._if_manager = if_manager
@@ -332,6 +342,12 @@ class Device(object):
def get_conf_dict(self):
return self._conf_dict
+ def set_peer(self, dev):
+ self._peer = dev
+
+ def get_peer(self):
+ return self._peer
+
def set_configuration(self, conf):
self.clear_configuration()
if "name" not in conf or conf["name"] == None:
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 14d1d48..bd023cb 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -371,6 +371,17 @@ class SlaveMethods:
def machine_cleanup(self):
logging.info("Performing machine cleanup.")
self._command_context.cleanup()
+
+ devs = self._if_manager.get_mapped_devices()
+ for if_id, dev in devs.iteritems():
+ peer = dev.get_peer()
+ if peer == None:
+ dev.clear_configuration()
+ else:
+ peer_if_index = peer.get_if_index()
+ peer_id = self._if_manager.get_id_by_if_index(peer_if_index)
+ self.deconfigure_if_pair(if_id, peer_id)
+
self._if_manager.deconfigure_all()
for netns in self._net_namespaces.keys():