diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/pybind/mgr/rook/tests | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pybind/mgr/rook/tests')
-rw-r--r-- | src/pybind/mgr/rook/tests/__init__.py | 0 | ||||
-rw-r--r-- | src/pybind/mgr/rook/tests/fixtures.py | 11 | ||||
-rw-r--r-- | src/pybind/mgr/rook/tests/test_placement.py | 100 | ||||
-rw-r--r-- | src/pybind/mgr/rook/tests/test_rook.py | 120 |
4 files changed, 231 insertions, 0 deletions
diff --git a/src/pybind/mgr/rook/tests/__init__.py b/src/pybind/mgr/rook/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/pybind/mgr/rook/tests/__init__.py diff --git a/src/pybind/mgr/rook/tests/fixtures.py b/src/pybind/mgr/rook/tests/fixtures.py new file mode 100644 index 000000000..65a519743 --- /dev/null +++ b/src/pybind/mgr/rook/tests/fixtures.py @@ -0,0 +1,11 @@ +from rook.module import RookOrchestrator +from orchestrator import raise_if_exception, OrchResult + +try: + from typing import Any +except ImportError: + pass + + +def wait(m: RookOrchestrator, c: OrchResult) -> Any: + return raise_if_exception(c) diff --git a/src/pybind/mgr/rook/tests/test_placement.py b/src/pybind/mgr/rook/tests/test_placement.py new file mode 100644 index 000000000..eeaf191e2 --- /dev/null +++ b/src/pybind/mgr/rook/tests/test_placement.py @@ -0,0 +1,100 @@ +# flake8: noqa + +from rook.rook_cluster import placement_spec_to_node_selector, node_selector_to_placement_spec +from rook.rook_client.ceph.cephcluster import MatchExpressionsItem, MatchExpressionsList, NodeSelectorTermsItem +import pytest +from orchestrator import HostSpec +from ceph.deployment.service_spec import PlacementSpec + +@pytest.mark.parametrize("hosts", + [ # noqa: E128 + [ + HostSpec( + hostname="node1", + labels=["label1"] + ), + HostSpec( + hostname="node2", + labels=[] + ), + HostSpec( + hostname="node3", + labels=["label1"] + ) + ] + ]) +@pytest.mark.parametrize("expected_placement_spec, expected_node_selector", + [ # noqa: E128 + ( + PlacementSpec( + label="label1" + ), + NodeSelectorTermsItem( + matchExpressions=MatchExpressionsList( + [ + MatchExpressionsItem( + key="ceph-label/label1", + operator="Exists" + ) + ] + ) + ) + ), + ( + PlacementSpec( + label="label1", + host_pattern="*" + ), + NodeSelectorTermsItem( + matchExpressions=MatchExpressionsList( + [ + MatchExpressionsItem( + key="ceph-label/label1", + operator="Exists" + ), + MatchExpressionsItem( + key="kubernetes.io/hostname", + operator="Exists", + ) + ] + ) + ) + ), + ( + PlacementSpec( + host_pattern="*" + ), + NodeSelectorTermsItem( + matchExpressions=MatchExpressionsList( + [ + MatchExpressionsItem( + key="kubernetes.io/hostname", + operator="Exists", + ) + ] + ) + ) + ), + ( + PlacementSpec( + hosts=["node1", "node2", "node3"] + ), + NodeSelectorTermsItem( + matchExpressions=MatchExpressionsList( + [ + MatchExpressionsItem( + key="kubernetes.io/hostname", + operator="In", + values=["node1", "node2", "node3"] + ) + ] + ) + ) + ), + ]) +def test_placement_spec_translate(hosts, expected_placement_spec, expected_node_selector): + node_selector = placement_spec_to_node_selector(expected_placement_spec, hosts) + assert [(getattr(expression, 'key', None), getattr(expression, 'operator', None), getattr(expression, 'values', None)) for expression in node_selector.matchExpressions] == [(getattr(expression, 'key', None), getattr(expression, 'operator', None), getattr(expression, 'values', None)) for expression in expected_node_selector.matchExpressions] + placement_spec = node_selector_to_placement_spec(expected_node_selector) + assert placement_spec == expected_placement_spec + assert (getattr(placement_spec, 'label', None), getattr(placement_spec, 'hosts', None), getattr(placement_spec, 'host_pattern', None)) == (getattr(expected_placement_spec, 'label', None), getattr(expected_placement_spec, 'hosts', None), getattr(expected_placement_spec, 'host_pattern', None)) diff --git a/src/pybind/mgr/rook/tests/test_rook.py b/src/pybind/mgr/rook/tests/test_rook.py new file mode 100644 index 000000000..08028ba85 --- /dev/null +++ b/src/pybind/mgr/rook/tests/test_rook.py @@ -0,0 +1,120 @@ +import orchestrator +from .fixtures import wait +import pytest +from unittest.mock import patch, PropertyMock + +from rook.module import RookOrchestrator +from rook.rook_cluster import RookCluster + + +# we use this intermediate class as .rook_cluster property +# is read only in the paretn class RookCluster +class FakeRookCluster(RookCluster): + def __init__(self): + pass + + +class TestRook(object): + + @pytest.mark.parametrize("pods, expected_daemon_types", [ + ( + [ + { + 'name': 'ceph-rook-exporter', + 'hostname': 'host1', + "labels": {'app': 'rook-ceph-exporter', + 'ceph_daemon_id': 'exporter'}, + 'phase': 'Pending', + 'container_image_name': 'quay.io/ceph/ceph:v18', + 'container_image_id': 'docker-pullable://quay.io/ceph/ceph@sha256:f239715e1c7756e32a202a572e2763a4ce15248e09fc6e8990985f8a09ffa784', + 'refreshed': 'pod1_ts', + 'started': 'pod1_ts', + 'created': 'pod1_1ts', + }, + { + 'name': 'rook-ceph-mgr-a-68c7b9b6d8-vjjhl', + 'hostname': 'host1', + "labels": {'app': 'rook-ceph-mgr', + 'ceph_daemon_type': 'mgr', + 'ceph_daemon_id': 'a'}, + 'phase': 'Failed', + 'container_image_name': 'quay.io/ceph/ceph:v18', + 'container_image_id': '', + 'refreshed': 'pod2_ts', + 'started': 'pod2_ts', + 'created': 'pod2_1ts', + }, + { + 'name': 'rook-ceph-mon-a-65fb8694b4-mmtl5', + 'hostname': 'host1', + "labels": {'app': 'rook-ceph-mon', + 'ceph_daemon_type': 'mon', + 'ceph_daemon_id': 'b'}, + 'phase': 'Running', + 'container_image_name': 'quay.io/ceph/ceph:v18', + 'container_image_id': '', + 'refreshed': 'pod3_ts', + 'started': 'pod3_ts', + 'created': 'pod3_1ts', + }, + { + 'name': 'rook-ceph-osd-0-58cbd7b65c-6cjnr', + 'hostname': 'host1', + "labels": {'app': 'rook-ceph-osd', + 'ceph-osd-id': '0', + 'ceph_daemon_type': 'osd', + 'ceph_daemon_id': '0'}, + 'phase': 'Succeeded', + 'container_image_name': 'quay.io/ceph/ceph:v18', + 'container_image_id': '', + 'refreshed': 'pod4_ts', + 'started': 'pod4_ts', + 'created': 'pod4_1ts', + }, + # unknown pod: has no labels are provided, it shouldn't + # be part of the output + { + 'name': 'unknown-pod', + 'hostname': '', + "labels": {'app': 'unkwon'}, + 'phase': 'Pending', + 'container_image_name': 'quay.io/ceph/ceph:v18', + 'container_image_id': '', + 'refreshed': '', + 'started': '', + 'created': '', + } + ], + ['ceph-exporter', 'mgr', 'mon', 'osd'] + ) + ]) + def test_list_daemons(self, pods, expected_daemon_types): + + status = { + 'Pending': orchestrator.DaemonDescriptionStatus.starting, + 'Running': orchestrator.DaemonDescriptionStatus.running, + 'Succeeded': orchestrator.DaemonDescriptionStatus.stopped, + 'Failed': orchestrator.DaemonDescriptionStatus.error, + 'Unknown': orchestrator.DaemonDescriptionStatus.unknown, + } + + fake_rook_cluster = FakeRookCluster() + ro = RookOrchestrator('rook', None, self) + with patch('rook.RookOrchestrator.rook_cluster', + new_callable=PropertyMock, + return_value=fake_rook_cluster): + with patch.object(fake_rook_cluster, 'describe_pods') as mock_describe_pods: + mock_describe_pods.return_value = pods + dds = wait(ro, ro.list_daemons()) + assert len(dds) == len(expected_daemon_types) + for i in range(0, len(dds)): + assert dds[i].daemon_type == expected_daemon_types[i] + assert dds[i].hostname == pods[i]['hostname'] + assert dds[i].status == status[pods[i]['phase']] + assert dds[i].container_image_name == pods[i]['container_image_name'] + assert dds[i].container_image_id == pods[i]['container_image_id'] + assert dds[i].created == pods[i]['created'] + assert dds[i].last_configured == pods[i]['created'] + assert dds[i].last_deployed == pods[i]['created'] + assert dds[i].started == pods[i]['started'] + assert dds[i].last_refresh == pods[i]['refreshed'] |