From: Guillaume Abrioux Date: Fri, 20 Jan 2023 10:07:31 +0000 (+0100) Subject: tests: introduce `ceph_status` fixture X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0e086c4c61c7987a88126a8c0d9e104abaab1da7;p=ceph-ansible.git tests: introduce `ceph_status` fixture This avoids some duplicated code in various test_*_is_up() tests Signed-off-by: Guillaume Abrioux --- diff --git a/tests/conftest.py b/tests/conftest.py index 70e2345db..89194b022 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,28 @@ import pytest import os +@pytest.fixture +def ceph_status(host, setup): + def _run(keyring, + name=None, + cluster='ceph', + container_binary='podman'): + containerized_deployment = setup["containerized_deployment"] + container_image = setup["container_image"] + client_name = '' + if name is not None: + client_name = f'-n {name}' + ceph_args = f"--connect-timeout 5 {client_name} -k {keyring} --cluster {cluster} -f json -s" + + if containerized_deployment: + cmd = f"sudo {container_binary} run --rm -v /etc/ceph:/etc/ceph -v {keyring}:{keyring}:z --entrypoint=ceph {container_image} {ceph_args}" + else: + cmd = f"ceph {ceph_args}" + output = host.check_output(cmd) + return output + return _run + + def str_to_bool(val): try: val = val.lower() @@ -24,6 +46,11 @@ def setup(host): ansible_vars = host.ansible.get_variables() ansible_facts = host.ansible("setup") + containerized_deployment = ansible_vars.get("containerized_deployment", False) + ceph_docker_registry = ansible_vars.get("ceph_docker_registry") + ceph_docker_image = ansible_vars.get("ceph_docker_image") + ceph_docker_image_tag = ansible_vars.get("ceph_docker_image_tag") + container_image = f"{ceph_docker_registry}/{ceph_docker_image}:{ceph_docker_image_tag}" docker = ansible_vars.get("docker") container_binary = ansible_vars.get("container_binary", "") osd_auto_discovery = ansible_vars.get("osd_auto_discovery") @@ -68,6 +95,8 @@ def setup(host): data = dict( cluster_name=cluster_name, + containerized_deployment=containerized_deployment, + container_image=container_image, subnet=subnet, osd_ids=osd_ids, num_mons=num_mons, diff --git a/tests/functional/tests/mds/test_mds.py b/tests/functional/tests/mds/test_mds.py index 0da32c3d2..2e1da220a 100644 --- a/tests/functional/tests/mds/test_mds.py +++ b/tests/functional/tests/mds/test_mds.py @@ -16,19 +16,10 @@ class TestMDSs(object): assert s.is_enabled assert s.is_running - def test_mds_is_up(self, node, host, setup): - hostname = node["vars"]["inventory_hostname"] - container_binary = setup['container_binary'] - if node["docker"]: - container_exec_cmd = '{container_binary} exec ceph-mds-{hostname}'.format( # noqa E501 - hostname=hostname, container_binary=container_binary) - else: - container_exec_cmd = '' - - cmd = "sudo {container_exec_cmd} ceph --name client.bootstrap-mds --keyring /var/lib/ceph/bootstrap-mds/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( # noqa E501 - container_exec_cmd=container_exec_cmd, - cluster=setup['cluster_name'] - ) - cluster_status = json.loads(host.check_output(cmd)) + def test_mds_is_up(self, node, setup, ceph_status): + cluster = setup["cluster_name"] + name = 'client.bootstrap-mds' + output = ceph_status(f'/var/lib/ceph/bootstrap-mds/{cluster}.keyring', name=name) + cluster_status = json.loads(output) assert (cluster_status['fsmap'].get('up', 0) + cluster_status['fsmap'].get( # noqa E501 'up:standby', 0)) == len(node["vars"]["groups"]["mdss"]) diff --git a/tests/functional/tests/mgr/test_mgr.py b/tests/functional/tests/mgr/test_mgr.py index 49f28729a..a14fed669 100644 --- a/tests/functional/tests/mgr/test_mgr.py +++ b/tests/functional/tests/mgr/test_mgr.py @@ -29,21 +29,11 @@ class TestMGRs(object): s = host.socket('tcp://%s:%s' % (setup["address"], port)) assert s.is_listening - def test_mgr_is_up(self, node, host, setup): + def test_mgr_is_up(self, node, setup, ceph_status): hostname = node["vars"]["inventory_hostname"] cluster = setup["cluster_name"] - container_binary = setup["container_binary"] - if node['docker']: - container_exec_cmd = '{container_binary} exec ceph-mgr-{hostname}'.format( # noqa E501 - hostname=hostname, container_binary=container_binary) - else: - container_exec_cmd = '' - cmd = "sudo {container_exec_cmd} ceph --name mgr.{hostname} --keyring /var/lib/ceph/mgr/{cluster}-{hostname}/keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( # noqa E501 - container_exec_cmd=container_exec_cmd, - hostname=node["vars"]["inventory_hostname"], - cluster=cluster - ) - output_raw = host.check_output(cmd) + name = f"mgr.{hostname}" + output_raw = ceph_status(f'/var/lib/ceph/mgr/{cluster}-{hostname}/keyring', name=name) output_json = json.loads(output_raw) assert output_json['mgrmap']['available'] diff --git a/tests/functional/tests/nfs/test_nfs_ganesha.py b/tests/functional/tests/nfs/test_nfs_ganesha.py index 2b8c0c035..fda75adf7 100644 --- a/tests/functional/tests/nfs/test_nfs_ganesha.py +++ b/tests/functional/tests/nfs/test_nfs_ganesha.py @@ -23,21 +23,11 @@ class TestNFSs(object): assert host.file( "/etc/ganesha/ganesha.conf").contains("Entries_HWMark") - def test_nfs_is_up(self, node, host, setup): + def test_nfs_is_up(self, node, setup, ceph_status): hostname = node["vars"]["inventory_hostname"] - cluster = setup['cluster_name'] - container_binary = setup["container_binary"] - if node['docker']: - container_exec_cmd = '{container_binary} exec ceph-nfs-{hostname}'.format( # noqa E501 - hostname=hostname, container_binary=container_binary) - else: - container_exec_cmd = '' - cmd = "sudo {container_exec_cmd} ceph --name client.rgw.{hostname} --keyring /var/lib/ceph/radosgw/{cluster}-rgw.{hostname}/keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( # noqa E501 - container_exec_cmd=container_exec_cmd, - hostname=hostname, - cluster=cluster - ) - output = host.check_output(cmd) + cluster = setup["cluster_name"] + name = f"client.rgw.{hostname}" + output = ceph_status(f'/var/lib/ceph/radosgw/{cluster}-rgw.{hostname}/keyring', name=name) keys = list(json.loads( output)["servicemap"]["services"]["rgw-nfs"]["daemons"].keys()) keys.remove('summary') diff --git a/tests/functional/tests/rbd-mirror/test_rbd_mirror.py b/tests/functional/tests/rbd-mirror/test_rbd_mirror.py index eb5b74981..12af2e170 100644 --- a/tests/functional/tests/rbd-mirror/test_rbd_mirror.py +++ b/tests/functional/tests/rbd-mirror/test_rbd_mirror.py @@ -19,27 +19,14 @@ class TestRbdMirrors(object): assert s.is_running @pytest.mark.rbdmirror_secondary - def test_rbd_mirror_is_up(self, node, host, setup): + def test_rbd_mirror_is_up(self, node, setup, ceph_status): hostname = node["vars"]["inventory_hostname"] cluster = setup["cluster_name"] - container_binary = setup["container_binary"] - daemons = [] - if node['docker']: - container_exec_cmd = '{container_binary} exec ceph-rbd-mirror-{hostname}'.format( # noqa E501 - hostname=hostname, container_binary=container_binary) - else: - container_exec_cmd = '' - hostname = node["vars"]["inventory_hostname"] - cluster = setup['cluster_name'] - cmd = "sudo {container_exec_cmd} ceph --name client.bootstrap-rbd-mirror --keyring /var/lib/ceph/bootstrap-rbd-mirror/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( # noqa E501 - container_exec_cmd=container_exec_cmd, - hostname=hostname, - cluster=cluster - ) - output = host.check_output(cmd) + output = ceph_status(f'/var/lib/ceph/bootstrap-rbd-mirror/{cluster}.keyring') status = json.loads(output) daemon_ids = [i for i in status["servicemap"]["services"] ["rbd-mirror"]["daemons"].keys() if i != "summary"] + daemons = [] for daemon_id in daemon_ids: daemons.append(status["servicemap"]["services"]["rbd-mirror"] ["daemons"][daemon_id]["metadata"]["hostname"]) diff --git a/tests/functional/tests/rgw/test_rgw.py b/tests/functional/tests/rgw/test_rgw.py index 07cadd705..8a45be0c7 100644 --- a/tests/functional/tests/rgw/test_rgw.py +++ b/tests/functional/tests/rgw/test_rgw.py @@ -21,21 +21,11 @@ class TestRGWs(object): assert s.is_enabled assert s.is_running - def test_rgw_is_up(self, node, host, setup): + def test_rgw_is_up(self, node, setup, ceph_status): hostname = node["vars"]["inventory_hostname"] cluster = setup["cluster_name"] - container_binary = setup["container_binary"] - if node['docker']: - container_exec_cmd = '{container_binary} exec ceph-rgw-{hostname}-rgw0'.format( # noqa E501 - hostname=hostname, container_binary=container_binary) - else: - container_exec_cmd = '' - cmd = "sudo {container_exec_cmd} ceph --name client.bootstrap-rgw --keyring /var/lib/ceph/bootstrap-rgw/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( # noqa E501 - container_exec_cmd=container_exec_cmd, - hostname=hostname, - cluster=cluster - ) - output = host.check_output(cmd) + name = "client.bootstrap-rgw" + output = ceph_status(f'/var/lib/ceph/bootstrap-rgw/{cluster}.keyring', name=name) keys = list(json.loads( output)["servicemap"]["services"]["rgw"]["daemons"].keys()) keys.remove('summary') @@ -43,6 +33,7 @@ class TestRGWs(object): hostnames = [] for key in keys: hostnames.append(daemons[key]['metadata']['hostname']) + assert hostname in hostnames @pytest.mark.no_docker def test_rgw_http_endpoint(self, node, host, setup):