Skip to content

Commit

Permalink
Merge pull request #2 from asm0deuz/fix_ci_test
Browse files Browse the repository at this point in the history
Fixing all CI errors
  • Loading branch information
asm0deuz authored Jul 16, 2024
2 parents 33cd0da + d9577ab commit 51ff35b
Show file tree
Hide file tree
Showing 19 changed files with 587 additions and 204 deletions.
1 change: 1 addition & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ issues: http://example.com/issue/tracker
build_ignore:
- .gitignore
- changelogs/.plugin-cache.yaml
- ".*"
# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a
# list of MANIFEST.in style
# L(directives,https://packaging.python.org/en/latest/guides/using-manifest-in/#manifest-in-commands). The key
Expand Down
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
requires_ansible: ">=2.14.0"
requires_ansible: ">=2.15.0"
13 changes: 8 additions & 5 deletions plugins/module_utils/ceph_common.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type

import datetime
import time
from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar
from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar, Optional

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

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


def retry(exceptions: Type[ExceptionType], retries: int = 20, delay: int = 1) -> Callable:
def retry(exceptions: Type[ExceptionType], module: "AnsibleModule", 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:
print("{}".format(_tries))
module.debug(_tries)
return f(*args, **kwargs)
except exceptions:
time.sleep(delay)
_tries -= 1
print("{} has failed after {} tries".format(f, retries))
module.debug(f, " has failed after ", retries, " retries")
return f(*args, **kwargs)
return _retry
return decorator
Expand Down Expand Up @@ -63,7 +66,7 @@ def exit_module(module: "AnsibleModule",
out: str = '',
err: str = '',
changed: bool = False,
diff: Dict[str, str] = dict(before="", after="")) -> None:
diff: Optional[Dict[str, str]] = None) -> None:
endd = datetime.datetime.now()
delta = endd - startd

Expand Down
33 changes: 20 additions & 13 deletions plugins/modules/ceph_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
# Author: Guillaume Abrioux <[email protected]>

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

import datetime
import json

from ansible.module_utils.basic import AnsibleModule # type: ignore
try:
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore
except ImportError:
from module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore

ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
Expand All @@ -25,38 +15,45 @@
---
module: ceph_config
short_description: set ceph config
version_added: "2.10"
version_added: "1.0.0"
description:
- Set Ceph config options.
options:
fsid:
description:
- the fsid of the Ceph cluster to interact with.
type: str
required: false
image:
description:
- The Ceph container image to use.
type: str
required: false
action:
description:
- whether to get or set the parameter specified in 'option'
required: false
type: str
choices: ['get', 'set']
default: 'set'
who:
description:
- which daemon the configuration should be set to
type: str
required: true
option:
description:
- name of the parameter to be set
type: str
required: true
value:
description:
- value of the parameter
required: true if action is 'set'
type: str
required: false
author:
- Guillaume Abrioux <[email protected]>
- guillaume abrioux (@guits)
'''

EXAMPLES = '''
Expand Down Expand Up @@ -84,6 +81,16 @@

RETURN = '''# '''

from typing import Any, Dict, List, Tuple, Union
from ansible.module_utils.basic import AnsibleModule # type: ignore
try:
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore
except ImportError:
from module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore

import datetime
import json


def set_option(module: "AnsibleModule",
who: str,
Expand Down
53 changes: 39 additions & 14 deletions plugins/modules/ceph_orch_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,8 @@
# limitations under the License.

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

import datetime
import yaml

from ansible.module_utils.basic import AnsibleModule # type: ignore
try:
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_orch # type: ignore
except ImportError:
from module_utils.ceph_common import exit_module, build_base_cmd_orch


ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
Expand All @@ -38,24 +27,33 @@
---
module: ceph_orch_apply
short_description: apply service spec
version_added: "2.9"
version_added: "1.0.0"
description:
- apply a service spec
options:
fsid:
description:
- the fsid of the Ceph cluster to interact with.
type: str
required: false
image:
description:
- The Ceph container image to use.
type: str
required: false
docker:
description:
- Use docker instead of podman
type: bool
required: false
default: false
spec:
description:
- The service spec to apply
type: str
required: true
author:
- Guillaume Abrioux <[email protected]>
- Guillaume Abrioux (@guits)
'''

EXAMPLES = '''
Expand All @@ -71,6 +69,28 @@
all: true
'''

RETURN = '''# '''

import traceback
from ansible.module_utils.basic import missing_required_lib
try:
import yaml
except ImportError:
HAS_ANOTHER_LIBRARY = False
ANOTHER_LIBRARY_IMPORT_ERROR = traceback.format_exc()
else:
HAS_ANOTHER_LIBRARY = True
ANOTHER_LIBRARY_IMPORT_ERROR = None

from typing import List, Tuple, Dict
import datetime

from ansible.module_utils.basic import AnsibleModule # type: ignore
try:
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, build_base_cmd_orch # type: ignore
except ImportError:
from module_utils.ceph_common import exit_module, build_base_cmd_orch


def parse_spec(spec: str) -> Dict:
""" parse spec string to yaml """
Expand Down Expand Up @@ -123,7 +143,7 @@ def run_module() -> None:
module_args = dict(
spec=dict(type='str', required=True),
fsid=dict(type='str', required=False),
docker=dict(type=bool,
docker=dict(type='bool',
required=False,
default=False),
image=dict(type='str', required=False)
Expand All @@ -134,6 +154,11 @@ def run_module() -> None:
supports_check_mode=True
)

if not HAS_ANOTHER_LIBRARY:
module.fail_json(
msg=missing_required_lib('another_library'),
exception=ANOTHER_LIBRARY_IMPORT_ERROR)

startd = datetime.datetime.now()
spec = module.params.get('spec')

Expand Down
43 changes: 29 additions & 14 deletions plugins/modules/ceph_orch_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
# Author: Guillaume Abrioux <[email protected]>

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

import datetime
import json

from ansible.module_utils.basic import AnsibleModule # type: ignore
try:
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore
except ImportError:
from module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore

ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
Expand All @@ -25,36 +15,51 @@
---
module: ceph_orch_daemon
short_description: stop/start daemon
version_added: "2.9"
version_added: "1.0.0"
description:
- Start, stop or restart ceph daemon
options:
fsid:
description:
- the fsid of the Ceph cluster to interact with.
type: str
required: false
image:
description:
- The Ceph container image to use.
type: str
required: false
docker:
description:
- Use docker instead of podman
type: bool
default: false
required: false
state:
description:
- The desired state of the service specified in 'name'.
If 'started', it ensures the service is started.
If 'stopped', it ensures the service is stopped.
If 'restarted', it will restart the service.
choices:
- started
- stopped
- restarted
type: str
required: True
daemon_id:
description:
- The id of the service.
type: str
required: true
daemon_type:
description:
- The type of the service.
type: str
required: true
author:
- Guillaume Abrioux <[email protected]>
- Guillaume Abrioux (@guits)
'''

EXAMPLES = '''
Expand All @@ -73,6 +78,16 @@

RETURN = '''# '''

from ansible.module_utils.basic import AnsibleModule # type: ignore
try:
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore
except ImportError:
from module_utils.ceph_common import retry, exit_module, build_base_cmd_orch, fatal # type: ignore

from typing import List, Tuple
import datetime
import json


def get_current_state(module: "AnsibleModule",
daemon_type: str,
Expand All @@ -97,7 +112,7 @@ def update_daemon_status(module: "AnsibleModule",
return rc, cmd, out, err


@retry(RuntimeError)
@retry(RuntimeError, AnsibleModule)
def validate_updated_status(module: "AnsibleModule",
action: str,
daemon_type: str,
Expand All @@ -116,7 +131,7 @@ def main() -> None:
choices=['started', 'stopped', 'restarted']),
daemon_id=dict(type='str', required=True),
daemon_type=dict(type='str', required=True),
docker=dict(type=bool,
docker=dict(type='bool',
required=False,
default=False),
fsid=dict(type='str', required=False),
Expand Down
Loading

0 comments on commit 51ff35b

Please sign in to comment.