summaryrefslogtreecommitdiffstats
path: root/vio
diff options
context:
space:
mode:
Diffstat (limited to 'vio')
-rw-r--r--vio/vio/tests/test_aai_client.py198
-rw-r--r--vio/vio/tests/test_apiv2_controller.py52
-rw-r--r--vio/vio/tests/test_restcall.py35
3 files changed, 285 insertions, 0 deletions
diff --git a/vio/vio/tests/test_aai_client.py b/vio/vio/tests/test_aai_client.py
index 80d5200..17a0047 100644
--- a/vio/vio/tests/test_aai_client.py
+++ b/vio/vio/tests/test_aai_client.py
@@ -13,6 +13,7 @@
import mock
import unittest
+from vio.pub.exceptions import VimDriverVioException
from vio.pub.utils import restcall
@@ -61,6 +62,28 @@ class TestAAIClient(unittest.TestCase):
mock_call.assert_called_once()
@mock.patch.object(restcall, "call_req")
+ def test_add_flavors_with_hpa(self, mock_call):
+ flavors = {
+ "flavors": [{
+ "name": "onap.small",
+ "id": "1",
+ "vcpus": 1,
+ "ram": 512,
+ "disk": 10,
+ "ephemeral": 0,
+ "swap": 0,
+ "is_public": True,
+ "links": [{"href": "http://fake-url"}],
+ "is_disabled": False,
+ "extra_specs": {},
+ }]
+ }
+ self.view._get_ovsdpdk_capabilities = mock.MagicMock()
+ self.view._get_ovsdpdk_capabilities.return_value = {}
+ self.view.add_flavors(flavors)
+ mock_call.assert_called_once()
+
+ @mock.patch.object(restcall, "call_req")
def test_add_images(self, mock_call):
images = {
"images": [{
@@ -167,3 +190,178 @@ class TestAAIClient(unittest.TestCase):
}
self.view._del_azs(rsp)
mock_call.assert_called_once()
+
+ @mock.patch.object(restcall, "call_req")
+ def test_del_hpa(self, mock_call):
+ mock_call.return_value = [0]
+ rsp = {
+ "flavor-id": "id1",
+ "hpa-capabilities": {
+ "hpa-capability": [{
+ "resource-version": "v1",
+ "hpa-capability-id": "id2"
+ }]
+ }
+ }
+ self.view._del_hpa(rsp)
+ mock_call.assert_called_once()
+
+ @mock.patch.object(restcall, "call_req")
+ def test_del_vim(self, mock_call):
+ resp = {
+ "resource-version": "1"
+ }
+ self.view.get_vim = mock.MagicMock()
+ self.view.get_vim.return_value = resp
+ mock_call.return_value = [0, "", "", ""]
+ self.view.delete_vim()
+ mock_call.assert_called_once()
+
+ @mock.patch.object(restcall, "call_req")
+ def test_del_vim_fail(self, mock_call):
+ resp = {
+ "resource-version": "1"
+ }
+ self.view.get_vim = mock.MagicMock()
+ self.view.get_vim.return_value = resp
+ mock_call.return_value = [1, "", "", ""]
+ self.assertRaises(VimDriverVioException, self.view.delete_vim)
+
+ @mock.patch.object(restcall, "call_req")
+ def test_update_vim(self, mock_call):
+ resp = {
+ "resource-version": "1"
+ }
+ self.view.get_vim = mock.MagicMock()
+ self.view.get_vim.return_value = resp
+ content = {
+ "tenants": [],
+ "images": [],
+ "flavors": [],
+ "networks": [],
+ "hypervisors": []
+ }
+ self.view.update_vim(content)
+ mock_call.assert_called_once()
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa(self, mock_call):
+ self.view._get_hpa_basic_capabilities = mock.MagicMock()
+ self.view._get_hpa_basic_capabilities.return_value = {"hpa": "basic"}
+ self.view._get_cpupinning_capabilities = mock.MagicMock()
+ self.view._get_cpupinning_capabilities.return_value = {"hpa": "basic"}
+ self.view._get_cputopology_capabilities = mock.MagicMock()
+ self.view._get_cputopology_capabilities.return_value = {"hpa": "basic"}
+ self.view._get_hugepages_capabilities = mock.MagicMock()
+ self.view._get_hugepages_capabilities.return_value = {"hpa": "basic"}
+ self.view._get_numa_capabilities = mock.MagicMock()
+ self.view._get_numa_capabilities.return_value = {"hpa": "basic"}
+ self.view._get_storage_capabilities = mock.MagicMock()
+ self.view._get_storage_capabilities.return_value = {"hpa": "basic"}
+ self.view._get_instruction_set_capabilities = mock.MagicMock()
+ self.view._get_instruction_set_capabilities.return_value = {
+ "hpa": "basic"}
+ self.view._get_pci_passthrough_capabilities = mock.MagicMock()
+ self.view._get_pci_passthrough_capabilities.return_value = {
+ "hpa": "basic"}
+ self.view._get_ovsdpdk_capabilities = mock.MagicMock()
+ self.view._get_ovsdpdk_capabilities.return_value = {"hpa": "basic"}
+ ret = self.view._get_hpa_capabilities({"extra_specs": {}})
+ self.assertEqual([{"hpa": "basic"}]*9, ret)
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_basic(self, mock_call):
+ flavor = {
+ "vcpus": 1,
+ "ram": 1024
+ }
+ ret = self.view._get_hpa_basic_capabilities(flavor)
+ self.assertEqual(len(ret["hpa-feature-attributes"]), 2)
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_cpupin(self, mock_call):
+ extra = {
+ "hw:cpu_policy": "cpu_policy",
+ "hw:cpu_thread_policy": "thread_policy"
+ }
+ ret = self.view._get_cpupinning_capabilities(extra)
+ self.assertEqual(len(ret["hpa-feature-attributes"]), 2)
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_cputopo(self, mock_call):
+ extra = {
+ "hw:cpu_sockets": 2,
+ "hw:cpu_cores": 2,
+ "hw:cpu_threads": 4
+ }
+ ret = self.view._get_cputopology_capabilities(extra)
+ self.assertEqual(len(ret["hpa-feature-attributes"]), 3)
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_hugepage_large(self, mock_call):
+ extra = {
+ "hw:mem_page_size": "large"
+ }
+ ret = self.view._get_hugepages_capabilities(extra)
+ self.assertIn(
+ "2", ret["hpa-feature-attributes"][0]["hpa-attribute-value"])
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_hugepage_small(self, mock_call):
+ extra = {
+ "hw:mem_page_size": "small"
+ }
+ ret = self.view._get_hugepages_capabilities(extra)
+ self.assertIn(
+ "4", ret["hpa-feature-attributes"][0]["hpa-attribute-value"])
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_hugepage_int(self, mock_call):
+ extra = {
+ "hw:mem_page_size": 8,
+ }
+ ret = self.view._get_hugepages_capabilities(extra)
+ self.assertIn(
+ "8", ret["hpa-feature-attributes"][0]["hpa-attribute-value"])
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_hugepage_any(self, mock_call):
+ extra = {
+ "hw:mem_page_size": "any",
+ }
+ ret = self.view._get_hugepages_capabilities(extra)
+ self.assertEqual(0, len(ret["hpa-feature-attributes"]))
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_numa(self, mock_call):
+ extra = {
+ "hw:numa_nodes": 1,
+ "hw:numa_cpus.0": 1,
+ "hw:numa_mem.0": 1024,
+ }
+ ret = self.view._get_numa_capabilities(extra)
+ self.assertEqual(3, len(ret["hpa-feature-attributes"]))
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_storage(self, mock_call):
+ extra = {
+ "disk": 10,
+ }
+ ret = self.view._get_storage_capabilities(extra)
+ self.assertEqual(3, len(ret["hpa-feature-attributes"]))
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_instru(self, mock_call):
+ extra = {
+ "hw:capabilities:cpu_info:features": "avx",
+ }
+ ret = self.view._get_instruction_set_capabilities(extra)
+ self.assertEqual(1, len(ret["hpa-feature-attributes"]))
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_hpa_pci(self, mock_call):
+ extra = {
+ "pci_passthrough:alias": "gpu-nvidia-x86-0011-0022:1",
+ }
+ ret = self.view._get_pci_passthrough_capabilities(extra)
+ self.assertEqual(3, len(ret["hpa-feature-attributes"]))
diff --git a/vio/vio/tests/test_apiv2_controller.py b/vio/vio/tests/test_apiv2_controller.py
new file mode 100644
index 0000000..132a105
--- /dev/null
+++ b/vio/vio/tests/test_apiv2_controller.py
@@ -0,0 +1,52 @@
+# Copyright (c) 2018 VMware, 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.
+
+import mock
+import unittest
+
+from keystoneauth1.identity import v2 as keystone_v2
+from keystoneauth1.identity import v3 as keystone_v3
+
+from vio.api_v2.api_router import controller_builder as cb
+from vio.pub.msapi import extsys
+
+
+class TestAPIv2Controller(unittest.TestCase):
+
+ @mock.patch.object(keystone_v2, "Password")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_get_vim_session_v2(self, mock_getvim, mock_kv2):
+ mock_getvim.return_value = {
+ "url": "http://aa/v2",
+ "userName": "admin",
+ "password": "admin",
+ "domain": "default"
+ }
+ mock_kv2.return_value = mock.Mock()
+ cb._get_vim_auth_session("vmware_vio", "tenant1")
+
+ @mock.patch.object(keystone_v3, "Password")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_get_vim_session_v3(self, mock_getvim, mock_kv3):
+ mock_getvim.return_value = {
+ "url": "http://aa/v3",
+ "userName": "admin",
+ "password": "admin",
+ "domain": "default"
+ }
+ mock_kv3.return_value = mock.Mock()
+ cb._get_vim_auth_session("vmware_vio", "tenant1")
+
+ def test_convert_default_val(self):
+ self.assertEqual(None, cb._convert_default_value("None"))
+ self.assertEqual(True, cb._convert_default_value("true"))
+ self.assertEqual(False, cb._convert_default_value("false"))
diff --git a/vio/vio/tests/test_restcall.py b/vio/vio/tests/test_restcall.py
index 051dddf..b04aec1 100644
--- a/vio/vio/tests/test_restcall.py
+++ b/vio/vio/tests/test_restcall.py
@@ -10,6 +10,7 @@
import mock
import unittest
+import urllib2
from vio.pub.utils import restcall
@@ -64,3 +65,37 @@ class TestRestCall(unittest.TestCase):
ret = restcall.call_req("http://onap.org/", "user", "pass",
restcall.rest_no_auth, "vim", "GET")
self.assertEqual(expect_ret, ret)
+
+ @mock.patch("httplib2.Http.request")
+ def test_call_req_not_200(self, mock_req):
+ mock_resp = {
+ "status": "404"
+ }
+ resp_content = "hello"
+ mock_req.return_value = mock_resp, resp_content
+ expect_ret = [1, resp_content, "404", mock_resp]
+ ret = restcall.call_req("http://onap.org/", "user", "pass",
+ restcall.rest_no_auth, "vim", "GET")
+ self.assertEqual(expect_ret, ret)
+
+ @mock.patch("traceback.format_exc")
+ @mock.patch("sys.exc_info")
+ @mock.patch("httplib2.Http.request")
+ def test_call_req_response_not_ready(self, mock_req, mock_sys,
+ mock_traceback):
+ mock_sys.return_value = "httplib.ResponseNotReady"
+ mock_req.side_effect = [Exception("httplib.ResponseNotReady")] * 3
+ expect_ret = [1, "Unable to connect to http://onap.org/vim", "", ""]
+ ret = restcall.call_req("http://onap.org/", "user", "pass",
+ restcall.rest_no_auth, "vim", "GET")
+ self.assertEqual(expect_ret, ret)
+ self.assertEqual(3, mock_req.call_count)
+
+ @mock.patch("httplib2.Http.request")
+ def test_call_req_url_err(self, mock_req):
+ urlerr = urllib2.URLError("urlerror")
+ mock_req.side_effect = [urlerr]
+ expect_ret = [2, str(urlerr), "", ""]
+ ret = restcall.call_req("http://onap.org/", "user", "pass",
+ restcall.rest_no_auth, "vim", "GET")
+ self.assertEqual(expect_ret, ret)