Change in vdsm[master]: hooks: Extract function for command execution

mkolesni at redhat.com mkolesni at redhat.com
Fri Dec 20 11:05:55 UTC 2013


Mike Kolesnik has uploaded a new change for review.

Change subject: hooks: Extract function for command execution
......................................................................

hooks: Extract function for command execution

This function will be used by the openstacknet hook to execute commands
in a more convenient way, instead of repeating the logic to exit the
hook everywhere.

Change-Id: Id0bcc3be324d1afd9855f9d624cbe4efbf3cf6dd
Signed-off-by: Mike Kolesnik <mkolesni at redhat.com>
---
M vdsm_hooks/openstacknet/after_device_create.py
M vdsm_hooks/openstacknet/openstacknet_utils.py
2 files changed, 11 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/83/22583/1

diff --git a/vdsm_hooks/openstacknet/after_device_create.py b/vdsm_hooks/openstacknet/after_device_create.py
index be23a32..bdd1c22 100755
--- a/vdsm_hooks/openstacknet/after_device_create.py
+++ b/vdsm_hooks/openstacknet/after_device_create.py
@@ -33,17 +33,13 @@
 from openstacknet_utils import PROVIDER_TYPE_KEY
 from openstacknet_utils import PT_BRIDGE
 from openstacknet_utils import VNIC_ID_KEY
+from openstacknet_utils import executeOrExit
 from vdsm.constants import EXT_BRCTL
 
 
 def disconnectVnic(portId):
     tapName = ('tap' + portId)[:DEV_MAX_LENGTH]
-    command = [EXT_BRCTL, 'delif', DUMMY_BRIDGE, tapName]
-    retcode, out, err = hooking.execCmd(command, sudo=True, raw=True)
-
-    if retcode != 0:
-        hooking.exit_hook("Can't disconnect %s from %s, due to: %s"
-                          % (tapName, DUMMY_BRIDGE, err))
+    executeOrExit([EXT_BRCTL, 'delif', DUMMY_BRIDGE, tapName])
 
 
 def main():
diff --git a/vdsm_hooks/openstacknet/openstacknet_utils.py b/vdsm_hooks/openstacknet/openstacknet_utils.py
index d6c769b..36f6e0f 100644
--- a/vdsm_hooks/openstacknet/openstacknet_utils.py
+++ b/vdsm_hooks/openstacknet/openstacknet_utils.py
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import hooking
 from vdsm.netinfo import DUMMY_BRIDGE
 
 # Constants for hook's API
@@ -15,3 +16,11 @@
 
 # Make pyflakes happy
 DUMMY_BRIDGE
+
+
+def executeOrExit(command, expectSuccess=True):
+    retcode, out, err = hooking.execCmd(command, sudo=True, raw=True)
+    commandFailed = retcode != 0 if expectSuccess else retcode == 0
+    if commandFailed:
+        hooking.exit_hook("Failed to execute %s, due to: %s" %
+                          (str(command), err))


-- 
To view, visit http://gerrit.ovirt.org/22583
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id0bcc3be324d1afd9855f9d624cbe4efbf3cf6dd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mike Kolesnik <mkolesni at redhat.com>


More information about the vdsm-patches mailing list