From 74659f0cb7619ce2622f8655201db8d96f16300f Mon Sep 17 00:00:00 2001 From: malar Date: Wed, 11 May 2022 11:57:02 +0000 Subject: Fix bug in fetching capacity attributes from DCAE Issue-ID: OPTFRA-1064 Signed-off-by: Malarvizhi Paramasivam Change-Id: Idbe002cb67d2387fd39649dd806dad5631b856ce --- .../data/plugins/inventory_provider/dcae.py | 116 ++++++++++++++------- .../plugins/inventory_provider/dcae_response.json | 12 +-- 2 files changed, 87 insertions(+), 41 deletions(-) diff --git a/conductor/conductor/data/plugins/inventory_provider/dcae.py b/conductor/conductor/data/plugins/inventory_provider/dcae.py index 72890a7..02f7c79 100644 --- a/conductor/conductor/data/plugins/inventory_provider/dcae.py +++ b/conductor/conductor/data/plugins/inventory_provider/dcae.py @@ -21,7 +21,9 @@ from conductor.common import rest from conductor.i18n import _LE +from http.client import HTTPConnection import json +import logging from oslo_config import cfg from oslo_log import log import time @@ -29,6 +31,13 @@ import uuid LOG = log.getLogger(__name__) +log = logging.getLogger('urllib3') +log.setLevel(logging.DEBUG) +ch = logging.StreamHandler() +ch.setLevel(logging.DEBUG) +log.addHandler(ch) +HTTPConnection.debuglevel = 1 + CONF = cfg.CONF DCAE_OPTS = [ @@ -129,35 +138,56 @@ class DCAE(object): LOG.debug("from AAI ", candidates) for candidate in candidates: inventory_type = candidate.get('inventory_type') - candidate_id = candidate.get('candidate_id') + if inventory_type == 'nsi': + candidate_id = candidate.get('instance_id') + elif inventory_type == 'nssi': + candidate_id = candidate.get('instance_id') + else: + LOG.debug("No candidate_id found") domain = candidate.get('domain') - response = self.get_dcae_response() + LOG.debug("domain from the candidate list is ", domain) + response = self.get_dcae_response(candidate_id) + LOG.debug(" DCAE response in capacity_filter() : ", response) # max_no_of_connections = self.get_max_no_of_connections(response) - dLThpt = self.get_dLThpt(response, candidate_id) - uLThpt = self.get_uLThpt(response, candidate_id) - # max_no_of_pdu_sessions = self.get_max_no_of_pdu_sessions() - if inventory_type == 'nsi': - uLThpt_ServiceProfile = candidate.get('uLThptPerSlice') - dLThpt_ServiceProfile = candidate.get('dLThptPerSlice') - uLThpt_difference = self.get_difference(uLThpt_ServiceProfile, uLThpt) - dLThpt_difference = self.get_difference(dLThpt_ServiceProfile, dLThpt) - candidate['uLThpt_difference'] = uLThpt_difference - candidate['dLThpt_difference'] = dLThpt_difference - elif inventory_type == 'nssi' and (domain != 'tn_fh' and domain != 'tn_mh'): - uLThpt_SliceProfile = candidate.get('exp_data_rate_ul') - dLThpt_SliceProfile = candidate.get('exp_data_rate_dl') - uLThpt_difference = self.get_difference(uLThpt_SliceProfile, uLThpt) - dLThpt_difference = self.get_difference(dLThpt_SliceProfile, dLThpt) - candidate['uLThpt_difference'] = uLThpt_difference - candidate['dLThpt_difference'] = dLThpt_difference - # connections_difference = self.get_difference(max_no_of_pdu_sessions, max_no_of_connections) - elif inventory_type == 'nssi' and (domain == 'tn_fh' and domain == 'tn_mh'): - uLThpt_difference = 10 - dLThpt_difference = 10 - candidate['uLThpt_difference'] = uLThpt_difference - candidate['dLThpt_difference'] = dLThpt_difference + if response is not None: + dLThpt = self.get_dLThpt(response, candidate_id) + LOG.debug("dLThpt fetched from dcae response is", dLThpt) + uLThpt = self.get_uLThpt(response, candidate_id) + LOG.debug("uLThpt fetched from dcae response is", uLThpt) + # max_no_of_pdu_sessions = self.get_max_no_of_pdu_sessions() + if inventory_type == 'nsi': + uLThpt_ServiceProfile = candidate.get('ul_thpt_per_slice') + LOG.debug("uLThpt fetched from service profile is", uLThpt_ServiceProfile) + dLThpt_ServiceProfile = candidate.get('dl_thpt_per_slice') + LOG.debug("dLThpt fetched from service profile is", dLThpt_ServiceProfile) + uLThpt_difference = self.get_difference(uLThpt_ServiceProfile, uLThpt) + LOG.debug(" uLThpt_difference for nsi is ", uLThpt_difference) + dLThpt_difference = self.get_difference(dLThpt_ServiceProfile, dLThpt) + LOG.debug(" dLThpt_difference for nsi is ", dLThpt_difference) + candidate['uLThpt_difference'] = uLThpt_difference + candidate['dLThpt_difference'] = dLThpt_difference + elif inventory_type == 'nssi' and (domain != 'TN_FH' and domain != 'TN_MH'): + uLThpt_SliceProfile = candidate.get('exp_data_rate_ul') + LOG.debug("uLThpt fetched from slice profile is", uLThpt_SliceProfile) + dLThpt_SliceProfile = candidate.get('exp_data_rate_dl') + LOG.debug("dLThpt fetched from slice profile is", dLThpt_SliceProfile) + uLThpt_difference = self.get_difference(uLThpt_SliceProfile, uLThpt) + LOG.debug(" uLThpt_difference for nssi is ", uLThpt_difference) + dLThpt_difference = self.get_difference(dLThpt_SliceProfile, dLThpt) + LOG.debug(" dLThpt_difference for nssi is ", dLThpt_difference) + candidate['uLThpt_difference'] = uLThpt_difference + candidate['dLThpt_difference'] = dLThpt_difference + # connections_difference = self.get_difference(max_no_of_pdu_sessions, max_no_of_connections) + elif inventory_type == 'nssi' and (domain == 'TN_FH' and domain == 'TN_MH'): + uLThpt_difference = 10 + dLThpt_difference = 10 + candidate['uLThpt_difference'] = uLThpt_difference + candidate['dLThpt_difference'] = dLThpt_difference + else: + LOG.debug("No difference attribute was added to the candidate") else: - LOG.debug("No difference attribute was added to the candidate") + candidate = candidate + LOG.debug("Returning original candidate list") candidatesList.update(candidate) LOG.debug("capacity filter ", candidatesList) updated_candidateList.append(candidatesList) @@ -172,18 +202,20 @@ class DCAE(object): responseJson = json.loads(response) configDetails = responseJson["sliceConfigDetails"] for i in range(len(configDetails)): - if configDetails[i]["sliceIdentifier"] == candidate_id: + if configDetails[i]["sliceIdentifiers"] == candidate_id: aggregatedConfig = configDetails[i]['aggregatedConfig'] - uLThpt = aggregatedConfig.get("uLThptPerSlice") + uLThpt = aggregatedConfig.get("ulthptPerSlice") + LOG.debug(" uLthpt from DCAE is : ", uLThpt) return uLThpt def get_dLThpt(self, response, candidate_id): responseJson = json.loads(response) configDetails = responseJson["sliceConfigDetails"] for i in range(len(configDetails)): - if configDetails[i]["sliceIdentifier"] == candidate_id: + if configDetails[i]["sliceIdentifiers"] == candidate_id: aggregatedConfig = configDetails[i]['aggregatedConfig'] - dLThpt = aggregatedConfig.get("dLThptPerSlice") + dLThpt = aggregatedConfig.get("dlthptPerSlice") + LOG.debug(" dLthpt from DCAE is : ", dLThpt) return dLThpt def get_difference(self, attribute1, attribute2): @@ -218,10 +250,24 @@ class DCAE(object): "link: {}{}").format(context, value, response.status_code, response.reason, self.base, path)) return response - def get_dcae_response(self): + def get_dcae_response(self, candidate_id): path = self.conf.dcae.get_slice_config_url - dcae_response = self._request('get', path, data=None) - if dcae_response is None or dcae_response.status_code != 200: + data = {"sliceIdentifiers": [candidate_id], "configParams": ["dLThptPerSlice", + "uLThptPerSlice", "maxNumberOfConns"]} + dcae_response = self._request('get', path, data=data) + LOG.debug(self._request('get', path, data=data)) + LOG.debug(" DCAE response : ", dcae_response) + LOG.debug("DCAE json response is : ", json.dumps(dcae_response.json())) + dcae_response2 = json.dumps(dcae_response.json()) + LOG.debug(" processed DCAE response is ", dcae_response2) + if dcae_response2 is None or dcae_response.status_code != 200: return None - if dcae_response: - return dcae_response + if dcae_response2: + responseJson = json.loads(dcae_response2) + LOG.debug("response json from DCAE is :", responseJson) + if 'sliceConfigDetails' not in responseJson or len(responseJson['sliceConfigDetails']) == 0: + LOG.debug(" Returning None to capacity_filter()") + return None + else: + LOG.debug("returning DCAE response to capacity_filter() from get_dcae_response()") + return dcae_response2 diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/dcae_response.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/dcae_response.json index 4a8ea71..4941953 100644 --- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/dcae_response.json +++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/dcae_response.json @@ -1,17 +1,17 @@ { "sliceConfigDetails": [{ - "sliceIdentifier": "cdad9f49-4201-4e3a-aac1-b0f27902c299", + "sliceIdentifiers": "cdad9f49-4201-4e3a-aac1-b0f27902c299", "aggregatedConfig": { - "dLThptPerSlice":27, - "uLThptPerSlice":30, + "dlthptPerSlice":27, + "ulthptPerSlice":30, "maxNumberOfConns":300 } }, { - "sliceIdentifier": "e316f4b2-01fa-479a-8522-64fe9c0c2971", + "sliceIdentifiers": "e316f4b2-01fa-479a-8522-64fe9c0c2971", "aggregatedConfig": { - "dLThptPerSlice":40, - "uLThptPerSlice":25, + "dlthptPerSlice":40, + "ulthptPerSlice":25, "maxNumberOfConns":400 } }] -- cgit 1.2.3-korg