diff options
Diffstat (limited to 'vio')
-rw-r--r-- | vio/vio/tests/test_aai_client.py | 129 | ||||
-rw-r--r-- | vio/vio/tests/test_restcall.py | 35 |
2 files changed, 164 insertions, 0 deletions
diff --git a/vio/vio/tests/test_aai_client.py b/vio/vio/tests/test_aai_client.py index 80d5200..ea333d1 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,109 @@ 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) 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) |