Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@ To skip specific tests, set the SKIP_SCT variable:
|test_grafana.py| grafana |
|test_opensearch.py| opensearch |
|test_prometheus.py| prometheus |
|ceph/test_cephadm.py| cephadm |
|ceph/test_health.py| ceph-health|
|ceph/test_config.py| ceph-config|
|ceph/test_rgw.py| ceph-rgw |
|ceph/test_mgr_exporter.py| ceph-exporter|

To skip more than one test, set SKIP_SCT to a comma separated list:
```sh
# Skip both test_docker.py and test_ntp.py
export SKIP_SCT=docker,ntp
```

Values are matched as substrings, so no value may contain another. For example
a value of `ceph-prometheus` would also skip `test_prometheus.py`.
13 changes: 13 additions & 0 deletions stackhpc_cloud_tests/ceph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2026 StackHPC Ltd.

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
81 changes: 81 additions & 0 deletions stackhpc_cloud_tests/ceph/test_cephadm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) 2026 StackHPC Ltd.

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""Checks that the Ceph admin tooling works on this host.

cephadm labels the monitor hosts "_admin", which is what places
/etc/ceph/ceph.conf and the admin keyring on them. Without both of those
no Ceph command can run from the host at all.
"""

import pytest

from stackhpc_cloud_tests.ceph import utils

skip = utils.should_skip("cephadm")

# Distributed by cephadm to hosts labelled "_admin".
CEPH_CONF = "/etc/ceph/ceph.conf"
ADMIN_KEYRING = "/etc/ceph/ceph.client.admin.keyring"


@pytest.mark.skipif(skip, reason="Cephadm tests skipped.")
def test_cephadm_installed(host):
"""Check that the cephadm binary is available."""
assert host.exists("cephadm")


@pytest.mark.skipif(skip, reason="Cephadm tests skipped.")
def test_cephadm_shell_accessible(host):
"""Check that a cephadm shell starts and can run the Ceph CLI."""
result = utils.run_ceph(host, "--version")
message = f"Could not run 'cephadm shell': {result.stderr}"
assert result.rc == 0, message
assert "ceph version" in result.stdout


@pytest.mark.skipif(skip, reason="Cephadm tests skipped.")
def test_ceph_conf_present(host):
"""Check that the Ceph configuration file has been distributed."""
ceph_conf = host.file(CEPH_CONF)
assert ceph_conf.exists
# Clients need mon_host to find the cluster.
assert ceph_conf.contains("mon_host")


@pytest.mark.skipif(skip, reason="Cephadm tests skipped.")
def test_admin_keyring_present(host):
"""Check that the admin keyring exists and only root can read it."""
keyring = host.file(ADMIN_KEYRING)
assert keyring.exists

# File permissions are an octal number. Last digit must be
# 0 to restrict access to root only
permission_for_other_users = keyring.mode % 8
message = f"{ADMIN_KEYRING} can be read by any user on this host"
assert permission_for_other_users == 0, message


@pytest.mark.skipif(skip, reason="Cephadm tests skipped.")
def test_mon_in_quorum(host):
"""Check that the monitor on this host is a member of the quorum."""
hostname = host.check_output("hostname -s")
status = utils.run_ceph_json(host, "-s")
monitors_in_quorum = status["quorum_names"]

message = (
f"The monitor on {hostname} is not in the quorum. "
f"The quorum contains {monitors_in_quorum}."
)
assert hostname in monitors_in_quorum, message
143 changes: 143 additions & 0 deletions stackhpc_cloud_tests/ceph/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Copyright (c) 2026 StackHPC Ltd.

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""Checks that the cluster was configured the way the deployment asked.

CEPH_EXPECTED_POOLS and CEPH_EXPECTED_KEYS hold the cephadm_pools and
cephadm_keys lists as JSON, so the expectations come from the deployment
rather than being repeated here.

Note that Ceph and the cephadm collection both abbreviate capabilities to
"caps" in their data, so that spelling appears when reading their fields.
"""

import pytest

from stackhpc_cloud_tests.ceph import utils

skip = utils.should_skip("ceph-config")


def _applications_by_pool(host):
"""Return a mapping of pool name to the applications using it."""
return utils.run_ceph_json(host, "osd pool application get")


def _capabilities_by_entity(host):
"""Return a mapping of cephx entity name to its capabilities."""
# "ceph auth ls" also returns the secret key for every entity. Only the
# capabilities are kept here so a key cannot reach a test report.
auth = utils.run_ceph_json(host, "auth ls")

capabilities_by_entity = {}
for entry in auth["auth_dump"]:
capabilities_by_entity[entry["entity"]] = entry["caps"]
return capabilities_by_entity


@pytest.mark.skipif(skip, reason="Ceph config tests skipped.")
def test_expected_pools_present(subtests, host):
"""Check each pool the deployment asks for exists with its application."""
expected_pools = utils.json_from_env("CEPH_EXPECTED_POOLS")
if not expected_pools:
pytest.skip("CEPH_EXPECTED_POOLS is empty or not set")

applications_by_pool = _applications_by_pool(host)

for pool in expected_pools:
if pool["state"] != "present":
continue

with subtests.test(msg="pool=" + pool["name"]):
message = f"Pool {pool['name']} does not exist"
assert pool["name"] in applications_by_pool, message

# Ceph tags each pool with the application using it, which stops
# one service writing into another service's pool.
expected_application = pool.get("application")
if expected_application is not None:
applications = applications_by_pool[pool["name"]]
message = (
f"Pool {pool['name']} has applications "
f"{list(applications)}, expected {expected_application}"
)
assert expected_application in applications, message


@pytest.mark.skipif(skip, reason="Ceph config tests skipped.")
def test_absent_pools_removed(subtests, host):
"""Check that pools the deployment asks to remove are not present."""
expected_pools = utils.json_from_env("CEPH_EXPECTED_POOLS")
# An empty list would make the loop below pass without checking anything.
if not expected_pools:
pytest.skip("CEPH_EXPECTED_POOLS is empty or not set")

applications_by_pool = _applications_by_pool(host)

for pool in expected_pools:
if pool["state"] != "absent":
continue

with subtests.test(msg="pool=" + pool["name"]):
message = f"Pool {pool['name']} should have been removed"
assert pool["name"] not in applications_by_pool, message


@pytest.mark.skipif(skip, reason="Ceph config tests skipped.")
def test_expected_keys_present(subtests, host):
"""Check each cephx key the deployment asks for exists, with its
capabilities.
"""
expected_keys = utils.json_from_env("CEPH_EXPECTED_KEYS")
if not expected_keys:
pytest.skip("CEPH_EXPECTED_KEYS is empty or not set")

capabilities_by_entity = _capabilities_by_entity(host)

for key in expected_keys:
if key["state"] != "present":
continue

with subtests.test(msg="key=" + key["name"]):
message = f"Cephx key {key['name']} does not exist"
assert key["name"] in capabilities_by_entity, message

# Capabilities decide which pools a client may use, so a wrong
# one makes a service fail to write with nothing else noticing.
actual_capabilities = capabilities_by_entity[key["name"]]
for daemon_type, expected_capability in key["caps"].items():
actual_capability = actual_capabilities.get(daemon_type)
message = (
f"Cephx key {key['name']} has {daemon_type} capability "
f"'{actual_capability}', expected '{expected_capability}'"
)
assert actual_capability == expected_capability, message


@pytest.mark.skipif(skip, reason="Ceph config tests skipped.")
def test_absent_keys_removed(subtests, host):
"""Check that cephx keys the deployment asks to remove are not present."""
expected_keys = utils.json_from_env("CEPH_EXPECTED_KEYS")
if not expected_keys:
pytest.skip("CEPH_EXPECTED_KEYS is empty or not set")

capabilities_by_entity = _capabilities_by_entity(host)

for key in expected_keys:
if key["state"] != "absent":
continue

with subtests.test(msg="key=" + key["name"]):
message = f"Cephx key {key['name']} should have been removed"
assert key["name"] not in capabilities_by_entity, message
Loading