Change in vdsm[master]: move _kill_and_rm_pid to utils

ibarkan at redhat.com ibarkan at redhat.com
Mon Aug 31 10:19:16 UTC 2015


Ido Barkan has uploaded a new change for review.

Change subject: move _kill_and_rm_pid to utils
......................................................................

move _kill_and_rm_pid to utils

Further patches will use it in nettestlib.py

Change-Id: Ia459c02b63123dda081122a72b2517219978fc12
Signed-off-by: Ido Barkan <ibarkan at redhat.com>
---
M lib/vdsm/utils.py
M vdsm/network/configurators/dhclient.py
2 files changed, 15 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/45527/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index d847a23..e6ce981 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -1270,3 +1270,15 @@
         log.debug("%s: %.2f seconds", message, elapsed)
     else:
         yield
+
+
+def kill_and_rm_pid(pid, pid_file):
+    try:
+        os.kill(pid, signal.SIGTERM)
+    except OSError as e:
+        if e.errno == os.errno.ESRCH:  # Already exited
+            pass
+        else:
+            raise
+    if pid_file is not None:
+        rmFile(pid_file)
diff --git a/vdsm/network/configurators/dhclient.py b/vdsm/network/configurators/dhclient.py
index 181c302..0435584 100644
--- a/vdsm/network/configurators/dhclient.py
+++ b/vdsm/network/configurators/dhclient.py
@@ -22,7 +22,6 @@
 import errno
 import logging
 import os
-import signal
 import threading
 
 from vdsm import cmdutils
@@ -31,7 +30,7 @@
 from vdsm.utils import CommandPath
 from vdsm.utils import execCmd
 from vdsm.utils import pgrep
-from vdsm.utils import rmFile
+from vdsm.utils import kill_and_rm_pid
 
 DHCLIENT_CGROUP = 'vdsm-dhclient'
 LEASE_DIR = '/var/lib/dhclient'
@@ -90,7 +89,7 @@
             else:
                 raise
         else:
-            _kill_and_rm_pid(pid, self.pidFile)
+            kill_and_rm_pid(pid, self.pidFile)
 
 
 def kill_dhclient(device_name, family=4):
@@ -118,22 +117,10 @@
             continue
         logging.info('Stopping dhclient -%s before running our own on %s',
                      family, device_name)
-        _kill_and_rm_pid(pid, pid_file)
+        kill_and_rm_pid(pid, pid_file)
 
     #  In order to be able to configure the device with dhclient again. It is
     #  necessary that dhclient does not find it configured with any IP address
     #  (except 0.0.0.0 which is fine, or IPv6 link-local address needed for
     #   DHCPv6).
     ipwrapper.addrFlush(device_name, family)
-
-
-def _kill_and_rm_pid(pid, pid_file):
-    try:
-        os.kill(pid, signal.SIGTERM)
-    except OSError as e:
-        if e.errno == os.errno.ESRCH:  # Already exited
-            pass
-        else:
-            raise
-    if pid_file is not None:
-        rmFile(pid_file)


-- 
To view, visit https://gerrit.ovirt.org/45527
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia459c02b63123dda081122a72b2517219978fc12
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ido Barkan <ibarkan at redhat.com>


More information about the vdsm-patches mailing list