Skip to content

Commit

Permalink
library: move fatal() into ca_common.py
Browse files Browse the repository at this point in the history
this function is defined in various modules, let's move it to
`ca_common.py`

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
  • Loading branch information
guits committed Jan 27, 2021
1 parent bbcad96 commit 959140e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 36 deletions.
14 changes: 4 additions & 10 deletions library/ceph_crush.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import fatal
except ImportError:
from module_utils.ca_common import fatal
import datetime

ANSIBLE_METADATA = {
Expand Down Expand Up @@ -62,16 +66,6 @@
RETURN = '''# '''


def fatal(message, module):
'''
Report a fatal error and exit
'''
if module:
module.fail_json(msg=message, rc=1)
else:
raise(Exception(message))


def generate_cmd(cluster, subcommand, bucket, bucket_type, containerized=None):
'''
Generate command line to execute
Expand Down
15 changes: 2 additions & 13 deletions library/ceph_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import is_containerized, container_exec
from ansible.module_utils.ca_common import is_containerized, container_exec, fatal
except ImportError:
from module_utils.ca_common import is_containerized, container_exec
from module_utils.ca_common import is_containerized, container_exec, fatal
import datetime
import json
import os
Expand Down Expand Up @@ -219,17 +219,6 @@ def str_to_bool(val):
raise ValueError("Invalid input value: %s" % val)


def fatal(message, module):
'''
Report a fatal error and exit
'''

if module:
module.fail_json(msg=message, rc=1)
else:
raise(Exception(message))


def generate_secret():
'''
Generate a CephX secret
Expand Down
15 changes: 2 additions & 13 deletions library/ceph_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exec_command, is_containerized
from ansible.module_utils.ca_common import exec_command, is_containerized, fatal
except ImportError:
from module_utils.ca_common import exec_command, is_containerized
from module_utils.ca_common import exec_command, is_containerized, fatal
import datetime
import copy
import json
Expand Down Expand Up @@ -186,17 +186,6 @@
'''


def fatal(message, module):
'''
Report a fatal error and exit
'''

if module:
module.fail_json(msg=message, changed=False, rc=1)
else:
raise(Exception(message))


def container_exec(binary, container_image):
'''
Build the docker CLI to run a command inside a container
Expand Down
10 changes: 10 additions & 0 deletions module_utils/ca_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ def exit_module(module, out, rc, cmd, err, startd, changed=False):
changed=changed,
)
module.exit_json(**result)

def fatal(message, module):
'''
Report a fatal error and exit
'''

if module:
module.fail_json(msg=message, rc=1)
else:
raise(Exception(message))

0 comments on commit 959140e

Please sign in to comment.