2019-10-26 03:47:05 +08:00
|
|
|
import sys
|
2018-11-28 01:38:37 +08:00
|
|
|
import mock
|
|
|
|
import os
|
2020-04-01 04:51:55 +08:00
|
|
|
import pytest
|
2021-08-12 23:08:27 +08:00
|
|
|
import ca_test_common
|
2020-10-02 04:28:17 +08:00
|
|
|
sys.path.append('./library')
|
|
|
|
import ceph_volume # noqa: E402
|
2017-12-02 03:27:13 +08:00
|
|
|
|
|
|
|
|
2019-04-09 15:22:06 +08:00
|
|
|
# Python 3
|
|
|
|
try:
|
2021-08-12 23:08:27 +08:00
|
|
|
from unittest.mock import MagicMock, patch
|
2019-04-09 15:22:06 +08:00
|
|
|
except ImportError:
|
|
|
|
# Python 2
|
|
|
|
try:
|
2021-08-12 23:08:27 +08:00
|
|
|
from mock import MagicMock, patch
|
2019-04-09 15:22:06 +08:00
|
|
|
except ImportError:
|
|
|
|
print('You need the mock library installed on python2.x to run tests')
|
|
|
|
|
|
|
|
|
2021-11-30 16:52:59 +08:00
|
|
|
def get_mounts(mounts=None):
|
|
|
|
volumes = {}
|
|
|
|
volumes['/run/lock/lvm'] = '/run/lock/lvm:z'
|
|
|
|
volumes['/var/run/udev'] = '/var/run/udev:z'
|
|
|
|
volumes['/dev'] = '/dev'
|
|
|
|
volumes['/etc/ceph'] = '/etc/ceph:z'
|
|
|
|
volumes['/run/lvm'] = '/run/lvm'
|
|
|
|
volumes['/var/lib/ceph'] = '/var/lib/ceph:z'
|
|
|
|
volumes['/var/log/ceph'] = '/var/log/ceph:z'
|
|
|
|
if mounts is not None:
|
|
|
|
volumes.update(mounts)
|
|
|
|
|
|
|
|
return sum([['-v', '{}:{}'.format(src_dir, dst_dir)] for src_dir, dst_dir in volumes.items()], [])
|
|
|
|
|
|
|
|
|
|
|
|
def get_container_cmd(mounts=None):
|
|
|
|
|
|
|
|
return ['docker', 'run', '--rm', '--privileged',
|
|
|
|
'--net=host', '--ipc=host'] + \
|
|
|
|
get_mounts(mounts) + ['--entrypoint=ceph-volume']
|
2020-04-01 04:31:40 +08:00
|
|
|
|
|
|
|
|
2018-11-28 01:38:37 +08:00
|
|
|
@mock.patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': 'docker'})
|
2017-12-02 03:27:13 +08:00
|
|
|
class TestCephVolumeModule(object):
|
|
|
|
|
|
|
|
def test_data_no_vg(self):
|
|
|
|
result = ceph_volume.get_data("/dev/sda", None)
|
|
|
|
assert result == "/dev/sda"
|
|
|
|
|
|
|
|
def test_data_with_vg(self):
|
|
|
|
result = ceph_volume.get_data("data-lv", "data-vg")
|
|
|
|
assert result == "data-vg/data-lv"
|
|
|
|
|
|
|
|
def test_journal_no_vg(self):
|
|
|
|
result = ceph_volume.get_journal("/dev/sda1", None)
|
|
|
|
assert result == "/dev/sda1"
|
|
|
|
|
|
|
|
def test_journal_with_vg(self):
|
|
|
|
result = ceph_volume.get_journal("journal-lv", "journal-vg")
|
|
|
|
assert result == "journal-vg/journal-lv"
|
|
|
|
|
|
|
|
def test_db_no_vg(self):
|
|
|
|
result = ceph_volume.get_db("/dev/sda1", None)
|
|
|
|
assert result == "/dev/sda1"
|
|
|
|
|
|
|
|
def test_db_with_vg(self):
|
|
|
|
result = ceph_volume.get_db("db-lv", "db-vg")
|
|
|
|
assert result == "db-vg/db-lv"
|
|
|
|
|
|
|
|
def test_wal_no_vg(self):
|
|
|
|
result = ceph_volume.get_wal("/dev/sda1", None)
|
|
|
|
assert result == "/dev/sda1"
|
|
|
|
|
|
|
|
def test_wal_with_vg(self):
|
|
|
|
result = ceph_volume.get_wal("wal-lv", "wal-vg")
|
|
|
|
assert result == "wal-vg/wal-lv"
|
2018-10-04 01:52:42 +08:00
|
|
|
|
2018-11-08 17:02:37 +08:00
|
|
|
def test_container_exec(self):
|
2018-10-04 01:52:42 +08:00
|
|
|
fake_binary = "ceph-volume"
|
2020-09-04 22:50:26 +08:00
|
|
|
fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest"
|
2021-11-30 16:52:59 +08:00
|
|
|
expected_command_list = get_container_cmd() + [fake_container_image]
|
2018-10-04 01:52:42 +08:00
|
|
|
result = ceph_volume.container_exec(fake_binary, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_zap_osd_container(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda'}
|
2020-09-04 22:50:26 +08:00
|
|
|
fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest"
|
2021-11-30 16:52:59 +08:00
|
|
|
expected_command_list = get_container_cmd() + \
|
|
|
|
[fake_container_image,
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'zap',
|
|
|
|
'--destroy',
|
|
|
|
'/dev/sda']
|
2018-10-04 01:52:42 +08:00
|
|
|
result = ceph_volume.zap_devices(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_zap_osd(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda'}
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
2020-06-19 21:09:04 +08:00
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
2018-10-04 01:52:42 +08:00
|
|
|
'lvm',
|
|
|
|
'zap',
|
|
|
|
'--destroy',
|
|
|
|
'/dev/sda']
|
|
|
|
result = ceph_volume.zap_devices(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2019-01-17 07:50:08 +08:00
|
|
|
def test_zap_osd_fsid(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'osd_fsid': 'a_uuid'}
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
2020-06-19 21:09:04 +08:00
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
2019-01-17 07:50:08 +08:00
|
|
|
'lvm',
|
|
|
|
'zap',
|
|
|
|
'--destroy',
|
|
|
|
'--osd-fsid',
|
|
|
|
'a_uuid']
|
|
|
|
result = ceph_volume.zap_devices(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2021-07-09 17:07:08 +08:00
|
|
|
def test_zap_osd_id(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'osd_id': '123'}
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'zap',
|
|
|
|
'--destroy',
|
|
|
|
'--osd-id',
|
|
|
|
'123']
|
|
|
|
result = ceph_volume.zap_devices(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2018-10-04 01:52:42 +08:00
|
|
|
def test_activate_osd(self):
|
|
|
|
expected_command_list = ['ceph-volume',
|
2020-06-19 21:09:04 +08:00
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
2018-10-04 01:52:42 +08:00
|
|
|
'lvm',
|
|
|
|
'activate',
|
|
|
|
'--all']
|
|
|
|
result = ceph_volume.activate_osd()
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_list_osd(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'cluster': 'ceph', 'data': '/dev/sda'}
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'list',
|
|
|
|
'/dev/sda',
|
2020-04-01 04:31:40 +08:00
|
|
|
'--format=json']
|
2018-10-04 01:52:42 +08:00
|
|
|
result = ceph_volume.list_osd(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_list_osd_container(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'cluster': 'ceph', 'data': '/dev/sda'}
|
2020-09-04 22:50:26 +08:00
|
|
|
fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest"
|
2021-11-30 16:52:59 +08:00
|
|
|
expected_command_list = get_container_cmd(
|
|
|
|
{
|
|
|
|
'/var/lib/ceph': '/var/lib/ceph:ro'
|
|
|
|
}) + \
|
|
|
|
[fake_container_image,
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'list',
|
|
|
|
'/dev/sda',
|
|
|
|
'--format=json']
|
2018-10-04 01:52:42 +08:00
|
|
|
result = ceph_volume.list_osd(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2018-12-06 07:14:08 +08:00
|
|
|
def test_list_storage_inventory(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
2020-06-19 21:09:04 +08:00
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
2018-12-06 07:14:08 +08:00
|
|
|
'inventory',
|
|
|
|
'--format=json',
|
|
|
|
]
|
|
|
|
result = ceph_volume.list_storage_inventory(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_list_storage_inventory_container(self):
|
|
|
|
fake_module = MagicMock()
|
2020-09-04 22:50:26 +08:00
|
|
|
fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest"
|
2021-11-30 16:52:59 +08:00
|
|
|
expected_command_list = get_container_cmd() + \
|
|
|
|
[fake_container_image,
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'inventory',
|
|
|
|
'--format=json']
|
2018-12-06 07:14:08 +08:00
|
|
|
result = ceph_volume.list_storage_inventory(fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2020-10-02 04:28:17 +08:00
|
|
|
@pytest.mark.parametrize('objectstore', ['bluestore', 'filestore'])
|
2020-04-01 04:51:55 +08:00
|
|
|
def test_create_osd_container(self, objectstore):
|
2018-10-04 01:52:42 +08:00
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda',
|
2020-04-01 04:51:55 +08:00
|
|
|
'objectstore': objectstore,
|
2018-10-04 01:52:42 +08:00
|
|
|
'cluster': 'ceph', }
|
|
|
|
|
|
|
|
fake_action = "create"
|
2020-09-04 22:50:26 +08:00
|
|
|
fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest"
|
2021-11-30 16:52:59 +08:00
|
|
|
expected_command_list = get_container_cmd() + \
|
|
|
|
[fake_container_image,
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'create',
|
|
|
|
'--%s' % objectstore,
|
|
|
|
'--data',
|
|
|
|
'/dev/sda']
|
2018-10-04 01:52:42 +08:00
|
|
|
result = ceph_volume.prepare_or_create_osd(
|
|
|
|
fake_module, fake_action, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2020-10-02 04:28:17 +08:00
|
|
|
@pytest.mark.parametrize('objectstore', ['bluestore', 'filestore'])
|
2020-04-01 04:51:55 +08:00
|
|
|
def test_create_osd(self, objectstore):
|
2018-10-04 01:52:42 +08:00
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda',
|
2020-04-01 04:51:55 +08:00
|
|
|
'objectstore': objectstore,
|
2018-10-04 01:52:42 +08:00
|
|
|
'cluster': 'ceph', }
|
|
|
|
|
|
|
|
fake_container_image = None
|
|
|
|
fake_action = "create"
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'create',
|
2020-04-01 04:51:55 +08:00
|
|
|
'--%s' % objectstore,
|
2018-10-04 01:52:42 +08:00
|
|
|
'--data',
|
|
|
|
'/dev/sda']
|
|
|
|
result = ceph_volume.prepare_or_create_osd(
|
|
|
|
fake_module, fake_action, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2020-10-02 04:28:17 +08:00
|
|
|
@pytest.mark.parametrize('objectstore', ['bluestore', 'filestore'])
|
2020-04-01 04:51:55 +08:00
|
|
|
def test_prepare_osd_container(self, objectstore):
|
2018-10-04 01:52:42 +08:00
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda',
|
2020-04-01 04:51:55 +08:00
|
|
|
'objectstore': objectstore,
|
2018-10-04 01:52:42 +08:00
|
|
|
'cluster': 'ceph', }
|
|
|
|
|
|
|
|
fake_action = "prepare"
|
2020-09-04 22:50:26 +08:00
|
|
|
fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest"
|
2021-11-30 16:52:59 +08:00
|
|
|
expected_command_list = get_container_cmd() + \
|
|
|
|
[fake_container_image,
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'prepare',
|
|
|
|
'--%s' % objectstore,
|
|
|
|
'--data',
|
|
|
|
'/dev/sda']
|
2018-10-04 01:52:42 +08:00
|
|
|
result = ceph_volume.prepare_or_create_osd(
|
|
|
|
fake_module, fake_action, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2020-10-02 04:28:17 +08:00
|
|
|
@pytest.mark.parametrize('objectstore', ['bluestore', 'filestore'])
|
2020-04-01 04:51:55 +08:00
|
|
|
def test_prepare_osd(self, objectstore):
|
2018-10-04 01:52:42 +08:00
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda',
|
2020-04-01 04:51:55 +08:00
|
|
|
'objectstore': objectstore,
|
2018-10-04 01:52:42 +08:00
|
|
|
'cluster': 'ceph', }
|
|
|
|
|
|
|
|
fake_container_image = None
|
|
|
|
fake_action = "prepare"
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'prepare',
|
2020-04-01 04:51:55 +08:00
|
|
|
'--%s' % objectstore,
|
2018-10-04 01:52:42 +08:00
|
|
|
'--data',
|
|
|
|
'/dev/sda']
|
|
|
|
result = ceph_volume.prepare_or_create_osd(
|
|
|
|
fake_module, fake_action, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2020-10-02 04:28:17 +08:00
|
|
|
@pytest.mark.parametrize('objectstore', ['bluestore', 'filestore'])
|
2020-04-01 04:51:55 +08:00
|
|
|
def test_batch_osd_container(self, objectstore):
|
2018-10-04 01:52:42 +08:00
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda',
|
2020-04-01 04:51:55 +08:00
|
|
|
'objectstore': objectstore,
|
|
|
|
'block_db_size': '4096',
|
|
|
|
'journal_size': '4096',
|
2018-10-04 01:52:42 +08:00
|
|
|
'cluster': 'ceph',
|
|
|
|
'batch_devices': ["/dev/sda", "/dev/sdb"]}
|
|
|
|
|
2020-09-04 22:50:26 +08:00
|
|
|
fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest"
|
2021-11-30 16:52:59 +08:00
|
|
|
expected_command_list = get_container_cmd() + \
|
|
|
|
[fake_container_image,
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'batch',
|
|
|
|
'--%s' % objectstore,
|
|
|
|
'--yes',
|
|
|
|
'--prepare',
|
|
|
|
'--journal-size' if objectstore == 'filestore' else '--block-db-size', # noqa E501
|
|
|
|
'4096',
|
|
|
|
'/dev/sda',
|
|
|
|
'/dev/sdb']
|
2018-10-04 01:52:42 +08:00
|
|
|
result = ceph_volume.batch(
|
|
|
|
fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
2020-10-02 04:28:17 +08:00
|
|
|
@pytest.mark.parametrize('objectstore', ['bluestore', 'filestore'])
|
2020-04-01 04:51:55 +08:00
|
|
|
def test_batch_osd(self, objectstore):
|
2018-10-04 01:52:42 +08:00
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'data': '/dev/sda',
|
2020-04-01 04:51:55 +08:00
|
|
|
'objectstore': objectstore,
|
|
|
|
'block_db_size': '4096',
|
|
|
|
'journal_size': '4096',
|
2018-10-04 01:52:42 +08:00
|
|
|
'cluster': 'ceph',
|
|
|
|
'batch_devices': ["/dev/sda", "/dev/sdb"]}
|
|
|
|
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'batch',
|
2020-04-01 04:51:55 +08:00
|
|
|
'--%s' % objectstore,
|
2018-10-04 01:52:42 +08:00
|
|
|
'--yes',
|
2020-04-01 04:51:55 +08:00
|
|
|
'--journal-size' if objectstore == 'filestore' else '--block-db-size', # noqa E501
|
|
|
|
'4096',
|
2018-10-04 01:52:42 +08:00
|
|
|
'/dev/sda',
|
|
|
|
'/dev/sdb']
|
|
|
|
result = ceph_volume.batch(
|
|
|
|
fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
2020-02-29 02:59:22 +08:00
|
|
|
|
|
|
|
def test_batch_filestore_with_dedicated_journal(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'objectstore': 'filestore',
|
|
|
|
'journal_size': '100',
|
|
|
|
'cluster': 'ceph',
|
|
|
|
'batch_devices': ["/dev/sda", "/dev/sdb"],
|
2020-03-28 05:16:41 +08:00
|
|
|
'journal_devices': ["/dev/sdc", "/dev/sdd"]}
|
2020-02-29 02:59:22 +08:00
|
|
|
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'batch',
|
|
|
|
'--filestore',
|
|
|
|
'--yes',
|
|
|
|
'--journal-size',
|
|
|
|
'100',
|
|
|
|
'/dev/sda',
|
|
|
|
'/dev/sdb',
|
|
|
|
'--journal-devices',
|
2020-03-28 05:16:41 +08:00
|
|
|
'/dev/sdc',
|
|
|
|
'/dev/sdd']
|
|
|
|
result = ceph_volume.batch(
|
|
|
|
fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_batch_bluestore_with_dedicated_db(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'objectstore': 'bluestore',
|
|
|
|
'block_db_size': '-1',
|
|
|
|
'cluster': 'ceph',
|
|
|
|
'batch_devices': ["/dev/sda", "/dev/sdb"],
|
|
|
|
'block_db_devices': ["/dev/sdc", "/dev/sdd"]}
|
|
|
|
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'batch',
|
|
|
|
'--bluestore',
|
|
|
|
'--yes',
|
|
|
|
'/dev/sda',
|
|
|
|
'/dev/sdb',
|
|
|
|
'--db-devices',
|
|
|
|
'/dev/sdc',
|
|
|
|
'/dev/sdd']
|
|
|
|
result = ceph_volume.batch(
|
|
|
|
fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_batch_bluestore_with_dedicated_wal(self):
|
|
|
|
fake_module = MagicMock()
|
|
|
|
fake_module.params = {'objectstore': 'bluestore',
|
|
|
|
'cluster': 'ceph',
|
|
|
|
'block_db_size': '-1',
|
|
|
|
'batch_devices': ["/dev/sda", "/dev/sdb"],
|
|
|
|
'wal_devices': ["/dev/sdc", "/dev/sdd"]}
|
|
|
|
|
|
|
|
fake_container_image = None
|
|
|
|
expected_command_list = ['ceph-volume',
|
|
|
|
'--cluster',
|
|
|
|
'ceph',
|
|
|
|
'lvm',
|
|
|
|
'batch',
|
|
|
|
'--bluestore',
|
|
|
|
'--yes',
|
|
|
|
'/dev/sda',
|
|
|
|
'/dev/sdb',
|
|
|
|
'--wal-devices',
|
|
|
|
'/dev/sdc',
|
|
|
|
'/dev/sdd']
|
|
|
|
result = ceph_volume.batch(
|
|
|
|
fake_module, fake_container_image)
|
|
|
|
assert result == expected_command_list
|
2021-08-12 23:08:27 +08:00
|
|
|
|
|
|
|
@patch('ansible.module_utils.basic.AnsibleModule.exit_json')
|
|
|
|
@patch('ansible.module_utils.basic.AnsibleModule.run_command')
|
|
|
|
def test_prepare_no_keyring_in_output(self, m_run_command, m_exit_json):
|
|
|
|
ca_test_common.set_module_args({'data': '/dev/sda',
|
|
|
|
'objectstore': 'bluestore',
|
|
|
|
'cluster': 'ceph',
|
|
|
|
'action': 'prepare'})
|
|
|
|
keyring = 'AQBqkhNhQDlqEhAAXKxu87L3Mh3mHY+agonKZA=='
|
|
|
|
m_exit_json.side_effect = ca_test_common.exit_json
|
|
|
|
list_rc = 0
|
|
|
|
list_stderr = ''
|
|
|
|
list_stdout = '{}'
|
|
|
|
prepare_rc = 0
|
|
|
|
prepare_stderr = """
|
|
|
|
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 {}
|
|
|
|
stdout: creating /var/lib/ceph/osd/ceph-1/keyring
|
|
|
|
added entity osd.1 auth(key={})
|
|
|
|
""".format(keyring, keyring)
|
|
|
|
prepare_stdout = ''
|
|
|
|
m_run_command.side_effect = [
|
|
|
|
(list_rc, list_stdout, list_stderr),
|
|
|
|
(prepare_rc, prepare_stdout, prepare_stderr)
|
|
|
|
]
|
|
|
|
|
|
|
|
with pytest.raises(ca_test_common.AnsibleExitJson) as result:
|
|
|
|
ceph_volume.main()
|
|
|
|
|
|
|
|
result = result.value.args[0]
|
|
|
|
assert result['changed']
|
|
|
|
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']
|
|
|
|
assert not result['stdout']
|
|
|
|
|
|
|
|
@patch('ansible.module_utils.basic.AnsibleModule.exit_json')
|
|
|
|
@patch('ansible.module_utils.basic.AnsibleModule.run_command')
|
|
|
|
def test_batch_no_keyring_in_output(self, m_run_command, m_exit_json):
|
|
|
|
ca_test_common.set_module_args({'batch_devices': ['/dev/sda'],
|
|
|
|
'objectstore': 'bluestore',
|
|
|
|
'cluster': 'ceph',
|
|
|
|
'action': 'batch'})
|
|
|
|
keyring = 'AQBUixJhnDF1NRAAhl2xrnmOHCCI/T+W6FjqmA=='
|
|
|
|
m_exit_json.side_effect = ca_test_common.exit_json
|
|
|
|
report_rc = 0
|
|
|
|
report_stderr = ''
|
|
|
|
report_stdout = '[{"data": "/dev/sda", "data_size": "50.00 GB", "encryption": "None"}]'
|
|
|
|
batch_rc = 0
|
|
|
|
batch_stderr = """
|
|
|
|
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 {}
|
|
|
|
stdout: creating /var/lib/ceph/osd/ceph-0/keyring
|
|
|
|
added entity osd.0 auth(key={})
|
|
|
|
""".format(keyring, keyring)
|
|
|
|
batch_stdout = ''
|
|
|
|
m_run_command.side_effect = [
|
|
|
|
(report_rc, report_stdout, report_stderr),
|
|
|
|
(batch_rc, batch_stdout, batch_stderr)
|
|
|
|
]
|
|
|
|
|
|
|
|
with pytest.raises(ca_test_common.AnsibleExitJson) as result:
|
|
|
|
ceph_volume.main()
|
|
|
|
|
|
|
|
result = result.value.args[0]
|
|
|
|
assert result['changed']
|
|
|
|
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']
|
|
|
|
assert not result['stdout']
|