From 4793bd71a31347d0c2ab5f494c9129081689e423 Mon Sep 17 00:00:00 2001 From: Nitin Garg Date: Thu, 3 Oct 2024 07:36:21 +0000 Subject: [PATCH] fix some var names --- .../testing_on_gke/examples/run-gke-tests.sh | 8 ++--- .../examples/utils/utils_test.py | 33 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/perfmetrics/scripts/testing_on_gke/examples/run-gke-tests.sh b/perfmetrics/scripts/testing_on_gke/examples/run-gke-tests.sh index a811ca7de7..9159d5a209 100755 --- a/perfmetrics/scripts/testing_on_gke/examples/run-gke-tests.sh +++ b/perfmetrics/scripts/testing_on_gke/examples/run-gke-tests.sh @@ -298,10 +298,10 @@ function installDependencies() { sudo apt install docker-ce -y fi # Ensure that gcloud monitoring tools are installed. - # pip install --upgrade google-cloud-storage - # pip install --ignore-installed --upgrade google-api-python-client - # pip install --ignore-installed --upgrade google-cloud - pip install --upgrade google-cloud-monitoring + pip install --upgrade google-cloud-storage 1>/dev/null + pip install --ignore-installed --upgrade google-api-python-client 1>/dev/null + pip install --ignore-installed --upgrade google-cloud 1>/dev/null + pip install --upgrade google-cloud-monitoring 1>/dev/null # Ensure that jq is installed. which jq || sudo apt-get install -y jq # Ensure sudoless docker is installed. diff --git a/perfmetrics/scripts/testing_on_gke/examples/utils/utils_test.py b/perfmetrics/scripts/testing_on_gke/examples/utils/utils_test.py index 1c4d2b3b57..daa207d161 100644 --- a/perfmetrics/scripts/testing_on_gke/examples/utils/utils_test.py +++ b/perfmetrics/scripts/testing_on_gke/examples/utils/utils_test.py @@ -34,8 +34,8 @@ def setUpClass(self): self.start = '2024-09-25 06:32:22 UTC' self.end = '2024-09-25 07:06:22 UTC' - def test_get_memory(self): - low1, high1 = get_memory_from_monitoring_api( + def test_get_memory_from_monitoring_api(self): + low, high = get_memory_from_monitoring_api( project_id=self.project_id, cluster_name=self.cluster_name, pod_name=self.pod_name, @@ -43,11 +43,12 @@ def test_get_memory(self): start_epoch=self.start_epoch, end_epoch=self.end_epoch, ) - self.assertLessEqual(low1, high1) - self.assertGreater(high1, 0) - def test_get_cpu(self): - low1, high1 = get_cpu_from_monitoring_api( + self.assertLessEqual(low, high) + self.assertGreater(high, 0) + + def test_get_cpu_from_monitoring_api(self): + low, high = get_cpu_from_monitoring_api( project_id=self.project_id, cluster_name=self.cluster_name, pod_name=self.pod_name, @@ -55,8 +56,9 @@ def test_get_cpu(self): start_epoch=self.start_epoch, end_epoch=self.end_epoch, ) - self.assertLessEqual(low1, high1) - self.assertGreater(high1, 0) + + self.assertLessEqual(low, high) + self.assertGreater(high, 0) def test_timestamp_to_epoch(self): self.assertEqual(timestamp_to_epoch('2024-08-21T19:20:25'), 1724268025) @@ -66,7 +68,7 @@ def test_timestamp_to_epoch_with_nznano(self): timestamp_to_epoch('2024-08-21T19:20:25.547456'), 1724268025 ) - def test_resource_limit(self): + def test_resource_limits(self): inputs = [ { 'nodeType': 'n2-standard-32', @@ -96,17 +98,20 @@ def test_resource_limit(self): {'nodeType': 'n2-standard-1', 'expected_error': True}, {'nodeType': 'unknown-machine-type', 'expected_error': True}, ] + for input in inputs: - self.assertEqual(dict, type(input)) - try: + + if input['expected_error']: + + with self.assertRaises(utils.UnknownMachineTypeError): + resource_limits = utils.resource_limits(input['nodeType']) + else: resource_limits = utils.resource_limits(input['nodeType']) + self.assertEqual( input['expected_limits_cpu'], resource_limits[0]['cpu'], ) - self.assertFalse(input['expected_error']) - except utils.UnknownMachineTypeError: - self.assertTrue(input['expected_error']) if __name__ == '__main__':