Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,35 @@ jobs:
run: |
ansible-lint -v --force-color
antsibull-changelog lint
flake8 -v

ansible-test-sanity:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
# Checks-out the repository under $GITHUB_WORKSPACE, so it's accessible to the job
- uses: actions/checkout@v3
with:
path: ansible_collections/stackhpc/cephadm

- name: Install dependencies
working-directory: ansible_collections/stackhpc/cephadm
run: |
python -m pip install --upgrade pip
pip install -r test-requirements.txt

- name: Run ansible-test sanity to download docker images
working-directory: ansible_collections/stackhpc/cephadm
run: |
ansible-test sanity --docker --prime-containers

- name: Run ansible-test sanity
working-directory: ansible_collections/stackhpc/cephadm
run: |
ansible-test sanity --verbose --docker --junit

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/tests/output/junit/*.xml'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/changelogs/.plugin-cache.yaml
/tests/output
7 changes: 4 additions & 3 deletions plugins/module_utils/cephadm_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python3

# Copyright 2020, Red Hat, Inc.
# Copyright 2021, StackHPC, Ltd.
# NOTE: Files adapted from github.com/ceph/ceph-ansible
Expand All @@ -16,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import datetime


Expand Down Expand Up @@ -75,4 +76,4 @@ def fatal(message, module):
if module:
module.fail_json(msg=message, rc=1)
else:
raise(Exception(message))
raise Exception(message)
35 changes: 21 additions & 14 deletions plugins/modules/cephadm_crush_rule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/python

# Copyright 2020, Red Hat, Inc.
# Copyright 2021, StackHPC, Ltd.
Expand All @@ -19,13 +19,6 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.stackhpc.cephadm.plugins.module_utils.cephadm_common \
import generate_ceph_cmd, exec_command, exit_module

import datetime
import json


DOCUMENTATION = r'''
---
Expand All @@ -34,11 +27,15 @@
version_added: "1.4.0"
description:
- Manage Ceph Crush rule(s) creation, deletion and updates.
author:
- Dimitri Savineau <dsavinea@redhat.com>
- Michal Nasiadka <michal@stackhpc.com>
options:
name:
description:
- name of the Ceph Crush rule.
required: true
type: str
state:
description:
If 'present' is used, the module creates a rule if it doesn't
Expand All @@ -49,33 +46,35 @@
required: false
choices: ['present', 'absent', 'info']
default: present
type: str
rule_type:
description:
- The ceph CRUSH rule type.
required: false
choices: ['replicated', 'erasure']
required: false
type: str
bucket_root:
description:
- The ceph bucket root for replicated rule.
required: false
type: str
bucket_type:
description:
- The ceph bucket type for replicated rule.
required: false
choices: ['osd', 'host', 'chassis', 'rack', 'row', 'pdu', 'pod',
'room', 'datacenter', 'zone', 'region', 'root']
type: str
device_class:
description:
- The ceph device class for replicated rule.
required: false
type: str
profile:
description:
- The ceph erasure profile for erasure rule.
required: false
author:
- Dimitri Savineau <dsavinea@redhat.com>
Michal Nasiadka <michal@stackhpc.com>
type: str
'''

EXAMPLES = '''
Expand Down Expand Up @@ -107,6 +106,14 @@
RETURN = '''# '''


from ansible.module_utils.basic import AnsibleModule
from ansible_collections.stackhpc.cephadm.plugins.module_utils.cephadm_common \
import generate_ceph_cmd, exec_command, exit_module

import datetime
import json


def create_rule(module, container_image=None):
'''
Create a new crush replicated/erasure rule
Expand Down Expand Up @@ -211,7 +218,7 @@ def main():
else:
rule = json.loads(out)
if (rule['type'] == 1 and rule_type == 'erasure') or (rule['type'] == 3 and rule_type == 'replicated'): # noqa: E501
module.fail_json(msg="Can not convert crush rule {} to {}".format(name, rule_type), changed=False, rc=1) # noqa: E501
module.fail_json(msg="Can not convert crush rule {0} to {1}".format(str(name), str(rule_type)), changed=False, rc=1) # noqa: E501

elif state == "absent":
rc, cmd, out, err = exec_command(module, get_rule(module)) # noqa: E501
Expand All @@ -220,7 +227,7 @@ def main():
changed = True
else:
rc = 0
out = "Crush Rule {} doesn't exist".format(name)
out = "Crush Rule {0} doesn't exist".format(name)

elif state == "info":
rc, cmd, out, err = exec_command(module, get_rule(module)) # noqa: E501
Expand Down
48 changes: 26 additions & 22 deletions plugins/modules/cephadm_ec_profile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/python

# Copyright 2020, Red Hat, Inc.
# Copyright 2021, StackHPC, Ltd.
Expand All @@ -19,13 +19,6 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.stackhpc.cephadm.plugins.module_utils.cephadm_common \
import generate_ceph_cmd, exec_command, exit_module

import datetime
import json


DOCUMENTATION = '''
---
Expand All @@ -42,49 +35,52 @@
description:
- name of the profile.
required: true
type: str
state:
description:
If 'present' is used, the module creates a profile.
If 'absent' is used, the module will delete the profile.
required: false
choices: ['present', 'absent', 'info']
choices: ['present', 'absent']
default: present
type: str
stripe_unit:
description:
- The amount of data in a data chunk, per stripe.
required: false
type: str
k:
description:
- Number of data-chunks the object will be split in
required: false
type: str
m:
description:
- Compute coding chunks for each object and store them on different
OSDs.
required: false
type: str
plugin:
description:
- Use the erasure code plugin to compute coding chunks and recover
missing chunks.
required: false
type: str
directory:
description:
- Set the directory name from which the erasure code plugin is
loaded.
required: false
crush_root:
description:
- The name of the crush bucket used for the first step of the CRUSH
rule.
required: false
type: str
crush_device_class:
description:
- Restrict placement to devices of a specific class (hdd/ssd)
required: false
type: str

author:
- Guillaume Abrioux <gabrioux@redhat.com>
Michal Nasiadka <michal@stackhpc.com>
- Michal Nasiadka <michal@stackhpc.com>
'''

EXAMPLES = '''
Expand All @@ -100,6 +96,14 @@
state: absent
'''

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.stackhpc.cephadm.plugins.module_utils.cephadm_common \
import generate_ceph_cmd, exec_command, exit_module

import datetime
import json


RETURN = '''# '''


Expand All @@ -121,15 +125,15 @@ def create_profile(module, name, k, m, stripe_unit, crush_device_class, director
Create a profile
'''

args = ['set', name, 'k={}'.format(k), 'm={}'.format(m)]
args = ['set', name, 'k={0}'.format(k), 'm={0}'.format(m)]
if stripe_unit:
args.append('stripe_unit={}'.format(stripe_unit))
args.append('stripe_unit={0}'.format(stripe_unit))
if crush_device_class:
args.append('crush-device-class={}'.format(crush_device_class))
args.append('crush-device-class={0}'.format(crush_device_class))
if directory:
args.append('directory={}'.format(plugin))
args.append('directory={0}'.format(plugin))
if plugin:
args.append('plugin={}'.format(plugin))
args.append('plugin={0}'.format(plugin))
if force:
args.append('--force')

Expand Down Expand Up @@ -234,11 +238,11 @@ def run_module():
elif state == "absent":
rc, cmd, out, err = exec_command(module, delete_profile(module, name)) # noqa: E501
if not err:
out = 'Profile {} removed.'.format(name)
out = 'Profile {0} removed.'.format(name)
changed = True
else:
rc = 0
out = "Skipping, the profile {} doesn't exist".format(name)
out = "Skipping, the profile {0} doesn't exist".format(name)

exit_module(module=module, out=out, rc=rc, cmd=cmd, err=err, startd=startd, changed=changed) # noqa: E501

Expand Down
Loading