Skip to content

Commit 6a8f4e8

Browse files
VipulMascarenhasmingkang111
authored andcommitted
show extension for default region
1 parent 4d1d648 commit 6a8f4e8

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

ads/aqua/extension/common_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +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
1314

1415

1516
class ADSVersionHandler(AquaAPIhandler):
@@ -27,6 +28,8 @@ class CompatibilityCheckHandler(AquaAPIhandler):
2728
def get(self):
2829
if ODSC_MODEL_COMPARTMENT_OCID:
2930
return self.finish(dict(status="ok"))
31+
elif known_realm():
32+
return self.finish(dict(status="compatible"))
3033
else:
3134
raise AquaResourceAccessError(
3235
f"The AI Quick actions extension is not compatible in the given region."

ads/aqua/utils.py

Lines changed: 13 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,15 @@ 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
741+
given namespace.
742+
Returns
743+
-------
744+
bool:
745+
Return True if aqua service is available.
746+
747+
"""
748+
return os.environ.get("CONDA_BUCKET_NS", "#") in AQUA_GA_LIST
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
assert (
62+
json.loads(response.body)["message"]
63+
== "Authorization Failed: The resource you're looking for isn't accessible."
64+
)

0 commit comments

Comments
 (0)