[node-patches] Change in ovirt-node[master]: Catch exceptions on EL6 for service calls
rbarry at redhat.com
rbarry at redhat.com
Thu Aug 15 17:00:48 UTC 2013
Ryan Barry has uploaded a new change for review.
Change subject: Catch exceptions on EL6 for service calls
......................................................................
Catch exceptions on EL6 for service calls
Previously, we relied on exceptions being thrown from subprocess
to flag a service as bad, but threw Python 2.6 to pipe(), which
never returns the expected exception. Wrap the calls instead
so we cannot save bad kdump configurations.
Change-Id: Ia353ddcb912a304f5a9caca7ed40581ee79a92bf
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=991375
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/setup/core/plugins_page.py
M src/ovirt/node/utils/process.py
2 files changed, 28 insertions(+), 8 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/90/18190/1
diff --git a/src/ovirt/node/setup/core/plugins_page.py b/src/ovirt/node/setup/core/plugins_page.py
index f43cf84..3626ddd 100644
--- a/src/ovirt/node/setup/core/plugins_page.py
+++ b/src/ovirt/node/setup/core/plugins_page.py
@@ -24,7 +24,6 @@
import glob
import os
import re
-from subprocess import CalledProcessError
"""
A plugin for a plugins page
@@ -151,7 +150,7 @@
r'NAME: (.*?) DATE: (.*?) INST: (.*)',
process.check_output(cmd, shell=True
).strip()).groups()
- except CalledProcessError:
+ except process.CalledProcessError:
continue
plugin_dict[name] = (ver, install_date)
diff --git a/src/ovirt/node/utils/process.py b/src/ovirt/node/utils/process.py
index a9eda35..0c43429 100644
--- a/src/ovirt/node/utils/process.py
+++ b/src/ovirt/node/utils/process.py
@@ -19,6 +19,7 @@
# MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.
from subprocess import STDOUT, PIPE
+import inspect
import logging
import subprocess
import sys
@@ -31,11 +32,27 @@
LOGGER = logging.getLogger(__name__)
COMMON_POPEN_ARGS = {
- "close_fds": True
+"close_fds": True
}
-CalledProcessError = subprocess.CalledProcessError
+class CalledProcessError(subprocess.CalledProcessError):
+ def __init__(self, returncode, cmd, output):
+ if 'output' in inspect.getargspec(
+ subprocess.CalledProcessError.__init__):
+ super(CalledProcessError, self).__init__(returncode, cmd, output)
+ else:
+ super(CalledProcessError, self).__init__(returncode, cmd)
+ self.output = output
+
+
+def wrap_exceptions(func):
+ def run(*args, **kwargs):
+ try:
+ func(*args, **kwargs)
+ except subprocess.CalledProcessError, e:
+ raise CalledProcessError(e.returncode, e.cmd, e.output)
+ return run
def __update_kwargs(kwargs):
new_kwargs = dict(COMMON_POPEN_ARGS)
@@ -50,7 +67,6 @@
LOGGER.debug("Popen with: %s %s" % (args, kwargs))
return subprocess.Popen(*args, **kwargs)
-
def call(*args, **kwargs):
"""subprocess.call wrapper to not leak file descriptors
"""
@@ -58,7 +74,7 @@
LOGGER.debug("Calling with: %s %s" % (args, kwargs))
return int(subprocess.call(*args, **kwargs))
-
+ at wrap_exceptions
def check_call(*args, **kwargs):
"""subprocess.check_call wrapper to not leak file descriptors
"""
@@ -66,7 +82,7 @@
LOGGER.debug("Checking call with: %s %s" % (args, kwargs))
return int(subprocess.check_call(*args, **kwargs))
-
+ at wrap_exceptions
def check_output(*args, **kwargs):
"""subprocess.check_output wrapper to not leak file descriptors
"""
@@ -96,4 +112,9 @@
kwargs.update({"stdin": PIPE,
"stdout": PIPE,
"stderr": STDOUT})
- return unicode(popen(cmd, **kwargs).communicate(stdin)[0])
+ process = popen(cmd, **kwargs)
+ output = unicode(process.communicate(stdin)[0])
+ if process.returncode == 0:
+ return output
+ else:
+ raise CalledProcessError(process.returncode, cmd, output)
--
To view, visit http://gerrit.ovirt.org/18190
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia353ddcb912a304f5a9caca7ed40581ee79a92bf
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>
More information about the node-patches
mailing list