summaryrefslogtreecommitdiffstats
path: root/ocata
diff options
context:
space:
mode:
Diffstat (limited to 'ocata')
-rw-r--r--ocata/.gitignore2
-rw-r--r--ocata/ocata/registration/tests/test_registration.py39
-rw-r--r--ocata/ocata/resource/tests/__init__.py14
-rw-r--r--ocata/ocata/resource/tests/test_capacity.py120
4 files changed, 174 insertions, 1 deletions
diff --git a/ocata/.gitignore b/ocata/.gitignore
index e86d02b0..06570027 100644
--- a/ocata/.gitignore
+++ b/ocata/.gitignore
@@ -8,4 +8,6 @@ logs/*.log
.tox
.coverage
htmlcov/
+coverage.xml
+test-reports/
diff --git a/ocata/ocata/registration/tests/test_registration.py b/ocata/ocata/registration/tests/test_registration.py
index 7ab7e306..fc2eed25 100644
--- a/ocata/ocata/registration/tests/test_registration.py
+++ b/ocata/ocata/registration/tests/test_registration.py
@@ -21,6 +21,43 @@ from newton_base.tests import mock_info
from newton_base.tests import test_base
from newton_base.util import VimDriverUtils
+OCATA_MOCK_VIM_INFO = {
+ "createTime": "2017-04-01 02:22:27",
+ "domain": "Default",
+ "name": "TiS_R4",
+ "password": "admin",
+ "tenant": "admin",
+ "type": "openstack",
+ "url": "http://128.224.180.14:5000/v3",
+ "userName": "admin",
+ "vendor": "WindRiver",
+ "version": "newton",
+ "vimId": "windriver-hudson-dc_RegionOne",
+ 'cloud_owner': 'windriver-hudson-dc',
+ 'cloud_region_id': 'RegionOne',
+ 'cloud_extra_info':
+ '{'
+ '"ovsDpdk":{'
+ '"version": "v1",'
+ '"arch": "Intel64",'
+ '"libname":"dataProcessingAccelerationLibrary",'
+ '"libvalue":"v12.1",'
+ '}'
+ '}',
+ 'cloud_epa_caps':
+ '{'
+ '"huge_page":"true",'
+ '"cpu_pinning":"true",'
+ '"cpu_thread_policy":"true",'
+ '"numa_aware":"true",'
+ '"sriov":"true",'
+ '"dpdk_vswitch":"true",'
+ '"rdt":"false",'
+ '"numa_locality_pci":"true"'
+ '}',
+ 'insecure': 'True',
+}
+
MOCK_GET_TENANT_RESPONSE = {
"projects":[
{"id": "1", "name": "project"},
@@ -195,7 +232,7 @@ class TestFlavors(test_base.TestRequest):
self, mock_get_vim_info, mock_get_session):
restcall.req_to_aai = mock.Mock()
restcall.req_to_aai.return_value = (0, {}, status.HTTP_200_OK)
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
+ mock_get_vim_info.return_value = OCATA_MOCK_VIM_INFO
mock_get_session.return_value = test_base.get_mock_session(
["get"], {
"side_effect": [
diff --git a/ocata/ocata/resource/tests/__init__.py b/ocata/ocata/resource/tests/__init__.py
new file mode 100644
index 00000000..afa702d3
--- /dev/null
+++ b/ocata/ocata/resource/tests/__init__.py
@@ -0,0 +1,14 @@
+# Copyright (c) 2017-2018 Wind River Systems, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
diff --git a/ocata/ocata/resource/tests/test_capacity.py b/ocata/ocata/resource/tests/test_capacity.py
new file mode 100644
index 00000000..071997e3
--- /dev/null
+++ b/ocata/ocata/resource/tests/test_capacity.py
@@ -0,0 +1,120 @@
+# Copyright (c) 2017-2018 Wind River Systems, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import mock
+
+from rest_framework import status
+
+from common.utils import restcall
+from newton_base.tests import mock_info
+from newton_base.tests import test_base
+from newton_base.util import VimDriverUtils
+
+MOCK_GET_TENANT_LIMIT_RESPONSE = {
+ "limits" : {
+ "rate" : [],
+ "absolute" : {
+ "maxTotalRAMSize" : 128*1024,
+ "totalRAMUsed" : 8*1024,
+ "totalCoresUsed" : 4,
+ "maxTotalCores" : 20,
+ }
+ }
+}
+
+MOCK_GET_HYPER_STATATICS_RESPONSE = {
+ "hypervisor_statistics" : {
+ "vcpus_used" : 4,
+ "free_ram_mb" : 120*1024,
+ "vcpus" : 10,
+ "free_disk_gb" : 300
+ }
+}
+
+MOCK_GET_STORAGE_RESPONSE = {
+ "limits" : {
+ "rate" : [],
+ "absolute" : {
+ "totalGigabytesUsed" : 200,
+ "maxTotalVolumeGigabytes" : 500,
+ }
+ }
+}
+
+TEST_REQ_SUCCESS_SOURCE = {
+ "vCPU": "4",
+ "Memory": "4096",
+ "Storage": "200"
+}
+
+TEST_REQ_FAILED_SOURCE = {
+ "vCPU": "17",
+ "Memory": "4096",
+ "Storage": "200"
+}
+
+class TestCapacity(test_base.TestRequest):
+ def setUp(self):
+ super(TestCapacity, self).setUp()
+
+ def _get_mock_response(self, return_value=None):
+ mock_response = mock.Mock(spec=test_base.MockResponse)
+ mock_response.status_code = status.HTTP_200_OK
+ mock_response.json.return_value = return_value
+ return mock_response
+
+ @mock.patch.object(VimDriverUtils, 'get_session')
+ @mock.patch.object(VimDriverUtils, 'get_vim_info')
+ def test_capacity_check_success(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),
+ ]
+ })
+
+ response = self.client.post((
+ "/api/%s/v0/windriver-hudson-dc_RegionOne/"
+ "capacity_check" % test_base.MULTIVIM_VERSION),
+ TEST_REQ_SUCCESS_SOURCE,
+ HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+
+ self.assertEquals(status.HTTP_200_OK, response.status_code)
+ self.assertEqual({"result": True}, response.data)
+
+ @mock.patch.object(VimDriverUtils, 'get_session')
+ @mock.patch.object(VimDriverUtils, 'get_vim_info')
+ def test_capacity_check_nova_limits_failed(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),
+ ]
+ })
+
+ response = self.client.post((
+ "/api/%s/v0/windriver-hudson-dc_RegionOne/"
+ "capacity_check" % test_base.MULTIVIM_VERSION),
+ TEST_REQ_FAILED_SOURCE,
+ HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+
+ self.assertEquals(status.HTTP_200_OK, response.status_code)
+ self.assertEqual({"result": False}, response.data)
+