From f2e57a56db2801818135ba85479fedfc00eae30c Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Mon, 25 Jun 2018 17:10:37 +0200 Subject: [PATCH] tests: factorize docker tests using docker_exec_cmd logic avoid duplicating test unnecessarily just because of docker exec syntax. Using the same logic than in the playbook with `docker_exec_cmd` allow us to execute the same test on both containerized and non containerized environment. The idea is to set a variable `docker_exec_cmd` with the 'docker exec ' string when containerized and set it to '' when non containerized. Signed-off-by: Guillaume Abrioux --- tests/functional/tests/mds/test_mds.py | 19 +++++--------- tests/functional/tests/mgr/test_mgr.py | 22 +++++----------- .../functional/tests/nfs/test_nfs_ganesha.py | 20 +++++--------- .../tests/rbd-mirror/test_rbd_mirror.py | 23 ++++++---------- tests/functional/tests/rgw/test_rgw.py | 26 ++++++------------- 5 files changed, 36 insertions(+), 74 deletions(-) diff --git a/tests/functional/tests/mds/test_mds.py b/tests/functional/tests/mds/test_mds.py index 834382177..716e4884b 100644 --- a/tests/functional/tests/mds/test_mds.py +++ b/tests/functional/tests/mds/test_mds.py @@ -19,21 +19,16 @@ class TestMDSs(object): ) assert host.service(service_name).is_enabled - @pytest.mark.no_docker def test_mds_is_up(self, node, host): hostname = node["vars"]["inventory_hostname"] - cmd = "sudo ceph --name client.bootstrap-mds --keyring /var/lib/ceph/bootstrap-mds/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format(cluster=node['cluster_name']) - cluster_status = json.loads(host.check_output(cmd)) + if node['docker']: + docker_exec_cmd = 'docker exec ceph-mds-{hostname}'.format(hostname=hostname) + else: + docker_exec_cmd = '' - assert (cluster_status['fsmap'].get('up', 0) + cluster_status['fsmap'].get('up:standby', 0)) == len(node["vars"]["groups"]["mdss"]) - - @pytest.mark.docker - def test_docker_mds_is_up(self, node, host): - hostname = node["vars"]["inventory_hostname"] - cmd = "sudo docker exec ceph-mds-{hostname} ceph --name client.bootstrap-mds --keyring /var/lib/ceph/bootstrap-mds/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( - hostname=node["vars"]["inventory_hostname"], - cluster=node["cluster_name"] + cmd = "sudo {docker_exec_cmd} ceph --name client.bootstrap-mds --keyring /var/lib/ceph/bootstrap-mds/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + docker_exec_cmd=docker_exec_cmd, + cluster=node['cluster_name'] ) cluster_status = json.loads(host.check_output(cmd)) - assert (cluster_status['fsmap'].get('up', 0) + cluster_status['fsmap'].get('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 488c7ccb9..a6e62c52b 100644 --- a/tests/functional/tests/mgr/test_mgr.py +++ b/tests/functional/tests/mgr/test_mgr.py @@ -19,25 +19,17 @@ class TestMGRs(object): ) assert host.service(service_name).is_enabled - @pytest.mark.no_docker def test_mgr_is_up(self, node, host): hostname=node["vars"]["inventory_hostname"] cluster=node["cluster_name"] - cmd = "sudo ceph --name mgr.{hostname} --keyring /var/lib/ceph/mgr/{cluster}-{hostname}/keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( - hostname=hostname, - cluster=cluster - ) - output = host.check_output(cmd) - daemons = json.loads(output)["mgrmap"]["active_name"] - assert hostname in daemons - - @pytest.mark.docker - def test_docker_mgr_is_up(self, node, host): - hostname=node["vars"]["inventory_hostname"] - cluster=node["cluster_name"] - cmd = "sudo docker exec ceph-mgr-{hostname} ceph --name mgr.{hostname} --keyring /var/lib/ceph/mgr/{cluster}-{hostname}/keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + if node['docker']: + docker_exec_cmd = 'docker exec ceph-mgr-{hostname}'.format(hostname=hostname) + else: + docker_exec_cmd = '' + cmd = "sudo {docker_exec_cmd} ceph --name mgr.{hostname} --keyring /var/lib/ceph/mgr/{cluster}-{hostname}/keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + docker_exec_cmd=docker_exec_cmd, hostname=node["vars"]["inventory_hostname"], - cluster=node["cluster_name"] + cluster=cluster ) output_raw = host.check_output(cmd) output_json = json.loads(output_raw) diff --git a/tests/functional/tests/nfs/test_nfs_ganesha.py b/tests/functional/tests/nfs/test_nfs_ganesha.py index 8136ff459..8ec9218ea 100644 --- a/tests/functional/tests/nfs/test_nfs_ganesha.py +++ b/tests/functional/tests/nfs/test_nfs_ganesha.py @@ -23,23 +23,15 @@ class TestNFSs(object): def test_nfs_config_override(self, node, host): assert host.file("/etc/ganesha/ganesha.conf").contains("Entries_HWMark") - @pytest.mark.no_docker def test_nfs_is_up(self, node, host): hostname = node["vars"]["inventory_hostname"] cluster = node['cluster_name'] - cmd = "sudo ceph --name client.rgw.{hostname} --keyring /var/lib/ceph/radosgw/{cluster}-rgw.{hostname}/keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( - hostname=hostname, - cluster=cluster - ) - output = host.check_output(cmd) - daemons = [i for i in json.loads(output)["servicemap"]["services"]["rgw-nfs"]["daemons"]] - assert hostname in daemons - - @pytest.mark.docker - def test_docker_nfs_is_up(self, node, host): - hostname = node["vars"]["inventory_hostname"] - cluster = node['cluster_name'] - cmd = "sudo docker exec ceph-nfs-{hostname} ceph --name client.rgw.{hostname} --keyring /var/lib/ceph/radosgw/{cluster}-rgw.{hostname}/keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + if node['docker']: + docker_exec_cmd = 'docker exec ceph-nfs-{hostname}'.format(hostname=hostname) + else: + docker_exec_cmd = '' + cmd = "sudo {docker_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( + docker_exec_cmd=docker_exec_cmd, hostname=hostname, cluster=cluster ) diff --git a/tests/functional/tests/rbd-mirror/test_rbd_mirror.py b/tests/functional/tests/rbd-mirror/test_rbd_mirror.py index e195f41e8..6b8d86f61 100644 --- a/tests/functional/tests/rbd-mirror/test_rbd_mirror.py +++ b/tests/functional/tests/rbd-mirror/test_rbd_mirror.py @@ -58,25 +58,18 @@ class TestRbdMirrors(object): ) assert host.service(service_name).is_enabled - @pytest.mark.no_docker @pytest.mark.from_luminous def test_rbd_mirror_is_up(self, node, host): + hostname=node["vars"]["inventory_hostname"] + cluster=node["cluster_name"] + if node['docker']: + docker_exec_cmd = 'docker exec ceph-rbd-mirror-{hostname}'.format(hostname=hostname) + else: + docker_exec_cmd = '' hostname = node["vars"]["inventory_hostname"] cluster = node['cluster_name'] - cmd = "sudo ceph --name client.bootstrap-rbd --keyring /var/lib/ceph/bootstrap-rbd/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( - hostname=hostname, - cluster=cluster - ) - output = host.check_output(cmd) - daemons = [i for i in json.loads(output)["servicemap"]["services"]["rbd-mirror"]["daemons"]] - assert hostname in daemons - - @pytest.mark.docker - @pytest.mark.from_luminous - def test_docker_rbd_mirror_is_up(self, node, host): - hostname = node["vars"]["inventory_hostname"] - cluster = node['cluster_name'] - cmd = "sudo docker exec ceph-rbd-mirror-{hostname} ceph --name client.bootstrap-rbd --keyring /var/lib/ceph/bootstrap-rbd/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + cmd = "sudo {docker_exec_cmd} ceph --name client.bootstrap-rbd --keyring /var/lib/ceph/bootstrap-rbd/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + docker_exec_cmd=docker_exec_cmd, hostname=hostname, cluster=cluster ) diff --git a/tests/functional/tests/rgw/test_rgw.py b/tests/functional/tests/rgw/test_rgw.py index ba34fd68c..69bd001f2 100644 --- a/tests/functional/tests/rgw/test_rgw.py +++ b/tests/functional/tests/rgw/test_rgw.py @@ -22,12 +22,16 @@ class TestRGWs(object): ) assert host.service(service_name).is_enabled - @pytest.mark.no_docker @pytest.mark.from_luminous def test_rgw_is_up(self, node, host): - hostname = node["vars"]["inventory_hostname"] - cluster = node['cluster_name'] - cmd = "sudo ceph --name client.bootstrap-rgw --keyring /var/lib/ceph/bootstrap-rgw/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + hostname=node["vars"]["inventory_hostname"] + cluster=node["cluster_name"] + if node['docker']: + docker_exec_cmd = 'docker exec ceph-rgw-{hostname}'.format(hostname=hostname) + else: + docker_exec_cmd = '' + cmd = "sudo {docker_exec_cmd} ceph --name client.bootstrap-rgw --keyring /var/lib/ceph/bootstrap-rgw/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( + docker_exec_cmd=docker_exec_cmd, hostname=hostname, cluster=cluster ) @@ -40,17 +44,3 @@ class TestRGWs(object): # rgw frontends ip_addr is configured on eth1 ip_addr = host.interface("eth1").addresses[0] assert host.socket("tcp://{ip_addr}:{port}".format(ip_addr=ip_addr, port=8080)).is_listening - - - @pytest.mark.docker - @pytest.mark.from_luminous - def test_docker_rgw_is_up(self, node, host): - hostname = node["vars"]["inventory_hostname"] - cluster = node['cluster_name'] - cmd = "sudo docker exec ceph-rgw-{hostname} ceph --name client.bootstrap-rgw --keyring /var/lib/ceph/bootstrap-rgw/{cluster}.keyring --cluster={cluster} --connect-timeout 5 -f json -s".format( - hostname=hostname, - cluster=cluster - ) - output = host.check_output(cmd) - daemons = [i for i in json.loads(output)["servicemap"]["services"]["rgw"]["daemons"]] - assert hostname in daemons