Fix pep8 errors with new hacking
Hacking has bumped the version of flake8 that it's using to 5.0 in its 6.0.1 release. This turns up quite a few pep8 errors lurking in our code. Fix them. Needed-by: https://review.opendev.org/c/openstack/hacking/+/874516 Change-Id: I3b9c7f9f5de757f818ec358c992ffb0e5f3e310f
This commit is contained in:
parent
439c672548
commit
faa1e64e5b
@ -700,9 +700,9 @@ def expected_errors(errors):
|
|||||||
|
|
||||||
LOG.exception("Unexpected exception in API method")
|
LOG.exception("Unexpected exception in API method")
|
||||||
msg = _("Unexpected API Error. "
|
msg = _("Unexpected API Error. "
|
||||||
"%(support)s\n%(exc)s" % {
|
"{support}\n{exc}").format(
|
||||||
'support': version.support_string(),
|
support=version.support_string(),
|
||||||
'exc': type(exc)})
|
exc=type(exc))
|
||||||
raise webob.exc.HTTPInternalServerError(explanation=msg)
|
raise webob.exc.HTTPInternalServerError(explanation=msg)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
@ -2604,7 +2604,7 @@ class PlacementCommands(object):
|
|||||||
# By default we suspect the orphaned allocation was for a
|
# By default we suspect the orphaned allocation was for a
|
||||||
# migration...
|
# migration...
|
||||||
consumer_type = 'migration'
|
consumer_type = 'migration'
|
||||||
if not(consumer_uuid in inst_uuids):
|
if consumer_uuid not in inst_uuids:
|
||||||
# ... but if we can't find it either for an instance,
|
# ... but if we can't find it either for an instance,
|
||||||
# that means it was for this.
|
# that means it was for this.
|
||||||
consumer_type = 'instance'
|
consumer_type = 'instance'
|
||||||
@ -2778,8 +2778,8 @@ class LibvirtCommands(object):
|
|||||||
print(mtype)
|
print(mtype)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
print(_('No machine type registered for instance %s' %
|
print(_('No machine type registered for instance %s') %
|
||||||
instance_uuid))
|
instance_uuid)
|
||||||
return 3
|
return 3
|
||||||
except (exception.InstanceNotFound,
|
except (exception.InstanceNotFound,
|
||||||
exception.InstanceMappingNotFound) as e:
|
exception.InstanceMappingNotFound) as e:
|
||||||
|
@ -229,8 +229,9 @@ def _load_yaml_file(path):
|
|||||||
if hasattr(ex, 'problem_mark'):
|
if hasattr(ex, 'problem_mark'):
|
||||||
pos = ex.problem_mark
|
pos = ex.problem_mark
|
||||||
message += _("File: %s ") % open_file.name
|
message += _("File: %s ") % open_file.name
|
||||||
message += _("Error position: (%s:%s)") % (
|
message += _("Error position: "
|
||||||
pos.line + 1, pos.column + 1)
|
"({line}:{column})").format(
|
||||||
|
line=pos.line + 1, column=pos.column + 1)
|
||||||
raise nova_exc.ProviderConfigException(error=message)
|
raise nova_exc.ProviderConfigException(error=message)
|
||||||
except OSError:
|
except OSError:
|
||||||
message = _("Unable to read yaml config file: %s") % path
|
message = _("Unable to read yaml config file: %s") % path
|
||||||
|
@ -110,10 +110,10 @@ class RFBAuthSchemeVeNCrypt(auth.RFBAuthScheme):
|
|||||||
# MITM'd Anonymous Diffie Hellmann (DH) cyphers)
|
# MITM'd Anonymous Diffie Hellmann (DH) cyphers)
|
||||||
if AuthVeNCryptSubtype.X509NONE not in sub_types:
|
if AuthVeNCryptSubtype.X509NONE not in sub_types:
|
||||||
reason = _(
|
reason = _(
|
||||||
"Server does not support the %d (%s) VeNCrypt auth subtype"
|
"Server does not support the {value} ({name}) "
|
||||||
) % (
|
"VeNCrypt auth subtype"
|
||||||
AuthVeNCryptSubtype.X509NONE.value,
|
).format(value=AuthVeNCryptSubtype.X509NONE.value,
|
||||||
AuthVeNCryptSubtype.X509NONE.name)
|
name=AuthVeNCryptSubtype.X509NONE.name)
|
||||||
raise exception.RFBAuthHandshakeFailed(reason=reason)
|
raise exception.RFBAuthHandshakeFailed(reason=reason)
|
||||||
|
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
|
@ -164,19 +164,17 @@ class RFBSecurityProxy(base.SecurityProxy):
|
|||||||
if client_auth != auth.AuthType.NONE:
|
if client_auth != auth.AuthType.NONE:
|
||||||
self._fail(
|
self._fail(
|
||||||
tenant_sock, compute_sock,
|
tenant_sock, compute_sock,
|
||||||
_("Only the security type %d (%s) is supported") % (
|
_("Only the security type {value} ({name}) "
|
||||||
auth.AuthType.NONE.value, auth.AuthType.NONE.name,
|
"is supported").format(value=auth.AuthType.NONE.value,
|
||||||
))
|
name=auth.AuthType.NONE.name))
|
||||||
|
|
||||||
reason = _(
|
reason = _(
|
||||||
"Client requested a security type other than %d (%s): "
|
"Client requested a security type other than "
|
||||||
"%d (%s)"
|
"{value} ({name}): {client_value} ({client_name})"
|
||||||
) % (
|
).format(value=auth.AuthType.NONE.value,
|
||||||
auth.AuthType.NONE.value,
|
name=auth.AuthType.NONE.name,
|
||||||
auth.AuthType.NONE.name,
|
client_value=auth.AuthType(client_auth).value,
|
||||||
auth.AuthType(client_auth).value,
|
client_name=auth.AuthType(client_auth).name)
|
||||||
auth.AuthType(client_auth).name,
|
|
||||||
)
|
|
||||||
raise exception.SecurityProxyNegotiationFailed(reason=reason)
|
raise exception.SecurityProxyNegotiationFailed(reason=reason)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -389,7 +389,8 @@ class GlanceImageServiceV2(object):
|
|||||||
|
|
||||||
def _verify_and_write(self, context, image_id, trusted_certs,
|
def _verify_and_write(self, context, image_id, trusted_certs,
|
||||||
image_chunks, data, dst_path):
|
image_chunks, data, dst_path):
|
||||||
"""Perform image signature verification and save the image file if needed.
|
"""Perform image signature verification and save the image file if
|
||||||
|
needed.
|
||||||
|
|
||||||
This function writes the content of the image_chunks iterator either to
|
This function writes the content of the image_chunks iterator either to
|
||||||
a file object provided by the data parameter or to a filepath provided
|
a file object provided by the data parameter or to a filepath provided
|
||||||
|
@ -437,7 +437,7 @@ def _get_by_host_from_db(context, host, key=None):
|
|||||||
|
|
||||||
@api_db_api.context_manager.reader
|
@api_db_api.context_manager.reader
|
||||||
def _get_by_metadata_from_db(context, key=None, value=None):
|
def _get_by_metadata_from_db(context, key=None, value=None):
|
||||||
assert(key is not None or value is not None)
|
assert key is not None or value is not None
|
||||||
query = context.session.query(api_models.Aggregate)
|
query = context.session.query(api_models.Aggregate)
|
||||||
query = query.join(api_models.Aggregate._metadata)
|
query = query.join(api_models.Aggregate._metadata)
|
||||||
if key is not None:
|
if key is not None:
|
||||||
|
@ -168,7 +168,7 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
|
|||||||
# gave this bdm a uuid
|
# gave this bdm a uuid
|
||||||
result = query.one()
|
result = query.one()
|
||||||
uuid = result['uuid']
|
uuid = result['uuid']
|
||||||
assert(uuid is not None)
|
assert uuid is not None
|
||||||
|
|
||||||
return uuid
|
return uuid
|
||||||
|
|
||||||
|
@ -49,8 +49,10 @@ class InstanceNUMACell(base.NovaEphemeralObject,
|
|||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='obj_make_compatible',
|
action='obj_make_compatible',
|
||||||
reason=_(
|
reason=_(
|
||||||
'%s policy is not supported in version %s'
|
'{policy} policy is not supported in '
|
||||||
) % (primitive['cpu_policy'], target_version))
|
'version {version}'
|
||||||
|
).format(policy=primitive['cpu_policy'],
|
||||||
|
version=target_version))
|
||||||
|
|
||||||
# NOTE(huaqiang): Since version 1.5, 'cpuset' is modified to track the
|
# NOTE(huaqiang): Since version 1.5, 'cpuset' is modified to track the
|
||||||
# unpinned CPUs only, with pinned CPUs tracked via 'pcpuset' instead.
|
# unpinned CPUs only, with pinned CPUs tracked via 'pcpuset' instead.
|
||||||
|
@ -82,7 +82,7 @@ class ImagePropertiesFilter(filters.BaseHostFilter):
|
|||||||
|
|
||||||
def _compare_product_version(hyper_version, image_props):
|
def _compare_product_version(hyper_version, image_props):
|
||||||
version_required = image_props.get('img_hv_requested_version')
|
version_required = image_props.get('img_hv_requested_version')
|
||||||
if not(hypervisor_version and version_required):
|
if not (hypervisor_version and version_required):
|
||||||
return True
|
return True
|
||||||
img_prop_predicate = versionpredicate.VersionPredicate(
|
img_prop_predicate = versionpredicate.VersionPredicate(
|
||||||
'image_prop (%s)' % version_required)
|
'image_prop (%s)' % version_required)
|
||||||
|
39
nova/tests/fixtures/__init__.py
vendored
39
nova/tests/fixtures/__init__.py
vendored
@ -10,22 +10,23 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from .api_paste import ApiPasteNoProjectId # noqa: F401
|
from .api_paste import ApiPasteNoProjectId # noqa: F401, H304
|
||||||
from .api_paste import ApiPasteV21Fixture # noqa: F401
|
from .api_paste import ApiPasteV21Fixture # noqa: F401, H304
|
||||||
from .cast_as_call import CastAsCallFixture # noqa: F401
|
from .cast_as_call import CastAsCallFixture # noqa: F401, H304
|
||||||
from .cinder import CinderFixture # noqa: F401
|
from .cinder import CinderFixture # noqa: F401, H304
|
||||||
from .conf import ConfFixture # noqa: F401, F403
|
from .conf import ConfFixture # noqa: F401, H304, F403
|
||||||
from .cyborg import CyborgFixture # noqa: F401
|
from .cyborg import CyborgFixture # noqa: F401, H304
|
||||||
from .filesystem import SysFileSystemFixture # noqa: F401
|
from .filesystem import SysFileSystemFixture # noqa: F401, H304
|
||||||
from .filesystem import TempFileSystemFixture # noqa: F401
|
from .filesystem import TempFileSystemFixture # noqa: F401, H304
|
||||||
from .glance import GlanceFixture # noqa: F401
|
from .glance import GlanceFixture # noqa: F401, H304
|
||||||
from .libvirt import LibvirtFixture # noqa: F401
|
from .libvirt import LibvirtFixture # noqa: F401, H304
|
||||||
from .libvirt_imagebackend import LibvirtImageBackendFixture # noqa: F401
|
from .libvirt_imagebackend import \
|
||||||
from .neutron import NeutronFixture # noqa: F401
|
LibvirtImageBackendFixture # noqa: F401, H304
|
||||||
from .notifications import NotificationFixture # noqa: F401
|
from .neutron import NeutronFixture # noqa: F401, H304
|
||||||
from .nova import * # noqa: F401, F403
|
from .notifications import NotificationFixture # noqa: F401, H304
|
||||||
from .os_brick import OSBrickFixture # noqa: F401
|
from .nova import * # noqa: F401, F403, H303, H304
|
||||||
from .policy import OverridePolicyFixture # noqa: F401
|
from .os_brick import OSBrickFixture # noqa: F401, H304
|
||||||
from .policy import PolicyFixture # noqa: F401
|
from .policy import OverridePolicyFixture # noqa: F401, H304
|
||||||
from .policy import RealPolicyFixture # noqa: F401
|
from .policy import PolicyFixture # noqa: F401, H304
|
||||||
from .policy import RoleBasedPolicyFixture # noqa: F401
|
from .policy import RealPolicyFixture # noqa: F401, H304
|
||||||
|
from .policy import RoleBasedPolicyFixture # noqa: F401, H304
|
||||||
|
@ -49,7 +49,7 @@ def format_action(action, expect_traceback=True, expect_host=False,
|
|||||||
'deleted')
|
'deleted')
|
||||||
for key in to_delete:
|
for key in to_delete:
|
||||||
if key in action:
|
if key in action:
|
||||||
del(action[key])
|
del action[key]
|
||||||
if 'start_time' in action:
|
if 'start_time' in action:
|
||||||
# NOTE(danms): Without WSGI above us, these will be just stringified
|
# NOTE(danms): Without WSGI above us, these will be just stringified
|
||||||
action['start_time'] = str(action['start_time'].replace(tzinfo=None))
|
action['start_time'] = str(action['start_time'].replace(tzinfo=None))
|
||||||
@ -73,7 +73,7 @@ def format_event(event, project_id, expect_traceback=True, expect_host=False,
|
|||||||
to_delete.append('hostId')
|
to_delete.append('hostId')
|
||||||
for key in to_delete:
|
for key in to_delete:
|
||||||
if key in event:
|
if key in event:
|
||||||
del(event[key])
|
del event[key]
|
||||||
if 'start_time' in event:
|
if 'start_time' in event:
|
||||||
# NOTE(danms): Without WSGI above us, these will be just stringified
|
# NOTE(danms): Without WSGI above us, these will be just stringified
|
||||||
event['start_time'] = str(event['start_time'].replace(tzinfo=None))
|
event['start_time'] = str(event['start_time'].replace(tzinfo=None))
|
||||||
|
@ -5612,7 +5612,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||||||
'_get_instance_block_device_info',
|
'_get_instance_block_device_info',
|
||||||
return_value='fake-bdminfo'),
|
return_value='fake-bdminfo'),
|
||||||
mock.patch.object(self.compute, '_check_trusted_certs'),
|
mock.patch.object(self.compute, '_check_trusted_certs'),
|
||||||
) as(
|
) as (
|
||||||
mock_notify_usage,
|
mock_notify_usage,
|
||||||
mock_setup,
|
mock_setup,
|
||||||
mock_setup_inst,
|
mock_setup_inst,
|
||||||
@ -5712,7 +5712,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||||||
return_value=is_vol_backed),
|
return_value=is_vol_backed),
|
||||||
mock.patch.object(self.compute, '_rebuild_volume_backed_instance'),
|
mock.patch.object(self.compute, '_rebuild_volume_backed_instance'),
|
||||||
mock.patch.object(compute_utils, 'get_root_bdm')
|
mock.patch.object(compute_utils, 'get_root_bdm')
|
||||||
) as(
|
) as (
|
||||||
mock_destroy,
|
mock_destroy,
|
||||||
mock_spawn,
|
mock_spawn,
|
||||||
mock_save,
|
mock_save,
|
||||||
@ -5844,7 +5844,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||||||
return_value=root_bdm),
|
return_value=root_bdm),
|
||||||
mock.patch.object(self.compute, 'volume_api'),
|
mock.patch.object(self.compute, 'volume_api'),
|
||||||
mock.patch.object(self.compute.image_api, 'get'),
|
mock.patch.object(self.compute.image_api, 'get'),
|
||||||
) as(
|
) as (
|
||||||
mock_save,
|
mock_save,
|
||||||
mock_get_root_bdm,
|
mock_get_root_bdm,
|
||||||
mock_vol_api,
|
mock_vol_api,
|
||||||
|
@ -100,8 +100,8 @@ class RescueServerPolicyTest(base.BasePolicyTest):
|
|||||||
|
|
||||||
|
|
||||||
class RescueServerNoLegacyNoScopePolicyTest(RescueServerPolicyTest):
|
class RescueServerNoLegacyNoScopePolicyTest(RescueServerPolicyTest):
|
||||||
"""Test rescue/unrescue server APIs policies with no legacy deprecated rules
|
"""Test rescue/unrescue server APIs policies with no legacy deprecated
|
||||||
and no scope checks which means new defaults only.
|
rules and no scope checks which means new defaults only.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class ThreadController(object):
|
|||||||
self.waiting = True
|
self.waiting = True
|
||||||
self.wait_lock.notify_all()
|
self.wait_lock.notify_all()
|
||||||
self.wait_lock.wait(1)
|
self.wait_lock.wait(1)
|
||||||
assert(time.time() - wait_since < MAX_WAIT)
|
assert time.time() - wait_since < MAX_WAIT
|
||||||
|
|
||||||
self.epoch += 1
|
self.epoch += 1
|
||||||
self.waiting = False
|
self.waiting = False
|
||||||
@ -141,7 +141,7 @@ class ThreadController(object):
|
|||||||
wait_since = time.time()
|
wait_since = time.time()
|
||||||
while self.epoch == self.last_epoch or not self.waiting:
|
while self.epoch == self.last_epoch or not self.waiting:
|
||||||
self.wait_lock.wait(1)
|
self.wait_lock.wait(1)
|
||||||
assert(time.time() - wait_since < MAX_WAIT)
|
assert time.time() - wait_since < MAX_WAIT
|
||||||
|
|
||||||
self.last_epoch = self.epoch
|
self.last_epoch = self.epoch
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ class ThreadController(object):
|
|||||||
self.wait_lock.notify_all()
|
self.wait_lock.notify_all()
|
||||||
while not self.complete:
|
while not self.complete:
|
||||||
self.wait_lock.wait(1)
|
self.wait_lock.wait(1)
|
||||||
assert(time.time() - wait_since < MAX_WAIT)
|
assert time.time() - wait_since < MAX_WAIT
|
||||||
|
|
||||||
self.thread.wait()
|
self.thread.wait()
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ class Mount(object):
|
|||||||
|
|
||||||
def map_dev(self):
|
def map_dev(self):
|
||||||
"""Map partitions of the device to the file system namespace."""
|
"""Map partitions of the device to the file system namespace."""
|
||||||
assert(os.path.exists(self.device))
|
assert os.path.exists(self.device)
|
||||||
LOG.debug("Map dev %s", self.device)
|
LOG.debug("Map dev %s", self.device)
|
||||||
automapped_path = '/dev/%sp%s' % (os.path.basename(self.device),
|
automapped_path = '/dev/%sp%s' % (os.path.basename(self.device),
|
||||||
self.partition)
|
self.partition)
|
||||||
@ -194,7 +194,7 @@ class Mount(object):
|
|||||||
elif self.partition and not os.path.exists(automapped_path):
|
elif self.partition and not os.path.exists(automapped_path):
|
||||||
map_path = '/dev/mapper/%sp%s' % (os.path.basename(self.device),
|
map_path = '/dev/mapper/%sp%s' % (os.path.basename(self.device),
|
||||||
self.partition)
|
self.partition)
|
||||||
assert(not os.path.exists(map_path))
|
assert not os.path.exists(map_path)
|
||||||
|
|
||||||
# Note kpartx can output warnings to stderr and succeed
|
# Note kpartx can output warnings to stderr and succeed
|
||||||
# Also it can output failures to stderr and "succeed"
|
# Also it can output failures to stderr and "succeed"
|
||||||
|
@ -1837,7 +1837,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
# Set maximum attempt as 5, most test can remove the directory
|
# Set maximum attempt as 5, most test can remove the directory
|
||||||
# for the second time.
|
# for the second time.
|
||||||
attempts = 0
|
attempts = 0
|
||||||
while(os.path.exists(target) and attempts < 5):
|
while os.path.exists(target) and attempts < 5:
|
||||||
shutil.rmtree(target, ignore_errors=True)
|
shutil.rmtree(target, ignore_errors=True)
|
||||||
if os.path.exists(target):
|
if os.path.exists(target):
|
||||||
time.sleep(random.randint(20, 200) / 100.0)
|
time.sleep(random.randint(20, 200) / 100.0)
|
||||||
@ -11103,7 +11103,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
announce_pause = (
|
announce_pause = (
|
||||||
CONF.workarounds.qemu_monitor_announce_self_interval)
|
CONF.workarounds.qemu_monitor_announce_self_interval)
|
||||||
|
|
||||||
while(current_attempt < max_attempts):
|
while current_attempt < max_attempts:
|
||||||
# Increment attempt
|
# Increment attempt
|
||||||
current_attempt += 1
|
current_attempt += 1
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# of appearance. Changing the order has an impact on the overall integration
|
# of appearance. Changing the order has an impact on the overall integration
|
||||||
# process, which may cause wedges in the gate later.
|
# process, which may cause wedges in the gate later.
|
||||||
|
|
||||||
hacking>=3.1.0,<3.2.0 # Apache-2.0
|
hacking>=6.0.1,<=6.0.1 # Apache-2.0
|
||||||
mypy>=0.761 # MIT
|
mypy>=0.761 # MIT
|
||||||
types-paramiko>=0.1.3 # Apache-2.0
|
types-paramiko>=0.1.3 # Apache-2.0
|
||||||
coverage!=4.4,>=4.0 # Apache-2.0
|
coverage!=4.4,>=4.0 # Apache-2.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user