From e2af206ad46bc4dd7f1b6d607b7f33e89ddbfa5b Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Wed, 28 Mar 2018 12:22:34 +0800 Subject: newton UT for capacity_check fail in hypervisor fail due to out of RAM Change-Id: I9ae1dbfb1398bfa1516e69396275f6ee8f7084a9 Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang --- newton/newton/resource/tests/test_capacity.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'newton') diff --git a/newton/newton/resource/tests/test_capacity.py b/newton/newton/resource/tests/test_capacity.py index fa585237..662325ad 100644 --- a/newton/newton/resource/tests/test_capacity.py +++ b/newton/newton/resource/tests/test_capacity.py @@ -13,6 +13,7 @@ # limitations under the License. import mock +import json from rest_framework import status @@ -42,6 +43,15 @@ MOCK_GET_HYPER_STATATICS_RESPONSE = { } } +MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFRAM = { + "hypervisor_statistics" : { + "vcpus_used" : 4, + "free_ram_mb" : 1*1024, + "vcpus" : 10, + "free_disk_gb" : 300 + } +} + MOCK_GET_STORAGE_RESPONSE = { "limits" : { "rate" : [], @@ -116,3 +126,25 @@ class TestCapacity(test_base.TestRequest): self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEqual({"result": False}, response.data) + @mock.patch.object(VimDriverUtils, 'get_session') + @mock.patch.object(VimDriverUtils, 'get_vim_info') + def test_capacity_check_nova_hypervisor_outofram(self, mock_get_vim_info, mock_get_session): + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = test_base.get_mock_session( + ["get"], { + "side_effect": [ + self._get_mock_response(MOCK_GET_TENANT_LIMIT_RESPONSE), + self._get_mock_response(MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFRAM), + self._get_mock_response(MOCK_GET_STORAGE_RESPONSE), + ] + }) + + response = self.client.post( + "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/capacity_check", + data=json.dumps(TEST_REQ_SUCCESS_SOURCE), + content_type='application/json', + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual({"result": False}, response.data) + -- cgit 1.2.3-korg From 5932bcb2b9c7fdbd66e3d8fea3928c1fec24527e Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Wed, 28 Mar 2018 12:29:13 +0800 Subject: Newton UT for capacity_check fail in hypervisor fail due to out of storage Change-Id: Ia460b88047de823a13386282c25cc5172ff9d500 Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang --- newton/newton/resource/tests/test_capacity.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'newton') diff --git a/newton/newton/resource/tests/test_capacity.py b/newton/newton/resource/tests/test_capacity.py index 662325ad..90d88944 100644 --- a/newton/newton/resource/tests/test_capacity.py +++ b/newton/newton/resource/tests/test_capacity.py @@ -43,6 +43,15 @@ MOCK_GET_HYPER_STATATICS_RESPONSE = { } } +MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFSTORAGE = { + "hypervisor_statistics" : { + "vcpus_used" : 4, + "free_ram_mb" : 120*1024, + "vcpus" : 10, + "free_disk_gb" : 3 + } +} + MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFRAM = { "hypervisor_statistics" : { "vcpus_used" : 4, @@ -148,3 +157,24 @@ class TestCapacity(test_base.TestRequest): self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEqual({"result": False}, response.data) + @mock.patch.object(VimDriverUtils, 'get_session') + @mock.patch.object(VimDriverUtils, 'get_vim_info') + def test_capacity_check_nova_hypervisor_outofstorage(self, mock_get_vim_info, mock_get_session): + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = test_base.get_mock_session( + ["get"], { + "side_effect": [ + self._get_mock_response(MOCK_GET_TENANT_LIMIT_RESPONSE), + self._get_mock_response(MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFSTORAGE), + self._get_mock_response(MOCK_GET_STORAGE_RESPONSE), + ] + }) + + response = self.client.post( + "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/capacity_check", + data=json.dumps(TEST_REQ_SUCCESS_SOURCE), + content_type='application/json', + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual({"result": False}, response.data) -- cgit 1.2.3-korg From 330ccef9b10bc9dfa90dfeeaa334087f905d6082 Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Wed, 28 Mar 2018 12:32:12 +0800 Subject: Netwon capacity_check_nova_hypervisor_outofvcpu Change-Id: I2b353dac77d1b580d6aa8fe02e8bcc958a027961 Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang --- newton/newton/resource/tests/test_capacity.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'newton') diff --git a/newton/newton/resource/tests/test_capacity.py b/newton/newton/resource/tests/test_capacity.py index 90d88944..7c6452b0 100644 --- a/newton/newton/resource/tests/test_capacity.py +++ b/newton/newton/resource/tests/test_capacity.py @@ -43,6 +43,15 @@ MOCK_GET_HYPER_STATATICS_RESPONSE = { } } +MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFVCPU = { + "hypervisor_statistics": { + "vcpus_used": 9, + "free_ram_mb": 120 * 1024, + "vcpus": 10, + "free_disk_gb": 300 + } +} + MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFSTORAGE = { "hypervisor_statistics" : { "vcpus_used" : 4, @@ -178,3 +187,26 @@ class TestCapacity(test_base.TestRequest): self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEqual({"result": False}, response.data) + + @mock.patch.object(VimDriverUtils, 'get_session') + @mock.patch.object(VimDriverUtils, 'get_vim_info') + def test_capacity_check_nova_hypervisor_outofvcpu(self, mock_get_vim_info, mock_get_session): + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = test_base.get_mock_session( + ["get"], { + "side_effect": [ + self._get_mock_response(MOCK_GET_TENANT_LIMIT_RESPONSE), + self._get_mock_response(MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFVCPU), + self._get_mock_response(MOCK_GET_STORAGE_RESPONSE), + ] + }) + + response = self.client.post( + "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/capacity_check", + data=json.dumps(TEST_REQ_SUCCESS_SOURCE), + content_type='application/json', + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual({"result": False}, response.data) + -- cgit 1.2.3-korg From 2165c7dd12c4e6447c875f8d261d9b802d1b4def Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Wed, 28 Mar 2018 12:36:37 +0800 Subject: Newton test_capacity_check_nova_limits_outofram Change-Id: I6efe5583695b63849936a90e71f7b46eaa98f226 Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang --- newton/newton/resource/tests/test_capacity.py | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'newton') diff --git a/newton/newton/resource/tests/test_capacity.py b/newton/newton/resource/tests/test_capacity.py index 7c6452b0..3cdc8473 100644 --- a/newton/newton/resource/tests/test_capacity.py +++ b/newton/newton/resource/tests/test_capacity.py @@ -43,6 +43,18 @@ MOCK_GET_HYPER_STATATICS_RESPONSE = { } } +MOCK_GET_TENANT_LIMIT_RESPONSE_OUTOFRAM = { + "limits": { + "rate": [], + "absolute": { + "maxTotalRAMSize": 128 * 1024, + "totalRAMUsed": 127 * 1024, + "totalCoresUsed": 4, + "maxTotalCores": 20, + } + } +} + MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFVCPU = { "hypervisor_statistics": { "vcpus_used": 9, @@ -210,3 +222,25 @@ class TestCapacity(test_base.TestRequest): self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEqual({"result": False}, response.data) + @mock.patch.object(VimDriverUtils, 'get_session') + @mock.patch.object(VimDriverUtils, 'get_vim_info') + def test_capacity_check_nova_limits_outofram(self, mock_get_vim_info, mock_get_session): + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = test_base.get_mock_session( + ["get"], { + "side_effect": [ + self._get_mock_response(MOCK_GET_TENANT_LIMIT_RESPONSE_OUTOFRAM), + self._get_mock_response(MOCK_GET_HYPER_STATATICS_RESPONSE), + self._get_mock_response(MOCK_GET_STORAGE_RESPONSE), + ] + }) + + response = self.client.post( + "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/capacity_check", + data=json.dumps(TEST_REQ_SUCCESS_SOURCE), + content_type='application/json', + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual({"result": False}, response.data) + -- cgit 1.2.3-korg From d9fed0d8ec902f8be6a223aed9548f6807878361 Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Wed, 28 Mar 2018 12:42:25 +0800 Subject: Newton capacity_check_volume_limits_outofstorage Change-Id: I09af1f3c60d7b43090e67605281cbc7b94d57ede Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang --- newton/newton/resource/tests/test_capacity.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'newton') diff --git a/newton/newton/resource/tests/test_capacity.py b/newton/newton/resource/tests/test_capacity.py index 3cdc8473..1c721b58 100644 --- a/newton/newton/resource/tests/test_capacity.py +++ b/newton/newton/resource/tests/test_capacity.py @@ -43,6 +43,16 @@ MOCK_GET_HYPER_STATATICS_RESPONSE = { } } +MOCK_GET_STORAGE_RESPONSE_OOS = { + "limits": { + "rate": [], + "absolute": { + "totalGigabytesUsed": 498, + "maxTotalVolumeGigabytes": 500, + } + } +} + MOCK_GET_TENANT_LIMIT_RESPONSE_OUTOFRAM = { "limits": { "rate": [], @@ -243,4 +253,26 @@ class TestCapacity(test_base.TestRequest): self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEqual({"result": False}, response.data) + + @mock.patch.object(VimDriverUtils, 'get_session') + @mock.patch.object(VimDriverUtils, 'get_vim_info') + def test_capacity_check_volume_limits_outofstorage(self, mock_get_vim_info, mock_get_session): + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = test_base.get_mock_session( + ["get"], { + "side_effect": [ + self._get_mock_response(MOCK_GET_TENANT_LIMIT_RESPONSE), + self._get_mock_response(MOCK_GET_HYPER_STATATICS_RESPONSE), + self._get_mock_response(MOCK_GET_STORAGE_RESPONSE_OOS), + ] + }) + + response = self.client.post( + "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/capacity_check", + data=json.dumps(TEST_REQ_SUCCESS_SOURCE), + content_type='application/json', + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual({"result": False}, response.data) -- cgit 1.2.3-korg