summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaifeng Wang <kaifeng.w@gmail.com>2018-09-29 17:08:44 +0800
committerDmitry Tantsur <divius.inside@gmail.com>2018-10-08 11:45:25 +0200
commit1ef55e3603fd7bffebaf308a4ae3868de76172ce (patch)
tree36d272fd094b7f7604eb3b7f8a06cafe4861508c
parent4dc14000634db3b0768ba5cc1b9614b1122dd9df (diff)
Replace subprocess with processutils
Trying to fix the dsvm-python3 job. Depends-On: https://review.openstack.org/608620 Change-Id: Ibdfed9545a26e752ab7aeed2db122a368c3c06fb
Notes
Notes (review): Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Code-Review+1: Iury Gregory Melo Ferreira <iurygregory@gmail.com> Code-Review+2: Sam Betts <sam@code-smash.net> Workflow+1: Sam Betts <sam@code-smash.net> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 09 Oct 2018 17:41:06 +0000 Reviewed-on: https://review.openstack.org/606349 Project: openstack/ironic-inspector Branch: refs/heads/master
-rw-r--r--ironic_inspector/pxe_filter/iptables.py24
-rw-r--r--ironic_inspector/test/unit/test_iptables.py6
2 files changed, 13 insertions, 17 deletions
diff --git a/ironic_inspector/pxe_filter/iptables.py b/ironic_inspector/pxe_filter/iptables.py
index 44ba878..c4f1ad6 100644
--- a/ironic_inspector/pxe_filter/iptables.py
+++ b/ironic_inspector/pxe_filter/iptables.py
@@ -15,7 +15,7 @@ import contextlib
15import os 15import os
16import re 16import re
17 17
18from eventlet.green import subprocess 18from oslo_concurrency import processutils
19from oslo_config import cfg 19from oslo_config import cfg
20from oslo_log import log 20from oslo_log import log
21 21
@@ -68,10 +68,9 @@ class IptablesFilter(pxe_filter.BaseFilter):
68 # -w flag makes iptables wait for xtables lock, but it's not supported 68 # -w flag makes iptables wait for xtables lock, but it's not supported
69 # everywhere yet 69 # everywhere yet
70 try: 70 try:
71 with open(os.devnull, 'wb') as null: 71 cmd = self.base_command + ('-w', '-h')
72 subprocess.check_call(self.base_command + ('-w', '-h'), 72 processutils.execute(*cmd)
73 stderr=null, stdout=null) 73 except processutils.ProcessExecutionError:
74 except subprocess.CalledProcessError:
75 LOG.warning('iptables does not support -w flag, please update ' 74 LOG.warning('iptables does not support -w flag, please update '
76 'it to at least version 1.4.21') 75 'it to at least version 1.4.21')
77 else: 76 else:
@@ -151,18 +150,15 @@ class IptablesFilter(pxe_filter.BaseFilter):
151 cmd = self.base_command + args 150 cmd = self.base_command + args
152 ignore = kwargs.pop('ignore', False) 151 ignore = kwargs.pop('ignore', False)
153 LOG.debug('Running iptables %s', args) 152 LOG.debug('Running iptables %s', args)
154 kwargs['stderr'] = subprocess.STDOUT
155 try: 153 try:
156 subprocess.check_output(cmd, **kwargs) 154 processutils.execute(*cmd)
157 except subprocess.CalledProcessError as exc: 155 except processutils.ProcessExecutionError as exc:
158 decoded_output = exc.output.decode("utf-8")
159 output = decoded_output.replace('\n', '. ')
160 if ignore: 156 if ignore:
161 LOG.debug('Ignoring failed iptables %(args)s: %(output)s', 157 LOG.debug('Ignoring failed iptables %(args)s: %(error)s',
162 {'args': args, 'output': output}) 158 {'args': args, 'error': exc})
163 else: 159 else:
164 LOG.error('iptables %(iptables)s failed: %(exc)s', 160 LOG.error('iptables %(iptables)s failed: %(error)s',
165 {'iptables': args, 'exc': output}) 161 {'iptables': args, 'error': exc})
166 raise 162 raise
167 163
168 def _clean_up(self, chain): 164 def _clean_up(self, chain):
diff --git a/ironic_inspector/test/unit/test_iptables.py b/ironic_inspector/test/unit/test_iptables.py
index 4602a94..3053ead 100644
--- a/ironic_inspector/test/unit/test_iptables.py
+++ b/ironic_inspector/test/unit/test_iptables.py
@@ -37,7 +37,7 @@ class TestIptablesDriver(test_base.NodeTest):
37 self.mock_fsm = self.useFixture( 37 self.mock_fsm = self.useFixture(
38 fixtures.MockPatchObject(iptables.IptablesFilter, 'fsm')).mock 38 fixtures.MockPatchObject(iptables.IptablesFilter, 'fsm')).mock
39 self.mock_call = self.useFixture( 39 self.mock_call = self.useFixture(
40 fixtures.MockPatchObject(iptables.subprocess, 'check_call')).mock 40 fixtures.MockPatchObject(iptables.processutils, 'execute')).mock
41 self.driver = iptables.IptablesFilter() 41 self.driver = iptables.IptablesFilter()
42 self.mock_iptables = self.useFixture( 42 self.mock_iptables = self.useFixture(
43 fixtures.MockPatchObject(self.driver, '_iptables')).mock 43 fixtures.MockPatchObject(self.driver, '_iptables')).mock
@@ -73,8 +73,8 @@ class TestIptablesDriver(test_base.NodeTest):
73 self.check_fsm([pxe_filter.Events.initialize]) 73 self.check_fsm([pxe_filter.Events.initialize])
74 74
75 def test_init_args_old_iptables(self): 75 def test_init_args_old_iptables(self):
76 self.mock_call.side_effect = iptables.subprocess.CalledProcessError( 76 exc = iptables.processutils.ProcessExecutionError(2, '')
77 2, '') 77 self.mock_call.side_effect = exc
78 self.driver.init_filter() 78 self.driver.init_filter()
79 init_expected_args = [ 79 init_expected_args = [
80 ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67', 80 ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',