Initialize rbd pool at pool creation

When creating a RBD pool it needs to be initialized as per documentation[1]
Modified (pre_)generate_ceph_cmd to make it usable with any command with
the same parameters as the ceph command

[1]https://docs.ceph.com/en/latest/rbd/rados-rbd-cmds/#create-a-block-device-pool

Signed-off-by: Teoman ONAY <tonay@redhat.com>
pull/7375/head
Teoman ONAY 2022-11-29 09:47:58 +01:00 committed by Guillaume Abrioux
parent e5ad1953dc
commit c39bbc3dea
13 changed files with 289 additions and 208 deletions

View File

@ -18,12 +18,12 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import exit_module, \ from ansible.module_utils.ca_common import exit_module, \
generate_ceph_cmd, \ generate_cmd, \
is_containerized, \ is_containerized, \
exec_command exec_command
except ImportError: except ImportError:
from module_utils.ca_common import exit_module, \ from module_utils.ca_common import exit_module, \
generate_ceph_cmd, \ generate_cmd, \
is_containerized, \ is_containerized, \
exec_command exec_command
import datetime import datetime
@ -142,10 +142,10 @@ def create_rule(module, container_image=None):
if profile: if profile:
args.append(profile) args.append(profile)
cmd = generate_ceph_cmd(['osd', 'crush', 'rule'], cmd = generate_cmd(sub_cmd=['osd', 'crush', 'rule'],
args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -160,10 +160,10 @@ def get_rule(module, container_image=None):
args = ['dump', name, '--format=json'] args = ['dump', name, '--format=json']
cmd = generate_ceph_cmd(['osd', 'crush', 'rule'], cmd = generate_cmd(sub_cmd=['osd', 'crush', 'rule'],
args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -178,10 +178,10 @@ def remove_rule(module, container_image=None):
args = ['rm', name] args = ['rm', name]
cmd = generate_ceph_cmd(['osd', 'crush', 'rule'], cmd = generate_cmd(sub_cmd=['osd', 'crush', 'rule'],
args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd

View File

@ -17,13 +17,13 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import generate_ceph_cmd, \ from ansible.module_utils.ca_common import generate_cmd, \
is_containerized, \ is_containerized, \
exec_command, \ exec_command, \
exit_module, \ exit_module, \
fatal fatal
except ImportError: except ImportError:
from module_utils.ca_common import generate_ceph_cmd, is_containerized, exec_command, exit_module, fatal # noqa: E501 from module_utils.ca_common import generate_cmd, is_containerized, exec_command, exit_module, fatal # noqa: E501
import datetime import datetime
import json import json
@ -123,11 +123,11 @@ def create_user(module, container_image=None):
args = ['ac-user-create', '-i', '-', name] args = ['ac-user-create', '-i', '-', name]
cmd = generate_ceph_cmd(sub_cmd=['dashboard'], cmd = generate_cmd(sub_cmd=['dashboard'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image, container_image=container_image,
interactive=True) interactive=True)
return cmd return cmd
@ -145,10 +145,10 @@ def set_roles(module, container_image=None):
args.extend(roles) args.extend(roles)
cmd = generate_ceph_cmd(sub_cmd=['dashboard'], cmd = generate_cmd(sub_cmd=['dashboard'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -163,11 +163,11 @@ def set_password(module, container_image=None):
args = ['ac-user-set-password', '-i', '-', name] args = ['ac-user-set-password', '-i', '-', name]
cmd = generate_ceph_cmd(sub_cmd=['dashboard'], cmd = generate_cmd(sub_cmd=['dashboard'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image, container_image=container_image,
interactive=True) interactive=True)
return cmd return cmd
@ -182,10 +182,10 @@ def get_user(module, container_image=None):
args = ['ac-user-show', name, '--format=json'] args = ['ac-user-show', name, '--format=json']
cmd = generate_ceph_cmd(sub_cmd=['dashboard'], cmd = generate_cmd(sub_cmd=['dashboard'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -200,10 +200,10 @@ def remove_user(module, container_image=None):
args = ['ac-user-delete', name] args = ['ac-user-delete', name]
cmd = generate_ceph_cmd(sub_cmd=['dashboard'], cmd = generate_cmd(sub_cmd=['dashboard'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd

View File

@ -18,12 +18,12 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import is_containerized, \ from ansible.module_utils.ca_common import is_containerized, \
generate_ceph_cmd, \ generate_cmd, \
exec_command, \ exec_command, \
exit_module exit_module
except ImportError: except ImportError:
from module_utils.ca_common import is_containerized, \ from module_utils.ca_common import is_containerized, \
generate_ceph_cmd, \ generate_cmd, \
exec_command, \ exec_command, \
exit_module exit_module
import datetime import datetime
@ -108,10 +108,10 @@ def get_profile(module, name, cluster='ceph', container_image=None):
args = ['get', name, '--format=json'] args = ['get', name, '--format=json']
cmd = generate_ceph_cmd(sub_cmd=['osd', 'erasure-code-profile'], cmd = generate_cmd(sub_cmd=['osd', 'erasure-code-profile'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -129,10 +129,10 @@ def create_profile(module, name, k, m, stripe_unit, crush_device_class, cluster=
if force: if force:
args.append('--force') args.append('--force')
cmd = generate_ceph_cmd(sub_cmd=['osd', 'erasure-code-profile'], cmd = generate_cmd(sub_cmd=['osd', 'erasure-code-profile'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -144,10 +144,10 @@ def delete_profile(module, name, cluster='ceph', container_image=None):
args = ['rm', name] args = ['rm', name]
cmd = generate_ceph_cmd(sub_cmd=['osd', 'erasure-code-profile'], cmd = generate_cmd(sub_cmd=['osd', 'erasure-code-profile'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -205,7 +205,7 @@ def run_module():
if current_profile['k'] != k or \ if current_profile['k'] != k or \
current_profile['m'] != m or \ current_profile['m'] != m or \
current_profile.get('stripe_unit', stripe_unit) != stripe_unit or \ current_profile.get('stripe_unit', stripe_unit) != stripe_unit or \
current_profile.get('crush-device-class', crush_device_class) != crush_device_class: current_profile.get('crush-device-class', crush_device_class) != crush_device_class: # noqa: E501
rc, cmd, out, err = exec_command(module, rc, cmd, out, err = exec_command(module,
create_profile(module, create_profile(module,
name, name,

View File

@ -19,12 +19,12 @@ from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import is_containerized, \ from ansible.module_utils.ca_common import is_containerized, \
exec_command, \ exec_command, \
generate_ceph_cmd, \ generate_cmd, \
exit_module exit_module
except ImportError: except ImportError:
from module_utils.ca_common import is_containerized, \ from module_utils.ca_common import is_containerized, \
exec_command, \ exec_command, \
generate_ceph_cmd, \ generate_cmd, \
exit_module exit_module
import datetime import datetime
@ -119,10 +119,10 @@ def create_fs(module, container_image=None):
args = ['new', name, metadata, data] args = ['new', name, metadata, data]
cmd = generate_ceph_cmd(sub_cmd=['fs'], cmd = generate_cmd(sub_cmd=['fs'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -137,10 +137,10 @@ def get_fs(module, container_image=None):
args = ['get', name, '--format=json'] args = ['get', name, '--format=json']
cmd = generate_ceph_cmd(sub_cmd=['fs'], cmd = generate_cmd(sub_cmd=['fs'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -155,10 +155,10 @@ def remove_fs(module, container_image=None):
args = ['rm', name, '--yes-i-really-mean-it'] args = ['rm', name, '--yes-i-really-mean-it']
cmd = generate_ceph_cmd(sub_cmd=['fs'], cmd = generate_cmd(sub_cmd=['fs'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -173,10 +173,10 @@ def fail_fs(module, container_image=None):
args = ['fail', name] args = ['fail', name]
cmd = generate_ceph_cmd(sub_cmd=['fs'], cmd = generate_cmd(sub_cmd=['fs'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -192,10 +192,10 @@ def set_fs(module, container_image=None):
args = ['set', name, 'max_mds', str(max_mds)] args = ['set', name, 'max_mds', str(max_mds)]
cmd = generate_ceph_cmd(sub_cmd=['fs'], cmd = generate_cmd(sub_cmd=['fs'],
args=args, args=args,
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
return cmd return cmd

View File

@ -19,12 +19,12 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import generate_ceph_cmd, \ from ansible.module_utils.ca_common import generate_cmd, \
is_containerized, \ is_containerized, \
container_exec, \ container_exec, \
fatal fatal
except ImportError: except ImportError:
from module_utils.ca_common import generate_ceph_cmd, \ from module_utils.ca_common import generate_cmd, \
is_containerized, \ is_containerized, \
container_exec, \ container_exec, \
fatal fatal
@ -304,12 +304,12 @@ def create_key(module, result, cluster, user, user_key, name, secret, caps, impo
cluster, name, secret, caps, dest, container_image)) cluster, name, secret, caps, dest, container_image))
if import_key or user != 'client.admin': if import_key or user != 'client.admin':
cmd_list.append(generate_ceph_cmd(sub_cmd=['auth'], cmd_list.append(generate_cmd(sub_cmd=['auth'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image)) container_image=container_image))
return cmd_list return cmd_list
@ -326,12 +326,12 @@ def delete_key(cluster, user, user_key, name, container_image=None):
name, name,
] ]
cmd_list.append(generate_ceph_cmd(sub_cmd=['auth'], cmd_list.append(generate_cmd(sub_cmd=['auth'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image)) container_image=container_image))
return cmd_list return cmd_list
@ -350,12 +350,12 @@ def get_key(cluster, user, user_key, name, dest, container_image=None):
dest, dest,
] ]
cmd_list.append(generate_ceph_cmd(sub_cmd=['auth'], cmd_list.append(generate_cmd(sub_cmd=['auth'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image)) container_image=container_image))
return cmd_list return cmd_list
@ -374,12 +374,12 @@ def info_key(cluster, name, user, user_key, output_format, container_image=None)
output_format, output_format,
] ]
cmd_list.append(generate_ceph_cmd(sub_cmd=['auth'], cmd_list.append(generate_cmd(sub_cmd=['auth'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image)) container_image=container_image))
return cmd_list return cmd_list
@ -397,12 +397,12 @@ def list_keys(cluster, user, user_key, container_image=None):
'json', 'json',
] ]
cmd_list.append(generate_ceph_cmd(sub_cmd=['auth'], cmd_list.append(generate_cmd(sub_cmd=['auth'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image)) container_image=container_image))
return cmd_list return cmd_list

View File

@ -18,11 +18,11 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import exit_module, \ from ansible.module_utils.ca_common import exit_module, \
generate_ceph_cmd, \ generate_cmd, \
is_containerized is_containerized
except ImportError: except ImportError:
from module_utils.ca_common import exit_module, \ from module_utils.ca_common import exit_module, \
generate_ceph_cmd, \ generate_cmd, \
is_containerized is_containerized
import datetime import datetime
@ -97,10 +97,10 @@ def main():
container_image = is_containerized() container_image = is_containerized()
cmd = generate_ceph_cmd(['mgr', 'module'], cmd = generate_cmd(sub_cmd=['mgr', 'module'],
[state, name], args=[state, name],
cluster=cluster, cluster=cluster,
container_image=container_image) container_image=container_image)
if module.check_mode: if module.check_mode:
exit_module( exit_module(

View File

@ -17,9 +17,9 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import exit_module, generate_ceph_cmd, is_containerized # noqa: E501 from ansible.module_utils.ca_common import exit_module, generate_cmd, is_containerized # noqa: E501
except ImportError: except ImportError:
from module_utils.ca_common import exit_module, generate_ceph_cmd, is_containerized # noqa: E501 from module_utils.ca_common import exit_module, generate_cmd, is_containerized # noqa: E501
import datetime import datetime
@ -111,7 +111,7 @@ def main():
container_image = is_containerized() container_image = is_containerized()
cmd = generate_ceph_cmd(['osd', state], ids, cluster=cluster, container_image=container_image) # noqa: E501 cmd = generate_cmd(sub_cmd=['osd', state], args=ids, cluster=cluster, container_image=container_image) # noqa: E501
if state in ['destroy', 'purge']: if state in ['destroy', 'purge']:
cmd.append('--yes-i-really-mean-it') cmd.append('--yes-i-really-mean-it')

View File

@ -18,11 +18,11 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import exit_module, \ from ansible.module_utils.ca_common import exit_module, \
generate_ceph_cmd, \ generate_cmd, \
is_containerized is_containerized
except ImportError: except ImportError:
from module_utils.ca_common import exit_module, \ from module_utils.ca_common import exit_module, \
generate_ceph_cmd, \ generate_cmd, \
is_containerized is_containerized
import datetime import datetime
@ -99,9 +99,9 @@ def main():
container_image = is_containerized() container_image = is_containerized()
if state == 'present': if state == 'present':
cmd = generate_ceph_cmd(['osd', 'set'], [name], cluster=cluster, container_image=container_image) # noqa: E501 cmd = generate_cmd(sub_cmd=['osd', 'set'], args=[name], cluster=cluster, container_image=container_image) # noqa: E501
else: else:
cmd = generate_ceph_cmd(['osd', 'unset'], [name], cluster=cluster, container_image=container_image) # noqa: E501 cmd = generate_cmd(sub_cmd=['osd', 'unset'], args=[name], cluster=cluster, container_image=container_image) # noqa: E501
if module.check_mode: if module.check_mode:
exit_module( exit_module(

View File

@ -19,14 +19,14 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import generate_ceph_cmd, \ from ansible.module_utils.ca_common import generate_cmd, \
pre_generate_ceph_cmd, \ pre_generate_cmd, \
is_containerized, \ is_containerized, \
exec_command, \ exec_command, \
exit_module exit_module
except ImportError: except ImportError:
from module_utils.ca_common import generate_ceph_cmd, \ from module_utils.ca_common import generate_cmd, \
pre_generate_ceph_cmd, \ pre_generate_cmd, \
is_containerized, \ is_containerized, \
exec_command, \ exec_command, \
exit_module exit_module
@ -167,12 +167,12 @@ def check_pool_exist(cluster,
args = ['stats', name, '-f', output_format] args = ['stats', name, '-f', output_format]
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -182,7 +182,7 @@ def generate_get_config_cmd(param,
user, user,
user_key, user_key,
container_image=None): container_image=None):
_cmd = pre_generate_ceph_cmd(container_image=container_image) _cmd = pre_generate_cmd('ceph', container_image=container_image)
args = [ args = [
'-n', '-n',
user, user,
@ -211,12 +211,12 @@ def get_application_pool(cluster,
args = ['application', 'get', name, '-f', output_format] args = ['application', 'get', name, '-f', output_format]
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -233,12 +233,34 @@ def enable_application_pool(cluster,
args = ['application', 'enable', name, application] args = ['application', 'enable', name, application]
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
return cmd
def init_rbd_pool(cluster,
name,
user,
user_key,
container_image=None):
'''
Initialize a rbd pool
'''
args = [name]
cmd = generate_cmd(cmd='rbd',
sub_cmd=['pool', 'init'],
args=args,
cluster=cluster,
user=user,
user_key=user_key,
container_image=container_image)
return cmd return cmd
@ -256,12 +278,12 @@ def disable_application_pool(cluster,
args = ['application', 'disable', name, args = ['application', 'disable', name,
application, '--yes-i-really-mean-it'] application, '--yes-i-really-mean-it']
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -279,12 +301,12 @@ def get_pool_details(module,
args = ['ls', 'detail', '-f', output_format] args = ['ls', 'detail', '-f', output_format]
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
rc, cmd, out, err = exec_command(module, cmd) rc, cmd, out, err = exec_command(module, cmd)
@ -368,18 +390,17 @@ def list_pools(cluster,
args.extend(['-f', output_format]) args.extend(['-f', output_format])
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
return cmd return cmd
def create_pool(cluster, def create_pool(cluster,
name,
user, user,
user_key, user_key,
user_pool_config, user_pool_config,
@ -423,12 +444,12 @@ def create_pool(cluster,
'--autoscale-mode', '--autoscale-mode',
user_pool_config['pg_autoscale_mode']['value']]) user_pool_config['pg_autoscale_mode']['value']])
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -440,12 +461,12 @@ def remove_pool(cluster, name, user, user_key, container_image=None):
args = ['rm', name, name, '--yes-i-really-really-mean-it'] args = ['rm', name, name, '--yes-i-really-really-mean-it']
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
return cmd return cmd
@ -465,12 +486,12 @@ def update_pool(module, cluster, name,
delta[key]['cli_set_opt'], delta[key]['cli_set_opt'],
delta[key]['value']] delta[key]['value']]
cmd = generate_ceph_cmd(sub_cmd=['osd', 'pool'], cmd = generate_cmd(sub_cmd=['osd', 'pool'],
args=args, args=args,
cluster=cluster, cluster=cluster,
user=user, user=user,
user_key=user_key, user_key=user_key,
container_image=container_image) container_image=container_image)
rc, cmd, out, err = exec_command(module, cmd) rc, cmd, out, err = exec_command(module, cmd)
if rc != 0: if rc != 0:
@ -634,7 +655,6 @@ def run_module():
else: else:
rc, cmd, out, err = exec_command(module, rc, cmd, out, err = exec_command(module,
create_pool(cluster, create_pool(cluster,
name,
user, user,
user_key, user_key,
user_pool_config=user_pool_config, # noqa: E501 user_pool_config=user_pool_config, # noqa: E501
@ -647,6 +667,13 @@ def run_module():
user, user,
user_key, user_key,
container_image=container_image)) # noqa: E501 container_image=container_image)) # noqa: E501
if rc == 0 and user_pool_config['application']['value'] == 'rbd': # noqa: E501
rc, cmd, out, err = exec_command(module,
init_rbd_pool(cluster,
user_pool_config['pool_name']['value'], # noqa: E501
user,
user_key,
container_image=container_image)) # noqa: E501
if user_pool_config['min_size']['value']: if user_pool_config['min_size']['value']:
# not implemented yet # not implemented yet
pass pass

View File

@ -2,15 +2,22 @@ import os
import datetime import datetime
def generate_ceph_cmd(sub_cmd, args, user_key=None, cluster='ceph', user='client.admin', container_image=None, interactive=False): def generate_cmd(cmd='ceph',
sub_cmd=None,
args=None,
user_key=None,
cluster='ceph',
user='client.admin',
container_image=None,
interactive=False):
''' '''
Generate 'ceph' command line to execute Generate 'ceph' command line to execute
''' '''
if not user_key: if user_key is None:
user_key = '/etc/ceph/{}.{}.keyring'.format(cluster, user) user_key = '/etc/ceph/{}.{}.keyring'.format(cluster, user)
cmd = pre_generate_ceph_cmd(container_image=container_image, interactive=interactive) cmd = pre_generate_cmd(cmd, container_image=container_image, interactive=interactive) # noqa: E501
base_cmd = [ base_cmd = [
'-n', '-n',
@ -20,8 +27,11 @@ def generate_ceph_cmd(sub_cmd, args, user_key=None, cluster='ceph', user='client
'--cluster', '--cluster',
cluster cluster
] ]
base_cmd.extend(sub_cmd)
cmd.extend(base_cmd + args) if sub_cmd is not None:
base_cmd.extend(sub_cmd)
cmd.extend(base_cmd) if args is None else cmd.extend(base_cmd + args)
return cmd return cmd
@ -59,14 +69,14 @@ def is_containerized():
return container_image return container_image
def pre_generate_ceph_cmd(container_image=None, interactive=False): def pre_generate_cmd(cmd, container_image=None, interactive=False):
''' '''
Generate ceph prefix comaand Generate ceph prefix command
''' '''
if container_image: if container_image:
cmd = container_exec('ceph', container_image, interactive=interactive) cmd = container_exec(cmd, container_image, interactive=interactive)
else: else:
cmd = ['ceph'] cmd = [cmd]
return cmd return cmd
@ -84,7 +94,7 @@ def exec_command(module, cmd, stdin=None):
return rc, cmd, out, err return rc, cmd, out, err
def exit_module(module, out, rc, cmd, err, startd, changed=False, diff=dict(before="", after="")): def exit_module(module, out, rc, cmd, err, startd, changed=False, diff=dict(before="", after="")): # noqa: E501
endd = datetime.datetime.now() endd = datetime.datetime.now()
delta = endd - startd delta = endd - startd

View File

@ -62,7 +62,7 @@ class TestCephKeyModule(object):
'auth', 'auth',
'arg' 'arg'
] ]
result = ceph_key.generate_ceph_cmd( result = ceph_key.generate_cmd(
sub_cmd=['auth'], sub_cmd=['auth'],
args=fake_args, args=fake_args,
cluster=fake_cluster, cluster=fake_cluster,
@ -93,7 +93,7 @@ class TestCephKeyModule(object):
fake_cluster, fake_cluster,
'auth', 'auth',
'arg'] 'arg']
result = ceph_key.generate_ceph_cmd( result = ceph_key.generate_cmd(
sub_cmd=['auth'], sub_cmd=['auth'],
args=fake_args, args=fake_args,
cluster=fake_cluster, cluster=fake_cluster,

View File

@ -2,6 +2,7 @@ import os
import sys import sys
import ceph_pool import ceph_pool
from mock.mock import patch from mock.mock import patch
import pytest
sys.path.append('./library') sys.path.append('./library')
fake_user = 'client.admin' fake_user = 'client.admin'
@ -282,6 +283,53 @@ class TestCephPoolModule(object):
assert cmd == expected_command assert cmd == expected_command
@pytest.mark.parametrize("container_image", [None, fake_container_image_name])
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): def test_disable_application_pool(self):
expected_command = [ expected_command = [
'podman', 'podman',
@ -442,7 +490,6 @@ class TestCephPoolModule(object):
] ]
cmd = ceph_pool.create_pool(fake_cluster_name, cmd = ceph_pool.create_pool(fake_cluster_name,
self.fake_user_pool_config['pool_name']['value'],
fake_user, fake_user_key, self.fake_user_pool_config, fake_user, fake_user_key, self.fake_user_pool_config,
container_image=fake_container_image_name) container_image=fake_container_image_name)
@ -489,7 +536,6 @@ class TestCephPoolModule(object):
] ]
cmd = ceph_pool.create_pool(fake_cluster_name, cmd = ceph_pool.create_pool(fake_cluster_name,
self.fake_user_pool_config['pool_name']['value'],
fake_user, fake_user_key, fake_user, fake_user_key,
self.fake_user_pool_config, self.fake_user_pool_config,
container_image=fake_container_image_name) container_image=fake_container_image_name)
@ -535,7 +581,6 @@ class TestCephPoolModule(object):
] ]
cmd = ceph_pool.create_pool(fake_cluster_name, cmd = ceph_pool.create_pool(fake_cluster_name,
self.fake_user_pool_config['pool_name']['value'],
fake_user, fake_user_key, self.fake_user_pool_config, fake_user, fake_user_key, self.fake_user_pool_config,
container_image=fake_container_image_name) container_image=fake_container_image_name)
@ -583,7 +628,6 @@ class TestCephPoolModule(object):
] ]
cmd = ceph_pool.create_pool(fake_cluster_name, cmd = ceph_pool.create_pool(fake_cluster_name,
self.fake_user_pool_config['pool_name']['value'],
fake_user, fake_user_key, self.fake_user_pool_config, fake_user, fake_user_key, self.fake_user_pool_config,
container_image=fake_container_image_name) container_image=fake_container_image_name)

View File

@ -38,17 +38,17 @@ class TestCommon(object):
@pytest.mark.parametrize('image', [None, fake_container_image]) @pytest.mark.parametrize('image', [None, fake_container_image])
@patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
def test_pre_generate_ceph_cmd(self, image): def test_pre_generate_cmd(self, image):
if image: if image:
expected_cmd = self.fake_container_cmd expected_cmd = self.fake_container_cmd
else: else:
expected_cmd = [self.fake_binary] expected_cmd = [self.fake_binary]
assert ca_common.pre_generate_ceph_cmd(image) == expected_cmd assert ca_common.pre_generate_cmd(self.fake_binary, image) == expected_cmd # noqa: E501
@pytest.mark.parametrize('image', [None, fake_container_image]) @pytest.mark.parametrize('image', [None, fake_container_image])
@patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
def test_generate_ceph_cmd(self, image): def test_generate_cmd(self, image):
sub_cmd = ['osd', 'pool'] sub_cmd = ['osd', 'pool']
args = ['create', 'foo'] args = ['create', 'foo']
if image: if image:
@ -64,11 +64,11 @@ class TestCommon(object):
'osd', 'pool', 'osd', 'pool',
'create', 'foo' 'create', 'foo'
]) ])
assert ca_common.generate_ceph_cmd(sub_cmd, args, cluster=self.fake_cluster, container_image=image) == expected_cmd assert ca_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]) @pytest.mark.parametrize('image', [None, fake_container_image])
@patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
def test_generate_ceph_cmd_different_cluster_name(self, image): def test_generate_cmd_different_cluster_name(self, image):
sub_cmd = ['osd', 'pool'] sub_cmd = ['osd', 'pool']
args = ['create', 'foo'] args = ['create', 'foo']
if image: if image:
@ -84,12 +84,12 @@ class TestCommon(object):
'osd', 'pool', 'osd', 'pool',
'create', 'foo' 'create', 'foo'
]) ])
result = ca_common.generate_ceph_cmd(sub_cmd, args, cluster='foo', container_image=image) result = ca_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster='foo', container_image=image) # noqa: E501
assert result == expected_cmd assert result == expected_cmd
@pytest.mark.parametrize('image', [None, fake_container_image]) @pytest.mark.parametrize('image', [None, fake_container_image])
@patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
def test_generate_ceph_cmd_different_cluster_name_and_user(self, image): def test_generate_cmd_different_cluster_name_and_user(self, image):
sub_cmd = ['osd', 'pool'] sub_cmd = ['osd', 'pool']
args = ['create', 'foo'] args = ['create', 'foo']
if image: if image:
@ -105,12 +105,12 @@ class TestCommon(object):
'osd', 'pool', 'osd', 'pool',
'create', 'foo' 'create', 'foo'
]) ])
result = ca_common.generate_ceph_cmd(sub_cmd, args, cluster='foo', user='client.foo', container_image=image) result = ca_common.generate_cmd(sub_cmd=sub_cmd, args=args, cluster='foo', user='client.foo', container_image=image) # noqa: E501
assert result == expected_cmd assert result == expected_cmd
@pytest.mark.parametrize('image', [None, fake_container_image]) @pytest.mark.parametrize('image', [None, fake_container_image])
@patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
def test_generate_ceph_cmd_different_user(self, image): def test_generate_cmd_different_user(self, image):
sub_cmd = ['osd', 'pool'] sub_cmd = ['osd', 'pool']
args = ['create', 'foo'] args = ['create', 'foo']
if image: if image:
@ -126,7 +126,7 @@ class TestCommon(object):
'osd', 'pool', 'osd', 'pool',
'create', 'foo' 'create', 'foo'
]) ])
result = ca_common.generate_ceph_cmd(sub_cmd, args, user='client.foo', container_image=image) result = ca_common.generate_cmd(sub_cmd=sub_cmd, args=args, user='client.foo', container_image=image) # noqa: E501
assert result == expected_cmd assert result == expected_cmd
@pytest.mark.parametrize('stdin', [None, 'foo']) @pytest.mark.parametrize('stdin', [None, 'foo'])
@ -137,7 +137,7 @@ class TestCommon(object):
stdout = 'ceph version 1.2.3' stdout = 'ceph version 1.2.3'
fake_module.run_command.return_value = 0, stdout, stderr fake_module.run_command.return_value = 0, stdout, stderr
expected_cmd = [self.fake_binary, '--version'] expected_cmd = [self.fake_binary, '--version']
_rc, _cmd, _out, _err = ca_common.exec_command(fake_module, expected_cmd, stdin=stdin) _rc, _cmd, _out, _err = ca_common.exec_command(fake_module, expected_cmd, stdin=stdin) # noqa: E501
assert _rc == rc assert _rc == rc
assert _cmd == expected_cmd assert _cmd == expected_cmd
assert _err == stderr assert _err == stderr