Skip to content

Commit 51ff35b

Browse files
authored
Merge pull request #2 from asm0deuz/fix_ci_test
Fixing all CI errors
2 parents 33cd0da + d9577ab commit 51ff35b

19 files changed

+587
-204
lines changed

galaxy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ issues: http://example.com/issue/tracker
2828
build_ignore:
2929
- .gitignore
3030
- changelogs/.plugin-cache.yaml
31+
- ".*"
3132
# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a
3233
# list of MANIFEST.in style
3334
# L(directives,https://packaging.python.org/en/latest/guides/using-manifest-in/#manifest-in-commands). The key

meta/runtime.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
requires_ansible: ">=2.14.0"
2+
requires_ansible: ">=2.15.0"

plugins/module_utils/ceph_common.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1+
from __future__ import absolute_import, division, print_function
2+
__metaclass__ = type
3+
14
import datetime
25
import time
3-
from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar
6+
from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar, Optional
47

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

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

1013

11-
def retry(exceptions: Type[ExceptionType], retries: int = 20, delay: int = 1) -> Callable:
14+
def retry(exceptions: Type[ExceptionType], module: "AnsibleModule", retries: int = 20, delay: int = 1) -> Callable:
1215
def decorator(f: Callable) -> Callable:
1316
def _retry(*args: Any, **kwargs: Any) -> Callable:
1417
_tries = retries
1518
while _tries > 1:
1619
try:
17-
print("{}".format(_tries))
20+
module.debug(_tries)
1821
return f(*args, **kwargs)
1922
except exceptions:
2023
time.sleep(delay)
2124
_tries -= 1
22-
print("{} has failed after {} tries".format(f, retries))
25+
module.debug(f, " has failed after ", retries, " retries")
2326
return f(*args, **kwargs)
2427
return _retry
2528
return decorator
@@ -63,7 +66,7 @@ def exit_module(module: "AnsibleModule",
6366
out: str = '',
6467
err: str = '',
6568
changed: bool = False,
66-
diff: Dict[str, str] = dict(before="", after="")) -> None:
69+
diff: Optional[Dict[str, str]] = None) -> None:
6770
endd = datetime.datetime.now()
6871
delta = endd - startd
6972

plugins/modules/ceph_config.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,8 @@
33
# Author: Guillaume Abrioux <[email protected]>
44

55
from __future__ import absolute_import, division, print_function
6-
from typing import Any, Dict, List, Tuple, Union
76
__metaclass__ = type
87

9-
import datetime
10-
import json
11-
12-
from ansible.module_utils.basic import AnsibleModule # type: ignore
13-
try:
14-
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore
15-
except ImportError:
16-
from module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore
17-
188
ANSIBLE_METADATA = {
199
'metadata_version': '1.1',
2010
'status': ['preview'],
@@ -25,38 +15,45 @@
2515
---
2616
module: ceph_config
2717
short_description: set ceph config
28-
version_added: "2.10"
18+
version_added: "1.0.0"
2919
description:
3020
- Set Ceph config options.
3121
options:
3222
fsid:
3323
description:
3424
- the fsid of the Ceph cluster to interact with.
25+
type: str
3526
required: false
3627
image:
3728
description:
3829
- The Ceph container image to use.
30+
type: str
3931
required: false
4032
action:
4133
description:
4234
- whether to get or set the parameter specified in 'option'
4335
required: false
36+
type: str
37+
choices: ['get', 'set']
4438
default: 'set'
4539
who:
4640
description:
4741
- which daemon the configuration should be set to
42+
type: str
4843
required: true
4944
option:
5045
description:
5146
- name of the parameter to be set
47+
type: str
5248
required: true
5349
value:
5450
description:
5551
- value of the parameter
56-
required: true if action is 'set'
52+
type: str
53+
required: false
5754
5855
author:
59-
- Guillaume Abrioux <[email protected]>
56+
- guillaume abrioux (@guits)
6057
'''
6158

6259
EXAMPLES = '''
@@ -84,6 +81,16 @@
8481

8582
RETURN = '''# '''
8683

84+
from typing import Any, Dict, List, Tuple, Union
85+
from ansible.module_utils.basic import AnsibleModule # type: ignore
86+
try:
87+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore
88+
except ImportError:
89+
from module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore
90+
91+
import datetime
92+
import json
93+
8794

8895
def set_option(module: "AnsibleModule",
8996
who: str,

plugins/modules/ceph_orch_apply.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,8 @@
1515
# limitations under the License.
1616

1717
from __future__ import absolute_import, division, print_function
18-
from typing import List, Tuple, Dict
1918
__metaclass__ = type
2019

21-
import datetime
22-
import yaml
23-
24-
from ansible.module_utils.basic import AnsibleModule # type: ignore
25-
try:
26-
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_orch # type: ignore
27-
except ImportError:
28-
from module_utils.ceph_common import exit_module, build_base_cmd_orch
29-
30-
3120
ANSIBLE_METADATA = {
3221
'metadata_version': '1.1',
3322
'status': ['preview'],
@@ -38,24 +27,33 @@
3827
---
3928
module: ceph_orch_apply
4029
short_description: apply service spec
41-
version_added: "2.9"
30+
version_added: "1.0.0"
4231
description:
4332
- apply a service spec
4433
options:
4534
fsid:
4635
description:
4736
- the fsid of the Ceph cluster to interact with.
37+
type: str
4838
required: false
4939
image:
5040
description:
5141
- The Ceph container image to use.
42+
type: str
5243
required: false
44+
docker:
45+
description:
46+
- Use docker instead of podman
47+
type: bool
48+
required: false
49+
default: false
5350
spec:
5451
description:
5552
- The service spec to apply
53+
type: str
5654
required: true
5755
author:
58-
- Guillaume Abrioux <[email protected]>
56+
- Guillaume Abrioux (@guits)
5957
'''
6058

6159
EXAMPLES = '''
@@ -71,6 +69,28 @@
7169
all: true
7270
'''
7371

72+
RETURN = '''# '''
73+
74+
import traceback
75+
from ansible.module_utils.basic import missing_required_lib
76+
try:
77+
import yaml
78+
except ImportError:
79+
HAS_ANOTHER_LIBRARY = False
80+
ANOTHER_LIBRARY_IMPORT_ERROR = traceback.format_exc()
81+
else:
82+
HAS_ANOTHER_LIBRARY = True
83+
ANOTHER_LIBRARY_IMPORT_ERROR = None
84+
85+
from typing import List, Tuple, Dict
86+
import datetime
87+
88+
from ansible.module_utils.basic import AnsibleModule # type: ignore
89+
try:
90+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_orch # type: ignore
91+
except ImportError:
92+
from module_utils.ceph_common import exit_module, build_base_cmd_orch
93+
7494

7595
def parse_spec(spec: str) -> Dict:
7696
""" parse spec string to yaml """
@@ -123,7 +143,7 @@ def run_module() -> None:
123143
module_args = dict(
124144
spec=dict(type='str', required=True),
125145
fsid=dict(type='str', required=False),
126-
docker=dict(type=bool,
146+
docker=dict(type='bool',
127147
required=False,
128148
default=False),
129149
image=dict(type='str', required=False)
@@ -134,6 +154,11 @@ def run_module() -> None:
134154
supports_check_mode=True
135155
)
136156

157+
if not HAS_ANOTHER_LIBRARY:
158+
module.fail_json(
159+
msg=missing_required_lib('another_library'),
160+
exception=ANOTHER_LIBRARY_IMPORT_ERROR)
161+
137162
startd = datetime.datetime.now()
138163
spec = module.params.get('spec')
139164

plugins/modules/ceph_orch_daemon.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,8 @@
33
# Author: Guillaume Abrioux <[email protected]>
44

55
from __future__ import absolute_import, division, print_function
6-
from typing import List, Tuple
76
__metaclass__ = type
87

9-
import datetime
10-
import json
11-
12-
from ansible.module_utils.basic import AnsibleModule # type: ignore
13-
try:
14-
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore
15-
except ImportError:
16-
from module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore
17-
188
ANSIBLE_METADATA = {
199
'metadata_version': '1.1',
2010
'status': ['preview'],
@@ -25,36 +15,51 @@
2515
---
2616
module: ceph_orch_daemon
2717
short_description: stop/start daemon
28-
version_added: "2.9"
18+
version_added: "1.0.0"
2919
description:
3020
- Start, stop or restart ceph daemon
3121
options:
3222
fsid:
3323
description:
3424
- the fsid of the Ceph cluster to interact with.
25+
type: str
3526
required: false
3627
image:
3728
description:
3829
- The Ceph container image to use.
30+
type: str
31+
required: false
32+
docker:
33+
description:
34+
- Use docker instead of podman
35+
type: bool
36+
default: false
3937
required: false
4038
state:
4139
description:
4240
- The desired state of the service specified in 'name'.
4341
If 'started', it ensures the service is started.
4442
If 'stopped', it ensures the service is stopped.
4543
If 'restarted', it will restart the service.
44+
choices:
45+
- started
46+
- stopped
47+
- restarted
48+
type: str
4649
required: True
4750
daemon_id:
4851
description:
4952
- The id of the service.
53+
type: str
5054
required: true
5155
daemon_type:
5256
description:
5357
- The type of the service.
58+
type: str
5459
required: true
5560
5661
author:
57-
- Guillaume Abrioux <[email protected]>
62+
- Guillaume Abrioux (@guits)
5863
'''
5964

6065
EXAMPLES = '''
@@ -73,6 +78,16 @@
7378

7479
RETURN = '''# '''
7580

81+
from ansible.module_utils.basic import AnsibleModule # type: ignore
82+
try:
83+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore
84+
except ImportError:
85+
from module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore
86+
87+
from typing import List, Tuple
88+
import datetime
89+
import json
90+
7691

7792
def get_current_state(module: "AnsibleModule",
7893
daemon_type: str,
@@ -97,7 +112,7 @@ def update_daemon_status(module: "AnsibleModule",
97112
return rc, cmd, out, err
98113

99114

100-
@retry(RuntimeError)
115+
@retry(RuntimeError, AnsibleModule)
101116
def validate_updated_status(module: "AnsibleModule",
102117
action: str,
103118
daemon_type: str,
@@ -116,7 +131,7 @@ def main() -> None:
116131
choices=['started', 'stopped', 'restarted']),
117132
daemon_id=dict(type='str', required=True),
118133
daemon_type=dict(type='str', required=True),
119-
docker=dict(type=bool,
134+
docker=dict(type='bool',
120135
required=False,
121136
default=False),
122137
fsid=dict(type='str', required=False),

0 commit comments

Comments
 (0)