Skip to content

Commit c424a09

Browse files
[ODSC-55513] Show Aqua extension for the default region (#778)
2 parents 82d011c + 88bb9c6 commit c424a09

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

ads/aqua/extension/common_handler.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from importlib import metadata
88

99
from ads.aqua import ODSC_MODEL_COMPARTMENT_OCID
10-
from ads.aqua.decorator import handle_exceptions
1110
from ads.aqua.exception import AquaResourceAccessError
11+
from ads.aqua.utils import known_realm
12+
from ads.aqua.decorator import handle_exceptions
1213
from ads.aqua.extension.base_handler import AquaAPIhandler
1314

1415

@@ -25,8 +26,23 @@ class CompatibilityCheckHandler(AquaAPIhandler):
2526

2627
@handle_exceptions
2728
def get(self):
29+
"""This method provides the availability status of Aqua. If ODSC_MODEL_COMPARTMENT_OCID environment variable
30+
is set, then status `ok` is returned. For regions where Aqua is available but the environment variable is not
31+
set due to accesses/policies, we return the `compatible` status to indicate that the extension can be enabled
32+
for the selected notebook session.
33+
34+
Returns
35+
-------
36+
status dict:
37+
ok or compatible
38+
Raises:
39+
AquaResourceAccessError: raised when aqua is not accessible in the given session/region.
40+
41+
"""
2842
if ODSC_MODEL_COMPARTMENT_OCID:
2943
return self.finish(dict(status="ok"))
44+
elif known_realm():
45+
return self.finish(dict(status="compatible"))
3046
else:
3147
raise AquaResourceAccessError(
3248
f"The AI Quick actions extension is not compatible in the given region."

ads/aqua/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
LIFECYCLE_DETAILS_MISSING_JOBRUN = "The asscociated JobRun resource has been deleted."
8080
READY_TO_DEPLOY_STATUS = "ACTIVE"
8181
READY_TO_FINE_TUNE_STATUS = "TRUE"
82+
AQUA_GA_LIST = ["id19sfcrra6z"]
8283

8384

8485
class LifecycleStatus(Enum):
@@ -733,3 +734,14 @@ def _is_valid_mvs(mvs: ModelVersionSet, target_tag: str) -> bool:
733734
return False
734735

735736
return target_tag in mvs.freeform_tags
737+
738+
739+
def known_realm():
740+
"""This helper function returns True if the Aqua service is available by default in the given namespace.
741+
Returns
742+
-------
743+
bool:
744+
Return True if aqua service is available.
745+
746+
"""
747+
return os.environ.get("CONDA_BUCKET_NS") in AQUA_GA_LIST
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*--
3+
4+
# Copyright (c) 2024 Oracle and/or its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
7+
import os
8+
import json
9+
from importlib import reload
10+
from tornado.web import Application
11+
from tornado.testing import AsyncHTTPTestCase
12+
13+
import ads.config
14+
import ads.aqua
15+
from ads.aqua.utils import AQUA_GA_LIST
16+
from ads.aqua.extension.common_handler import CompatibilityCheckHandler
17+
18+
19+
class TestDataset:
20+
SERVICE_COMPARTMENT_ID = "ocid1.compartment.oc1..<OCID>"
21+
22+
23+
class TestYourHandler(AsyncHTTPTestCase):
24+
def get_app(self):
25+
return Application([(r"/hello", CompatibilityCheckHandler)])
26+
27+
def setUp(self):
28+
super().setUp()
29+
os.environ["ODSC_MODEL_COMPARTMENT_OCID"] = TestDataset.SERVICE_COMPARTMENT_ID
30+
reload(ads.config)
31+
reload(ads.aqua)
32+
reload(ads.aqua.extension.common_handler)
33+
34+
def tearDown(self):
35+
super().tearDown()
36+
os.environ.pop("ODSC_MODEL_COMPARTMENT_OCID", None)
37+
reload(ads.config)
38+
reload(ads.aqua)
39+
reload(ads.aqua.extension.common_handler)
40+
41+
def test_get_ok(self):
42+
response = self.fetch("/hello", method="GET")
43+
assert json.loads(response.body)["status"] == "ok"
44+
45+
def test_get_compatible_status(self):
46+
os.environ["ODSC_MODEL_COMPARTMENT_OCID"] = ""
47+
os.environ["CONDA_BUCKET_NS"] = AQUA_GA_LIST[0]
48+
reload(ads.common)
49+
reload(ads.aqua)
50+
reload(ads.aqua.extension.common_handler)
51+
response = self.fetch("/hello", method="GET")
52+
assert json.loads(response.body)["status"] == "compatible"
53+
54+
def test_raise_not_compatible_error(self):
55+
os.environ["ODSC_MODEL_COMPARTMENT_OCID"] = ""
56+
os.environ["CONDA_BUCKET_NS"] = "test-namespace"
57+
reload(ads.common)
58+
reload(ads.aqua)
59+
reload(ads.aqua.extension.common_handler)
60+
response = self.fetch("/hello", method="GET")
61+
body = json.loads(response.body)
62+
assert body["status"] == 404
63+
assert (
64+
body["reason"]
65+
== "The AI Quick actions extension is not compatible in the given region."
66+
)

0 commit comments

Comments
 (0)