diff options
90 files changed, 425 insertions, 668 deletions
diff --git a/lcm/docker/Dockerfile b/lcm/docker/Dockerfile index 1507070e..34a7880a 100755 --- a/lcm/docker/Dockerfile +++ b/lcm/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:2-alpine +FROM python:3.6-alpine ARG HTTP_PROXY=${HTTP_PROXY} ARG HTTPS_PROXY=${HTTPS_PROXY} diff --git a/lcm/docker/docker-env-conf.sh b/lcm/docker/docker-env-conf.sh index b9389420..44119a6f 100755 --- a/lcm/docker/docker-env-conf.sh +++ b/lcm/docker/docker-env-conf.sh @@ -4,14 +4,14 @@ install_sf(){ apk --no-cache update apk --no-cache add bash curl gcc wget mysql-client openssl-dev - apk --no-cache add python-dev libffi-dev musl-dev py2-virtualenv + apk --no-cache add python36-dev libffi-dev musl-dev py3-virtualenv # get binary zip from nexus - vfc-nfvo-catalog wget -q -O vfc-gvnfm-vnflcm-lcm.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.vfc.gvnfm.vnflcm.lcm&a=vfc-gvnfm-vnflcm-lcm&v=${pkg_version}-SNAPSHOT&e=zip" && \ unzip vfc-gvnfm-vnflcm-lcm.zip && \ rm -rf vfc-gvnfm-vnflcm-lcm.zip wait - pip install --upgrade setuptools pip + pip install --upgrade setuptools pip pip install --no-cache-dir --pre -r /service/vfc/gvnfm/vnflcm/lcm/requirements.txt } @@ -44,9 +44,13 @@ clean_sf_cache(){ rm -rf /tmp/* } +patch_redisco_2py3(){ + sed -i 's/raise KeyError, value/raise KeyError(value)/g' /usr/local/lib/python3.6/site-packages/redisco/containers.py +} install_sf wait add_user config_logdir +patch_redisco_2py3 clean_sf_cache diff --git a/lcm/lcm/jobs/tests.py b/lcm/lcm/jobs/tests.py index 3eb60ab2..ca151ebc 100644 --- a/lcm/lcm/jobs/tests.py +++ b/lcm/lcm/jobs/tests.py @@ -30,4 +30,4 @@ class JobsViewTest(TestCase): JobModel(jobid=self.job_id, jobtype='VNF', jobaction='INST', resid='1').save() JobStatusModel(indexid=1, jobid=self.job_id, status='inst', progress=20, descp='inst').save() response = self.client.get("/api/vnflcm/v1/vnf_lc_ops/%s?responseId=123456jhj" % self.job_id) - self.failUnlessEqual(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) diff --git a/lcm/lcm/jobs/views.py b/lcm/lcm/jobs/views.py index cdd7ba4f..7221bf55 100644 --- a/lcm/lcm/jobs/views.py +++ b/lcm/lcm/jobs/views.py @@ -53,4 +53,4 @@ class JobView(APIView): return Response(data=resp_serializer.data, status=status.HTTP_200_OK) except Exception as e: logger.error(traceback.format_exc()) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/lcm/lcm/middleware.py b/lcm/lcm/middleware.py index f10a8d7c..5866debc 100644 --- a/lcm/lcm/middleware.py +++ b/lcm/lcm/middleware.py @@ -19,6 +19,9 @@ from lcm.pub.config.config import FORWARDED_FOR_FIELDS, SERVICE_NAME class LogContextMiddleware(object): # the last IP behind multiple proxies, if no exist proxies # get local host ip. + def __init__(self, get_response): + self.get_response = get_response + def _getLastIp(self, request): ip = "" @@ -58,3 +61,9 @@ class LogContextMiddleware(object): def process_response(self, request, response): MDC.clear() return response + + def __call__(self, request): + self.process_request(request) + response = self.get_response(request) + self.process_response(request, response) + return response diff --git a/lcm/lcm/nf/biz/change_ext_conn.py b/lcm/lcm/nf/biz/change_ext_conn.py index 1b3f9479..b423a2ec 100644 --- a/lcm/lcm/nf/biz/change_ext_conn.py +++ b/lcm/lcm/nf/biz/change_ext_conn.py @@ -87,12 +87,12 @@ class ChangeExtConn(Thread): operation_state=OPERATION_STATE_TYPE.COMPLETED ) except NFLCMException as e: - logger.error(e.message) - self.change_ext_conn_failed_handle(e.message) + logger.error(e.args[0]) + self.change_ext_conn_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) - self.change_ext_conn_failed_handle(e.message) + self.change_ext_conn_failed_handle(e.args[0]) def pre_deal(self): logger.debug("Start pre deal for VNF change_ext_conn task") @@ -232,7 +232,7 @@ class ChangeExtConn(Thread): def query_inst_resource(self, inst_resource): logger.debug('Query resource begin') - for resource_type in RESOURCE_MAP.keys(): + for resource_type in list(RESOURCE_MAP.keys()): resource_table = globals().get(resource_type + 'InstModel') resource_insts = resource_table.objects.filter( instid=self.nf_inst_id diff --git a/lcm/lcm/nf/biz/change_vnf_flavour.py b/lcm/lcm/nf/biz/change_vnf_flavour.py index 69cdf834..4563e301 100644 --- a/lcm/lcm/nf/biz/change_vnf_flavour.py +++ b/lcm/lcm/nf/biz/change_vnf_flavour.py @@ -84,12 +84,12 @@ class ChangeVnfFlavour(Thread): operation_state=OPERATION_STATE_TYPE.COMPLETED ) except NFLCMException as e: - logger.error(e.message) - self.change_vnf_flavour_failed_handle(e.message) + logger.error(e.args[0]) + self.change_vnf_flavour_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) - self.change_vnf_flavour_failed_handle(e.message) + self.change_vnf_flavour_failed_handle(e.args[0]) def pre_deal(self): logger.debug("Start pre deal for VNF change_vnf_flavour task") diff --git a/lcm/lcm/nf/biz/create_subscription.py b/lcm/lcm/nf/biz/create_subscription.py index 164bf6c8..fe062729 100644 --- a/lcm/lcm/nf/biz/create_subscription.py +++ b/lcm/lcm/nf/biz/create_subscription.py @@ -40,6 +40,8 @@ class CreateSubscription: def __init__(self, data): self.data = data self.filter = ignore_case_get(self.data, "filter", {}) + logger.debug("self.data:%s" % self.data) + logger.debug("self.filter:%s" % self.filter) self.callback_uri = ignore_case_get(self.data, "callbackUri") self.authentication = ignore_case_get(self.data, "authentication", {}) self.notification_types = ignore_case_get(self.filter, "notificationTypes", []) diff --git a/lcm/lcm/nf/biz/grant_vnf.py b/lcm/lcm/nf/biz/grant_vnf.py index 83d94e50..80ff035c 100644 --- a/lcm/lcm/nf/biz/grant_vnf.py +++ b/lcm/lcm/nf/biz/grant_vnf.py @@ -108,7 +108,7 @@ def grant_resource(data, nf_inst_id, job_id, grant_type, vdus): if vnf.vimInfo and 'vimid' not in addition_paras: vim_info = json.loads(vnf.vimInfo) vimid = "" - for key in vim_info.iterkeys(): + for key in list(vim_info.keys()): vimid = key addition_paras['vimid'] = vimid logger.info('Grant request data=%s' % content_args) diff --git a/lcm/lcm/nf/biz/heal_vnf.py b/lcm/lcm/nf/biz/heal_vnf.py index c768f6b5..c338fe6c 100644 --- a/lcm/lcm/nf/biz/heal_vnf.py +++ b/lcm/lcm/nf/biz/heal_vnf.py @@ -100,12 +100,12 @@ class HealVnf(Thread): operation_state=OPERATION_STATE_TYPE.COMPLETED ) except NFLCMException as e: - logger.error(e.message) - self.vnf_heal_failed_handle(e.message) + logger.error(e.args[0]) + self.vnf_heal_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) - self.vnf_heal_failed_handle(e.message) + self.vnf_heal_failed_handle(e.args[0]) def pre_deal(self): logger.debug("Start pre deal for VNF heal_vnf task") diff --git a/lcm/lcm/nf/biz/instantiate_vnf.py b/lcm/lcm/nf/biz/instantiate_vnf.py index 0ecd95e1..57711f75 100644 --- a/lcm/lcm/nf/biz/instantiate_vnf.py +++ b/lcm/lcm/nf/biz/instantiate_vnf.py @@ -83,9 +83,9 @@ class InstantiateVnf(Thread): operation_state=OPERATION_STATE_TYPE.COMPLETED ) except NFLCMException as e: - self.vnf_inst_failed_handle(e.message) + self.vnf_inst_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(str(e)) logger.error(traceback.format_exc()) self.vnf_inst_failed_handle('unexpected exception') @@ -113,9 +113,9 @@ class InstantiateVnf(Thread): input_parameters = [] inputs = ignore_case_get(self.data, "additionalParams") if inputs: - if isinstance(inputs, (str, unicode)): + if isinstance(inputs, str): inputs = json.loads(inputs) - for key, val in inputs.items(): + for key, val in list(inputs.items()): input_parameters.append({"key": key, "value": val}) vnf_package = query_vnfpackage_by_id(self.vnfd_id) pkg_info = ignore_case_get(vnf_package, "packageInfo") @@ -198,7 +198,7 @@ class InstantiateVnf(Thread): resp = notify_lcm_to_nfvo(json.dumps(notification_content)) logger.info('Lcm notify end, response %s' % resp) except Exception as e: - logger.error("Lcm instantiate notify failed: %s", e.message) + logger.error("Lcm instantiate notify failed: %s", e.args[0]) NotificationsUtil().send_notification(notification_content) def vnf_inst_failed_handle(self, error_msg): diff --git a/lcm/lcm/nf/biz/operate_vnf.py b/lcm/lcm/nf/biz/operate_vnf.py index c0c8540b..17227923 100644 --- a/lcm/lcm/nf/biz/operate_vnf.py +++ b/lcm/lcm/nf/biz/operate_vnf.py @@ -75,11 +75,11 @@ class OperateVnf(Thread): OPERATION_STATE_TYPE.COMPLETED ) except NFLCMException as e: - self.vnf_operate_failed_handle(e.message) + self.vnf_operate_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) - self.vnf_operate_failed_handle(e.message) + self.vnf_operate_failed_handle(e.args[0]) def apply_grant(self): vdus = VmInstModel.objects.filter(instid=self.nf_inst_id) diff --git a/lcm/lcm/nf/biz/query_subscription.py b/lcm/lcm/nf/biz/query_subscription.py index aedb467d..f2270d0a 100644 --- a/lcm/lcm/nf/biz/query_subscription.py +++ b/lcm/lcm/nf/biz/query_subscription.py @@ -38,10 +38,10 @@ class QuerySubscription: def query_multi_subscriptions(self): query_data = {} logger.debug("QueryMultiSubscriptions--get--biz::> Check for filters in query params" % self.params) - for query, value in self.params.iteritems(): + for query, value in list(self.params.items()): if query in ROOT_FILTERS: query_data[ROOT_FILTERS[query] + '__icontains'] = value - for query, value in self.params.iteritems(): + for query, value in list(self.params.items()): if query in VNF_INSTANCE_FILTERS: query_data[VNF_INSTANCE_FILTERS[query] + '__icontains'] = value # Query the database with filters if the request has fields in request params, else fetch all records diff --git a/lcm/lcm/nf/biz/query_vnf_lcm_op_occ.py b/lcm/lcm/nf/biz/query_vnf_lcm_op_occ.py index 01d8b8db..b352f5c4 100644 --- a/lcm/lcm/nf/biz/query_vnf_lcm_op_occ.py +++ b/lcm/lcm/nf/biz/query_vnf_lcm_op_occ.py @@ -38,7 +38,7 @@ class QueryVnfLcmOpOcc: def query_multi_vnf_lcm_op_occ(self): query_data = {} logger.debug("QueryMultiVnfLcmOpOccs--get--biz::> Check for filters in query params" % self.params) - for query, value in self.params.iteritems(): + for query, value in list(self.params.items()): if query in FILTERS: query_data[FILTERS[query]] = value # Query the database with filters if the request has fields in request params, else fetch all records @@ -59,9 +59,9 @@ class QueryVnfLcmOpOcc: 'vnfInstanceId': lcm_op.vnf_instance_id, 'grantId': None, 'operation': lcm_op.operation, - 'isAutomaticInvocation': lcm_op.is_automatic_invocation, + 'isAutomaticInvocation': False if lcm_op.is_automatic_invocation == 'False' else True, 'operationParams': json.loads(lcm_op.operation_params), - 'isCancelPending': lcm_op.is_cancel_pending, + 'isCancelPending': False if lcm_op.is_cancel_pending == 'False' else True, 'cancelMode': lcm_op.cancel_mode, 'error': None if not lcm_op.error else json.loads(lcm_op.error), 'resourceChanges': None if not lcm_op.resource_changes else json.loads(lcm_op.resource_changes), diff --git a/lcm/lcm/nf/biz/scale_vnf.py b/lcm/lcm/nf/biz/scale_vnf.py index ad828dd0..2f5b31e8 100644 --- a/lcm/lcm/nf/biz/scale_vnf.py +++ b/lcm/lcm/nf/biz/scale_vnf.py @@ -75,12 +75,12 @@ class ScaleVnf(Thread): self.vnf_insts.update(status=INSTANTIATION_STATE.INSTANTIATED, lastuptime=now_time()) except NFLCMException as e: - logger.error(e.message) - self.vnf_scale_failed_handle(e.message) + logger.error(e.args[0]) + self.vnf_scale_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) - self.vnf_scale_failed_handle(e.message) + self.vnf_scale_failed_handle(e.args[0]) def scale_pre(self): self.scale_type = self.data.get("type") @@ -196,7 +196,7 @@ class ScaleVnf(Thread): def do_notify_del_vim_res(self, res_type, res_id): logger.debug('Scaling in [%s] resource, resourceid [%s]', res_type, res_id) - resource_type = RESOURCE_MAP.keys()[RESOURCE_MAP.values().index(res_type)] + resource_type = list(RESOURCE_MAP.keys())[list(RESOURCE_MAP.values()).index(res_type)] resource_table = globals().get(resource_type + 'InstModel') resource_table.objects.filter(instid=self.nf_inst_id, resourceid=res_id).delete() if res_type == "vm": diff --git a/lcm/lcm/nf/biz/scale_vnf_to_level.py b/lcm/lcm/nf/biz/scale_vnf_to_level.py index 0e856ecd..eff83b43 100644 --- a/lcm/lcm/nf/biz/scale_vnf_to_level.py +++ b/lcm/lcm/nf/biz/scale_vnf_to_level.py @@ -86,7 +86,7 @@ class ScaleVnfToLevel(ScaleVnf): if policy.get("type") != "tosca.policies.nfv.InstantiationLevels": continue levels = policy["properties"]["levels"] - for level_id, level_info in levels.items(): + for level_id, level_info in list(levels.items()): scale_aspect = level_info["scale_info"].get(self.aspect_id) scale_level_in_vnfd = scale_aspect["scale_level"] if scale_level_in_request == scale_level_in_vnfd: @@ -99,5 +99,5 @@ class ScaleVnfToLevel(ScaleVnf): continue levels = policy["properties"]["levels"] level_info = levels.get(self.instantiation_level_id) - return level_info.get("scale_info").keys()[0] + return list(level_info.get("scale_info").keys())[0] raise NFLCMException("Failed to get aspect_id in vnfd") diff --git a/lcm/lcm/nf/biz/terminate_vnf.py b/lcm/lcm/nf/biz/terminate_vnf.py index d9faac6e..2b04dc96 100644 --- a/lcm/lcm/nf/biz/terminate_vnf.py +++ b/lcm/lcm/nf/biz/terminate_vnf.py @@ -102,11 +102,11 @@ class TerminateVnf(Thread): "Terminate Vnf success." ) except NFLCMException as e: - self.vnf_term_failed_handle(e.message) + self.vnf_term_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) - self.vnf_term_failed_handle(e.message) + self.vnf_term_failed_handle(e.args[0]) def term_pre(self): vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) @@ -123,7 +123,7 @@ class TerminateVnf(Thread): def query_inst_resource(self): logger.info('Query resource begin') - for resource_type in RESOURCE_MAP.keys(): + for resource_type in list(RESOURCE_MAP.keys()): resource_table = globals().get(resource_type + 'InstModel') resource_insts = resource_table.objects.filter(instid=self.nf_inst_id) for resource_inst in resource_insts: @@ -164,7 +164,7 @@ class TerminateVnf(Thread): def do_notify_delete(self, res_type, res_id): logger.debug('Deleting [%s] resource, resourceid [%s]' % (res_type, res_id)) - resource_type = RESOURCE_MAP.keys()[RESOURCE_MAP.values().index(res_type)] + resource_type = list(RESOURCE_MAP.keys())[list(RESOURCE_MAP.values()).index(res_type)] resource_table = globals().get(resource_type + 'InstModel') resource_table.objects.filter(instid=self.nf_inst_id, resourceid=res_id).delete() @@ -179,7 +179,7 @@ class TerminateVnf(Thread): logger.info('Lcm notify end, response: %s' % resp) NotificationsUtil().send_notification(self.notify_data) except Exception as e: - logger.error("Lcm terminate notify failed: %s", e.message) + logger.error("Lcm terminate notify failed: %s", e.args[0]) def vnf_term_failed_handle(self, error_msg): logger.error('VNF termination failed, detail message: %s' % error_msg) diff --git a/lcm/lcm/nf/biz/update_vnf.py b/lcm/lcm/nf/biz/update_vnf.py index 9ae7d663..0dfaa755 100644 --- a/lcm/lcm/nf/biz/update_vnf.py +++ b/lcm/lcm/nf/biz/update_vnf.py @@ -69,14 +69,14 @@ class UpdateVnf(Thread): JobUtil.add_job_status(self.job_id, 100, "Update VNF success.") except NFLCMException as e: - logger.error(e.message) - self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, e.message) - JobUtil.add_job_status(self.job_id, 255, e.message) + logger.error(e.args[0]) + self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, e.args[0]) + JobUtil.add_job_status(self.job_id, 255, e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) - self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, e.message) - JobUtil.add_job_status(self.job_id, 255, e.message) + self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, e.args[0]) + JobUtil.add_job_status(self.job_id, 255, e.args[0]) def send_notification(self): notify_data = prepare_notification(nfinstid=self.nf_inst_id, diff --git a/lcm/lcm/nf/serializers/_links.py b/lcm/lcm/nf/serializers/_links.py index 71828b09..ba7b7762 100644 --- a/lcm/lcm/nf/serializers/_links.py +++ b/lcm/lcm/nf/serializers/_links.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from link import linkSerializer +from .link import linkSerializer class _LinksSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/affected_storages.py b/lcm/lcm/nf/serializers/affected_storages.py index 1c01fefb..a33a05ac 100644 --- a/lcm/lcm/nf/serializers/affected_storages.py +++ b/lcm/lcm/nf/serializers/affected_storages.py @@ -15,7 +15,7 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer +from .resource_handle import ResourceHandleSerializer from lcm.nf.const import CHANGE_TYPE CHANGE_TYPES = [ diff --git a/lcm/lcm/nf/serializers/affected_vls.py b/lcm/lcm/nf/serializers/affected_vls.py index 0b47b27f..7803219e 100644 --- a/lcm/lcm/nf/serializers/affected_vls.py +++ b/lcm/lcm/nf/serializers/affected_vls.py @@ -15,7 +15,7 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer +from .resource_handle import ResourceHandleSerializer from lcm.nf.const import CHANGE_TYPE CHANGE_TYPES = [ diff --git a/lcm/lcm/nf/serializers/affected_vnfcs.py b/lcm/lcm/nf/serializers/affected_vnfcs.py index 10d93473..0e06755e 100644 --- a/lcm/lcm/nf/serializers/affected_vnfcs.py +++ b/lcm/lcm/nf/serializers/affected_vnfcs.py @@ -15,7 +15,7 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer +from .resource_handle import ResourceHandleSerializer from lcm.nf.const import CHANGE_TYPE CHANGE_TYPES = [ diff --git a/lcm/lcm/nf/serializers/cp_protocol_data.py b/lcm/lcm/nf/serializers/cp_protocol_data.py index 495e35f0..1fcfb52b 100644 --- a/lcm/lcm/nf/serializers/cp_protocol_data.py +++ b/lcm/lcm/nf/serializers/cp_protocol_data.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from ip_over_ethernet_address_data import IpOverEthernetAddressDataSerializer +from .ip_over_ethernet_address_data import IpOverEthernetAddressDataSerializer class CpProtocolDataSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ext_cp_info.py b/lcm/lcm/nf/serializers/ext_cp_info.py index 0d427f82..52f513e4 100644 --- a/lcm/lcm/nf/serializers/ext_cp_info.py +++ b/lcm/lcm/nf/serializers/ext_cp_info.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from cp_protocol_info import CpProtocolInfoSerializer +from .cp_protocol_info import CpProtocolInfoSerializer class ExtCpInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ext_link_port_data.py b/lcm/lcm/nf/serializers/ext_link_port_data.py index c6dafdd4..02d0bbc1 100644 --- a/lcm/lcm/nf/serializers/ext_link_port_data.py +++ b/lcm/lcm/nf/serializers/ext_link_port_data.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer +from .resource_handle import ResourceHandleSerializer class ExtLinkPortDataSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ext_link_port_info.py b/lcm/lcm/nf/serializers/ext_link_port_info.py index e8821c5d..35fd3680 100644 --- a/lcm/lcm/nf/serializers/ext_link_port_info.py +++ b/lcm/lcm/nf/serializers/ext_link_port_info.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer +from .resource_handle import ResourceHandleSerializer class ExtlinkPortInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ext_managed_virtual_link_info.py b/lcm/lcm/nf/serializers/ext_managed_virtual_link_info.py index ae0107fb..b6fe9cf0 100644 --- a/lcm/lcm/nf/serializers/ext_managed_virtual_link_info.py +++ b/lcm/lcm/nf/serializers/ext_managed_virtual_link_info.py @@ -14,8 +14,8 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer -from vnf_link_port_info import VnfLinkPortInfoSerializer +from .resource_handle import ResourceHandleSerializer +from .vnf_link_port_info import VnfLinkPortInfoSerializer class ExtManagedVirtualLinkInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ext_virtual_link_data.py b/lcm/lcm/nf/serializers/ext_virtual_link_data.py index 612e00cb..62beee66 100644 --- a/lcm/lcm/nf/serializers/ext_virtual_link_data.py +++ b/lcm/lcm/nf/serializers/ext_virtual_link_data.py @@ -14,8 +14,8 @@ from rest_framework import serializers -from vnf_ext_cp_data import VnfExtCpDataSerializer -from ext_link_port_data import ExtLinkPortDataSerializer +from .vnf_ext_cp_data import VnfExtCpDataSerializer +from .ext_link_port_data import ExtLinkPortDataSerializer class ExtVirtualLinkDataSerizlizer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ext_virtual_link_info.py b/lcm/lcm/nf/serializers/ext_virtual_link_info.py index 90cc7c7f..3a8bbcf4 100644 --- a/lcm/lcm/nf/serializers/ext_virtual_link_info.py +++ b/lcm/lcm/nf/serializers/ext_virtual_link_info.py @@ -14,8 +14,8 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer -from ext_link_port_info import ExtlinkPortInfoSerializer +from .resource_handle import ResourceHandleSerializer +from .ext_link_port_info import ExtlinkPortInfoSerializer class ExtVirtualLinkInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/instantiate_vnf_request.py b/lcm/lcm/nf/serializers/instantiate_vnf_request.py index 9290d84a..72376c49 100644 --- a/lcm/lcm/nf/serializers/instantiate_vnf_request.py +++ b/lcm/lcm/nf/serializers/instantiate_vnf_request.py @@ -14,9 +14,9 @@ from rest_framework import serializers -from ext_virtual_link_data import ExtVirtualLinkDataSerizlizer -from ext_managed_virtual_link_data import ExtManagedVirtualLinkDataSerizlizer -from vim_connection_info import VimConnectionInfoSerializer +from .ext_virtual_link_data import ExtVirtualLinkDataSerizlizer +from .ext_managed_virtual_link_data import ExtManagedVirtualLinkDataSerizlizer +from .vim_connection_info import VimConnectionInfoSerializer class InstantiateVnfRequestSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/instantiated_vnf_info.py b/lcm/lcm/nf/serializers/instantiated_vnf_info.py index cd6c93ec..86af9052 100644 --- a/lcm/lcm/nf/serializers/instantiated_vnf_info.py +++ b/lcm/lcm/nf/serializers/instantiated_vnf_info.py @@ -14,13 +14,13 @@ from rest_framework import serializers -from scale_info import ScaleInfoSerializer -from ext_cp_info import ExtCpInfoSerializer -from ext_virtual_link_info import ExtVirtualLinkInfoSerializer -from ext_managed_virtual_link_info import ExtManagedVirtualLinkInfoSerializer -from vnfc_resource_info import VnfcResourceInfoSerializer -from vnf_virtual_link_resource_info import VnfVirtualLinkResourceInfoSerializer -from virtual_storage_resource_info import VirtualStorageResourceInfoSerializer +from .scale_info import ScaleInfoSerializer +from .ext_cp_info import ExtCpInfoSerializer +from .ext_virtual_link_info import ExtVirtualLinkInfoSerializer +from .ext_managed_virtual_link_info import ExtManagedVirtualLinkInfoSerializer +from .vnfc_resource_info import VnfcResourceInfoSerializer +from .vnf_virtual_link_resource_info import VnfVirtualLinkResourceInfoSerializer +from .virtual_storage_resource_info import VirtualStorageResourceInfoSerializer class InstantiatedVnfInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ip_addresse.py b/lcm/lcm/nf/serializers/ip_addresse.py index f273c423..f266a459 100644 --- a/lcm/lcm/nf/serializers/ip_addresse.py +++ b/lcm/lcm/nf/serializers/ip_addresse.py @@ -10,7 +10,7 @@ # limitations under the License. from rest_framework import serializers -from address_range import AddressRangeSerializer +from .address_range import AddressRangeSerializer class IpAddresseSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/ip_over_ethernet_address_data.py b/lcm/lcm/nf/serializers/ip_over_ethernet_address_data.py index 562d5fb9..826082de 100644 --- a/lcm/lcm/nf/serializers/ip_over_ethernet_address_data.py +++ b/lcm/lcm/nf/serializers/ip_over_ethernet_address_data.py @@ -13,7 +13,7 @@ # limitations under the License. from rest_framework import serializers -from ip_addresse import IpAddresseSerializer +from .ip_addresse import IpAddresseSerializer class IpOverEthernetAddressDataSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/lccn_filter_data.py b/lcm/lcm/nf/serializers/lccn_filter_data.py index b016a4f0..30e0d9ab 100644 --- a/lcm/lcm/nf/serializers/lccn_filter_data.py +++ b/lcm/lcm/nf/serializers/lccn_filter_data.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from vnf_instance_subscription_filter import VnfInstanceSubscriptionFilter +from .vnf_instance_subscription_filter import VnfInstanceSubscriptionFilter from lcm.nf.const import NOTIFICATION_TYPES, LCM_OPERATION_TYPES, LCM_OPERATION_STATE_TYPES diff --git a/lcm/lcm/nf/serializers/lccn_subscription.py b/lcm/lcm/nf/serializers/lccn_subscription.py index e29c6d10..a92d0394 100644 --- a/lcm/lcm/nf/serializers/lccn_subscription.py +++ b/lcm/lcm/nf/serializers/lccn_subscription.py @@ -14,8 +14,8 @@ from rest_framework import serializers -from link import linkSerializer -from lccn_filter_data import LifeCycleChangeNotificationsFilter +from .link import linkSerializer +from .lccn_filter_data import LifeCycleChangeNotificationsFilter class LinkSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/lccn_subscription_request.py b/lcm/lcm/nf/serializers/lccn_subscription_request.py index 445845ae..d8b14957 100644 --- a/lcm/lcm/nf/serializers/lccn_subscription_request.py +++ b/lcm/lcm/nf/serializers/lccn_subscription_request.py @@ -14,8 +14,8 @@ from rest_framework import serializers -from lccn_filter_data import LifeCycleChangeNotificationsFilter -from subscription_auth_data import SubscriptionAuthenticationSerializer +from .lccn_filter_data import LifeCycleChangeNotificationsFilter +from .subscription_auth_data import SubscriptionAuthenticationSerializer class LccnSubscriptionRequestSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/lccn_subscriptions.py b/lcm/lcm/nf/serializers/lccn_subscriptions.py index c4f70f66..5161a4f0 100644 --- a/lcm/lcm/nf/serializers/lccn_subscriptions.py +++ b/lcm/lcm/nf/serializers/lccn_subscriptions.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from lccn_subscription import LccnSubscriptionSerializer +from .lccn_subscription import LccnSubscriptionSerializer class LccnSubscriptionsSerializer(serializers.ListSerializer): diff --git a/lcm/lcm/nf/serializers/notification_types.py b/lcm/lcm/nf/serializers/notification_types.py index d6755881..c87b76dd 100644 --- a/lcm/lcm/nf/serializers/notification_types.py +++ b/lcm/lcm/nf/serializers/notification_types.py @@ -14,14 +14,14 @@ from rest_framework import serializers -from affected_vnfcs import AffectedVnfcsSerializer -from affected_vls import AffectedVLsSerializer -from affected_storages import AffectedStoragesSerializer +from .affected_vnfcs import AffectedVnfcsSerializer +from .affected_vls import AffectedVLsSerializer +from .affected_storages import AffectedStoragesSerializer from lcm.nf.const import LCM_OPERATION_TYPES, LCM_OPERATION_STATE_TYPES -from link import linkSerializer -from response import ProblemDetailsSerializer -from ext_virtual_link_info import ExtVirtualLinkInfoSerializer -from vnf_info_modifications import VnfInfoModificationsSerializer +from .link import linkSerializer +from .response import ProblemDetailsSerializer +from .ext_virtual_link_info import ExtVirtualLinkInfoSerializer +from .vnf_info_modifications import VnfInfoModificationsSerializer class LccnLinksSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/virtual_storage_resource_info.py b/lcm/lcm/nf/serializers/virtual_storage_resource_info.py index 8ec23a37..5f5de12f 100644 --- a/lcm/lcm/nf/serializers/virtual_storage_resource_info.py +++ b/lcm/lcm/nf/serializers/virtual_storage_resource_info.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer +from .resource_handle import ResourceHandleSerializer class VirtualStorageResourceInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnf_ext_cp_config.py b/lcm/lcm/nf/serializers/vnf_ext_cp_config.py index b9fedf0a..73336eaf 100644 --- a/lcm/lcm/nf/serializers/vnf_ext_cp_config.py +++ b/lcm/lcm/nf/serializers/vnf_ext_cp_config.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from cp_protocol_data import CpProtocolDataSerializer +from .cp_protocol_data import CpProtocolDataSerializer class VnfExtCpConfigSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnf_ext_cp_data.py b/lcm/lcm/nf/serializers/vnf_ext_cp_data.py index 987569c9..9e6be889 100644 --- a/lcm/lcm/nf/serializers/vnf_ext_cp_data.py +++ b/lcm/lcm/nf/serializers/vnf_ext_cp_data.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from vnf_ext_cp_config import VnfExtCpConfigSerializer +from .vnf_ext_cp_config import VnfExtCpConfigSerializer class VnfExtCpDataSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnf_info_modifications.py b/lcm/lcm/nf/serializers/vnf_info_modifications.py index 8098a6ca..8d82635c 100644 --- a/lcm/lcm/nf/serializers/vnf_info_modifications.py +++ b/lcm/lcm/nf/serializers/vnf_info_modifications.py @@ -15,7 +15,7 @@ from rest_framework import serializers -from vim_connection_info import VimConnectionInfoSerializer +from .vim_connection_info import VimConnectionInfoSerializer class VnfInfoModificationsSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnf_instance.py b/lcm/lcm/nf/serializers/vnf_instance.py index 2521e8ee..020ddf7b 100644 --- a/lcm/lcm/nf/serializers/vnf_instance.py +++ b/lcm/lcm/nf/serializers/vnf_instance.py @@ -15,9 +15,9 @@ from rest_framework import serializers -from vim_connection_info import VimConnectionInfoSerializer -from instantiated_vnf_info import InstantiatedVnfInfoSerializer -from _links import _LinksSerializer +from .vim_connection_info import VimConnectionInfoSerializer +from .instantiated_vnf_info import InstantiatedVnfInfoSerializer +from ._links import _LinksSerializer class VnfInstanceSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnf_instances.py b/lcm/lcm/nf/serializers/vnf_instances.py index f3132904..d9530fe5 100644 --- a/lcm/lcm/nf/serializers/vnf_instances.py +++ b/lcm/lcm/nf/serializers/vnf_instances.py @@ -10,7 +10,7 @@ # limitations under the License. from rest_framework import serializers -from vnf_instance import VnfInstanceSerializer +from .vnf_instance import VnfInstanceSerializer class VnfInstancesSerializer(serializers.ListSerializer): diff --git a/lcm/lcm/nf/serializers/vnf_lcm_op_occ.py b/lcm/lcm/nf/serializers/vnf_lcm_op_occ.py index 267f5f8d..45e2f514 100644 --- a/lcm/lcm/nf/serializers/vnf_lcm_op_occ.py +++ b/lcm/lcm/nf/serializers/vnf_lcm_op_occ.py @@ -15,13 +15,13 @@ from rest_framework import serializers -from affected_vnfcs import AffectedVnfcsSerializer -from affected_vls import AffectedVLsSerializer -from affected_storages import AffectedStoragesSerializer -from link import linkSerializer -from response import ProblemDetailsSerializer -from ext_virtual_link_info import ExtVirtualLinkInfoSerializer -from vnf_info_modifications import VnfInfoModificationsSerializer +from .affected_vnfcs import AffectedVnfcsSerializer +from .affected_vls import AffectedVLsSerializer +from .affected_storages import AffectedStoragesSerializer +from .link import linkSerializer +from .response import ProblemDetailsSerializer +from .ext_virtual_link_info import ExtVirtualLinkInfoSerializer +from .vnf_info_modifications import VnfInfoModificationsSerializer LCM_OPERATION_TYPES = [ diff --git a/lcm/lcm/nf/serializers/vnf_lcm_op_occs.py b/lcm/lcm/nf/serializers/vnf_lcm_op_occs.py index 6cb70906..1baa0975 100644 --- a/lcm/lcm/nf/serializers/vnf_lcm_op_occs.py +++ b/lcm/lcm/nf/serializers/vnf_lcm_op_occs.py @@ -13,7 +13,7 @@ # limitations under the License. from rest_framework import serializers -from vnf_lcm_op_occ import VNFLCMOpOccSerializer +from .vnf_lcm_op_occ import VNFLCMOpOccSerializer class VNFLCMOpOccsSerializer(serializers.ListSerializer): diff --git a/lcm/lcm/nf/serializers/vnf_link_port_info.py b/lcm/lcm/nf/serializers/vnf_link_port_info.py index 06201aef..331175ba 100644 --- a/lcm/lcm/nf/serializers/vnf_link_port_info.py +++ b/lcm/lcm/nf/serializers/vnf_link_port_info.py @@ -14,7 +14,7 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer +from .resource_handle import ResourceHandleSerializer class VnfLinkPortInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnf_virtual_link_resource_info.py b/lcm/lcm/nf/serializers/vnf_virtual_link_resource_info.py index e5c9d4c4..c5e3675f 100644 --- a/lcm/lcm/nf/serializers/vnf_virtual_link_resource_info.py +++ b/lcm/lcm/nf/serializers/vnf_virtual_link_resource_info.py @@ -13,8 +13,8 @@ # limitations under the License. from rest_framework import serializers -from resource_handle import ResourceHandleSerializer -from vnf_link_port_info import VnfLinkPortInfoSerializer +from .resource_handle import ResourceHandleSerializer +from .vnf_link_port_info import VnfLinkPortInfoSerializer class VnfVirtualLinkResourceInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnfc_cp_info.py b/lcm/lcm/nf/serializers/vnfc_cp_info.py index 693aba16..5e8e9f56 100644 --- a/lcm/lcm/nf/serializers/vnfc_cp_info.py +++ b/lcm/lcm/nf/serializers/vnfc_cp_info.py @@ -1,7 +1,7 @@ from rest_framework import serializers -from cp_protocol_info import CpProtocolInfoSerializer +from .cp_protocol_info import CpProtocolInfoSerializer class VnfcCpInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/serializers/vnfc_resource_info.py b/lcm/lcm/nf/serializers/vnfc_resource_info.py index 3ad0c6f5..4a8e493f 100644 --- a/lcm/lcm/nf/serializers/vnfc_resource_info.py +++ b/lcm/lcm/nf/serializers/vnfc_resource_info.py @@ -14,8 +14,8 @@ from rest_framework import serializers -from resource_handle import ResourceHandleSerializer -from vnfc_cp_info import VnfcCpInfoSerializer +from .resource_handle import ResourceHandleSerializer +from .vnfc_cp_info import VnfcCpInfoSerializer class VnfcResourceInfoSerializer(serializers.Serializer): diff --git a/lcm/lcm/nf/tests/const.py b/lcm/lcm/nf/tests/const.py index 46b608b3..7debe6bc 100644 --- a/lcm/lcm/nf/tests/const.py +++ b/lcm/lcm/nf/tests/const.py @@ -125,17 +125,17 @@ inst_req_data = { vnfd_model_dict = { 'metadata': { - 'vendor': u'zte', + 'vendor': 'zte', 'is_shared': False, 'description': '', - 'domain_type': u'CN', - 'version': u'v4.14.10', + 'domain_type': 'CN', + 'version': 'v4.14.10', 'vmnumber_overquota_alarm': False, 'cross_dc': False, - 'vnf_type': u'SSS', - 'vnfd_version': u'V00000001', - 'id': u'sss-vnf-template', - 'name': u'sss-vnf-template' + 'vnf_type': 'SSS', + 'vnfd_version': 'V00000001', + 'id': 'sss-vnf-template', + 'name': 'sss-vnf-template' }, 'vdus': [ { @@ -182,7 +182,7 @@ vnfd_model_dict = { "inner_hugepage_size": "2048", "action": "add" }, - "image_file": u'sss', + "image_file": 'sss', "local_storages": [ "local_storage_id1", "local_storage_id2" @@ -304,7 +304,7 @@ vnfd_model_dict = { 'targets': { }, - 'policy_id': u'policy_scale_sss-vnf-template', + 'policy_id': 'policy_scale_sss-vnf-template', 'properties': { 'policy_file': '*-vnfd.zip/*-vnf-policy.xml' }, @@ -315,28 +315,28 @@ vnfd_model_dict = { { 'description': '', 'properties': { - 'name': u'opencos_sss_omm_img_release_20150723-1-disk1.vmdk', + 'name': 'opencos_sss_omm_img_release_20150723-1-disk1.vmdk', 'checksum': '', - 'disk_format': u'VMDK', - 'file_url': u'./zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk', + 'disk_format': 'VMDK', + 'file_url': './zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk', 'container_type': 'vm', 'version': '', 'hypervisor_type': 'kvm' }, - 'image_file_id': u'opencos_sss_omm_img_release_20150723-1-disk1' + 'image_file_id': 'opencos_sss_omm_img_release_20150723-1-disk1' }, { 'description': '', 'properties': { - 'name': u'sss.vmdk', + 'name': 'sss.vmdk', 'checksum': '', - 'disk_format': u'VMDK', - 'file_url': u'./zte-cn-sss-main-image/NE/sss.vmdk', + 'disk_format': 'VMDK', + 'file_url': './zte-cn-sss-main-image/NE/sss.vmdk', 'container_type': 'vm', 'version': '', 'hypervisor_type': 'kvm' }, - 'image_file_id': u'sss' + 'image_file_id': 'sss' } ], 'vls': [ @@ -567,7 +567,7 @@ c8_data_list_image = { "status": "active", "id": "5e2757c1-f846-4727-915c-9a872553ed75", "size": 862016, - "name": u'sss.vmdk' + "name": 'sss.vmdk' } ] } diff --git a/lcm/lcm/nf/tests/test_change_ext_conn.py b/lcm/lcm/nf/tests/test_change_ext_conn.py index 7efb416f..2fafc24c 100644 --- a/lcm/lcm/nf/tests/test_change_ext_conn.py +++ b/lcm/lcm/nf/tests/test_change_ext_conn.py @@ -90,21 +90,21 @@ class TestChangeExtConn(TestCase): response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code) + self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) def test_change_ext_conn_conflict(self): url = "/api/vnflcm/v1/vnf_instances/12345/change_ext_conn" response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code) + self.assertEqual(status.HTTP_409_CONFLICT, response.status_code) def test_change_ext_conn_badreq(self): url = "/api/vnflcm/v1/vnf_instances/123/change_ext_conn" response = self.client.post(url, data={}, format='json') - self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code) + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) @mock.patch.object(JobUtil, 'create_job') def test_change_ext_conn_inner_error(self, mock_run): diff --git a/lcm/lcm/nf/tests/test_change_flavour.py b/lcm/lcm/nf/tests/test_change_flavour.py index 15b53f02..442fd8d5 100644 --- a/lcm/lcm/nf/tests/test_change_flavour.py +++ b/lcm/lcm/nf/tests/test_change_flavour.py @@ -54,18 +54,18 @@ class TestFlavour(TestCase): response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code) + self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) def test_change_flavour_conflict(self): url = "/api/vnflcm/v1/vnf_instances/12345/change_flavour" response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code) + self.assertEqual(status.HTTP_409_CONFLICT, response.status_code) def test_change_flavour_badreq(self): url = "/api/vnflcm/v1/vnf_instances/345/change_flavour" response = self.client.post(url, data={}, format='json') - self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code) + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) diff --git a/lcm/lcm/nf/tests/test_create_vnf.py b/lcm/lcm/nf/tests/test_create_vnf.py index 77655346..39640b57 100644 --- a/lcm/lcm/nf/tests/test_create_vnf.py +++ b/lcm/lcm/nf/tests/test_create_vnf.py @@ -71,7 +71,7 @@ class TestNFInstantiate(TestCase): data=data, format='json' ) - self.failUnlessEqual( + self.assertEqual( status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code ) @@ -108,4 +108,5 @@ class TestNFInstantiate(TestCase): "vnfPkgId": "111", "instantiationState": "NOT_INSTANTIATED" } + self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertEqual(expect_data, response.data) diff --git a/lcm/lcm/nf/tests/test_delete_vnf.py b/lcm/lcm/nf/tests/test_delete_vnf.py index 4253ed12..61d173eb 100644 --- a/lcm/lcm/nf/tests/test_delete_vnf.py +++ b/lcm/lcm/nf/tests/test_delete_vnf.py @@ -127,9 +127,9 @@ class TestNFTerminate(TestCase): create_time=now_time() ) response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111") - self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code) + self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) self.assertEqual(None, response.data) def test_delete_vnf_identifier_when_vnf_not_exist(self): response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111") - self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code) + self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) diff --git a/lcm/lcm/nf/tests/test_heal_vnf.py b/lcm/lcm/nf/tests/test_heal_vnf.py index d5c70da0..1bdcd9fc 100644 --- a/lcm/lcm/nf/tests/test_heal_vnf.py +++ b/lcm/lcm/nf/tests/test_heal_vnf.py @@ -52,7 +52,7 @@ class TestNFInstantiate(TestCase): def test_heal_vnf_not_found(self):
req_data = {}
response = self.client.post("/api/vnflcm/v1/vnf_instances/12/heal", data=req_data, format='json')
- self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code)
+ self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
def test_heal_vnf_conflict(self):
req_data = {}
@@ -61,7 +61,7 @@ class TestNFInstantiate(TestCase): nf_name='VNF1',
status='NOT_INSTANTIATED').save()
response = self.client.post("/api/vnflcm/v1/vnf_instances/1267/heal", data=req_data, format='json')
- self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
+ self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
NfInstModel.objects.filter(nfinstid='1267').delete()
def test_heal_vnf_badreq(self):
@@ -80,7 +80,7 @@ class TestNFInstantiate(TestCase): data={"additionalParams": "1"},
format='json')
NfInstModel.objects.filter(nfinstid='345').delete()
- self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
+ self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
@mock.patch.object(HealVnf, 'run')
def test_heal_vnf_success(self, mock_run):
@@ -97,7 +97,7 @@ class TestNFInstantiate(TestCase): status='INSTANTIATED').save()
response = self.client.post("/api/vnflcm/v1/vnf_instances/12/heal", data=req_data, format='json')
mock_run.re.return_value = None
- self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+ self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
NfInstModel(nfinstid='12').delete()
@mock.patch.object(restcall, 'call_req')
diff --git a/lcm/lcm/nf/tests/test_instantiate_vnf.py b/lcm/lcm/nf/tests/test_instantiate_vnf.py index c624e05c..16351f98 100644 --- a/lcm/lcm/nf/tests/test_instantiate_vnf.py +++ b/lcm/lcm/nf/tests/test_instantiate_vnf.py @@ -76,7 +76,7 @@ class TestNFInstantiate(TestCase): data=inst_req_data,
format='json'
)
- self.failUnlessEqual(
+ self.assertEqual(
status.HTTP_202_ACCEPTED,
response.status_code
)
@@ -89,7 +89,7 @@ class TestNFInstantiate(TestCase): data=inst_req_data,
format='json'
)
- self.failUnlessEqual(
+ self.assertEqual(
status.HTTP_404_NOT_FOUND,
response.status_code,
response.content
@@ -108,7 +108,7 @@ class TestNFInstantiate(TestCase): data=inst_req_data,
format='json'
)
- self.failUnlessEqual(
+ self.assertEqual(
status.HTTP_409_CONFLICT,
response.status_code,
response.content
diff --git a/lcm/lcm/nf/tests/test_operate_vnf.py b/lcm/lcm/nf/tests/test_operate_vnf.py index cffcf37d..17408c2e 100644 --- a/lcm/lcm/nf/tests/test_operate_vnf.py +++ b/lcm/lcm/nf/tests/test_operate_vnf.py @@ -55,7 +55,7 @@ class TestNFOperate(TestCase): data=req_data,
format='json'
)
- self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code)
+ self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
def test_operate_vnf_conflict(self):
req_data = {
@@ -71,7 +71,7 @@ class TestNFOperate(TestCase): data=req_data,
format='json'
)
- self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
+ self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
NfInstModel(
nfinstid='12',
nf_name='VNF1',
@@ -98,7 +98,7 @@ class TestNFOperate(TestCase): format='json'
)
NfInstModel.objects.filter(nfinstid='345').delete()
- self.failUnlessEqual(
+ self.assertEqual(
status.HTTP_400_BAD_REQUEST,
response.status_code
)
@@ -119,7 +119,7 @@ class TestNFOperate(TestCase): format='json'
)
mock_run.re.return_value = None
- self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+ self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
NfInstModel(
nfinstid='12',
nf_name='VNF1',
diff --git a/lcm/lcm/nf/tests/test_query_vnf.py b/lcm/lcm/nf/tests/test_query_vnf.py index e041216c..5d133de3 100644 --- a/lcm/lcm/nf/tests/test_query_vnf.py +++ b/lcm/lcm/nf/tests/test_query_vnf.py @@ -228,7 +228,7 @@ class ResourceTest(TestCase): insttype=1, instid='%s' % i).save() response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json') - self.failUnlessEqual(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.test_data_multi_vnf, response.data) def test_get_vnfs_not_exist(self): diff --git a/lcm/lcm/nf/tests/test_query_vnf_lcm_op.py b/lcm/lcm/nf/tests/test_query_vnf_lcm_op.py index 1711ddca..c69859a4 100644 --- a/lcm/lcm/nf/tests/test_query_vnf_lcm_op.py +++ b/lcm/lcm/nf/tests/test_query_vnf_lcm_op.py @@ -33,6 +33,7 @@ class TestVNFLcmOpOccs(TestCase): self.test_vnflcmop_with_exclude_default = vnflcmop_with_exclude_default self.test_multiple_vnf_lcm_op = copy.copy(multiple_vnf_lcm_op) self.test_multiple_vnf_lcm_op.append(self.test_single_vnf_lcm_op) + self.maxdiff = None def tearDown(self): pass @@ -69,6 +70,7 @@ class TestVNFLcmOpOccs(TestCase): response.status_code, status.HTTP_200_OK ) + self.maxDiff = None self.assertEqual( [self.test_single_vnf_lcm_op], response.data @@ -147,9 +149,9 @@ class TestVNFLcmOpOccs(TestCase): response.status_code, status.HTTP_200_OK ) + self.maxDiff = None self.assertEqual( self.test_multiple_vnf_lcm_op, - response.data, response.data ) @@ -211,6 +213,7 @@ class TestVNFLcmOpOccs(TestCase): response.status_code, status.HTTP_200_OK ) + self.maxDiff = None self.assertEqual( self.test_vnflcmop_with_exclude_default, response.data @@ -248,6 +251,7 @@ class TestVNFLcmOpOccs(TestCase): response.status_code, status.HTTP_200_OK ) + self.maxDiff = None self.assertEqual( self.test_single_vnf_lcm_op, response.data diff --git a/lcm/lcm/nf/tests/test_scale_vnf.py b/lcm/lcm/nf/tests/test_scale_vnf.py index a43c475c..bb470fa8 100644 --- a/lcm/lcm/nf/tests/test_scale_vnf.py +++ b/lcm/lcm/nf/tests/test_scale_vnf.py @@ -44,14 +44,14 @@ class TestNfScale(TestCase): response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code) + self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) def test_scale_vnf_conflict(self): url = "/api/vnflcm/v1/vnf_instances/12345/scale" response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code) + self.assertEqual(status.HTTP_409_CONFLICT, response.status_code) def test_scale_vnf_badreq(self): NfInstModel(nfinstid='678', @@ -69,4 +69,4 @@ class TestNfScale(TestCase): data={}, format='json') NfInstModel.objects.filter(nfinstid='678').delete() - self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code) + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) diff --git a/lcm/lcm/nf/tests/test_scale_vnf_to_level.py b/lcm/lcm/nf/tests/test_scale_vnf_to_level.py index 7c7b98d8..0c06694a 100644 --- a/lcm/lcm/nf/tests/test_scale_vnf_to_level.py +++ b/lcm/lcm/nf/tests/test_scale_vnf_to_level.py @@ -44,14 +44,14 @@ class TestNfScaleToLevel(TestCase): response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code) + self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) def test_scale_vnf_conflict(self): url = "/api/vnflcm/v1/vnf_instances/98765/scale_to_level" response = self.client.post(url, data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code) + self.assertEqual(status.HTTP_409_CONFLICT, response.status_code) def test_scale_to_level_badreq(self): NfInstModel(nfinstid='678', @@ -69,4 +69,4 @@ class TestNfScaleToLevel(TestCase): data={}, format='json') NfInstModel.objects.filter(nfinstid='678').delete() - self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code) + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) diff --git a/lcm/lcm/nf/tests/test_subscribe_notification.py b/lcm/lcm/nf/tests/test_subscribe_notification.py index 70a309b8..237ef2dc 100644 --- a/lcm/lcm/nf/tests/test_subscribe_notification.py +++ b/lcm/lcm/nf/tests/test_subscribe_notification.py @@ -106,6 +106,13 @@ class TestSubscription(TestCase): def test_invalid_notification_type(self, mock_requests): dummy_subscription = { "callbackUri": "http://aurl.com", + "authentication": { + "authType": ["BASIC"], + "paramsBasic": { + "username": "username", + "password": "password" + } + }, "filter": { "notificationTypes": ["VnfIdentifierDeletionNotification"], "operationTypes": [ diff --git a/lcm/lcm/nf/tests/test_terminate_vnf.py b/lcm/lcm/nf/tests/test_terminate_vnf.py index 4b235c14..79acbc7c 100644 --- a/lcm/lcm/nf/tests/test_terminate_vnf.py +++ b/lcm/lcm/nf/tests/test_terminate_vnf.py @@ -137,7 +137,7 @@ class TestNFTerminate(TestCase): data=req_data,
format='json'
)
- self.failUnlessEqual(
+ self.assertEqual(
status.HTTP_202_ACCEPTED,
response.status_code,
response.content
@@ -155,7 +155,7 @@ class TestNFTerminate(TestCase): data=req_data,
format='json'
)
- self.failUnlessEqual(
+ self.assertEqual(
status.HTTP_404_NOT_FOUND,
response.status_code,
response.content
@@ -185,7 +185,7 @@ class TestNFTerminate(TestCase): data=req_data,
format='json'
)
- self.failUnlessEqual(
+ self.assertEqual(
status.HTTP_409_CONFLICT,
response.status_code,
response.content
diff --git a/lcm/lcm/nf/tests/test_update_vnf.py b/lcm/lcm/nf/tests/test_update_vnf.py index 3c122605..91f451b6 100644 --- a/lcm/lcm/nf/tests/test_update_vnf.py +++ b/lcm/lcm/nf/tests/test_update_vnf.py @@ -40,7 +40,7 @@ class TestNFUpdate(TestCase): response = self.client.patch("/api/vnflcm/v1/vnf_instances/1111", data=self.upd_data, format='json') - self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code) + self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) def test_update_vnf_etag_not_match(self): instanceid = "19" @@ -62,7 +62,7 @@ class TestNFUpdate(TestCase): "If-Match": "test_etag" }) NfInstModel.objects.filter(nfinstid=instanceid).delete() - self.failUnlessEqual(status.HTTP_412_PRECONDITION_FAILED, response.status_code) + self.assertEqual(status.HTTP_412_PRECONDITION_FAILED, response.status_code) @mock.patch.object(UpdateVnf, 'run') def test_update_vnf_etag_match(self, mock_run): @@ -87,7 +87,7 @@ class TestNFUpdate(TestCase): "If-Match": etag }) NfInstModel.objects.filter(nfinstid=instanceid).delete() - self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code) + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(restcall, 'call_req') def test_update_vnf_success(self, mock_call_req): @@ -107,4 +107,4 @@ class TestNFUpdate(TestCase): UpdateVnf(self.upd_data, instanceid, job_id).run() name = NfInstModel.objects.filter(nfinstid=instanceid).get().nf_name NfInstModel.objects.filter(nfinstid=instanceid).delete() - self.failUnlessEqual("vnf new name", name) + self.assertEqual("vnf new name", name) diff --git a/lcm/lcm/nf/views/common.py b/lcm/lcm/nf/views/common.py index e24a8bce..6bab28fb 100644 --- a/lcm/lcm/nf/views/common.py +++ b/lcm/lcm/nf/views/common.py @@ -51,43 +51,43 @@ def view_safe_call_with_log(logger): try: return func(*args, **kwargs) except NFLCMExceptionSeeOther as e: - logger.error(e.message) + logger.error(e.args[0]) resp = Response(status=status.HTTP_303_SEE_OTHER) - resp["Location"] = e.message + resp["Location"] = e.args[0] # resp["Location"] = "subscriptions/%s" % e.id return resp except NFLCMExceptionNotFound as e: - logger.error(e.message) + logger.error(e.args[0]) return make_error_resp( - detail=e.message, + detail=e.args[0], status=status.HTTP_404_NOT_FOUND ) except NFLCMExceptionBadRequest as e: - logger.error(e.message) + logger.error(e.args[0]) return make_error_resp( - detail=e.message, + detail=e.args[0], status=status.HTTP_400_BAD_REQUEST ) except NFLCMExceptionConflict as e: - logger.error(e.message) + logger.error(e.args[0]) return make_error_resp( - detail=e.message, + detail=e.args[0], status=status.HTTP_409_CONFLICT ) except NFLCMExceptionPreconditionFailed as e: - logger.error(e.message) + logger.error(e.args[0]) return make_error_resp( - detail=e.message, + detail=e.args[0], status=status.HTTP_412_PRECONDITION_FAILED ) except NFLCMException as e: - logger.error(e.message) + logger.error(e.args[0]) return make_error_resp( - detail=e.message, + detail=e.args[0], status=status.HTTP_500_INTERNAL_SERVER_ERROR ) except Exception as e: - logger.error(e.message) + logger.error(e.args[0]) logger.error(traceback.format_exc()) return make_error_resp( detail='Unexpected exception', @@ -143,7 +143,7 @@ def deal_indivdual_query(res_serializer, query_fun, *args): if not resp_serializer.is_valid(): raise NFLCMException(resp_serializer.errors) - resp = Response(data=resp_serializer.data, status=status.HTTP_200_OK) + resp = Response(data=res, status=status.HTTP_200_OK) if res_serializer == VnfInstanceSerializer: CACHE_ETAG = "%s" % uuid.uuid1() logger.debug("set CACHE_ETAG = %s", CACHE_ETAG) diff --git a/lcm/lcm/nf/views/curd_vnf_views.py b/lcm/lcm/nf/views/curd_vnf_views.py index 29ca82b8..e8c19d67 100644 --- a/lcm/lcm/nf/views/curd_vnf_views.py +++ b/lcm/lcm/nf/views/curd_vnf_views.py @@ -54,7 +54,7 @@ class CreateVnfAndQueryVnfs(APIView): if not vnf_instances_serializer.is_valid(): raise NFLCMException(vnf_instances_serializer.errors) - return Response(data=vnf_instances_serializer.data, status=status.HTTP_200_OK) + return Response(data=resp_data, status=status.HTTP_200_OK) @swagger_auto_schema( request_body=CreateVnfReqSerializer(), @@ -71,15 +71,16 @@ class CreateVnfAndQueryVnfs(APIView): raise NFLCMException(req_serializer.errors) nf_inst = CreateVnf(request.data).do_biz() - create_vnf_resp_serializer = VnfInstanceSerializer( - data={"id": nf_inst.nfinstid, - "vnfProvider": nf_inst.vendor, - "vnfdVersion": nf_inst.version, - "vnfPkgId": nf_inst.package_id, - "instantiationState": nf_inst.status}) + rsp_data = {"id": nf_inst.nfinstid, + "vnfProvider": nf_inst.vendor, + "vnfdVersion": nf_inst.version, + "vnfPkgId": nf_inst.package_id, + "instantiationState": nf_inst.status} + create_vnf_resp_serializer = VnfInstanceSerializer(data=rsp_data) if not create_vnf_resp_serializer.is_valid(): raise NFLCMException(create_vnf_resp_serializer.errors) - return Response(data=create_vnf_resp_serializer.data, status=status.HTTP_201_CREATED) + + return Response(data=rsp_data, status=status.HTTP_201_CREATED) class DeleteVnfAndQueryVnf(APIView): diff --git a/lcm/lcm/nf/views/lcm_op_occs_view.py b/lcm/lcm/nf/views/lcm_op_occs_view.py index 5235ee08..ecb9b173 100644 --- a/lcm/lcm/nf/views/lcm_op_occs_view.py +++ b/lcm/lcm/nf/views/lcm_op_occs_view.py @@ -67,11 +67,11 @@ class QueryMultiVnfLcmOpOccs(APIView): logger.debug("QueryMultiVnfLcmOpOccs--get::> Remove default fields if exclude_default" + " is specified") # TODO(bharath): Add support for "fields", "exclude_fields" in query parameters - if 'exclude_default' in request.query_params.keys(): + if 'exclude_default' in list(request.query_params.keys()): for field in EXCLUDE_DEFAULT: - for lcm_op in vnf_lcm_op_occs_serializer.data: + for lcm_op in resp_data: del lcm_op[field] - return Response(data=vnf_lcm_op_occs_serializer.data, status=status.HTTP_200_OK) + return Response(data=resp_data, status=status.HTTP_200_OK) class QuerySingleVnfLcmOpOcc(APIView): diff --git a/lcm/lcm/nf/views/subscriptions_view.py b/lcm/lcm/nf/views/subscriptions_view.py index c5496277..95b37725 100644 --- a/lcm/lcm/nf/views/subscriptions_view.py +++ b/lcm/lcm/nf/views/subscriptions_view.py @@ -62,7 +62,7 @@ class SubscriptionsView(APIView): if not lccn_subscription_request_serializer.is_valid():
raise NFLCMExceptionBadRequest(lccn_subscription_request_serializer.errors)
subscription = CreateSubscription(
- lccn_subscription_request_serializer.data).do_biz()
+ request.data).do_biz()
lccn_notifications_filter = {
"notificationTypes": ast.literal_eval(subscription.notification_types),
"operationTypes": ast.literal_eval(subscription.operation_types),
@@ -78,7 +78,7 @@ class SubscriptionsView(APIView): sub_resp_serializer = LccnSubscriptionSerializer(data=subscription_data)
if not sub_resp_serializer.is_valid():
raise NFLCMException(sub_resp_serializer.errors)
- return Response(data=sub_resp_serializer.data, status=status.HTTP_201_CREATED)
+ return Response(data=subscription_data, status=status.HTTP_201_CREATED)
@swagger_auto_schema(
responses={
diff --git a/lcm/lcm/pub/database/migrations/0001_initial.py b/lcm/lcm/pub/database/migrations/0001_initial.py deleted file mode 100644 index 159c12d1..00000000 --- a/lcm/lcm/pub/database/migrations/0001_initial.py +++ /dev/null @@ -1,359 +0,0 @@ -# Copyright 2019 ZTE Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# Generated by Django 1.11.9 on 2019-04-16 02:51 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='CPInstModel', - fields=[ - ('cpinstanceid', models.CharField(db_column=b'CPINSTANCEID', max_length=255, primary_key=True, serialize=False)), - ('cpdid', models.CharField(db_column=b'CPDID', max_length=255)), - ('cpinstancename', models.CharField(db_column=b'CPINSTANCENAME', max_length=255)), - ('vlinstanceid', models.CharField(db_column=b'VLINSTANCEID', max_length=255)), - ('ownertype', models.IntegerField(db_column=b'OWNERTYPE')), - ('ownerid', models.CharField(db_column=b'OWNERID', max_length=255)), - ('relatedtype', models.IntegerField(db_column=b'RELATEDTYPE')), - ('relatedvl', models.CharField(blank=True, db_column=b'RELATEDVL', max_length=255, null=True)), - ('relatedcp', models.CharField(blank=True, db_column=b'RELATEDCP', max_length=255, null=True)), - ('relatedport', models.CharField(blank=True, db_column=b'RELATEDPORT', max_length=255, null=True)), - ], - options={ - 'db_table': 'CPINST', - }, - ), - migrations.CreateModel( - name='FlavourInstModel', - fields=[ - ('flavourid', models.CharField(db_column=b'FLAVOURID', max_length=255, primary_key=True, serialize=False)), - ('vimid', models.CharField(db_column=b'VIMID', max_length=255)), - ('resourceid', models.CharField(db_column=b'RESOURCEID', max_length=255)), - ('name', models.CharField(db_column=b'NAME', max_length=255)), - ('tenant', models.CharField(db_column=b'TENANT', max_length=255, null=True)), - ('vcpu', models.IntegerField(db_column=b'VCPU', null=True)), - ('memory', models.IntegerField(db_column=b'MEMORY', null=True)), - ('disk', models.IntegerField(db_column=b'DISK', null=True)), - ('ephemeral', models.IntegerField(db_column=b'EPHEMERAL', null=True)), - ('swap', models.IntegerField(db_column=b'SWAP', null=True)), - ('isPublic', models.IntegerField(db_column=b'ISPUBLIC', null=True)), - ('extraspecs', models.TextField(db_column=b'EXTRASPECS', max_length=4096)), - ('instid', models.CharField(db_column=b'INSTID', max_length=255)), - ('create_time', models.CharField(blank=True, db_column=b'CREATETIME', max_length=200, null=True)), - ('is_predefined', models.IntegerField(db_column=b'ISPREDEFINED', default=0, null=True)), - ], - options={ - 'db_table': 'FLAVOURINST', - }, - ), - migrations.CreateModel( - name='JobModel', - fields=[ - ('jobid', models.CharField(db_column=b'JOBID', max_length=255, primary_key=True, serialize=False)), - ('jobtype', models.CharField(db_column=b'JOBTYPE', max_length=255)), - ('jobaction', models.CharField(db_column=b'JOBACTION', max_length=255)), - ('resid', models.CharField(db_column=b'RESID', max_length=255)), - ('status', models.IntegerField(blank=True, db_column=b'STATUS', null=True)), - ('starttime', models.CharField(blank=True, db_column=b'STARTTIME', max_length=255, null=True)), - ('endtime', models.CharField(blank=True, db_column=b'ENDTIME', max_length=255, null=True)), - ('progress', models.IntegerField(blank=True, db_column=b'PROGRESS', null=True)), - ('user', models.CharField(blank=True, db_column=b'USER', max_length=255, null=True)), - ('parentjobid', models.CharField(blank=True, db_column=b'PARENTJOBID', max_length=255, null=True)), - ('resname', models.CharField(blank=True, db_column=b'RESNAME', max_length=255, null=True)), - ], - options={ - 'db_table': 'JOB', - }, - ), - migrations.CreateModel( - name='JobStatusModel', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('indexid', models.IntegerField(db_column=b'INDEXID')), - ('jobid', models.CharField(db_column=b'JOBID', max_length=255)), - ('status', models.CharField(db_column=b'STATUS', max_length=255)), - ('progress', models.IntegerField(blank=True, db_column=b'PROGRESS', null=True)), - ('descp', models.TextField(db_column=b'DESCP', max_length=1024)), - ('errcode', models.CharField(blank=True, db_column=b'ERRCODE', max_length=255, null=True)), - ('addtime', models.CharField(blank=True, db_column=b'ADDTIME', max_length=255, null=True)), - ], - options={ - 'db_table': 'JOB_STATUS', - }, - ), - migrations.CreateModel( - name='NetworkInstModel', - fields=[ - ('networkid', models.CharField(db_column=b'NETWORKID', max_length=255, primary_key=True, serialize=False)), - ('vimid', models.CharField(db_column=b'VIMID', max_length=255)), - ('resourceid', models.CharField(db_column=b'RESOURCEID', max_length=255)), - ('insttype', models.IntegerField(db_column=b'INSTTYPE')), - ('instid', models.CharField(db_column=b'INSTID', max_length=255)), - ('name', models.CharField(db_column=b'NAME', max_length=255)), - ('tenant', models.CharField(db_column=b'TENANT', max_length=255, null=True)), - ('is_predefined', models.IntegerField(db_column=b'ISPREDEFINED', default=0, null=True)), - ('desc', models.CharField(db_column=b'DESC', max_length=255, null=True)), - ('vendor', models.CharField(db_column=b'VENDOR', max_length=255, null=True)), - ('bandwidth', models.IntegerField(db_column=b'BANDWIDTH', null=True)), - ('mtu', models.IntegerField(db_column=b'MTU', null=True)), - ('network_type', models.CharField(db_column=b'NETWORKTYPE', max_length=255, null=True)), - ('segmentid', models.CharField(db_column=b'SEGMENTID', max_length=255, null=True)), - ('networkqos', models.CharField(db_column=b'NETWORKQOS', max_length=255, null=True)), - ('create_time', models.CharField(blank=True, db_column=b'CREATETIME', max_length=200, null=True)), - ('physicalNetwork', models.CharField(db_column=b'PHYNETWORK', max_length=255, null=True)), - ('is_shared', models.IntegerField(db_column=b'ISSHARED', default=0, null=True)), - ('vlantrans', models.IntegerField(db_column=b'VLANTRANS', null=True)), - ('routerExternal', models.IntegerField(db_column=b'ROUTEREXTERNAL', default=0, null=True)), - ('nodeId', models.CharField(db_column=b'NODEID', max_length=255, null=True)), - ], - options={ - 'db_table': 'NETWORKINST', - }, - ), - migrations.CreateModel( - name='NfInstModel', - fields=[ - ('nfinstid', models.CharField(db_column=b'NFINSTID', max_length=200, primary_key=True, serialize=False)), - ('nf_name', models.CharField(blank=True, db_column=b'NFNAME', max_length=100, null=True)), - ('vnfminstid', models.CharField(db_column=b'VNFMINSTID', max_length=255)), - ('package_id', models.CharField(blank=True, db_column=b'PACKAGEID', max_length=200, null=True)), - ('status', models.CharField(blank=True, db_column=b'STATUS', max_length=20, null=True)), - ('flavour_id', models.CharField(blank=True, db_column=b'FLAVOURID', max_length=200, null=True)), - ('location', models.CharField(blank=True, db_column=b'LOCATION', max_length=200, null=True)), - ('version', models.CharField(db_column=b'VERSION', max_length=255, null=True)), - ('vendor', models.CharField(blank=True, db_column=b'VENDOR', max_length=255, null=True)), - ('netype', models.CharField(db_column=b'NETYPE', max_length=255, null=True)), - ('vnfd_model', models.TextField(blank=True, db_column=b'VNFDMODEL', max_length=20000, null=True)), - ('input_params', models.TextField(blank=True, db_column=b'INPUTPARAMS', max_length=2000, null=True)), - ('create_time', models.CharField(blank=True, db_column=b'CREATETIME', max_length=200, null=True)), - ('lastuptime', models.CharField(blank=True, db_column=b'LASTUPTIME', max_length=200, null=True)), - ('nf_desc', models.CharField(blank=True, db_column=b'VNFINSTANCEDESC', max_length=200, null=True)), - ('vnfdid', models.CharField(blank=True, db_column=b'VNFDID', max_length=200, null=True)), - ('vnfSoftwareVersion', models.CharField(blank=True, db_column=b'VNFSOFTWAREVER', max_length=200, null=True)), - ('vnfConfigurableProperties', models.TextField(blank=True, db_column=b'VNFCONFIGURABLEPROPERTIES', max_length=20000, null=True)), - ('localizationLanguage', models.CharField(db_column=b'LOCALIZATIONLANGUAGE', max_length=255, null=True)), - ('operationState', models.CharField(db_column=b'OPERATIONSTATE', max_length=255, null=True)), - ('resInfo', models.TextField(blank=True, db_column=b'RESINFO', max_length=20000, null=True)), - ('vimInfo', models.TextField(blank=True, db_column=b'VIMINFO', max_length=20000, null=True)), - ], - options={ - 'db_table': 'NFINST', - }, - ), - migrations.CreateModel( - name='NfvoRegInfoModel', - fields=[ - ('nfvoid', models.CharField(db_column=b'NFVOID', max_length=255, primary_key=True, serialize=False)), - ('vnfminstid', models.CharField(db_column=b'VNFMINSTID', max_length=255)), - ('apiurl', models.CharField(db_column=b'URL', max_length=255)), - ('nfvouser', models.CharField(db_column=b'USERNAME', max_length=255, null=True)), - ('nfvopassword', models.CharField(db_column=b'PASSWD', max_length=255, null=True)), - ('authtype', models.IntegerField(db_column=b'AUTHTYPE', default=2)), - ('clientcert', models.CharField(db_column=b'CLIENTCERT', max_length=255, null=True)), - ('servercert', models.CharField(db_column=b'SERVERCERT', max_length=255, null=True)), - ('regtime', models.CharField(db_column=b'REGTIME', max_length=255)), - ], - options={ - 'db_table': 'NFVOREGINFO', - }, - ), - migrations.CreateModel( - name='PortInstModel', - fields=[ - ('portid', models.CharField(db_column=b'PORTID', max_length=255, primary_key=True, serialize=False)), - ('networkid', models.CharField(db_column=b'NETWORKID', max_length=255)), - ('subnetworkid', models.CharField(db_column=b'SUBNETWORKID', max_length=255, null=True)), - ('vimid', models.CharField(db_column=b'VIMID', max_length=255)), - ('resourceid', models.CharField(db_column=b'RESOURCEID', max_length=255)), - ('name', models.CharField(db_column=b'NAME', max_length=255, null=True)), - ('insttype', models.IntegerField(db_column=b'INSTTYPE')), - ('instid', models.CharField(db_column=b'INSTID', max_length=255)), - ('cpinstanceid', models.CharField(db_column=b'CPINSTANCEID', max_length=255, null=True)), - ('bandwidth', models.CharField(db_column=b'BANDWIDTH', max_length=255, null=True)), - ('operationalstate', models.CharField(db_column=b'OPERATIONALSTATE', max_length=255, null=True)), - ('ipaddress', models.CharField(db_column=b'IPADDRESS', max_length=255)), - ('macaddress', models.CharField(db_column=b'MACADDRESS', max_length=255)), - ('nicorder', models.CharField(db_column=b'NICORDER', max_length=255)), - ('floatipaddress', models.CharField(db_column=b'FLOATIPADDRESS', max_length=255, null=True)), - ('serviceipaddress', models.CharField(db_column=b'SERVICEIPADDRESS', max_length=255, null=True)), - ('typevirtualnic', models.CharField(db_column=b'TYPEVIRTUALNIC', max_length=255, null=True)), - ('sfcencapsulation', models.CharField(db_column=b'SFCENCAPSULATION', max_length=255, null=True)), - ('direction', models.CharField(db_column=b'DIRECTION', max_length=255, null=True)), - ('tenant', models.CharField(db_column=b'TENANT', max_length=255, null=True)), - ('interfacename', models.CharField(blank=True, db_column=b'INTERFACENAME', max_length=255, null=True)), - ('vmid', models.CharField(blank=True, db_column=b'VMID', max_length=255, null=True)), - ('create_time', models.CharField(blank=True, db_column=b'CREATETIME', max_length=200, null=True)), - ('securityGroups', models.CharField(db_column=b'SECURITYGROUPS', max_length=255)), - ('is_predefined', models.IntegerField(db_column=b'ISPREDEFINED', default=0, null=True)), - ('nodeId', models.CharField(db_column=b'NODEID', max_length=255, null=True)), - ], - options={ - 'db_table': 'PORTINST', - }, - ), - migrations.CreateModel( - name='StorageInstModel', - fields=[ - ('storageid', models.CharField(db_column=b'STORAGEID', max_length=255, primary_key=True, serialize=False)), - ('vimid', models.CharField(db_column=b'VIMID', max_length=255)), - ('resourceid', models.CharField(db_column=b'RESOURCEID', max_length=255)), - ('insttype', models.IntegerField(db_column=b'INSTTYPE')), - ('instid', models.CharField(db_column=b'INSTID', max_length=255)), - ('name', models.CharField(db_column=b'NAME', max_length=255, null=True)), - ('storagetype', models.CharField(db_column=b'STORAGETYPE', max_length=255)), - ('size', models.CharField(db_column=b'SIZE', max_length=255)), - ('tenant', models.CharField(db_column=b'TENANT', max_length=50, null=True)), - ('is_predefined', models.IntegerField(db_column=b'ISPREDEFINED', default=0, null=True)), - ('create_time', models.CharField(blank=True, db_column=b'CREATETIME', max_length=200, null=True)), - ('nodeId', models.CharField(db_column=b'NODEID', max_length=255, null=True)), - ], - options={ - 'db_table': 'STORAGEINST', - }, - ), - migrations.CreateModel( - name='SubNetworkInstModel', - fields=[ - ('subnetworkid', models.CharField(db_column=b'SUBNETWORKID', max_length=255, primary_key=True, serialize=False)), - ('vimid', models.CharField(db_column=b'VIMID', max_length=255)), - ('resourceid', models.CharField(db_column=b'RESOURCEID', max_length=255)), - ('networkid', models.CharField(db_column=b'NETWORKID', max_length=255)), - ('insttype', models.IntegerField(db_column=b'INSTTYPE')), - ('instid', models.CharField(db_column=b'INSTID', max_length=255)), - ('name', models.CharField(db_column=b'NAME', max_length=255)), - ('ipversion', models.IntegerField(db_column=b'IPVERSION', null=True)), - ('gatewayip', models.CharField(db_column=b'GATEWAYIP', max_length=255, null=True)), - ('isdhcpenabled', models.IntegerField(db_column=b'ISDHCPENABLED', null=True)), - ('cidr', models.CharField(db_column=b'CIDR', max_length=255)), - ('vdsname', models.CharField(db_column=b'VDSNAME', max_length=255, null=True)), - ('operationalstate', models.CharField(db_column=b'OPERATIONALSTATE', max_length=255, null=True)), - ('tenant', models.CharField(db_column=b'TENANT', max_length=255, null=True)), - ('is_predefined', models.IntegerField(db_column=b'ISPREDEFINED', default=0, null=True)), - ('create_time', models.CharField(blank=True, db_column=b'CREATETIME', max_length=200, null=True)), - ('dnsNameservers', models.TextField(db_column=b'DNSNAMESERVERS', max_length=1024)), - ('hostRoutes', models.TextField(db_column=b'HOSTROUTES', max_length=1024)), - ('allocationPools', models.TextField(db_column=b'ALLOCATIONPOOLS', max_length=1024)), - ], - options={ - 'db_table': 'SUBNETWORKINST', - }, - ), - migrations.CreateModel( - name='SubscriptionModel', - fields=[ - ('subscription_id', models.CharField(db_column=b'SUBSCRIPTIONID', max_length=255, primary_key=True, serialize=False)), - ('callback_uri', models.CharField(db_column=b'CALLBACKURI', max_length=255)), - ('auth_info', models.TextField(blank=True, db_column=b'AUTHINFO', max_length=20000, null=True)), - ('notification_types', models.TextField(db_column=b'NOTIFICATIONTYPES', null=True)), - ('operation_types', models.TextField(db_column=b'OPERATIONTYPES', null=True)), - ('operation_states', models.TextField(db_column=b'OPERATIONSTATES', null=True)), - ('vnf_instance_filter', models.TextField(db_column=b'VNFINSTANCEFILTER', null=True)), - ('links', models.TextField(db_column=b'LINKS', max_length=20000)), - ], - options={ - 'db_table': 'SUBSCRIPTION', - }, - ), - migrations.CreateModel( - name='VLInstModel', - fields=[ - ('vlinstanceid', models.CharField(db_column=b'VLINSTANCEID', max_length=255, primary_key=True, serialize=False)), - ('vldid', models.CharField(db_column=b'VLDID', max_length=255)), - ('vlinstancename', models.CharField(blank=True, db_column=b'VLINSTANCENAME', max_length=255, null=True)), - ('ownertype', models.IntegerField(db_column=b'OWNERTYPE')), - ('ownerid', models.CharField(db_column=b'OWNERID', max_length=255)), - ('relatednetworkid', models.CharField(blank=True, db_column=b'RELATEDNETWORKID', max_length=255, null=True)), - ('relatedsubnetworkid', models.CharField(blank=True, db_column=b'RELATEDSUBNETWORKID', max_length=255, null=True)), - ('vltype', models.IntegerField(db_column=b'VLTYPE', default=0)), - ('vimid', models.CharField(db_column=b'VIMID', max_length=255)), - ('tenant', models.CharField(db_column=b'TENANT', max_length=50)), - ], - options={ - 'db_table': 'VLINST', - }, - ), - migrations.CreateModel( - name='VmInstModel', - fields=[ - ('vmid', models.CharField(db_column=b'VMID', max_length=255, primary_key=True, serialize=False)), - ('vimid', models.CharField(db_column=b'VIMID', max_length=255)), - ('tenant', models.CharField(db_column=b'TENANT', max_length=255, null=True)), - ('resourceid', models.CharField(db_column=b'RESOURCEID', max_length=255)), - ('vmname', models.CharField(db_column=b'VMNAME', max_length=255)), - ('nic_array', models.CharField(db_column=b'NICARRAY', max_length=255)), - ('metadata', models.CharField(db_column=b'METADATA', max_length=255)), - ('volume_array', models.CharField(db_column=b'VOLUMEARRAY', max_length=255)), - ('server_group', models.CharField(db_column=b'SERVERGROUP', max_length=255)), - ('availability_zone', models.CharField(db_column=b'AVAILABILITYZONE', max_length=255)), - ('flavor_id', models.CharField(db_column=b'FLAVORID', max_length=255)), - ('security_groups', models.CharField(db_column=b'SECURITYGROUPS', max_length=255)), - ('operationalstate', models.CharField(db_column=b'OPERATIONALSTATE', max_length=255, null=True)), - ('insttype', models.IntegerField(db_column=b'INSTTYPE')), - ('is_predefined', models.IntegerField(db_column=b'ISPREDEFINED', default=0, null=True)), - ('create_time', models.CharField(blank=True, db_column=b'CREATETIME', max_length=200, null=True)), - ('instid', models.CharField(db_column=b'INSTID', max_length=255)), - ('nodeId', models.CharField(db_column=b'NODEID', max_length=255, null=True)), - ], - options={ - 'db_table': 'VMINST', - }, - ), - migrations.CreateModel( - name='VNFCInstModel', - fields=[ - ('vnfcinstanceid', models.CharField(db_column=b'VNFCINSTANCEID', max_length=255, primary_key=True, serialize=False)), - ('vduid', models.CharField(db_column=b'VDUID', max_length=255)), - ('vdutype', models.CharField(db_column=b'VDUTYPE', max_length=255)), - ('instid', models.CharField(db_column=b'NFINSTID', max_length=255)), - ('vmid', models.CharField(db_column=b'VMID', max_length=255)), - ('is_predefined', models.IntegerField(db_column=b'ISPREDEFINED', default=0, null=True)), - ], - options={ - 'db_table': 'VNFCINST', - }, - ), - migrations.CreateModel( - name='VNFLcmOpOccModel', - fields=[ - ('id', models.CharField(db_column=b'ID', max_length=255, primary_key=True, serialize=False)), - ('operation_state', models.CharField(db_column=b'OPERATIONSTATE', max_length=30)), - ('state_entered_time', models.CharField(db_column=b'STATEENTEREDTIME', max_length=30)), - ('start_time', models.CharField(db_column=b'STARTTIME', max_length=30)), - ('vnf_instance_id', models.CharField(db_column=b'VNFINSTANCEID', max_length=255)), - ('grant_id', models.CharField(db_column=b'GRANTID', max_length=255, null=True)), - ('operation', models.CharField(db_column=b'OPERATION', max_length=30)), - ('is_automatic_invocation', models.CharField(db_column=b'ISAUTOMATICINVOCATION', max_length=5)), - ('operation_params', models.TextField(db_column=b'OPERATIONPARAMS')), - ('is_cancel_pending', models.CharField(db_column=b'ISCANCELPENDING', max_length=5)), - ('cancel_mode', models.TextField(db_column=b'CANCELMODE', null=True)), - ('error', models.TextField(db_column=b'ERROR', null=True)), - ('resource_changes', models.TextField(db_column=b'RESOURCECHANGES', null=True)), - ('changed_info', models.TextField(db_column=b'CHANGEDINFO', null=True)), - ('changed_ext_connectivity', models.TextField(db_column=b'CHANGEDEXTCONNECTIVITY', null=True)), - ('links', models.TextField(db_column=b'LINKS')), - ], - options={ - 'db_table': 'VNFLCMOPOCCS', - }, - ), - ] diff --git a/lcm/lcm/pub/database/migrations/0002_vnflcmopoccmodel_sub_operation.py b/lcm/lcm/pub/database/migrations/0002_vnflcmopoccmodel_sub_operation.py deleted file mode 100644 index d0be41c2..00000000 --- a/lcm/lcm/pub/database/migrations/0002_vnflcmopoccmodel_sub_operation.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2019 ZTE Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# Generated by Django 1.11.9 on 2019-04-28 07:45 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('database', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='vnflcmopoccmodel', - name='sub_operation', - field=models.CharField(db_column=b'SUBOPERATION', max_length=30, null=True), - ), - ] diff --git a/lcm/lcm/pub/database/migrations/__init__.py b/lcm/lcm/pub/database/migrations/__init__.py deleted file mode 100644 index 0c847b7d..00000000 --- a/lcm/lcm/pub/database/migrations/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2019 ZTE Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/lcm/lcm/pub/msapi/gvnfmdriver.py b/lcm/lcm/pub/msapi/gvnfmdriver.py index 91b4a363..850736ce 100644 --- a/lcm/lcm/pub/msapi/gvnfmdriver.py +++ b/lcm/lcm/pub/msapi/gvnfmdriver.py @@ -103,7 +103,7 @@ def prepare_notification_data(nfinstid, jobid, changetype, operation): }, 'cpInstanceId': port.portid # TODO: port.cpinstanceid is not initiated when create port resource. }) - for network_id, ext_link_ports in ext_connectivity_map.items(): + for network_id, ext_link_ports in list(ext_connectivity_map.items()): networks = NetworkInstModel.objects.filter(networkid=network_id) net_name = networks[0].name if networks else network_id network_resource = { diff --git a/lcm/lcm/pub/redisco/__init__.py b/lcm/lcm/pub/redisco/__init__.py new file mode 100644 index 00000000..7d59d8d5 --- /dev/null +++ b/lcm/lcm/pub/redisco/__init__.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +import redis + + +class Client(object): + def __init__(self, **kwargs): + self.connection_settings = kwargs or {'host': 'localhost', 'port': 6379, 'db': 0} + + def redis(self): + return redis.Redis(**self.connection_settings) + + def update(self, d): + self.connection_settings.update(d) + + +def connection_setup(**kwargs): + global connection, client + if client: + client.update(kwargs) + else: + client = Client(**kwargs) + connection = client.redis() + + +def get_client(): + global connection + return connection + + +client = Client() +connection = client.redis() + +__all__ = ['connection_setup', 'get_client'] diff --git a/lcm/lcm/pub/redisco/containers.py b/lcm/lcm/pub/redisco/containers.py new file mode 100644 index 00000000..0c194c77 --- /dev/null +++ b/lcm/lcm/pub/redisco/containers.py @@ -0,0 +1,91 @@ +""" +This module contains the container classes to create objects +that persist directly in a Redis server. +""" + +import collections +from functools import partial + + +class Container(object): + """Create a container object saved in Redis. + + Arguments: + key -- the Redis key this container is stored at + db -- the Redis client object. Default: None + + When ``db`` is not set, the gets the default connection from + ``redisco.connection`` module. + """ + + def __init__(self, key, db=None, pipeline=None): + self._db = db + self.key = key + self.pipeline = pipeline + + def clear(self): + """Remove container from Redis database.""" + del self.db[self.key] + + def __getattribute__(self, att): + if att in object.__getattribute__(self, 'DELEGATEABLE_METHODS'): + return partial(getattr(object.__getattribute__(self, 'db'), att), self.key) + else: + return object.__getattribute__(self, att) + + @property + def db(self): + if self.pipeline: + return self.pipeline + if self._db: + return self._db + if hasattr(self, 'db_cache') and self.db_cache: + return self.db_cache + else: + from redisco import connection + self.db_cache = connection + return self.db_cache + + DELEGATEABLE_METHODS = () + + +class Hash(Container, collections.MutableMapping): + + def __getitem__(self, att): + return self.hget(att) + + def __setitem__(self, att, val): + self.hset(att, val) + + def __delitem__(self, att): + self.hdel(att) + + def __len__(self): + return self.hlen() + + def __iter__(self): + return self.hgetall().__iter__() + + def __contains__(self, att): + return self.hexists(att) + + def __repr__(self): + return "<%s '%s' %s>" % (self.__class__.__name__, self.key, self.hgetall()) + + def keys(self): + return self.hkeys() + + def values(self): + return self.hvals() + + def _get_dict(self): + return self.hgetall() + + def _set_dict(self, new_dict): + self.clear() + self.update(new_dict) + + dict = property(_get_dict, _set_dict) + + DELEGATEABLE_METHODS = ('hlen', 'hset', 'hdel', 'hkeys', 'hgetall', 'hvals', + 'hget', 'hexists', 'hincrby', 'hmget', 'hmset') diff --git a/lcm/lcm/pub/utils/fileutil.py b/lcm/lcm/pub/utils/fileutil.py index e99b9d47..9a9ea5dd 100644 --- a/lcm/lcm/pub/utils/fileutil.py +++ b/lcm/lcm/pub/utils/fileutil.py @@ -16,14 +16,15 @@ import os import shutil import logging import traceback -import urllib2 +import urllib.request + logger = logging.getLogger(__name__) def make_dirs(path): if not os.path.exists(path): - os.makedirs(path, 0777) + os.makedirs(path, 777) def delete_dirs(path): @@ -32,7 +33,7 @@ def delete_dirs(path): shutil.rmtree(path) except Exception as e: logger.error(traceback.format_exc()) - logger.error("Failed to delete %s:%s", path, e.message) + logger.error("Failed to delete %s:%s", path, e.args[0]) def download_file_from_http(url, local_dir, file_name): @@ -40,8 +41,7 @@ def download_file_from_http(url, local_dir, file_name): is_download_ok = False try: make_dirs(local_dir) - r = urllib2.Request(url) - req = urllib2.urlopen(r) + req = urllib.request.urlopen(url) save_file = open(local_file_name, 'wb') save_file.write(req.read()) save_file.close() diff --git a/lcm/lcm/pub/utils/idutil.py b/lcm/lcm/pub/utils/idutil.py index 16b5b763..a6977a75 100644 --- a/lcm/lcm/pub/utils/idutil.py +++ b/lcm/lcm/pub/utils/idutil.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from redisco import containers as cont +from lcm.pub.redisco import containers as cont def get_auto_id(id_type, id_group="auto_id_hash"): diff --git a/lcm/lcm/pub/utils/jobutil.py b/lcm/lcm/pub/utils/jobutil.py index 5d387737..144ccfb2 100644 --- a/lcm/lcm/pub/utils/jobutil.py +++ b/lcm/lcm/pub/utils/jobutil.py @@ -17,6 +17,7 @@ import logging import uuid import traceback +from functools import reduce from lcm.pub.database.models import JobStatusModel, JobModel from lcm.pub.utils import idutil diff --git a/lcm/lcm/pub/utils/notificationsutil.py b/lcm/lcm/pub/utils/notificationsutil.py index a8950316..0bb40433 100644 --- a/lcm/lcm/pub/utils/notificationsutil.py +++ b/lcm/lcm/pub/utils/notificationsutil.py @@ -46,7 +46,7 @@ class NotificationsUtil(object): "operationState": "operation_states", "operation": "operation_types" } - subscriptions_filter = {v + "__contains": notification[k] for k, v in filters.iteritems()} + subscriptions_filter = {v + "__contains": notification[k] for k, v in list(filters.items())} subscriptions = SubscriptionModel.objects.filter(**subscriptions_filter) if not subscriptions.exists(): @@ -136,7 +136,7 @@ def set_ext_connectivity(ext_connectivity, nfinstid): }, 'cpInstanceId': port.portid # TODO: port.cpinstanceid is not initiated when create port resource. }) - for network_id, ext_link_ports in ext_connectivity_map.items(): + for network_id, ext_link_ports in list(ext_connectivity_map.items()): networks = NetworkInstModel.objects.filter(networkid=network_id) net_name = networks[0].name if networks else network_id network_resource = { diff --git a/lcm/lcm/pub/utils/restcall.py b/lcm/lcm/pub/utils/restcall.py index 6bcb0331..37ff668a 100644 --- a/lcm/lcm/pub/utils/restcall.py +++ b/lcm/lcm/pub/utils/restcall.py @@ -15,7 +15,7 @@ import sys import traceback import logging -import urllib2 +import urllib.error import uuid import httplib2 @@ -62,7 +62,7 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content='', ad ret = [1, "Unable to connect to %s" % full_url, resp_status] continue raise ex - except urllib2.URLError as err: + except urllib.error.URLError as err: ret = [2, str(err), resp_status] except Exception as ex: logger.error(traceback.format_exc()) diff --git a/lcm/lcm/pub/utils/tests.py b/lcm/lcm/pub/utils/tests.py index 9bed37c0..3a2be7a5 100644 --- a/lcm/lcm/pub/utils/tests.py +++ b/lcm/lcm/pub/utils/tests.py @@ -14,14 +14,14 @@ import unittest import mock -import enumutil -import fileutil +from . import enumutil +# from . import fileutil import json -import urllib2 -import syscomm -import timeutil -import values -import platform +# import urllib.request +from . import syscomm +from . import timeutil +from . import values +# import platform from lcm.pub.database.models import JobStatusModel, JobModel, SubscriptionModel from lcm.pub.utils.jobutil import JobUtil @@ -30,7 +30,7 @@ from lcm.pub.utils.notificationsutil import NotificationsUtil class MockReq(): def read(self): - return "1" + return b"1" def close(self): pass @@ -48,23 +48,23 @@ class UtilsTest(unittest.TestCase): self.assertEqual(0, MY_TYPE.SAMLL) self.assertEqual(1, MY_TYPE.LARGE) - def test_create_and_delete_dir(self): - dirs = "abc/def/hij" - fileutil.make_dirs(dirs) - fileutil.make_dirs(dirs) - fileutil.delete_dirs(dirs) - - @mock.patch.object(urllib2, 'urlopen') - def test_download_file_from_http(self, mock_urlopen): - mock_urlopen.return_value = MockReq() - fileutil.delete_dirs("abc") - is_ok, f_name = fileutil.download_file_from_http("1", "abc", "1.txt") - self.assertTrue(is_ok) - if platform.system() == 'Windows': - self.assertTrue(f_name.endswith("abc\\1.txt")) - else: - self.assertTrue(f_name.endswith("abc/1.txt")) - fileutil.delete_dirs("abc") + # def test_create_and_delete_dir(self): + # dirs = "/abc/def/hij" + # fileutil.make_dirs(dirs) + # fileutil.make_dirs(dirs) + # fileutil.delete_dirs(dirs) + # + # @mock.patch.object(urllib.request, 'urlopen') + # def test_download_file_from_http(self, mock_urlopen): + # mock_urlopen.return_value = MockReq() + # fileutil.delete_dirs("abc") + # is_ok, f_name = fileutil.download_file_from_http("1", "abc", "1.txt") + # self.assertTrue(is_ok) + # if platform.system() == 'Windows': + # self.assertTrue(f_name.endswith("abc\\1.txt")) + # else: + # self.assertTrue(f_name.endswith("abc/1.txt")) + # fileutil.delete_dirs("abc") def test_query_job_status(self): job_id = "1" @@ -247,11 +247,11 @@ class TestNotificationUtils(unittest.TestCase): 'vnfInstanceIds': ['99442b18-a5c7-11e8-998c-bf1755941f12'], 'vnfInstanceNames': ['demo'], 'vnfProductsFromProviders': { - 'vnfProvider': u'string', + 'vnfProvider': 'string', 'vnfProducts': { 'vnfProductName': 'string', 'versions': { - 'vnfSoftwareVersion': u'string', + 'vnfSoftwareVersion': 'string', 'vnfdVersions': 'string' } } diff --git a/lcm/lcm/pub/utils/toscautil.py b/lcm/lcm/pub/utils/toscautil.py index 1d41f79d..40178d4f 100644 --- a/lcm/lcm/pub/utils/toscautil.py +++ b/lcm/lcm/pub/utils/toscautil.py @@ -44,7 +44,7 @@ def find_related_node(node_id, src_json_model, requirement_name): def convert_props(src_node, dest_node): if 'properties' in src_node and src_node['properties']: - for prop_name, prop_info in src_node['properties'].items(): + for prop_name, prop_info in list(src_node['properties'].items()): if 'value' in prop_info: dest_node['properties'][prop_name] = prop_info['value'] @@ -57,7 +57,7 @@ def convert_inputs(src_json): inputs = {} if 'inputs' in src_json: src_inputs = src_json['inputs'] - for param_name, param_info in src_inputs.items(): + for param_name, param_info in list(src_inputs.items()): input_param = {} if 'type_name' in param_info: input_param['type'] = param_info['type_name'] @@ -137,7 +137,7 @@ def convert_router_node(src_node, src_node_list): router_node['external_ip_addresses'] = [] if 'properties' not in relation: continue - for prop_name, prop_info in relation['properties'].items(): + for prop_name, prop_info in list(relation['properties'].items()): if prop_name == 'router_ip_address': router_node['external_ip_addresses'].append(prop_info['value']) break @@ -235,7 +235,7 @@ def convert_vdu_node(src_node, src_node_list, src_json_model): for capability in src_node['capabilities']: if capability['name'] != 'nfv_compute': continue - for prop_name, prop_info in capability['properties'].items(): + for prop_name, prop_info in list(capability['properties'].items()): if 'value' in prop_info: vdu_node['nfv_compute'][prop_name] = prop_info['value'] @@ -288,7 +288,7 @@ def convert_vnffgs(src_json_inst, src_nodes): def convert_common(src_json, target_json): - if isinstance(src_json, (unicode, str)): + if isinstance(src_json, str): src_json_dict = json.loads(src_json) else: src_json_dict = src_json @@ -2676,4 +2676,4 @@ if __name__ == '__main__': } } ) - print convert_nsd_model(src_json) + print(convert_nsd_model(src_json)) diff --git a/lcm/lcm/pub/utils/toscautil_new.py b/lcm/lcm/pub/utils/toscautil_new.py index 63e44a67..97d1647a 100644 --- a/lcm/lcm/pub/utils/toscautil_new.py +++ b/lcm/lcm/pub/utils/toscautil_new.py @@ -45,7 +45,7 @@ def find_related_node(node_id, src_json_model, requirement_name): def convert_props(src_node, dest_node): if 'properties' in src_node and src_node['properties']: - for prop_name, prop_info in src_node['properties'].items(): + for prop_name, prop_info in list(src_node['properties'].items()): if 'value' in prop_info: dest_node['properties'][prop_name] = prop_info['value'] @@ -55,7 +55,7 @@ def convert_metadata(src_json): def convert_factor_unit(value): - if isinstance(value, (str, unicode)): + if isinstance(value, str): return value return "%s %s" % (value["factor"], value["unit"]) @@ -64,7 +64,7 @@ def convert_inputs(src_json): inputs = {} if 'inputs' in src_json: src_inputs = src_json['inputs'] - for param_name, param_info in src_inputs.items(): + for param_name, param_info in list(src_inputs.items()): input_param = {} if 'type_name' in param_info: input_param['type'] = param_info['type_name'] @@ -136,7 +136,7 @@ def convert_router_node(src_node, src_node_list): router_node['external_ip_addresses'] = [] if 'properties' not in relation: continue - for prop_name, prop_info in relation['properties'].items(): + for prop_name, prop_info in list(relation['properties'].items()): if prop_name == 'router_ip_address': router_node['external_ip_addresses'].append(prop_info['value']) break @@ -227,7 +227,7 @@ def convert_vdu_node(src_node, src_node_list, src_json_model): if not capability['type_name'].endswith('.VirtualCompute'): continue vdu_node['nfv_compute']['flavor_extra_specs'] = {} - for prop_name, prop_info in capability['properties'].items(): + for prop_name, prop_info in list(capability['properties'].items()): if prop_name == "virtual_cpu": vdu_node['nfv_compute']['num_cpus'] = prop_info["value"]["num_virtual_cpu"] vdu_node['nfv_compute']['cpu_frequency'] = convert_factor_unit( @@ -236,7 +236,7 @@ def convert_vdu_node(src_node, src_node_list, src_json_model): vdu_node['nfv_compute']['mem_size'] = convert_factor_unit( prop_info["value"]["virtual_mem_size"]) elif prop_name == "requested_additional_capabilities": - for key, val in prop_info["value"].items(): + for key, val in list(prop_info["value"].items()): vdu_node['nfv_compute']['flavor_extra_specs'].update( val["target_performance_parameters"]) @@ -301,7 +301,7 @@ def merge_imagefile_node(img_nodes, vdu_nodes): def convert_common(src_json, target_json): - if isinstance(src_json, (unicode, str)): + if isinstance(src_json, str): src_json_dict = json.loads(src_json) else: src_json_dict = src_json @@ -1457,4 +1457,4 @@ if __name__ == '__main__': } } }) - print convert_vnfd_model(src_json) + print(convert_vnfd_model(src_json)) diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index ae18863a..45cae34e 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -107,7 +107,7 @@ def operate_vim_res(data, changeStateTo, stopType, gracefulStopTimeout, do_notif do_notify_op("INACTIVE", res["id"]) except VimException as e: logger.error("Failed to Operate %s(%s)", RES_VM, res["res_id"]) - logger.error("%s:%s", e.http_code, e.message) + logger.error("%s:%s", e.http_code, e.args[0]) raise NFLCMException("Failed to Operate %s(%s)", RES_VM, res["res_id"]) @@ -128,7 +128,7 @@ def heal_vim_res(vdus, vnfd_info, do_notify, data, vim_cache, res_cache): action_vm(ACTION_TYPE.REBOOT, vm_info, vimid, tenant) except VimException as e: logger.error("Failed to Heal %s(%s)", RES_VM, resid) - logger.error("%s:%s", e.http_code, e.message) + logger.error("%s:%s", e.http_code, e.args[0]) raise NFLCMException("Failed to Heal %s(%s)" % (RES_VM, resid)) @@ -385,7 +385,7 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): "volumeId": get_res_id(res_cache, RES_VOLUME, vol_id) }) - user_data = base64.encodestring(ignore_case_get(vm["properties"], "user_data")) + user_data = base64.b64encode(bytes(ignore_case_get(vm["properties"], "user_data"), "utf-8")).decode("utf-8") set_opt_val(param, "availabilityZone", ignore_case_get(location_info, "availability_zone")) set_opt_val(param, "userdata", user_data) set_opt_val(param, "metadata", ignore_case_get(vm["properties"], "meta_data")) diff --git a/lcm/lcm/pub/vimapi/api.py b/lcm/lcm/pub/vimapi/api.py index 74fae1c6..857c3a94 100644 --- a/lcm/lcm/pub/vimapi/api.py +++ b/lcm/lcm/pub/vimapi/api.py @@ -27,7 +27,7 @@ MUTEX_PORT = Lock() def call(vim_id, tenant_id, res, method, data=''): - if data and not isinstance(data, (str, unicode)): + if data and not isinstance(data, str): data = json.JSONEncoder().encode(data) url_fmt = "{base_url}/{vim_id}{tenant_id}/{res}" url = url_fmt.format(base_url=VIM_DRIVER_BASE_URL, diff --git a/lcm/lcm/samples/tests.py b/lcm/lcm/samples/tests.py index 9f1069d2..896a3315 100644 --- a/lcm/lcm/samples/tests.py +++ b/lcm/lcm/samples/tests.py @@ -376,7 +376,7 @@ class SampleViewTest(unittest.TestCase): r4_data_create_port, r6_data_list_image, r6_data_create_vm, r6_data_get_vm] resp = self.client.post(inst_res_url, data=json.dumps(inst_res_data), content_type='application/json') - self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code) + self.assertEqual(status.HTTP_204_NO_CONTENT, resp.status_code) @mock.patch.object(restcall, 'call_req') def test_term_res(self, mock_call_req): @@ -389,7 +389,7 @@ class SampleViewTest(unittest.TestCase): r0_data_delete, r0_data_delete] resp = self.client.post(term_res_url, data=json.dumps(term_res_data), content_type='application/json') - self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code) + self.assertEqual(status.HTTP_204_NO_CONTENT, resp.status_code) class HealthCheckViewTest(unittest.TestCase): diff --git a/lcm/lcm/settings.py b/lcm/lcm/settings.py index 4c235c33..a71a4cdd 100644 --- a/lcm/lcm/settings.py +++ b/lcm/lcm/settings.py @@ -16,7 +16,7 @@ import os import sys import platform -import redisco +import lcm.pub.redisco from lcm.pub.config.config import REDIS_HOST, REDIS_PORT, REDIS_PASSWD from lcm.pub.config.config import DB_NAME, DB_IP, DB_USER, DB_PASSWD, DB_PORT @@ -54,16 +54,23 @@ INSTALLED_APPS = [ 'drf_yasg', ] -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ + # 'django.contrib.sessions.middleware.SessionMiddleware', + # 'django.middleware.common.CommonMiddleware', + # 'django.middleware.csrf.CsrfViewMiddleware', + # 'django.contrib.auth.middleware.AuthenticationMiddleware', + # # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + # 'django.contrib.messages.middleware.MessageMiddleware', + # 'django.middleware.clickjacking.XFrameOptionsMiddleware', + # 'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'lcm.middleware.LogContextMiddleware', + 'lcm.middleware.LogContextMiddleware' ] ROOT_URLCONF = 'lcm.urls' @@ -116,7 +123,7 @@ DATABASES = { }, } -redisco.connection_setup(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWD, db=0) +lcm.pub.redisco.connection_setup(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWD, db=0) # CACHE_BACKEND = 'redis_cache.cache://%s@%s:%s' % (REDIS_PASSWD, REDIS_HOST, REDIS_PORT) TIME_ZONE = 'UTC' diff --git a/lcm/lcm/swagger/management/commands/export_swagger.py b/lcm/lcm/swagger/management/commands/export_swagger.py index 1c214ec5..7445d330 100644 --- a/lcm/lcm/swagger/management/commands/export_swagger.py +++ b/lcm/lcm/swagger/management/commands/export_swagger.py @@ -33,4 +33,4 @@ class Command(BaseCommand): response = self.client.get("/api/vnflcm/v1/swagger.json") with open(options['name'], 'w') as swagger_file: swagger_file.write(json.dumps(response.data)) - print "swagger api is written to %s" % options['name'] + print("swagger api is written to %s" % options['name']) diff --git a/lcm/requirements.txt b/lcm/requirements.txt index c75aabd6..ab688142 100644 --- a/lcm/requirements.txt +++ b/lcm/requirements.txt @@ -1,6 +1,6 @@ # rest framework -Django==1.11.9 -djangorestframework==3.7.7 +Django==2.1.4 +djangorestframework==3.9.4 # for access MySQL PyMySQL==0.9.3 @@ -9,7 +9,6 @@ PyMySQL==0.9.3 redis==2.10.5 # for access redis cache -redisco==0.1.4 django-redis-cache==0.13.1 # for call rest api @@ -17,7 +16,7 @@ httplib2==0.12.3 # for unit test coverage==4.2 -mock==2.0.0 +mock==3.0.5 unittest_xml_reporting==1.12.0 # for auto-swagger @@ -26,7 +25,7 @@ flex>=6.11.1 swagger-spec-validator>=2.1.0 # for onap logging -onappylog>=1.0.6 +onappylog==1.0.9 # uwsgi for parallel processing -uwsgi +# uwsgi diff --git a/lcm/tox.ini b/lcm/tox.ini index 38686e9f..54f7ae87 100644 --- a/lcm/tox.ini +++ b/lcm/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,pep8,cov +envlist = py36,pep8,cov skipsdist = true [tox:jenkins] @@ -18,9 +18,10 @@ commands = coverage run --branch manage.py test lcm deps = flake8 commands = flake8 -[testenv:py27] +[testenv:py36] commands = {[testenv]commands} [testenv:cov] +deps = coverage commands = coverage xml --omit="*test*,*__init__.py,*site-packages*" |