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
This commit is contained in:
Joshua Hesketh
2013-09-03 16:00:59 +10:00
parent 8b5f0c9bee
commit 4c2f36bfe0
3 changed files with 6 additions and 15 deletions

View File

@@ -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")

View File

@@ -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})

View File

@@ -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')