diff options
Diffstat (limited to 'windriver/titanium_cloud/vesagent/tests')
5 files changed, 0 insertions, 619 deletions
diff --git a/windriver/titanium_cloud/vesagent/tests/__init__.py b/windriver/titanium_cloud/vesagent/tests/__init__.py deleted file mode 100644 index 5f8b0d18..00000000 --- a/windriver/titanium_cloud/vesagent/tests/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# 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/windriver/titanium_cloud/vesagent/tests/tests_fault_vm.py b/windriver/titanium_cloud/vesagent/tests/tests_fault_vm.py deleted file mode 100644 index 880c1d5d..00000000 --- a/windriver/titanium_cloud/vesagent/tests/tests_fault_vm.py +++ /dev/null @@ -1,228 +0,0 @@ -# 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 - -import unittest -import json - -from titanium_cloud.vesagent import vespublish -from common.utils import restcall -from titanium_cloud.vesagent.event_domain import fault_vm - -MOCK_TOKEN_RESPONSE = { - "access": - {"token": {"issued_at": "2018-05-10T16:56:56.000000Z", - "expires": "2018-05-10T17:56:56.000000Z", - "id": "4a832860dd744306b3f66452933f939e", - "tenant": {"domain": {"id": "default", "name": "Default"}, - "enabled": "true", "id": "0e148b76ee8c42f78d37013bf6b7b1ae", "name": "VIM"}}, - "serviceCatalog": [], "user": {"domain": {"id": "default", "name": "Default"}, - "id": "ba76c94eb5e94bb7bec6980e5507aae2", "name": "demo"}} -} - -MOCK_SERVERS_GET_RESPONSE = { - "servers": [ - {"id": "c4b575fa-ed85-4642-ab4b-335cb5744721", - "links": [{ - "href": "http://10.12.25.2:8774/v2.1/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", - "rel": "self"}, - { - "href": "http://10.12.25.2:8774/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", - "rel": "bookmark"}], - "name": "onap-aaf"}] -} - -MOCK_BACKLOG_INPUT = { - "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" -} - -MOCK_BACKLOG_INPUT_wo_tenant_id = { - "backlog_uuid": "ce2d7597-22e1-4239-890f-bc303bd67076", - "server_id": "c4b575fa-ed85-4642-ab4b-335cb5744721", - "source": "onap-aaf", - "api_link": - "/onaplab_RegionOne/compute/v2.1/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", - "domain": "fault", "type": "vm", "tenant": "VIM" -} - -MOCK_BACKLOG_INPUT_wo_tenant = { - "backlog_uuid": "ce2d7597-22e1-4239-890f-bc303bd67076", - "server_id": "c4b575fa-ed85-4642-ab4b-335cb5744721", - "source": "onap-aaf", - "domain": "fault", "type": "vm", } - -MOCK_BACKLOG_INPUT_wo_server_id = { - "source": "onap-aaf", - "domain": "fault", "type": "vm", "tenant": "VIM"} - -MOCK_BACKLOG_INPUT_wo_server = {"domain": "fault", "type": "vm", "tenant": "VIM"} - -MOCK_SERVER_GET_RESPONSE = { - "server": {"wrs-res:topology": "node:0, 4096MB, pgsize:2M, vcpus:0,1, pol:sha", - "OS-EXT-STS:task_state": None, - "addresses": { - "oam_onap_BTHY": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:6c:0d:6b", - "version": 4, "addr": "10.0.13.1", "OS-EXT-IPS:type": "fixed"}, - {"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:6c:0d:6b", "version": 4, - "addr": "10.12.5.185", "OS-EXT-IPS:type": "floating"}]}, - "links": [], "image": {"id": "6e219e86-cd94-4989-9119-def29aa10b12", "links": []}, - "wrs-if:nics": [], "wrs-sg:server_group": "", - "OS-EXT-STS:vm_state": "active", "OS-SRV-USG:launched_at": "2018-04-26T08:01:28.000000", - "flavor": {}, "id": "c4b575fa-ed85-4642-ab4b-335cb5744721", - "security_groups": [{"name": "onap_sg_BTHY"}], - "user_id": "ba76c94eb5e94bb7bec6980e5507aae2", - "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", - "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 1, - "OS-EXT-AZ:availability_zone": "nova", "metadata": {}, - "status": "ACTIVE", "updated": "2018-04-26T08:01:28Z", - "hostId": "17acc9f2ae4f618c314e4cdf0c206585b895bc72a9ec57e57b254133", - "OS-SRV-USG:terminated_at": None, "wrs-res:pci_devices": "", - "wrs-res:vcpus": [2, 2, 2], "key_name": "onap_key_BTHY", "name": "onap-aaf", - "created": "2018-04-26T08:01:20Z", "tenant_id": "0e148b76ee8c42f78d37013bf6b7b1ae", - "os-extended-volumes:volumes_attached": [], "config_drive": ""}} - -MOCK_SERVER_GET_RESPONSE_empty = {} - -MOCK_vesAgentConfig = { - "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_vesAgentState = {"ce2d7597-22e1-4239-890f-bc303bd67076": {"timestamp": 1525975400}} -MOCK_oneBacklog = { - "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"} - - -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) - - @mock.patch.object(restcall, '_call_req') - def test_buildBacklog_fault_vm(self, mock_call_req): - mock_call_req.side_effect = [ - (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), - (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") - ] - backlog = fault_vm.buildBacklog_fault_vm( - vimid="windriver-hudson-dc_RegionOne", - backlog_input=MOCK_BACKLOG_INPUT) - - self.assertIsNotNone(backlog) - - @mock.patch.object(restcall, '_call_req') - def test_buildBacklog_fault_vm_wo_tenant_id(self, mock_call_req): - mock_call_req.side_effect = [ - (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), - (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") - ] - backlog = fault_vm.buildBacklog_fault_vm( - vimid="windriver-hudson-dc_RegionOne", - backlog_input=MOCK_BACKLOG_INPUT_wo_tenant_id) - self.assertIsNotNone(backlog) - - @mock.patch.object(restcall, '_call_req') - def test_buildBacklog_fault_vm_wo_tenant(self, mock_call_req): - mock_call_req.side_effect = [ - (1, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body: failed"), - (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") - ] - backlog = fault_vm.buildBacklog_fault_vm( - vimid="windriver-hudson-dc_RegionOne", - backlog_input=MOCK_BACKLOG_INPUT_wo_tenant) - self.assertIsNone(backlog) - - @mock.patch.object(restcall, '_call_req') - def test_buildBacklog_fault_vm_wo_server_id(self, mock_call_req): - mock_call_req.side_effect = [ - (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), - (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") - ] - backlog = fault_vm.buildBacklog_fault_vm( - vimid="windriver-hudson-dc_RegionOne", - backlog_input=MOCK_BACKLOG_INPUT_wo_server_id) - self.assertIsNotNone(backlog) - - @mock.patch.object(restcall, '_call_req') - def test_buildBacklog_fault_vm_wo_server(self, mock_call_req): - mock_call_req.side_effect = [ - (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), - (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") - ] - backlog = fault_vm.buildBacklog_fault_vm( - vimid="windriver-hudson-dc_RegionOne", - backlog_input=MOCK_BACKLOG_INPUT_wo_server) - self.assertIsNotNone(backlog) - - @mock.patch.object(vespublish, 'publishAnyEventToVES') - @mock.patch.object(restcall, '_call_req') - def test_processBacklog_fault_vm( - self, mock_call_req, mock_publishAnyEventToVES): - mock_call_req.side_effect = [ - (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), - (0, json.dumps(MOCK_SERVER_GET_RESPONSE), "MOCKED response body") - ] - mock_publishAnyEventToVES.return_value = "mocked return value" - - result = fault_vm.processBacklog_fault_vm( - vesAgentConfig=MOCK_vesAgentConfig, - vesAgentState=MOCK_vesAgentState, - oneBacklog=MOCK_oneBacklog) - self.assertIsNone(result) - pass - - @mock.patch.object(vespublish, 'publishAnyEventToVES') - @mock.patch.object(restcall, '_call_req') - def test_processBacklog_fault_vm_wo_server( - self, mock_call_req, mock_publishAnyEventToVES): - mock_call_req.side_effect = [ - (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), - (0, json.dumps(MOCK_SERVER_GET_RESPONSE_empty), "MOCKED response body") - ] - mock_publishAnyEventToVES.return_value = "mocked return value" - - result = fault_vm.processBacklog_fault_vm( - vesAgentConfig=MOCK_vesAgentConfig, - vesAgentState=MOCK_vesAgentState, - oneBacklog=MOCK_oneBacklog) - - self.assertIsNone(result) diff --git a/windriver/titanium_cloud/vesagent/tests/tests_tasks.py b/windriver/titanium_cloud/vesagent/tests/tests_tasks.py deleted file mode 100644 index 64b8d3df..00000000 --- a/windriver/titanium_cloud/vesagent/tests/tests_tasks.py +++ /dev/null @@ -1,143 +0,0 @@ -# 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 - -import unittest -import json -from django.test import Client -# from rest_framework import status - -from django.core.cache import cache -from common.msapi import extsys - -from titanium_cloud.vesagent import tasks -from titanium_cloud.vesagent.event_domain import fault_vm - -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': - '{"vesagent_config":{"backlogs":[{"source":"onap-aaf","domain":"fault","type":"vm","tenant":"VIM"}],"poll_interval_default":10,"ves_subscription":{"username":"user","password":"password","endpoint":"http://127.0.0.1:9005/sample"}}}', - 'insecure': 'True', -} - -COUNT_TIME_SLOT1 = (1, 1) -COUNT_TIME_SLOT2 = (0, 1) - - -class VesTaskTest(unittest.TestCase): - def setUp(self): - self.client = Client() - - def tearDown(self): - pass - - @mock.patch.object(tasks, 'processBacklogs') - @mock.patch.object(extsys, 'get_vim_by_id') - def test_tasks_scheduleBacklogs(self, mock_get_vim_by_id, mock_processBacklogs): - mock_get_vim_by_id.return_value = MOCK_VIM_INFO - mock_processBacklogs.side_effect = [ - COUNT_TIME_SLOT1, - COUNT_TIME_SLOT2 - ] - result = tasks.scheduleBacklogs(vimid="windriver-hudson-dc_RegionOne") - self.assertEquals(None, result) - - @mock.patch.object(tasks, 'processBacklogsOfOneVIM') - @mock.patch.object(cache, 'get') - def test_tasks_processBacklogs( - self, mock_cache_get, mock_tasks_processBacklogsOfOneVIM): - mock_VesAgentBacklogs_vimlist = ["windriver-hudson-dc_RegionOne"] - COUNT_TIME_SLOT_ONE_VIM = (1, 1) - mock_tasks_processBacklogsOfOneVIM.return_value = COUNT_TIME_SLOT_ONE_VIM - mock_cache_get.side_effect = [ - json.dumps(mock_VesAgentBacklogs_vimlist), - ] - result = tasks.processBacklogs() - self.assertEquals(COUNT_TIME_SLOT_ONE_VIM, result) - - @mock.patch.object(tasks, 'processOneBacklog') - @mock.patch.object(cache, 'set') - @mock.patch.object(cache, 'get') - def test_tasks_processBacklogsOfOneVIM( - self, mock_cache_get, mock_cache_set, mock_tasks_processOneBacklog): - # 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_cache_get.side_effect = [ - json.dumps(mock_vesagent_config), - json.dumps({}) - ] - mock_tasks_processOneBacklog.return_value = (1, 11) - mock_cache_set.return_value = "mocked cache set" - result = tasks.processBacklogsOfOneVIM(vimid="windriver-hudson-dc_RegionOne") - COUNT_TIME_SLOT = (1, 10) - self.assertEquals(COUNT_TIME_SLOT, result) - - @mock.patch.object(fault_vm, 'processBacklog_fault_vm') - def test_tasks_processOneBacklog( - self, mock_fault_vm_processBacklog_fault_vm): - mock_fault_vm_processBacklog_fault_vm.return_value = None - 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"}} - - vesagent_onebacklog = { - "backlog_uuid": "ce2d7597-22e1-4239-890f-bc303bd67076", - "poll_interval": 10, - "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" - } - - result = tasks.processOneBacklog( - vesAgentConfig=vesagent_config, - vesAgentState={}, - poll_interval_default=10, - oneBacklog=vesagent_onebacklog) - COUNT_TIME_SLOT = (1, 10) - self.assertEquals(COUNT_TIME_SLOT, result) diff --git a/windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py b/windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py deleted file mode 100644 index 289e43d8..00000000 --- a/windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py +++ /dev/null @@ -1,179 +0,0 @@ -# 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 - -import unittest -import json -from django.test import Client -from rest_framework import status - -from django.core.cache import cache -from common.msapi import extsys -from titanium_cloud.vesagent import vesagent_ctrl -from titanium_cloud.vesagent.event_domain import fault_vm -from titanium_cloud.vesagent.tasks import scheduleBacklogs - -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': - '{"vesagent_config":{"backlogs":[{"source": "onap-aaf","domain": "fault","type": "vm","tenant": "VIM"}],"poll_interval_default":10,"ves_subscription":{"username": "user","password": "password","endpoint": "http://127.0.0.1:9005/sample"}}}', - 'insecure': 'True', -} - - -class VesAgentCtrlTest(unittest.TestCase): - def setUp(self): - self.client = Client() - self.view = vesagent_ctrl.VesAgentCtrl() - - def tearDown(self): - pass - - @mock.patch.object(cache, 'get') - @mock.patch.object(extsys, 'get_vim_by_id') - def test_get(self, mock_get_vim_by_id, mock_get): - mock_get_vim_by_id.return_value = MOCK_VIM_INFO - mock_get.return_value = \ - '{"backlogs": [{"backlog_uuid": "2b8f6ff8-bc64-339b-a714-155909db937f", "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"}}' - - response = self.client.get("/api/multicloud-titaniumcloud/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) - - @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) - - @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) - - @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) - - @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) - - @mock.patch.object(fault_vm, 'buildBacklog_fault_vm') - def test_buildBacklog(self, mock_buildBacklog_fault_vm): - mock_backlog_input = { - "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"} - - mock_buildBacklog_fault_vm.return_value = "mocked buildBacklog_fault_vm" - - VesAgentBacklogsConfig = self.view.buildBacklog( - vimid="windriver-hudson-dc_RegionOne", - backlog_input=mock_backlog_input) - self.assertIsNotNone(VesAgentBacklogsConfig) diff --git a/windriver/titanium_cloud/vesagent/tests/tests_vespublish.py b/windriver/titanium_cloud/vesagent/tests/tests_vespublish.py deleted file mode 100644 index 64ea7d00..00000000 --- a/windriver/titanium_cloud/vesagent/tests/tests_vespublish.py +++ /dev/null @@ -1,54 +0,0 @@ -# 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 - -import unittest -# import json -import urllib2 - -from titanium_cloud.vesagent import vespublish - -MOCK_VESENDPOINT = { - "endpoint": "MOCKED_VES_COLLECTOR_EP1", - "username": "MOCKED_VES_COLLECTOR_USER1", - "password": "MOCKED_VES_COLLECTOR_PASSWD1", -} - -MOCK_VESPUBLISH_EVENT1 = [{"name": "event1"}] - - -class VespublishTest(unittest.TestCase): - def setUp(self): - pass - - def tearDown(self): - pass - - @mock.patch.object(urllib2, 'urlopen') - @mock.patch.object(urllib2, 'Request') - def test_publishAnyEventToVES(self, mock_Request, mock_urlopen): - mock_request = mock.Mock() - - mock_Request.side_effect = [ - mock_request - ] - - mock_response = mock.Mock(["read"]) - mock_response.read.return_value = "MOCKED_VESPUBLISH_RESPONSE_MESSAGE" - mock_urlopen.side_effect = [ - mock_response - ] - - vespublish.publishAnyEventToVES(MOCK_VESENDPOINT, MOCK_VESPUBLISH_EVENT1) |