summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Goirand <zigo@debian.org>2018-08-30 10:20:02 +0200
committerThomas Goirand <zigo@debian.org>2018-08-30 10:22:19 +0200
commit2459cd853115f4ae2ea1e79f46cb98f76278491f (patch)
tree2384a3e48bef5bba84da9612838ce393f9409771
parent56138d8f06f531fadc184b0e0efa537c9ad66022 (diff)
Python 3.7: fix os.errno -> errno
In Python 3.7, there's no longer a os.errno, it's now available directly from the root instead. This patch therefore, tries to "import errno", and fallsback to "import os.errno as errno" if it fails. Then in the content of the code, we simply use the errno module directly. Change-Id: Ibf385ab32a8098e936c019303633de38a848076c
Notes
Notes (review): Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Code-Review+2: Kaifeng Wang <kaifeng.w@gmail.com> Workflow+1: Kaifeng Wang <kaifeng.w@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 31 Aug 2018 13:40:59 +0000 Reviewed-on: https://review.openstack.org/598082 Project: openstack/ironic-inspector Branch: refs/heads/master
-rw-r--r--ironic_inspector/pxe_filter/dnsmasq.py8
-rw-r--r--ironic_inspector/test/unit/test_dnsmasq_pxe_filter.py10
2 files changed, 13 insertions, 5 deletions
diff --git a/ironic_inspector/pxe_filter/dnsmasq.py b/ironic_inspector/pxe_filter/dnsmasq.py
index 5c7c56a..d96d887 100644
--- a/ironic_inspector/pxe_filter/dnsmasq.py
+++ b/ironic_inspector/pxe_filter/dnsmasq.py
@@ -20,6 +20,10 @@
20# http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html 20# http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html
21 21
22 22
23try:
24 import errno
25except ImportError:
26 import os.errno as errno
23import fcntl 27import fcntl
24import os 28import os
25import time 29import time
@@ -206,7 +210,7 @@ def _exclusive_write_or_pass(path, buf):
206 f.flush() 210 f.flush()
207 return True 211 return True
208 except IOError as e: 212 except IOError as e:
209 if e.errno == os.errno.EWOULDBLOCK: 213 if e.errno == errno.EWOULDBLOCK:
210 LOG.debug('%s locked; will try again (later)', path) 214 LOG.debug('%s locked; will try again (later)', path)
211 attempts -= 1 215 attempts -= 1
212 time.sleep(_EXCLUSIVE_WRITE_ATTEMPTS_DELAY) 216 time.sleep(_EXCLUSIVE_WRITE_ATTEMPTS_DELAY)
@@ -261,7 +265,7 @@ def _configure_unknown_hosts():
261 if os.stat(path).st_size == len(wildcard_filter): 265 if os.stat(path).st_size == len(wildcard_filter):
262 return 266 return
263 except OSError as e: 267 except OSError as e:
264 if e.errno != os.errno.ENOENT: 268 if e.errno != errno.ENOENT:
265 raise 269 raise
266 270
267 if _exclusive_write_or_pass(path, '%s' % wildcard_filter): 271 if _exclusive_write_or_pass(path, '%s' % wildcard_filter):
diff --git a/ironic_inspector/test/unit/test_dnsmasq_pxe_filter.py b/ironic_inspector/test/unit/test_dnsmasq_pxe_filter.py
index fdfbda8..2b9511b 100644
--- a/ironic_inspector/test/unit/test_dnsmasq_pxe_filter.py
+++ b/ironic_inspector/test/unit/test_dnsmasq_pxe_filter.py
@@ -11,6 +11,10 @@
11# See the License for the specific language governing permissions and 11# See the License for the specific language governing permissions and
12# limitations under the License. 12# limitations under the License.
13 13
14try:
15 import errno
16except ImportError:
17 import os.errno as errno
14import datetime 18import datetime
15import os 19import os
16 20
@@ -131,7 +135,7 @@ class TestExclusiveWriteOrPass(test_base.BaseTest):
131 135
132 def test_write_would_block(self): 136 def test_write_would_block(self):
133 err = IOError('Oops!') 137 err = IOError('Oops!')
134 err.errno = os.errno.EWOULDBLOCK 138 err.errno = errno.EWOULDBLOCK
135 # lock/unlock paired calls 139 # lock/unlock paired calls
136 self.mock_fcntl.side_effect = [ 140 self.mock_fcntl.side_effect = [
137 # first try 141 # first try
@@ -156,7 +160,7 @@ class TestExclusiveWriteOrPass(test_base.BaseTest):
156 'ironic_inspector.pxe_filter.dnsmasq._EXCLUSIVE_WRITE_ATTEMPTS', 160 'ironic_inspector.pxe_filter.dnsmasq._EXCLUSIVE_WRITE_ATTEMPTS',
157 1)) 161 1))
158 err = IOError('Oops!') 162 err = IOError('Oops!')
159 err.errno = os.errno.EWOULDBLOCK 163 err.errno = errno.EWOULDBLOCK
160 self.mock_fcntl.side_effect = [err, None] 164 self.mock_fcntl.side_effect = [err, None]
161 165
162 wrote = dnsmasq._exclusive_write_or_pass(self.path, self.buf) 166 wrote = dnsmasq._exclusive_write_or_pass(self.path, self.buf)
@@ -180,7 +184,7 @@ class TestExclusiveWriteOrPass(test_base.BaseTest):
180 def test_write_custom_ioerror(self): 184 def test_write_custom_ioerror(self):
181 185
182 err = IOError('Oops!') 186 err = IOError('Oops!')
183 err.errno = os.errno.EBADF 187 err.errno = errno.EBADF
184 self.mock_fcntl.side_effect = [err, None] 188 self.mock_fcntl.side_effect = [err, None]
185 189
186 self.assertRaisesRegex( 190 self.assertRaisesRegex(