summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaibin Huang <haibin.huang@intel.com>2019-01-14 22:10:01 +0800
committerHaibin Huang <haibin.huang@intel.com>2019-01-15 10:55:18 +0800
commit2c585dc5c1cce52e2da58e6bcbc0d25797f5786e (patch)
tree9b32f59cefce2bc5fe3116aface5126811e758d4
parentcc24922e8133c6415747943860cdd09da205a85c (diff)
Fix vesagent pep8 error for ocata
This patch is only fixing the pep8 issues under the vesagent folder for ocata release, which is only triggered by tox mannually. Change-Id: I203770908136f4a81ddfe61981e55bb51778438b Issue-ID: MULTICLOUD-434 Signed-off-by: Haibin Huang <haibin.huang@intel.com>
-rw-r--r--ocata/ocata/vesagent/__init__.py1
-rw-r--r--ocata/ocata/vesagent/event_domain/__init__.py1
-rw-r--r--ocata/ocata/vesagent/event_domain/fault_vm.py47
-rw-r--r--ocata/ocata/vesagent/event_domain/tests_fault_vm.py231
-rw-r--r--ocata/ocata/vesagent/tasks.py41
-rw-r--r--ocata/ocata/vesagent/tests.py105
-rw-r--r--ocata/ocata/vesagent/tests_tasks.py113
-rw-r--r--ocata/ocata/vesagent/vesagent_ctrl.py42
-rw-r--r--ocata/ocata/vesagent/vespublish.py7
9 files changed, 370 insertions, 218 deletions
diff --git a/ocata/ocata/vesagent/__init__.py b/ocata/ocata/vesagent/__init__.py
index e4fe7a00..5f8b0d18 100644
--- a/ocata/ocata/vesagent/__init__.py
+++ b/ocata/ocata/vesagent/__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/ocata/ocata/vesagent/event_domain/__init__.py b/ocata/ocata/vesagent/event_domain/__init__.py
index e4fe7a00..5f8b0d18 100644
--- a/ocata/ocata/vesagent/event_domain/__init__.py
+++ b/ocata/ocata/vesagent/event_domain/__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/ocata/ocata/vesagent/event_domain/fault_vm.py b/ocata/ocata/vesagent/event_domain/fault_vm.py
index faddd25c..c3387114 100644
--- a/ocata/ocata/vesagent/event_domain/fault_vm.py
+++ b/ocata/ocata/vesagent/event_domain/fault_vm.py
@@ -18,13 +18,15 @@ import logging
import json
import uuid
import time
+import datetime
from django.conf import settings
from ocata.vesagent.vespublish import publishAnyEventToVES
from common.utils import restcall
-import datetime
-import time
+logger = logging.getLogger(__name__)
+
+
def get_epoch_now_usecond():
'''
get epoch timestamp of this moment in usecond
@@ -34,10 +36,8 @@ def get_epoch_now_usecond():
epoch_time_sec = time.mktime(now_time.timetuple())
return int(epoch_time_sec * 1e6 + now_time.microsecond)
-logger = logging.getLogger(__name__)
-
-### build backlog with domain:"fault", type:"vm"
+# build backlog with domain:"fault", type:"vm"
def buildBacklog_fault_vm(vimid, backlog_input):
logger.info("vimid: %s" % vimid)
@@ -45,7 +45,7 @@ def buildBacklog_fault_vm(vimid, backlog_input):
try:
- #must resolve the tenant id and server id while building the backlog
+ # must resolve the tenant id and server id while building the backlog
tenant_id = backlog_input.get("tenantid", None)
server_id = backlog_input.get("sourceid", None)
server_name = backlog_input.get("source", None)
@@ -58,7 +58,7 @@ def buildBacklog_fault_vm(vimid, backlog_input):
# resolve tenant_name to tenant_id
auth_api_url_format = "/{f_vim_id}/identity/v2.0/tokens"
auth_api_url = auth_api_url_format.format(f_vim_id=vimid)
- auth_api_data = { "auth":{"tenantName": tenant_name} }
+ auth_api_data = {"auth": {"tenantName": tenant_name}}
base_url = settings.MULTICLOUD_PREFIX
extra_headers = ''
ret = restcall._call_req(base_url, "", "", 0, auth_api_url, "POST", extra_headers, json.dumps(auth_api_data))
@@ -95,7 +95,7 @@ def buildBacklog_fault_vm(vimid, backlog_input):
% (server_name, tenant_id))
return None
- #m.c. proxied OpenStack API
+ # m.c. proxied OpenStack API
if server_id is None and server_name is None:
# monitor all VMs of the specified VIMs since no server_id can be resolved
api_url_fmt = "/{f_vim_id}/compute/v2.1/{f_tenant_id}/servers/detail"
@@ -103,12 +103,11 @@ def buildBacklog_fault_vm(vimid, backlog_input):
f_vim_id=vimid, f_tenant_id=tenant_id)
else:
api_url_fmt = "/{f_vim_id}/compute/v2.1/{f_tenant_id}/servers/{f_server_id}"
- api_url = api_url_fmt.format(
- f_vim_id=vimid, f_tenant_id=tenant_id, f_server_id=server_id)
+ api_url = api_url_fmt.format(f_vim_id=vimid, f_tenant_id=tenant_id, f_server_id=server_id)
backlog = {
- "backlog_uuid":str(uuid.uuid3(uuid.NAMESPACE_URL,
- str("%s-%s-%s"%(vimid, tenant_id,server_id)))),
+ "backlog_uuid": str(uuid.uuid3(uuid.NAMESPACE_URL,
+ str("%s-%s-%s" % (vimid, tenant_id, server_id)))),
"tenant_id": tenant_id,
"server_id": server_id,
"api_method": "GET",
@@ -124,10 +123,7 @@ def buildBacklog_fault_vm(vimid, backlog_input):
return backlog
-### process backlog with domain:"fault", type:"vm"
-
-
-
+# process backlog with domain:"fault", type:"vm"
def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog):
logger.debug("vesAgentConfig:%s, vesAgentState:%s, oneBacklog: %s"
% (vesAgentConfig, vesAgentState, oneBacklog))
@@ -139,7 +135,7 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog):
# get token
auth_api_url_format = "/{f_vim_id}/identity/v2.0/tokens"
auth_api_url = auth_api_url_format.format(f_vim_id=vimid)
- auth_api_data = { "auth":{"tenantName": tenant_name} }
+ auth_api_data = {"auth": {"tenantName": tenant_name}}
base_url = settings.MULTICLOUD_PREFIX
extra_headers = ''
logger.debug("authenticate with url:%s" % auth_api_url)
@@ -157,8 +153,8 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog):
base_url = settings.MULTICLOUD_PREFIX
data = ''
extra_headers = {'X-Auth-Token': token}
- #which one is correct? extra_headers = {'HTTP_X_AUTH_TOKEN': token}
- logger.debug("authenticate with url:%s, header:%s" % (auth_api_url,extra_headers))
+ # which one is correct? extra_headers = {'HTTP_X_AUTH_TOKEN': token}
+ logger.debug("authenticate with url:%s, header:%s" % (auth_api_url, extra_headers))
ret = restcall._call_req(base_url, "", "", 0, api_link, method, extra_headers, data)
if ret[0] > 0 or ret[1] is None:
logger.critical("call url %s failed with status %s" % (api_link, ret[0]))
@@ -170,10 +166,10 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog):
backlog_uuid = oneBacklog.get("backlog_uuid", None)
backlogState = vesAgentState.get("%s" % (backlog_uuid), None)
- #iterate all VMs
+ # iterate all VMs
all_events = []
- server_1 = server_resp.get("server",None) # in case querying single server
- for s in server_resp.get("servers",[server_1] if server_1 else []):
+ server_1 = server_resp.get("server", None) # in case querying single server
+ for s in server_resp.get("servers", [server_1] if server_1 else []):
server_id = s.get("id", None)
server_name = s.get("name", None)
if not server_id:
@@ -194,7 +190,7 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog):
publishAnyEventToVES(ves_subscription, all_events)
# store the latest data into cache, never expire
- except Exception as e:
+ except Exception as e:
logger.error("exception:%s" % str(e))
return
@@ -220,7 +216,6 @@ def data2event_fault_vm(vimid, oneBacklog, last_event, vm_data):
priority = "High"
eventSeverity = "CRITICAL"
alarmCondition = "Guest_Os_Failure"
- vfStatus = "Active"
specificProblem = "Fault_MultiCloud_VMFailure"
eventType = ''
reportingEntityId = vimid
@@ -238,17 +233,15 @@ def data2event_fault_vm(vimid, oneBacklog, last_event, vm_data):
# not assert alarm yet, so no need to clear it
return None
-
eventName = "Fault_MultiCloud_VMFailureCleared"
priority = "Normal"
eventSeverity = "NORMAL"
alarmCondition = "Vm_Restart"
- vfStatus = "Active"
specificProblem = "Fault_MultiCloud_VMFailure"
eventType = ''
reportingEntityId = vimid
reportingEntityName = vimid
- sequence = 1 #last_event['event']['commonEventHeader']['sequence'] + 1
+ sequence = 1 # last_event['event']['commonEventHeader']['sequence'] + 1
startEpochMicrosec = last_event['event']['commonEventHeader']['startEpochMicrosec']
lastEpochMicrosec = get_epoch_now_usecond()
diff --git a/ocata/ocata/vesagent/event_domain/tests_fault_vm.py b/ocata/ocata/vesagent/event_domain/tests_fault_vm.py
index 919988e2..7798ae52 100644
--- a/ocata/ocata/vesagent/event_domain/tests_fault_vm.py
+++ b/ocata/ocata/vesagent/event_domain/tests_fault_vm.py
@@ -21,45 +21,163 @@ from ocata.vesagent import vespublish
from common.utils import restcall
from ocata.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_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):
@@ -73,64 +191,63 @@ class FaultVMTest(unittest.TestCase):
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_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_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_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_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_input=MOCK_BACKLOG_INPUT_wo_server)
self.assertIsNotNone(backlog)
pass
@@ -138,15 +255,15 @@ class FaultVMTest(unittest.TestCase):
@mock.patch.object(restcall, '_call_req')
def test_processBacklog_fault_vm(self, mock_call_req, mock_publishAnyEventToVES):
- mock_call_req.side_effect= [
+ 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)
+ vesAgentState=MOCK_vesAgentState,
+ oneBacklog=MOCK_oneBacklog)
self.assertIsNone(result)
pass
@@ -154,14 +271,14 @@ class FaultVMTest(unittest.TestCase):
@mock.patch.object(restcall, '_call_req')
def test_processBacklog_fault_vm_wo_server(self, mock_call_req, mock_publishAnyEventToVES):
- mock_call_req.side_effect= [
+ 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)
+ vesAgentState=MOCK_vesAgentState,
+ oneBacklog=MOCK_oneBacklog)
self.assertIsNone(result)
pass
diff --git a/ocata/ocata/vesagent/tasks.py b/ocata/ocata/vesagent/tasks.py
index 7dfb61da..5b63be36 100644
--- a/ocata/ocata/vesagent/tasks.py
+++ b/ocata/ocata/vesagent/tasks.py
@@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-### VES agent workers
+# VES agent workers
from __future__ import absolute_import, unicode_literals
from ocata.celery import app
-import os
import logging
import json
import time
@@ -49,24 +48,23 @@ def processBacklogs():
backlog_count = 0
next_time_slot = 10
try:
- #get the whole list of backlog
+ # get the whole list of backlog
VesAgentBacklogsVimListStr = cache.get("VesAgentBacklogs.vimlist")
if VesAgentBacklogsVimListStr is None:
logger.warn("VesAgentBacklogs.vimlist cannot be found in cache")
- return 0,next_time_slot
+ return 0, next_time_slot
logger.debug("VesAgentBacklogs.vimlist: %s" % (VesAgentBacklogsVimListStr))
backlogsAllVims = json.loads(VesAgentBacklogsVimListStr)
if backlogsAllVims is None:
logger.warn("VesAgentBacklogs.vimlist is empty")
- return 0,next_time_slot
+ return 0, next_time_slot
for vimid in backlogsAllVims:
- #iterate each backlogs
- backlog_count_tmp,next_time_slot_tmp = processBacklogsOfOneVIM(vimid)
- logger.debug("vimid:%s, backlog_count,next_time_slot:%s,%s"
- %( vimid,backlog_count_tmp,next_time_slot_tmp ))
+ # iterate each backlogs
+ backlog_count_tmp, next_time_slot_tmp = processBacklogsOfOneVIM(vimid)
+ logger.debug("vimid:%s, backlog_count,next_time_slot:%s,%s" % (vimid, backlog_count_tmp, next_time_slot_tmp))
backlog_count += backlog_count_tmp
next_time_slot = next_time_slot_tmp if next_time_slot > next_time_slot_tmp else next_time_slot
pass
@@ -92,15 +90,14 @@ def processBacklogsOfOneVIM(vimid):
vesAgentConfigStr = cache.get("VesAgentBacklogs.config.%s" % (vimid))
if vesAgentConfigStr is None:
logger.warn("VesAgentBacklogs.config.%s cannot be found in cache" % (vimid))
- return 0,next_time_slot
+ return 0, next_time_slot
logger.debug("VesAgentBacklogs.config.%s: %s" % (vimid, vesAgentConfigStr))
vesAgentConfig = json.loads(vesAgentConfigStr)
if vesAgentConfig is None:
logger.warn("VesAgentBacklogs.config.%s corrupts" % (vimid))
- return 0,next_time_slot
-
+ return 0, next_time_slot
vesAgentStateStr = cache.get("VesAgentBacklogs.state.%s" % (vimid))
vesAgentState = json.loads(vesAgentStateStr) if vesAgentStateStr is not None else {}
@@ -108,26 +105,28 @@ def processBacklogsOfOneVIM(vimid):
ves_info = vesAgentConfig.get("subscription", None)
if ves_info is None:
logger.warn("VesAgentBacklogs.config.%s: ves subscription corrupts:%s" % (vimid, vesAgentConfigStr))
- return 0,next_time_slot
+ return 0, next_time_slot
poll_interval_default = vesAgentConfig.get("poll_interval_default", None)
if poll_interval_default is None:
logger.warn("VesAgentBacklogs.config.%s: poll_interval_default corrupts:%s" % (vimid, vesAgentConfigStr))
- return 0,next_time_slot
+ return 0, next_time_slot
if poll_interval_default == 0:
# invalid interval value
logger.warn("VesAgentBacklogs.config.%s: poll_interval_default invalid:%s" % (vimid, vesAgentConfigStr))
- return 0,next_time_slot
+ return 0, next_time_slot
backlogs_list = vesAgentConfig.get("backlogs", None)
if backlogs_list is None:
logger.warn("VesAgentBacklogs.config.%s: backlogs corrupts:%s" % (vimid, vesAgentConfigStr))
- return 0,next_time_slot
+ return 0, next_time_slot
for backlog in backlogs_list:
- backlog_count_tmp, next_time_slot_tmp = processOneBacklog(
- vesAgentConfig, vesAgentState, poll_interval_default, backlog)
+ backlog_count_tmp, next_time_slot_tmp = processOneBacklog(vesAgentConfig,
+ vesAgentState,
+ poll_interval_default,
+ backlog)
logger.debug("processOneBacklog return with %s,%s" % (backlog_count_tmp, next_time_slot_tmp))
backlog_count += backlog_count_tmp
next_time_slot = next_time_slot_tmp if next_time_slot > next_time_slot_tmp else next_time_slot
@@ -146,7 +145,7 @@ def processBacklogsOfOneVIM(vimid):
def processOneBacklog(vesAgentConfig, vesAgentState, poll_interval_default, oneBacklog):
logger.info("Process one backlog")
- #logger.debug("vesAgentConfig:%s, vesAgentState:%s, poll_interval_default:%s, oneBacklog: %s"
+ # logger.debug("vesAgentConfig:%s, vesAgentState:%s, poll_interval_default:%s, oneBacklog: %s"
# % (vesAgentConfig, vesAgentState, poll_interval_default, oneBacklog))
backlog_count = 1
@@ -167,8 +166,7 @@ def processOneBacklog(vesAgentConfig, vesAgentState, poll_interval_default, oneB
vesAgentState["%s" % (backlog_uuid)] = initialBacklogState
backlogState = initialBacklogState
- time_expiration = backlogState["timestamp"] \
- + oneBacklog.get("poll_interval", poll_interval_default)
+ time_expiration = backlogState["timestamp"] + oneBacklog.get("poll_interval", poll_interval_default)
# check if poll interval expires
if timestamp_now < time_expiration:
# not expired yet
@@ -193,4 +191,3 @@ def processOneBacklog(vesAgentConfig, vesAgentState, poll_interval_default, oneB
logger.info("return")
return backlog_count, next_time_slot
-
diff --git a/ocata/ocata/vesagent/tests.py b/ocata/ocata/vesagent/tests.py
index 242f7d19..a730ba87 100644
--- a/ocata/ocata/vesagent/tests.py
+++ b/ocata/ocata/vesagent/tests.py
@@ -43,6 +43,7 @@ MOCK_VIM_INFO = {
'insecure': 'True',
}
+
class VesAgentCtrlTest(unittest.TestCase):
def setUp(self):
self.client = Client()
@@ -66,8 +67,8 @@ 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)
@@ -89,7 +90,26 @@ class VesAgentCtrlTest(unittest.TestCase):
@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_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")
@@ -101,28 +121,36 @@ class VesAgentCtrlTest(unittest.TestCase):
@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_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')
@@ -130,25 +158,36 @@ class VesAgentCtrlTest(unittest.TestCase):
@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_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)
+ vesagent_config=mock_vesagent_config)
self.assertIsNotNone(VesAgentBacklogsConfig)
pass
diff --git a/ocata/ocata/vesagent/tests_tasks.py b/ocata/ocata/vesagent/tests_tasks.py
index 45fbea1b..a4618f54 100644
--- a/ocata/ocata/vesagent/tests_tasks.py
+++ b/ocata/ocata/vesagent/tests_tasks.py
@@ -17,16 +17,13 @@ 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 common.msapi import extsys
from ocata.vesagent import tasks
from ocata.vesagent.event_domain import fault_vm
-
MOCK_VIM_INFO = {
"createTime": "2017-04-01 02:22:27",
"domain": "Default",
@@ -48,6 +45,7 @@ MOCK_VIM_INFO = {
COUNT_TIME_SLOT1 = (1, 1)
COUNT_TIME_SLOT2 = (0, 1)
+
class VesTaskTest(unittest.TestCase):
def setUp(self):
self.client = Client()
@@ -59,10 +57,10 @@ 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
@@ -73,9 +71,9 @@ class VesTaskTest(unittest.TestCase):
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
@@ -84,20 +82,29 @@ class VesTaskTest(unittest.TestCase):
@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_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")
@@ -108,29 +115,39 @@ class VesTaskTest(unittest.TestCase):
@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)
+ 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/ocata/ocata/vesagent/vesagent_ctrl.py b/ocata/ocata/vesagent/vesagent_ctrl.py
index 3293f829..fcf222b7 100644
--- a/ocata/ocata/vesagent/vesagent_ctrl.py
+++ b/ocata/ocata/vesagent/vesagent_ctrl.py
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import traceback
import json
from rest_framework import status
@@ -29,6 +28,7 @@ from django.core.cache import cache
logger = logging.getLogger(__name__)
+
class VesAgentCtrl(APIView):
'''
control plane of VesAgent
@@ -152,7 +152,6 @@ class VesAgentCtrl(APIView):
self._logger = logger
self.proxy_prefix = settings.MULTICLOUD_PREFIX
-
def get(self, request, vimid=""):
'''
get blob of vesagent-config
@@ -170,8 +169,8 @@ class VesAgentCtrl(APIView):
cloud_extra_info = json.loads(cloud_extra_info_str) if cloud_extra_info_str != '' else None
vesagent_config = cloud_extra_info.get("vesagent_config", None) if cloud_extra_info is not None else None
except Exception as e:
- #ignore this error
- self._logger.warn("cloud extra info is provided with data in bad format: %s" % cloud_extra_info_str)
+ # ignore this error
+ self._logger.warn("cloud extra info is provided with data in bad format: %s" % str(e))
pass
vesagent_backlogs = self.getBacklogsOneVIM(vimid)
@@ -182,11 +181,10 @@ class VesAgentCtrl(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
self._logger.info("return with %s" % status.HTTP_200_OK)
- return Response(data={"vesagent_config":vesagent_config,
+ return Response(data={"vesagent_config": vesagent_config,
"vesagent_backlogs": vesagent_backlogs},
status=status.HTTP_200_OK)
-
def post(self, request, vimid=""):
'''
update the blob of vesagent-config, rebuild the backlog for the vesagent workers,
@@ -212,7 +210,7 @@ class VesAgentCtrl(APIView):
try:
vesagent_config = None
if request.data is None or request.data.get("vesagent_config", None) is None:
- #Try to load the vesagent_config out of cloud_region["cloud_extra_info"]
+ # Try to load the vesagent_config out of cloud_region["cloud_extra_info"]
viminfo = extsys.get_vim_by_id(vimid)
cloud_extra_info_str = viminfo.get('cloud_extra_info', None)
cloud_extra_info = json.loads(cloud_extra_info_str) if cloud_extra_info_str is not None else None
@@ -222,7 +220,7 @@ class VesAgentCtrl(APIView):
if vesagent_config is None:
return Response(data={'vesagent_config is not provided'},
- status=status.HTTP_400_BAD_REQUEST)
+ status=status.HTTP_400_BAD_REQUEST)
vesagent_backlogs = self.buildBacklogsOneVIM(vimid, vesagent_config)
@@ -235,7 +233,7 @@ class VesAgentCtrl(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
self._logger.info("return with %s" % status.HTTP_201_CREATED)
- return Response(data={"vesagent_config":vesagent_config,
+ return Response(data={"vesagent_config": vesagent_config,
"vesagent_backlogs": vesagent_backlogs},
status=status.HTTP_201_CREATED)
@@ -259,7 +257,6 @@ class VesAgentCtrl(APIView):
self._logger.info("return with %s" % status.HTTP_200_OK)
return Response(status=status.HTTP_200_OK)
-
def getBacklogsOneVIM(self, vimid):
'''
remove the specified backlogs for a VIM
@@ -337,7 +334,7 @@ class VesAgentCtrl(APIView):
self._logger.debug("return")
return 0
- def buildBacklogsOneVIM(self, vimid, vesagent_config = None):
+ def buildBacklogsOneVIM(self, vimid, vesagent_config=None):
'''
build and cache backlog for specific cloud region,spawn vesagent workers if needed
:param vimid:
@@ -349,7 +346,7 @@ class VesAgentCtrl(APIView):
VesAgentBacklogsConfig = None
try:
- if vesagent_config :
+ if vesagent_config:
# now rebuild the backlog
VesAgentBacklogsConfig = {
"vimid": vimid,
@@ -358,7 +355,6 @@ class VesAgentCtrl(APIView):
"backlogs": [self.buildBacklog(vimid, b) for b in vesagent_config.get("backlogs", [])]
}
-
# add/update the backlog into cache
VesAgentBacklogsConfigStr = json.dumps(VesAgentBacklogsConfig)
# cache forever
@@ -375,14 +371,14 @@ class VesAgentCtrl(APIView):
logger.debug("VesAgentBacklogs.vimlist is %s" % VesAgentBacklogsVimList)
- #cache forever
+ # cache forever
cache.set("VesAgentBacklogs.vimlist", json.dumps(VesAgentBacklogsVimList), None)
# notify schduler
scheduleBacklogs.delay(vimid)
except Exception as e:
self._logger.error("exception:%s" % str(e))
- VesAgentBacklogsConfig = {"error":"exception occurs during build backlogs"}
+ VesAgentBacklogsConfig = {"error": "exception occurs during build backlogs"}
self._logger.debug("return")
return VesAgentBacklogsConfig
@@ -413,7 +409,6 @@ class APIv1VesAgentCtrl(VesAgentCtrl):
# self._logger = logger
self.proxy_prefix = settings.MULTICLOUD_API_V1_PREFIX
-
def get(self, request, cloud_owner="", cloud_region_id=""):
'''
:param request:
@@ -421,11 +416,10 @@ class APIv1VesAgentCtrl(VesAgentCtrl):
:param cloud_region_id:
:return:
'''
- self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner,cloud_region_id))
+ self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id))
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
- return super(APIv1VesAgentCtrl,self).get(request, vimid)
-
+ return super(APIv1VesAgentCtrl, self).get(request, vimid)
def post(self, request, cloud_owner="", cloud_region_id=""):
'''
@@ -435,11 +429,10 @@ class APIv1VesAgentCtrl(VesAgentCtrl):
:param cloud_region_id:
:return:
'''
- self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner,cloud_region_id))
+ self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id))
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
- return super(APIv1VesAgentCtrl,self).post(request, vimid)
-
+ return super(APIv1VesAgentCtrl, self).post(request, vimid)
def delete(self, request, cloud_owner="", cloud_region_id=""):
'''
@@ -449,8 +442,7 @@ class APIv1VesAgentCtrl(VesAgentCtrl):
:param cloud_region_id:
:return:
'''
- self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner,cloud_region_id))
+ self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id))
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
- return super(APIv1VesAgentCtrl,self).delete(request, vimid)
-
+ return super(APIv1VesAgentCtrl, self).delete(request, vimid)
diff --git a/ocata/ocata/vesagent/vespublish.py b/ocata/ocata/vesagent/vespublish.py
index b67a64ee..358bd9a4 100644
--- a/ocata/ocata/vesagent/vespublish.py
+++ b/ocata/ocata/vesagent/vespublish.py
@@ -21,14 +21,13 @@ import urllib2
logger = logging.getLogger(__name__)
+
def publishAnyEventToVES(ves_subscription, events):
if not events or len(events) == 0:
return
logger.info("Start to send single event to VES collector.")
endpoint = ves_subscription.get("endpoint", None)
- username = ves_subscription.get("username", None)
- password = ves_subscription.get("password", None)
if endpoint:
try:
@@ -44,9 +43,9 @@ def publishAnyEventToVES(ves_subscription, events):
time.sleep(1)
response = urllib2.urlopen(request)
logger.info("VES response is: %s" % response.read())
- except urllib2.URLError, e:
+ except urllib2.URLError as e:
logger.critical("Failed to publish to %s: %s" % (endpoint, e.reason))
except Exception as e:
logger.error("exception:%s" % str(e))
else:
- logger.info("Missing VES info.") \ No newline at end of file
+ logger.info("Missing VES info.")