Skip to content

Commit e6768ad

Browse files
committed
bug fixes
1 parent 7e022b9 commit e6768ad

File tree

5 files changed

+169
-53
lines changed

5 files changed

+169
-53
lines changed

ads/opctl/backend/marketplace/helm_helper.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
from ads.opctl import logger
1414
from ads.opctl.backend.marketplace.marketplace_utils import (
1515
StatusIcons,
16-
get_docker_bearer_token, WARNING, Color,
16+
get_docker_bearer_token,
17+
WARNING,
18+
Color,
1719
)
1820

1921

@@ -46,13 +48,18 @@ def run_helm_install(
4648
)
4749
helm_cmd = [
4850
_HELM_BINARY_,
49-
cmd,
51+
HelmCommand.Upgrade,
5052
name,
5153
chart,
5254
*_get_as_flags_(
53-
namespace=namespace, values=values_yaml_path, version=version, timeout="300s",**kwargs
55+
namespace=namespace,
56+
values=values_yaml_path,
57+
version=version,
58+
timeout="300s",
59+
**kwargs,
5460
),
55-
"--wait"
61+
"--wait",
62+
"-i",
5663
]
5764
print(f"\n{Color.BLUE}{' '.join(helm_cmd)}{Color.END}")
5865
return subprocess.run(helm_cmd)

ads/opctl/operator/lowcode/feature_store_marketplace/models/apigw_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import Union, Optional
2+
from typing import Union, Optional, List
33

44
from ads.opctl.operator.lowcode.feature_store_marketplace.models.serializable_yaml_model import (
55
SerializableYAMLModel,

ads/opctl/operator/lowcode/feature_store_marketplace/operator_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ def detect_or_create_stack(apigw_config: APIGatewayConfig):
139139
print(
140140
f"Auto-detected feature store APIGW stack: {stacks[0].display_name}({stacks[0].id}"
141141
)
142+
click.prompt(
143+
f"Auto detected existing feature store stack: '{stacks[0].display_name}({stacks[0].id}'\n.Provide an OCID to use or",
144+
default=stacks[0].id,
145+
)
142146
return stacks[0].id
143147
elif len(stacks) == 0:
144148
if not click.confirm(
@@ -268,7 +272,7 @@ def update_resource_manager_stack(
268272
)
269273
)
270274
update_stack_details = oci.resource_manager.models.UpdateStackDetails()
271-
groups = ",".join(apigw_config.authorized_user_groups)
275+
groups = ",".join(apigw_config.authorized_user_groups.split(","))
272276
update_stack_details.variables = {
273277
"nlb_id": nlb_id,
274278
"tenancy_ocid": apigw_config.root_compartment_id,

tests/unitary/with_extras/operator/feature-store/test_helm_helper_util.py

Lines changed: 147 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
import pandas as pd
44
import pytest
55

6-
from ads.opctl.backend.marketplace.helm_helper import run_helm_install, _HELM_BINARY_, HelmCommand, _get_as_flags_, \
7-
run_helm_list, run_helm_login, _check_if_chart_already_exists_, check_helm_pull, HelmPullStatus
8-
from unittest.mock import patch, Mock, create_autospec
6+
from ads.opctl.backend.marketplace.helm_helper import (
7+
run_helm_install,
8+
_HELM_BINARY_,
9+
HelmCommand,
10+
_get_as_flags_,
11+
run_helm_list,
12+
run_helm_login,
13+
_check_if_chart_already_exists_,
14+
check_helm_pull,
15+
HelmPullStatus,
16+
)
17+
from unittest.mock import patch, Mock
918

1019
name = "NAME"
1120
chart = "CHART_NAME"
@@ -28,9 +37,13 @@ def test_helm_install(mock_check_chart_exist: Mock, subprocess_mock: Mock):
2837
name,
2938
chart,
3039
*_get_as_flags_(
31-
namespace=namespace, values=values_yaml_path, version=version, timeout="300s", **kwargs
40+
namespace=namespace,
41+
values=values_yaml_path,
42+
version=version,
43+
timeout="300s",
44+
**kwargs,
3245
),
33-
"--wait"
46+
"--wait",
3447
]
3548

3649
subprocess_mock.assert_called_with(helm_cmd)
@@ -48,34 +61,65 @@ def test_helm_upgrade(mock_check_chart_exist: Mock, subprocess_mock: Mock):
4861
name,
4962
chart,
5063
*_get_as_flags_(
51-
namespace=namespace, values=values_yaml_path, version=version, timeout="300s", **kwargs
64+
namespace=namespace,
65+
values=values_yaml_path,
66+
version=version,
67+
timeout="300s",
68+
**kwargs,
5269
),
53-
"--wait"
70+
"--wait",
5471
]
5572
subprocess_mock.assert_called_with(helm_cmd)
5673

5774

5875
@patch("ads.opctl.backend.marketplace.helm_helper.subprocess.run")
5976
def test_helm_list_returns_single_value(subprocess_mock: Mock):
60-
header = ["NAME", "NAMESPACE", "REVISION", "UPDATED", "STATUS", "CHART", "APP VERSION"]
61-
data = ["fs-dp-api-test", "feature-store", "4", "2023-11-22 10:22:13.425579296 +0530 IST", "deployed",
62-
"feature-store-dp-api-1.0", "0.1.270.marketplace-vuls"]
77+
header = [
78+
"NAME",
79+
"NAMESPACE",
80+
"REVISION",
81+
"UPDATED",
82+
"STATUS",
83+
"CHART",
84+
"APP VERSION",
85+
]
86+
data = [
87+
"fs-dp-api-test",
88+
"feature-store",
89+
"4",
90+
"2023-11-22 10:22:13.425579296 +0530 IST",
91+
"deployed",
92+
"feature-store-dp-api-1.0",
93+
"0.1.270.marketplace-vuls",
94+
]
6395
std_out = "\t".join(header) + "\n" + "\t".join(data)
6496

65-
list_result = subprocess.CompletedProcess(args="", returncode=0, stdout=std_out.encode())
97+
list_result = subprocess.CompletedProcess(
98+
args="", returncode=0, stdout=std_out.encode()
99+
)
66100
subprocess_mock.return_value = list_result
67101
result = run_helm_list(namespace, **kwargs)
68102
assert len(result) == 1
69103
assert "NAME" in result.columns
70-
assert any(result['NAME'] == "fs-dp-api-test")
104+
assert any(result["NAME"] == "fs-dp-api-test")
71105

72106

73107
@patch("ads.opctl.backend.marketplace.helm_helper.subprocess.run")
74108
def test_helm_list_returns_no_value(subprocess_mock: Mock):
75-
header = ["NAME", "NAMESPACE", "REVISION", "UPDATED", "STATUS", "CHART", "APP VERSION"]
109+
header = [
110+
"NAME",
111+
"NAMESPACE",
112+
"REVISION",
113+
"UPDATED",
114+
"STATUS",
115+
"CHART",
116+
"APP VERSION",
117+
]
76118
std_out = "\t".join(header)
77119

78-
list_result = subprocess.CompletedProcess(args="", returncode=0, stdout=std_out.encode())
120+
list_result = subprocess.CompletedProcess(
121+
args="", returncode=0, stdout=std_out.encode()
122+
)
79123
subprocess_mock.return_value = list_result
80124
result = run_helm_list(namespace, **kwargs)
81125
assert len(result) == 0
@@ -84,7 +128,9 @@ def test_helm_list_returns_no_value(subprocess_mock: Mock):
84128

85129
@patch("ads.opctl.backend.marketplace.helm_helper.subprocess.run")
86130
def test_helm_list_throws_exception(subprocess_mock: Mock):
87-
list_result = subprocess.CompletedProcess(args="", returncode=1, stderr="Some Exception")
131+
list_result = subprocess.CompletedProcess(
132+
args="", returncode=1, stderr="Some Exception"
133+
)
88134
subprocess_mock.return_value = list_result
89135
with pytest.raises(Exception) as e_info:
90136
run_helm_list(namespace, **kwargs)
@@ -94,75 +140,133 @@ def test_helm_list_throws_exception(subprocess_mock: Mock):
94140
def test_helm_login_success(subprocess_mock: Mock):
95141
subprocess_return = subprocess.CompletedProcess(args="", returncode=0)
96142
subprocess_mock.return_value = subprocess_return
97-
run_helm_login('oci_repo', 'token')
143+
run_helm_login("oci_repo", "token")
98144
subprocess_mock.assert_called_with(
99-
['helm', 'registry', 'login', 'oci_repo', '--username', 'BEARER_TOKEN', '--password', 'token'],
100-
capture_output=True)
145+
[
146+
"helm",
147+
"registry",
148+
"login",
149+
"oci_repo",
150+
"--username",
151+
"BEARER_TOKEN",
152+
"--password",
153+
"token",
154+
],
155+
capture_output=True,
156+
)
101157

102158

103159
@patch("ads.opctl.backend.marketplace.helm_helper.subprocess.run")
104160
def test_helm_login_throws_exception(subprocess_mock: Mock):
105-
subprocess_return = subprocess.CompletedProcess(args="", returncode=1, stderr="Some Exception")
161+
subprocess_return = subprocess.CompletedProcess(
162+
args="", returncode=1, stderr="Some Exception"
163+
)
106164
subprocess_mock.return_value = subprocess_return
107165
with pytest.raises(Exception) as e_info:
108-
run_helm_login('oci_repo', 'token')
166+
run_helm_login("oci_repo", "token")
109167
subprocess_mock.assert_called_with(
110-
['helm', 'registry', 'login', 'oci_repo', '--username', 'BEARER_TOKEN', '--password', 'token'],
111-
capture_output=True)
168+
[
169+
"helm",
170+
"registry",
171+
"login",
172+
"oci_repo",
173+
"--username",
174+
"BEARER_TOKEN",
175+
"--password",
176+
"token",
177+
],
178+
capture_output=True,
179+
)
112180

113181

114182
@patch("ads.opctl.backend.marketplace.helm_helper.subprocess.run")
115183
def test_helm_pull_success(subprocess_mock: Mock):
116184
subprocess_return = subprocess.CompletedProcess(args="", returncode=0, stderr=b"")
117185
subprocess_mock.return_value = subprocess_return
118-
assert check_helm_pull('helm_chart_url', 'version') == HelmPullStatus.SUCCESS
186+
assert check_helm_pull("helm_chart_url", "version") == HelmPullStatus.SUCCESS
119187
subprocess_mock.assert_called_with(
120-
['helm', 'pull', 'helm_chart_url', '--version', 'version'],
121-
capture_output=True)
188+
["helm", "pull", "helm_chart_url", "--version", "version"], capture_output=True
189+
)
122190

123191

124192
@patch("ads.opctl.backend.marketplace.helm_helper.subprocess.run")
125193
def test_helm_pull_unauthorized(subprocess_mock: Mock):
126-
subprocess_return = subprocess.CompletedProcess(args="", returncode=1, stderr=b"unauthorized")
194+
subprocess_return = subprocess.CompletedProcess(
195+
args="", returncode=1, stderr=b"unauthorized"
196+
)
127197
subprocess_mock.return_value = subprocess_return
128-
assert check_helm_pull('helm_chart_url', 'version') == HelmPullStatus.AUTHENTICATION_FAILURE
198+
assert (
199+
check_helm_pull("helm_chart_url", "version")
200+
== HelmPullStatus.AUTHENTICATION_FAILURE
201+
)
129202
subprocess_mock.assert_called_with(
130-
['helm', 'pull', 'helm_chart_url', '--version', 'version'],
131-
capture_output=True)
203+
["helm", "pull", "helm_chart_url", "--version", "version"], capture_output=True
204+
)
132205

133206

134207
@patch("ads.opctl.backend.marketplace.helm_helper.subprocess.run")
135208
def test_helm_pull_unknown_failure(subprocess_mock: Mock):
136-
subprocess_return = subprocess.CompletedProcess(args="", returncode=1, stderr=b"some failure")
209+
subprocess_return = subprocess.CompletedProcess(
210+
args="", returncode=1, stderr=b"some failure"
211+
)
137212
subprocess_mock.return_value = subprocess_return
138-
assert check_helm_pull('helm_chart_url', 'version') == HelmPullStatus.UNKNOWN_FAILURE
213+
assert (
214+
check_helm_pull("helm_chart_url", "version") == HelmPullStatus.UNKNOWN_FAILURE
215+
)
139216
subprocess_mock.assert_called_with(
140-
['helm', 'pull', 'helm_chart_url', '--version', 'version'],
141-
capture_output=True)
217+
["helm", "pull", "helm_chart_url", "--version", "version"], capture_output=True
218+
)
142219

143220

144221
def test_get_as_flags_():
145-
args = {
146-
"key1": "value1",
147-
"key2": "value2"
148-
}
222+
args = {"key1": "value1", "key2": "value2"}
149223
assert _get_as_flags_(**args) == ["--key1", "value1", "--key2", "value2"]
150224

151225

152226
@patch("ads.opctl.backend.marketplace.helm_helper.run_helm_list")
153227
def test_check_helm_chart_exist_when_chart_do_exist(helm_list_cmd: Mock):
154-
header = ["NAME", "NAMESPACE", "REVISION", "UPDATED", "STATUS", "CHART", "APP VERSION"]
155-
data = ["fs-dp-api-test", "feature-store", "4", "2023-11-22 10:22:13.425579296 +0530 IST", "deployed",
156-
"feature-store-dp-api-1.0", "0.1.270.marketplace-vuls"]
228+
header = [
229+
"NAME",
230+
"NAMESPACE",
231+
"REVISION",
232+
"UPDATED",
233+
"STATUS",
234+
"CHART",
235+
"APP VERSION",
236+
]
237+
data = [
238+
"fs-dp-api-test",
239+
"feature-store",
240+
"4",
241+
"2023-11-22 10:22:13.425579296 +0530 IST",
242+
"deployed",
243+
"feature-store-dp-api-1.0",
244+
"0.1.270.marketplace-vuls",
245+
]
157246
helm_list_cmd.return_value = pd.DataFrame([data], columns=header)
158247
assert _check_if_chart_already_exists_("fs-dp-api-test", namespace)
159248

160249

161250
@patch("ads.opctl.backend.marketplace.helm_helper.run_helm_list")
162251
def test_check_helm_chart_exist_when_chart_do_not_exist(helm_list_cmd: Mock):
163-
header = ["NAME", "NAMESPACE", "REVISION", "UPDATED", "STATUS", "CHART", "APP VERSION"]
164-
data = ["some-other-chart", "feature-store", "4", "2023-11-22 10:22:13.425579296 +0530 IST", "deployed",
165-
"feature-store-dp-api-1.0", "0.1.270.marketplace-vuls"]
252+
header = [
253+
"NAME",
254+
"NAMESPACE",
255+
"REVISION",
256+
"UPDATED",
257+
"STATUS",
258+
"CHART",
259+
"APP VERSION",
260+
]
261+
data = [
262+
"some-other-chart",
263+
"feature-store",
264+
"4",
265+
"2023-11-22 10:22:13.425579296 +0530 IST",
266+
"deployed",
267+
"feature-store-dp-api-1.0",
268+
"0.1.270.marketplace-vuls",
269+
]
166270
helm_list_cmd.return_value = pd.DataFrame([data], columns=header)
167271
assert not _check_if_chart_already_exists_("fs-dp-api-test", namespace)
168272

tests/unitary/with_extras/operator/feature-store/test_marketplace_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
get_docker_bearer_token,
77
_export_helm_chart_,
88
list_container_images,
9-
get_tags_map,
9+
_get_tags_map,
1010
)
1111

1212

@@ -18,13 +18,14 @@ def test_set_kubernetes_session_token_env():
1818
assert os.getenv("OCI_CLI_PROFILE") == profile_name
1919

2020

21+
@patch("ads.common.auth.default_signer")
2122
@patch("ads.opctl.backend.marketplace.marketplace_utils.OCIClientFactory")
22-
def test_get_docker_bearer_token(client_factory: Mock):
23+
def test_get_docker_bearer_token(client_factory: Mock, signer_mock: Mock):
2324
mock_token = '{"token":"TOKEN"}'
2425
token_client = Mock()
2526
token_client.call_api.return_value.data = mock_token
2627
client_factory.return_value.create_client.return_value = token_client
27-
ocir_repo = "iad.ocir.io/idogsu2ylimg/feature-store-data-plane-api-helidon/"
28+
ocir_repo = "iad.ocir.io/namespace/feature-store-data-plane-api-helidon/"
2829
assert get_docker_bearer_token(ocir_repo) == mock_token
2930
token_client.call_api.assert_called_once_with(
3031
resource_path="/docker/token", method="GET", response_type="SecurityToken"
@@ -62,6 +63,6 @@ def test_export_helm_chart_to_container_registry(list_api: Mock, export_api: Moc
6263
)
6364
listing_details = Mock()
6465
listing_details.container_tag_pattern = [pattern]
65-
result = get_tags_map(listing_details)
66+
result = _get_tags_map(listing_details)
6667
assert pattern in result
6768
assert result[pattern] == f"{pattern}-1"

0 commit comments

Comments
 (0)