Skip to content

Commit

Permalink
tests: address mypy errors
Browse files Browse the repository at this point in the history
The new mypy options used brought out new mypy errors.
This commit addresses them.

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
  • Loading branch information
guits committed Feb 13, 2024
1 parent 0ab763d commit 15ec250
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions library/ceph_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author: Guillaume Abrioux <gabrioux@redhat.com>

from __future__ import absolute_import, division, print_function
from typing import List, Tuple
from typing import Any, Dict, List, Tuple, Union
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule # type: ignore
Expand Down Expand Up @@ -97,7 +97,7 @@ def set_option(module: "AnsibleModule",
return rc, cmd, out.strip(), err


def get_config_dump(module: "AnsibleModule"):
def get_config_dump(module: "AnsibleModule") -> Tuple[int, List[str], str, str]:
cmd = build_base_cmd_shell(module)
cmd.extend(['ceph', 'config', 'dump', '--format', 'json'])
rc, out, err = module.run_command(cmd)
Expand All @@ -107,7 +107,7 @@ def get_config_dump(module: "AnsibleModule"):
return rc, cmd, out, err


def get_current_value(who, option, config_dump):
def get_current_value(who: str, option: str, config_dump: List[Dict[str, Any]]) -> Union[str, None]:
for config in config_dump:
if config['section'] == who and config['name'] == option:
return config['value']
Expand Down
2 changes: 1 addition & 1 deletion library/ceph_orch_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def apply_spec(module: "AnsibleModule",
return rc, cmd, out, err


def main():
def main() -> None:
module = AnsibleModule(
argument_spec=dict(
fsid=dict(type='str', required=False),
Expand Down
10 changes: 5 additions & 5 deletions library/cephadm_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ def run_module() -> None:
ceph_pubkey = 'ceph.pub'

def extend_append(key: str, parameters: dict) -> None:
if parameters[key]["type"] == 'bool':
cmd.append("--" + k.replace('_', '-'))
if parameters[key]['type'] == 'bool':
cmd.append('--' + k.replace('_', '-'))
else:
cmd.extend(["--" + k.replace('_', '-'), module.params.get(k)])
cmd.extend(['--' + k.replace('_', '-'), module.params.get(k)])

if fsid:
if os.path.exists(os.path.join(data_dir, fsid)):
out = f"A cluster with fsid {fsid} is already deployed."
out = f'A cluster with fsid {fsid} is already deployed.'
exit_module(
rc=0,
startd=startd,
Expand Down Expand Up @@ -339,7 +339,7 @@ def extend_append(key: str, parameters: dict) -> None:
)


def main():
def main() -> None:
run_module()


Expand Down
10 changes: 6 additions & 4 deletions module_utils/ceph_common.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import datetime
import time
from typing import TYPE_CHECKING, List, Dict
from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar

if TYPE_CHECKING:
from ansible.module_utils.basic import AnsibleModule # type: ignore

ExceptionType = TypeVar('ExceptionType', bound=BaseException)

def retry(exceptions, retries=20, delay=1):
def decorator(f):
def _retry(*args, **kwargs):

def retry(exceptions: Type[ExceptionType], retries: int = 20, delay: int = 1) -> Callable:
def decorator(f: Callable) -> Callable:
def _retry(*args: Any, **kwargs: Any) -> Callable:
_tries = retries
while _tries > 1:
try:
Expand Down

0 comments on commit 15ec250

Please sign in to comment.