bug 585 change charm model to nsr_id. Create/Delete model name 56/7056/12
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 6 Feb 2019 09:21:27 +0000 (09:21 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 10 May 2019 12:20:19 +0000 (12:20 +0000)
Change-Id: Ie8b828b8ff91315fa498395fea68ca8148d9cf1e
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
Dockerfile.local
osm_lcm/lcm.cfg
osm_lcm/lcm.py
osm_lcm/ns.py

index 7c4684f..00f0402 100644 (file)
@@ -57,6 +57,8 @@ ENV OSMLCM_VCA_HOST        vca
 ENV OSMLCM_VCA_PORT:       17070
 ENV OSMLCM_VCA_USER:       admin
 ENV OSMLCM_VCA_SECRET:     secret
+# ENV OSMLCM_VCA_PUBKEY:     pubkey
+# ENV OSMLCM_VCA_CACERT:     cacert
 
 # database
 ENV OSMLCM_DATABASE_DRIVER mongo
index c6123f0..67d3ac9 100644 (file)
@@ -35,7 +35,10 @@ VCA:
     host:   vca
     port:   17070
     user:   admin
-    secret:   secret
+    secret: secret
+    # pubkey: pubkey
+    # cacert: cacert
+
     # loglevel: DEBUG
     # logfile:  /var/log/osm/lcm-vca.log
 
index 11447c2..c4e5eed 100644 (file)
@@ -46,8 +46,8 @@ min_RO_version = [0, 6, 3]
 min_n2vc_version = "0.0.2"
 min_common_version = "0.1.19"
 # uncomment if LCM is installed as library and installed, and get them from __init__.py
-lcm_version = '0.1.36'
-lcm_version_date = '2019-04-22'
+lcm_version = '0.1.37'
+lcm_version_date = '2019-04-30'
 health_check_file = path.expanduser("~") + "/time_last_ping"   # TODO find better location for this file
 
 
index 5d34b05..d6318ad 100644 (file)
@@ -29,7 +29,7 @@ from lcm_utils import LcmException, LcmExceptionNoMgmtIP, LcmBase
 
 from osm_common.dbbase import DbException
 from osm_common.fsbase import FsException
-from n2vc.vnf import N2VC, N2VCPrimitiveExecutionFailed
+from n2vc.vnf import N2VC, N2VCPrimitiveExecutionFailed, NetworkServiceDoesNotExist
 
 from copy import copy, deepcopy
 from http import HTTPStatus
@@ -99,6 +99,8 @@ class NsLcm(LcmBase):
             # it unset and pass it via DeployCharms
             # artifacts=vca_config[''],
             artifacts=None,
+            juju_public_key=vca_config.get('pubkey'),
+            ca_cert=vca_config.get('cacert'),
         )
 
     def vnfd2RO(self, vnfd, new_id=None, additionalParams=None, nsrId=None):
@@ -197,7 +199,8 @@ class NsLcm(LcmBase):
                 if model_name == vca_deployed["model"] and application_name == vca_deployed["application"]:
                     break
             else:
-                self.logger.error(logging_text + " Not present at nsr._admin.deployed.VCA")
+                self.logger.error(logging_text + " Not present at nsr._admin.deployed.VCA. Received model_name={}".
+                                  format(model_name))
                 return
             if task:
                 if task.cancelled():
@@ -675,8 +678,10 @@ class NsLcm(LcmBase):
 
             # Get or generates the _admin.deployed,VCA list
             vca_deployed_list = None
+            vca_model_name = None
             if db_nsr["_admin"].get("deployed"):
                 vca_deployed_list = db_nsr["_admin"]["deployed"].get("VCA")
+                vca_model_name = db_nsr["_admin"]["deployed"].get("VCA-model-name")
             if vca_deployed_list is None:
                 vca_deployed_list = []
                 db_nsr_update["_admin.deployed.VCA"] = vca_deployed_list
@@ -889,7 +894,7 @@ class NsLcm(LcmBase):
 
                 # ns_name will be ignored in the current version of N2VC
                 # but will be implemented for the next point release.
-                model_name = "default"    # TODO bug 585  nsr_id
+                model_name = nsr_id
                 if vdu_id:
                     vdu_id_text = vdu_id + "-"
                 else:
@@ -964,6 +969,13 @@ class NsLcm(LcmBase):
                     proxy_charm = vnf_config["juju"]["charm"]
 
                     if proxy_charm:
+                        if not vca_model_name:
+                            step = "creating VCA model name '{}'".format(nsr_id)
+                            self.logger.debug(logging_text + step)
+                            await self.n2vc.CreateNetworkService(nsr_id)
+                            vca_model_name = nsr_id
+                            db_nsr_update["_admin.deployed.VCA-model-name"] = nsr_id
+                            self.update_db_2("nsrs", nsr_id, db_nsr_update)
                         step = "connecting to N2VC to configure vnf {}".format(vnf_index)
                         vnfr_params["rw_mgmt_ip"] = db_vnfrs[vnf_index]["ip-address"]
                         charm_params = {
@@ -975,6 +987,7 @@ class NsLcm(LcmBase):
                         # Login to the VCA. If there are multiple calls to login(),
                         # subsequent calls will be a nop and return immediately.
                         await self.n2vc.login()
+
                         deploy_charm(vnf_index, None, None, None, charm_params, n2vc_info)
                         number_to_configure += 1
 
@@ -987,6 +1000,12 @@ class NsLcm(LcmBase):
                         proxy_charm = vdu_config["juju"]["charm"]
 
                         if proxy_charm:
+                            if not vca_model_name:
+                                step = "creating VCA model name"
+                                await self.n2vc.CreateNetworkService(nsr_id)
+                                vca_model_name = nsr_id
+                                db_nsr_update["_admin.deployed.VCA-model-name"] = nsr_id
+                                self.update_db_2("nsrs", nsr_id, db_nsr_update)
                             step = "connecting to N2VC to configure vdu {} from vnf {}".format(vdu["id"], vnf_index)
                             await self.n2vc.login()
                             vdur = db_vnfrs[vnf_index]["vdur"][vdu_index]
@@ -1179,7 +1198,21 @@ class NsLcm(LcmBase):
             db_nsr_update["operational-status"] = "terminating"
             db_nsr_update["config-status"] = "terminating"
 
-            if nsr_deployed and nsr_deployed.get("VCA"):
+            if nsr_deployed and nsr_deployed.get("VCA-model-name"):
+                vca_model_name = nsr_deployed["VCA-model-name"]
+                step = "deleting VCA model name '{}' and all charms".format(vca_model_name)
+                self.logger.debug(logging_text + step)
+                try:
+                    await self.n2vc.DestroyNetworkService(vca_model_name)
+                except NetworkServiceDoesNotExist:
+                    pass
+                db_nsr_update["_admin.deployed.VCA-model-name"] = None
+                if nsr_deployed.get("VCA"):
+                    for vca_index in range(0, len(nsr_deployed["VCA"])):
+                        db_nsr_update["_admin.deployed.VCA.{}".format(vca_index)] = None
+                self.update_db_2("nsrs", nsr_id, db_nsr_update)
+            # for backward compatibility if charm have been created with "default"  model name delete one by one
+            elif nsr_deployed and nsr_deployed.get("VCA"):
                 try:
                     step = "Scheduling configuration charms removing"
                     db_nsr_update["detailed-status"] = "Deleting charms"