summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/vesagent/tests/tests_tasks.py
diff options
context:
space:
mode:
Diffstat (limited to 'windriver/titanium_cloud/vesagent/tests/tests_tasks.py')
-rw-r--r--windriver/titanium_cloud/vesagent/tests/tests_tasks.py117
1 files changed, 62 insertions, 55 deletions
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
-