From 4c2f36bfe006cb0ef89ca7a706223f30488a182e Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Tue, 3 Sep 2013 16:00:59 +1000 Subject: [PATCH] Use utils.execute instead of subprocess Removes rogue subprocess.Popen calls to make better use of nova.utils.execute where appropriate to benefit from the patches pushed into oslo. Fixes bug 1053382 Change-Id: Iaee5379edd51f215a51d55263196dd6c0d2de0c3 --- nova/tests/db/test_sqlite.py | 6 ++---- nova/virt/hyperv/pathutils.py | 5 +++-- nova/virt/hyperv/volumeutils.py | 10 +--------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/nova/tests/db/test_sqlite.py b/nova/tests/db/test_sqlite.py index 0383f058b111..1cedc5621749 100644 --- a/nova/tests/db/test_sqlite.py +++ b/nova/tests/db/test_sqlite.py @@ -20,11 +20,11 @@ """Test cases for sqlite-specific logic""" from nova import test +from nova import utils import os from sqlalchemy import create_engine from sqlalchemy import Column, BigInteger, String from sqlalchemy.ext.declarative import declarative_base -import subprocess class TestSqlite(test.TestCase): @@ -48,9 +48,7 @@ class TestSqlite(test.TestCase): get_schema_cmd = "sqlite3 %s '.schema'" % self.db_file engine = create_engine("sqlite:///%s" % self.db_file) base_class.metadata.create_all(engine) - process = subprocess.Popen(get_schema_cmd, shell=True, - stdout=subprocess.PIPE) - output, _ = process.communicate() + output, _ = utils.execute(get_schema_cmd, shell=True) self.assertFalse('BIGINT' in output, msg="column type BIGINT " "not converted to INTEGER in schema") diff --git a/nova/virt/hyperv/pathutils.py b/nova/virt/hyperv/pathutils.py index 53ac29673647..a9b44dd373ea 100644 --- a/nova/virt/hyperv/pathutils.py +++ b/nova/virt/hyperv/pathutils.py @@ -18,9 +18,9 @@ import os import shutil -from eventlet.green import subprocess from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging +from nova import utils from oslo.config import cfg LOG = logging.getLogger(__name__) @@ -68,7 +68,8 @@ class PathUtils(object): # shutil.copy(...) but still 20% slower than a shell copy. # It can be replaced with Win32 API calls to avoid the process # spawning overhead. - if subprocess.call(['cmd.exe', '/C', 'copy', '/Y', src, dest]): + output, ret = utils.execute('cmd.exe', '/C', 'copy', '/Y', src, dest) + if ret: raise IOError(_('The file copy from %(src)s to %(dest)s failed') % {'src': src, 'dest': dest}) diff --git a/nova/virt/hyperv/volumeutils.py b/nova/virt/hyperv/volumeutils.py index 2a64d6e0a698..a3d8e2027131 100644 --- a/nova/virt/hyperv/volumeutils.py +++ b/nova/virt/hyperv/volumeutils.py @@ -23,7 +23,6 @@ and storage repositories import time -from eventlet.green import subprocess from oslo.config import cfg from nova.openstack.common.gettextutils import _ @@ -40,14 +39,7 @@ class VolumeUtils(basevolumeutils.BaseVolumeUtils): super(VolumeUtils, self).__init__() def execute(self, *args, **kwargs): - _PIPE = subprocess.PIPE # pylint: disable=E1101 - proc = subprocess.Popen( - [args], - stdin=_PIPE, - stdout=_PIPE, - stderr=_PIPE, - ) - stdout_value, stderr_value = proc.communicate() + stdout_value, stderr_value = utils.execute(*args, **kwargs) if stdout_value.find('The operation completed successfully') == -1: raise vmutils.HyperVException(_('An error has occurred when ' 'calling the iscsi initiator: %s')