Modify test case of apply_grant
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / vnfs / vnf_create / create_vnf_identifier.py
index 96ab163..580c531 100644 (file)
@@ -17,7 +17,9 @@ import uuid
 
 from lcm.pub.database.models import NfInstModel
 from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get
+from lcm.pub.msapi.catalog import query_rawdata_from_catalog
+from lcm.pub.msapi.nfvolcm import get_packageinfo_by_vnfdid
+from lcm.pub.utils import toscautil
 from lcm.pub.utils.timeutil import now_time
 from lcm.pub.utils.values import ignore_case_get
 
@@ -30,6 +32,9 @@ class CreateVnf:
         self.vnfd_id = ignore_case_get(self.data, "vnfdId")
         self.vnf_instance_mame = ignore_case_get(self.data, "vnfInstanceName")
         self.description = ignore_case_get(self.data, "vnfInstanceDescription")
+        self.package_info = ''
+        self.package_id = ''
+        self.csar_id = ''
 
     def do_biz(self):
         logger.debug("CreateVnfIdentifier--CreateVnf::> %s" % self.data)
@@ -38,24 +43,28 @@ class CreateVnf:
         if is_exist:
             raise NFLCMException('VNF is already exist.')
 
-        ret = vnfd_rawdata_get(self.vnfd_id)
-        if ret[0] != 0:
-            raise NFLCMException('Get vnfd data failed.')
-        vnfd_info = json.JSONDecoder().decode(ret[1])
-        vnfd_version = vnfd_info['metadata']['vnfd_version']
-        vendor = vnfd_info['metadata']['vendor']
-        producttype = vnfd_info['metadata']['domain_type']
-        netype = vnfd_info['metadata']['vnf_type']
-        vnfd_model = vnfd_info
-        vnfsoftwareversion = vnfd_info['metadata']['version']
+        # get package_info from nslcm by vnfd_id
+        self.package_info = get_packageinfo_by_vnfdid(self.vnfd_id)
+        self.package_id = ignore_case_get(self.package_info, "package_id")
+        self.csar_id = ignore_case_get(self.package_info, "csar_id")
+
+        # get rawdata from catalog by csar_id
+        raw_data = query_rawdata_from_catalog(self.csar_id, self.data)
+        self.vnfd = toscautil.convert_vnfd_model(raw_data["rawData"])  # convert to inner json
+        self.vnfd = json.JSONDecoder().decode(self.vnfd)
+
+        metadata = ignore_case_get(self.vnfd, "metadata")
+        version = ignore_case_get(metadata, "vnfd_version")
+        vendor = ignore_case_get(metadata, "vendor")
+        netype = ignore_case_get(metadata, "vnf_type")
+        vnfsoftwareversion = ignore_case_get(metadata, "version")
+        vnfd_model = self.vnfd
 
         nf_inst_id = str(uuid.uuid4())
-        NfInstModel.objects.create(nfinstid=nf_inst_id, mnfinstid=nf_inst_id, nf_name=self.vnf_instance_mame,
-                                   package_id='todo', vnfm_inst_id='todo', version=vnfd_version, vendor=vendor,
-                                   producttype=producttype, netype=netype, vnfd_model=vnfd_model,
-                                   instantiationState='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id,
-                                   vnfSoftwareVersion=vnfsoftwareversion, vnfConfigurableProperties='todo',
-                                   localizationLanguage='EN_US', create_time=now_time())
+        NfInstModel.objects.create(nfinstid=nf_inst_id, nf_name=self.vnf_instance_mame, package_id=self.package_id,
+                                   version=version, vendor=vendor, netype=netype, vnfd_model=vnfd_model,
+                                   status='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id,
+                                   vnfSoftwareVersion=vnfsoftwareversion, create_time=now_time())
         vnf_inst = NfInstModel.objects.get(nfinstid=nf_inst_id)
         logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s]' %
                      (vnf_inst.nfinstid, vnf_inst.nf_name, vnf_inst.vnfdid, vnf_inst.nf_desc, vnf_inst.create_time))