diff options
author | Bin Yang <bin.yang@windriver.com> | 2018-09-11 12:59:21 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-11 12:59:21 +0000 |
commit | 4caa99144fefa576136ff700ea246fa9705c3206 (patch) | |
tree | 511f09772abe7e01ad4a5491d109761ec1be8d8a /ocata | |
parent | 676ec47b90e7d98b3bf6655578e1c22b04c6e3a9 (diff) | |
parent | 5727afb520db08eb088df17ad628413ec72fe548 (diff) |
Merge changes I88d79049,If6ceaec6,I3877f034,I1e7693c1,Ie916b35a, ...
* changes:
Test case for get_epoch_now_usecond in ocata
Test case for buildBacklogsOneVIM in ocata
Test case for clearBacklogsOneVIM in ocata
Test case for vesagent getBacklogsOneVIM in ocata
Test case for vesagent delete API in ocata
Add test case for vesagent_ctrl in ocata
Diffstat (limited to 'ocata')
-rw-r--r-- | ocata/ocata/vesagent/event_domain/tests_fault_vm.py | 36 | ||||
-rw-r--r-- | ocata/ocata/vesagent/tests.py | 97 |
2 files changed, 132 insertions, 1 deletions
diff --git a/ocata/ocata/vesagent/event_domain/tests_fault_vm.py b/ocata/ocata/vesagent/event_domain/tests_fault_vm.py new file mode 100644 index 00000000..376f1fee --- /dev/null +++ b/ocata/ocata/vesagent/event_domain/tests_fault_vm.py @@ -0,0 +1,36 @@ +# Copyright (c) Intel Corporation, 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 + +import unittest +import json + +from ocata.vesagent.vespublish import publishAnyEventToVES +from common.utils.restcall import _call_req +from ocata.vesagent.event_domain import fault_vm + + + +class FaultVMTest(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + def test_get_epoch_now_usecond(self): + epoch = fault_vm.get_epoch_now_usecond() + self.assertGreater(epoch, 1) + pass diff --git a/ocata/ocata/vesagent/tests.py b/ocata/ocata/vesagent/tests.py index 9f34b3f5..242f7d19 100644 --- a/ocata/ocata/vesagent/tests.py +++ b/ocata/ocata/vesagent/tests.py @@ -21,7 +21,8 @@ from rest_framework import status from django.core.cache import cache from common.msapi import extsys - +from ocata.vesagent import vesagent_ctrl +from ocata.vesagent.tasks import scheduleBacklogs MOCK_VIM_INFO = { @@ -45,6 +46,7 @@ MOCK_VIM_INFO = { class VesAgentCtrlTest(unittest.TestCase): def setUp(self): self.client = Client() + self.view = vesagent_ctrl.VesAgentCtrl() def tearDown(self): pass @@ -57,3 +59,96 @@ class VesAgentCtrlTest(unittest.TestCase): response = self.client.get("/api/multicloud-ocata/v0/windriver-hudson-dc_RegionOne/vesagent") self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) + + @mock.patch.object(vesagent_ctrl.VesAgentCtrl, 'buildBacklogsOneVIM') + @mock.patch.object(extsys, 'get_vim_by_id') + def test_post(self, mock_get_vim_by_id, mock_buildBacklogsOneVIM): + mock_get_vim_by_id.return_value = MOCK_VIM_INFO + mock_buildBacklogsOneVIM.return_value = "mocked vesagent_backlogs" + mock_request = mock.Mock() + mock_request.META = {"testkey":"testvalue"} + mock_request.data = {"testdatakey":"testdatavalue"} + + response = self.view.post(request=mock_request, vimid="windriver-hudson-dc_RegionOne") + self.assertEquals(status.HTTP_201_CREATED, response.status_code) + + pass + + @mock.patch.object(vesagent_ctrl.VesAgentCtrl, 'clearBacklogsOneVIM') + @mock.patch.object(extsys, 'get_vim_by_id') + def test_delete(self, mock_get_vim_by_id, mock_clearBacklogsOneVIM): + mock_get_vim_by_id.return_value = MOCK_VIM_INFO + mock_clearBacklogsOneVIM.return_value = "mocked vesagent_backlogs" + mock_request = mock.Mock() + mock_request.META = {"testkey": "testvalue"} + + response = self.view.delete(request=mock_request, vimid="windriver-hudson-dc_RegionOne") + self.assertEquals(status.HTTP_200_OK, response.status_code) + + pass + + @mock.patch.object(cache, 'get') + def test_getBacklogsOneVIM(self, mock_get): + mock_vesagent_config = {"backlogs": [{"backlog_uuid": "ce2d7597-22e1-4239-890f-bc303bd67076", "server_id": "c4b575fa-ed85-4642-ab4b-335cb5744721", "tenant_id": "0e148b76ee8c42f78d37013bf6b7b1ae", "api_method": "GET", "source": "onap-aaf", "api_link": "/onaplab_RegionOne/compute/v2.1/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", "domain": "fault", "type": "vm", "tenant": "VIM"}], "poll_interval_default": 10, "vimid": "onaplab_RegionOne", "subscription": {"username": "user", "password": "password", "endpoint": "http://127.0.0.1:9005/sample"}} + mock_get.return_value = json.dumps(mock_vesagent_config) + + vesAgentConfig = self.view.getBacklogsOneVIM(vimid="windriver-hudson-dc_RegionOne") + self.assertEquals(vesAgentConfig, mock_vesagent_config) + + pass + + @mock.patch.object(cache, 'set') + @mock.patch.object(cache, 'get') + def test_clearBacklogsOneVIM(self, mock_get, mock_set): + mock_VesAgentBacklogs_vimlist = ["windriver-hudson-dc_RegionOne"] + mock_vesagent_config = {"backlogs": [{"backlog_uuid": "ce2d7597-22e1-4239-890f-bc303bd67076", + "server_id": "c4b575fa-ed85-4642-ab4b-335cb5744721", + "tenant_id": "0e148b76ee8c42f78d37013bf6b7b1ae", "api_method": "GET", + "source": "onap-aaf", + "api_link": "/onaplab_RegionOne/compute/v2.1/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", + "domain": "fault", "type": "vm", "tenant": "VIM"}], + "poll_interval_default": 10, "vimid": "onaplab_RegionOne", + "subscription": {"username": "user", "password": "password", + "endpoint": "http://127.0.0.1:9005/sample"}} + + mock_get.side_effect= [ + json.dumps(mock_VesAgentBacklogs_vimlist), + json.dumps(mock_vesagent_config) + ] + + + mock_set.return_value = "mocked cache set" + + result = self.view.clearBacklogsOneVIM(vimid="windriver-hudson-dc_RegionOne") + self.assertEquals(0, result) + + + pass + + @mock.patch.object(scheduleBacklogs, 'delay') + @mock.patch.object(cache, 'set') + @mock.patch.object(cache, 'get') + def test_buildBacklogsOneVIM(self, mock_get, mock_set, mock_scheduleBacklogs_delay): + mock_VesAgentBacklogs_vimlist = ["windriver-hudson-dc_RegionOne"] + mock_vesagent_config = {"backlogs": [{"backlog_uuid": "ce2d7597-22e1-4239-890f-bc303bd67076", + "server_id": "c4b575fa-ed85-4642-ab4b-335cb5744721", + "tenant_id": "0e148b76ee8c42f78d37013bf6b7b1ae", "api_method": "GET", + "source": "onap-aaf", + "api_link": "/onaplab_RegionOne/compute/v2.1/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", + "domain": "fault", "type": "vm", "tenant": "VIM"}], + "poll_interval_default": 10, "vimid": "windriver-hudson-dc_RegionOne", + "ves_subscription": {"username": "user", "password": "password", + "endpoint": "http://127.0.0.1:9005/sample"}} + + mock_get.side_effect= [ + json.dumps(mock_VesAgentBacklogs_vimlist), + ] + + mock_set.return_value = "mocked cache set" + mock_scheduleBacklogs_delay.return_value = "mocked delay" + + VesAgentBacklogsConfig = self.view.buildBacklogsOneVIM(vimid="windriver-hudson-dc_RegionOne", + vesagent_config = mock_vesagent_config) + self.assertIsNotNone(VesAgentBacklogsConfig) + + pass |