summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/vesagent/tests
diff options
context:
space:
mode:
Diffstat (limited to 'windriver/titanium_cloud/vesagent/tests')
-rw-r--r--windriver/titanium_cloud/vesagent/tests/__init__.py1
-rw-r--r--windriver/titanium_cloud/vesagent/tests/tests_fault_vm.py219
-rw-r--r--windriver/titanium_cloud/vesagent/tests/tests_tasks.py117
-rw-r--r--windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py125
-rw-r--r--windriver/titanium_cloud/vesagent/tests/tests_vespublish.py22
5 files changed, 276 insertions, 208 deletions
diff --git a/windriver/titanium_cloud/vesagent/tests/__init__.py b/windriver/titanium_cloud/vesagent/tests/__init__.py
index e4fe7a00..5f8b0d18 100644
--- a/windriver/titanium_cloud/vesagent/tests/__init__.py
+++ b/windriver/titanium_cloud/vesagent/tests/__init__.py
@@ -13,4 +13,3 @@
# 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
index 7cbc2229..880c1d5d 100644
--- a/windriver/titanium_cloud/vesagent/tests/tests_fault_vm.py
+++ b/windriver/titanium_cloud/vesagent/tests/tests_fault_vm.py
@@ -21,46 +21,110 @@ 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_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 = {
+ "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_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"}
+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):
@@ -72,98 +136,93 @@ class FaultVMTest(unittest.TestCase):
def test_get_epoch_now_usecond(self):
epoch = fault_vm.get_epoch_now_usecond()
self.assertGreater(epoch, 1)
- pass
-
@mock.patch.object(restcall, '_call_req')
def test_buildBacklog_fault_vm(self, mock_call_req):
-
- mock_call_req.side_effect= [
+ 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)
+ ]
+ backlog = fault_vm.buildBacklog_fault_vm(
+ vimid="windriver-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT)
+
self.assertIsNotNone(backlog)
- pass
@mock.patch.object(restcall, '_call_req')
def test_buildBacklog_fault_vm_wo_tenant_id(self, mock_call_req):
-
- mock_call_req.side_effect= [
+ 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)
+ ]
+ backlog = fault_vm.buildBacklog_fault_vm(
+ vimid="windriver-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_tenant_id)
self.assertIsNotNone(backlog)
- pass
-
@mock.patch.object(restcall, '_call_req')
def test_buildBacklog_fault_vm_wo_tenant(self, mock_call_req):
-
- mock_call_req.side_effect= [
+ 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)
+ ]
+ backlog = fault_vm.buildBacklog_fault_vm(
+ vimid="windriver-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_tenant)
self.assertIsNone(backlog)
- pass
@mock.patch.object(restcall, '_call_req')
def test_buildBacklog_fault_vm_wo_server_id(self, mock_call_req):
-
- mock_call_req.side_effect= [
+ 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)
+ ]
+ backlog = fault_vm.buildBacklog_fault_vm(
+ vimid="windriver-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_server_id)
self.assertIsNotNone(backlog)
- pass
@mock.patch.object(restcall, '_call_req')
def test_buildBacklog_fault_vm_wo_server(self, mock_call_req):
-
- mock_call_req.side_effect= [
+ 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)
+ ]
+ backlog = fault_vm.buildBacklog_fault_vm(
+ vimid="windriver-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_server)
self.assertIsNotNone(backlog)
- pass
@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= [
+ 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)
+ 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= [
+ 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)
+ result = fault_vm.processBacklog_fault_vm(
+ vesAgentConfig=MOCK_vesAgentConfig,
+ vesAgentState=MOCK_vesAgentState,
+ oneBacklog=MOCK_oneBacklog)
+
self.assertIsNone(result)
- pass
diff --git a/windriver/titanium_cloud/vesagent/tests/tests_tasks.py b/windriver/titanium_cloud/vesagent/tests/tests_tasks.py
index fef8e8ee..64b8d3df 100644
--- a/windriver/titanium_cloud/vesagent/tests/tests_tasks.py
+++ b/windriver/titanium_cloud/vesagent/tests/tests_tasks.py
@@ -17,7 +17,7 @@ import mock
import unittest
import json
from django.test import Client
-from rest_framework import status
+# from rest_framework import status
from django.core.cache import cache
from common.msapi import extsys
@@ -25,8 +25,6 @@ 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",
@@ -41,13 +39,15 @@ MOCK_VIM_INFO = {
"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"}}}',
+ '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()
@@ -59,78 +59,85 @@ class VesTaskTest(unittest.TestCase):
@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
- ]
+ mock_processBacklogs.side_effect = [
+ COUNT_TIME_SLOT1,
+ COUNT_TIME_SLOT2
+ ]
result = tasks.scheduleBacklogs(vimid="windriver-hudson-dc_RegionOne")
self.assertEquals(None, result)
- pass
@mock.patch.object(tasks, 'processBacklogsOfOneVIM')
@mock.patch.object(cache, 'get')
- def test_tasks_processBacklogs(self, mock_cache_get, mock_tasks_processBacklogsOfOneVIM):
+ 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),
- ]
+ mock_cache_get.side_effect = [
+ json.dumps(mock_VesAgentBacklogs_vimlist),
+ ]
result = tasks.processBacklogs()
self.assertEquals(COUNT_TIME_SLOT_ONE_VIM, result)
- pass
@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({})
- ]
+ 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)
- pass
@mock.patch.object(fault_vm, 'processBacklog_fault_vm')
- def test_tasks_processOneBacklog(self, mock_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)
+ 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)
- pass
-
diff --git a/windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py b/windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py
index 1fb8d51b..289e43d8 100644
--- a/windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py
+++ b/windriver/titanium_cloud/vesagent/tests/tests_vesagent_ctrl.py
@@ -23,8 +23,7 @@ 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",
@@ -40,7 +39,8 @@ MOCK_VIM_INFO = {
"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"}}}',
+ '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',
}
@@ -57,7 +57,8 @@ class VesAgentCtrlTest(unittest.TestCase):
@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"}}'
+ 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)
@@ -68,14 +69,12 @@ class VesAgentCtrlTest(unittest.TestCase):
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"}
+ 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):
@@ -87,22 +86,8 @@ class VesAgentCtrlTest(unittest.TestCase):
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",
@@ -112,65 +97,83 @@ class VesAgentCtrlTest(unittest.TestCase):
"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)
- mock_get.side_effect= [
- json.dumps(mock_VesAgentBacklogs_vimlist),
- 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")
+ result = self.view.clearBacklogsOneVIM(
+ vimid="windriver-hudson-dc_RegionOne")
self.assertEquals(0, result)
- pass
-
- from titanium_cloud.vesagent.tasks import scheduleBacklogs
-
@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):
+ 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_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)
+ VesAgentBacklogsConfig = self.view.buildBacklogsOneVIM(
+ vimid="windriver-hudson-dc_RegionOne",
+ vesagent_config=mock_vesagent_config)
self.assertIsNotNone(VesAgentBacklogsConfig)
- pass
-
-
@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_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)
+ VesAgentBacklogsConfig = self.view.buildBacklog(
+ vimid="windriver-hudson-dc_RegionOne",
+ backlog_input=mock_backlog_input)
self.assertIsNotNone(VesAgentBacklogsConfig)
-
- pass
diff --git a/windriver/titanium_cloud/vesagent/tests/tests_vespublish.py b/windriver/titanium_cloud/vesagent/tests/tests_vespublish.py
index 0178aaed..64ea7d00 100644
--- a/windriver/titanium_cloud/vesagent/tests/tests_vespublish.py
+++ b/windriver/titanium_cloud/vesagent/tests/tests_vespublish.py
@@ -15,17 +15,19 @@
import mock
import unittest
-import json
+# 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",
+ "endpoint": "MOCKED_VES_COLLECTOR_EP1",
+ "username": "MOCKED_VES_COLLECTOR_USER1",
+ "password": "MOCKED_VES_COLLECTOR_PASSWD1",
}
-MOCK_VESPUBLISH_EVENT1 = [{"name":"event1"}]
+
+MOCK_VESPUBLISH_EVENT1 = [{"name": "event1"}]
+
class VespublishTest(unittest.TestCase):
def setUp(self):
@@ -39,16 +41,14 @@ class VespublishTest(unittest.TestCase):
def test_publishAnyEventToVES(self, mock_Request, mock_urlopen):
mock_request = mock.Mock()
- mock_Request.side_effect= [
+ 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_urlopen.side_effect = [
mock_response
- ]
+ ]
vespublish.publishAnyEventToVES(MOCK_VESENDPOINT, MOCK_VESPUBLISH_EVENT1)
-
- pass