Skip to content

Commit 15ec250

Browse files
committed
tests: address mypy errors
The new mypy options used brought out new mypy errors. This commit addresses them. Signed-off-by: Guillaume Abrioux <[email protected]>
1 parent 0ab763d commit 15ec250

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

Diff for: library/ceph_config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Author: Guillaume Abrioux <[email protected]>
44

55
from __future__ import absolute_import, division, print_function
6-
from typing import List, Tuple
6+
from typing import Any, Dict, List, Tuple, Union
77
__metaclass__ = type
88

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

9999

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

109109

110-
def get_current_value(who, option, config_dump):
110+
def get_current_value(who: str, option: str, config_dump: List[Dict[str, Any]]) -> Union[str, None]:
111111
for config in config_dump:
112112
if config['section'] == who and config['name'] == option:
113113
return config['value']

Diff for: library/ceph_orch_apply.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def apply_spec(module: "AnsibleModule",
8282
return rc, cmd, out, err
8383

8484

85-
def main():
85+
def main() -> None:
8686
module = AnsibleModule(
8787
argument_spec=dict(
8888
fsid=dict(type='str', required=False),

Diff for: library/cephadm_bootstrap.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,14 @@ def run_module() -> None:
249249
ceph_pubkey = 'ceph.pub'
250250

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

257257
if fsid:
258258
if os.path.exists(os.path.join(data_dir, fsid)):
259-
out = f"A cluster with fsid {fsid} is already deployed."
259+
out = f'A cluster with fsid {fsid} is already deployed.'
260260
exit_module(
261261
rc=0,
262262
startd=startd,
@@ -339,7 +339,7 @@ def extend_append(key: str, parameters: dict) -> None:
339339
)
340340

341341

342-
def main():
342+
def main() -> None:
343343
run_module()
344344

345345

Diff for: module_utils/ceph_common.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import datetime
22
import time
3-
from typing import TYPE_CHECKING, List, Dict
3+
from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar
44

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

8+
ExceptionType = TypeVar('ExceptionType', bound=BaseException)
89

9-
def retry(exceptions, retries=20, delay=1):
10-
def decorator(f):
11-
def _retry(*args, **kwargs):
10+
11+
def retry(exceptions: Type[ExceptionType], retries: int = 20, delay: int = 1) -> Callable:
12+
def decorator(f: Callable) -> Callable:
13+
def _retry(*args: Any, **kwargs: Any) -> Callable:
1214
_tries = retries
1315
while _tries > 1:
1416
try:

0 commit comments

Comments
 (0)