summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfengyuanxing <feng.yuanxing@zte.com.cn>2018-03-12 15:12:38 +0800
committerfengyuanxing <feng.yuanxing@zte.com.cn>2018-03-12 15:12:38 +0800
commit348d4624de3c1109741d3590b76cdb2949494f9d (patch)
treec73b3f86eb0aff22010a27ec4daab89c6e4af906
parenta0ab1f2c33494c8386982a7ffc07264dd5f906c1 (diff)
Modify the code of scaling
Change-Id: Ib9c85f58e5d449b7f8d7429b8e4f4a0e22df44f1 Issue-ID: VFC-784 Signed-off-by: fengyuanxing <feng.yuanxing@zte.com.cn>
-rw-r--r--lcm/ns/tests/test_ns_manual_scale.py72
-rw-r--r--lcm/pub/tests/test_scaleaspect.py8
-rw-r--r--lcm/pub/utils/scaleaspect.py2
3 files changed, 73 insertions, 9 deletions
diff --git a/lcm/ns/tests/test_ns_manual_scale.py b/lcm/ns/tests/test_ns_manual_scale.py
index 1ca06509..ceb7498e 100644
--- a/lcm/ns/tests/test_ns_manual_scale.py
+++ b/lcm/ns/tests/test_ns_manual_scale.py
@@ -13,18 +13,19 @@
# limitations under the License.
import uuid
-
+import os
import mock
from django.test import Client
from django.test import TestCase
from rest_framework import status
-
from lcm.ns.const import NS_INST_STATUS
from lcm.ns.ns_manual_scale import NSManualScaleService
-from lcm.pub.database.models import NSInstModel, JobModel
+from lcm.pub.database.models import NSInstModel, JobModel, NfInstModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.utils import restcall
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE, JOB_MODEL_STATUS
+from lcm.pub.msapi import catalog
+from lcm.pub.utils.scaleaspect import get_json_data
SCALING_JSON = {
@@ -118,8 +119,19 @@ class TestNsManualScale(TestCase):
nspackage_id=self.package_id,
nsd_id="111").save()
+ self.init_scaling_map_json()
+
def tearDown(self):
NSInstModel.objects.filter().delete()
+ JobModel.objects.filter().delete()
+
+ def init_scaling_map_json(self):
+ curdir_path = os.path.dirname(
+ os.path.dirname(
+ os.path.dirname(
+ os.path.abspath(__file__))))
+ filename = curdir_path + "/ns/data/scalemapping.json"
+ self.scaling_map_json = get_json_data(filename)
def insert_new_ns(self):
ns_inst_id = str(uuid.uuid4())
@@ -133,6 +145,35 @@ class TestNsManualScale(TestCase):
nsd_id=package_id).save()
return ns_inst_id, job_id
+ def insert_new_nf(self):
+ # Create a third vnf instance
+ self.nf_name = "name_1"
+ self.vnf_id = "1"
+ self.vnfm_inst_id = "1"
+ nf_inst_id = "233"
+ package_id = "nf_zte_hss"
+ nf_uuid = "ab34-3g5j-de13-ab85-ij93"
+
+ NfInstModel.objects.create(
+ nfinstid=nf_inst_id,
+ nf_name=self.nf_name,
+ vnf_id=self.vnf_id,
+ vnfm_inst_id=self.vnfm_inst_id,
+ ns_inst_id=self.ns_inst_id,
+ max_cpu='14',
+ max_ram='12296',
+ max_hd='101',
+ max_shd="20",
+ max_net=10,
+ status='active',
+ mnfinstid=nf_uuid,
+ package_id=package_id,
+ vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
+ '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
+ '"productType": "CN","vnfType": "PGW",'
+ '"description": "PGW VNFD description",'
+ '"isShared":true,"vnfExtendType":"driver"}}')
+
@mock.patch.object(NSManualScaleService, 'run')
def test_ns_manual_scale(self, mock_run):
data = {
@@ -198,6 +239,29 @@ class TestNsManualScale(TestCase):
jobs = JobModel.objects.filter(jobid=job_id)
self.assertEqual(255, jobs[0].progress)
+ @mock.patch.object(catalog, 'get_scalingmap_json_package')
+ @mock.patch.object(NSManualScaleService, 'do_vnfs_scale')
+ def test_ns_manual_scale_success(self, mock_do_vnfs_scale, mock_get_scalingmap_json_package):
+ data = {
+ "scaleType": "SCALE_NS",
+ "scaleNsData": [{
+ "scaleNsByStepsData": [{
+ "aspectId": "TIC_EDGE_IMS",
+ "numberOfSteps": "1",
+ "scalingDirection": "0"
+ }]
+ }]
+ }
+ mock_get_scalingmap_json_package.return_value = self.scaling_map_json
+ mock_do_vnfs_scale.return_value = JOB_MODEL_STATUS.FINISHED
+ ns_inst_id, job_id = self.insert_new_ns()
+ job_id = JobUtil.create_job(
+ "NS", JOB_TYPE.MANUAL_SCALE_VNF, ns_inst_id)
+ self.insert_new_nf()
+ NSManualScaleService(ns_inst_id, data, job_id).run()
+ jobs = JobModel.objects.filter(jobid=job_id)
+ self.assertEqual(100, jobs[0].progress)
+
@mock.patch.object(restcall, 'call_req')
def test_ns_manual_scale_thread(self, mock_call):
data = {
diff --git a/lcm/pub/tests/test_scaleaspect.py b/lcm/pub/tests/test_scaleaspect.py
index e7c0ddaa..ed69cbf5 100644
--- a/lcm/pub/tests/test_scaleaspect.py
+++ b/lcm/pub/tests/test_scaleaspect.py
@@ -53,7 +53,7 @@ class TestScaleAspect(TestCase):
self.ns_scale_aspect = "TIC_EDGE_IMS"
self.ns_scale_steps = "1"
self.ns_scale_direction = "SCALE_IN"
- self.scaleNsData = {
+ self.scaleNsData = [{
"scaleNsByStepsData": [
{
"aspectId": self.ns_scale_aspect,
@@ -61,11 +61,11 @@ class TestScaleAspect(TestCase):
"scalingDirection": self.ns_scale_direction
}
]
- }
+ }]
self.ns_scale_aspect2 = "TIC_EDGE_HW"
self.ns_scale_steps2 = "4"
- self.scaleNsData2 = {
+ self.scaleNsData2 = [{
"scaleNsByStepsData": [
{
"aspectId": self.ns_scale_aspect2,
@@ -73,7 +73,7 @@ class TestScaleAspect(TestCase):
"scalingDirection": self.ns_scale_direction
}
]
- }
+ }]
def init_scaling_map_json(self):
curdir_path = os.path.dirname(
diff --git a/lcm/pub/utils/scaleaspect.py b/lcm/pub/utils/scaleaspect.py
index a70a6cad..81fdfd8b 100644
--- a/lcm/pub/utils/scaleaspect.py
+++ b/lcm/pub/utils/scaleaspect.py
@@ -137,7 +137,7 @@ 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]
+ scaleNsByStepsData = scaleNsData[0]["scaleNsByStepsData"][0]
if scaleNsByStepsData is None:
raise Exception("Error! scaleNsByStepsData in the request is Empty!")