Skip to content

Commit 466cd94

Browse files
committed
Updates for GA of Model Registry
1 parent 97aac18 commit 466cd94

File tree

3 files changed

+56
-106
lines changed

3 files changed

+56
-106
lines changed

tests/model_registry/conftest.py

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from utilities.constants import DscComponents
5454
from model_registry import ModelRegistry as ModelRegistryClient
5555
from utilities.general import wait_for_pods_by_labels
56-
from utilities.infra import get_data_science_cluster
56+
from utilities.infra import get_data_science_cluster, wait_for_dsc_status_ready
5757

5858
DEFAULT_TOKEN_DURATION = "10m"
5959
LOGGER = get_logger(name=__name__)
@@ -174,52 +174,68 @@ def updated_dsc_component_state_scope_session(
174174
pytestconfig: Config,
175175
request: FixtureRequest,
176176
admin_client: DynamicClient,
177-
teardown_resources: bool,
178177
) -> Generator[DataScienceCluster, Any, Any]:
179178
dsc_resource = get_data_science_cluster(client=admin_client)
180-
if not teardown_resources or pytestconfig.option.post_upgrade:
181-
# if we are not tearing down resources or we are in post upgrade, we don't need to do anything
182-
# the pre_upgrade/post_upgrade fixtures will handle the rest
183-
yield dsc_resource
184-
else:
185-
original_components = dsc_resource.instance.spec.components
186-
component_patch = {
187-
DscComponents.MODELREGISTRY: {
188-
"managementState": DscComponents.ManagementState.MANAGED,
189-
"registriesNamespace": py_config["model_registry_namespace"],
190-
},
191-
}
192-
LOGGER.info(f"Applying patch {component_patch}")
193-
194-
with ResourceEditor(patches={dsc_resource: {"spec": {"components": component_patch}}}):
195-
for component_name in component_patch:
196-
dsc_resource.wait_for_condition(
197-
condition=DscComponents.COMPONENT_MAPPING[component_name], status="True"
179+
original_namespace_name = dsc_resource.instance.spec.components.modelregistry.registriesNamespace
180+
if pytestconfig.option.custom_namespace:
181+
resource_editor = ResourceEditor(
182+
patches={
183+
dsc_resource: {
184+
"spec": {
185+
"components": {
186+
DscComponents.MODELREGISTRY: {
187+
"managementState": DscComponents.ManagementState.REMOVED,
188+
"registriesNamespace": original_namespace_name,
189+
},
190+
}
191+
}
192+
}
193+
}
194+
)
195+
try:
196+
# first disable MR
197+
resource_editor.update(backup_resources=True)
198+
wait_for_dsc_status_ready(dsc_resource=dsc_resource)
199+
# now delete the original namespace:
200+
original_namespace = Namespace(name=original_namespace_name, wait_for_resource=True)
201+
original_namespace.delete(wait=True)
202+
# Now enable it with the custom namespace
203+
with ResourceEditor(
204+
patches={
205+
dsc_resource: {
206+
"spec": {
207+
"components": {
208+
DscComponents.MODELREGISTRY: {
209+
"managementState": DscComponents.ManagementState.MANAGED,
210+
"registriesNamespace": py_config["model_registry_namespace"],
211+
},
212+
}
213+
}
214+
}
215+
}
216+
):
217+
namespace = Namespace(name=py_config["model_registry_namespace"], wait_for_resource=True)
218+
namespace.wait_for_status(status=Namespace.Status.ACTIVE)
219+
wait_for_pods_running(
220+
admin_client=admin_client,
221+
namespace_name=py_config["applications_namespace"],
222+
number_of_consecutive_checks=6,
198223
)
199-
namespace = Namespace(name=py_config["model_registry_namespace"], wait_for_resource=True)
200-
namespace.wait_for_status(status=Namespace.Status.ACTIVE)
224+
yield dsc_resource
225+
finally:
226+
resource_editor.restore()
227+
Namespace(name=py_config["model_registry_namespace"]).delete(wait=True)
228+
# create the original namespace object again, so that we can wait for it to be created first
229+
original_namespace = Namespace(name=original_namespace_name, wait_for_resource=True)
230+
original_namespace.wait_for_status(status=Namespace.Status.ACTIVE)
201231
wait_for_pods_running(
202232
admin_client=admin_client,
203233
namespace_name=py_config["applications_namespace"],
204234
number_of_consecutive_checks=6,
205235
)
206-
yield dsc_resource
207-
208-
for component_name, value in component_patch.items():
209-
LOGGER.info(f"Waiting for component {component_name} to be updated.")
210-
if original_components[component_name]["managementState"] == DscComponents.ManagementState.MANAGED:
211-
dsc_resource.wait_for_condition(
212-
condition=DscComponents.COMPONENT_MAPPING[component_name], status="True"
213-
)
214-
if (
215-
component_name == DscComponents.MODELREGISTRY
216-
and value.get("managementState") == DscComponents.ManagementState.MANAGED
217-
):
218-
# Since namespace specified in registriesNamespace is automatically created after setting
219-
# managementStateto Managed. We need to explicitly delete it on clean up.
220-
namespace = Namespace(name=py_config["model_registry_namespace"], ensure_exists=True)
221-
if namespace:
222-
namespace.delete(wait=True)
236+
else:
237+
LOGGER.info("Model Registry is enabled by default and does not require any setup.")
238+
yield dsc_resource
223239

224240

225241
@pytest.fixture(scope="class")

tests/model_registry/upgrade/conftest.py

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

tests/model_registry/upgrade/test_model_registry_upgrade.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
],
2929
indirect=True,
3030
)
31-
@pytest.mark.usefixtures("pre_upgrade_dsc_patch", "model_registry_metadata_db_resources", "model_registry_instance")
31+
@pytest.mark.usefixtures("model_registry_metadata_db_resources", "model_registry_instance")
3232
class TestPreUpgradeModelRegistry:
3333
@pytest.mark.pre_upgrade
3434
def test_registering_model_pre_upgrade(
@@ -43,7 +43,6 @@ def test_registering_model_pre_upgrade(
4343
pytest.fail("errors found in model registry response validation:\n{}".format("\n".join(errors)))
4444

4545

46-
@pytest.mark.usefixtures("post_upgrade_dsc_patch")
4746
class TestPostUpgradeModelRegistry:
4847
@pytest.mark.post_upgrade
4948
def test_retrieving_model_post_upgrade(

0 commit comments

Comments
 (0)