Skip to content

Commit a853ac0

Browse files
authored
Updates for GA of Model Registry (#571)
1 parent c5ca79f commit a853ac0

File tree

3 files changed

+61
-111
lines changed

3 files changed

+61
-111
lines changed

tests/model_registry/conftest.py

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from utilities.constants import DscComponents
5353
from model_registry import ModelRegistry as ModelRegistryClient
5454
from utilities.general import wait_for_pods_by_labels
55-
from utilities.infra import get_data_science_cluster
55+
from utilities.infra import get_data_science_cluster, wait_for_dsc_status_ready
5656

5757
DEFAULT_TOKEN_DURATION = "10m"
5858
LOGGER = get_logger(name=__name__)
@@ -169,57 +169,73 @@ def updated_dsc_component_state_scope_session(
169169
pytestconfig: Config,
170170
request: FixtureRequest,
171171
admin_client: DynamicClient,
172-
teardown_resources: bool,
173172
) -> Generator[DataScienceCluster, Any, Any]:
174173
dsc_resource = get_data_science_cluster(client=admin_client)
175-
if not teardown_resources or pytestconfig.option.post_upgrade:
176-
# if we are not tearing down resources or we are in post upgrade, we don't need to do anything
177-
# the pre_upgrade/post_upgrade fixtures will handle the rest
178-
yield dsc_resource
179-
else:
180-
original_components = dsc_resource.instance.spec.components
181-
component_patch = {
182-
DscComponents.MODELREGISTRY: {
183-
"managementState": DscComponents.ManagementState.MANAGED,
184-
"registriesNamespace": py_config["model_registry_namespace"],
185-
},
186-
}
187-
LOGGER.info(f"Applying patch {component_patch}")
188-
189-
with ResourceEditor(patches={dsc_resource: {"spec": {"components": component_patch}}}):
190-
for component_name in component_patch:
191-
dsc_resource.wait_for_condition(
192-
condition=DscComponents.COMPONENT_MAPPING[component_name], status="True"
174+
original_namespace_name = dsc_resource.instance.spec.components.modelregistry.registriesNamespace
175+
if pytestconfig.option.custom_namespace:
176+
resource_editor = ResourceEditor(
177+
patches={
178+
dsc_resource: {
179+
"spec": {
180+
"components": {
181+
DscComponents.MODELREGISTRY: {
182+
"managementState": DscComponents.ManagementState.REMOVED,
183+
"registriesNamespace": original_namespace_name,
184+
},
185+
}
186+
}
187+
}
188+
}
189+
)
190+
try:
191+
# first disable MR
192+
resource_editor.update(backup_resources=True)
193+
wait_for_dsc_status_ready(dsc_resource=dsc_resource)
194+
# now delete the original namespace:
195+
original_namespace = Namespace(name=original_namespace_name, wait_for_resource=True)
196+
original_namespace.delete(wait=True)
197+
# Now enable it with the custom namespace
198+
with ResourceEditor(
199+
patches={
200+
dsc_resource: {
201+
"spec": {
202+
"components": {
203+
DscComponents.MODELREGISTRY: {
204+
"managementState": DscComponents.ManagementState.MANAGED,
205+
"registriesNamespace": py_config["model_registry_namespace"],
206+
},
207+
}
208+
}
209+
}
210+
}
211+
):
212+
namespace = Namespace(name=py_config["model_registry_namespace"], wait_for_resource=True)
213+
namespace.wait_for_status(status=Namespace.Status.ACTIVE)
214+
wait_for_pods_running(
215+
admin_client=admin_client,
216+
namespace_name=py_config["applications_namespace"],
217+
number_of_consecutive_checks=6,
218+
)
219+
wait_for_pods_running(
220+
admin_client=admin_client,
221+
namespace_name=py_config["model_registry_namespace"],
222+
number_of_consecutive_checks=6,
193223
)
194-
namespace = Namespace(name=py_config["model_registry_namespace"], wait_for_resource=True)
195-
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)
196231
wait_for_pods_running(
197232
admin_client=admin_client,
198233
namespace_name=py_config["applications_namespace"],
199234
number_of_consecutive_checks=6,
200235
)
201-
wait_for_pods_running(
202-
admin_client=admin_client,
203-
namespace_name=py_config["model_registry_namespace"],
204-
number_of_consecutive_checks=6,
205-
)
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)