From 3a97a41a71f40c514a4d7ec8f1efb3871acf4f60 Mon Sep 17 00:00:00 2001 From: fengyuanxing Date: Fri, 9 Mar 2018 11:38:07 +0800 Subject: Modify a scale_data structure and test cases Change-Id: I2a214d4b42edd88f0dddb22abfa00bfc165ee4c3 Issue-ID: VFC-784 Signed-off-by: fengyuanxing --- lcm/ns/data/scalemapping.json | 2 +- lcm/ns/ns_manual_scale.py | 39 +++++++++++++++++++++++++----------- lcm/ns/tests/test_ns_manual_scale.py | 12 ++++++----- lcm/pub/tests/test_scaleaspect.py | 20 ++++++++++++------ lcm/pub/utils/scaleaspect.py | 8 +++++--- 5 files changed, 54 insertions(+), 27 deletions(-) diff --git a/lcm/ns/data/scalemapping.json b/lcm/ns/data/scalemapping.json index 3391595e..07e74b6e 100644 --- a/lcm/ns/data/scalemapping.json +++ b/lcm/ns/data/scalemapping.json @@ -45,7 +45,7 @@ "vnf_scale_info":[ { "vnfd_id":"nf_hw_cscf", - "vnf_scaleAspectId": "gpu", + "vnf_scaleAspectId": "gsu", "numberOfSteps": "1" }, { diff --git a/lcm/ns/ns_manual_scale.py b/lcm/ns/ns_manual_scale.py index e9373a70..8ecde776 100644 --- a/lcm/ns/ns_manual_scale.py +++ b/lcm/ns/ns_manual_scale.py @@ -62,28 +62,38 @@ class NSManualScaleService(threading.Thread): def get_and_check_params(self): self.scale_type = ignore_case_get(self.request_data, 'scaleType') if not self.scale_type or self.scale_type != SCALE_TYPE[0]: - logger.error('scaleType parameter does not exist or value is incorrect. It must be SCALE_NS.') - raise NSLCMException('scaleType parameter does not exist or value incorrect. It must be SCALE_NS.') + logger.error( + 'scaleType parameter does not exist or value is incorrect. It must be SCALE_NS.') + raise NSLCMException( + 'scaleType parameter does not exist or value incorrect. It must be SCALE_NS.') # Get data if SCALE_NS - self.scale_ns_data = ignore_case_get(self.request_data, 'scaleNsByStepsData') - self.scale_vnf_data = get_scale_vnf_data_info_list(self.scale_ns_data, self.ns_instance_id) + self.scale_ns_data = ignore_case_get(self.request_data, 'scaleNsData') + self.scale_vnf_data = get_scale_vnf_data_info_list( + self.scale_ns_data, self.ns_instance_id) logger.debug('scale_vnf_data = %s' % self.scale_vnf_data) # Get data if SCALE_VNF if not self.scale_vnf_data: - logger.error('scaleVnfData parameter does not exist or value incorrect') - raise NSLCMException('scaleVnfData parameter does not exist or value incorrect') + logger.error( + 'scaleVnfData parameter does not exist or value incorrect') + raise NSLCMException( + 'scaleVnfData parameter does not exist or value incorrect') def do_vnfs_scale(self): for i in range(len(self.scale_vnf_data)): - vnf_scale_params = self.prepare_vnf_scale_params(self.scale_vnf_data[i]) + vnf_scale_params = self.prepare_vnf_scale_params( + self.scale_vnf_data[i]) count = len(self.scale_vnf_data) progress_range = [11 + 80 / count * i, 10 + 80 / count * (i + 1)] status = self.do_vnf_scale(vnf_scale_params, progress_range) if status is JOB_MODEL_STATUS.FINISHED: - logger.info('nf[%s] scale handle end' % vnf_scale_params.get('vnfInstanceId')) - self.update_job(progress_range[1], - desc='nf[%s] scale handle end' % vnf_scale_params.get('vnfInstanceId')) + logger.info( + 'nf[%s] scale handle end' % + vnf_scale_params.get('vnfInstanceId')) + self.update_job( + progress_range[1], + desc='nf[%s] scale handle end' % + vnf_scale_params.get('vnfInstanceId')) else: logger.error('nf scale failed') raise NSLCMException('nf scale failed') @@ -102,7 +112,10 @@ class NSManualScaleService(threading.Thread): nf_inst_id = vnf_scale_params.get('vnfInstanceId') nf_service = NFManualScaleService(nf_inst_id, vnf_scale_params) nf_service.start() - self.update_job(progress_range[0], desc='nf[%s] scale handle start' % nf_inst_id) + self.update_job( + progress_range[0], + desc='nf[%s] scale handle start' % + nf_inst_id) status = self.wait_job_finish(nf_service.job_id) return status @@ -126,4 +139,6 @@ class NSManualScaleService(threading.Thread): JobUtil.add_job_status(self.job_id, progress, desc) def update_ns_status(self, status): - NSInstModel.objects.filter(id=self.ns_instance_id).update(status=status) + NSInstModel.objects.filter( + id=self.ns_instance_id).update( + status=status) diff --git a/lcm/ns/tests/test_ns_manual_scale.py b/lcm/ns/tests/test_ns_manual_scale.py index f078631c..157f50e9 100644 --- a/lcm/ns/tests/test_ns_manual_scale.py +++ b/lcm/ns/tests/test_ns_manual_scale.py @@ -125,11 +125,13 @@ class TestNsManualScale(TestCase): def test_ns_manual_scale(self, mock_run): data = { "scaleType": "SCALE_NS", - "scaleNsByStepsData": { - "aspectId": "1", - "numberOfSteps": 1, - "scalingDirection": "0" - } + "scaleNsData": [{ + "scaleNsByStepsData": [{ + "aspectId": "1", + "numberOfSteps": 1, + "scalingDirection": "0" + }] + }] } response = self.client.post( "/api/nslcm/v1/ns/%s/scale" % diff --git a/lcm/pub/tests/test_scaleaspect.py b/lcm/pub/tests/test_scaleaspect.py index 1f0ba388..e7c0ddaa 100644 --- a/lcm/pub/tests/test_scaleaspect.py +++ b/lcm/pub/tests/test_scaleaspect.py @@ -54,17 +54,25 @@ class TestScaleAspect(TestCase): self.ns_scale_steps = "1" self.ns_scale_direction = "SCALE_IN" self.scaleNsData = { - "aspectId": self.ns_scale_aspect, - "numberOfSteps": self.ns_scale_steps, - "scalingDirection": self.ns_scale_direction + "scaleNsByStepsData": [ + { + "aspectId": self.ns_scale_aspect, + "numberOfSteps": self.ns_scale_steps, + "scalingDirection": self.ns_scale_direction + } + ] } self.ns_scale_aspect2 = "TIC_EDGE_HW" self.ns_scale_steps2 = "4" self.scaleNsData2 = { - "aspectId": self.ns_scale_aspect2, - "numberOfSteps": self.ns_scale_steps2, - "scalingDirection": self.ns_scale_direction + "scaleNsByStepsData": [ + { + "aspectId": self.ns_scale_aspect2, + "numberOfSteps": self.ns_scale_steps2, + "scalingDirection": self.ns_scale_direction + } + ] } def init_scaling_map_json(self): diff --git a/lcm/pub/utils/scaleaspect.py b/lcm/pub/utils/scaleaspect.py index a8a9c987..a70a6cad 100644 --- a/lcm/pub/utils/scaleaspect.py +++ b/lcm/pub/utils/scaleaspect.py @@ -133,11 +133,13 @@ def get_nsdId(ns_instanceId): return None -def get_and_check_params(scaleNsByStepsData, ns_InstanceId): +def get_and_check_params(scaleNsData, ns_InstanceId): + if scaleNsData is None: + raise Exception("Error! scaleNsData in the request is Empty!") + scaleNsByStepsData = scaleNsData["scaleNsByStepsData"][0] if scaleNsByStepsData is None: - pass - # raise NSLCMException("Error! scaleNsByStepsData in the request is Empty!") + raise Exception("Error! scaleNsByStepsData in the request is Empty!") aspect = scaleNsByStepsData["aspectId"] numberOfSteps = scaleNsByStepsData["numberOfSteps"] -- cgit 1.2.3-korg