execvp: almost passes tests
This commit is contained in:
@@ -343,7 +343,7 @@ def lease_ip(private_ip):
|
||||
private_ip)
|
||||
instance_ref = db.fixed_ip_get_instance(context.get_admin_context(),
|
||||
private_ip)
|
||||
cmd = (binpath('nova-dhcpbridge'), 'add'
|
||||
cmd = (binpath('nova-dhcpbridge'), 'add',
|
||||
instance_ref['mac_address'],
|
||||
private_ip, 'fake')
|
||||
env = {'DNSMASQ_INTERFACE': network_ref['bridge'],
|
||||
|
@@ -315,15 +315,16 @@ class IptablesFirewallTestCase(test.TestCase):
|
||||
instance_ref = db.instance_get(admin_ctxt, instance_ref['id'])
|
||||
|
||||
# self.fw.add_instance(instance_ref)
|
||||
def fake_iptables_execute(cmd, process_input=None):
|
||||
if cmd == 'sudo ip6tables-save -t filter':
|
||||
def fake_iptables_execute(*cmd, **kwargs):
|
||||
process_input=kwargs.get('process_input', None)
|
||||
if cmd == ('sudo', 'ip6tables-save', '-t', 'filter'):
|
||||
return '\n'.join(self.in6_rules), None
|
||||
if cmd == 'sudo iptables-save -t filter':
|
||||
if cmd == ('sudo', 'iptables-save', '-t', 'filter'):
|
||||
return '\n'.join(self.in_rules), None
|
||||
if cmd == 'sudo iptables-restore':
|
||||
if cmd == ('sudo', 'iptables-restore'):
|
||||
self.out_rules = process_input.split('\n')
|
||||
return '', ''
|
||||
if cmd == 'sudo ip6tables-restore':
|
||||
if cmd == ('sudo', 'ip6tables-restore'):
|
||||
self.out6_rules = process_input.split('\n')
|
||||
return '', ''
|
||||
self.fw.execute = fake_iptables_execute
|
||||
|
@@ -128,13 +128,20 @@ def fetchfile(url, target):
|
||||
execute("curl", "--fail", url, "-o", target)
|
||||
|
||||
|
||||
def execute(*cmd, process_input=None, addl_env=None, check_exit_code=True):
|
||||
def execute(*cmd, **kwargs):
|
||||
process_input=kwargs.get('process_input', None)
|
||||
addl_env=kwargs.get('addl_env', None)
|
||||
check_exit_code=kwargs.get('check_exit_code', True)
|
||||
stdin=kwargs.get('stdin', subprocess.PIPE)
|
||||
stdout=kwargs.get('stdout', subprocess.PIPE)
|
||||
stderr=kwargs.get('stderr', subprocess.PIPE)
|
||||
|
||||
LOG.debug(_("Running cmd (subprocess): %s"), ' '.join(cmd))
|
||||
env = os.environ.copy()
|
||||
if addl_env:
|
||||
env.update(addl_env)
|
||||
obj = subprocess.Popen(*cmd, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
|
||||
obj = subprocess.Popen(cmd, stdin=stdin,
|
||||
stdout=stdout, stderr=stderr, env=env)
|
||||
result = None
|
||||
if process_input != None:
|
||||
result = obj.communicate(process_input)
|
||||
@@ -220,9 +227,9 @@ def debug(arg):
|
||||
return arg
|
||||
|
||||
|
||||
def runthis(prompt, cmd, check_exit_code=True):
|
||||
LOG.debug(_("Running %s"), (cmd))
|
||||
rv, err = execute(cmd, check_exit_code=check_exit_code)
|
||||
def runthis(prompt, *cmd, **kwargs):
|
||||
LOG.debug(_("Running %s"), (" ".join(cmd)))
|
||||
rv, err = execute(*cmd, **kwargs)
|
||||
|
||||
|
||||
def generate_uid(topic, size=8):
|
||||
|
Reference in New Issue
Block a user