Skip to content

Commit 4726154

Browse files
authored
Merge branch 'main' into fix_test_errors
2 parents d9d6564 + 1e5a724 commit 4726154

File tree

6 files changed

+115
-51
lines changed

6 files changed

+115
-51
lines changed

docs/GETTING_STARTED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ To run tests with admin client only, pass `--tc=use_unprivileged_client:False` t
138138
### jira integration
139139

140140
To skip running tests which have open bugs, [pytest_jira](https://github.com/rhevm-qe-automation/pytest_jira) plugin is used.
141-
To run tests with jira integration, you need to set `PYTEST_JIRA_URL` and `PYTEST_JIRA_TOKEN` environment variables.
141+
To run tests with jira integration, you need to set `PYTEST_JIRA_URL`, `PYTEST_JIRA_USERNAME` and `PYTEST_JIRA_TOKEN` environment variables.
142142
To make a test with jira marker, add: `@pytest.mark.jira(jira_id="RHOAIENG-0000", run=False)` to the test.
143143

144144
### Running containerized tests

tests/llama_stack/inference/upgrade/test_upgrade_chat_completions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_inference_chat_completion_pre_upgrade(
6464
@pytest.mark.llama_stack
6565
class TestPostUpgradeLlamaStackInferenceCompletions:
6666
@pytest.mark.post_upgrade
67+
@pytest.mark.xfail(reason="RHAIENG-3650")
6768
def test_inference_chat_completion_post_upgrade(
6869
self,
6970
unprivileged_llama_stack_client: LlamaStackClient,

tests/llama_stack/vector_io/upgrade/test_upgrade_vector_store_rag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def test_vector_store_rag_pre_upgrade(
109109
@pytest.mark.rag
110110
class TestPostUpgradeLlamaStackVectorStoreRag:
111111
@pytest.mark.post_upgrade
112+
@pytest.mark.xfail(reason="RHAIENG-3650")
112113
def test_vector_store_rag_post_upgrade(
113114
self,
114115
unprivileged_llama_stack_client: LlamaStackClient,

tests/model_registry/model_catalog/db_check/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from kubernetes.dynamic import DynamicClient
3+
from ocp_resources.network_policy import NetworkPolicy
34
from ocp_resources.secret import Secret
45
from pytest_testconfig import config as py_config
56
from simple_logger.logger import get_logger
@@ -56,3 +57,14 @@ def recreated_model_catalog_postgres_secret(
5657
break
5758

5859
return extract_secret_values(secret=recreated_secret)
60+
61+
62+
@pytest.fixture(scope="class")
63+
def model_catalog_postgres_network_policy(admin_client: DynamicClient, model_registry_namespace: str) -> NetworkPolicy:
64+
"""Get the model-catalog-postgres NetworkPolicy from model registry namespace"""
65+
return NetworkPolicy(
66+
client=admin_client,
67+
name="model-catalog-postgres",
68+
namespace=model_registry_namespace,
69+
ensure_exists=True,
70+
)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import pytest
2+
from kubernetes.dynamic import DynamicClient
3+
from ocp_resources.network_policy import NetworkPolicy
4+
from simple_logger.logger import get_logger
5+
from timeout_sampler import TimeoutSampler
6+
7+
from tests.model_registry.model_catalog.utils import get_postgres_pod_in_namespace
8+
from tests.model_registry.utils import (
9+
wait_for_model_catalog_pod_ready_after_deletion,
10+
)
11+
12+
LOGGER = get_logger(name=__name__)
13+
14+
15+
class TestModelCatalogDBSecret:
16+
def test_model_catalog_postgres_secret_exists(self, model_catalog_postgres_secret_values):
17+
"""Test that model-catalog-postgres secret exists and is accessible"""
18+
assert model_catalog_postgres_secret_values, (
19+
f"model-catalog-postgres secret should exist and be accessible: {model_catalog_postgres_secret_values}"
20+
)
21+
22+
@pytest.mark.dependency(name="test_model_catalog_postgres_password_recreation")
23+
def test_model_catalog_postgres_password_recreation(
24+
self, model_catalog_postgres_secret_values, recreated_model_catalog_postgres_secret
25+
):
26+
"""Test that secret recreation generates new password but preserves user/database name"""
27+
# Verify database-name and database-user did NOT change
28+
unchanged_keys = ["database-name", "database-user"]
29+
for key in unchanged_keys:
30+
assert model_catalog_postgres_secret_values[key] == recreated_model_catalog_postgres_secret[key], (
31+
f"{key} should remain the same after secret recreation"
32+
)
33+
34+
# Verify database-password DID change (randomization working)
35+
assert (
36+
model_catalog_postgres_secret_values["database-password"]
37+
!= recreated_model_catalog_postgres_secret["database-password"]
38+
), "database-password should be different after secret recreation (randomized)"
39+
40+
LOGGER.info("Password randomization verified - new password generated on recreation")
41+
42+
@pytest.mark.dependency(depends=["test_model_catalog_postgres_password_recreation"])
43+
def test_model_catalog_pod_ready_after_secret_recreation(
44+
self, admin_client: DynamicClient, model_registry_namespace: str
45+
):
46+
"""Test that model catalog pod becomes ready after secret recreation"""
47+
# delete the postgres pod first
48+
get_postgres_pod_in_namespace(admin_client=admin_client, namespace=model_registry_namespace).delete()
49+
# Wait for model catalog pod to be ready after the secret deletion/recreation
50+
wait_for_model_catalog_pod_ready_after_deletion(
51+
client=admin_client, model_registry_namespace=model_registry_namespace
52+
)
53+
LOGGER.info("Model catalog pod is ready after secret recreation")
54+
55+
56+
class TestModelCatalogDBNetworkPolicy:
57+
def test_postgres_network_policy_exists(self, model_catalog_postgres_network_policy):
58+
"""Test that postgres NetworkPolicy exists and is accessible"""
59+
assert model_catalog_postgres_network_policy.exists, "model-catalog-postgres NetworkPolicy should exist"
60+
61+
def test_postgres_network_policy_restricts_to_port_5432(self, model_catalog_postgres_network_policy):
62+
"""Test that NetworkPolicy only allows TCP 5432 ingress"""
63+
spec = model_catalog_postgres_network_policy.instance.spec
64+
assert "Ingress" in spec.policyTypes, "NetworkPolicy should have Ingress policy type"
65+
assert len(spec.ingress) == 1, "NetworkPolicy should have exactly one ingress rule"
66+
67+
port = spec.ingress[0].ports[0]
68+
assert port.port == 5432, "NetworkPolicy should allow only PostgreSQL port 5432"
69+
assert port.protocol == "TCP", "NetworkPolicy port should use TCP protocol"
70+
71+
def test_postgres_network_policy_allows_only_catalog_pods(self, model_catalog_postgres_network_policy):
72+
"""Test that only model-catalog pods can reach postgres"""
73+
from_selector = model_catalog_postgres_network_policy.instance.spec.ingress[0]["from"][
74+
0
75+
].podSelector.matchLabels
76+
assert from_selector["component"] == "model-catalog", (
77+
"Only model-catalog pods should be allowed to access postgres"
78+
)
79+
80+
@pytest.mark.dependency(name="test_postgres_network_policy_recreation")
81+
def test_postgres_network_policy_recreated_after_deletion(
82+
self,
83+
admin_client: DynamicClient,
84+
model_catalog_postgres_network_policy,
85+
model_registry_namespace: str,
86+
):
87+
"""Test that operator recreates NetworkPolicy after deletion"""
88+
model_catalog_postgres_network_policy.delete()
89+
get_postgres_pod_in_namespace(admin_client=admin_client, namespace=model_registry_namespace).delete()
90+
for np in TimeoutSampler(
91+
wait_timeout=120,
92+
sleep=10,
93+
func=NetworkPolicy,
94+
client=admin_client,
95+
name="model-catalog-postgres",
96+
namespace=model_registry_namespace,
97+
):
98+
if np.exists:
99+
LOGGER.info("NetworkPolicy has been recreated by operator")
100+
break

tests/model_registry/model_catalog/db_check/test_model_catalog_secrets.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)