From 2a89883297f6b5398abb7486e9e26c12ab0fc0ec Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Fri, 5 Aug 2011 14:02:55 +0200 Subject: Remove spurious direct use of subprocess --- nova/utils.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 1e2dbebb1..3a2049464 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -137,6 +137,8 @@ def execute(*cmd, **kwargs): :delay_on_retry True | False. Defaults to True. If set to True, wait a short amount of time before retrying. :attempts How many times to retry cmd. + :shell True | False. Defaults to False. If set to True, + Popen command is called shell=True. :raises exception.Error on receiving unknown arguments :raises exception.ProcessExecutionError @@ -147,6 +149,7 @@ def execute(*cmd, **kwargs): check_exit_code = kwargs.pop('check_exit_code', 0) delay_on_retry = kwargs.pop('delay_on_retry', True) attempts = kwargs.pop('attempts', 1) + shell = kwargs.pop('shell', False) if len(kwargs): raise exception.Error(_('Got unknown keyword args ' 'to utils.execute: %r') % kwargs) @@ -164,6 +167,7 @@ def execute(*cmd, **kwargs): stdin=_PIPE, stdout=_PIPE, stderr=_PIPE, + shell=shell, env=env) result = None if process_input is not None: -- cgit From ecdb1c87fb3904080d48f3fd3b3619f6c4a40df9 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Fri, 5 Aug 2011 14:33:12 +0200 Subject: Add run_as_root parameter to utils.execute, uses new sudo_helper FLAG to prefix command --- nova/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 3a2049464..0820a2bde 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -28,6 +28,7 @@ import netaddr import os import random import re +import shlex import socket import struct import sys @@ -139,6 +140,9 @@ def execute(*cmd, **kwargs): :attempts How many times to retry cmd. :shell True | False. Defaults to False. If set to True, Popen command is called shell=True. + :run_as_root True | False. Defaults to False. If set to True, + the command is prefixed by the command specified + in the sudo_helper FLAG. :raises exception.Error on receiving unknown arguments :raises exception.ProcessExecutionError @@ -150,9 +154,13 @@ def execute(*cmd, **kwargs): delay_on_retry = kwargs.pop('delay_on_retry', True) attempts = kwargs.pop('attempts', 1) shell = kwargs.pop('shell', False) + run_as_root = kwargs.pop('run_as_root', False) if len(kwargs): raise exception.Error(_('Got unknown keyword args ' 'to utils.execute: %r') % kwargs) + + if run_as_root: + cmd = shlex.split(FLAGS.sudo_helper) + cmd cmd = map(str, cmd) while attempts > 0: -- cgit From 2a8cff40af58d6d2b2fc3a818816eb2a913cccfb Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Tue, 9 Aug 2011 11:22:32 +0100 Subject: Fix ajaxterm's use of shell=True, prevent vmops.py from running its own version of utils.execute --- nova/utils.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 0820a2bde..7f27c5fd5 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -138,8 +138,6 @@ def execute(*cmd, **kwargs): :delay_on_retry True | False. Defaults to True. If set to True, wait a short amount of time before retrying. :attempts How many times to retry cmd. - :shell True | False. Defaults to False. If set to True, - Popen command is called shell=True. :run_as_root True | False. Defaults to False. If set to True, the command is prefixed by the command specified in the sudo_helper FLAG. @@ -153,7 +151,6 @@ def execute(*cmd, **kwargs): check_exit_code = kwargs.pop('check_exit_code', 0) delay_on_retry = kwargs.pop('delay_on_retry', True) attempts = kwargs.pop('attempts', 1) - shell = kwargs.pop('shell', False) run_as_root = kwargs.pop('run_as_root', False) if len(kwargs): raise exception.Error(_('Got unknown keyword args ' @@ -175,7 +172,6 @@ def execute(*cmd, **kwargs): stdin=_PIPE, stdout=_PIPE, stderr=_PIPE, - shell=shell, env=env) result = None if process_input is not None: -- cgit From ed9ea0848e4c8e8220a7f3bc175d7855c88c84d0 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Tue, 9 Aug 2011 12:05:05 +0100 Subject: Use close_fds by default since it's good for you --- nova/utils.py | 1 + 1 file changed, 1 insertion(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 7f27c5fd5..d691481f8 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -172,6 +172,7 @@ def execute(*cmd, **kwargs): stdin=_PIPE, stdout=_PIPE, stderr=_PIPE, + close_fds=True, env=env) result = None if process_input is not None: -- cgit From 7e810e1f266daaa63167ea8412dc0416e88f688f Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Tue, 9 Aug 2011 12:21:28 +0100 Subject: Fix usage of sudo -E and addl_env in dnsmasq/radvd calls, remove addl_env support, fix fake_execute allowed kwargs --- nova/utils.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index d691481f8..dc81abdb9 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -132,7 +132,6 @@ def execute(*cmd, **kwargs): :cmd Passed to subprocess.Popen. :process_input Send to opened process. - :addl_env Added to the processes env. :check_exit_code Defaults to 0. Raise exception.ProcessExecutionError unless program exits with this code. :delay_on_retry True | False. Defaults to True. If set to True, wait a @@ -147,7 +146,6 @@ def execute(*cmd, **kwargs): """ process_input = kwargs.pop('process_input', None) - addl_env = kwargs.pop('addl_env', None) check_exit_code = kwargs.pop('check_exit_code', 0) delay_on_retry = kwargs.pop('delay_on_retry', True) attempts = kwargs.pop('attempts', 1) @@ -164,16 +162,12 @@ def execute(*cmd, **kwargs): attempts -= 1 try: LOG.debug(_('Running cmd (subprocess): %s'), ' '.join(cmd)) - env = os.environ.copy() - if addl_env: - env.update(addl_env) _PIPE = subprocess.PIPE # pylint: disable=E1101 obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE, stderr=_PIPE, - close_fds=True, - env=env) + close_fds=True) result = None if process_input is not None: result = obj.communicate(process_input) -- cgit From 446fb79eb0025ce50cac9fc5496d4e4840134bce Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Tue, 9 Aug 2011 13:30:06 +0100 Subject: Command args can be a tuple, convert them to list --- nova/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index dc81abdb9..80044e37d 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -155,7 +155,7 @@ def execute(*cmd, **kwargs): 'to utils.execute: %r') % kwargs) if run_as_root: - cmd = shlex.split(FLAGS.sudo_helper) + cmd + cmd = shlex.split(FLAGS.sudo_helper) + list(cmd) cmd = map(str, cmd) while attempts > 0: -- cgit From c1ac67222e18c5fe74a52aa864231d5311374816 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Tue, 9 Aug 2011 14:11:15 +0100 Subject: Rename sudo_helper FLAG into root_helper --- nova/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 80044e37d..46c329c85 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -139,7 +139,7 @@ def execute(*cmd, **kwargs): :attempts How many times to retry cmd. :run_as_root True | False. Defaults to False. If set to True, the command is prefixed by the command specified - in the sudo_helper FLAG. + in the root_helper FLAG. :raises exception.Error on receiving unknown arguments :raises exception.ProcessExecutionError @@ -155,7 +155,7 @@ def execute(*cmd, **kwargs): 'to utils.execute: %r') % kwargs) if run_as_root: - cmd = shlex.split(FLAGS.sudo_helper) + list(cmd) + cmd = shlex.split(FLAGS.root_helper) + list(cmd) cmd = map(str, cmd) while attempts > 0: -- cgit