Merge "Python 3.7: fix os.errno -> errno" into stable/rocky

This commit is contained in:
Zuul 2018-09-24 21:53:00 +00:00 committed by Gerrit Code Review
commit e89450c44e
2 changed files with 13 additions and 5 deletions

View File

@ -20,6 +20,10 @@
# http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html
try:
import errno
except ImportError:
import os.errno as errno
import fcntl
import os
import time
@ -206,7 +210,7 @@ def _exclusive_write_or_pass(path, buf):
f.flush()
return True
except IOError as e:
if e.errno == os.errno.EWOULDBLOCK:
if e.errno == errno.EWOULDBLOCK:
LOG.debug('%s locked; will try again (later)', path)
attempts -= 1
time.sleep(_EXCLUSIVE_WRITE_ATTEMPTS_DELAY)
@ -261,7 +265,7 @@ def _configure_unknown_hosts():
if os.stat(path).st_size == len(wildcard_filter):
return
except OSError as e:
if e.errno != os.errno.ENOENT:
if e.errno != errno.ENOENT:
raise
if _exclusive_write_or_pass(path, '%s' % wildcard_filter):

View File

@ -11,6 +11,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
try:
import errno
except ImportError:
import os.errno as errno
import datetime
import os
@ -131,7 +135,7 @@ class TestExclusiveWriteOrPass(test_base.BaseTest):
def test_write_would_block(self):
err = IOError('Oops!')
err.errno = os.errno.EWOULDBLOCK
err.errno = errno.EWOULDBLOCK
# lock/unlock paired calls
self.mock_fcntl.side_effect = [
# first try
@ -156,7 +160,7 @@ class TestExclusiveWriteOrPass(test_base.BaseTest):
'ironic_inspector.pxe_filter.dnsmasq._EXCLUSIVE_WRITE_ATTEMPTS',
1))
err = IOError('Oops!')
err.errno = os.errno.EWOULDBLOCK
err.errno = errno.EWOULDBLOCK
self.mock_fcntl.side_effect = [err, None]
wrote = dnsmasq._exclusive_write_or_pass(self.path, self.buf)
@ -180,7 +184,7 @@ class TestExclusiveWriteOrPass(test_base.BaseTest):
def test_write_custom_ioerror(self):
err = IOError('Oops!')
err.errno = os.errno.EBADF
err.errno = errno.EBADF
self.mock_fcntl.side_effect = [err, None]
self.assertRaisesRegex(