Skip to content

Commit

Permalink
fix(clusters): machineTypes list returns no data PLA-867 (#386)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bbatha committed Apr 13, 2022
1 parent e2f0f7b commit 2769721
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion gradient/api_sdk/repositories/machine_types.py
Expand Up @@ -13,17 +13,23 @@ def get_request_url(self, **kwargs):
def _get_api_url(self, **kwargs):
return config.config.CONFIG_HOST

def _get_request_params(self, kwargs):
return {'includePublicClusters': 'true'}

def _get_instance_dicts(self, data, cluster_id=None, **kwargs):
vm_types_dicts = {} # vmType["label"]: vmType dict
for cluster_list_of_vms in data.values():
current_cluster_id = cluster_list_of_vms[0]["clusters"][0]["id"]

for vm in cluster_list_of_vms:
if not vm["isAvailable"]:
continue
vm_type = vm["vmType"]
vm_type_label = vm_type["label"]
vm_types_dicts.setdefault(vm_type_label, vm_type)

clusters = vm_types_dicts[vm_type_label].setdefault("clusters", [])
clusters = vm_types_dicts[vm_type_label].setdefault(
"clusters", [])
if current_cluster_id not in clusters:
clusters.append(current_cluster_id)

Expand Down
11 changes: 6 additions & 5 deletions tests/functional/test_clusters.py
Expand Up @@ -127,6 +127,7 @@ class TestListVmTypes(object):

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

@mock.patch("gradient.api_sdk.clients.http_client.requests.get")
def test_should_send_get_request_and_print_list_of_machine_types(self, get_patched):
Expand All @@ -139,7 +140,7 @@ def test_should_send_get_request_and_print_list_of_machine_types(self, get_patch
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

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

Expand All @@ -154,7 +155,7 @@ def test_should_send_get_request_and_print_list_of_vm_machine_types_filtered_by_
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

@mock.patch("gradient.api_sdk.clients.http_client.requests.get")
def test_should_send_get_request_and_print_list_of_machine_types_but_none_found(self, get_patched):
Expand All @@ -166,7 +167,7 @@ def test_should_send_get_request_and_print_list_of_machine_types_but_none_found(
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

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

Expand All @@ -181,7 +182,7 @@ def test_should_print_proper_message_when_wrong_api_key_was_used(self, get_patch
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

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

0 comments on commit 2769721

Please sign in to comment.