commit 4b191254549b9730258c9cecf2073bc38c75e948
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Wed Aug 14 09:50:07 2013 +0200
NetTestSlave: update of slave cleanup
I didn't notice this before but we already had a method that did slave
cleanup. This commit makes a slight modification to the function and
makes use of it instead of calling the individual cleanup methods
themselves.
The cleanup process is now logged in DEBUG level, and I added detection
of server startup so that no cleanup happens when we didn't do anything
yet.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Common/NetTestCommand.py | 1 +
lnst/Slave/NetConfig.py | 1 +
lnst/Slave/NetConfigDevice.py | 1 +
lnst/Slave/NetTestSlave.py | 33 ++++++++++++++-------------------
4 files changed, 17 insertions(+), 19 deletions(-)
---
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index 08228d9..1d50c7c 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -218,6 +218,7 @@ class NetTestCommandContext:
self._dict[id].kill()
def cleanup(self):
+ logging.debug("Cleaning up leftover processes.")
self._kill_all_cmds()
self._dict = {}
diff --git a/lnst/Slave/NetConfig.py b/lnst/Slave/NetConfig.py
index cbb8487..f622848 100644
--- a/lnst/Slave/NetConfig.py
+++ b/lnst/Slave/NetConfig.py
@@ -104,6 +104,7 @@ class NetConfig:
device.deconfigure()
def deconfigure_all(self):
+ logging.debug("Deconfiguring interfaces.")
dev_order = self._get_dev_order()
for dev_id in reversed(dev_order):
self.deconfigure(dev_id)
diff --git a/lnst/Slave/NetConfigDevice.py b/lnst/Slave/NetConfigDevice.py
index 91dce5e..53e89b2 100644
--- a/lnst/Slave/NetConfigDevice.py
+++ b/lnst/Slave/NetConfigDevice.py
@@ -313,6 +313,7 @@ def NetConfigDeviceType(netdev, config):
return type_class_mapping[netdev["type"]]
def NetConfigDeviceAllCleanup():
+ logging.debug("Performing interface type cleanup.")
if check_process_running("NetworkManager") and \
lnst_config.get_option("environment", "use_nm"):
for dev_type in nm_type_class_mapping:
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index a3d7e66..629ed88 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -45,9 +45,9 @@ class SlaveMethods:
'''
Exported xmlrpc methods
'''
- def __init__(self, command_context, netconfig, log_ctl):
+ def __init__(self, command_context, log_ctl):
self._packet_captures = {}
- self._netconfig = netconfig
+ self._netconfig = NetConfig()
self._command_context = command_context
self._log_ctl = log_ctl
@@ -263,9 +263,11 @@ class SlaveMethods:
return True
def machine_cleanup(self):
- NetConfigDeviceAllCleanup()
- self._netconfig.cleanup()
+ logging.info("Performing machine cleanup.")
self._command_context.cleanup()
+ self._netconfig.deconfigure_all()
+ self._netconfig.cleanup()
+ NetConfigDeviceAllCleanup()
self._cache.del_old_entries()
self.restore_system_config()
return True
@@ -415,9 +417,7 @@ class NetTestSlave:
die_when_parent_die()
self._cmd_context = NetTestCommandContext()
- self._netconfig = NetConfig()
- self._methods = SlaveMethods(self._cmd_context, self._netconfig,
- log_ctl)
+ self._methods = SlaveMethods(self._cmd_context, log_ctl)
self.register_die_signal(signal.SIGHUP)
self.register_die_signal(signal.SIGINT)
@@ -429,21 +429,20 @@ class NetTestSlave:
self._log_ctl = log_ctl
+ self._start = True
+
def run(self):
while not self._finished:
if self._server_handler.get_ctl_sock() == None:
self._log_ctl.cancel_connection()
- logging.info("Waiting for connection, performing cleanup.")
- logging.info("Cleaning up leftover commands.")
- self._cmd_context.cleanup()
- logging.info("Cleaning up configured interfaces.")
- self._netconfig.deconfigure_all()
- self._netconfig.cleanup()
+ if not self._start:
+ self._methods.machine_cleanup()
try:
+ logging.info("Waiting for connection.")
self._server_handler.accept_connection()
+ self._start = False
except socket.error:
continue
- self._cmd_context.cleanup()
self._log_ctl.set_connection(
self._server_handler.get_ctl_sock())
@@ -452,11 +451,7 @@ class NetTestSlave:
for msg in msgs:
self._process_msg(msg[1])
- logging.info("Cleaning up leftover commands.")
- self._cmd_context.cleanup()
- logging.info("Cleaning up configured interfaces.")
- self._netconfig.deconfigure_all()
- self._netconfig.cleanup()
+ self._methods.machine_cleanup()
def _process_msg(self, msg):
if msg["type"] == "command":
Show replies by date