diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-22 16:32:32 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-22 16:32:32 +0800 |
commit | 5b05f88ce6e31a5c90fc21496c82f196f2180b2c (patch) | |
tree | e6e26fb532e7aef077cf4a3d5c9f987e47e681e8 /lcm | |
parent | 97ce57eed00e679487079b3ca5dc18ca65e8dc11 (diff) |
Add ETag check ut case
Change-Id: I8574a69afbbe05886ee6561630ceab4dc8fc30b4
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/nf/tests/test_update_vnf.py | 25 | ||||
-rw-r--r-- | lcm/lcm/nf/views/common.py | 7 |
2 files changed, 28 insertions, 4 deletions
diff --git a/lcm/lcm/nf/tests/test_update_vnf.py b/lcm/lcm/nf/tests/test_update_vnf.py index 484885a1..ce1cd6f0 100644 --- a/lcm/lcm/nf/tests/test_update_vnf.py +++ b/lcm/lcm/nf/tests/test_update_vnf.py @@ -15,6 +15,7 @@ import mock from django.test import TestCase from rest_framework.test import APIClient +from rest_framework.test import RequestsClient from rest_framework import status from lcm.pub.utils import restcall @@ -40,6 +41,29 @@ class TestNFUpdate(TestCase): format='json') self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code) + def test_update_vnf_etag_not_match(self): + instanceid = "19" + NfInstModel(nfinstid=instanceid, + nf_name='VNF1', + nf_desc="VNF DESC", + vnfdid="1", + netype="XGW", + vendor="ZTE", + vnfSoftwareVersion="V1", + version="V1", + package_id="2", + status='INSTANTIATED').save() + rc = RequestsClient() + response = rc.patch("http://localhost:8801/api/vnflcm/v1/vnf_instances/19", + json=self.upd_data, + headers={ + "Accept": "application/json", + "Content-Type": "application/json", + "If-Match": "test_etag" + }) + NfInstModel.objects.filter(nfinstid=instanceid).delete() + self.failUnlessEqual(status.HTTP_412_PRECONDITION_FAILED, response.status_code) + @mock.patch.object(restcall, 'call_req') def test_update_vnf_success(self, mock_call_req): instanceid = "12" @@ -57,4 +81,5 @@ class TestNFUpdate(TestCase): job_id = JobUtil.create_job('NF', 'UPDATETEST', instanceid) 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) diff --git a/lcm/lcm/nf/views/common.py b/lcm/lcm/nf/views/common.py index 57e6a621..4f864263 100644 --- a/lcm/lcm/nf/views/common.py +++ b/lcm/lcm/nf/views/common.py @@ -117,11 +117,10 @@ def deal_vnf_action(logger, opt_type, opt_status, instid, req, req_serializer, a raise NFLCMExceptionConflict("VNF(%s) is not INSTANTIATED." % instid) req_etag = None - is_upd_vnf_opt = (opt_type == "UpdateVnf") - if is_upd_vnf_opt: + if opt_type == OPERATION_TYPE.MODIFY_INFO: req_etag = req.META.get("HTTP_IF_MATCH") logger.debug("req_etag=%s, CACHE_ETAG=%s", req_etag, CACHE_ETAG) - if req_etag != CACHE_ETAG: + if req_etag and req_etag != CACHE_ETAG: raise NFLCMExceptionPreconditionFailed("Etag mismatch") job_id = JobUtil.create_job('NF', opt_type, instid) @@ -131,7 +130,7 @@ def deal_vnf_action(logger, opt_type, opt_status, instid, req, req_serializer, a act_task(req.data, instid, job_id).start() resp = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED) - if is_upd_vnf_opt: + if opt_type == OPERATION_TYPE.MODIFY_INFO: resp["ETag"] = req_etag return resp |