Browse Source

Replace subprocess with processutils

Trying to fix the dsvm-python3 job.

Depends-On: https://review.openstack.org/608620
Change-Id: Ibdfed9545a26e752ab7aeed2db122a368c3c06fb
tags/8.1.0
Kaifeng Wang 9 months ago
parent
commit
1ef55e3603
2 changed files with 13 additions and 17 deletions
  1. 10
    14
      ironic_inspector/pxe_filter/iptables.py
  2. 3
    3
      ironic_inspector/test/unit/test_iptables.py

+ 10
- 14
ironic_inspector/pxe_filter/iptables.py View File

@@ -15,7 +15,7 @@ import contextlib
15 15
 import os
16 16
 import re
17 17
 
18
-from eventlet.green import subprocess
18
+from oslo_concurrency import processutils
19 19
 from oslo_config import cfg
20 20
 from oslo_log import log
21 21
 
@@ -68,10 +68,9 @@ class IptablesFilter(pxe_filter.BaseFilter):
68 68
         # -w flag makes iptables wait for xtables lock, but it's not supported
69 69
         # everywhere yet
70 70
         try:
71
-            with open(os.devnull, 'wb') as null:
72
-                subprocess.check_call(self.base_command + ('-w', '-h'),
73
-                                      stderr=null, stdout=null)
74
-        except subprocess.CalledProcessError:
71
+            cmd = self.base_command + ('-w', '-h')
72
+            processutils.execute(*cmd)
73
+        except processutils.ProcessExecutionError:
75 74
             LOG.warning('iptables does not support -w flag, please update '
76 75
                         'it to at least version 1.4.21')
77 76
         else:
@@ -151,18 +150,15 @@ class IptablesFilter(pxe_filter.BaseFilter):
151 150
         cmd = self.base_command + args
152 151
         ignore = kwargs.pop('ignore', False)
153 152
         LOG.debug('Running iptables %s', args)
154
-        kwargs['stderr'] = subprocess.STDOUT
155 153
         try:
156
-            subprocess.check_output(cmd, **kwargs)
157
-        except subprocess.CalledProcessError as exc:
158
-            decoded_output = exc.output.decode("utf-8")
159
-            output = decoded_output.replace('\n', '. ')
154
+            processutils.execute(*cmd)
155
+        except processutils.ProcessExecutionError as exc:
160 156
             if ignore:
161
-                LOG.debug('Ignoring failed iptables %(args)s: %(output)s',
162
-                          {'args': args, 'output': output})
157
+                LOG.debug('Ignoring failed iptables %(args)s: %(error)s',
158
+                          {'args': args, 'error': exc})
163 159
             else:
164
-                LOG.error('iptables %(iptables)s failed: %(exc)s',
165
-                          {'iptables': args, 'exc': output})
160
+                LOG.error('iptables %(iptables)s failed: %(error)s',
161
+                          {'iptables': args, 'error': exc})
166 162
                 raise
167 163
 
168 164
     def _clean_up(self, chain):

+ 3
- 3
ironic_inspector/test/unit/test_iptables.py View File

@@ -37,7 +37,7 @@ class TestIptablesDriver(test_base.NodeTest):
37 37
         self.mock_fsm = self.useFixture(
38 38
             fixtures.MockPatchObject(iptables.IptablesFilter, 'fsm')).mock
39 39
         self.mock_call = self.useFixture(
40
-            fixtures.MockPatchObject(iptables.subprocess, 'check_call')).mock
40
+            fixtures.MockPatchObject(iptables.processutils, 'execute')).mock
41 41
         self.driver = iptables.IptablesFilter()
42 42
         self.mock_iptables = self.useFixture(
43 43
             fixtures.MockPatchObject(self.driver, '_iptables')).mock
@@ -73,8 +73,8 @@ class TestIptablesDriver(test_base.NodeTest):
73 73
         self.check_fsm([pxe_filter.Events.initialize])
74 74
 
75 75
     def test_init_args_old_iptables(self):
76
-        self.mock_call.side_effect = iptables.subprocess.CalledProcessError(
77
-            2, '')
76
+        exc = iptables.processutils.ProcessExecutionError(2, '')
77
+        self.mock_call.side_effect = exc
78 78
         self.driver.init_filter()
79 79
         init_expected_args = [
80 80
             ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',

Loading…
Cancel
Save