Fix pylint errors (raise-missing-from)
Change-Id: I02a00ed6b3611606785a3521361bf88705d42e07
This commit is contained in:
parent
154c0981f5
commit
946e59680e
@ -65,9 +65,9 @@ class TobikoException(Exception):
|
||||
def __getattr__(self, name):
|
||||
try:
|
||||
return self._properties[name]
|
||||
except KeyError:
|
||||
msg = ("{!r} object has no attribute {!r}").format(self, name)
|
||||
raise AttributeError(msg)
|
||||
except KeyError as ex:
|
||||
raise AttributeError(f"{self!r} object has no attribute "
|
||||
f"'{name}'") from ex
|
||||
|
||||
def __repr__(self):
|
||||
return "{class_name}({message!r})".format(
|
||||
|
@ -16,7 +16,7 @@ from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import typing
|
||||
import typing # noqa
|
||||
|
||||
from oslo_log import log
|
||||
from stestr import config_file
|
||||
@ -112,10 +112,9 @@ class TestCasesFinder(object):
|
||||
ids = cmd.list_tests()
|
||||
else:
|
||||
ids = cmd.test_ids
|
||||
except SystemExit:
|
||||
msg = ("Error discovering test cases IDs with parameters: "
|
||||
"{!r}").format(params)
|
||||
raise RuntimeError(msg)
|
||||
except SystemExit as ex:
|
||||
raise RuntimeError("Error discovering test cases IDs with "
|
||||
f"parameters: {params}") from ex
|
||||
finally:
|
||||
cmd.cleanUp()
|
||||
|
||||
|
@ -45,17 +45,14 @@ class HTTPConnection(connection.HTTPConnection):
|
||||
conn = connection.connection.create_connection(
|
||||
address, self.timeout, **extra_kw)
|
||||
|
||||
except connection.SocketTimeout:
|
||||
except connection.SocketTimeout as ex:
|
||||
raise connection.ConnectTimeoutError(
|
||||
self,
|
||||
"Connection to %s timed out. (connect timeout=%s)"
|
||||
% (self.host, self.timeout),
|
||||
)
|
||||
self, (f"Connection to {self.host} timed out. "
|
||||
f"(connect timeout={self.timeout})")) from ex
|
||||
|
||||
except connection.SocketError as e:
|
||||
except connection.SocketError as ex:
|
||||
raise connection.NewConnectionError(
|
||||
self, "Failed to establish a new connection: %s" % e
|
||||
)
|
||||
self, f"Failed to establish a new connection: {ex}") from ex
|
||||
|
||||
return conn
|
||||
|
||||
|
@ -139,29 +139,29 @@ def get_network(network, client=None, **params):
|
||||
try:
|
||||
return neutron_client(client).show_network(network,
|
||||
**params)['network']
|
||||
except neutronclient.exceptions.NotFound:
|
||||
raise NoSuchNetwork(id=network)
|
||||
except neutronclient.exceptions.NotFound as ex:
|
||||
raise NoSuchNetwork(id=network) from ex
|
||||
|
||||
|
||||
def get_port(port, client=None, **params):
|
||||
try:
|
||||
return neutron_client(client).show_port(port, **params)['port']
|
||||
except neutronclient.exceptions.NotFound:
|
||||
raise NoSuchPort(id=port)
|
||||
except neutronclient.exceptions.NotFound as ex:
|
||||
raise NoSuchPort(id=port) from ex
|
||||
|
||||
|
||||
def get_router(router, client=None, **params):
|
||||
try:
|
||||
return neutron_client(client).show_router(router, **params)['router']
|
||||
except neutronclient.exceptions.NotFound:
|
||||
raise NoSuchRouter(id=router)
|
||||
except neutronclient.exceptions.NotFound as ex:
|
||||
raise NoSuchRouter(id=router) from ex
|
||||
|
||||
|
||||
def get_subnet(subnet, client=None, **params):
|
||||
try:
|
||||
return neutron_client(client).show_subnet(subnet, **params)['subnet']
|
||||
except neutronclient.exceptions.NotFound:
|
||||
raise NoSuchSubnet(id=subnet)
|
||||
except neutronclient.exceptions.NotFound as ex:
|
||||
raise NoSuchSubnet(id=subnet) from ex
|
||||
|
||||
|
||||
def list_l3_agent_hosting_routers(router, client=None, **params):
|
||||
|
@ -60,10 +60,9 @@ def check_server_ip_address(address, ip_version=None, address_type=None):
|
||||
try:
|
||||
if address_type != address['OS-EXT-IPS:type']:
|
||||
return False
|
||||
except KeyError:
|
||||
message = ("Unable to get IP type from server address {!r}"
|
||||
).format(address)
|
||||
raise ValueError(message)
|
||||
except KeyError as ex:
|
||||
raise ValueError("Unable to get IP type from server address "
|
||||
f"'{address}'") from ex
|
||||
|
||||
return True
|
||||
|
||||
|
@ -269,13 +269,12 @@ def find_external_network(name=None):
|
||||
params['name'] = name
|
||||
try:
|
||||
network = neutron.find_network(**params)
|
||||
except tobiko.ObjectNotFound:
|
||||
except tobiko.ObjectNotFound as ex:
|
||||
LOG.exception('No such network (%s):',
|
||||
json.dumps(params, sort_keys=True))
|
||||
if name:
|
||||
message = ('No such external network with name or ID '
|
||||
'{!r}').format(name)
|
||||
raise ValueError(message)
|
||||
raise ValueError("No such external network with name or ID "
|
||||
f"'{name}'") from ex
|
||||
|
||||
if network:
|
||||
LOG.debug('Found external network %r:\n%s',
|
||||
|
@ -15,7 +15,7 @@ from __future__ import absolute_import
|
||||
|
||||
import collections
|
||||
import socket
|
||||
import typing
|
||||
import typing # noqa
|
||||
import weakref
|
||||
|
||||
|
||||
@ -300,8 +300,9 @@ class OpenStackTopology(tobiko.SharedFixture):
|
||||
def get_group(self, group):
|
||||
try:
|
||||
return self._nodes_by_group[group]
|
||||
except KeyError:
|
||||
raise _exception.NoSuchOpenStackTopologyNodeGroup(group=group)
|
||||
except KeyError as ex:
|
||||
raise _exception.NoSuchOpenStackTopologyNodeGroup(
|
||||
group=group) from ex
|
||||
|
||||
def get_groups(self, groups):
|
||||
nodes = []
|
||||
|
@ -28,8 +28,10 @@ def discover_podman_socket(ssh_client=None, **execute_params):
|
||||
raise _exception.PodmanSocketNotFoundError(details=result.stderr)
|
||||
try:
|
||||
socket = result.stdout.splitlines()[0]
|
||||
except IndexError:
|
||||
raise _exception.PodmanSocketNotFoundError(details=result.stderr)
|
||||
except IndexError as ex:
|
||||
podman_error = _exception.PodmanSocketNotFoundError(
|
||||
details=result.stderr)
|
||||
raise podman_error from ex
|
||||
if '0 sockets listed' in socket:
|
||||
raise _exception.PodmanSocketNotFoundError(details=socket)
|
||||
return socket
|
||||
|
@ -223,9 +223,9 @@ class ShellProcessFixture(tobiko.SharedFixture):
|
||||
try:
|
||||
# Get attributes from parameters class
|
||||
return getattr(self.parameters, name)
|
||||
except AttributeError:
|
||||
except AttributeError as ex:
|
||||
message = "object {!r} has not attribute {!r}".format(self, name)
|
||||
raise AttributeError(message)
|
||||
raise AttributeError(message) from ex
|
||||
|
||||
def kill(self):
|
||||
raise NotImplementedError
|
||||
|
@ -118,13 +118,13 @@ class SSHShellProcessFixture(_process.ShellProcessFixture):
|
||||
exc_info=1)
|
||||
try:
|
||||
attempt.check_limits()
|
||||
except tobiko.RetryTimeLimitError:
|
||||
except tobiko.RetryTimeLimitError as ex:
|
||||
LOG.debug(f"Timed out creating remote process. ({details})")
|
||||
raise _exception.ShellTimeoutExpired(command=command,
|
||||
stdin=None,
|
||||
stdout=None,
|
||||
stderr=None,
|
||||
timeout=timeout)
|
||||
timeout=timeout) from ex
|
||||
|
||||
def setup_stdin(self):
|
||||
self.stdin = _io.ShellStdin(
|
||||
|
Loading…
Reference in New Issue
Block a user