Skip to content

Commit 2769721

Browse files
authored
fix(clusters): machineTypes list returns no data PLA-867 (#386)
* Include public cluster data by default. You cannot use --clusterId to see public cluster data because of the way the endpoint works. * When there are inactive vmTypes in the cluster the response does not include enough info to render the table properly so inactive instances are now filtered from the response.
1 parent e2f0f7b commit 2769721

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

gradient/api_sdk/repositories/machine_types.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ def get_request_url(self, **kwargs):
1313
def _get_api_url(self, **kwargs):
1414
return config.config.CONFIG_HOST
1515

16+
def _get_request_params(self, kwargs):
17+
return {'includePublicClusters': 'true'}
18+
1619
def _get_instance_dicts(self, data, cluster_id=None, **kwargs):
1720
vm_types_dicts = {} # vmType["label"]: vmType dict
1821
for cluster_list_of_vms in data.values():
1922
current_cluster_id = cluster_list_of_vms[0]["clusters"][0]["id"]
2023

2124
for vm in cluster_list_of_vms:
25+
if not vm["isAvailable"]:
26+
continue
2227
vm_type = vm["vmType"]
2328
vm_type_label = vm_type["label"]
2429
vm_types_dicts.setdefault(vm_type_label, vm_type)
2530

26-
clusters = vm_types_dicts[vm_type_label].setdefault("clusters", [])
31+
clusters = vm_types_dicts[vm_type_label].setdefault(
32+
"clusters", [])
2733
if current_cluster_id not in clusters:
2834
clusters.append(current_cluster_id)
2935

tests/functional/test_clusters.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class TestListVmTypes(object):
127127

128128
RESPONSE_JSON_WHEN_WRONG_API_KEY_WAS_USED = {"status": 400, "message": "Invalid API token"}
129129
EXPECTED_STDOUT_WHEN_WRONG_API_KEY_WAS_USED = "Failed to fetch data: Invalid API token\n"
130+
DEFAULT_PARAMS = {'includePublicClusters': 'true'}
130131

131132
@mock.patch("gradient.api_sdk.clients.http_client.requests.get")
132133
def test_should_send_get_request_and_print_list_of_machine_types(self, get_patched):
@@ -139,7 +140,7 @@ def test_should_send_get_request_and_print_list_of_machine_types(self, get_patch
139140
get_patched.assert_called_once_with(self.URL,
140141
headers=EXPECTED_HEADERS,
141142
json=None,
142-
params=None)
143+
params=self.DEFAULT_PARAMS)
143144

144145
assert EXPECTED_HEADERS["X-API-Key"] != "some_key"
145146

@@ -154,7 +155,7 @@ def test_should_send_get_request_and_print_list_of_vm_machine_types_filtered_by_
154155
get_patched.assert_called_once_with(self.URL,
155156
headers=EXPECTED_HEADERS,
156157
json=None,
157-
params=None)
158+
params=self.DEFAULT_PARAMS)
158159

159160
@mock.patch("gradient.api_sdk.clients.http_client.requests.get")
160161
def test_should_send_get_request_and_print_list_of_machine_types_but_none_found(self, get_patched):
@@ -166,7 +167,7 @@ def test_should_send_get_request_and_print_list_of_machine_types_but_none_found(
166167
get_patched.assert_called_once_with(self.URL,
167168
headers=EXPECTED_HEADERS,
168169
json=None,
169-
params=None)
170+
params=self.DEFAULT_PARAMS)
170171

171172
assert result.output == "No data found\n"
172173

@@ -181,7 +182,7 @@ def test_should_print_proper_message_when_wrong_api_key_was_used(self, get_patch
181182
get_patched.assert_called_once_with(self.URL,
182183
headers=EXPECTED_HEADERS,
183184
json=None,
184-
params=None)
185+
params=self.DEFAULT_PARAMS)
185186

186187
assert result.output == self.EXPECTED_STDOUT_WHEN_WRONG_API_KEY_WAS_USED
187188
assert EXPECTED_HEADERS["X-API-Key"] != "some_key"
@@ -198,4 +199,4 @@ def test_should_read_options_defined_in_a_config_file(self, get_patched, vm_mach
198199
get_patched.assert_called_once_with(self.URL,
199200
headers=EXPECTED_HEADERS_WITH_CHANGED_API_KEY,
200201
json=None,
201-
params=None)
202+
params=self.DEFAULT_PARAMS)

0 commit comments

Comments
 (0)