Add query vnfm-info and unit test 45/11545/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Mon, 11 Sep 2017 05:20:32 +0000 (13:20 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Mon, 11 Sep 2017 05:20:32 +0000 (13:20 +0800)
Implement query vnfm info logic and unit test in vfc lcm
for vnfm driver.

Change-Id: I458a2bf49b1acb2520af6d06481129fac64db1d0
Issue-ID: VFC-323
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/ns/tests/vnfs/tests.py
lcm/ns/vnfs/urls.py
lcm/ns/vnfs/views.py

index 7024dfe..32eaf0e 100644 (file)
@@ -419,6 +419,64 @@ class TestHealVnfViews(TestCase):
         self.assertRaises(NSLCMException, NFHealService(nf_inst_id, req_data).run)
         self.assertEqual(len(NfInstModel.objects.filter(nfinstid=nf_inst_id)), 0)
 
+class TestGetVnfmInfoViews(TestCase):
+    def setUp(self):
+        self.client = Client()
+        self.vnfm_id = str(uuid.uuid4())
+
+    def tearDown(self):
+        pass
+
+    @mock.patch.object(restcall, "call_req")
+    def test_get_vnfm_info(self, mock_call_req):
+        vnfm_info_aai = { "vnfm-id": "example-vnfm-id-val-62576",
+                          "vim-id": "example-vim-id-val-35114",
+                          "certificate-url": "example-certificate-url-val-90242",
+                          "esr-system-info-list": {
+                            "esr-system-info": [
+                              {
+                                "esr-system-info-id": "example-esr-system-info-id-val-78484",
+                                "system-name": "example-system-name-val-23790",
+                                "type": "example-type-val-52596",
+                                "vendor": "example-vendor-val-47399",
+                                "version": "example-version-val-42051",
+                                "service-url": "example-service-url-val-10731",
+                                "user-name": "example-user-name-val-65946",
+                                "password": "example-password-val-22505",
+                                "system-type": "example-system-type-val-27221",
+                                "protocal": "example-protocal-val-54632",
+                                "ssl-cacert": "example-ssl-cacert-val-45965",
+                                "ssl-insecure": True,
+                                "ip-address": "example-ip-address-val-19212",
+                                "port": "example-port-val-57641",
+                                "cloud-domain": "example-cloud-domain-val-26296",
+                                "default-tenant": "example-default-tenant-val-87724"
+                              }
+                            ]
+                          }
+                        }
+        r1 = [0, json.JSONEncoder().encode(vnfm_info_aai), '200']
+        mock_call_req.side_effect = [r1]
+        esr_system_info = ignore_case_get(ignore_case_get(vnfm_info_aai, "esr-system-info-list"), "esr-system-info")
+        expect_data = { "vnfmId": vnfm_info_aai["vnfm-id"],
+                        "name": vnfm_info_aai["vnfm-id"],
+                        "type": ignore_case_get(esr_system_info[0], "type"),
+                        "vimId": vnfm_info_aai["vim-id"],
+                        "vendor": ignore_case_get(esr_system_info[0], "vendor"),
+                        "version": ignore_case_get(esr_system_info[0], "version"),
+                        "description": "vnfm",
+                        "certificateUrl": vnfm_info_aai["certificate-url"],
+                        "url": ignore_case_get(esr_system_info[0], "service-url"),
+                        "userName": ignore_case_get(esr_system_info[0], "user-name"),
+                        "password": ignore_case_get(esr_system_info[0], "password"),
+                        "createTime": "2016-07-06 15:33:18"
+                    }
+
+        response = self.client.get("/api/nslcm/v1/vnfms/%s" % self.vnfm_id)
+        self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+        context = json.loads(response.content)
+        self.assertEqual(expect_data, context)
+
 vnfd_model_dict = {
     'local_storages': [],
     'vdus': [
index 0a1ba17..d38fb4f 100644 (file)
@@ -14,7 +14,7 @@
 from django.conf.urls import patterns, url
 from rest_framework.urlpatterns import format_suffix_patterns
 
-from lcm.ns.vnfs.views import NfView, NfDetailView, NfGrant, LcmNotify, NfScaleView, NfVerifyView
+from lcm.ns.vnfs.views import NfView, NfDetailView, NfGrant, LcmNotify, NfScaleView, NfVerifyView, NfVnfmInfoView
 
 urlpatterns = patterns('',
                        url(r'^api/nslcm/v1/ns/vnfs$', NfView.as_view()),
@@ -25,6 +25,7 @@ urlpatterns = patterns('',
                            LcmNotify.as_view()),
                        url(r'^api/nslcm/v1/ns/vnfs/(?P<vnfinstid>[0-9a-zA-Z_-]+)/scaling$', NfScaleView.as_view()),
                        url(r'^api/nslcm/v1/vnfonboarding$', NfVerifyView.as_view()),
+                       url(r'^api/nslcm/v1/vnfms/(?P<vnfmid>[0-9a-zA-Z_-]+)', NfVnfmInfoView.as_view()),
                        )
 
 urlpatterns = format_suffix_patterns(urlpatterns)
index 5c92569..c3328ff 100644 (file)
@@ -27,6 +27,8 @@ from lcm.ns.vnfs.scale_vnfs import NFManualScaleService
 from lcm.ns.vnfs.terminate_nfs import TerminateVnfs
 from lcm.ns.vnfs.grant_vnfs import GrantVnfs
 from lcm.ns.vnfs.notify_lcm import NotifyLcm
+from lcm.pub.exceptions import NSLCMException
+from lcm.pub.msapi.extsys import get_vnfm_by_id
 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
 from lcm.pub.utils.values import ignore_case_get
 
@@ -121,4 +123,18 @@ class NfVerifyView(APIView):
         job_id = "VNFSDK_" + str(uuid.uuid4())
         logger.debug("NfVerifyView--post::%s> %s", job_id, request.data)
         VerifyVnfs(request.data, job_id).start()
-        return Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)
\ No newline at end of file
+        return Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)
+
+class NfVnfmInfoView(APIView):
+    def get(self, request, vnfmid):
+        logger.debug("NfVnfmInfoView--get::> %s" % vnfmid)
+        try:
+            vnfm_info = get_vnfm_by_id(vnfmid)
+        except NSLCMException as e:
+            logger.error(e.message)
+            return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        except:
+            logger.error(traceback.format_exc())
+            return Response(data={'error': 'Failed to get vnfm info.'},
+                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        return Response(data=vnfm_info, status=status.HTTP_200_OK)