mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-04-04 02:31:28 +00:00
Address broad-exception-caught.
This commit is contained in:
parent
451e235c2a
commit
1d30856e67
@ -381,7 +381,6 @@ disable=raw-checker-failed,
|
|||||||
# To clean up:
|
# To clean up:
|
||||||
abstract-method,
|
abstract-method,
|
||||||
arguments-differ,
|
arguments-differ,
|
||||||
broad-exception-caught,
|
|
||||||
consider-iterating-dictionary,
|
consider-iterating-dictionary,
|
||||||
consider-using-dict-comprehension,
|
consider-using-dict-comprehension,
|
||||||
consider-using-f-string,
|
consider-using-f-string,
|
||||||
|
|||||||
@ -368,7 +368,7 @@ def _load_legacy_config(config_file):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e: # pylint: disable=broad-exception-caught
|
||||||
log.debug(e)
|
log.debug(e)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ def get_current_context_name_with_source():
|
|||||||
json.load(f).get("currentContext", "default"),
|
json.load(f).get("currentContext", "default"),
|
||||||
f"configuration file {docker_cfg_path}",
|
f"configuration file {docker_cfg_path}",
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception: # pylint: disable=broad-exception-caught
|
||||||
pass
|
pass
|
||||||
return "default", "fallback value"
|
return "default", "fallback value"
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ def write_context_name_to_docker_config(name=None):
|
|||||||
try:
|
try:
|
||||||
with open(docker_cfg_path, "rt", encoding="utf-8") as f:
|
with open(docker_cfg_path, "rt", encoding="utf-8") as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
except Exception as e:
|
except Exception as e: # pylint: disable=broad-exception-caught
|
||||||
return e
|
return e
|
||||||
current_context = config.get("currentContext", None)
|
current_context = config.get("currentContext", None)
|
||||||
if current_context and not name:
|
if current_context and not name:
|
||||||
@ -68,7 +68,7 @@ def write_context_name_to_docker_config(name=None):
|
|||||||
try:
|
try:
|
||||||
with open(docker_cfg_path, "wt", encoding="utf-8") as f:
|
with open(docker_cfg_path, "wt", encoding="utf-8") as f:
|
||||||
json.dump(config, f, indent=4)
|
json.dump(config, f, indent=4)
|
||||||
except Exception as e:
|
except Exception as e: # pylint: disable=broad-exception-caught
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -237,7 +237,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
self.docker_api_version_str = self.api_version
|
self.docker_api_version_str = self.api_version
|
||||||
except APIError as exc:
|
except APIError as exc:
|
||||||
self.fail(f"Docker API error: {exc}")
|
self.fail(f"Docker API error: {exc}")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error connecting: {exc}")
|
self.fail(f"Error connecting: {exc}")
|
||||||
|
|
||||||
self.docker_api_version = LooseVersion(self.docker_api_version_str)
|
self.docker_api_version = LooseVersion(self.docker_api_version_str)
|
||||||
@ -409,7 +409,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
return result
|
return result
|
||||||
except NotFound:
|
except NotFound:
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting container: {exc}")
|
self.fail(f"Error inspecting container: {exc}")
|
||||||
|
|
||||||
def get_container(self, name=None):
|
def get_container(self, name=None):
|
||||||
@ -441,7 +441,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
break
|
break
|
||||||
except SSLError as exc:
|
except SSLError as exc:
|
||||||
self._handle_ssl_error(exc)
|
self._handle_ssl_error(exc)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error retrieving container list: {exc}")
|
self.fail(f"Error retrieving container list: {exc}")
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
@ -470,7 +470,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
break
|
break
|
||||||
except SSLError as exc:
|
except SSLError as exc:
|
||||||
self._handle_ssl_error(exc)
|
self._handle_ssl_error(exc)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error retrieving network list: {exc}")
|
self.fail(f"Error retrieving network list: {exc}")
|
||||||
|
|
||||||
if result is not None:
|
if result is not None:
|
||||||
@ -483,7 +483,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
self.log("Completed network inspection")
|
self.log("Completed network inspection")
|
||||||
except NotFound:
|
except NotFound:
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting network: {exc}")
|
self.fail(f"Error inspecting network: {exc}")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -533,7 +533,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
except NotFound:
|
except NotFound:
|
||||||
self.log(f"Image {name}:{tag} not found.")
|
self.log(f"Image {name}:{tag} not found.")
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting image {name}:{tag} - {exc}")
|
self.fail(f"Error inspecting image {name}:{tag} - {exc}")
|
||||||
return inspection
|
return inspection
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
||||||
self.log(f"Image {image_id} not found.")
|
self.log(f"Image {image_id} not found.")
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
||||||
return inspection
|
return inspection
|
||||||
|
|
||||||
@ -567,7 +567,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = self.images(name=name)
|
response = self.images(name=name)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error searching for image {name} - {exc}")
|
self.fail(f"Error searching for image {name} - {exc}")
|
||||||
images = response
|
images = response
|
||||||
if tag:
|
if tag:
|
||||||
@ -606,7 +606,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.fail(f"Error pulling {name} - {line.get('error')}")
|
self.fail(f"Error pulling {name} - {line.get('error')}")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error pulling image {name}:{tag} - {exc}")
|
self.fail(f"Error pulling image {name}:{tag} - {exc}")
|
||||||
|
|
||||||
new_tag = self.find_image(name, tag)
|
new_tag = self.find_image(name, tag)
|
||||||
|
|||||||
@ -128,7 +128,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
)
|
)
|
||||||
except APIError as exc:
|
except APIError as exc:
|
||||||
self.fail(f"Docker API error: {exc}")
|
self.fail(f"Docker API error: {exc}")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error connecting: {exc}")
|
self.fail(f"Error connecting: {exc}")
|
||||||
|
|
||||||
self.docker_api_version = LooseVersion(self.docker_api_version_str)
|
self.docker_api_version = LooseVersion(self.docker_api_version_str)
|
||||||
@ -308,7 +308,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
return result
|
return result
|
||||||
except NotFound:
|
except NotFound:
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting container: {exc}")
|
self.fail(f"Error inspecting container: {exc}")
|
||||||
|
|
||||||
def get_container(self, name=None):
|
def get_container(self, name=None):
|
||||||
@ -347,7 +347,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
break
|
break
|
||||||
except SSLError as exc:
|
except SSLError as exc:
|
||||||
self._handle_ssl_error(exc)
|
self._handle_ssl_error(exc)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error retrieving container list: {exc}")
|
self.fail(f"Error retrieving container list: {exc}")
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
@ -377,7 +377,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
break
|
break
|
||||||
except SSLError as exc:
|
except SSLError as exc:
|
||||||
self._handle_ssl_error(exc)
|
self._handle_ssl_error(exc)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error retrieving network list: {exc}")
|
self.fail(f"Error retrieving network list: {exc}")
|
||||||
|
|
||||||
if result is not None:
|
if result is not None:
|
||||||
@ -390,7 +390,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
self.log("Completed network inspection")
|
self.log("Completed network inspection")
|
||||||
except NotFound:
|
except NotFound:
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting network: {exc}")
|
self.fail(f"Error inspecting network: {exc}")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -412,7 +412,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
else:
|
else:
|
||||||
params["filters"] = convert_filters({"reference": name})
|
params["filters"] = convert_filters({"reference": name})
|
||||||
images = self.get_json("/images/json", params=params)
|
images = self.get_json("/images/json", params=params)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error searching for image {name} - {exc}")
|
self.fail(f"Error searching for image {name} - {exc}")
|
||||||
if tag:
|
if tag:
|
||||||
lookup = f"{name}:{tag}"
|
lookup = f"{name}:{tag}"
|
||||||
@ -472,7 +472,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
except NotFound:
|
except NotFound:
|
||||||
self.log(f"Image {name}:{tag} not found.")
|
self.log(f"Image {name}:{tag} not found.")
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting image {name}:{tag} - {exc}")
|
self.fail(f"Error inspecting image {name}:{tag} - {exc}")
|
||||||
|
|
||||||
self.log(f"Image {name}:{tag} not found.")
|
self.log(f"Image {name}:{tag} not found.")
|
||||||
@ -493,7 +493,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
||||||
self.log(f"Image {image_id} not found.")
|
self.log(f"Image {image_id} not found.")
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
self.fail(f"Error inspecting image ID {image_id} - {exc}")
|
||||||
|
|
||||||
def pull_image(self, name, tag="latest", image_platform=None):
|
def pull_image(self, name, tag="latest", image_platform=None):
|
||||||
@ -535,7 +535,7 @@ class AnsibleDockerClientBase(Client):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.fail(f"Error pulling {name} - {line.get('error')}")
|
self.fail(f"Error pulling {name} - {line.get('error')}")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error pulling image {name}:{tag} - {exc}")
|
self.fail(f"Error pulling image {name}:{tag} - {exc}")
|
||||||
|
|
||||||
new_tag = self.find_image(name, tag)
|
new_tag = self.find_image(name, tag)
|
||||||
|
|||||||
@ -159,7 +159,7 @@ class AnsibleDockerClientBase:
|
|||||||
self.warn(to_native(stderr))
|
self.warn(to_native(stderr))
|
||||||
try:
|
try:
|
||||||
data = json.loads(stdout)
|
data = json.loads(stdout)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Error while parsing JSON output of {self._compose_cmd_str(args)}: {exc}\nJSON output: {to_native(stdout)}"
|
f"Error while parsing JSON output of {self._compose_cmd_str(args)}: {exc}\nJSON output: {to_native(stdout)}"
|
||||||
)
|
)
|
||||||
@ -177,7 +177,7 @@ class AnsibleDockerClientBase:
|
|||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith(b"{"):
|
if line.startswith(b"{"):
|
||||||
result.append(json.loads(line))
|
result.append(json.loads(line))
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Error while parsing JSON output of {self._compose_cmd_str(args)}: {exc}\nJSON output: {to_native(stdout)}"
|
f"Error while parsing JSON output of {self._compose_cmd_str(args)}: {exc}\nJSON output: {to_native(stdout)}"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -405,7 +405,7 @@ def parse_json_events(stderr, warn_function=None):
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
line_data = json.loads(line)
|
line_data = json.loads(line)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
if warn_function:
|
if warn_function:
|
||||||
warn_function(
|
warn_function(
|
||||||
f"Cannot parse event from line: {line!r}: {exc}. Please report this at "
|
f"Cannot parse event from line: {line!r}: {exc}. Please report this at "
|
||||||
@ -748,7 +748,7 @@ class BaseComposeManager(DockerBaseClass):
|
|||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
Dumper=_SafeDumper,
|
Dumper=_SafeDumper,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error writing to {compose_file} - {exc}")
|
self.fail(f"Error writing to {compose_file} - {exc}")
|
||||||
else:
|
else:
|
||||||
self.project_src = os.path.abspath(parameters["project_src"])
|
self.project_src = os.path.abspath(parameters["project_src"])
|
||||||
@ -804,7 +804,7 @@ class BaseComposeManager(DockerBaseClass):
|
|||||||
if version == "dev":
|
if version == "dev":
|
||||||
return None
|
return None
|
||||||
return version.lstrip("v")
|
return version.lstrip("v")
|
||||||
except Exception:
|
except Exception: # pylint: disable=broad-exception-caught
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_compose_version_from_api(self):
|
def get_compose_version_from_api(self):
|
||||||
@ -946,6 +946,6 @@ class BaseComposeManager(DockerBaseClass):
|
|||||||
for directory in self.cleanup_dirs:
|
for directory in self.cleanup_dirs:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(directory, True)
|
shutil.rmtree(directory, True)
|
||||||
except Exception:
|
except Exception: # pylint: disable=broad-exception-caught
|
||||||
# should not happen, but simply ignore to be on the safe side
|
# should not happen, but simply ignore to be on the safe side
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -431,7 +431,7 @@ def _parse_port_range(range_or_port, module):
|
|||||||
if "-" in range_or_port:
|
if "-" in range_or_port:
|
||||||
try:
|
try:
|
||||||
start, end = [int(port) for port in range_or_port.split("-")]
|
start, end = [int(port) for port in range_or_port.split("-")]
|
||||||
except Exception:
|
except ValueError:
|
||||||
module.fail_json(msg=f'Invalid port range: "{range_or_port}"')
|
module.fail_json(msg=f'Invalid port range: "{range_or_port}"')
|
||||||
if end < start:
|
if end < start:
|
||||||
module.fail_json(msg=f'Invalid port range: "{range_or_port}"')
|
module.fail_json(msg=f'Invalid port range: "{range_or_port}"')
|
||||||
@ -439,7 +439,7 @@ def _parse_port_range(range_or_port, module):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
return [int(range_or_port)]
|
return [int(range_or_port)]
|
||||||
except Exception:
|
except ValueError:
|
||||||
module.fail_json(msg=f'Invalid port: "{range_or_port}"')
|
module.fail_json(msg=f'Invalid port: "{range_or_port}"')
|
||||||
|
|
||||||
|
|
||||||
@ -707,7 +707,7 @@ def _preprocess_mounts(module, values):
|
|||||||
if mount_dict["tmpfs_mode"] is not None:
|
if mount_dict["tmpfs_mode"] is not None:
|
||||||
try:
|
try:
|
||||||
mount_dict["tmpfs_mode"] = int(mount_dict["tmpfs_mode"], 8)
|
mount_dict["tmpfs_mode"] = int(mount_dict["tmpfs_mode"], 8)
|
||||||
except Exception:
|
except ValueError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg=f'tmp_fs mode of mount "{target}" is not an octal string!'
|
msg=f'tmp_fs mode of mount "{target}" is not an octal string!'
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1060,7 +1060,7 @@ def _get_network_id(module, client, network_name):
|
|||||||
network_id = network["Id"]
|
network_id = network["Id"]
|
||||||
break
|
break
|
||||||
return network_id
|
return network_id
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
client.fail(f"Error getting network id for {network_name} - {exc}")
|
client.fail(f"Error getting network id for {network_name} - {exc}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -481,7 +481,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.unpause_container(
|
self.engine_driver.unpause_container(
|
||||||
self.client, container.id
|
self.client, container.id
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Error {'pausing' if self.param_paused else 'unpausing'} container {container.id}: {exc}"
|
f"Error {'pausing' if self.param_paused else 'unpausing'} container {container.id}: {exc}"
|
||||||
)
|
)
|
||||||
@ -951,7 +951,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.disconnect_container_from_network(
|
self.engine_driver.disconnect_container_from_network(
|
||||||
self.client, container.id, diff["parameter"]["id"]
|
self.client, container.id, diff["parameter"]["id"]
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Error disconnecting container from network {diff['parameter']['name']} - {exc}"
|
f"Error disconnecting container from network {diff['parameter']['name']} - {exc}"
|
||||||
)
|
)
|
||||||
@ -976,7 +976,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.connect_container_to_network(
|
self.engine_driver.connect_container_to_network(
|
||||||
self.client, container.id, diff["parameter"]["id"], params
|
self.client, container.id, diff["parameter"]["id"], params
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Error connecting container to network {diff['parameter']['name']} - {exc}"
|
f"Error connecting container to network {diff['parameter']['name']} - {exc}"
|
||||||
)
|
)
|
||||||
@ -990,7 +990,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.disconnect_container_from_network(
|
self.engine_driver.disconnect_container_from_network(
|
||||||
self.client, container.id, network["name"]
|
self.client, container.id, network["name"]
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Error disconnecting container from network {network['name']} - {exc}"
|
f"Error disconnecting container from network {network['name']} - {exc}"
|
||||||
)
|
)
|
||||||
@ -1028,7 +1028,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
container_id = self.engine_driver.create_container(
|
container_id = self.engine_driver.create_container(
|
||||||
self.client, self.param_name, create_parameters, networks=networks
|
self.client, self.param_name, create_parameters, networks=networks
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error creating container: {exc}")
|
self.fail(f"Error creating container: {exc}")
|
||||||
return self._get_container(container_id)
|
return self._get_container(container_id)
|
||||||
return new_container
|
return new_container
|
||||||
@ -1040,7 +1040,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
try:
|
try:
|
||||||
self.engine_driver.start_container(self.client, container_id)
|
self.engine_driver.start_container(self.client, container_id)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error starting container {container_id}: {exc}")
|
self.fail(f"Error starting container {container_id}: {exc}")
|
||||||
|
|
||||||
if self.module.params["detach"] is False:
|
if self.module.params["detach"] is False:
|
||||||
@ -1097,7 +1097,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
link=link,
|
link=link,
|
||||||
force=force,
|
force=force,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.client.fail(f"Error removing container {container_id}: {exc}")
|
self.client.fail(f"Error removing container {container_id}: {exc}")
|
||||||
|
|
||||||
def container_update(self, container_id, update_parameters):
|
def container_update(self, container_id, update_parameters):
|
||||||
@ -1113,7 +1113,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.update_container(
|
self.engine_driver.update_container(
|
||||||
self.client, container_id, update_parameters
|
self.client, container_id, update_parameters
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error updating container {container_id}: {exc}")
|
self.fail(f"Error updating container {container_id}: {exc}")
|
||||||
return self._get_container(container_id)
|
return self._get_container(container_id)
|
||||||
|
|
||||||
@ -1127,7 +1127,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.kill_container(
|
self.engine_driver.kill_container(
|
||||||
self.client, container_id, kill_signal=self.param_kill_signal
|
self.client, container_id, kill_signal=self.param_kill_signal
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error killing container {container_id}: {exc}")
|
self.fail(f"Error killing container {container_id}: {exc}")
|
||||||
|
|
||||||
def container_restart(self, container_id):
|
def container_restart(self, container_id):
|
||||||
@ -1140,7 +1140,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.restart_container(
|
self.engine_driver.restart_container(
|
||||||
self.client, container_id, self.module.params["stop_timeout"] or 10
|
self.client, container_id, self.module.params["stop_timeout"] or 10
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error restarting container {container_id}: {exc}")
|
self.fail(f"Error restarting container {container_id}: {exc}")
|
||||||
return self._get_container(container_id)
|
return self._get_container(container_id)
|
||||||
|
|
||||||
@ -1157,7 +1157,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
self.engine_driver.stop_container(
|
self.engine_driver.stop_container(
|
||||||
self.client, container_id, self.module.params["stop_timeout"]
|
self.client, container_id, self.module.params["stop_timeout"]
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error stopping container {container_id}: {exc}")
|
self.fail(f"Error stopping container {container_id}: {exc}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,7 @@ class DockerSocketHandlerBase:
|
|||||||
if hasattr(self._sock, "recv"):
|
if hasattr(self._sock, "recv"):
|
||||||
try:
|
try:
|
||||||
data = self._sock.recv(262144)
|
data = self._sock.recv(262144)
|
||||||
except Exception as e:
|
except Exception as e: # pylint: disable=broad-exception-caught
|
||||||
# After calling self._sock.shutdown(), OpenSSL's/urllib3's
|
# After calling self._sock.shutdown(), OpenSSL's/urllib3's
|
||||||
# WrappedSocket seems to eventually raise ZeroReturnError in
|
# WrappedSocket seems to eventually raise ZeroReturnError in
|
||||||
# case of EOF
|
# case of EOF
|
||||||
|
|||||||
@ -179,7 +179,7 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient):
|
|||||||
if skip_missing:
|
if skip_missing:
|
||||||
return None
|
return None
|
||||||
self.fail(f"Error while reading from Swarm manager: {exc}")
|
self.fail(f"Error while reading from Swarm manager: {exc}")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting swarm node: {exc}")
|
self.fail(f"Error inspecting swarm node: {exc}")
|
||||||
|
|
||||||
json_str = json.dumps(node_info, ensure_ascii=False)
|
json_str = json.dumps(node_info, ensure_ascii=False)
|
||||||
@ -215,7 +215,7 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient):
|
|||||||
"Cannot inspect node: To inspect node execute module on Swarm Manager"
|
"Cannot inspect node: To inspect node execute module on Swarm Manager"
|
||||||
)
|
)
|
||||||
self.fail(f"Error while reading from Swarm manager: {exc}")
|
self.fail(f"Error while reading from Swarm manager: {exc}")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting swarm node: {exc}")
|
self.fail(f"Error inspecting swarm node: {exc}")
|
||||||
|
|
||||||
json_str = json.dumps(node_info, ensure_ascii=False)
|
json_str = json.dumps(node_info, ensure_ascii=False)
|
||||||
@ -295,7 +295,7 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient):
|
|||||||
"Cannot inspect service: To inspect service execute module on Swarm Manager"
|
"Cannot inspect service: To inspect service execute module on Swarm Manager"
|
||||||
)
|
)
|
||||||
self.fail(f"Error inspecting swarm service: {exc}")
|
self.fail(f"Error inspecting swarm service: {exc}")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting swarm service: {exc}")
|
self.fail(f"Error inspecting swarm service: {exc}")
|
||||||
|
|
||||||
json_str = json.dumps(service_info, ensure_ascii=False)
|
json_str = json.dumps(service_info, ensure_ascii=False)
|
||||||
|
|||||||
@ -243,7 +243,7 @@ class ConfigManager(DockerBaseClass):
|
|||||||
try:
|
try:
|
||||||
with open(data_src, "rb") as f:
|
with open(data_src, "rb") as f:
|
||||||
self.data = f.read()
|
self.data = f.read()
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.client.fail(f"Error while reading {data_src}: {exc}")
|
self.client.fail(f"Error while reading {data_src}: {exc}")
|
||||||
self.labels = parameters.get("labels")
|
self.labels = parameters.get("labels")
|
||||||
self.force = parameters.get("force")
|
self.force = parameters.get("force")
|
||||||
|
|||||||
@ -1084,9 +1084,7 @@ def main():
|
|||||||
if client.module.params["content_is_b64"]:
|
if client.module.params["content_is_b64"]:
|
||||||
try:
|
try:
|
||||||
content = base64.b64decode(content)
|
content = base64.b64decode(content)
|
||||||
except (
|
except Exception as e: # pylint: disable=broad-exception-caught
|
||||||
Exception
|
|
||||||
) as e: # depending on Python version and error, multiple different exceptions can be raised
|
|
||||||
client.fail(f"Cannot Base64 decode the content option: {e}")
|
client.fail(f"Cannot Base64 decode the content option: {e}")
|
||||||
else:
|
else:
|
||||||
content = to_bytes(content)
|
content = to_bytes(content)
|
||||||
|
|||||||
@ -618,7 +618,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
except NotFound:
|
except NotFound:
|
||||||
# If the image vanished while we were trying to remove it, do not fail
|
# If the image vanished while we were trying to remove it, do not fail
|
||||||
pass
|
pass
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error removing image {name} - {exc}")
|
self.fail(f"Error removing image {name} - {exc}")
|
||||||
|
|
||||||
self.results["changed"] = True
|
self.results["changed"] = True
|
||||||
@ -714,14 +714,14 @@ class ImageManager(DockerBaseClass):
|
|||||||
DEFAULT_DATA_CHUNK_SIZE,
|
DEFAULT_DATA_CHUNK_SIZE,
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error getting image {image_name} - {exc}")
|
self.fail(f"Error getting image {image_name} - {exc}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(self.archive_path, "wb") as fd:
|
with open(self.archive_path, "wb") as fd:
|
||||||
for chunk in saved_image:
|
for chunk in saved_image:
|
||||||
fd.write(chunk)
|
fd.write(chunk)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error writing image archive {self.archive_path} - {exc}")
|
self.fail(f"Error writing image archive {self.archive_path} - {exc}")
|
||||||
|
|
||||||
self.results["image"] = image
|
self.results["image"] = image
|
||||||
@ -784,7 +784,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
if status == "Pushing":
|
if status == "Pushing":
|
||||||
changed = True
|
changed = True
|
||||||
self.results["changed"] = changed
|
self.results["changed"] = changed
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
if "unauthorized" in str(exc):
|
if "unauthorized" in str(exc):
|
||||||
if "authentication required" in str(exc):
|
if "authentication required" in str(exc):
|
||||||
self.fail(
|
self.fail(
|
||||||
@ -843,7 +843,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
self.client._raise_for_status(res)
|
self.client._raise_for_status(res)
|
||||||
if res.status_code != 201:
|
if res.status_code != 201:
|
||||||
raise RuntimeError("Tag operation failed.")
|
raise RuntimeError("Tag operation failed.")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error: failed to tag image - {exc}")
|
self.fail(f"Error: failed to tag image - {exc}")
|
||||||
self.results["image"] = self.client.find_image(name=repo, tag=repo_tag)
|
self.results["image"] = self.client.find_image(name=repo, tag=repo_tag)
|
||||||
if image and image["Id"] == self.results["image"]["Id"]:
|
if image and image["Id"] == self.results["image"]["Id"]:
|
||||||
@ -1019,7 +1019,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
f"Error loading image {self.name} - {exc}",
|
f"Error loading image {self.name} - {exc}",
|
||||||
stdout="\n".join(load_output),
|
stdout="\n".join(load_output),
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.client.fail(
|
self.client.fail(
|
||||||
f"Error loading image {self.name} - {exc}",
|
f"Error loading image {self.name} - {exc}",
|
||||||
stdout="\n".join(load_output),
|
stdout="\n".join(load_output),
|
||||||
|
|||||||
@ -189,7 +189,7 @@ class ImageExportManager(DockerBaseClass):
|
|||||||
with open(self.path, "wb") as fd:
|
with open(self.path, "wb") as fd:
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
fd.write(chunk)
|
fd.write(chunk)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error writing image archive {self.path} - {exc}")
|
self.fail(f"Error writing image archive {self.path} - {exc}")
|
||||||
|
|
||||||
def export_images(self):
|
def export_images(self):
|
||||||
@ -205,7 +205,7 @@ class ImageExportManager(DockerBaseClass):
|
|||||||
DEFAULT_DATA_CHUNK_SIZE,
|
DEFAULT_DATA_CHUNK_SIZE,
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error getting image {image_names[0]} - {exc}")
|
self.fail(f"Error getting image {image_names[0]} - {exc}")
|
||||||
else:
|
else:
|
||||||
self.log(f"Getting archive of images {image_names_str}")
|
self.log(f"Getting archive of images {image_names_str}")
|
||||||
@ -219,7 +219,7 @@ class ImageExportManager(DockerBaseClass):
|
|||||||
DEFAULT_DATA_CHUNK_SIZE,
|
DEFAULT_DATA_CHUNK_SIZE,
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error getting images {image_names_str} - {exc}")
|
self.fail(f"Error getting images {image_names_str} - {exc}")
|
||||||
|
|
||||||
self.write_chunks(chunks)
|
self.write_chunks(chunks)
|
||||||
|
|||||||
@ -212,7 +212,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
inspection = self.client.get_json("/images/{0}/json", image["Id"])
|
inspection = self.client.get_json("/images/{0}/json", image["Id"])
|
||||||
except NotFound:
|
except NotFound:
|
||||||
inspection = None
|
inspection = None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error inspecting image {image['Id']} - {exc}")
|
self.fail(f"Error inspecting image {image['Id']} - {exc}")
|
||||||
results.append(inspection)
|
results.append(inspection)
|
||||||
return results
|
return results
|
||||||
|
|||||||
@ -141,7 +141,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
f"Error loading archive {self.path} - {exc}",
|
f"Error loading archive {self.path} - {exc}",
|
||||||
stdout="\n".join(load_output),
|
stdout="\n".join(load_output),
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.client.fail(
|
self.client.fail(
|
||||||
f"Error loading archive {self.path} - {exc}",
|
f"Error loading archive {self.path} - {exc}",
|
||||||
stdout="\n".join(load_output),
|
stdout="\n".join(load_output),
|
||||||
|
|||||||
@ -159,7 +159,7 @@ class ImagePusher(DockerBaseClass):
|
|||||||
status = line.get("status")
|
status = line.get("status")
|
||||||
if status == "Pushing":
|
if status == "Pushing":
|
||||||
results["changed"] = True
|
results["changed"] = True
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
if "unauthorized" in str(exc):
|
if "unauthorized" in str(exc):
|
||||||
if "authentication required" in str(exc):
|
if "authentication required" in str(exc):
|
||||||
self.client.fail(
|
self.client.fail(
|
||||||
|
|||||||
@ -194,7 +194,7 @@ class ImageRemover(DockerBaseClass):
|
|||||||
except NotFound:
|
except NotFound:
|
||||||
# If the image vanished while we were trying to remove it, do not fail
|
# If the image vanished while we were trying to remove it, do not fail
|
||||||
res = []
|
res = []
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error removing image {name} - {exc}")
|
self.fail(f"Error removing image {name} - {exc}")
|
||||||
|
|
||||||
for entry in res:
|
for entry in res:
|
||||||
|
|||||||
@ -215,7 +215,7 @@ class ImageTagger(DockerBaseClass):
|
|||||||
self.client._raise_for_status(res)
|
self.client._raise_for_status(res)
|
||||||
if res.status_code != 201:
|
if res.status_code != 201:
|
||||||
raise RuntimeError("Tag operation failed.")
|
raise RuntimeError("Tag operation failed.")
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(f"Error: failed to tag image as {name}:{tag} - {exc}")
|
self.fail(f"Error: failed to tag image as {name}:{tag} - {exc}")
|
||||||
|
|
||||||
return True, msg, tagged_image
|
return True, msg, tagged_image
|
||||||
|
|||||||
@ -309,7 +309,7 @@ class LoginManager(DockerBaseClass):
|
|||||||
self.log(f"Log into {self.registry_url} with username {self.username}")
|
self.log(f"Log into {self.registry_url} with username {self.username}")
|
||||||
try:
|
try:
|
||||||
response = self._login(self.reauthorize)
|
response = self._login(self.reauthorize)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Logging into {self.registry_url} for user {self.username} failed - {exc}"
|
f"Logging into {self.registry_url} for user {self.username} failed - {exc}"
|
||||||
)
|
)
|
||||||
@ -322,7 +322,7 @@ class LoginManager(DockerBaseClass):
|
|||||||
if not self.reauthorize and response["password"] != self.password:
|
if not self.reauthorize and response["password"] != self.password:
|
||||||
try:
|
try:
|
||||||
response = self._login(True)
|
response = self._login(True)
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.fail(
|
self.fail(
|
||||||
f"Logging into {self.registry_url} for user {self.username} failed - {exc}"
|
f"Logging into {self.registry_url} for user {self.username} failed - {exc}"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -235,7 +235,7 @@ class SecretManager(DockerBaseClass):
|
|||||||
try:
|
try:
|
||||||
with open(data_src, "rb") as f:
|
with open(data_src, "rb") as f:
|
||||||
self.data = f.read()
|
self.data = f.read()
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
self.client.fail(f"Error while reading {data_src}: {exc}")
|
self.client.fail(f"Error while reading {data_src}: {exc}")
|
||||||
self.labels = parameters.get("labels")
|
self.labels = parameters.get("labels")
|
||||||
self.force = parameters.get("force")
|
self.force = parameters.get("force")
|
||||||
|
|||||||
@ -2510,7 +2510,7 @@ class DockerServiceManager:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
current_service = self.get_service(module.params["name"])
|
current_service = self.get_service(module.params["name"])
|
||||||
except Exception as e:
|
except Exception as e: # pylint: disable=broad-exception-caught
|
||||||
self.client.fail(
|
self.client.fail(
|
||||||
f"Error looking for service named {module.params['name']}: {e}"
|
f"Error looking for service named {module.params['name']}: {e}"
|
||||||
)
|
)
|
||||||
@ -2527,7 +2527,7 @@ class DockerServiceManager:
|
|||||||
network_ids,
|
network_ids,
|
||||||
self.client,
|
self.client,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e: # pylint: disable=broad-exception-caught
|
||||||
return self.client.fail(f"Error parsing module parameters: {e}")
|
return self.client.fail(f"Error parsing module parameters: {e}")
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|||||||
@ -87,7 +87,7 @@ def get_existing_volume(client, volume_name):
|
|||||||
return client.get_json("/volumes/{0}", volume_name)
|
return client.get_json("/volumes/{0}", volume_name)
|
||||||
except NotFound:
|
except NotFound:
|
||||||
return None
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
||||||
client.fail(f"Error inspecting volume: {exc}")
|
client.fail(f"Error inspecting volume: {exc}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user