Skip to content

Commit 09e6dc3

Browse files
Avoid deactivate/activate when feature flag for Aqua is enabled. (#797)
2 parents ff40286 + c231b6f commit 09e6dc3

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

ads/aqua/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,10 @@ def set_log_level(log_level: str):
5353
if OCI_RESOURCE_PRINCIPAL_VERSION:
5454
set_auth("resource_principal")
5555

56-
ODSC_MODEL_COMPARTMENT_OCID = os.environ.get("ODSC_MODEL_COMPARTMENT_OCID")
56+
ODSC_MODEL_COMPARTMENT_OCID = (
57+
os.environ.get("ODSC_MODEL_COMPARTMENT_OCID") or fetch_service_compartment()
58+
)
5759
if not ODSC_MODEL_COMPARTMENT_OCID:
58-
try:
59-
ODSC_MODEL_COMPARTMENT_OCID = fetch_service_compartment()
60-
except:
61-
pass
62-
63-
if not ODSC_MODEL_COMPARTMENT_OCID:
64-
logger.error(
65-
f"ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
66-
)
6760
if NB_SESSION_OCID:
6861
logger.error(
6962
f"Aqua is not available for this notebook session {NB_SESSION_OCID}."

ads/aqua/extension/common_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ads.aqua.decorator import handle_exceptions
1111
from ads.aqua.exception import AquaResourceAccessError
1212
from ads.aqua.extension.base_handler import AquaAPIhandler
13-
from ads.aqua.utils import known_realm
13+
from ads.aqua.utils import known_realm, fetch_service_compartment
1414

1515

1616
class ADSVersionHandler(AquaAPIhandler):
@@ -39,7 +39,7 @@ def get(self):
3939
AquaResourceAccessError: raised when aqua is not accessible in the given session/region.
4040
4141
"""
42-
if ODSC_MODEL_COMPARTMENT_OCID:
42+
if ODSC_MODEL_COMPARTMENT_OCID or fetch_service_compartment():
4343
return self.finish(dict(status="ok"))
4444
elif known_realm():
4545
return self.finish(dict(status="compatible"))

ads/aqua/utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,20 +567,27 @@ def get_container_image(
567567
return container_image
568568

569569

570-
def fetch_service_compartment():
571-
"""Loads the compartment mapping json from service bucket"""
570+
def fetch_service_compartment() -> Union[str, None]:
571+
"""Loads the compartment mapping json from service bucket. This json file has a service-model-compartment key which
572+
contains a dictionary of namespaces and the compartment OCID of the service models in that namespace.
573+
"""
572574
config_file_name = (
573575
f"oci://{AQUA_SERVICE_MODELS_BUCKET}@{CONDA_BUCKET_NS}/service_models/config"
574576
)
575577

576-
config = load_config(
577-
file_path=config_file_name,
578-
config_file_name=CONTAINER_INDEX,
579-
)
578+
try:
579+
config = load_config(
580+
file_path=config_file_name,
581+
config_file_name=CONTAINER_INDEX,
582+
)
583+
except AquaFileNotFoundError:
584+
logger.error(
585+
f"ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
586+
)
587+
return
580588
compartment_mapping = config.get(COMPARTMENT_MAPPING_KEY)
581589
if compartment_mapping:
582590
return compartment_mapping.get(CONDA_BUCKET_NS)
583-
return None
584591

585592

586593
def get_max_version(versions):

0 commit comments

Comments
 (0)