Add query vim-info and unit test 81/11581/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Mon, 11 Sep 2017 06:55:43 +0000 (14:55 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Mon, 11 Sep 2017 06:55:43 +0000 (14:55 +0800)
Change-Id: I64fd93eaf69ac6a211b216e832c7b43e406bef8e
Issue-ID: VFC-325
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 32eaf0e..48e4ab1 100644 (file)
@@ -429,54 +429,93 @@ class TestGetVnfmInfoViews(TestCase):
 
     @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"
-                              }
-                            ]
-                          }
+        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"
-                    }
+        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)
 
+class TestGetVimInfoViews(TestCase):
+    def setUp(self):
+        self.client = Client()
+        self.vim_id = "zte_test"
+
+    def tearDown(self):
+        pass
+
+    @mock.patch.object(restcall, "call_req")
+    def test_get_vim_info(self, mock_call_req):
+        r1 = [0, json.JSONEncoder().encode(vim_info_aai), '200']
+        mock_call_req.side_effect = [r1]
+        esr_system_info = ignore_case_get(ignore_case_get(vim_info_aai, "esr-system-info-list"), "esr-system-info")
+        expect_data = \
+            {
+                "vimId": self.vim_id,
+                "name": self.vim_id,
+                "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"),
+                # "tenant": ignore_case_get(tenants[0], "tenant-id"),
+                "tenant": ignore_case_get(esr_system_info[0], "default-tenant"),
+                "vendor": ignore_case_get(esr_system_info[0], "vendor"),
+                "version": ignore_case_get(esr_system_info[0], "version"),
+                "description": "vim",
+                "domain": "",
+                "type": ignore_case_get(esr_system_info[0], "type"),
+                "createTime": "2016-07-18 12:22:53"
+            }
+
+        response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
+        self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+        context = json.loads(response.content)
+        self.assertEqual(expect_data["url"], context["url"])
+
 vnfd_model_dict = {
     'local_storages': [],
     'vdus': [
@@ -813,3 +852,297 @@ nsd_model_dict = {
         "vendor": "zte",
         "id": "vbras_ns",
         "name": "vbras_ns"}}
+
+
+vim_info_aai = {
+    "cloud-owner": "example-cloud-owner-val-1140",
+    "cloud-region-id": "example-cloud-region-id-val-73665",
+    "cloud-type": "example-cloud-type-val-14605",
+    "owner-defined-type": "example-owner-defined-type-val-84308",
+    "cloud-region-version": "example-cloud-region-version-val-67581",
+    "identity-url": "example-identity-url-val-98779",
+    "cloud-zone": "example-cloud-zone-val-67799",
+    "complex-name": "example-complex-name-val-62313",
+    "sriov-automation": True,
+    "cloud-extra-info": "example-cloud-extra-info-val-72366",
+    "cloud-epa-caps": "example-cloud-epa-caps-val-6090",
+    "volume-groups": {
+        "volume-group": [
+            {
+                "volume-group-id": "example-volume-group-id-val-22419",
+                "volume-group-name": "example-volume-group-name-val-41986",
+                "heat-stack-id": "example-heat-stack-id-val-53241",
+                "vnf-type": "example-vnf-type-val-19402",
+                "orchestration-status": "example-orchestration-status-val-61478",
+                "model-customization-id": "example-model-customization-id-val-82523",
+                "vf-module-model-customization-id": "example-vf-module-model-customization-id-val-49214"
+            }
+        ]
+    },
+    "tenants": {
+        "tenant": [
+            {
+                "tenant-id": "example-tenant-id-val-28032",
+                "tenant-name": "example-tenant-name-val-65072",
+                "tenant-context": "example-tenant-context-val-81984",
+                "vservers": {
+                    "vserver": [
+                        {
+                            "vserver-id": "example-vserver-id-val-25067",
+                            "vserver-name": "example-vserver-name-val-16505",
+                            "vserver-name2": "example-vserver-name2-val-84664",
+                            "prov-status": "example-prov-status-val-1789",
+                            "vserver-selflink": "example-vserver-selflink-val-6858",
+                            "in-maint": True,
+                            "is-closed-loop-disabled": True,
+                            "volumes": {
+                                "volume": [
+                                    {
+                                        "volume-id": "example-volume-id-val-69135",
+                                        "volume-selflink": "example-volume-selflink-val-96457"
+                                    }
+                                ]
+                            },
+                            "l-interfaces": {
+                                "l-interface": [
+                                    {
+                                        "interface-name": "example-interface-name-val-57532",
+                                        "interface-role": "example-interface-role-val-10218",
+                                        "v6-wan-link-ip": "example-v6-wan-link-ip-val-64941",
+                                        "selflink": "example-selflink-val-80427",
+                                        "interface-id": "example-interface-id-val-53136",
+                                        "macaddr": "example-macaddr-val-35417",
+                                        "network-name": "example-network-name-val-77107",
+                                        "management-option": "example-management-option-val-19752",
+                                        "interface-description": "example-interface-description-val-34461",
+                                        "is-port-mirrored": True,
+                                        "in-maint": True,
+                                        "prov-status": "example-prov-status-val-39824",
+                                        "is-ip-unnumbered": True,
+                                        "allowed-address-pairs": "example-allowed-address-pairs-val-76052",
+                                        "vlans": {
+                                            "vlan": [
+                                                {
+                                                    "vlan-interface": "example-vlan-interface-val-81272",
+                                                    "vlan-id-inner": 70939085,
+                                                    "vlan-id-outer": 80445097,
+                                                    "speed-value": "example-speed-value-val-47939",
+                                                    "speed-units": "example-speed-units-val-90989",
+                                                    "vlan-description": "example-vlan-description-val-96792",
+                                                    "backdoor-connection": "example-backdoor-connection-val-74707",
+                                                    "vpn-key": "example-vpn-key-val-73677",
+                                                    "orchestration-status": "example-orchestration-status-val-93544",
+                                                    "in-maint": True,
+                                                    "prov-status": "example-prov-status-val-18854",
+                                                    "is-ip-unnumbered": True,
+                                                    "l3-interface-ipv4-address-list": [
+                                                        {
+                                                            "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-46993",
+                                                            "l3-interface-ipv4-prefix-length": 28216731,
+                                                            "vlan-id-inner": 8589169,
+                                                            "vlan-id-outer": 22167953,
+                                                            "is-floating": True,
+                                                            "neutron-network-id": "example-neutron-network-id-val-45028",
+                                                            "neutron-subnet-id": "example-neutron-subnet-id-val-99844"
+                                                        }
+                                                    ],
+                                                    "l3-interface-ipv6-address-list": [
+                                                        {
+                                                            "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-8414",
+                                                            "l3-interface-ipv6-prefix-length": 6761190,
+                                                            "vlan-id-inner": 88349266,
+                                                            "vlan-id-outer": 87459050,
+                                                            "is-floating": True,
+                                                            "neutron-network-id": "example-neutron-network-id-val-23050",
+                                                            "neutron-subnet-id": "example-neutron-subnet-id-val-49448"
+                                                        }
+                                                    ]
+                                                }
+                                            ]
+                                        },
+                                        "sriov-vfs": {
+                                            "sriov-vf": [
+                                                {
+                                                    "pci-id": "example-pci-id-val-9702",
+                                                    "vf-vlan-filter": "example-vf-vlan-filter-val-94893",
+                                                    "vf-mac-filter": "example-vf-mac-filter-val-40257",
+                                                    "vf-vlan-strip": True,
+                                                    "vf-vlan-anti-spoof-check": True,
+                                                    "vf-mac-anti-spoof-check": True,
+                                                    "vf-mirrors": "example-vf-mirrors-val-86932",
+                                                    "vf-broadcast-allow": True,
+                                                    "vf-unknown-multicast-allow": True,
+                                                    "vf-unknown-unicast-allow": True,
+                                                    "vf-insert-stag": True,
+                                                    "vf-link-status": "example-vf-link-status-val-94678",
+                                                    "neutron-network-id": "example-neutron-network-id-val-18823"
+                                                }
+                                            ]
+                                        },
+                                        "l-interfaces": {
+                                            "l-interface": [
+                                                {
+                                                    "interface-name": "example-interface-name-val-42153",
+                                                    "interface-role": "example-interface-role-val-38539",
+                                                    "v6-wan-link-ip": "example-v6-wan-link-ip-val-12452",
+                                                    "selflink": "example-selflink-val-38250",
+                                                    "interface-id": "example-interface-id-val-68366",
+                                                    "macaddr": "example-macaddr-val-76392",
+                                                    "network-name": "example-network-name-val-58136",
+                                                    "management-option": "example-management-option-val-88555",
+                                                    "interface-description": "example-interface-description-val-66875",
+                                                    "is-port-mirrored": True,
+                                                    "in-maint": True,
+                                                    "prov-status": "example-prov-status-val-9493",
+                                                    "is-ip-unnumbered": True,
+                                                    "allowed-address-pairs": "example-allowed-address-pairs-val-80407"
+                                                }
+                                            ]
+                                        },
+                                        "l3-interface-ipv4-address-list": [
+                                            {
+                                                "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-57596",
+                                                "l3-interface-ipv4-prefix-length": 90030728,
+                                                "vlan-id-inner": 43361064,
+                                                "vlan-id-outer": 18962103,
+                                                "is-floating": True,
+                                                "neutron-network-id": "example-neutron-network-id-val-55667",
+                                                "neutron-subnet-id": "example-neutron-subnet-id-val-46585"
+                                            }
+                                        ],
+                                        "l3-interface-ipv6-address-list": [
+                                            {
+                                                "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-74591",
+                                                "l3-interface-ipv6-prefix-length": 38739444,
+                                                "vlan-id-inner": 65048885,
+                                                "vlan-id-outer": 94802338,
+                                                "is-floating": True,
+                                                "neutron-network-id": "example-neutron-network-id-val-64105",
+                                                "neutron-subnet-id": "example-neutron-subnet-id-val-65190"
+                                            }
+                                        ]
+                                    }
+                                ]
+                            }
+                        }
+                    ]
+                }
+            }
+        ]
+    },
+    "flavors": {
+        "flavor": [
+            {
+                "flavor-id": "example-flavor-id-val-92555",
+                "flavor-name": "example-flavor-name-val-35938",
+                "flavor-vcpus": 88056,
+                "flavor-ram": 18804,
+                "flavor-disk": 2575,
+                "flavor-ephemeral": 28190,
+                "flavor-swap": "example-flavor-swap-val-76888",
+                "flavor-is-public": True,
+                "flavor-selflink": "example-flavor-selflink-val-33816",
+                "flavor-disabled": True
+            }
+        ]
+    },
+    "group-assignments": {
+        "group-assignment": [
+            {
+                "group-id": "example-group-id-val-6872",
+                "group-type": "example-group-type-val-64490",
+                "group-name": "example-group-name-val-67702",
+                "group-description": "example-group-description-val-99149"
+            }
+        ]
+    },
+    "snapshots": {
+        "snapshot": [
+            {
+                "snapshot-id": "example-snapshot-id-val-32009",
+                "snapshot-name": "example-snapshot-name-val-47165",
+                "snapshot-architecture": "example-snapshot-architecture-val-84769",
+                "snapshot-os-distro": "example-snapshot-os-distro-val-70763",
+                "snapshot-os-version": "example-snapshot-os-version-val-4220",
+                "application": "example-application-val-12453",
+                "application-vendor": "example-application-vendor-val-95617",
+                "application-version": "example-application-version-val-77699",
+                "snapshot-selflink": "example-snapshot-selflink-val-90202",
+                "prev-snapshot-id": "example-prev-snapshot-id-val-10951"
+            }
+        ]
+    },
+    "images": {
+        "image": [
+            {
+                "image-id": "example-image-id-val-17245",
+                "image-name": "example-image-name-val-93251",
+                "image-architecture": "example-image-architecture-val-21934",
+                "image-os-distro": "example-image-os-distro-val-51699",
+                "image-os-version": "example-image-os-version-val-92745",
+                "application": "example-application-val-47760",
+                "application-vendor": "example-application-vendor-val-67650",
+                "application-version": "example-application-version-val-4499",
+                "image-selflink": "example-image-selflink-val-70348",
+                "metadata": {
+                    "metadatum": [
+                        {
+                            "metaname": "example-metaname-val-57218",
+                            "metaval": "example-metaval-val-39269"
+                        }
+                    ]
+                }
+            }
+        ]
+    },
+    "dvs-switches": {
+        "dvs-switch": [
+            {
+                "switch-name": "example-switch-name-val-31508",
+                "vcenter-url": "example-vcenter-url-val-57139"
+            }
+        ]
+    },
+    "oam-networks": {
+        "oam-network": [
+            {
+                "network-uuid": "example-network-uuid-val-93435",
+                "network-name": "example-network-name-val-66722",
+                "cvlan-tag": 54019733,
+                "ipv4-oam-gateway-address": "example-ipv4-oam-gateway-address-val-3261",
+                "ipv4-oam-gateway-address-prefix-length": 53725
+            }
+        ]
+    },
+    "availability-zones": {
+        "availability-zone": [
+            {
+                "availability-zone-name": "example-availability-zone-name-val-71842",
+                "hypervisor-type": "example-hypervisor-type-val-21339",
+                "operational-status": "example-operational-status-val-18872"
+            }
+        ]
+    },
+    "esr-system-info-list": {
+        "esr-system-info": [
+            {
+                "esr-system-info-id": "example-esr-system-info-id-val-42986",
+                "system-name": "example-system-name-val-1117",
+                "type": "example-type-val-28567",
+                "vendor": "example-vendor-val-99666",
+                "version": "example-version-val-9880",
+                "service-url": "example-service-url-val-95838",
+                "user-name": "example-user-name-val-88013",
+                "password": "example-password-val-51483",
+                "system-type": "example-system-type-val-24554",
+                "protocal": "example-protocal-val-92250",
+                "ssl-cacert": "example-ssl-cacert-val-80275",
+                "ssl-insecure": True,
+                "ip-address": "example-ip-address-val-49558",
+                "port": "example-port-val-55636",
+                "cloud-domain": "example-cloud-domain-val-77975",
+                "default-tenant": "example-default-tenant-val-85499"
+            }
+        ]
+    }
+}
\ No newline at end of file
index d38fb4f..6e79c4d 100644 (file)
@@ -14,7 +14,8 @@
 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, NfVnfmInfoView
+from lcm.ns.vnfs.views import NfView, NfDetailView, NfGrant, LcmNotify, NfScaleView, NfVerifyView, NfVnfmInfoView, \
+    NfVimInfoView
 
 urlpatterns = patterns('',
                        url(r'^api/nslcm/v1/ns/vnfs$', NfView.as_view()),
@@ -26,6 +27,7 @@ urlpatterns = patterns('',
                        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()),
+                       url(r'^api/nslcm/v1/vims/(?P<vimid>[0-9a-zA-Z_-]+)', NfVimInfoView.as_view()),
                        )
 
 urlpatterns = format_suffix_patterns(urlpatterns)
index c3328ff..ea04bdc 100644 (file)
@@ -28,7 +28,7 @@ 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.msapi.extsys import get_vnfm_by_id, get_vim_by_id
 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
 from lcm.pub.utils.values import ignore_case_get
 
@@ -138,3 +138,17 @@ class NfVnfmInfoView(APIView):
             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)
+
+class NfVimInfoView(APIView):
+    def get(self, request, vimid):
+        logger.debug("NfVimInfoView--get::> %s" % vimid)
+        try:
+            vim_info = get_vim_by_id(vimid)
+        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 vim info.'},
+                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        return Response(data=vim_info, status=status.HTTP_200_OK)