summaryrefslogtreecommitdiffstats
path: root/newton
diff options
context:
space:
mode:
authorzhang ab <zhanganbing@chinamobile.com>2018-03-28 05:34:39 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-28 05:34:39 +0000
commite38d564a2d382b6d338ef119b80d54a1ebd9447c (patch)
treef293ad4544be3343b42f236ea630c78a3759a244 /newton
parentb79e5b94b71c30c0013cef0cf55b2e28ea3622bb (diff)
parent5a4a7d74efb9a86823f7650a080d3b58e18c8078 (diff)
Merge changes I30528936,I7ff4321c,Ib603915b,I82644ff6,I8fdc222f, ...
* changes: Ocata capacity_check_volume_limits_outofstorage Ocata test_capacity_check_nova_limits_outofram Ocata capacity_check_nova_hypervisor_outofvcpu Ocata UT for capacity_check fail in hypervisor Ocata UT for capacity_check fail in hypervisor Newton capacity_check_volume_limits_outofstorage Newton test_capacity_check_nova_limits_outofram Netwon capacity_check_nova_hypervisor_outofvcpu Newton UT for capacity_check fail in hypervisor newton UT for capacity_check fail in hypervisor Add TC capacity_check_volume_limits_outofstorage Add TC test_capacity_check_nova_limits_outofram Add TC test_capacity_check_hypervisor_outofvcpu Add TC UT for capacity_check fail in hypervisor
Diffstat (limited to 'newton')
-rw-r--r--newton/newton/resource/tests/test_capacity.py160
1 files changed, 160 insertions, 0 deletions
diff --git a/newton/newton/resource/tests/test_capacity.py b/newton/newton/resource/tests/test_capacity.py
index fa585237..1c721b58 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,55 @@ 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": [],
+ "absolute": {
+ "maxTotalRAMSize": 128 * 1024,
+ "totalRAMUsed": 127 * 1024,
+ "totalCoresUsed": 4,
+ "maxTotalCores": 20,
+ }
+ }
+}
+
+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,
+ "free_ram_mb" : 120*1024,
+ "vcpus" : 10,
+ "free_disk_gb" : 3
+ }
+}
+
+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 +166,113 @@ 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)
+
+ @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)
+
+ @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)
+
+ @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)
+
+ @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)
+