diff options
-rw-r--r-- | lcm/ns/tests/test_ns_heal.py | 3 | ||||
-rw-r--r-- | lcm/ns/tests/vnfs/tests.py | 65 | ||||
-rw-r--r-- | lcm/pub/utils/tests.py | 138 |
3 files changed, 183 insertions, 23 deletions
diff --git a/lcm/ns/tests/test_ns_heal.py b/lcm/ns/tests/test_ns_heal.py index 8d2f93a6..de810503 100644 --- a/lcm/ns/tests/test_ns_heal.py +++ b/lcm/ns/tests/test_ns_heal.py @@ -23,6 +23,7 @@ from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE from lcm.ns.const import NS_INST_STATUS from lcm.pub.exceptions import NSLCMException from lcm.ns.ns_heal import NSHealService +from lcm.ns.vnfs.heal_vnfs import NFHealService class TestHealNsViews(TestCase): @@ -96,7 +97,7 @@ class TestHealNsViews(TestCase): response = self.client.delete("/api/nslcm/v1/ns/%s" % self.ns_inst_id) self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) - @mock.patch.object(NSHealService, 'start') + @mock.patch.object(NFHealService, 'start') @mock.patch.object(NSHealService, 'wait_job_finish') @mock.patch.object(NSHealService, 'update_job') def test_ns_manual_scale_thread(self, mock_start, mock_wait, mock_update): diff --git a/lcm/ns/tests/vnfs/tests.py b/lcm/ns/tests/vnfs/tests.py index 1406fae2..2e3e4f14 100644 --- a/lcm/ns/tests/vnfs/tests.py +++ b/lcm/ns/tests/vnfs/tests.py @@ -436,15 +436,33 @@ class TestHealVnfViews(TestCase): self.job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, self.nf_inst_id) NSInstModel(id=self.ns_inst_id, name="ns_name").save() - NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1', - vnfm_inst_id='1', ns_inst_id='111,2-2-2', - max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10, - status='active', mnfinstid=self.nf_uuid, package_id='pkg1', - 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"}}') + NfInstModel.objects.create(nfinstid=self.nf_inst_id, + nf_name='name_1', + vnf_id='1', + vnfm_inst_id='1', + ns_inst_id='111,2-2-2', + max_cpu='14', + max_ram='12296', + max_hd='101', + max_shd="20", + max_net=10, + status='active', + mnfinstid=self.nf_uuid, + package_id='pkg1', + vnfd_model=json.dumps({ + "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" + } + })) def tearDown(self): NSInstModel.objects.all().delete() @@ -461,18 +479,23 @@ class TestHealVnfViews(TestCase): "/api/resmgr/v1/vnf/1": [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'], "/api/ztevnfmdriver/v1/1/jobs/" + self.job_id + "?responseId=0": - [0, json.JSONEncoder().encode({"jobId": self.job_id, - "responsedescriptor": {"progress": "100", - "status": JOB_MODEL_STATUS.FINISHED, - "responseid": "3", - "statusdescription": "creating", - "errorcode": "0", - "responsehistorylist": [ - {"progress": "0", - "status": JOB_MODEL_STATUS.PROCESSING, - "responseid": "2", - "statusdescription": "creating", - "errorcode": "0"}]}}), '200']} + [0, json.JSONEncoder().encode({ + "jobId": self.job_id, + "responsedescriptor": { + "progress": "100", + "status": JOB_MODEL_STATUS.FINISHED, + "responseid": "3", + "statusdescription": "creating", + "errorcode": "0", + "responsehistorylist": [{ + "progress": "0", + "status": JOB_MODEL_STATUS.PROCESSING, + "responseid": "2", + "statusdescription": "creating", + "errorcode": "0" + }] + } + }), '200']} def side_effect(*args): return mock_vals[args[4]] diff --git a/lcm/pub/utils/tests.py b/lcm/pub/utils/tests.py index 232acf05..d7d628e0 100644 --- a/lcm/pub/utils/tests.py +++ b/lcm/pub/utils/tests.py @@ -17,8 +17,11 @@ import mock import enumutil import fileutil import urllib2 +import syscomm +import timeutil +import values -from lcm.pub.database.models import JobStatusModel +from lcm.pub.database.models import JobStatusModel, JobModel from lcm.pub.utils.jobutil import JobUtil @@ -85,3 +88,136 @@ class UtilsTest(unittest.TestCase): self.assertEqual(2, len(jobs)) self.assertEqual(3, jobs[0].indexid) self.assertEqual(2, jobs[1].indexid) + JobStatusModel.objects.filter().delete() + + def test_is_job_exists(self): + job_id = "1" + JobModel.objects.filter().delete() + JobModel( + jobid=job_id, + jobtype="1", + jobaction="2", + resid="3", + status=0 + ).save() + self.assertTrue(JobUtil.is_job_exists(job_id)) + JobModel.objects.filter().delete() + + def test_create_job(self): + job_id = "5" + JobModel.objects.filter().delete() + JobUtil.create_job( + inst_type="1", + jobaction="2", + inst_id="3", + user="4", + job_id=5, + res_name="6") + self.assertEqual(1, len(JobModel.objects.filter(jobid=job_id))) + JobModel.objects.filter().delete() + + def test_clear_job(self): + job_id = "1" + JobModel.objects.filter().delete() + JobModel( + jobid=job_id, + jobtype="1", + jobaction="2", + resid="3", + status=0 + ).save() + JobUtil.clear_job(job_id) + self.assertEqual(0, len(JobModel.objects.filter(jobid=job_id))) + + def test_add_job_status_when_job_is_not_created(self): + JobModel.objects.filter().delete() + self.assertRaises( + Exception, + JobUtil.add_job_status, + job_id="1", + progress=1, + status_decs="2", + error_code="0" + ) + + def test_add_job_status_normal(self): + job_id = "1" + JobModel.objects.filter().delete() + JobStatusModel.objects.filter().delete() + JobModel( + jobid=job_id, + jobtype="1", + jobaction="2", + resid="3", + status=0 + ).save() + JobUtil.add_job_status( + job_id="1", + progress=1, + status_decs="2", + error_code="0" + ) + self.assertEqual(1, len(JobStatusModel.objects.filter(jobid=job_id))) + JobStatusModel.objects.filter().delete() + JobModel.objects.filter().delete() + + def test_clear_job_status(self): + job_id = "1" + JobStatusModel.objects.filter().delete() + JobStatusModel( + indexid=1, + jobid=job_id, + status="success", + progress=10 + ).save() + JobUtil.clear_job_status(job_id) + self.assertEqual(0, len(JobStatusModel.objects.filter(jobid=job_id))) + + def test_get_unfinished_jobs(self): + JobModel.objects.filter().delete() + JobModel( + jobid="11", + jobtype="InstVnf", + jobaction="2", + resid="3", + status=0 + ).save() + JobModel( + jobid="22", + jobtype="InstVnf", + jobaction="2", + resid="3", + status=0 + ).save() + JobModel( + jobid="33", + jobtype="InstVnf", + jobaction="2", + resid="3", + status=0 + ).save() + progresses = JobUtil.get_unfinished_jobs( + url_prefix="/vnfinst", + inst_id="3", + inst_type="InstVnf" + ) + expect_progresses = ['/vnfinst/11', '/vnfinst/22', '/vnfinst/33'] + self.assertEqual(expect_progresses, progresses) + JobModel.objects.filter().delete() + + def test_fun_name(self): + self.assertEqual("test_fun_name", syscomm.fun_name()) + + def test_now_time(self): + self.assertIn(":", timeutil.now_time()) + self.assertIn("-", timeutil.now_time()) + + def test_ignore_case_get(self): + data = { + "Abc": "def", + "HIG": "klm" + } + self.assertEqual("def", values.ignore_case_get(data, 'ABC')) + self.assertEqual("def", values.ignore_case_get(data, 'abc')) + self.assertEqual("klm", values.ignore_case_get(data, 'hig')) + self.assertEqual("bbb", values.ignore_case_get(data, 'aaa', 'bbb')) |