refactor ceph_volume.py so it's easier to test

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
pull/2245/head
Andrew Schoen 2017-12-01 13:26:36 -06:00 committed by Sébastien Han
parent 5e3d8dbf63
commit 4b4680d1e6
1 changed files with 28 additions and 9 deletions

View File

@ -105,6 +105,30 @@ EXAMPLES = '''
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
def get_data(data, data_vg):
if data_vg:
data = "{0}/{1}".format(data_vg, data)
return data
def get_journal(journal, journal_vg):
if journal_vg:
journal = "{0}/{1}".format(journal_vg, journal)
return journal
def get_db(db, db_vg):
if db_vg:
db = "{0}/{1}".format(db_vg, db)
return db
def get_wal(wal, wal_vg):
if wal_vg:
wal = "{0}/{1}".format(wal_vg, wal)
return wal
def run_module(): def run_module():
module_args = dict( module_args = dict(
cluster=dict(type='str', required=False, default='ceph'), cluster=dict(type='str', required=False, default='ceph'),
@ -147,24 +171,19 @@ def run_module():
'--data', '--data',
] ]
if data_vg: data = get_data(data, data_vg)
data = "{0}/{1}".format(data_vg, data)
cmd.append(data) cmd.append(data)
if journal: if journal:
if journal_vg: journal = get_journal(journal, journal_vg)
journal = "{0}/{1}".format(journal_vg, journal)
cmd.extend(["--journal", journal]) cmd.extend(["--journal", journal])
if db: if db:
if db_vg: db = get_db(db, db_vg)
db = "{0}/{1}".format(db_vg, db)
cmd.extend(["--block.db", db]) cmd.extend(["--block.db", db])
if wal: if wal:
if wal_vg: wal = get_wal(wal, wal_vg)
wal = "{0}/{1}".format(wal_vg, wal)
cmd.extend(["--block.wal", wal]) cmd.extend(["--block.wal", wal])
result = dict( result = dict(