2016-10-28 03:39:12 +08:00
|
|
|
import pytest
|
2017-05-05 03:04:23 +08:00
|
|
|
import os
|
2016-10-28 03:39:12 +08:00
|
|
|
|
|
|
|
|
2023-01-20 18:07:31 +08:00
|
|
|
@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
|
|
|
|
|
|
|
|
|
2019-05-23 16:49:54 +08:00
|
|
|
def str_to_bool(val):
|
|
|
|
try:
|
|
|
|
val = val.lower()
|
|
|
|
except AttributeError:
|
|
|
|
val = str(val).lower()
|
|
|
|
if val == 'true':
|
|
|
|
return True
|
|
|
|
elif val == 'false':
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
raise ValueError("Invalid input value: %s" % val)
|
|
|
|
|
2020-10-04 16:32:45 +08:00
|
|
|
|
2019-02-18 21:59:18 +08:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def setup(host):
|
|
|
|
cluster_address = ""
|
|
|
|
osd_ids = []
|
|
|
|
osds = []
|
|
|
|
|
|
|
|
ansible_vars = host.ansible.get_variables()
|
|
|
|
ansible_facts = host.ansible("setup")
|
|
|
|
|
2023-01-20 18:07:31 +08:00
|
|
|
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}"
|
2019-02-18 21:59:18 +08:00
|
|
|
docker = ansible_vars.get("docker")
|
2020-04-03 03:58:11 +08:00
|
|
|
container_binary = ansible_vars.get("container_binary", "")
|
2019-02-18 21:59:18 +08:00
|
|
|
osd_auto_discovery = ansible_vars.get("osd_auto_discovery")
|
|
|
|
group_names = ansible_vars["group_names"]
|
|
|
|
|
2019-02-22 17:04:28 +08:00
|
|
|
ansible_distribution = ansible_facts["ansible_facts"]["ansible_distribution"]
|
|
|
|
|
2019-02-22 17:13:53 +08:00
|
|
|
if ansible_distribution == "CentOS":
|
|
|
|
public_interface = "eth1"
|
|
|
|
cluster_interface = "eth2"
|
|
|
|
else:
|
|
|
|
public_interface = "ens6"
|
|
|
|
cluster_interface = "ens7"
|
|
|
|
|
2019-02-18 21:59:18 +08:00
|
|
|
subnet = ".".join(ansible_vars["public_network"].split(".")[0:-1])
|
2020-03-28 00:56:26 +08:00
|
|
|
num_mons = len(ansible_vars["groups"].get('mons', []))
|
2019-02-18 21:59:18 +08:00
|
|
|
if osd_auto_discovery:
|
|
|
|
num_osds = 3
|
|
|
|
else:
|
|
|
|
num_osds = len(ansible_vars.get("devices", []))
|
|
|
|
if not num_osds:
|
|
|
|
num_osds = len(ansible_vars.get("lvm_volumes", []))
|
|
|
|
osds_per_device = ansible_vars.get("osds_per_device", 1)
|
|
|
|
num_osds = num_osds * osds_per_device
|
|
|
|
|
|
|
|
# If number of devices doesn't map to number of OSDs, allow tests to define
|
|
|
|
# that custom number, defaulting it to ``num_devices``
|
|
|
|
num_osds = ansible_vars.get('num_osds', num_osds)
|
|
|
|
cluster_name = ansible_vars.get("cluster", "ceph")
|
|
|
|
conf_path = "/etc/ceph/{}.conf".format(cluster_name)
|
|
|
|
if "osds" in group_names:
|
|
|
|
cluster_address = host.interface(cluster_interface).addresses[0]
|
|
|
|
cmd = host.run('sudo ls /var/lib/ceph/osd/ | sed "s/.*-//"')
|
|
|
|
if cmd.rc == 0:
|
|
|
|
osd_ids = cmd.stdout.rstrip("\n").split("\n")
|
|
|
|
osds = osd_ids
|
|
|
|
|
|
|
|
address = host.interface(public_interface).addresses[0]
|
|
|
|
|
2020-04-03 03:58:11 +08:00
|
|
|
if docker and not container_binary:
|
2019-02-18 21:59:18 +08:00
|
|
|
container_binary = "podman"
|
|
|
|
|
|
|
|
data = dict(
|
|
|
|
cluster_name=cluster_name,
|
2023-01-20 18:07:31 +08:00
|
|
|
containerized_deployment=containerized_deployment,
|
|
|
|
container_image=container_image,
|
2019-02-18 21:59:18 +08:00
|
|
|
subnet=subnet,
|
|
|
|
osd_ids=osd_ids,
|
|
|
|
num_mons=num_mons,
|
|
|
|
num_osds=num_osds,
|
|
|
|
address=address,
|
|
|
|
osds=osds,
|
|
|
|
conf_path=conf_path,
|
2019-02-22 17:13:53 +08:00
|
|
|
public_interface=public_interface,
|
|
|
|
cluster_interface=cluster_interface,
|
2019-02-18 21:59:18 +08:00
|
|
|
cluster_address=cluster_address,
|
|
|
|
container_binary=container_binary)
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
2020-10-04 16:32:45 +08:00
|
|
|
|
2016-12-03 22:07:09 +08:00
|
|
|
@pytest.fixture()
|
2017-08-22 02:07:43 +08:00
|
|
|
def node(host, request):
|
2016-12-06 23:54:50 +08:00
|
|
|
"""
|
|
|
|
This fixture represents a single node in the ceph cluster. Using the
|
2018-03-29 18:19:29 +08:00
|
|
|
host.ansible fixture provided by testinfra it can access all the ansible
|
|
|
|
variables provided to it by the specific test scenario being ran.
|
2016-12-06 23:54:50 +08:00
|
|
|
|
2018-03-29 18:19:29 +08:00
|
|
|
You must include this fixture on any tests that operate on specific type
|
|
|
|
of node because it contains the logic to manage which tests a node
|
|
|
|
should run.
|
2016-12-06 23:54:50 +08:00
|
|
|
"""
|
2017-08-22 02:07:43 +08:00
|
|
|
ansible_vars = host.ansible.get_variables()
|
2017-05-05 03:04:23 +08:00
|
|
|
# tox will pass in this environment variable. we need to do it this way
|
|
|
|
# because testinfra does not collect and provide ansible config passed in
|
|
|
|
# from using --extra-vars
|
2021-09-29 22:25:42 +08:00
|
|
|
ceph_stable_release = os.environ.get("CEPH_STABLE_RELEASE", "quincy")
|
2018-07-18 17:07:49 +08:00
|
|
|
rolling_update = os.environ.get("ROLLING_UPDATE", "False")
|
2018-06-20 19:44:08 +08:00
|
|
|
group_names = ansible_vars["group_names"]
|
2016-12-08 09:17:09 +08:00
|
|
|
docker = ansible_vars.get("docker")
|
2019-07-13 02:56:01 +08:00
|
|
|
dashboard = ansible_vars.get("dashboard_enabled", True)
|
2019-01-25 18:05:55 +08:00
|
|
|
radosgw_num_instances = ansible_vars.get("radosgw_num_instances", 1)
|
2022-08-02 05:12:13 +08:00
|
|
|
ceph_rbd_mirror_remote_user = ansible_vars.get('ceph_rbd_mirror_remote_user', '')
|
2017-10-11 22:21:52 +08:00
|
|
|
ceph_release_num = {
|
2018-03-29 18:19:29 +08:00
|
|
|
'jewel': 10,
|
|
|
|
'kraken': 11,
|
|
|
|
'luminous': 12,
|
|
|
|
'mimic': 13,
|
2019-04-09 15:49:03 +08:00
|
|
|
'nautilus': 14,
|
|
|
|
'octopus': 15,
|
2020-03-24 02:22:46 +08:00
|
|
|
'pacific': 16,
|
2021-02-02 06:39:07 +08:00
|
|
|
'quincy': 17,
|
2022-10-07 16:49:00 +08:00
|
|
|
'reef': 18,
|
2024-02-16 18:13:30 +08:00
|
|
|
'squid': 19,
|
2018-03-29 18:19:29 +08:00
|
|
|
'dev': 99
|
2017-10-11 22:21:52 +08:00
|
|
|
}
|
2016-12-03 22:07:09 +08:00
|
|
|
|
2024-01-16 05:27:17 +08:00
|
|
|
sanitized_group_names = group_names
|
|
|
|
if 'all' in sanitized_group_names:
|
|
|
|
sanitized_group_names.remove('all')
|
|
|
|
|
2018-06-20 19:44:08 +08:00
|
|
|
# capture the initial/default state
|
|
|
|
test_is_applicable = False
|
|
|
|
for marker in request.node.iter_markers():
|
|
|
|
if marker.name in group_names or marker.name == 'all':
|
|
|
|
test_is_applicable = True
|
|
|
|
break
|
2018-11-19 18:09:30 +08:00
|
|
|
# Check if any markers on the test method exist in the nodes group_names.
|
|
|
|
# If they do not, this test is not valid for the node being tested.
|
2018-06-20 19:44:08 +08:00
|
|
|
if not test_is_applicable:
|
2018-11-19 18:09:30 +08:00
|
|
|
reason = "%s: Not a valid test for node type: %s" % (
|
|
|
|
request.function, group_names)
|
2018-06-20 19:44:08 +08:00
|
|
|
pytest.skip(reason)
|
|
|
|
|
2022-08-02 05:12:13 +08:00
|
|
|
if request.node.get_closest_marker('rbdmirror_secondary') and not ceph_rbd_mirror_remote_user: # noqa E501
|
|
|
|
pytest.skip('Not a valid test for a non-secondary rbd-mirror node')
|
|
|
|
|
2024-06-17 22:35:10 +08:00
|
|
|
if request.node.get_closest_marker('ceph_crash') and sanitized_group_names in [['nfss'], ['clients'], ['monitoring']]:
|
|
|
|
pytest.skip('Not a valid test for nfs or client nodes')
|
2020-07-03 16:21:49 +08:00
|
|
|
|
2024-06-17 22:35:10 +08:00
|
|
|
if request.node.get_closest_marker('ceph_exporter') and sanitized_group_names in [['nfss'], ['clients'], ['monitoring']]:
|
|
|
|
pytest.skip('Not a valid test for nfs or client nodes')
|
2024-03-04 09:03:19 +08:00
|
|
|
|
2018-06-20 19:44:08 +08:00
|
|
|
if request.node.get_closest_marker("no_docker") and docker:
|
2018-03-29 18:19:29 +08:00
|
|
|
pytest.skip(
|
|
|
|
"Not a valid test for containerized deployments or atomic hosts")
|
2016-12-08 09:17:09 +08:00
|
|
|
|
2018-06-20 19:44:08 +08:00
|
|
|
if request.node.get_closest_marker("docker") and not docker:
|
2018-03-29 18:19:29 +08:00
|
|
|
pytest.skip(
|
|
|
|
"Not a valid test for non-containerized deployments or atomic hosts") # noqa E501
|
2017-05-01 23:45:03 +08:00
|
|
|
|
2019-07-13 02:56:01 +08:00
|
|
|
if request.node.get_closest_marker("dashboard") and not dashboard:
|
|
|
|
pytest.skip(
|
|
|
|
"Not a valid test with dashboard disabled")
|
2019-01-30 21:16:19 +08:00
|
|
|
|
2024-01-16 05:27:17 +08:00
|
|
|
if request.node.get_closest_marker("dashboard") and sanitized_group_names == ['clients']:
|
2020-09-14 21:14:24 +08:00
|
|
|
pytest.skip('Not a valid test for client node')
|
|
|
|
|
2016-12-04 10:01:30 +08:00
|
|
|
data = dict(
|
2016-12-06 23:58:01 +08:00
|
|
|
vars=ansible_vars,
|
2016-12-08 09:17:09 +08:00
|
|
|
docker=docker,
|
2017-05-05 03:04:23 +08:00
|
|
|
ceph_stable_release=ceph_stable_release,
|
tests: add mimic support for test_rbd_mirror_is_up()
prior mimic, the data structure returned by `ceph -s -f json` used to
gather information about rbd-mirror daemons looked like below:
```
"servicemap": {
"epoch": 8,
"modified": "2018-07-05 13:21:06.207483",
"services": {
"rbd-mirror": {
"daemons": {
"summary": "",
"ceph-nano-luminous-faa32aebf00b": {
"start_epoch": 8,
"start_stamp": "2018-07-05 13:21:04.668450",
"gid": 14107,
"addr": "172.17.0.2:0/2229952892",
"metadata": {
"arch": "x86_64",
"ceph_version": "ceph version 12.2.5 (cad919881333ac92274171586c827e01f554a70a) luminous (stable)",
"cpu": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
"distro": "centos",
"distro_description": "CentOS Linux 7 (Core)",
"distro_version": "7",
"hostname": "ceph-nano-luminous-faa32aebf00b",
"instance_id": "14107",
"kernel_description": "#1 SMP Wed Mar 14 15:12:16 UTC 2018",
"kernel_version": "4.9.87-linuxkit-aufs",
"mem_swap_kb": "1048572",
"mem_total_kb": "2046652",
"os": "Linux"
}
}
}
}
}
}
```
This part has changed from mimic and became:
```
"servicemap": {
"epoch": 2,
"modified": "2018-07-04 09:54:36.164786",
"services": {
"rbd-mirror": {
"daemons": {
"summary": "",
"14151": {
"start_epoch": 2,
"start_stamp": "2018-07-04 09:54:35.541272",
"gid": 14151,
"addr": "192.168.1.80:0/240942528",
"metadata": {
"arch": "x86_64",
"ceph_release": "mimic",
"ceph_version": "ceph version 13.2.0 (79a10589f1f80dfe21e8f9794365ed98143071c4) mimic (stable)",
"ceph_version_short": "13.2.0",
"cpu": "Intel(R) Xeon(R) CPU X5650 @ 2.67GHz",
"distro": "centos",
"distro_description": "CentOS Linux 7 (Core)",
"distro_version": "7",
"hostname": "ceph-rbd-mirror0",
"id": "ceph-rbd-mirror0",
"instance_id": "14151",
"kernel_description": "#1 SMP Wed May 9 18:05:47 UTC 2018",
"kernel_version": "3.10.0-862.2.3.el7.x86_64",
"mem_swap_kb": "1572860",
"mem_total_kb": "1015548",
"os": "Linux"
}
}
}
}
}
}
```
This patch modifies the function `test_rbd_mirror_is_up()` in
`test_rbd_mirror.py` so it works with `mimic` and keeps backward compatibility
with `luminous`
Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
2018-07-05 21:16:19 +08:00
|
|
|
ceph_release_num=ceph_release_num,
|
2018-07-18 17:07:49 +08:00
|
|
|
rolling_update=rolling_update,
|
2019-01-25 18:05:55 +08:00
|
|
|
radosgw_num_instances=radosgw_num_instances,
|
2016-12-04 10:01:30 +08:00
|
|
|
)
|
|
|
|
return data
|
|
|
|
|
2016-12-03 22:07:09 +08:00
|
|
|
|
|
|
|
def pytest_collection_modifyitems(session, config, items):
|
|
|
|
for item in items:
|
|
|
|
test_path = item.location[0]
|
|
|
|
if "mon" in test_path:
|
|
|
|
item.add_marker(pytest.mark.mons)
|
|
|
|
elif "osd" in test_path:
|
|
|
|
item.add_marker(pytest.mark.osds)
|
|
|
|
elif "mds" in test_path:
|
|
|
|
item.add_marker(pytest.mark.mdss)
|
2017-09-17 17:16:54 +08:00
|
|
|
elif "mgr" in test_path:
|
|
|
|
item.add_marker(pytest.mark.mgrs)
|
|
|
|
elif "rbd-mirror" in test_path:
|
|
|
|
item.add_marker(pytest.mark.rbdmirrors)
|
2016-12-03 22:07:09 +08:00
|
|
|
elif "rgw" in test_path:
|
|
|
|
item.add_marker(pytest.mark.rgws)
|
2024-06-17 22:35:10 +08:00
|
|
|
elif "nfs" in test_path:
|
|
|
|
item.add_marker(pytest.mark.nfss)
|
2021-09-09 22:01:47 +08:00
|
|
|
elif "grafana" in test_path:
|
|
|
|
item.add_marker(pytest.mark.grafanas)
|
2016-12-03 22:07:09 +08:00
|
|
|
else:
|
|
|
|
item.add_marker(pytest.mark.all)
|
2016-12-06 06:21:52 +08:00
|
|
|
|
|
|
|
if "journal_collocation" in test_path:
|
|
|
|
item.add_marker(pytest.mark.journal_collocation)
|