|
53 | 53 | from utilities.constants import DscComponents |
54 | 54 | from model_registry import ModelRegistry as ModelRegistryClient |
55 | 55 | 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 |
57 | 57 |
|
58 | 58 | DEFAULT_TOKEN_DURATION = "10m" |
59 | 59 | LOGGER = get_logger(name=__name__) |
@@ -174,52 +174,68 @@ def updated_dsc_component_state_scope_session( |
174 | 174 | pytestconfig: Config, |
175 | 175 | request: FixtureRequest, |
176 | 176 | admin_client: DynamicClient, |
177 | | - teardown_resources: bool, |
178 | 177 | ) -> Generator[DataScienceCluster, Any, Any]: |
179 | 178 | 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, |
198 | 223 | ) |
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) |
201 | 231 | wait_for_pods_running( |
202 | 232 | admin_client=admin_client, |
203 | 233 | namespace_name=py_config["applications_namespace"], |
204 | 234 | number_of_consecutive_checks=6, |
205 | 235 | ) |
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 |
223 | 239 |
|
224 | 240 |
|
225 | 241 | @pytest.fixture(scope="class") |
|
0 commit comments