|
52 | 52 | from utilities.constants import DscComponents |
53 | 53 | from model_registry import ModelRegistry as ModelRegistryClient |
54 | 54 | 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 |
56 | 56 |
|
57 | 57 | DEFAULT_TOKEN_DURATION = "10m" |
58 | 58 | LOGGER = get_logger(name=__name__) |
@@ -169,57 +169,73 @@ def updated_dsc_component_state_scope_session( |
169 | 169 | pytestconfig: Config, |
170 | 170 | request: FixtureRequest, |
171 | 171 | admin_client: DynamicClient, |
172 | | - teardown_resources: bool, |
173 | 172 | ) -> Generator[DataScienceCluster, Any, Any]: |
174 | 173 | 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, |
193 | 223 | ) |
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) |
196 | 231 | wait_for_pods_running( |
197 | 232 | admin_client=admin_client, |
198 | 233 | namespace_name=py_config["applications_namespace"], |
199 | 234 | number_of_consecutive_checks=6, |
200 | 235 | ) |
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 |
223 | 239 |
|
224 | 240 |
|
225 | 241 | @pytest.fixture(scope="class") |
|
0 commit comments