execvp passes pep8

This commit is contained in:
Eric Windisch
2011-03-09 15:33:20 -05:00
parent 23369a63f4
commit fc9840bae6
6 changed files with 30 additions and 23 deletions

View File

@@ -134,9 +134,9 @@ class XVPConsoleProxy(object):
logging.debug(_("Starting xvp")) logging.debug(_("Starting xvp"))
try: try:
utils.execute('xvp', utils.execute('xvp',
'-p',FLAGS.console_xvp_pid, '-p', FLAGS.console_xvp_pid,
'-c',FLAGS.console_xvp_conf, '-c', FLAGS.console_xvp_conf,
'-l',FLAGS.console_xvp_log) '-l', FLAGS.console_xvp_log)
except exception.ProcessExecutionError, err: except exception.ProcessExecutionError, err:
logging.error(_("Error starting xvp: %s") % err) logging.error(_("Error starting xvp: %s") % err)

View File

@@ -120,7 +120,8 @@ def generate_key_pair(bits=1024):
# bio = M2Crypto.BIO.MemoryBuffer() # bio = M2Crypto.BIO.MemoryBuffer()
# key.save_pub_key_bio(bio) # key.save_pub_key_bio(bio)
# public_key = bio.read() # public_key = bio.read()
# public_key, err = execute('ssh-keygen', '-y', '-f', '/dev/stdin', private_key) # public_key, err = execute('ssh-keygen', '-y', '-f',
# '/dev/stdin', private_key)
return (private_key, public_key, fingerprint) return (private_key, public_key, fingerprint)

View File

@@ -68,7 +68,8 @@ def metadata_forward():
_confirm_rule("PREROUTING", '-t', 'nat', '-s', '0.0.0.0/0', _confirm_rule("PREROUTING", '-t', 'nat', '-s', '0.0.0.0/0',
'-d', '169.254.169.254/32', '-p', 'tcp', '-m', 'tcp', '-d', '169.254.169.254/32', '-p', 'tcp', '-m', 'tcp',
'--dport', '80', '-j', 'DNAT', '--dport', '80', '-j', 'DNAT',
'--to-destination', '%s:%s' % (FLAGS.ec2_dmz_host, FLAGS.ec2_port)) '--to-destination',
'%s:%s' % (FLAGS.ec2_dmz_host, FLAGS.ec2_port))
def init_host(): def init_host():
@@ -86,7 +87,8 @@ def init_host():
_execute('sudo', 'iptables', '-D', 'FORWARD', '-j', 'nova_forward', _execute('sudo', 'iptables', '-D', 'FORWARD', '-j', 'nova_forward',
check_exit_code=False) check_exit_code=False)
_execute('sudo', 'iptables', '-A', 'FORWARD', '-j', 'nova_forward') _execute('sudo', 'iptables', '-A', 'FORWARD', '-j', 'nova_forward')
_execute('sudo', 'iptables', '-N', 'nova_output', check_exit_code=False) _execute('sudo', 'iptables', '-N', 'nova_output',
check_exit_code=False)
_execute('sudo', 'iptables', '-D', 'OUTPUT', '-j', 'nova_output', _execute('sudo', 'iptables', '-D', 'OUTPUT', '-j', 'nova_output',
check_exit_code=False) check_exit_code=False)
_execute('sudo', 'iptables', '-A', 'OUTPUT', '-j', 'nova_output') _execute('sudo', 'iptables', '-A', 'OUTPUT', '-j', 'nova_output')
@@ -237,7 +239,8 @@ def ensure_bridge(bridge, interface, net_attrs=None):
# bridge, then the bridge has to be in promiscuous # bridge, then the bridge has to be in promiscuous
# to forward packets properly. # to forward packets properly.
if(FLAGS.public_interface == bridge): if(FLAGS.public_interface == bridge):
_execute('sudo', 'ip', 'link', 'set', 'dev', bridge, 'promisc', 'on') _execute('sudo', 'ip', 'link', 'set',
'dev', bridge, 'promisc', 'on')
if interface: if interface:
# NOTE(vish): This will break if there is already an ip on the # NOTE(vish): This will break if there is already an ip on the
# interface, so we move any ips to the bridge # interface, so we move any ips to the bridge
@@ -253,8 +256,10 @@ def ensure_bridge(bridge, interface, net_attrs=None):
fields = line.split() fields = line.split()
if fields and fields[0] == "inet": if fields and fields[0] == "inet":
params = ' '.join(fields[1:-1]) params = ' '.join(fields[1:-1])
_execute('sudo', 'ip', 'addr', 'del', params, 'dev', fields[-1]) _execute('sudo', 'ip', 'addr',
_execute('sudo', 'ip', 'addr', 'add', params, 'dev', bridge) 'del', params, 'dev', fields[-1])
_execute('sudo', 'ip', 'addr',
'add', params, 'dev', bridge)
if gateway: if gateway:
_execute('sudo', 'route', 'add', '0.0.0.0', 'gw', gateway) _execute('sudo', 'route', 'add', '0.0.0.0', 'gw', gateway)
out, err = _execute('sudo', 'brctl', 'addif', bridge, interface, out, err = _execute('sudo', 'brctl', 'addif', bridge, interface,
@@ -397,7 +402,7 @@ def _device_exists(device):
def _confirm_rule(chain, *cmd, **kwargs): def _confirm_rule(chain, *cmd, **kwargs):
append=kwargs.get('append',False) append = kwargs.get('append', False)
"""Delete and re-add iptables rule""" """Delete and re-add iptables rule"""
if FLAGS.use_nova_chains: if FLAGS.use_nova_chains:
chain = "nova_%s" % chain.lower() chain = "nova_%s" % chain.lower()

View File

@@ -316,7 +316,7 @@ class IptablesFirewallTestCase(test.TestCase):
# self.fw.add_instance(instance_ref) # self.fw.add_instance(instance_ref)
def fake_iptables_execute(*cmd, **kwargs): def fake_iptables_execute(*cmd, **kwargs):
process_input=kwargs.get('process_input', None) process_input = kwargs.get('process_input', None)
if cmd == ('sudo', 'ip6tables-save', '-t', 'filter'): if cmd == ('sudo', 'ip6tables-save', '-t', 'filter'):
return '\n'.join(self.in6_rules), None return '\n'.join(self.in6_rules), None
if cmd == ('sudo', 'iptables-save', '-t', 'filter'): if cmd == ('sudo', 'iptables-save', '-t', 'filter'):

View File

@@ -40,7 +40,7 @@ import netaddr
from eventlet import event from eventlet import event
from eventlet import greenthread from eventlet import greenthread
from eventlet.green import subprocess from eventlet.green import subprocess
None
from nova import exception from nova import exception
from nova.exception import ProcessExecutionError from nova.exception import ProcessExecutionError
from nova import log as logging from nova import log as logging
@@ -129,13 +129,13 @@ 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', 0) 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)
cmd=map(str,cmd) cmd = map(str, cmd)
LOG.debug(_("Running cmd (subprocess): %s"), ' '.join(cmd)) LOG.debug(_("Running cmd (subprocess): %s"), ' '.join(cmd))
env = os.environ.copy() env = os.environ.copy()
@@ -151,7 +151,8 @@ 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 is not None and obj.returncode != check_exit_code: if type(check_exit_code) == types.IntType \
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

@@ -112,7 +112,7 @@ class VolumeDriver(object):
# If the volume isn't present, then don't attempt to delete # If the volume isn't present, then don't attempt to delete
return True return True
self._try_execute('sudo', 'lvremove', '-f',"%s/%s" % self._try_execute('sudo', 'lvremove', '-f', "%s/%s" %
(FLAGS.volume_group, (FLAGS.volume_group,
volume['name'])) volume['name']))
@@ -256,7 +256,7 @@ class ISCSIDriver(VolumeDriver):
self._sync_exec('sudo', 'ietadm', '--op', 'new', self._sync_exec('sudo', 'ietadm', '--op', 'new',
"--tid=%s" % iscsi_target, "--tid=%s" % iscsi_target,
'--params', '--params',
"Name=%s" % iscsi-name, "Name=%s" % iscsi_name,
check_exit_code=False) check_exit_code=False)
self._sync_exec('sudo', 'ietadm', '--op', 'new', self._sync_exec('sudo', 'ietadm', '--op', 'new',
"--tid=%s" % iscsi_target, "--tid=%s" % iscsi_target,