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
|
|
|
|
|
|
|
|
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
|
2017-08-22 02:07:43 +08:00
|
|
|
host.ansible fixture provided by testinfra it can access all the ansible variables
|
2016-12-06 23:54:50 +08:00
|
|
|
provided to it by the specific test scenario being ran.
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
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
|
|
|
|
ceph_stable_release = os.environ.get("CEPH_STABLE_RELEASE", "kraken")
|
2016-12-06 23:58:01 +08:00
|
|
|
node_type = ansible_vars["group_names"][0]
|
2016-12-08 09:17:09 +08:00
|
|
|
docker = ansible_vars.get("docker")
|
2017-08-22 02:07:43 +08:00
|
|
|
lvm_scenario = ansible_vars.get("osd_scenario") == 'lvm'
|
2016-12-06 00:07:04 +08:00
|
|
|
if not request.node.get_marker(node_type) and not request.node.get_marker('all'):
|
2016-12-07 00:50:54 +08:00
|
|
|
pytest.skip("Not a valid test for node type: %s" % node_type)
|
2016-12-03 22:07:09 +08:00
|
|
|
|
2017-08-31 20:48:24 +08:00
|
|
|
if request.node.get_marker("no_lvm_scenario") and lvm_scenario:
|
|
|
|
pytest.skip("Not a valid test for lvm scenarios")
|
|
|
|
|
2017-08-22 02:07:43 +08:00
|
|
|
if not lvm_scenario and request.node.get_marker("lvm_scenario"):
|
|
|
|
pytest.skip("Not a valid test for non-lvm scenarios")
|
|
|
|
|
2016-12-08 09:17:09 +08:00
|
|
|
if request.node.get_marker("no_docker") and docker:
|
|
|
|
pytest.skip("Not a valid test for containerized deployments or atomic hosts")
|
|
|
|
|
2017-05-01 23:45:03 +08:00
|
|
|
if request.node.get_marker("docker") and not docker:
|
|
|
|
pytest.skip("Not a valid test for non-containerized deployments or atomic hosts")
|
|
|
|
|
2017-05-05 03:04:23 +08:00
|
|
|
if node_type == "mgrs" and ceph_stable_release == "jewel":
|
|
|
|
pytest.skip("mgr nodes can not be tested with ceph release jewel")
|
|
|
|
|
2017-07-27 23:05:59 +08:00
|
|
|
journal_collocation_test = ansible_vars.get("osd_scenario") == "collocated"
|
2016-12-07 04:13:50 +08:00
|
|
|
if request.node.get_marker("journal_collocation") and not journal_collocation_test:
|
2016-12-07 00:50:54 +08:00
|
|
|
pytest.skip("Scenario is not using journal collocation")
|
2016-12-06 06:21:52 +08:00
|
|
|
|
2016-12-06 05:03:44 +08:00
|
|
|
osd_ids = []
|
2016-12-08 09:24:40 +08:00
|
|
|
osds = []
|
2016-12-07 06:52:02 +08:00
|
|
|
cluster_address = ""
|
2016-12-04 10:01:30 +08:00
|
|
|
# I can assume eth1 because I know all the vagrant
|
|
|
|
# boxes we test with use that interface
|
2017-08-22 02:07:43 +08:00
|
|
|
address = host.interface("eth1").addresses[0]
|
2016-12-06 23:58:01 +08:00
|
|
|
subnet = ".".join(ansible_vars["public_network"].split(".")[0:-1])
|
2016-12-07 00:55:20 +08:00
|
|
|
num_mons = len(ansible_vars["groups"]["mons"])
|
2017-07-26 03:37:25 +08:00
|
|
|
num_devices = len(ansible_vars.get("devices", []))
|
|
|
|
if not num_devices:
|
|
|
|
num_devices = len(ansible_vars.get("lvm_volumes", []))
|
2016-12-08 04:31:31 +08:00
|
|
|
num_osd_hosts = len(ansible_vars["groups"]["osds"])
|
|
|
|
total_osds = num_devices * num_osd_hosts
|
2016-12-07 00:55:20 +08:00
|
|
|
cluster_name = ansible_vars.get("cluster", "ceph")
|
|
|
|
conf_path = "/etc/ceph/{}.conf".format(cluster_name)
|
2017-02-03 02:39:06 +08:00
|
|
|
if node_type == "osds":
|
|
|
|
# I can assume eth2 because I know all the vagrant
|
|
|
|
# boxes we test with use that interface. OSDs are the only
|
|
|
|
# nodes that have this interface.
|
2017-08-22 02:07:43 +08:00
|
|
|
cluster_address = host.interface("eth2").addresses[0]
|
|
|
|
cmd = host.run('sudo ls /var/lib/ceph/osd/ | sed "s/.*-//"')
|
2017-02-03 02:39:06 +08:00
|
|
|
if cmd.rc == 0:
|
|
|
|
osd_ids = cmd.stdout.rstrip("\n").split("\n")
|
|
|
|
osds = osd_ids
|
|
|
|
if docker:
|
2017-07-26 03:37:25 +08:00
|
|
|
osds = [device.split("/")[-1] for device in ansible_vars.get("devices", [])]
|
2017-02-03 02:39:06 +08:00
|
|
|
|
2016-12-04 10:01:30 +08:00
|
|
|
data = dict(
|
|
|
|
address=address,
|
2016-12-05 23:47:33 +08:00
|
|
|
subnet=subnet,
|
2016-12-06 23:58:01 +08:00
|
|
|
vars=ansible_vars,
|
2016-12-06 05:03:44 +08:00
|
|
|
osd_ids=osd_ids,
|
2016-12-07 00:55:20 +08:00
|
|
|
num_mons=num_mons,
|
2016-12-08 00:32:00 +08:00
|
|
|
num_devices=num_devices,
|
2016-12-08 04:31:31 +08:00
|
|
|
num_osd_hosts=num_osd_hosts,
|
|
|
|
total_osds=total_osds,
|
2016-12-07 03:32:28 +08:00
|
|
|
cluster_name=cluster_name,
|
|
|
|
conf_path=conf_path,
|
2016-12-07 06:52:02 +08:00
|
|
|
cluster_address=cluster_address,
|
2016-12-08 09:17:09 +08:00
|
|
|
docker=docker,
|
2016-12-08 09:24:40 +08:00
|
|
|
osds=osds,
|
2017-05-05 03:04:23 +08:00
|
|
|
ceph_stable_release=ceph_stable_release,
|
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)
|
|
|
|
elif "rgw" in test_path:
|
|
|
|
item.add_marker(pytest.mark.rgws)
|
|
|
|
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)
|