Skip to content

Commit d4e968f

Browse files
committed
test: add cluster health and fix bug on image creation
Signed-off-by: Debarati Basu-Nag <dbasunag@redhat.com>
1 parent 9084133 commit d4e968f

File tree

8 files changed

+68
-9
lines changed

8 files changed

+68
-9
lines changed

.github/workflows/build-push-container-on-merge.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout Repository
18-
uses: actions/checkout@v4
18+
uses: actions/checkout@v5
19+
with:
20+
ref: ${{ github.event.pull_request.base.ref }}
1921
- name: Set env TAG
2022
run: |
2123
if [ ${{ github.event.pull_request.base.ref }} == "main" ]; then

pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ testpaths = tests
55
markers =
66
# General
77
polarion: Store polarion test ID
8-
8+
cluster_health: Tests that verifies that cluster is healthy to begin testing
9+
operator_health: Tests that verifies that OpenDataHub/RHOAI operators are healthy and functioning correctly
910
# CI
1011
smoke: Mark tests as smoke tests; covers core functionality of the product. Aims to ensure that the build is stable enough for further testing.
1112
sanity: Mark tests as sanity tests. Aims to verify that specific functionality is working as expected.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from ocp_resources.node import Node
3+
from ocp_utilities.infra import assert_nodes_in_healthy_condition, assert_nodes_schedulable
4+
from simple_logger.logger import get_logger
5+
6+
LOGGER = get_logger(name=__name__)
7+
8+
9+
@pytest.mark.cluster_health
10+
def test_cluster_node_healthy(nodes: list[Node]) -> None:
11+
"""
12+
Tests if the cluster nodes are healthy
13+
"""
14+
assert_nodes_in_healthy_condition(nodes=nodes, healthy_node_condition_type={"KubeletReady": "True"})
15+
assert_nodes_schedulable(nodes=nodes)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from ocp_resources.data_science_cluster import DataScienceCluster
3+
from simple_logger.logger import get_logger
4+
5+
from tests.cluster_health.utils import wait_for_dsc_status_ready
6+
7+
LOGGER = get_logger(name=__name__)
8+
9+
10+
@pytest.mark.operator_health
11+
def test_data_science_cluster_healthy(dsc_resource: DataScienceCluster) -> None:
12+
"""
13+
Checks if a data science cluster is healthy
14+
"""
15+
wait_for_dsc_status_ready(dsc_resource=dsc_resource)

tests/cluster_health/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from simple_logger.logger import get_logger
2+
3+
from ocp_resources.data_science_cluster import DataScienceCluster
4+
5+
from timeout_sampler import retry
6+
7+
LOGGER = get_logger(name=__name__)
8+
9+
10+
class ResourceNotReadyError(Exception):
11+
pass
12+
13+
14+
@retry(
15+
wait_timeout=120,
16+
sleep=5,
17+
exceptions_dict={ResourceNotReadyError: []},
18+
)
19+
def wait_for_dsc_status_ready(dsc_resource: DataScienceCluster) -> bool:
20+
LOGGER.info(f"Wait for DSC {dsc_resource.name} are {dsc_resource.Status.READY}.")
21+
if dsc_resource.status == dsc_resource.Status.READY:
22+
return True
23+
raise ResourceNotReadyError(
24+
f"DSC {dsc_resource.name} is not ready.\nCurrent status: {dsc_resource.instance.status}"
25+
)

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import yaml
1010
from _pytest.tmpdir import TempPathFactory
1111
from ocp_resources.config_map import ConfigMap
12+
from ocp_resources.node import Node
1213
from ocp_resources.secret import Secret
1314
from pyhelper_utils.shell import run_command
1415
from pytest import FixtureRequest, Config
@@ -303,3 +304,8 @@ def cluster_monitoring_config(admin_client: DynamicClient) -> Generator[ConfigMa
303304
data=data,
304305
) as cm:
305306
yield cm
307+
308+
309+
@pytest.fixture(scope="session")
310+
def nodes(admin_client: DynamicClient) -> list[Node]:
311+
return list(Node.get(dyn_client=admin_client))

tests/model_serving/model_server/multi_node/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
)
2020

2121

22-
@pytest.fixture(scope="session")
23-
def nodes(admin_client: DynamicClient) -> list[Node]:
24-
return list(Node.get(dyn_client=admin_client))
25-
26-
2722
@pytest.fixture(scope="session")
2823
def nvidia_gpu_nodes(nodes: list[Node]) -> list[Node]:
2924
return [node for node in nodes if "nvidia.com/gpu.present" in node.labels.keys()]

utilities/jira.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def get_jira_connection() -> JIRA:
2323
2424
"""
2525
return JIRA(
26-
token_auth=os.getenv("PYTEST_JIRA_TOKEN"),
27-
options={"server": os.getenv("PYTEST_JIRA_URL")},
26+
server=os.getenv("PYTEST_JIRA_URL"),
27+
basic_auth=(os.getenv("PYTEST_JIRA_USERNAME"), os.getenv("PYTEST_JIRA_TOKEN")),
2828
)
2929

3030

0 commit comments

Comments
 (0)