Enable ruff UP031
This is kept separate since it is a little more intricate. Change-Id: If340ff5c1e44a1b42fb2a34806d7e8a0164432ec Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
@@ -274,8 +274,8 @@ def forever_retry_uncaught_exceptions(*args, **kwargs):
|
|||||||
# The watch has expired or the exception message
|
# The watch has expired or the exception message
|
||||||
# changed, so time to log it again...
|
# changed, so time to log it again...
|
||||||
logging.exception(
|
logging.exception(
|
||||||
'Unexpected exception occurred %d time(s)... '
|
f'Unexpected exception occurred '
|
||||||
'retrying.' % same_failure_count
|
f'{same_failure_count} time(s)... retrying.'
|
||||||
)
|
)
|
||||||
if not watch.has_started():
|
if not watch.has_started():
|
||||||
watch.start()
|
watch.start()
|
||||||
|
@@ -792,7 +792,7 @@ class VHDXInspector(FileInspector):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if count >= 2048:
|
if count >= 2048:
|
||||||
raise ImageFormatError('Region count is %i (limit 2047)' % count)
|
raise ImageFormatError('Region count is {int(count)} (limit 2047)')
|
||||||
|
|
||||||
# Process the regions until we find the metadata one; grab the
|
# Process the regions until we find the metadata one; grab the
|
||||||
# offset and return
|
# offset and return
|
||||||
@@ -849,7 +849,7 @@ class VHDXInspector(FileInspector):
|
|||||||
|
|
||||||
if count >= 2048:
|
if count >= 2048:
|
||||||
raise ImageFormatError(
|
raise ImageFormatError(
|
||||||
'Metadata item count is %i (limit 2047)' % count
|
'Metadata item count is {int(count)} (limit 2047)'
|
||||||
)
|
)
|
||||||
|
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
@@ -1003,7 +1003,7 @@ class VMDKInspector(FileInspector):
|
|||||||
raise ImageFormatError(f'Signature KDMV not found: {sig!r}')
|
raise ImageFormatError(f'Signature KDMV not found: {sig!r}')
|
||||||
|
|
||||||
if ver not in (1, 2, 3):
|
if ver not in (1, 2, 3):
|
||||||
raise ImageFormatError('Unsupported format version %i' % ver)
|
raise ImageFormatError('Unsupported format version {int(ver)}')
|
||||||
|
|
||||||
if gdOffset == self.GD_AT_END and not self.has_region('footer'):
|
if gdOffset == self.GD_AT_END and not self.has_region('footer'):
|
||||||
# This means we have a footer, which takes precedence over the
|
# This means we have a footer, which takes precedence over the
|
||||||
@@ -1364,7 +1364,9 @@ class GPTInspector(FileInspector):
|
|||||||
sizelba,
|
sizelba,
|
||||||
) = struct.unpack('<B3BB3BII', pte)
|
) = struct.unpack('<B3BB3BII', pte)
|
||||||
if boot not in (0x00, 0x80):
|
if boot not in (0x00, 0x80):
|
||||||
raise SafetyViolation('MBR PTE %i has invalid boot flag' % i)
|
raise SafetyViolation(
|
||||||
|
f'MBR PTE {int(i)} has invalid boot flag'
|
||||||
|
)
|
||||||
if ostype != 0:
|
if ostype != 0:
|
||||||
valid_partitions.append(i)
|
valid_partitions.append(i)
|
||||||
if ostype == 0xEE:
|
if ostype == 0xEE:
|
||||||
@@ -1415,7 +1417,7 @@ class LUKSInspector(FileInspector):
|
|||||||
header = self.header_items
|
header = self.header_items
|
||||||
if header['version'] != 1:
|
if header['version'] != 1:
|
||||||
raise SafetyViolation(
|
raise SafetyViolation(
|
||||||
'LUKS version %i is not supported' % header['version']
|
f'LUKS version {int(header["version"])} is not supported'
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@@ -89,7 +89,7 @@ class TestFormatInspectors(test_base.BaseTestCase):
|
|||||||
fn = tempfile.mktemp(prefix=prefix, suffix='.iso')
|
fn = tempfile.mktemp(prefix=prefix, suffix='.iso')
|
||||||
self._created_files.append(fn)
|
self._created_files.append(fn)
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
'dd if=/dev/zero of=%s bs=1M count=%i' % (fn, size), shell=True
|
f'dd if=/dev/zero of={fn} bs=1M count={int(size)}', shell=True
|
||||||
)
|
)
|
||||||
# We need to use different file as input and output as the behavior
|
# We need to use different file as input and output as the behavior
|
||||||
# of mkisofs is version dependent if both the input and the output
|
# of mkisofs is version dependent if both the input and the output
|
||||||
@@ -140,7 +140,7 @@ class TestFormatInspectors(test_base.BaseTestCase):
|
|||||||
'-o',
|
'-o',
|
||||||
'key-secret=sec0',
|
'key-secret=sec0',
|
||||||
fn,
|
fn,
|
||||||
'%i' % image_size,
|
f'{int(image_size)}',
|
||||||
]
|
]
|
||||||
subprocess.check_output(' '.join(cmd), shell=True)
|
subprocess.check_output(' '.join(cmd), shell=True)
|
||||||
return fn
|
return fn
|
||||||
@@ -200,7 +200,7 @@ class TestFormatInspectors(test_base.BaseTestCase):
|
|||||||
fn = tempfile.mktemp(prefix=prefix, suffix=f'.{fmt}')
|
fn = tempfile.mktemp(prefix=prefix, suffix=f'.{fmt}')
|
||||||
self._created_files.append(fn)
|
self._created_files.append(fn)
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
'qemu-img create -f %s %s %s %i' % (fmt, opt, fn, size), shell=True
|
f'qemu-img create -f {fmt} {opt} {fn} {int(size)}', shell=True
|
||||||
)
|
)
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
@@ -223,13 +223,14 @@ class TestFormatInspectors(test_base.BaseTestCase):
|
|||||||
# Create a file with pseudo-random data, otherwise it will get
|
# Create a file with pseudo-random data, otherwise it will get
|
||||||
# compressed in the streamOptimized format
|
# compressed in the streamOptimized format
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
'dd if=/dev/urandom of=%s bs=1M count=%i' % (raw, size_mb),
|
f'dd if=/dev/urandom of={raw} bs=1M count={int(size_mb)}',
|
||||||
shell=True,
|
shell=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Convert it to VMDK
|
# Convert it to VMDK
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
f'qemu-img convert -f raw -O vmdk -o subformat={subformat} -S 0 {raw} {fn}',
|
f'qemu-img convert -f raw -O vmdk -o subformat={subformat} '
|
||||||
|
f'-S 0 {raw} {fn}',
|
||||||
shell=True,
|
shell=True,
|
||||||
)
|
)
|
||||||
return fn
|
return fn
|
||||||
@@ -287,14 +288,14 @@ class TestFormatInspectors(test_base.BaseTestCase):
|
|||||||
fmt = self._test_format_at_block_size(format_name, img, block_size)
|
fmt = self._test_format_at_block_size(format_name, img, block_size)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
fmt.format_match,
|
fmt.format_match,
|
||||||
'Failed to match %s at size %i block %i'
|
f'Failed to match {format_name} at '
|
||||||
% (format_name, image_size, block_size),
|
f'size {int(image_size)} block {int(block_size)}',
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
virtual_size,
|
virtual_size,
|
||||||
fmt.virtual_size,
|
fmt.virtual_size,
|
||||||
('Failed to calculate size for %s at size %i block %i')
|
f'Failed to calculate size for {format_name} at '
|
||||||
% (format_name, image_size, block_size),
|
f'size {int(image_size)} block {int(block_size)}',
|
||||||
)
|
)
|
||||||
memory = sum(fmt.context_info.values())
|
memory = sum(fmt.context_info.values())
|
||||||
self.assertLess(
|
self.assertLess(
|
||||||
@@ -481,14 +482,14 @@ class TestFormatInspectors(test_base.BaseTestCase):
|
|||||||
fmt = self._test_format_at_block_size(format_name, img, block_size)
|
fmt = self._test_format_at_block_size(format_name, img, block_size)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
fmt.format_match,
|
fmt.format_match,
|
||||||
'Failed to match %s at size %i block %i'
|
f'Failed to match {format_name} at '
|
||||||
% (format_name, image_size, block_size),
|
f'size {int(image_size)} block {int(block_size)}',
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
virtual_size,
|
virtual_size,
|
||||||
fmt.virtual_size,
|
fmt.virtual_size,
|
||||||
('Failed to calculate size for %s at size %i block %i')
|
f'Failed to calculate size for {format_name} at '
|
||||||
% (format_name, image_size, block_size),
|
f'size {int(image_size)} block {int(block_size)}',
|
||||||
)
|
)
|
||||||
memory = sum(fmt.context_info.values())
|
memory = sum(fmt.context_info.values())
|
||||||
self.assertLess(
|
self.assertLess(
|
||||||
|
@@ -132,10 +132,10 @@ class ImageUtilsHumanRawTestCase(test_base.BaseTestCase):
|
|||||||
)
|
)
|
||||||
for i in range(self.snapshot_count):
|
for i in range(self.snapshot_count):
|
||||||
img_info = img_info + (
|
img_info = img_info + (
|
||||||
'%d '
|
f'{i + 1} '
|
||||||
'd9a9784a500742a7bb95627bb3aace38 '
|
f'd9a9784a500742a7bb95627bb3aace38 '
|
||||||
'0 2012-08-20 10:52:46 '
|
f'0 2012-08-20 10:52:46 '
|
||||||
'00:00:00.000' % (i + 1),
|
f'00:00:00.000',
|
||||||
)
|
)
|
||||||
return img_info
|
return img_info
|
||||||
|
|
||||||
|
@@ -175,9 +175,7 @@ class ForeverRetryUncaughtExceptionsTest(test_base.BaseTestCase):
|
|||||||
@mock.patch.object(logging, 'exception')
|
@mock.patch.object(logging, 'exception')
|
||||||
@mock.patch.object(timeutils, 'now')
|
@mock.patch.object(timeutils, 'now')
|
||||||
def test_exc_retrier_1exc_gives_1log(self, mock_now, mock_log):
|
def test_exc_retrier_1exc_gives_1log(self, mock_now, mock_log):
|
||||||
self._exceptions = [
|
self._exceptions = [Exception('unexpected 1')]
|
||||||
Exception('unexpected %d' % 1),
|
|
||||||
]
|
|
||||||
mock_now.side_effect = [0]
|
mock_now.side_effect = [0]
|
||||||
|
|
||||||
self.exception_generator()
|
self.exception_generator()
|
||||||
@@ -185,7 +183,7 @@ class ForeverRetryUncaughtExceptionsTest(test_base.BaseTestCase):
|
|||||||
self.assertEqual([], self._exceptions)
|
self.assertEqual([], self._exceptions)
|
||||||
# log should only be called once
|
# log should only be called once
|
||||||
mock_log.assert_called_once_with(
|
mock_log.assert_called_once_with(
|
||||||
'Unexpected exception occurred %d time(s)... retrying.' % 1
|
'Unexpected exception occurred 1 time(s)... retrying.'
|
||||||
)
|
)
|
||||||
mock_now.assert_has_calls(
|
mock_now.assert_has_calls(
|
||||||
[
|
[
|
||||||
|
@@ -44,7 +44,6 @@ docstring-code-format = true
|
|||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = ["E4", "E7", "E9", "F", "S", "UP"]
|
select = ["E4", "E7", "E9", "F", "S", "UP"]
|
||||||
ignore = ["UP031"]
|
|
||||||
|
|
||||||
[tool.ruff.lint.per-file-ignores]
|
[tool.ruff.lint.per-file-ignores]
|
||||||
"oslo_utils/tests/*" = ["S"]
|
"oslo_utils/tests/*" = ["S"]
|
||||||
|
@@ -29,7 +29,7 @@ infile = 'large_json_payload.txt'
|
|||||||
|
|
||||||
with open(infile) as f:
|
with open(infile) as f:
|
||||||
input_str = f.read()
|
input_str = f.read()
|
||||||
print('payload has %d bytes' % len(input_str))
|
print(f'payload has {len(input_str)} bytes')
|
||||||
|
|
||||||
for pattern in strutils._SANITIZE_PATTERNS_2['admin_pass']:
|
for pattern in strutils._SANITIZE_PATTERNS_2['admin_pass']:
|
||||||
print(f'\ntesting {pattern.pattern}')
|
print(f'\ntesting {pattern.pattern}')
|
||||||
|
Reference in New Issue
Block a user