diff options
-rw-r--r-- | lcm/ns/tests/vnfs/tests.py | 58 | ||||
-rw-r--r-- | lcm/ns/vnfs/urls.py | 3 | ||||
-rw-r--r-- | lcm/ns/vnfs/views.py | 18 |
3 files changed, 77 insertions, 2 deletions
diff --git a/lcm/ns/tests/vnfs/tests.py b/lcm/ns/tests/vnfs/tests.py index 7024dfe3..32eaf0e3 100644 --- a/lcm/ns/tests/vnfs/tests.py +++ b/lcm/ns/tests/vnfs/tests.py @@ -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': [ diff --git a/lcm/ns/vnfs/urls.py b/lcm/ns/vnfs/urls.py index 0a1ba178..d38fb4f9 100644 --- a/lcm/ns/vnfs/urls.py +++ b/lcm/ns/vnfs/urls.py @@ -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) diff --git a/lcm/ns/vnfs/views.py b/lcm/ns/vnfs/views.py index 5c925697..c3328ff9 100644 --- a/lcm/ns/vnfs/views.py +++ b/lcm/ns/vnfs/views.py @@ -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) |