Switch to os.system instead of subprocess which is not thread-safe

This commit is contained in:
Dmitry Tantsur 2014-10-06 18:31:52 +02:00
parent 026a2f6859
commit bc28c27d75
1 changed files with 8 additions and 13 deletions

View File

@ -1,7 +1,7 @@
import ConfigParser
import logging
import os
import re
from subprocess import call, check_call
import threading
from ironicclient import client, exceptions
@ -139,20 +139,15 @@ class Firewall(object):
@staticmethod
def _iptables(*args, **kwargs):
cmd = ('iptables',) + args
cmd = ' '.join(('iptables',) + args)
LOG.debug('Running iptables %s', args)
if kwargs.pop('ignore', False):
if call(cmd, **kwargs):
LOG.warn('iptables failed: %s', args)
return False
# Would use subprocess if it was thread-safe
if os.system(cmd):
if not kwargs.pop('ignore', False):
raise RuntimeError('Failed to execute iptables %s' %
list(args))
else:
return True
else:
try:
return check_call(cmd, **kwargs)
except Exception:
LOG.error('iptables failed: %s', args)
raise
LOG.warn('iptables failed: %s', args)
@classmethod
def init(cls):