diff --git a/plugins/module_utils/ceph_common.py b/plugins/module_utils/ceph_common.py index 6929f14..a7f4d35 100644 --- a/plugins/module_utils/ceph_common.py +++ b/plugins/module_utils/ceph_common.py @@ -2,6 +2,7 @@ __metaclass__ = type import datetime +import os import time from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar, Optional @@ -10,6 +11,7 @@ ExceptionType = TypeVar('ExceptionType', bound=BaseException) + def generate_cmd(cmd='ceph', sub_cmd=None, args=None, diff --git a/plugins/modules/ceph_add_users_buckets.py b/plugins/modules/ceph_add_users_buckets.py index d00b162..8bf6882 100644 --- a/plugins/modules/ceph_add_users_buckets.py +++ b/plugins/modules/ceph_add_users_buckets.py @@ -1,14 +1,22 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- -# Copyright 2018 Daniel Pivonka -# Copyright 2018 Red Hat, Inc. +# Copyright 2018, Red Hat, Inc. # -# GNU General Public License v3.0+ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -from ansible.module_utils.basic import AnsibleModule -from socket import error as socket_error -import boto -import radosgw +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = { 'metadata_version': '1.1', @@ -20,36 +28,43 @@ --- module: ceph_add_users_buckets short_description: bulk create user and buckets +version_added: "1.0.0" description: - Bulk create Ceph Object Storage users and buckets - -option: +options: rgw_host: description: - a radosgw host in the ceph cluster + type: str required: true port: description: - tcp port of the radosgw host + type: int required: true is_secure: description: - boolean indicating whether the instance is running over https + type: bool required: false default: false admin_access_key: description: - radosgw admin user's access key + type: str required: true admin_secret_key: description: - radosgw admin user's secret key + type: str required: true users: description: - list of users to be created containing sub options + type: list + elements: dict required: false - sub_options: + suboptions: username: description: - username for new user @@ -118,8 +133,10 @@ buckets: description: - list of buckets to be created containing sub options + type: list + elements: dict required: false - sub_options: + suboptions: bucket: description: - name for new bucket @@ -133,128 +150,127 @@ requirements: ['radosgw', 'boto'] author: - - 'Daniel Pivonka' + - Daniel Pivonka (@Daniel-Pivonka) ''' EXAMPLES = ''' # single basic user - name: single basic user - ceph_add_users_buckets: - rgw_host: '172.16.0.12' - port: 8080 - admin_access_key: 'N61I8625V4XTWGDTLBLL' - admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' - users: - - username: 'test1' - fullname: 'tester' + ceph_add_users_buckets: + rgw_host: '172.16.0.12' + port: 8080 + admin_access_key: 'N61I8625V4XTWGDTLBLL' + admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' + users: + - username: 'test1' + fullname: 'tester' # single complex user - name: single complex user - ceph_add_users_buckets: - rgw_host: '172.16.0.12' - port: 8080 - admin_access_key: 'N61I8625V4XTWGDTLBLL' - admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' - users: - - username: 'test1' - fullname: 'tester' - email: 'dan@email.com' - maxbucket: 666 - suspend: true - autogenkey: true - accesskey: 'B3AR4Q33L59YV56A9A2F' - secretkey: 'd84BRnMysnVGSyZiRlYUMduVgIarQWiNMdKzrF76' - userquota: true - usermaxsize: '1000' - usermaxobjects: 3 - bucketquota: true - bucketmaxsize: '1000' - bucketmaxobjects: 3 + ceph_add_users_buckets: + rgw_host: '172.16.0.12' + port: 8080 + admin_access_key: 'N61I8625V4XTWGDTLBLL' + admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' + users: + - username: 'test1' + fullname: 'tester' + email: 'dan@email.com' + maxbucket: 666 + suspend: true + autogenkey: true + accesskey: 'B3AR4Q33L59YV56A9A2F' + secretkey: 'd84BRnMysnVGSyZiRlYUMduVgIarQWiNMdKzrF76' + userquota: true + usermaxsize: '1000' + usermaxobjects: 3 + bucketquota: true + bucketmaxsize: '1000' + bucketmaxobjects: 3 # multi user - name: multi user - ceph_add_users_buckets: - rgw_host: '172.16.0.12' - port: 8080 - admin_access_key: 'N61I8625V4XTWGDTLBLL' - admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' - users: - - username: 'test1' - fullname: 'tester' - email: 'dan@email.com' - maxbucket: 666 - suspend: true - autogenkey: true - accesskey: 'B3AR4Q33L59YV56A9A2F' - secretkey: 'd84BRnMysnVGSyZiRlYUMduVgIarQWiNMdKzrF76' - userquota: true - usermaxsize: '1000K' - usermaxobjects: 3 - bucketquota: true - bucketmaxsize: '1000K' - bucketmaxobjects: 3 - - username: 'test2' - fullname: 'tester' + ceph_add_users_buckets: + rgw_host: '172.16.0.12' + port: 8080 + admin_access_key: 'N61I8625V4XTWGDTLBLL' + admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' + users: + - username: 'test1' + fullname: 'tester' + email: 'dan@email.com' + maxbucket: 666 + suspend: true + autogenkey: true + accesskey: 'B3AR4Q33L59YV56A9A2F' + secretkey: 'd84BRnMysnVGSyZiRlYUMduVgIarQWiNMdKzrF76' + userquota: true + usermaxsize: '1000K' + usermaxobjects: 3 + bucketquota: true + bucketmaxsize: '1000K' + bucketmaxobjects: 3 + - username: 'test2' + fullname: 'tester' # single bucket - name: single basic user - ceph_add_users_buckets: - rgw_host: '172.16.0.12' - port: 8080 - admin_access_key: 'N61I8625V4XTWGDTLBLL' - admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' - buckets: - - bucket: 'heyimabucket1' - user: 'test1' + ceph_add_users_buckets: + rgw_host: '172.16.0.12' + port: 8080 + admin_access_key: 'N61I8625V4XTWGDTLBLL' + admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' + buckets: + - bucket: 'heyimabucket1' + user: 'test1' # multi bucket - name: single basic user - ceph_add_users_buckets: - rgw_host: '172.16.0.12' - port: 8080 - admin_access_key: 'N61I8625V4XTWGDTLBLL' - admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' - buckets: - - bucket: 'heyimabucket1' - user: 'test1' - - bucket: 'heyimabucket2' - user: 'test2' - - bucket: 'heyimabucket3' - user: 'test2' + ceph_add_users_buckets: + rgw_host: '172.16.0.12' + port: 8080 + admin_access_key: 'N61I8625V4XTWGDTLBLL' + admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' + buckets: + - bucket: 'heyimabucket1' + user: 'test1' + - bucket: 'heyimabucket2' + user: 'test2' + - bucket: 'heyimabucket3' + user: 'test2' # buckets and users - name: single basic user - ceph_add_users_buckets: - rgw_host: '172.16.0.12' - port: 8080 - admin_access_key: 'N61I8625V4XTWGDTLBLL' - admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' - users: - - username: 'test1' - fullname: 'tester' - email: 'dan@email.com' - maxbucket: 666 - - username: 'test2' - fullname: 'tester' - email: 'dan1@email.com' - accesskey: 'B3AR4Q33L59YV56A9A2F' - secretkey: 'd84BRnMysnVGSyZiRlYUMduVgIarQWiNMdKzrF76' - userquota: true - usermaxsize: '1000' - usermaxobjects: 3 - bucketquota: true - bucketmaxsize: '1000' - bucketmaxobjects: 3 - buckets: - - bucket: 'heyimabucket1' - user: 'test1' - - bucket: 'heyimabucket2' - user: 'test2' - - bucket: 'heyimabucket3' - user: 'test2' - + ceph_add_users_buckets: + rgw_host: '172.16.0.12' + port: 8080 + admin_access_key: 'N61I8625V4XTWGDTLBLL' + admin_secret_key: 'HZrkuHHO9usUurDWBQHTeLIjO325bIULaC7DxcoV' + users: + - username: 'test1' + fullname: 'tester' + email: 'dan@email.com' + maxbucket: 666 + - username: 'test2' + fullname: 'tester' + email: 'dan1@email.com' + accesskey: 'B3AR4Q33L59YV56A9A2F' + secretkey: 'd84BRnMysnVGSyZiRlYUMduVgIarQWiNMdKzrF76' + userquota: true + usermaxsize: '1000' + usermaxobjects: 3 + bucketquota: true + bucketmaxsize: '1000' + bucketmaxobjects: 3 + buckets: + - bucket: 'heyimabucket1' + user: 'test1' + - bucket: 'heyimabucket2' + user: 'test2' + - bucket: 'heyimabucket3' + user: 'test2' ''' RETURN = ''' @@ -292,6 +308,11 @@ ''' +from ansible.module_utils.basic import AnsibleModule # type: ignore +from socket import error as socket_error +import boto +import radosgw + def create_users(rgw, users, result): diff --git a/plugins/modules/ceph_authtool.py b/plugins/modules/ceph_authtool.py index bfdc379..9b5b53b 100644 --- a/plugins/modules/ceph_authtool.py +++ b/plugins/modules/ceph_authtool.py @@ -1,13 +1,104 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Copyright 2018, Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community' +} + +DOCUMENTATION = ''' +--- +module: ceph_authtool +short_description: ceph keyring manipulation +version_added: "1.0.0" +description: + - Create, view, and modify a Ceph keyring file. +options: + name: + description: + - specify entityname to operate on + type: str + required: false + create_keyring: + description: + - will create a new keyring, overwriting any existing keyringfile + type: bool + required: false + default: false + gen_key: + description: + - will generate a new secret key for the specified entityname + type: bool + required: false + default: false + add_key: + description: + - will add an encoded key to the keyring + type: str + required: false + import_keyring: + description: + - will import the content of a given keyring to the keyringfile + type: str + required: false + caps: + description: + - will set the capability for given subsystem + type: dict + required: false + path: + description: + - where the caps file will be created + type: str + required: true +author: + - guillaume abrioux (@guits) +''' + +EXAMPLES = ''' +- name: Create admin keyring + ceph_authtool: + name: client.admin + path: "/etc/ceph/ceph.client.admin.keyring" + owner: 'ceph' + group: 'ceph' + mode: "0400" + caps: + mon: allow * + mgr: allow * + osd: allow * + mds: allow * + create_keyring: true + gen_key: true + add_key: admin_secret +''' + +RETURN = '''# ''' + +from ansible.module_utils.basic import AnsibleModule # type: ignore try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import container_exec, \ - is_containerized + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import container_exec, is_containerized # type: ignore except ImportError: - from module_utils.ca_common import container_exec, \ - is_containerized + from module_utils.ceph_common import container_exec, is_containerized + import datetime import os @@ -59,8 +150,8 @@ def run_module(): name=dict(type='str', required=False), create_keyring=dict(type='bool', required=False, default=False), gen_key=dict(type='bool', required=False, default=False), - add_key=dict(type='str', required=False, default=None), - import_keyring=dict(type='str', required=False, default=None), + add_key=dict(type='str', required=False, default=None, no_log=False), + import_keyring=dict(type='str', required=False, default=None, no_log=False), caps=dict(type='dict', required=False, default=None), path=dict(type='str', required=True) ) diff --git a/plugins/modules/ceph_config.py b/plugins/modules/ceph_config.py index 17a4644..f56909c 100644 --- a/plugins/modules/ceph_config.py +++ b/plugins/modules/ceph_config.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright Red Hat # SPDX-License-Identifier: Apache-2.0 # Author: Guillaume Abrioux @@ -32,10 +35,10 @@ action: description: - whether to get or set the parameter specified in 'option' - required: false type: str choices: ['get', 'set'] default: 'set' + required: false who: description: - which daemon the configuration should be set to diff --git a/plugins/modules/ceph_crush.py b/plugins/modules/ceph_crush.py index 38cb5eb..1a1567f 100644 --- a/plugins/modules/ceph_crush.py +++ b/plugins/modules/ceph_crush.py @@ -1,19 +1,23 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- -# Copyright (c) 2018 Red Hat, Inc. +# Copyright 2018, Red Hat, Inc. # -# GNU General Public License v3.0+ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal -except ImportError: - from module_utils.ca_common import fatal -import datetime - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -23,34 +27,28 @@ DOCUMENTATION = ''' --- module: ceph_crush - -author: Sebastien Han - short_description: Create Ceph CRUSH hierarchy - -version_added: "2.6" - +version_added: "1.0.0" description: - - By using the hostvar variable 'osd_crush_location' - ceph_crush creates buckets and places them in the right CRUSH hierarchy - + - By using the hostvar variable 'osd_crush_location' ceph_crush creates buckets and places them in the right CRUSH hierarchy options: cluster: description: - The ceph cluster name. + type: str required: false default: ceph location: description: - - osd_crush_location dict from the inventory file. It contains - the placement of each host in the CRUSH map. + - osd_crush_location dict from the inventory file. It contains the placement of each host in the CRUSH map. + type: dict required: true containerized: description: - - Weither or not this is a containerized cluster. The value is - assigned or not depending on how the playbook runs. + - Weither or not this is a containerized cluster. The value is assigned or not depending on how the playbook runs. + type: str required: false - default: None +author: Sebastien Han (@leseb) ''' EXAMPLES = ''' @@ -65,6 +63,13 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal +except ImportError: + from module_utils.ceph_common import fatal +import datetime + def generate_cmd(cluster, subcommand, bucket, bucket_type, containerized=None): ''' diff --git a/plugins/modules/ceph_crush_rule.py b/plugins/modules/ceph_crush_rule.py index b75c24d..343a590 100644 --- a/plugins/modules/ceph_crush_rule.py +++ b/plugins/modules/ceph_crush_rule.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,21 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \ - generate_cmd, \ - is_containerized, \ - exec_command -except ImportError: - from module_utils.ca_common import exit_module, \ - generate_cmd, \ - is_containerized, \ - exec_command -import datetime -import json - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -40,7 +28,7 @@ --- module: ceph_crush_rule short_description: Manage Ceph Crush Replicated/Erasure Rule -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph Crush rule(s) creation, deletion and updates. options: @@ -48,48 +36,53 @@ description: - name of the Ceph Crush rule. If state is 'info' - empty string can be provided as a value to get all crush rules - required: true + type: str + required: false cluster: description: - The ceph cluster name. + type: str required: false default: ceph state: description: - If 'present' is used, the module creates a rule if it doesn't - exist or update it if it already exists. - If 'absent' is used, the module will simply delete the rule. - If 'info' is used, the module will return all details about the - existing rule (json formatted). + - If 'present' is used, the module creates a rule if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the rule. + - If 'info' is used, the module will return all details about the existing rule (json formatted). + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent'] default: present rule_type: description: - The ceph CRUSH rule type. + type: str required: false choices: ['replicated', 'erasure'] - required: false bucket_root: description: - The ceph bucket root for replicated rule. + type: str required: false bucket_type: description: - The ceph bucket type for replicated rule. + type: str required: false choices: ['osd', 'host', 'chassis', 'rack', 'row', 'pdu', 'pod', 'room', 'datacenter', 'zone', 'region', 'root'] device_class: description: - The ceph device class for replicated rule. + type: str required: false profile: description: - The ceph erasure profile for erasure rule. + type: str required: false author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -120,6 +113,21 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \ + generate_cmd, \ + is_containerized, \ + exec_command +except ImportError: + from module_utils.ceph_common import exit_module, \ + generate_cmd, \ + is_containerized, \ + exec_command + +import datetime +import json + def create_rule(module, container_image=None): ''' @@ -192,7 +200,7 @@ def main(): argument_spec=dict( name=dict(type='str', required=False), cluster=dict(type='str', required=False, default='ceph'), - state=dict(type='str', required=False, choices=['present', 'absent', 'info'], default='present'), # noqa: E501 + state=dict(type='str', required=False, choices=['present', 'absent'], default='present'), # noqa: E501 rule_type=dict(type='str', required=False, choices=['replicated', 'erasure']), # noqa: E501 bucket_root=dict(type='str', required=False), bucket_type=dict(type='str', required=False, choices=['osd', 'host', 'chassis', 'rack', 'row', 'pdu', 'pod', # noqa: E501 diff --git a/plugins/modules/ceph_dashboard_user.py b/plugins/modules/ceph_dashboard_user.py index 037a3b9..b968778 100644 --- a/plugins/modules/ceph_dashboard_user.py +++ b/plugins/modules/ceph_dashboard_user.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,20 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \ - is_containerized, \ - exec_command, \ - exit_module, \ - fatal -except ImportError: - from module_utils.ca_common import generate_cmd, is_containerized, exec_command, exit_module, fatal # noqa: E501 - -import datetime -import json - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -41,7 +30,7 @@ short_description: Manage Ceph Dashboard User -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph Dashboard user(s) creation, deletion and updates. @@ -49,34 +38,39 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the Ceph Dashboard user. + type: str required: true state: description: - If 'present' is used, the module creates a user if it doesn't - exist or update it if it already exists. - If 'absent' is used, the module will simply delete the user. - If 'info' is used, the module will return all details about the - existing user (json formatted). + - If 'present' is used, the module creates a user if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the user. + - If 'info' is used, the module will return all details about the existing user (json formatted). + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent'] default: present password: description: - password of the Ceph Dashboard user. + type: str required: false roles: description: - roles of the Ceph Dashboard user. + type: list + choices: ['administrator', 'read-only', 'block-manager', 'rgw-manager', 'cluster-manager', 'pool-manager', 'cephfs-manager'] + elements: str required: false default: [] author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -113,6 +107,20 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \ + is_containerized, \ + exec_command, \ + exit_module, \ + fatal +except ImportError: + from module_utils.ceph_common import generate_cmd, is_containerized, exec_command, exit_module, fatal # noqa: E501 + +import datetime +import json + + def create_user(module, container_image=None): ''' Create a new user @@ -121,7 +129,7 @@ def create_user(module, container_image=None): cluster = module.params.get('cluster') name = module.params.get('name') - args = ['ac-user-create', '-i', '-', name] + args = ['ac-user-create', '-i', '-', name] cmd = generate_cmd(sub_cmd=['dashboard'], args=args, @@ -212,9 +220,10 @@ def run_module(): module_args = dict( cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=True), - state=dict(type='str', required=False, choices=['present', 'absent', 'info'], default='present'), # noqa: E501 + state=dict(type='str', required=False, choices=['present', 'absent'], default='present'), # noqa: E501 password=dict(type='str', required=False, no_log=True), roles=dict(type='list', + elements='str', required=False, choices=['administrator', 'read-only', 'block-manager', 'rgw-manager', 'cluster-manager', 'pool-manager', 'cephfs-manager'], # noqa: E501 default=[]), diff --git a/plugins/modules/ceph_ec_profile.py b/plugins/modules/ceph_ec_profile.py index a854560..2d15ee0 100644 --- a/plugins/modules/ceph_ec_profile.py +++ b/plugins/modules/ceph_ec_profile.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,21 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \ - generate_cmd, \ - exec_command, \ - exit_module -except ImportError: - from module_utils.ca_common import is_containerized, \ - generate_cmd, \ - exec_command, \ - exit_module -import datetime -import json - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -42,7 +30,7 @@ short_description: Manage Ceph Erasure Code profile -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph Erasure Code profile @@ -50,39 +38,91 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the profile. + type: str required: true state: description: - If 'present' is used, the module creates a profile. - If 'absent' is used, the module will delete the profile. + - If 'present' is used, the module creates a profile. + - If 'absent' is used, the module will delete the profile. + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent'] default: present stripe_unit: description: - The amount of data in a data chunk, per stripe. + type: str + required: false + plugin: + description: + - TBD + type: str required: false + default: 'jerasure' k: description: - Number of data-chunks the object will be split in - required: true + type: str + required: false m: description: - - Compute coding chunks for each object and store them on different - OSDs. - required: true + - Compute coding chunks for each object and store them on different OSDs. + type: str + required: false + d: + description: + - Number of data-chunks the object will be split in + type: str + required: false + l: + description: + - TBD + type: str + required: false + c: + description: + - TBD + type: str + required: false + scalar_mds: + description: + - TBD + type: str + required: false + technique: + description: + - TBD + type: str + required: false + crush_root: + description: + - TBD + type: str + required: false + crush_failure_domain: + description: + - TBD + type: str + required: false crush_device_class: description: - Restrict placement to devices of a specific class (hdd/ssd) + type: str required: false - + force: + description: + - TBD + type: bool + required: false + default: false author: - - Guillaume Abrioux + - Guillaume Abrioux (@guits) ''' EXAMPLES = ''' @@ -100,6 +140,21 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \ + generate_cmd, \ + exec_command, \ + exit_module +except ImportError: + from module_utils.ceph_common import is_containerized, \ + generate_cmd, \ + exec_command, \ + exit_module + +import datetime +import json + def get_profile(name, cluster='ceph', container_image=None): ''' diff --git a/plugins/modules/ceph_fs.py b/plugins/modules/ceph_fs.py index ea84b31..66d572f 100644 --- a/plugins/modules/ceph_fs.py +++ b/plugins/modules/ceph_fs.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,22 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \ - exec_command, \ - generate_cmd, \ - exit_module -except ImportError: - from module_utils.ca_common import is_containerized, \ - exec_command, \ - generate_cmd, \ - exit_module - -import datetime -import json - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -43,7 +30,7 @@ short_description: Manage Ceph File System -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph File System(s) creation, deletion and updates. @@ -51,38 +38,42 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the Ceph File System. + type: str required: true state: description: - If 'present' is used, the module creates a filesystem if it - doesn't exist or update it if it already exists. - If 'absent' is used, the module will simply delete the filesystem. - If 'info' is used, the module will return all details about the - existing filesystem (json formatted). + - If 'present' is used, the module creates a filesystem if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the filesystem. + - If 'info' is used, the module will return all details about the existing filesystem (json formatted). + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent'] default: present data: description: - name of the data pool. + type: str required: false metadata: description: - name of the metadata pool. + type: str required: false max_mds: description: - name of the max_mds attribute. + type: int required: false author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -106,6 +97,21 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \ + exec_command, \ + generate_cmd, \ + exit_module +except ImportError: + from module_utils.ceph_common import is_containerized, \ + exec_command, \ + generate_cmd, \ + exit_module + +import datetime +import json + def create_fs(module, container_image=None): ''' @@ -204,7 +210,7 @@ def run_module(): module_args = dict( cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=True), - state=dict(type='str', required=False, choices=['present', 'absent', 'info'], default='present'), # noqa: E501 + state=dict(type='str', required=False, choices=['present', 'absent'], default='present'), # noqa: E501 data=dict(type='str', required=False), metadata=dict(type='str', required=False), max_mds=dict(type='int', required=False), diff --git a/plugins/modules/ceph_key.py b/plugins/modules/ceph_key.py index 12118ce..863181d 100644 --- a/plugins/modules/ceph_key.py +++ b/plugins/modules/ceph_key.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2018, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,26 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \ - is_containerized, \ - container_exec, \ - fatal -except ImportError: - from module_utils.ca_common import generate_cmd, \ - is_containerized, \ - container_exec, \ - fatal -import datetime -import json -import os -import struct -import time -import base64 -import socket - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -45,100 +28,92 @@ --- module: ceph_key -author: Sebastien Han +author: Sebastien Han (@leseb) short_description: Manage Cephx key(s) -version_added: "2.6" +version_added: "1.0.0" description: - - Manage CephX creation, deletion and updates. - It can also list and get information about keyring(s). + - Manage CephX creation, deletion and updates. It can also list and get information about keyring(s). options: cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the CephX key - required: true + type: str + required: false user: description: - - entity used to perform operation. - It corresponds to the -n option (--name) + - entity used to perform operation. It corresponds to the -n option (--name) + type: str required: false + default: 'client.admin' user_key: description: - - the path to the keyring corresponding to the - user being used. - It corresponds to the -k option (--keyring) + - the path to the keyring corresponding to the user being used. It corresponds to the -k option (--keyring) + type: str + required: false state: description: - - If 'present' is used, the module creates a keyring - with the associated capabilities. - If 'present' is used and a secret is provided the module - will always add the key. Which means it will update - the keyring if the secret changes, the same goes for - the capabilities. - If 'absent' is used, the module will simply delete the keyring. - If 'list' is used, the module will list all the keys and will - return a json output. - If 'info' is used, the module will return in a json format the - description of a given keyring. - If 'generate_secret' is used, the module will simply output a cephx keyring. + - If 'present' is used, the module creates a keyring with the associated capabilities. + - If 'present' is used and a secret is provided the module will always add the key. Which means it will update the keyring if the secret changes, the same goes for the capabilities. + - If 'absent' is used, the module will simply delete the keyring. + - If 'list' is used, the module will list all the keys and will return a json output. + - If 'info' is used, the module will return in a json format the description of a given keyring. + - If 'generate_secret' is used, the module will simply output a cephx keyring. + type: str required: false - choices: ['present', 'update', 'absent', 'list', 'info', 'fetch_initial_keys', 'generate_secret'] + choices: ['present', 'update', 'absent', 'fetch_initial_keys', 'generate_secret'] default: present caps: description: - CephX key capabilities - default: None + type: dict required: false secret: description: - keyring's secret value + type: str required: false default: None import_key: description: - - Wether or not to import the created keyring into Ceph. - This can be useful for someone that only wants to generate keyrings - but not add them into Ceph. + - Wether or not to import the created keyring into Ceph. + - This can be useful for someone that only wants to generate keyrings but not add them into Ceph. + type: bool required: false default: True dest: description: - Destination to write the keyring, can a file or a directory + type: str required: false default: /etc/ceph/ fetch_initial_keys: description: - Fetch client.admin and bootstrap key. - This is only needed for Nautilus and above. - Writes down to the filesystem the initial keys generated by the monitor. # noqa: E501 - This command can ONLY run from a monitor node. + - This is only needed for Nautilus and above. + - Writes down to the filesystem the initial keys generated by the monitor. # noqa: E501 + - This command can ONLY run from a monitor node. required: false default: false output_format: description: - - The key output format when retrieving the information of an - entity. + - The key output format when retrieving the information of an entity. + type: str + choices: ['json', 'plain', 'xml', 'yaml'] required: false default: json ''' EXAMPLES = ''' -keys_to_create: - - { name: client.key, key: "AQAin8tUUK84ExAA/QgBtI7gEMWdmnvKBzlXdQ==", caps: { mon: "allow rwx", mds: "allow *" } , mode: "0600" } # noqa: E501 - - { name: client.cle, caps: { mon: "allow r", osd: "allow *" } , mode: "0600" } # noqa: E501 - -caps: - mon: "allow rwx" - mds: "allow *" - - name: create ceph admin key ceph_key: name: client.admin @@ -164,17 +139,17 @@ - name: create cephx key ceph_key: - name: "{{ keys_to_create }}" + name: client.key user: client.bootstrap-rgw user_key: /var/lib/ceph/bootstrap-rgw/ceph.keyring state: present - caps: "{{ caps }}" + caps: 'mon: "allow rwx"' - name: create cephx key but don't import it in Ceph ceph_key: - name: "{{ keys_to_create }}" + name: client.key state: present - caps: "{{ caps }}" + caps: 'mon: "allow r"' import_key: False - name: delete cephx key @@ -184,7 +159,7 @@ - name: info cephx key ceph_key: - name: "my_key"" + name: "my_key" state: info - name: info cephx admin key (plain) @@ -205,6 +180,19 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule # type: ignore +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, is_containerized, container_exec, fatal # type: ignore +except ImportError: + from module_utils.ceph_common import generate_cmd, is_containerized, container_exec, fatal + +import socket +import datetime +import base64 +import time +import struct +import os +import json CEPH_INITIAL_KEYS = ['client.admin', 'client.bootstrap-mds', 'client.bootstrap-mgr', # noqa: E501 'client.bootstrap-osd', 'client.bootstrap-rbd', 'client.bootstrap-rbd-mirror', 'client.bootstrap-rgw'] # noqa: E501 @@ -487,13 +475,14 @@ def run_module(): cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=False), state=dict(type='str', required=False, default='present', choices=['present', 'update', 'absent', # noqa: E501 - 'list', 'info', 'fetch_initial_keys', 'generate_secret']), # noqa: E501 + 'fetch_initial_keys', 'generate_secret']), # noqa: E501 caps=dict(type='dict', required=False, default=None), secret=dict(type='str', required=False, default=None, no_log=True), - import_key=dict(type='bool', required=False, default=True), + import_key=dict(type='bool', required=False, + default=True, no_log=False), dest=dict(type='str', required=False, default='/etc/ceph/'), user=dict(type='str', required=False, default='client.admin'), - user_key=dict(type='str', required=False, default=None), + user_key=dict(type='str', required=False, default=None, no_log=False), output_format=dict(type='str', required=False, default='json', choices=['json', 'plain', 'xml', 'yaml']) # noqa: E501 ) diff --git a/plugins/modules/ceph_mgr_module.py b/plugins/modules/ceph_mgr_module.py index 5fd5f4b..3b3a071 100644 --- a/plugins/modules/ceph_mgr_module.py +++ b/plugins/modules/ceph_mgr_module.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,18 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \ - generate_cmd, \ - is_containerized -except ImportError: - from module_utils.ca_common import exit_module, \ - generate_cmd, \ - is_containerized -import datetime - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -37,28 +28,30 @@ --- module: ceph_mgr_module short_description: Manage Ceph MGR module -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph MGR module options: name: description: - name of the ceph MGR module. + type: str required: true cluster: description: - The ceph cluster name. + type: str required: false default: ceph state: description: - - If 'enable' is used, the module enables the MGR module. - If 'absent' is used, the module disables the MGR module. + - If 'enable' is used, the module enables the MGR module. If 'absent' is used, the module disables the MGR module. + type: str required: false choices: ['enable', 'disable'] default: enable author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -69,7 +62,7 @@ - name: disable multiple mgr modules ceph_mgr_module: - name: '{{ item }}' + name: name state: disable loop: - 'dashboard' @@ -78,6 +71,18 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \ + generate_cmd, \ + is_containerized +except ImportError: + from module_utils.ceph_common import exit_module, \ + generate_cmd, \ + is_containerized + +import datetime + def main(): module = AnsibleModule( diff --git a/plugins/modules/ceph_orch_apply.py b/plugins/modules/ceph_orch_apply.py index 3394e08..c0feb37 100644 --- a/plugins/modules/ceph_orch_apply.py +++ b/plugins/modules/ceph_orch_apply.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright Red Hat # SPDX-License-Identifier: Apache-2.0 # Author: Guillaume Abrioux diff --git a/plugins/modules/ceph_orch_daemon.py b/plugins/modules/ceph_orch_daemon.py index 0112079..279a459 100644 --- a/plugins/modules/ceph_orch_daemon.py +++ b/plugins/modules/ceph_orch_daemon.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright Red Hat # SPDX-License-Identifier: Apache-2.0 # Author: Guillaume Abrioux @@ -38,9 +41,9 @@ 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. + - 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 diff --git a/plugins/modules/ceph_orch_host.py b/plugins/modules/ceph_orch_host.py index 71e2262..703e6a0 100644 --- a/plugins/modules/ceph_orch_host.py +++ b/plugins/modules/ceph_orch_host.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright Red Hat # SPDX-License-Identifier: Apache-2.0 # Author: Guillaume Abrioux @@ -60,8 +63,7 @@ required: false set_admin_label: description: - - enforce '_admin' label on the host specified - in 'name' + - enforce '_admin' label on the host specified in 'name' type: bool required: false default: false @@ -74,12 +76,9 @@ default: [] state: description: - - if set to 'present', it will ensure the name specified - in 'name' will be present. - - if set to 'absent', it will remove the host specified in - 'name'. - - if set to 'drain', it will schedule to remove all daemons - from the host specified in 'name'. + - if set to 'present', it will ensure the name specified in 'name' will be present. + - if set to 'absent', it will remove the host specified in 'name'. + - if set to 'drain', it will schedule to remove all daemons from the host specified in 'name'. choices: - present - absent diff --git a/plugins/modules/ceph_osd.py b/plugins/modules/ceph_osd.py index 65a07f9..25e8352 100644 --- a/plugins/modules/ceph_osd.py +++ b/plugins/modules/ceph_osd.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, generate_cmd, is_containerized # noqa: E501 -except ImportError: - from module_utils.ca_common import exit_module, generate_cmd, is_containerized # noqa: E501 -import datetime - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -33,26 +28,30 @@ --- module: ceph_osd short_description: Manage Ceph OSD state -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph OSD state options: ids: description: - The ceph OSD id(s). + type: list + elements: int required: true cluster: description: - The ceph cluster name. + type: str required: false default: ceph state: description: - The ceph OSD state. + type: str required: true choices: ['destroy', 'down', 'in', 'out', 'purge', 'rm'] author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -89,11 +88,18 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, generate_cmd, is_containerized # noqa: E501 +except ImportError: + from module_utils.ceph_common import exit_module, generate_cmd, is_containerized # noqa: E501 +import datetime + def main(): module = AnsibleModule( argument_spec=dict( - ids=dict(type='list', required=True), + ids=dict(type='list', elements='int', required=True), cluster=dict(type='str', required=False, default='ceph'), state=dict(type='str', required=True, choices=['destroy', 'down', 'in', 'out', 'purge', 'rm']), # noqa: E501 ), diff --git a/plugins/modules/ceph_osd_flag.py b/plugins/modules/ceph_osd_flag.py index 9b5d030..7ad4bf8 100644 --- a/plugins/modules/ceph_osd_flag.py +++ b/plugins/modules/ceph_osd_flag.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,18 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \ - generate_cmd, \ - is_containerized -except ImportError: - from module_utils.ca_common import exit_module, \ - generate_cmd, \ - is_containerized -import datetime - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -37,30 +28,31 @@ --- module: ceph_osd_flag short_description: Manage Ceph OSD flag -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph OSD flag options: name: description: - name of the ceph OSD flag. + type: str required: true - choices: ['noup', 'nodown', 'noout', 'nobackfill', 'norebalance', - 'norecover', 'noscrub', 'nodeep-scrub'] + choices: ['noup', 'nodown', 'noout', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub'] cluster: description: - The ceph cluster name. + type: str required: false default: ceph state: description: - - If 'present' is used, the module sets the OSD flag. - If 'absent' is used, the module will unset the OSD flag. + - If 'present' is used, the module sets the OSD flag. If 'absent' is used, the module will unset the OSD flag. + type: str required: false choices: ['present', 'absent'] default: present author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -79,6 +71,18 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \ + generate_cmd, \ + is_containerized +except ImportError: + from module_utils.ceph_common import exit_module, \ + generate_cmd, \ + is_containerized + +import datetime + def main(): module = AnsibleModule( diff --git a/plugins/modules/ceph_pool.py b/plugins/modules/ceph_pool.py index ec9670f..1246ce9 100644 --- a/plugins/modules/ceph_pool.py +++ b/plugins/modules/ceph_pool.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,26 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \ - pre_generate_cmd, \ - is_containerized, \ - exec_command, \ - exit_module -except ImportError: - from module_utils.ca_common import generate_cmd, \ - pre_generate_cmd, \ - is_containerized, \ - exec_command, \ - exit_module - - -import datetime -import json -import os - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -45,11 +28,11 @@ --- module: ceph_pool -author: Guillaume Abrioux +author: Guillaume Abrioux (@guits) short_description: Manage Ceph Pools -version_added: "2.8" +version_added: "1.0.0" description: - Manage Ceph pool(s) creation, deletion and updates. @@ -57,85 +40,97 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the Ceph pool + type: str required: true state: description: - If 'present' is used, the module creates a pool if it doesn't exist - or update it if it already exists. - If 'absent' is used, the module will simply delete the pool. - If 'list' is used, the module will return all details about the - existing pools. (json formatted). + - If 'present' is used, the module creates a pool if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the pool. + - If 'list' is used, the module will return all details about the existing pools. (json formatted). + type: str required: false - choices: ['present', 'absent', 'list'] + choices: ['present', 'absent'] default: present + details: + description: + - TBD + type: bool + required: false + default: false size: description: - set the replica size of the pool. + type: str required: false - default: 3 + default: "3" min_size: description: - set the min_size parameter of the pool. + - default to `osd_pool_default_min_size` (ceph) + type: str required: false - default: default to `osd_pool_default_min_size` (ceph) pg_num: description: - set the pg_num of the pool. + - default to `osd_pool_default_pg_num` (ceph) + type: str required: false - default: default to `osd_pool_default_pg_num` (ceph) pgp_num: description: - set the pgp_num of the pool. + - default to `osd_pool_default_pgp_num` (ceph) + type: str required: false - default: default to `osd_pool_default_pgp_num` (ceph) pg_autoscale_mode: description: - set the pg autoscaler on the pool. + type: str required: false default: 'on' target_size_ratio: description: - set the target_size_ratio on the pool + type: str required: false - default: None pool_type: description: - set the pool type, either 'replicated' or 'erasure' + type: str + choices: ['replicated', 'erasure', '1', '3'] required: false default: 'replicated' erasure_profile: description: - When pool_type = 'erasure', set the erasure profile of the pool + type: str required: false default: 'default' rule_name: description: - - Set the crush rule name assigned to the pool + - Set the crush rule name assigned to the pool. default 'replicated_rule' when pool_type is 'erasure' else None + type: str required: false - default: 'replicated_rule' when pool_type is 'erasure' else None expected_num_objects: description: - - Set the expected_num_objects parameter of the pool. + - Set the expected_num_objects parameter of the pool. + type: str required: false default: '0' application: description: - Set the pool application on the pool. + type: str required: false - default: None ''' EXAMPLES = ''' -pools: - - { name: foo, size: 3, application: rbd, pool_type: 'replicated', - pg_autoscale_mode: 'on' } - - hosts: all become: true tasks: @@ -152,6 +147,25 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \ + pre_generate_cmd, \ + is_containerized, \ + exec_command, \ + exit_module +except ImportError: + from module_utils.ceph_common import generate_cmd, \ + pre_generate_cmd, \ + is_containerized, \ + exec_command, \ + exit_module + + +import datetime +import json +import os + def check_pool_exist(cluster, name, @@ -515,9 +529,9 @@ def run_module(): cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=True), state=dict(type='str', required=False, default='present', - choices=['present', 'absent', 'list']), + choices=['present', 'absent']), details=dict(type='bool', required=False, default=False), - size=dict(type='str', required=False), + size=dict(type='str', required=False, default='3'), min_size=dict(type='str', required=False), pg_num=dict(type='str', required=False), pgp_num=dict(type='str', required=False), @@ -643,7 +657,7 @@ def run_module(): user_pool_config=user_pool_config, # noqa: E501 container_image=container_image)) # noqa: E501 if user_pool_config['application']['value']: - rc, _, _, _ = exec_command(module, + rc, cmd, out, err = exec_command(module, enable_application_pool(cluster, name, user_pool_config['application']['value'], # noqa: E501 diff --git a/plugins/modules/ceph_volume.py b/plugins/modules/ceph_volume.py index afa1bfc..f287223 100644 --- a/plugins/modules/ceph_volume.py +++ b/plugins/modules/ceph_volume.py @@ -1,19 +1,22 @@ #!/usr/bin/python - -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exec_command, \ - is_containerized, \ - fatal -except ImportError: - from module_utils.ca_common import exec_command, \ - is_containerized, \ - fatal -import datetime -import copy -import json -import os -import re +# -*- coding: utf-8 -*- + +# Copyright 2020, Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = { 'metadata_version': '1.0', @@ -26,7 +29,7 @@ module: ceph_volume short_description: Create ceph OSDs with ceph-volume - +version_added: "1.0.0" description: - Using the ceph-volume utility available in Ceph this module can be used to create ceph OSDs that are backed by logical volumes. @@ -36,69 +39,87 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph objectstore: description: - The objectstore of the OSD. + type: str required: false choices: ['bluestore'] default: bluestore action: description: - The action to take. Creating OSDs and zapping or querying devices. - required: true + type: str + required: false choices: ['create', 'zap', 'batch', 'prepare', 'activate', 'list', 'inventory'] default: create data: description: - The logical volume name or device to use for the OSD data. - required: true + type: str + required: false data_vg: description: - If data is a lv, this must be the name of the volume group it belongs to. + type: str required: false osd_fsid: description: - The OSD FSID + type: str required: false osd_id: description: - The OSD ID + type: str required: false db: description: - A partition or logical volume name to use for block.db. + type: str required: false db_vg: description: - If db is a lv, this must be the name of the volume group it belongs to. # noqa: E501 + type: str required: false wal: description: - A partition or logical volume name to use for block.wal. + type: str required: false wal_vg: description: - If wal is a lv, this must be the name of the volume group it belongs to. # noqa: E501 + type: str required: false crush_device_class: description: - Will set the crush device class for the OSD. + type: str required: false dmcrypt: description: - If set to True the OSD will be encrypted with dmcrypt. + type: bool required: false + default: false batch_devices: description: - A list of devices to pass to the 'ceph-volume lvm batch' subcommand. - Only applicable if action is 'batch'. + type: list + elements: str required: false + default: [] osds_per_device: description: - The number of OSDs to create per device. - Only applicable if action is 'batch'. + type: int required: false default: 1 block_db_size: @@ -106,37 +127,44 @@ - The size in bytes of bluestore block db lvs. - The default of -1 means to create them as big as possible. - Only applicable if action is 'batch'. + type: str required: false - default: -1 + default: "-1" block_db_devices: description: - A list of devices for bluestore block db to pass to the 'ceph-volume lvm batch' subcommand. - Only applicable if action is 'batch'. + type: list + elements: str required: false + default: [] wal_devices: description: - A list of devices for bluestore block wal to pass to the 'ceph-volume lvm batch' subcommand. - Only applicable if action is 'batch'. + type: list + elements: str required: false + default: [] report: description: - If provided the --report flag will be passed to 'ceph-volume lvm batch'. - No OSDs will be created. - Results will be returned in json format. - Only applicable if action is 'batch'. + type: bool required: false - list: + default: false + destroy: description: - - List potential Ceph LVM metadata on a device - required: false - inventory: - description: - - List storage device inventory. + - TBD + type: bool required: false + default: true author: - Andrew Schoen (@andrewschoen) - - Sebastien Han + - Sebastien Han (@leseb) ''' EXAMPLES = ''' @@ -157,6 +185,22 @@ action: create ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exec_command, \ + is_containerized, \ + fatal +except ImportError: + from module_utils.ceph_common import exec_command, \ + is_containerized, \ + fatal + +import datetime +import copy +import json +import os +import re + def container_exec(binary, container_image, mounts=None): ''' @@ -509,11 +553,11 @@ def run_module(): wal_vg=dict(type='str', required=False), crush_device_class=dict(type='str', required=False), dmcrypt=dict(type='bool', required=False, default=False), - batch_devices=dict(type='list', required=False, default=[]), + batch_devices=dict(type='list', elements='str', required=False, default=[]), osds_per_device=dict(type='int', required=False, default=1), block_db_size=dict(type='str', required=False, default='-1'), - block_db_devices=dict(type='list', required=False, default=[]), - wal_devices=dict(type='list', required=False, default=[]), + block_db_devices=dict(type='list', elements='str', required=False, default=[]), + wal_devices=dict(type='list', elements='str', required=False, default=[]), report=dict(type='bool', required=False, default=False), osd_fsid=dict(type='str', required=False), osd_id=dict(type='str', required=False), diff --git a/plugins/modules/ceph_volume_simple_activate.py b/plugins/modules/ceph_volume_simple_activate.py index f3e131b..a202162 100644 --- a/plugins/modules/ceph_volume_simple_activate.py +++ b/plugins/modules/ceph_volume_simple_activate.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module -except ImportError: - from module_utils.ca_common import exit_module -import datetime -import os - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -34,7 +28,7 @@ --- module: ceph_volume_simple_activate short_description: Activate legacy OSD with ceph-volume -version_added: "2.8" +version_added: "1.0.0" description: - Activate legacy OSD with ceph-volume by providing the JSON file from the scan operation or by passing the OSD ID and OSD FSID. @@ -42,32 +36,37 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph path: description: - - The OSD metadata as JSON file in /etc/ceph/osd directory, it - must exist. + - The OSD metadata as JSON file in /etc/ceph/osd directory, it must exist. + type: path required: false osd_id: description: - The legacy OSD ID. + type: str required: false osd_fsid: description: - The legacy OSD FSID. + type: str required: false osd_all: description: - Activate all legacy OSDs. + type: bool required: false systemd: description: - Using systemd unit during the OSD activation. + type: bool required: false default: true author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -96,6 +95,14 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module +except ImportError: + from module_utils.ceph_common import exit_module +import datetime +import os + def main(): module = AnsibleModule( diff --git a/plugins/modules/ceph_volume_simple_scan.py b/plugins/modules/ceph_volume_simple_scan.py index 06ed70e..d4f8229 100644 --- a/plugins/modules/ceph_volume_simple_scan.py +++ b/plugins/modules/ceph_volume_simple_scan.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module -except ImportError: - from module_utils.ca_common import exit_module -import datetime -import os - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -34,33 +28,35 @@ --- module: ceph_volume_simple_scan short_description: Scan legacy OSD with ceph-volume -version_added: "2.8" +version_added: "1.0.0" description: - - Scan legacy OSD with ceph-volume and store the output as JSON file - in /etc/ceph/osd directory with {OSD_ID}-{OSD_FSID}.json format. + - Scan legacy OSD with ceph-volume and store the output as JSON file in /etc/ceph/osd directory with {OSD_ID}-{OSD_FSID}.json format. options: cluster: description: - The ceph cluster name. + type: str required: false default: ceph path: description: - - The OSD directory or metadata partition. The directory or - partition must exist. + - The OSD directory or metadata partition. The directory or partition must exist. + type: path required: false force: description: - Force re-scanning an OSD and overwriting the JSON content. + type: bool required: false default: false stdout: description: - Do not store the output to JSON file but stdout instead. + type: bool required: false default: false author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -88,6 +84,14 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module +except ImportError: + from module_utils.ceph_common import exit_module +import datetime +import os + def main(): module = AnsibleModule( diff --git a/plugins/modules/cephadm_adopt.py b/plugins/modules/cephadm_adopt.py index 2f87f34..5b38307 100644 --- a/plugins/modules/cephadm_adopt.py +++ b/plugins/modules/cephadm_adopt.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module -except ImportError: - from module_utils.ca_common import exit_module -import datetime -import json - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -34,44 +28,51 @@ --- module: cephadm_adopt short_description: Adopt a Ceph cluster with cephadm -version_added: "2.8" +version_added: "1.0.0" description: - Adopt a Ceph cluster with cephadm options: name: description: - The ceph daemon name. + type: str required: true cluster: description: - The ceph cluster name. + type: str required: false default: ceph style: description: - Cep deployment style. + type: str required: false default: legacy image: description: - Ceph container image. + type: str required: false docker: description: - Use docker instead of podman. + type: bool required: false pull: description: - Pull the Ceph container image. + type: bool required: false default: true firewalld: description: - Manage firewall rules with firewalld. + type: bool required: false default: true author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -98,6 +99,14 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule # type: ignore +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module # type: ignore +except ImportError: + from module_utils.ceph_common import exit_module +import datetime +import json + def main(): module = AnsibleModule( diff --git a/plugins/modules/cephadm_registry_login.py b/plugins/modules/cephadm_registry_login.py index 9017652..c206e05 100644 --- a/plugins/modules/cephadm_registry_login.py +++ b/plugins/modules/cephadm_registry_login.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright Red Hat # SPDX-License-Identifier: Apache-2.0 # Author: Guillaume Abrioux @@ -65,9 +68,8 @@ required: false registry_json: description: - - The path to a json file. This file must be present on remote hosts - prior to running this task. - *not supported yet*. + - The path to a json file. This file must be present on remote hosts prior to running this task. + - not supported yet. type: str author: - Guillaume Abrioux (@guits) diff --git a/plugins/modules/radosgw_caps.py b/plugins/modules/radosgw_caps.py index dac20b8..3fc799f 100644 --- a/plugins/modules/radosgw_caps.py +++ b/plugins/modules/radosgw_caps.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2022, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,31 +16,8 @@ # limitations under the License. from __future__ import absolute_import, division, print_function - __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule - -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import ( - exit_module, - exec_command, - is_containerized, - container_exec, - ) -except ImportError: - from module_utils.ca_common import ( - exit_module, - exec_command, - is_containerized, - container_exec, - ) -import datetime -import json -import re -from enum import IntFlag - - ANSIBLE_METADATA = { "metadata_version": "1.1", "status": ["preview"], @@ -50,7 +30,7 @@ short_description: Manage RADOS Gateway Admin capabilities -version_added: "2.10" +version_added: "1.0.0" description: - Manage RADOS Gateway capabilities addition and deletion. @@ -83,7 +63,7 @@ elements: str author: - - Mathias Chapelain + - Mathias Chapelain (@Papawy) """ EXAMPLES = """ @@ -160,6 +140,17 @@ """ +from ansible.module_utils.basic import AnsibleModule # type: ignore +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, exec_command, is_containerized, container_exec +except ImportError: + from module_utils.ceph_common import exit_module, exec_command, is_containerized, container_exec +from enum import IntFlag +import re +import json +import datetime + + def pre_generate_radosgw_cmd(container_image=None): """ Generate radosgw-admin prefix comaand @@ -277,11 +268,13 @@ def params_to_caps_output(current_caps, params, deletion=False): cap = splitted[0] new_perm = perm_string_to_flag(splitted[1]) - current = next((item for item in out_caps if item["type"] == cap), None) + current = next( + (item for item in out_caps if item["type"] == cap), None) if not current: if not deletion: - out_caps.append(dict(type=cap, perm=perm_flag_to_string(new_perm))) + out_caps.append( + dict(type=cap, perm=perm_flag_to_string(new_perm))) continue current_perm = perm_string_to_flag(current["perm"]) diff --git a/plugins/modules/radosgw_realm.py b/plugins/modules/radosgw_realm.py index 8a93f86..f3ef0b0 100644 --- a/plugins/modules/radosgw_realm.py +++ b/plugins/modules/radosgw_realm.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,11 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -import datetime -import os - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -32,7 +30,7 @@ short_description: Manage RADOS Gateway Realm -version_added: "2.8" +version_added: "1.0.0" description: - Manage RADOS Gateway realm(s) creation, deletion and updates. @@ -40,42 +38,47 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the RADOS Gateway realm. + type: str required: true state: description: - If 'present' is used, the module creates a realm if it doesn't - exist or update it if it already exists. - If 'absent' is used, the module will simply delete the realm. - If 'info' is used, the module will return all details about the - existing realm (json formatted). + - If 'present' is used, the module creates a realm if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the realm. + - If 'info' is used, the module will return all details about the existing realm (json formatted). + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent', 'pull'] default: present default: description: - set the default flag on the realm. + type: bool required: false default: false url: description: - URL to the master RADOS Gateway zone. + type: str required: false access_key: description: - S3 access key of the master RADOS Gateway zone. + type: str required: false secret_key: description: - S3 secret key of the master RADOS Gateway zone. + type: str required: false author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -97,6 +100,10 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +import datetime +import os + def container_exec(binary, container_image): ''' @@ -270,11 +277,11 @@ def run_module(): module_args = dict( cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=True), - state=dict(type='str', required=False, choices=['present', 'absent', 'info', 'pull'], default='present'), # noqa: E501 + state=dict(type='str', required=False, choices=['present', 'absent', 'pull'], default='present'), # noqa: E501 default=dict(type='bool', required=False, default=False), url=dict(type='str', required=False), - access_key=dict(type='str', required=False), - secret_key=dict(type='str', required=False), + access_key=dict(type='str', required=False, no_log=False), + secret_key=dict(type='str', required=False, no_log=False), ) module = AnsibleModule( diff --git a/plugins/modules/radosgw_user.py b/plugins/modules/radosgw_user.py index 78addd0..15614f3 100644 --- a/plugins/modules/radosgw_user.py +++ b/plugins/modules/radosgw_user.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -import datetime -import json -import os - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -33,7 +30,7 @@ short_description: Manage RADOS Gateway User -version_added: "2.8" +version_added: "1.0.0" description: - Manage RADOS Gateway user(s) creation, deletion and updates. @@ -41,70 +38,73 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the RADOS Gateway user (uid). + type: str required: true state: description: - If 'present' is used, the module creates a user if it doesn't - exist or update it if it already exists. - If 'absent' is used, the module will simply delete the user. - If 'info' is used, the module will return all details about the - existing user (json formatted). + - If 'present' is used, the module creates a user if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the user. + - If 'info' is used, the module will return all details about the existing user (json formatted). + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent'] default: present display_name: description: - set the display name of the user. + type: str required: false - default: None email: description: - set the email of the user. + type: str required: false - default: None access_key: description: - set the S3 access key of the user. + type: str required: false - default: None secret_key: description: - set the S3 secret key of the user. + type: str required: false - default: None realm: description: - set the realm of the user. + type: str required: false - default: None zonegroup: description: - set the zonegroup of the user. + type: str required: false - default: None zone: description: - set the zone of the user. + type: str required: false - default: None system: description: - set the system flag on the user. + type: bool required: false default: false admin: description: - set the admin flag on the user. + type: bool required: false default: false author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -134,6 +134,11 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +import datetime +import json +import os + def container_exec(binary, container_image): ''' @@ -389,7 +394,7 @@ def run_module(): module_args = dict( cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=True), - state=dict(type='str', required=False, choices=['present', 'absent', 'info'], default='present'), # noqa: E501 + state=dict(type='str', required=False, choices=['present', 'absent'], default='present'), # noqa: E501 display_name=dict(type='str', required=False), email=dict(type='str', required=False), access_key=dict(type='str', required=False, no_log=True), diff --git a/plugins/modules/radosgw_zone.py b/plugins/modules/radosgw_zone.py index bc38769..e25844f 100644 --- a/plugins/modules/radosgw_zone.py +++ b/plugins/modules/radosgw_zone.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,16 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal -except ImportError: - from module_utils.ca_common import fatal -import datetime -import json -import os - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -37,7 +30,7 @@ short_description: Manage RADOS Gateway Zone -version_added: "2.8" +version_added: "1.0.0" description: - Manage RADOS Gateway zone(s) creation, deletion and updates. @@ -45,58 +38,71 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the RADOS Gateway zone. + type: str required: true state: description: - If 'present' is used, the module creates a zone if it doesn't - exist or update it if it already exists. - If 'absent' is used, the module will simply delete the zone. - If 'info' is used, the module will return all details about the - existing zone (json formatted). + - If 'present' is used, the module creates a zone if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the zone. + - If 'info' is used, the module will return all details about the existing zone (json formatted). + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent', 'set'] default: present realm: description: - name of the RADOS Gateway realm. + type: str required: true zonegroup: description: - name of the RADOS Gateway zonegroup. + type: str required: true endpoints: description: - endpoints of the RADOS Gateway zone. + type: list + elements: str required: false default: [] access_key: description: - set the S3 access key of the user. + type: str required: false - default: None secret_key: description: - set the S3 secret key of the user. + type: str required: false - default: None default: description: - set the default flag on the zone. + type: bool required: false default: false master: description: - set the master flag on the zone. + type: bool required: false default: false + zone_doc: + description: + - TBD + type: dict + required: false + default: {} author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -123,8 +129,17 @@ RETURN = '''# ''' +from ansible.module_utils.basic import AnsibleModule +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal +except ImportError: + from module_utils.ceph_common import fatal +import datetime +import json +import os + -def container_exec(binary, container_image, container_args=[]): +def container_exec(binary, container_image, container_args=None): ''' Build the docker CLI to run a command inside a container ''' @@ -157,7 +172,7 @@ def is_containerized(): return container_image -def pre_generate_radosgw_cmd(container_image=None, container_args=[]): +def pre_generate_radosgw_cmd(container_image=None, container_args=None): ''' Generate radosgw-admin prefix comaand ''' @@ -169,7 +184,7 @@ def pre_generate_radosgw_cmd(container_image=None, container_args=[]): return cmd -def generate_radosgw_cmd(cluster, args, container_image=None, container_args=[]): +def generate_radosgw_cmd(cluster, args, container_image=None, container_args=None): ''' Generate 'radosgw' command line to execute ''' @@ -438,10 +453,10 @@ def run_module(): module_args = dict( cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=True), - state=dict(type='str', required=False, choices=['present', 'absent', 'info', 'set'], default='present'), # noqa: E501 - realm=dict(type='str', require=True), - zonegroup=dict(type='str', require=True), - endpoints=dict(type='list', require=False, default=[]), + state=dict(type='str', required=False, choices=['present', 'absent', 'set'], default='present'), # noqa: E501 + realm=dict(type='str', required=True), + zonegroup=dict(type='str', required=True), + endpoints=dict(type='list', elements='str', required=False, default=[]), access_key=dict(type='str', required=False, no_log=True), secret_key=dict(type='str', required=False, no_log=True), default=dict(type='bool', required=False, default=False), diff --git a/plugins/modules/radosgw_zonegroup.py b/plugins/modules/radosgw_zonegroup.py index dc99195..e49b793 100644 --- a/plugins/modules/radosgw_zonegroup.py +++ b/plugins/modules/radosgw_zonegroup.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright 2020, Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,16 +18,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule -try: - from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal -except ImportError: - from module_utils.ca_common import fatal -import datetime -import json -import os - - ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], @@ -37,7 +30,7 @@ short_description: Manage RADOS Gateway Zonegroup -version_added: "2.8" +version_added: "1.0.0" description: - Manage RADOS Gateway zonegroup(s) creation, deletion and updates. @@ -45,44 +38,50 @@ cluster: description: - The ceph cluster name. + type: str required: false default: ceph name: description: - name of the RADOS Gateway zonegroup. + type: str required: true state: description: - If 'present' is used, the module creates a zonegroup if it doesn't - exist or update it if it already exists. - If 'absent' is used, the module will simply delete the zonegroup. - If 'info' is used, the module will return all details about the - existing zonegroup (json formatted). + - If 'present' is used, the module creates a zonegroup if it doesn't exist or update it if it already exists. + - If 'absent' is used, the module will simply delete the zonegroup. + - If 'info' is used, the module will return all details about the existing zonegroup (json formatted). + type: str required: false - choices: ['present', 'absent', 'info'] + choices: ['present', 'absent'] default: present realm: description: - name of the RADOS Gateway realm. + type: str required: true endpoints: description: - endpoints of the RADOS Gateway zonegroup. + type: list + elements: str required: false default: [] default: description: - set the default flag on the zonegroup. + type: bool required: false default: false master: description: - set the master flag on the zonegroup. + type: bool required: false default: false author: - - Dimitri Savineau + - Dimitri Savineau (@dsavineau) ''' EXAMPLES = ''' @@ -110,6 +109,16 @@ RETURN = '''# ''' +import os +import json +import datetime +from ansible.module_utils.basic import AnsibleModule + +try: + from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal +except ImportError: + from module_utils.ceph_common import fatal + def container_exec(binary, container_image): ''' @@ -327,9 +336,9 @@ def run_module(): module_args = dict( cluster=dict(type='str', required=False, default='ceph'), name=dict(type='str', required=True), - state=dict(type='str', required=False, choices=['present', 'absent', 'info'], default='present'), # noqa: E501 - realm=dict(type='str', require=True), - endpoints=dict(type='list', require=False, default=[]), + state=dict(type='str', required=False, choices=['present', 'absent'], default='present'), # noqa: E501 + realm=dict(type='str', required=True), + endpoints=dict(type='list', elements='str', required=False, default=[]), default=dict(type='bool', required=False, default=False), master=dict(type='bool', required=False, default=False), ) diff --git a/requirements.txt b/requirements.txt index 7c211b0..3795b8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ # TO-DO: add python packages that are required for this collection -tox \ No newline at end of file +tox +boto +boto3 \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index 31c4664..19b4241 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,3 +3,5 @@ pytest-ansible pytest-xdist molecule mock +boto +boto3 \ No newline at end of file diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index e957a64..e5e9065 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -1,6 +1,27 @@ +plugins/modules/ceph_add_users_buckets.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_adopt.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_authtool.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_config.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush_rule.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_dashboard_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_ec_profile.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_fs.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_key.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_mgr_module.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_apply.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_daemon.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_host.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file +plugins/modules/ceph_osd_flag.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_osd.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_pool.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_activate.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_scan.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_caps.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_realm.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zonegroup.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zone.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt index e957a64..e5e9065 100644 --- a/tests/sanity/ignore-2.16.txt +++ b/tests/sanity/ignore-2.16.txt @@ -1,6 +1,27 @@ +plugins/modules/ceph_add_users_buckets.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_adopt.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_authtool.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_config.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush_rule.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_dashboard_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_ec_profile.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_fs.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_key.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_mgr_module.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_apply.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_daemon.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_host.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file +plugins/modules/ceph_osd_flag.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_osd.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_pool.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_activate.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_scan.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_caps.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_realm.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zonegroup.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zone.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file diff --git a/tests/sanity/ignore-2.17.txt b/tests/sanity/ignore-2.17.txt index e957a64..e5e9065 100644 --- a/tests/sanity/ignore-2.17.txt +++ b/tests/sanity/ignore-2.17.txt @@ -1,6 +1,27 @@ +plugins/modules/ceph_add_users_buckets.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_adopt.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_authtool.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_config.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush_rule.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_dashboard_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_ec_profile.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_fs.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_key.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_mgr_module.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_apply.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_daemon.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_host.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file +plugins/modules/ceph_osd_flag.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_osd.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_pool.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_activate.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_scan.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_caps.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_realm.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zonegroup.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zone.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file diff --git a/tests/sanity/ignore-devel.txt b/tests/sanity/ignore-devel.txt index e957a64..e5e9065 100644 --- a/tests/sanity/ignore-devel.txt +++ b/tests/sanity/ignore-devel.txt @@ -1,6 +1,27 @@ +plugins/modules/ceph_add_users_buckets.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_adopt.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_authtool.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_config.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush_rule.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_dashboard_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_ec_profile.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_fs.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_key.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_mgr_module.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_apply.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_daemon.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_host.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file +plugins/modules/ceph_osd_flag.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_osd.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_pool.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_activate.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_scan.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_caps.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_realm.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zonegroup.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zone.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file diff --git a/tests/sanity/ignore-milestone.txt b/tests/sanity/ignore-milestone.txt index e957a64..e5e9065 100644 --- a/tests/sanity/ignore-milestone.txt +++ b/tests/sanity/ignore-milestone.txt @@ -1,6 +1,27 @@ +plugins/modules/ceph_add_users_buckets.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_adopt.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_authtool.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_config.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_crush_rule.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_dashboard_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_ec_profile.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_fs.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_key.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_mgr_module.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_apply.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_daemon.py validate-modules:missing-gplv3-license # ignore license check plugins/modules/ceph_orch_host.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_bootstrap.py validate-modules:missing-gplv3-license # ignore license check -plugins/modules/cephadm_registry_login.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file +plugins/modules/ceph_osd_flag.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_osd.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_pool.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_activate.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/ceph_volume_simple_scan.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_caps.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_realm.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_user.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zonegroup.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/radosgw_zone.py validate-modules:missing-gplv3-license # ignore license check \ No newline at end of file diff --git a/tests/unit/module_utils/test_ca_common.py b/tests/unit/module_utils/test_ca_common.py index e562bae..99224c2 100644 --- a/tests/unit/module_utils/test_ca_common.py +++ b/tests/unit/module_utils/test_ca_common.py @@ -1,6 +1,6 @@ from mock.mock import patch, MagicMock import os -import ca_common +import ceph_common import pytest fake_container_binary = 'podman' @@ -26,15 +26,15 @@ def setup_method(self): @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) def test_container_exec(self): - cmd = ca_common.container_exec(self.fake_binary, fake_container_image) + cmd = ceph_common.container_exec(self.fake_binary, fake_container_image) assert cmd == self.fake_container_cmd def test_not_is_containerized(self): - assert ca_common.is_containerized() is None + assert ceph_common.is_containerized() is None @patch.dict(os.environ, {'CEPH_CONTAINER_IMAGE': fake_container_image}) def test_is_containerized(self): - assert ca_common.is_containerized() == fake_container_image + assert ceph_common.is_containerized() == fake_container_image @pytest.mark.parametrize('image', [None, fake_container_image]) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @@ -44,7 +44,7 @@ def test_pre_generate_cmd(self, image): else: expected_cmd = [self.fake_binary] - assert ca_common.pre_generate_cmd(self.fake_binary, image) == expected_cmd # noqa: E501 + assert ceph_common.pre_generate_cmd(self.fake_binary, image) == expected_cmd # noqa: E501 @pytest.mark.parametrize('image', [None, fake_container_image]) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @@ -64,7 +64,7 @@ def test_generate_cmd(self, image): 'osd', 'pool', 'create', 'foo' ]) - assert ca_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster=self.fake_cluster, container_image=image) == expected_cmd # noqa: E501 + assert ceph_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster=self.fake_cluster, container_image=image) == expected_cmd # noqa: E501 @pytest.mark.parametrize('image', [None, fake_container_image]) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @@ -84,7 +84,7 @@ def test_generate_cmd_different_cluster_name(self, image): 'osd', 'pool', 'create', 'foo' ]) - result = ca_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster='foo', container_image=image) # noqa: E501 + result = ceph_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster='foo', container_image=image) # noqa: E501 assert result == expected_cmd @pytest.mark.parametrize('image', [None, fake_container_image]) @@ -105,7 +105,7 @@ def test_generate_cmd_different_cluster_name_and_user(self, image): 'osd', 'pool', 'create', 'foo' ]) - result = ca_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster='foo', user='client.foo', container_image=image) # noqa: E501 + result = ceph_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster='foo', user='client.foo', container_image=image) # noqa: E501 assert result == expected_cmd @pytest.mark.parametrize('image', [None, fake_container_image]) @@ -126,7 +126,7 @@ def test_generate_cmd_different_user(self, image): 'osd', 'pool', 'create', 'foo' ]) - result = ca_common.generate_cmd(sub_cmd=sub_cmd, args=args, user='client.foo', container_image=image) # noqa: E501 + result = ceph_common.generate_cmd(sub_cmd=sub_cmd, args=args, user='client.foo', container_image=image) # noqa: E501 assert result == expected_cmd @pytest.mark.parametrize('stdin', [None, 'foo']) @@ -137,7 +137,7 @@ def test_exec_command(self, stdin): stdout = 'ceph version 1.2.3' fake_module.run_command.return_value = 0, stdout, stderr expected_cmd = [self.fake_binary, '--version'] - _rc, _cmd, _out, _err = ca_common.exec_command(fake_module, expected_cmd, stdin=stdin) # noqa: E501 + _rc, _cmd, _out, _err = ceph_common.exec_command(fake_module, expected_cmd, stdin=stdin) # noqa: E501 assert _rc == rc assert _cmd == expected_cmd assert _err == stderr diff --git a/tests/unit/modules/test_ceph_ec_profile.py b/tests/unit/modules/test_ceph_ec_profile.py index 955148f..64dc93a 100644 --- a/tests/unit/modules/test_ceph_ec_profile.py +++ b/tests/unit/modules/test_ceph_ec_profile.py @@ -26,15 +26,22 @@ def test_get_profile(self): '--format=json' ] - assert ceph_ec_profile.get_profile(self.fake_module, self.fake_name) == expected_cmd + assert ceph_ec_profile.get_profile( + self.fake_module, self.fake_name) == expected_cmd @pytest.mark.parametrize("stripe_unit,crush_device_class,force", [(False, None, False), - (32, None, True), - (False, None, True), - (32, None, False), - (False, 'hdd', False), - (32, 'ssd', True), - (False, 'nvme', True), + (32, None, + True), + (False, + None, True), + (32, None, + False), + (False, 'hdd', + False), + (32, 'ssd', + True), + (False, + 'nvme', True), (32, 'hdd', False)]) def test_create_profile(self, stripe_unit, crush_device_class, force): expected_cmd = [ @@ -49,7 +56,8 @@ def test_create_profile(self, stripe_unit, crush_device_class, force): if stripe_unit: expected_cmd.append('stripe_unit={}'.format(stripe_unit)) if crush_device_class: - expected_cmd.append('crush-device-class={}'.format(crush_device_class)) + expected_cmd.append( + 'crush-device-class={}'.format(crush_device_class)) if force: expected_cmd.append('--force') @@ -70,7 +78,7 @@ def test_delete_profile(self): '--cluster', self.fake_cluster, 'osd', 'erasure-code-profile', 'rm', self.fake_name - ] + ] assert ceph_ec_profile.delete_profile(self.fake_module, self.fake_name, @@ -89,7 +97,8 @@ def test_state_present_nothing_to_update(self, m_exec_command, m_exit_json, m_fa m_exit_json.side_effect = ca_test_common.exit_json m_fail_json.side_effect = ca_test_common.fail_json m_exec_command.return_value = (0, - ['ceph', 'osd', 'erasure-code-profile', 'get', 'foo', '--format', 'json'], + ['ceph', 'osd', 'erasure-code-profile', + 'get', 'foo', '--format', 'json'], '{"crush-device-class":"","crush-failure-domain":"host","crush-root":"default","jerasure-per-chunk-alignment":"false","k":"2","m":"4","plugin":"jerasure","stripe_unit":"32","technique":"reed_sol_van","w":"8"}', # noqa: E501 '') @@ -98,7 +107,8 @@ def test_state_present_nothing_to_update(self, m_exec_command, m_exit_json, m_fa result = r.value.args[0] assert not result['changed'] - assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', 'get', 'foo', '--format', 'json'] + assert result['cmd'] == ['ceph', 'osd', + 'erasure-code-profile', 'get', 'foo', '--format', 'json'] assert result['stdout'] == '{"crush-device-class":"","crush-failure-domain":"host","crush-root":"default","jerasure-per-chunk-alignment":"false","k":"2","m":"4","plugin":"jerasure","stripe_unit":"32","technique":"reed_sol_van","w":"8"}' # noqa: E501 assert not result['stderr'] assert result['rc'] == 0 @@ -117,11 +127,13 @@ def test_state_present_profile_to_update(self, m_exec_command, m_exit_json, m_fa m_fail_json.side_effect = ca_test_common.fail_json m_exec_command.side_effect = [ (0, - ['ceph', 'osd', 'erasure-code-profile', 'get', 'foo', '--format', 'json'], + ['ceph', 'osd', 'erasure-code-profile', + 'get', 'foo', '--format', 'json'], '{"crush-device-class":"","crush-failure-domain":"host","crush-root":"default","jerasure-per-chunk-alignment":"false","k":"2","m":"4","plugin":"jerasure","stripe_unit":"32","technique":"reed_sol_van","w":"8"}', # noqa: E501 ''), (0, - ['ceph', 'osd', 'erasure-code-profile', 'set', 'foo', 'k=2', 'm=6', 'stripe_unit=32', '--force'], + ['ceph', 'osd', 'erasure-code-profile', 'set', + 'foo', 'k=2', 'm=6', 'stripe_unit=32', '--force'], '', '' ) @@ -132,7 +144,8 @@ def test_state_present_profile_to_update(self, m_exec_command, m_exit_json, m_fa result = r.value.args[0] assert result['changed'] - assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', 'set', 'foo', 'k=2', 'm=6', 'stripe_unit=32', '--force'] + assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', + 'set', 'foo', 'k=2', 'm=6', 'stripe_unit=32', '--force'] assert not result['stdout'] assert not result['stderr'] assert result['rc'] == 0 @@ -150,23 +163,27 @@ def test_state_present_profile_doesnt_exist(self, m_exec_command, m_exit_json, m m_exit_json.side_effect = ca_test_common.exit_json m_fail_json.side_effect = ca_test_common.fail_json m_exec_command.side_effect = [ - (2, - ['ceph', 'osd', 'erasure-code-profile', 'get', 'foo', '--format', 'json'], - '', - "Error ENOENT: unknown erasure code profile 'foo'"), - (0, - ['ceph', 'osd', 'erasure-code-profile', 'set', 'foo', 'k=2', 'm=4', 'stripe_unit=32', '--force'], - '', - '' - ) - ] + (2, + ['ceph', 'osd', 'erasure-code-profile', + 'get', 'foo', '--format', 'json'], + '', + "Error ENOENT: unknown erasure code profile 'foo'"), + (0, + ['ceph', 'osd', 'erasure-code-profile', 'set', + 'foo', 'k=2', 'm=4', 'stripe_unit=32', '--force'], + '', + '' + ) + + ] with pytest.raises(ca_test_common.AnsibleExitJson) as r: ceph_ec_profile.run_module() result = r.value.args[0] assert result['changed'] - assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', 'set', 'foo', 'k=2', 'm=4', 'stripe_unit=32', '--force'] + assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', + 'set', 'foo', 'k=2', 'm=4', 'stripe_unit=32', '--force'] assert not result['stdout'] assert not result['stderr'] assert result['rc'] == 0 @@ -181,7 +198,8 @@ def test_state_absent_on_existing_profile(self, m_exec_command, m_exit_json, m_f m_exit_json.side_effect = ca_test_common.exit_json m_fail_json.side_effect = ca_test_common.fail_json m_exec_command.return_value = (0, - ['ceph', 'osd', 'erasure-code-profile', 'rm', 'foo'], + ['ceph', 'osd', 'erasure-code-profile', + 'rm', 'foo'], '', '') @@ -190,7 +208,8 @@ def test_state_absent_on_existing_profile(self, m_exec_command, m_exit_json, m_f result = r.value.args[0] assert result['changed'] - assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', 'rm', 'foo'] + assert result['cmd'] == ['ceph', 'osd', + 'erasure-code-profile', 'rm', 'foo'] assert result['stdout'] == 'Profile foo removed.' assert not result['stderr'] assert result['rc'] == 0 @@ -205,7 +224,8 @@ def test_state_absent_on_nonexisting_profile(self, m_exec_command, m_exit_json, m_exit_json.side_effect = ca_test_common.exit_json m_fail_json.side_effect = ca_test_common.fail_json m_exec_command.return_value = (0, - ['ceph', 'osd', 'erasure-code-profile', 'rm', 'foo'], + ['ceph', 'osd', 'erasure-code-profile', + 'rm', 'foo'], '', 'erasure-code-profile foo does not exist') @@ -214,7 +234,8 @@ def test_state_absent_on_nonexisting_profile(self, m_exec_command, m_exit_json, result = r.value.args[0] assert not result['changed'] - assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', 'rm', 'foo'] + assert result['cmd'] == ['ceph', 'osd', + 'erasure-code-profile', 'rm', 'foo'] assert result['stdout'] == "Skipping, the profile foo doesn't exist" assert result['stderr'] == 'erasure-code-profile foo does not exist' assert result['rc'] == 0 diff --git a/tests/unit/modules/test_ceph_key.py b/tests/unit/modules/test_ceph_key.py index 4b19754..8e28263 100644 --- a/tests/unit/modules/test_ceph_key.py +++ b/tests/unit/modules/test_ceph_key.py @@ -330,10 +330,11 @@ def test_delete_key_non_container(self): fake_cluster = "fake" fake_name = "client.fake" expected_command_list = [ - ['ceph', '-n', 'client.admin', '-k', '/etc/ceph/fake.client.admin.keyring', + ['ceph', '-n', 'client.admin', '-k', '/etc/ceph/fake.client.admin.keyring', '--cluster', fake_cluster, 'auth', 'del', fake_name], ] - result = ceph_key.delete_key(fake_cluster, fake_user, fake_user_key, fake_name) + result = ceph_key.delete_key( + fake_cluster, fake_user, fake_user_key, fake_name) assert result == expected_command_list def test_delete_key_container(self): @@ -458,7 +459,8 @@ def test_list_key_non_container_with_mon_key(self): fake_cluster = "fake" fake_user = "mon." fake_keyring_dirname = fake_cluster + "-" + fake_hostname - fake_key = os.path.join("/var/lib/ceph/mon/", fake_keyring_dirname, 'keyring') + fake_key = os.path.join("/var/lib/ceph/mon/", + fake_keyring_dirname, 'keyring') expected_command_list = [ ['ceph', '-n', "mon.", '-k', "/var/lib/ceph/mon/fake-mon01/keyring", '--cluster', fake_cluster, 'auth', 'ls', '-f', 'json'], @@ -471,7 +473,8 @@ def test_list_key_container_with_mon_key(self): fake_cluster = "fake" fake_user = "mon." fake_keyring_dirname = fake_cluster + "-" + fake_hostname - fake_key = os.path.join("/var/lib/ceph/mon/", fake_keyring_dirname, 'keyring') + fake_key = os.path.join("/var/lib/ceph/mon/", + fake_keyring_dirname, 'keyring') fake_container_image = "quay.io/ceph/daemon:latest-luminous" expected_command_list = [['docker', 'run', @@ -487,7 +490,8 @@ def test_list_key_container_with_mon_key(self): '--cluster', fake_cluster, 'auth', 'ls', '-f', 'json'], ] - result = ceph_key.list_keys(fake_cluster, fake_user, fake_key, fake_container_image) + result = ceph_key.list_keys( + fake_cluster, fake_user, fake_key, fake_container_image) assert result == expected_command_list def test_list_key_container(self): @@ -515,11 +519,12 @@ def test_list_key_container(self): def test_lookup_ceph_initial_entities(self): fake_module = "fake" - fake_ceph_dict = { "auth_dump":[ { "entity":"osd.0", "key":"AQAJkMhbszeBBBAA4/V1tDFXGlft1GnHJS5wWg==", "caps":{ "mgr":"allow profile osd", "mon":"allow profile osd", "osd":"allow *" } }, { "entity":"osd.1", "key":"AQAjkMhbshueAhAAjZec50aBgd1NObLz57SQvg==", "caps":{ "mgr":"allow profile osd", "mon":"allow profile osd", "osd":"allow *" } }, { "entity":"client.admin", "key":"AQDZjshbrJv6EhAAY9v6LzLYNDpPdlC3HD5KHA==", "auid":0, "caps":{ "mds":"allow", "mgr":"allow *", "mon":"allow *", "osd":"allow *" } }, { "entity":"client.bootstrap-mds", "key":"AQDojshbc4QCHhAA1ZTrkt9dbSZRVU2GzI6U4A==", "caps":{ "mon":"allow profile bootstrap-mds" } }, { "entity":"client.bootstrap-mgr", "key":"AQBfiu5bAAAAABAARcNG24hUMlk4AdstVA5MVQ==", "caps":{ "mon":"allow profile bootstrap-mgr" } }, { "entity":"client.bootstrap-osd", "key":"AQDjjshbYW+uGxAAyHcPCXXmVoL8VsTBI8z1Ng==", "caps":{ "mon":"allow profile bootstrap-osd" } }, { "entity":"client.bootstrap-rbd", "key":"AQDyjshb522eIhAAtAz6nUPMOdG4H9u0NgpXhA==", "caps":{ "mon":"allow profile bootstrap-rbd" } }, { "entity":"client.bootstrap-rbd-mirror", "key":"AQDfh+5bAAAAABAAEGBD59Lj2vAKIdN8pq4lbQ==", "caps":{ "mon":"allow profile bootstrap-rbd-mirror" } }, { "entity":"client.bootstrap-rgw", "key":"AQDtjshbDl8oIBAAq1SfSYQKDR49hJNWJVwDQw==", "caps":{ "mon":"allow profile bootstrap-rgw" } }, { "entity":"mgr.mon0", "key":"AQA0j8hbgGapORAAoDkyAvXVkM5ej4wNn4cwTQ==", "caps":{ "mds":"allow *", "mon":"allow profile mgr", "osd":"allow *" } } ] } # noqa E501 + fake_ceph_dict = {"auth_dump": [{"entity": "osd.0", "key": "AQAJkMhbszeBBBAA4/V1tDFXGlft1GnHJS5wWg==", "caps": {"mgr": "allow profile osd", "mon": "allow profile osd", "osd": "allow *"}}, {"entity": "osd.1", "key": "AQAjkMhbshueAhAAjZec50aBgd1NObLz57SQvg==", "caps": {"mgr": "allow profile osd", "mon": "allow profile osd", "osd": "allow *"}}, {"entity": "client.admin", "key": "AQDZjshbrJv6EhAAY9v6LzLYNDpPdlC3HD5KHA==", "auid": 0, "caps": {"mds": "allow", "mgr": "allow *", "mon": "allow *", "osd": "allow *"}}, {"entity": "client.bootstrap-mds", "key": "AQDojshbc4QCHhAA1ZTrkt9dbSZRVU2GzI6U4A==", "caps": {"mon": "allow profile bootstrap-mds"}}, {"entity": "client.bootstrap-mgr", "key": "AQBfiu5bAAAAABAARcNG24hUMlk4AdstVA5MVQ==", "caps": {"mon": "allow profile bootstrap-mgr"}}, {"entity": "client.bootstrap-osd", "key": "AQDjjshbYW+uGxAAyHcPCXXmVoL8VsTBI8z1Ng==", "caps": {"mon": "allow profile bootstrap-osd"}}, {"entity": "client.bootstrap-rbd", "key": "AQDyjshb522eIhAAtAz6nUPMOdG4H9u0NgpXhA==", "caps": {"mon": "allow profile bootstrap-rbd"}}, {"entity": "client.bootstrap-rbd-mirror", "key": "AQDfh+5bAAAAABAAEGBD59Lj2vAKIdN8pq4lbQ==", "caps": {"mon": "allow profile bootstrap-rbd-mirror"}}, {"entity": "client.bootstrap-rgw", "key": "AQDtjshbDl8oIBAAq1SfSYQKDR49hJNWJVwDQw==", "caps": {"mon": "allow profile bootstrap-rgw"}}, {"entity": "mgr.mon0", "key": "AQA0j8hbgGapORAAoDkyAvXVkM5ej4wNn4cwTQ==", "caps": {"mds": "allow *", "mon": "allow profile mgr", "osd": "allow *"}}]} # noqa E501 fake_ceph_dict_str = json.dumps(fake_ceph_dict) # convert to string expected_entity_list = ['client.admin', 'client.bootstrap-mds', 'client.bootstrap-mgr', # noqa E501 'client.bootstrap-osd', 'client.bootstrap-rbd', 'client.bootstrap-rbd-mirror', 'client.bootstrap-rgw'] # noqa E501 - result = ceph_key.lookup_ceph_initial_entities(fake_module, fake_ceph_dict_str) + result = ceph_key.lookup_ceph_initial_entities( + fake_module, fake_ceph_dict_str) assert result == expected_entity_list def test_build_key_path_admin(self): @@ -546,7 +551,8 @@ def test_state_info(self, m_exec_commands, m_exit_json, output_format): "output_format": output_format}) m_exit_json.side_effect = ca_test_common.exit_json m_exec_commands.return_value = (0, - ['ceph', 'auth', 'get', 'client.admin', '-f', output_format], + ['ceph', 'auth', 'get', + 'client.admin', '-f', output_format], '[{"entity":"client.admin","key":"AQC1tw5fF156GhAAoJCvHGX/jl/k7/N4VZm8iQ==","caps":{"mds":"allow *","mgr":"allow *","mon":"allow *","osd":"allow *"}}]', # noqa: E501 'exported keyring for client.admin') @@ -555,7 +561,8 @@ def test_state_info(self, m_exec_commands, m_exit_json, output_format): result = result.value.args[0] assert not result['changed'] - assert result['cmd'] == ['ceph', 'auth', 'get', 'client.admin', '-f', output_format] + assert result['cmd'] == ['ceph', 'auth', + 'get', 'client.admin', '-f', output_format] assert result['stdout'] == '[{"entity":"client.admin","key":"AQC1tw5fF156GhAAoJCvHGX/jl/k7/N4VZm8iQ==","caps":{"mds":"allow *","mgr":"allow *","mon":"allow *","osd":"allow *"}}]' # noqa: E501 assert result['stderr'] == 'exported keyring for client.admin' assert result['rc'] == 0 @@ -573,7 +580,8 @@ def test_state_info_invalid_format(self, m_fail_json): ceph_key.run_module() result = result.value.args[0] - assert result['msg'] == 'value of output_format must be one of: json, plain, xml, yaml, got: {}'.format(invalid_format) + assert result['msg'] == 'value of output_format must be one of: json, plain, xml, yaml, got: {}'.format( + invalid_format) @mock.patch('ceph_key.generate_secret') @mock.patch('ansible.module_utils.basic.AnsibleModule.exit_json') diff --git a/tests/unit/modules/test_ceph_pool.py b/tests/unit/modules/test_ceph_pool.py index f072c26..1c64366 100644 --- a/tests/unit/modules/test_ceph_pool.py +++ b/tests/unit/modules/test_ceph_pool.py @@ -88,7 +88,7 @@ def setup_method(self): 'rbd': {} }, 'application': 'rbd' - } + } self.fake_user_pool_config = { 'pool_name': { 'value': 'foo2' @@ -164,7 +164,7 @@ def test_check_pool_exist(self): self.fake_user_pool_config['pool_name']['value'], '-f', 'json' - ] + ] cmd = ceph_pool.check_pool_exist(fake_cluster_name, self.fake_user_pool_config['pool_name']['value'], @@ -214,31 +214,31 @@ def test_get_default_running_config(self): def test_get_application_pool(self): expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'application', - 'get', - self.fake_user_pool_config['pool_name']['value'], - '-f', - 'json' + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'application', + 'get', + self.fake_user_pool_config['pool_name']['value'], + '-f', + 'json' ] cmd = ceph_pool.get_application_pool(fake_cluster_name, @@ -250,30 +250,30 @@ def test_get_application_pool(self): def test_enable_application_pool(self): expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'application', - 'enable', - self.fake_user_pool_config['pool_name']['value'], - 'rbd' + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'application', + 'enable', + self.fake_user_pool_config['pool_name']['value'], + 'rbd' ] cmd = ceph_pool.enable_application_pool(fake_cluster_name, @@ -287,51 +287,6 @@ def test_enable_application_pool(self): def test_init_rbd_pool(self, container_image): if container_image: expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=rbd', - fake_container_image_name, - '-n', - fake_user, - '-k', - fake_user_key, - '--cluster', - fake_cluster_name, - 'pool', - 'init', - self.fake_user_pool_config['pool_name']['value'] - ] - else: - expected_command = [ - 'rbd', - '-n', - fake_user, - '-k', - fake_user_key, - '--cluster', - fake_cluster_name, - 'pool', - 'init', - self.fake_user_pool_config['pool_name']['value'] - ] - - cmd = ceph_pool.init_rbd_pool(fake_cluster_name, - self.fake_user_pool_config['pool_name']['value'], - fake_user, fake_user_key, - container_image) - - assert cmd == expected_command - - def test_disable_application_pool(self): - expected_command = [ 'podman', 'run', '--rm', @@ -342,21 +297,66 @@ def test_disable_application_pool(self): '/var/lib/ceph/:/var/lib/ceph/:z', '-v', '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', + '--entrypoint=rbd', fake_container_image_name, '-n', - 'client.admin', + fake_user, '-k', - '/etc/ceph/ceph.client.admin.keyring', + fake_user_key, '--cluster', - 'ceph', - 'osd', + fake_cluster_name, 'pool', - 'application', - 'disable', - self.fake_user_pool_config['pool_name']['value'], + 'init', + self.fake_user_pool_config['pool_name']['value'] + ] + else: + expected_command = [ 'rbd', - '--yes-i-really-mean-it' + '-n', + fake_user, + '-k', + fake_user_key, + '--cluster', + fake_cluster_name, + 'pool', + 'init', + self.fake_user_pool_config['pool_name']['value'] + ] + + cmd = ceph_pool.init_rbd_pool(fake_cluster_name, + self.fake_user_pool_config['pool_name']['value'], + fake_user, fake_user_key, + container_image) + + assert cmd == expected_command + + def test_disable_application_pool(self): + expected_command = [ + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'application', + 'disable', + self.fake_user_pool_config['pool_name']['value'], + 'rbd', + '--yes-i-really-mean-it' ] cmd = ceph_pool.disable_application_pool(fake_cluster_name, @@ -367,126 +367,134 @@ def test_disable_application_pool(self): assert cmd == expected_command def test_compare_pool_config_no_diff(self): - delta = ceph_pool.compare_pool_config(self.fake_user_pool_config, self.fake_running_pool_details) + delta = ceph_pool.compare_pool_config( + self.fake_user_pool_config, self.fake_running_pool_details) assert delta == {} def test_compare_pool_config_std_diff(self): self.fake_user_pool_config['size']['value'] = '3' - delta = ceph_pool.compare_pool_config(self.fake_user_pool_config, self.fake_running_pool_details) + delta = ceph_pool.compare_pool_config( + self.fake_user_pool_config, self.fake_running_pool_details) assert delta == {'size': {'cli_set_opt': 'size', 'value': '3'}} def test_compare_pool_config_target_size_ratio_diff(self): self.fake_user_pool_config['target_size_ratio']['value'] = '0.5' - delta = ceph_pool.compare_pool_config(self.fake_user_pool_config, self.fake_running_pool_details) + delta = ceph_pool.compare_pool_config( + self.fake_user_pool_config, self.fake_running_pool_details) - assert delta == {'target_size_ratio': {'cli_set_opt': 'target_size_ratio', 'value': '0.5'}} + assert delta == {'target_size_ratio': { + 'cli_set_opt': 'target_size_ratio', 'value': '0.5'}} def test_compare_pool_config_application_diff(self): self.fake_user_pool_config['application']['value'] = 'foo' - delta = ceph_pool.compare_pool_config(self.fake_user_pool_config, self.fake_running_pool_details) + delta = ceph_pool.compare_pool_config( + self.fake_user_pool_config, self.fake_running_pool_details) - assert delta == {'application': {'new_application': 'foo', 'old_application': 'rbd', 'value': 'foo'}} + assert delta == {'application': { + 'new_application': 'foo', 'old_application': 'rbd', 'value': 'foo'}} def test_list_pools_details(self): expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'ls', - 'detail', - '-f', - 'json' + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'ls', + 'detail', + '-f', + 'json' ] - cmd = ceph_pool.list_pools(fake_cluster_name, fake_user, fake_user_key, True, 'json', container_image=fake_container_image_name) + cmd = ceph_pool.list_pools(fake_cluster_name, fake_user, fake_user_key, + True, 'json', container_image=fake_container_image_name) assert cmd == expected_command def test_list_pools_nodetails(self): expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'ls', - '-f', - 'json' + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'ls', + '-f', + 'json' ] - cmd = ceph_pool.list_pools(fake_cluster_name, fake_user, fake_user_key, False, 'json', container_image=fake_container_image_name) + cmd = ceph_pool.list_pools(fake_cluster_name, fake_user, fake_user_key, + False, 'json', container_image=fake_container_image_name) assert cmd == expected_command def test_create_replicated_pool_pg_autoscaler_enabled(self): self.fake_user_pool_config['type']['value'] = 'replicated' expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'create', - self.fake_user_pool_config['pool_name']['value'], - self.fake_user_pool_config['type']['value'], - '--target_size_ratio', - self.fake_user_pool_config['target_size_ratio']['value'], - self.fake_user_pool_config['crush_rule']['value'], - '--expected_num_objects', - self.fake_user_pool_config['expected_num_objects']['value'], - '--autoscale-mode', - self.fake_user_pool_config['pg_autoscale_mode']['value'], - '--size', - self.fake_user_pool_config['size']['value'] + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'create', + self.fake_user_pool_config['pool_name']['value'], + self.fake_user_pool_config['type']['value'], + '--target_size_ratio', + self.fake_user_pool_config['target_size_ratio']['value'], + self.fake_user_pool_config['crush_rule']['value'], + '--expected_num_objects', + self.fake_user_pool_config['expected_num_objects']['value'], + '--autoscale-mode', + self.fake_user_pool_config['pg_autoscale_mode']['value'], + '--size', + self.fake_user_pool_config['size']['value'] ] cmd = ceph_pool.create_pool(fake_cluster_name, @@ -499,40 +507,40 @@ def test_create_replicated_pool_pg_autoscaler_disabled(self): self.fake_user_pool_config['type']['value'] = 'replicated' self.fake_user_pool_config['pg_autoscale_mode']['value'] = 'off' expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'create', - self.fake_user_pool_config['pool_name']['value'], - self.fake_user_pool_config['type']['value'], - '--pg_num', - self.fake_user_pool_config['pg_num']['value'], - '--pgp_num', - self.fake_user_pool_config['pgp_num']['value'], - self.fake_user_pool_config['crush_rule']['value'], - '--expected_num_objects', - self.fake_user_pool_config['expected_num_objects']['value'], - '--autoscale-mode', - self.fake_user_pool_config['pg_autoscale_mode']['value'], - '--size', - self.fake_user_pool_config['size']['value'] + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'create', + self.fake_user_pool_config['pool_name']['value'], + self.fake_user_pool_config['type']['value'], + '--pg_num', + self.fake_user_pool_config['pg_num']['value'], + '--pgp_num', + self.fake_user_pool_config['pgp_num']['value'], + self.fake_user_pool_config['crush_rule']['value'], + '--expected_num_objects', + self.fake_user_pool_config['expected_num_objects']['value'], + '--autoscale-mode', + self.fake_user_pool_config['pg_autoscale_mode']['value'], + '--size', + self.fake_user_pool_config['size']['value'] ] cmd = ceph_pool.create_pool(fake_cluster_name, @@ -547,37 +555,37 @@ def test_create_erasure_pool_pg_autoscaler_enabled(self): self.fake_user_pool_config['erasure_profile']['value'] = 'erasure-default' self.fake_user_pool_config['crush_rule']['value'] = 'erasure_rule' expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'create', - self.fake_user_pool_config['pool_name']['value'], - self.fake_user_pool_config['type']['value'], - '--target_size_ratio', - self.fake_user_pool_config['target_size_ratio']['value'], - self.fake_user_pool_config['erasure_profile']['value'], - self.fake_user_pool_config['crush_rule']['value'], - '--expected_num_objects', - self.fake_user_pool_config['expected_num_objects']['value'], - '--autoscale-mode', - self.fake_user_pool_config['pg_autoscale_mode']['value'] + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'create', + self.fake_user_pool_config['pool_name']['value'], + self.fake_user_pool_config['type']['value'], + '--target_size_ratio', + self.fake_user_pool_config['target_size_ratio']['value'], + self.fake_user_pool_config['erasure_profile']['value'], + self.fake_user_pool_config['crush_rule']['value'], + '--expected_num_objects', + self.fake_user_pool_config['expected_num_objects']['value'], + '--autoscale-mode', + self.fake_user_pool_config['pg_autoscale_mode']['value'] ] cmd = ceph_pool.create_pool(fake_cluster_name, @@ -592,39 +600,39 @@ def test_create_erasure_pool_pg_autoscaler_disabled(self): self.fake_user_pool_config['crush_rule']['value'] = 'erasure_rule' self.fake_user_pool_config['pg_autoscale_mode']['value'] = 'off' expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'create', - self.fake_user_pool_config['pool_name']['value'], - self.fake_user_pool_config['type']['value'], - '--pg_num', - self.fake_user_pool_config['pg_num']['value'], - '--pgp_num', - self.fake_user_pool_config['pgp_num']['value'], - self.fake_user_pool_config['erasure_profile']['value'], - self.fake_user_pool_config['crush_rule']['value'], - '--expected_num_objects', - self.fake_user_pool_config['expected_num_objects']['value'], - '--autoscale-mode', - self.fake_user_pool_config['pg_autoscale_mode']['value'] + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'create', + self.fake_user_pool_config['pool_name']['value'], + self.fake_user_pool_config['type']['value'], + '--pg_num', + self.fake_user_pool_config['pg_num']['value'], + '--pgp_num', + self.fake_user_pool_config['pgp_num']['value'], + self.fake_user_pool_config['erasure_profile']['value'], + self.fake_user_pool_config['crush_rule']['value'], + '--expected_num_objects', + self.fake_user_pool_config['expected_num_objects']['value'], + '--autoscale-mode', + self.fake_user_pool_config['pg_autoscale_mode']['value'] ] cmd = ceph_pool.create_pool(fake_cluster_name, @@ -635,30 +643,30 @@ def test_create_erasure_pool_pg_autoscaler_disabled(self): def test_remove_pool(self): expected_command = [ - 'podman', - 'run', - '--rm', - '--net=host', - '-v', - '/etc/ceph:/etc/ceph:z', - '-v', - '/var/lib/ceph/:/var/lib/ceph/:z', - '-v', - '/var/log/ceph/:/var/log/ceph/:z', - '--entrypoint=ceph', - fake_container_image_name, - '-n', - 'client.admin', - '-k', - '/etc/ceph/ceph.client.admin.keyring', - '--cluster', - 'ceph', - 'osd', - 'pool', - 'rm', - self.fake_user_pool_config['pool_name']['value'], - self.fake_user_pool_config['pool_name']['value'], - '--yes-i-really-really-mean-it' + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + 'client.admin', + '-k', + '/etc/ceph/ceph.client.admin.keyring', + '--cluster', + 'ceph', + 'osd', + 'pool', + 'rm', + self.fake_user_pool_config['pool_name']['value'], + self.fake_user_pool_config['pool_name']['value'], + '--yes-i-really-really-mean-it' ] cmd = ceph_pool.remove_pool(fake_cluster_name, self.fake_user_pool_config['pool_name']['value'], diff --git a/tests/unit/modules/test_ceph_volume.py b/tests/unit/modules/test_ceph_volume.py index 0499a53..ab1e4fe 100644 --- a/tests/unit/modules/test_ceph_volume.py +++ b/tests/unit/modules/test_ceph_volume.py @@ -37,7 +37,7 @@ def get_container_cmd(mounts=None): return ['docker', 'run', '--rm', '--privileged', '--net=host', '--ipc=host'] + \ - get_mounts(mounts) + ['--entrypoint=ceph-volume'] + get_mounts(mounts) + ['--entrypoint=ceph-volume'] @mock.patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': 'docker'}) @@ -170,9 +170,9 @@ def test_list_osd_container(self): fake_module.params = {'cluster': 'ceph', 'data': '/dev/sda'} fake_container_image = "quay.io/ceph/daemon:latest" expected_command_list = get_container_cmd( - { - '/var/lib/ceph': '/var/lib/ceph:ro' - }) + \ + { + '/var/lib/ceph': '/var/lib/ceph:ro' + }) + \ [fake_container_image, '--cluster', 'ceph', @@ -192,7 +192,8 @@ def test_list_storage_inventory(self): 'inventory', '--format=json', ] - result = ceph_volume.list_storage_inventory(fake_module, fake_container_image) + result = ceph_volume.list_storage_inventory( + fake_module, fake_container_image) assert result == expected_command_list def test_list_storage_inventory_container(self): @@ -204,7 +205,8 @@ def test_list_storage_inventory_container(self): 'ceph', 'inventory', '--format=json'] - result = ceph_volume.list_storage_inventory(fake_module, fake_container_image) + result = ceph_volume.list_storage_inventory( + fake_module, fake_container_image) assert result == expected_command_list @pytest.mark.parametrize('objectstore', ['bluestore']) @@ -410,17 +412,17 @@ def test_prepare_no_keyring_in_output(self, m_run_command, m_exit_json): list_stderr = '' list_stdout = '{}' prepare_rc = 0 - prepare_stderr = """ + prepare_stderr = f""" Running command: /usr/bin/ceph-authtool --gen-print-key Running command: /usr/bin/mount -t tmpfs tmpfs /var/lib/ceph/osd/ceph-0 Running command: /usr/bin/chown -h ceph:ceph /dev/test_group/data-lv1 Running command: /usr/bin/chown -R ceph:ceph /dev/dm-0 Running command: /usr/bin/ln -s /dev/test_group/data-lv1 /var/lib/ceph/osd/ceph-1/block stderr: got monmap epoch 1 - Running command: /usr/bin/ceph-authtool /var/lib/ceph/osd/ceph-1/keyring --create-keyring --name osd.1 --add-key {} + Running command: /usr/bin/ceph-authtool /var/lib/ceph/osd/ceph-1/keyring --create-keyring --name osd.1 --add-key {keyring} stdout: creating /var/lib/ceph/osd/ceph-1/keyring - added entity osd.1 auth(key={}) -""".format(keyring, keyring) + added entity osd.1 auth(key={keyring}) +""" prepare_stdout = '' m_run_command.side_effect = [ (list_rc, list_stdout, list_stderr), @@ -432,7 +434,8 @@ def test_prepare_no_keyring_in_output(self, m_run_command, m_exit_json): result = result.value.args[0] assert result['changed'] - assert result['cmd'] == ['ceph-volume', '--cluster', 'ceph', 'lvm', 'prepare', '--bluestore', '--data', '/dev/sda'] + assert result['cmd'] == ['ceph-volume', '--cluster', 'ceph', + 'lvm', 'prepare', '--bluestore', '--data', '/dev/sda'] assert result['rc'] == 0 assert keyring not in result['stderr'] assert '*' * 8 in result['stderr'] @@ -451,17 +454,17 @@ def test_batch_no_keyring_in_output(self, m_run_command, m_exit_json): report_stderr = '' report_stdout = '[{"data": "/dev/sda", "data_size": "50.00 GB", "encryption": "None"}]' batch_rc = 0 - batch_stderr = """ + batch_stderr = f""" Running command: /usr/bin/ceph-authtool --gen-print-key Running command: /usr/bin/mount -t tmpfs tmpfs /var/lib/ceph/osd/ceph-0 Running command: /usr/bin/chown -h ceph:ceph /dev/ceph-863337c4-bef9-4b96-aaac-27cde8c42b8f/osd-block-b1d1036f-0d6e-493b-9d1a-6f6b96df64b1 Running command: /usr/bin/chown -R ceph:ceph /dev/mapper/ceph--863337c4--bef9--4b96--aaac--27cde8c42b8f-osd--block--b1d1036f--0d6e--493b--9d1a--6f6b96df64b1 Running command: /usr/bin/ln -s /dev/ceph-863337c4-bef9-4b96-aaac-27cde8c42b8f/osd-block-b1d1036f-0d6e-493b-9d1a-6f6b96df64b1 /var/lib/ceph/osd/ceph-0/block stderr: got monmap epoch 1 - Running command: /usr/bin/ceph-authtool /var/lib/ceph/osd/ceph-0/keyring --create-keyring --name osd.0 --add-key {} + Running command: /usr/bin/ceph-authtool /var/lib/ceph/osd/ceph-0/keyring --create-keyring --name osd.0 --add-key {keyring} stdout: creating /var/lib/ceph/osd/ceph-0/keyring - added entity osd.0 auth(key={}) -""".format(keyring, keyring) + added entity osd.0 auth(key={keyring}) +""" batch_stdout = '' m_run_command.side_effect = [ (report_rc, report_stdout, report_stderr), @@ -473,7 +476,8 @@ def test_batch_no_keyring_in_output(self, m_run_command, m_exit_json): result = result.value.args[0] assert result['changed'] - assert result['cmd'] == ['ceph-volume', '--cluster', 'ceph', 'lvm', 'batch', '--bluestore', '--yes', '/dev/sda'] + assert result['cmd'] == ['ceph-volume', '--cluster', 'ceph', + 'lvm', 'batch', '--bluestore', '--yes', '/dev/sda'] assert result['rc'] == 0 assert keyring not in result['stderr'] assert '*' * 8 in result['stderr'] diff --git a/tests/unit/modules/test_cephadm_adopt.py b/tests/unit/modules/test_cephadm_adopt.py index 36e3bbf..e7f6d7a 100644 --- a/tests/unit/modules/test_cephadm_adopt.py +++ b/tests/unit/modules/test_cephadm_adopt.py @@ -65,13 +65,13 @@ def test_with_default_values(self, m_run_command, m_exit_json): 'name': fake_name }) m_exit_json.side_effect = ca_test_common.exit_json - stdout = 'Stopping old systemd unit ceph-mon@{}...\n' \ - 'Disabling old systemd unit ceph-mon@{}...\n' \ + stdout = f'Stopping old systemd unit ceph-mon@{fake_name}...\n' \ + 'Disabling old systemd unit ceph-mon@{fake_name}...\n' \ 'Moving data...\n' \ 'Chowning content...\n' \ 'Moving logs...\n' \ 'Creating new units...\n' \ - 'firewalld ready'.format(fake_name, fake_name) + 'firewalld ready' stderr = '' rc = 0 m_run_command.side_effect = [ @@ -84,7 +84,8 @@ def test_with_default_values(self, m_run_command, m_exit_json): result = result.value.args[0] assert result['changed'] - assert result['cmd'] == ['cephadm', 'adopt', '--cluster', fake_cluster, '--name', fake_name, '--style', 'legacy'] + assert result['cmd'] == ['cephadm', 'adopt', '--cluster', + fake_cluster, '--name', fake_name, '--style', 'legacy'] assert result['rc'] == 0 assert result['stderr'] == stderr assert result['stdout'] == stdout @@ -132,7 +133,8 @@ def test_with_docker(self, m_run_command, m_exit_json): result = result.value.args[0] assert result['changed'] - assert result['cmd'] == ['cephadm', '--docker', 'adopt', '--cluster', fake_cluster, '--name', fake_name, '--style', 'legacy'] + assert result['cmd'] == ['cephadm', '--docker', 'adopt', '--cluster', + fake_cluster, '--name', fake_name, '--style', 'legacy'] assert result['rc'] == 0 @patch('ansible.module_utils.basic.AnsibleModule.exit_json') @@ -156,7 +158,8 @@ def test_with_custom_image(self, m_run_command, m_exit_json): result = result.value.args[0] assert result['changed'] - assert result['cmd'] == ['cephadm', '--image', fake_image, 'adopt', '--cluster', fake_cluster, '--name', fake_name, '--style', 'legacy'] + assert result['cmd'] == ['cephadm', '--image', fake_image, 'adopt', + '--cluster', fake_cluster, '--name', fake_name, '--style', 'legacy'] assert result['rc'] == 0 @patch('ansible.module_utils.basic.AnsibleModule.exit_json') @@ -180,7 +183,8 @@ def test_without_pull(self, m_run_command, m_exit_json): result = result.value.args[0] assert result['changed'] - assert result['cmd'] == ['cephadm', 'adopt', '--cluster', fake_cluster, '--name', fake_name, '--style', 'legacy', '--skip-pull'] + assert result['cmd'] == ['cephadm', 'adopt', '--cluster', fake_cluster, + '--name', fake_name, '--style', 'legacy', '--skip-pull'] assert result['rc'] == 0 @patch('ansible.module_utils.basic.AnsibleModule.exit_json') @@ -204,5 +208,6 @@ def test_without_firewalld(self, m_run_command, m_exit_json): result = result.value.args[0] assert result['changed'] - assert result['cmd'] == ['cephadm', 'adopt', '--cluster', fake_cluster, '--name', fake_name, '--style', 'legacy', '--skip-firewalld'] + assert result['cmd'] == ['cephadm', 'adopt', '--cluster', fake_cluster, + '--name', fake_name, '--style', 'legacy', '--skip-firewalld'] assert result['rc'] == 0