summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorhongyuzhao <zhao.hongyu@zte.com.cn>2019-06-17 14:57:55 +0800
committerhongyuzhao <zhao.hongyu@zte.com.cn>2019-06-17 15:25:05 +0800
commit37b1ae2386c365293249421595f0722c25bc8e8d (patch)
tree3085e00360afa57daefa594b74546afa0b168632 /lcm
parent52e85ccb07db58e357c8140c7f098b5d1f8dbee2 (diff)
Fix bug for status code when vnf lcm post request body invalid what client inputs
Issue-ID: VFC-1420 Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn> Change-Id: I07bca00f677ebc9367492ed7d9d44be4e02d9877
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/tests/test_change_ext_conn.py19
-rw-r--r--lcm/lcm/nf/tests/test_change_flavour.py4
-rw-r--r--lcm/lcm/nf/tests/test_heal_vnf.py4
-rw-r--r--lcm/lcm/nf/tests/test_instantiate_vnf.py31
-rw-r--r--lcm/lcm/nf/tests/test_operate_vnf.py4
-rw-r--r--lcm/lcm/nf/tests/test_scale_vnf.py4
-rw-r--r--lcm/lcm/nf/tests/test_scale_vnf_to_level.py4
-rw-r--r--lcm/lcm/nf/views/common.py2
8 files changed, 59 insertions, 13 deletions
diff --git a/lcm/lcm/nf/tests/test_change_ext_conn.py b/lcm/lcm/nf/tests/test_change_ext_conn.py
index 8f304d10..7efb416f 100644
--- a/lcm/lcm/nf/tests/test_change_ext_conn.py
+++ b/lcm/lcm/nf/tests/test_change_ext_conn.py
@@ -11,11 +11,15 @@
# 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.
+import mock
+
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient
from lcm.pub.database.models import NfInstModel
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.utils.jobutil import JobUtil
class TestChangeExtConn(TestCase):
@@ -95,9 +99,20 @@ class TestChangeExtConn(TestCase):
format='json')
self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
- def test_change_ext_conn_inner_error(self):
+ 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_500_INTERNAL_SERVER_ERROR, response.status_code)
+ self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
+
+ @mock.patch.object(JobUtil, 'create_job')
+ def test_change_ext_conn_inner_error(self, mock_run):
+ mock_run.return_value = NFLCMException('Boom!')
+ url = "/api/vnflcm/v1/vnf_instances/123/change_ext_conn"
+ response = self.client.post(url,
+ data=self.req_data,
+ format='json')
+ self.assertEqual(
+ status.HTTP_500_INTERNAL_SERVER_ERROR,
+ response.status_code)
diff --git a/lcm/lcm/nf/tests/test_change_flavour.py b/lcm/lcm/nf/tests/test_change_flavour.py
index 7c15dfbd..15b53f02 100644
--- a/lcm/lcm/nf/tests/test_change_flavour.py
+++ b/lcm/lcm/nf/tests/test_change_flavour.py
@@ -63,9 +63,9 @@ class TestFlavour(TestCase):
format='json')
self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
- def test_change_flavour_inner_error(self):
+ 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_500_INTERNAL_SERVER_ERROR, response.status_code)
+ self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
diff --git a/lcm/lcm/nf/tests/test_heal_vnf.py b/lcm/lcm/nf/tests/test_heal_vnf.py
index cae9cd32..d5c70da0 100644
--- a/lcm/lcm/nf/tests/test_heal_vnf.py
+++ b/lcm/lcm/nf/tests/test_heal_vnf.py
@@ -64,7 +64,7 @@ class TestNFInstantiate(TestCase):
self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
NfInstModel.objects.filter(nfinstid='1267').delete()
- def test_heal_vnf_inner_error(self):
+ def test_heal_vnf_badreq(self):
NfInstModel(nfinstid='345',
nf_name='VNF1',
nf_desc="VNF DESC",
@@ -80,7 +80,7 @@ class TestNFInstantiate(TestCase):
data={"additionalParams": "1"},
format='json')
NfInstModel.objects.filter(nfinstid='345').delete()
- self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
+ self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
@mock.patch.object(HealVnf, 'run')
def test_heal_vnf_success(self, mock_run):
diff --git a/lcm/lcm/nf/tests/test_instantiate_vnf.py b/lcm/lcm/nf/tests/test_instantiate_vnf.py
index 76fd83ba..c624e05c 100644
--- a/lcm/lcm/nf/tests/test_instantiate_vnf.py
+++ b/lcm/lcm/nf/tests/test_instantiate_vnf.py
@@ -42,6 +42,7 @@ from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.notificationsutil import NotificationsUtil
from lcm.pub.vimapi import api
+from lcm.pub.exceptions import NFLCMException
from lcm.nf.biz.instantiate_vnf import InstantiateVnf
@@ -389,3 +390,33 @@ class TestNFInstantiate(TestCase):
nf_inst_id=self.nf_inst_id,
job_id=self.job_id
).run()
+
+ @mock.patch.object(JobUtil, 'create_job')
+ def test_instantiate_inner_error(self, mock_run):
+ NfInstModel(
+ nfinstid='144',
+ nf_name='VNF1',
+ status='NOT_INSTANTIATED'
+ ).save()
+ mock_run.return_value = NFLCMException('Boom!')
+ response = self.client.post(
+ '/api/vnflcm/v1/vnf_instances/144/instantiate',
+ data=inst_req_data,
+ format='json'
+ )
+ NfInstModel.objects.filter(nfinstid='144').delete()
+ self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
+
+ def test_instantiate_badreq(self):
+ NfInstModel(
+ nfinstid='144',
+ nf_name='VNF1',
+ status='NOT_INSTANTIATED'
+ ).save()
+ response = self.client.post(
+ '/api/vnflcm/v1/vnf_instances/144/instantiate',
+ data={},
+ format='json'
+ )
+ NfInstModel.objects.filter(nfinstid='144').delete()
+ self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
diff --git a/lcm/lcm/nf/tests/test_operate_vnf.py b/lcm/lcm/nf/tests/test_operate_vnf.py
index 296abad1..cffcf37d 100644
--- a/lcm/lcm/nf/tests/test_operate_vnf.py
+++ b/lcm/lcm/nf/tests/test_operate_vnf.py
@@ -78,7 +78,7 @@ class TestNFOperate(TestCase):
status='NOT_INSTANTIATED'
).delete()
- def test_operate_vnf_inner_error(self):
+ def test_operate_vnf_badreq(self):
NfInstModel(
nfinstid='345',
nf_name='VNF1',
@@ -99,7 +99,7 @@ class TestNFOperate(TestCase):
)
NfInstModel.objects.filter(nfinstid='345').delete()
self.failUnlessEqual(
- status.HTTP_500_INTERNAL_SERVER_ERROR,
+ status.HTTP_400_BAD_REQUEST,
response.status_code
)
diff --git a/lcm/lcm/nf/tests/test_scale_vnf.py b/lcm/lcm/nf/tests/test_scale_vnf.py
index 60cabbdb..a43c475c 100644
--- a/lcm/lcm/nf/tests/test_scale_vnf.py
+++ b/lcm/lcm/nf/tests/test_scale_vnf.py
@@ -53,7 +53,7 @@ class TestNfScale(TestCase):
format='json')
self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
- def test_scale_vnf_inner_error(self):
+ def test_scale_vnf_badreq(self):
NfInstModel(nfinstid='678',
nf_name='VNF1',
nf_desc="VNF DESC",
@@ -69,4 +69,4 @@ class TestNfScale(TestCase):
data={},
format='json')
NfInstModel.objects.filter(nfinstid='678').delete()
- self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
+ self.failUnlessEqual(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 657a19ff..7c7b98d8 100644
--- a/lcm/lcm/nf/tests/test_scale_vnf_to_level.py
+++ b/lcm/lcm/nf/tests/test_scale_vnf_to_level.py
@@ -53,7 +53,7 @@ class TestNfScaleToLevel(TestCase):
format='json')
self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
- def test_scale_to_level_inner_error(self):
+ def test_scale_to_level_badreq(self):
NfInstModel(nfinstid='678',
nf_name='VNF1',
nf_desc="VNF DESC",
@@ -69,4 +69,4 @@ class TestNfScaleToLevel(TestCase):
data={},
format='json')
NfInstModel.objects.filter(nfinstid='678').delete()
- self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
+ self.failUnlessEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
diff --git a/lcm/lcm/nf/views/common.py b/lcm/lcm/nf/views/common.py
index a3c87a3c..e24a8bce 100644
--- a/lcm/lcm/nf/views/common.py
+++ b/lcm/lcm/nf/views/common.py
@@ -103,7 +103,7 @@ def deal_vnf_action(logger, opt_type, opt_status, instid, req, req_serializer, a
act_vnf_req_serializer = req_serializer(data=req.data)
if not act_vnf_req_serializer.is_valid():
- raise NFLCMException(act_vnf_req_serializer.errors)
+ raise NFLCMExceptionBadRequest(act_vnf_req_serializer.errors)
vnf_insts = NfInstModel.objects.filter(nfinstid=instid)
if not vnf_insts.exists():