Skip to content

Commit 31c4d38

Browse files
Addressing Review comments
1 parent 9720f2d commit 31c4d38

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

ads/aqua/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self) -> None:
6464
set_auth("resource_principal")
6565
self._auth = default_signer({"service_endpoint": OCI_ODSC_SERVICE_ENDPOINT})
6666
self.ds_client = oc.OCIClientFactory(**self._auth).data_science
67+
self.compute_client = oc.OCIClientFactory(**default_signer()).compute
6768
self.logging_client = oc.OCIClientFactory(**default_signer()).logging_management
6869
self.identity_client = oc.OCIClientFactory(**default_signer()).identity
6970
self.region = extract_region(self._auth)

ads/aqua/ui.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ def list_capacity_reservations(self, **kwargs) -> list:
102102
"""
103103
compartment_id = kwargs.pop("compartment_id", COMPARTMENT_OCID)
104104
logger.info(f"Loading Capacity reservations from compartment: {compartment_id}")
105-
compute_client = oc.OCIClientFactory(**default_signer()).compute
106-
reservations = compute_client.list_compute_capacity_reservations(
105+
106+
reservations = self.compute_client.list_compute_capacity_reservations(
107107
compartment_id=compartment_id, **kwargs
108108
)
109-
return reservations.data
109+
return sanitize_response(
110+
oci_client=self.compute_client, response=reservations.data
111+
)
110112

111113
@telemetry(entry_point="plugin=ui&action=list_compartments", name="aqua")
112114
def list_compartments(self) -> str:

ads/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
OCI_IDENTITY_SERVICE_ENDPOINT = os.environ.get("OCI_IDENTITY_SERVICE_ENDPOINT")
1515
NB_SESSION_COMPARTMENT_OCID = os.environ.get("NB_SESSION_COMPARTMENT_OCID")
1616
PROJECT_OCID = os.environ.get("PROJECT_OCID") or os.environ.get("PIPELINE_PROJECT_OCID")
17-
IS_BYOR_ENABLED = os.environ.get("ALLOWLISTED_FOR_BYOR")
17+
IS_BYOR_ENABLED = os.environ.get("ALLOWLISTED_FOR_BYOR", False)
1818
NB_SESSION_OCID = os.environ.get("NB_SESSION_OCID")
1919
USER_OCID = os.environ.get("USER_OCID")
2020
OCI_RESOURCE_PRINCIPAL_VERSION = os.environ.get("OCI_RESOURCE_PRINCIPAL_VERSION")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"availability_domain": "<AD>",
4+
"compartment_id": "ocid1.compartment.oc1..<OCID>",
5+
"defined_tags": {},
6+
"display_name": "test-reservation",
7+
"freeform_tags": {},
8+
"id": "ocid1.capacityreservation.oc1.iad...<OCID>",
9+
"is_default_reservation": false,
10+
"lifecycle_state": "ACTIVE",
11+
"reserved_instance_count": 0,
12+
"time_created": "2025-05-14T07:17:53.795000Z",
13+
"used_instance_count": 0
14+
}
15+
]

tests/unitary/with_extras/aqua/test_ui.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,46 @@ def tearDownClass(cls):
9797
reload(ads.aqua)
9898
reload(ads.aqua.ui)
9999

100+
def test_list_capacity_reservations(self):
101+
capacity_reservations_list = os.path.join(
102+
self.curr_dir, "test_data/ui/capacity_reservations_list.json"
103+
)
104+
with open(capacity_reservations_list, "r") as _file:
105+
capacity_reservations = json.load(_file)
106+
107+
self.app.compute_client.list_compute_capacity_reservations = MagicMock(
108+
return_value=oci.response.Response(
109+
status=200,
110+
request=MagicMock(),
111+
headers=MagicMock(),
112+
data=[
113+
oci.core.models.ComputeCapacityReservationSummary(
114+
**capacity_reservation
115+
)
116+
for capacity_reservation in capacity_reservations
117+
],
118+
)
119+
)
120+
results = self.app.list_capacity_reservations()
121+
expected_attributes = {
122+
"id",
123+
"compartmentId",
124+
"displayName",
125+
"definedTags",
126+
"freeformTags",
127+
"lifecycleState",
128+
"availabilityDomain",
129+
"reservedInstanceCount",
130+
"usedInstanceCount",
131+
"isDefaultReservation",
132+
"timeCreated",
133+
}
134+
for result in results:
135+
self.assertTrue(
136+
expected_attributes.issuperset(set(result)), "Attributes mismatch"
137+
)
138+
assert len(results) == len(capacity_reservations)
139+
100140
def test_list_log_groups(self):
101141
"""Test to lists all log groups for the specified compartment or tenancy"""
102142
log_groups_list = os.path.join(

tests/unitary/with_extras/aqua/test_ui_handler.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def tearDownClass(cls):
5050
reload(ads.aqua)
5151
reload(ads.aqua.extension.ui_handler)
5252

53+
@patch("ads.aqua.ui.AquaUIApp.list_capacity_reservations")
54+
def test_list_capacity_reservations(self, mock_list_reservations):
55+
self.ui_handler.request.path = "aqua/capacityreservations"
56+
self.ui_handler.get(id="")
57+
mock_list_reservations.assert_called_with(
58+
compartment_id=TestDataset.USER_COMPARTMENT_ID
59+
)
60+
5361
@patch("ads.aqua.ui.AquaUIApp.list_log_groups")
5462
def test_list_log_groups(self, mock_list_log_groups):
5563
"""Test get method to fetch log groups"""

0 commit comments

Comments
 (0)