Fixes uses of process_input

This commit is contained in:
Eric Windisch
2011-03-09 14:31:23 -05:00
parent 1d7358e703
commit 23369a63f4
3 changed files with 8 additions and 11 deletions

View File

@@ -131,7 +131,7 @@ def fetchfile(url, target):
def execute(*cmd, **kwargs): def execute(*cmd, **kwargs):
process_input=kwargs.get('process_input', None) process_input=kwargs.get('process_input', None)
addl_env=kwargs.get('addl_env', None) addl_env=kwargs.get('addl_env', None)
check_exit_code=kwargs.get('check_exit_code', True) check_exit_code=kwargs.get('check_exit_code', 0)
stdin=kwargs.get('stdin', subprocess.PIPE) stdin=kwargs.get('stdin', subprocess.PIPE)
stdout=kwargs.get('stdout', subprocess.PIPE) stdout=kwargs.get('stdout', subprocess.PIPE)
stderr=kwargs.get('stderr', subprocess.PIPE) stderr=kwargs.get('stderr', subprocess.PIPE)
@@ -151,7 +151,7 @@ def execute(*cmd, **kwargs):
obj.stdin.close() obj.stdin.close()
if obj.returncode: if obj.returncode:
LOG.debug(_("Result was %s") % obj.returncode) LOG.debug(_("Result was %s") % obj.returncode)
if check_exit_code and obj.returncode != 0: if check_exit_code is not None and obj.returncode != check_exit_code:
(stdout, stderr) = result (stdout, stderr) = result
raise ProcessExecutionError(exit_code=obj.returncode, raise ProcessExecutionError(exit_code=obj.returncode,
stdout=stdout, stdout=stdout,

View File

@@ -175,8 +175,8 @@ def _inject_key_into_fs(key, fs):
utils.execute('sudo', 'chown', 'root', sshdir) utils.execute('sudo', 'chown', 'root', sshdir)
utils.execute('sudo', 'chmod', '700', sshdir) utils.execute('sudo', 'chmod', '700', sshdir)
keyfile = os.path.join(sshdir, 'authorized_keys') keyfile = os.path.join(sshdir, 'authorized_keys')
# TODO:EWINDISCH: not sure about the following /w execv patch utils.execute('sudo', 'tee', '-a', keyfile,
utils.execute('sudo', 'tee', '-a', keyfile, '\n' + key.strip() + '\n') process_input='\n' + key.strip() + '\n')
def _inject_net_into_fs(net, fs): def _inject_net_into_fs(net, fs):

View File

@@ -485,13 +485,10 @@ class LibvirtConnection(object):
port = random.randint(int(start_port), int(end_port)) port = random.randint(int(start_port), int(end_port))
# netcat will exit with 0 only if the port is in use, # netcat will exit with 0 only if the port is in use,
# so a nonzero return value implies it is unused # so a nonzero return value implies it is unused
cmd = 'netcat', '0.0.0.0', port, '-w', '1'
# TODO(ewindisch): broken /w execvp patch. try:
# subprocess lets us do this, but utils.execute stdout, stderr = utils.execute(*cmd, process_input='')
# abstracts it away from us except ProcessExecutionError:
cmd = 'netcat', '0.0.0.0', port, '-w', '1', '</dev/null || echo free' % (port)
stdout, stderr = utils.execute(cmd)
if stdout.strip() == 'free':
return port return port
raise Exception(_('Unable to find an open port')) raise Exception(_('Unable to find an open port'))