bug 760 skip get-ssh-public-key,generate-ssh-key,verify-ssh-credentials methods for... 53/7753/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Thu, 4 Jul 2019 17:17:06 +0000 (17:17 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 5 Jul 2019 15:15:59 +0000 (15:15 +0000)
Change-Id: I597c66df8c56662f15f8949e4a10aa73f7f5d4ac
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_lcm/ns.py

index a04f0a8..d2724a0 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, NetworkServiceDoesNotExist
+from n2vc.vnf import N2VC, N2VCPrimitiveExecutionFailed, NetworkServiceDoesNotExist, PrimitiveDoesNotExist
 
 from copy import copy, deepcopy
 from http import HTTPStatus
@@ -933,17 +933,28 @@ class NsLcm(LcmBase):
                                        .format(vca_deployed["member-vnf-index"],
                                                vca_deployed["vdu_id"])
                                 self.logger.debug(logging_text + step)
-                                primitive_id = await self.n2vc.ExecutePrimitive(
-                                    vca_deployed["model"],
-                                    vca_deployed["application"],
-                                    "get-ssh-public-key",
-                                    None,
-                                )
-                                vca_deployed["step"] = db_nsr_update[database_entry + "step"] = "get-ssh-public-key"
-                                vca_deployed["primitive_id"] = db_nsr_update[database_entry + "primitive_id"] =\
-                                    primitive_id
-                                db_nsr_update[database_entry + "operational-status"] =\
-                                    vca_deployed["operational-status"]
+                                try:
+                                    primitive_id = await self.n2vc.ExecutePrimitive(
+                                        vca_deployed["model"],
+                                        vca_deployed["application"],
+                                        "get-ssh-public-key",
+                                        None,
+                                    )
+                                    vca_deployed["step"] = db_nsr_update[database_entry + "step"] = "get-ssh-public-key"
+                                    vca_deployed["primitive_id"] = db_nsr_update[database_entry + "primitive_id"] =\
+                                        primitive_id
+                                    db_nsr_update[database_entry + "operational-status"] =\
+                                        vca_deployed["operational-status"]
+                                except PrimitiveDoesNotExist:
+                                    ssh_public_key = None
+                                    vca_deployed["step"] = db_nsr_update[database_entry + "step"] =\
+                                        "ssh-public-key-obtained"
+                                    vca_deployed["ssh-public-key"] = db_nsr_update[database_entry + "ssh-public-key"] =\
+                                        ssh_public_key
+                                    step = "charm ssh-public-key for  member_vnf_index={} vdu_id={} not needed".format(
+                                        vca_deployed["member-vnf-index"], vca_deployed["vdu_id"])
+                                    self.logger.debug(logging_text + step)
+
                         elif vca_deployed["step"] in ("get-ssh-public-key", "retry-get-ssh-public-key"):
                             primitive_id = vca_deployed["primitive_id"]
                             primitive_status = await self.n2vc.GetPrimitiveStatus(vca_deployed["model"],
@@ -1230,7 +1241,7 @@ class NsLcm(LcmBase):
 
                 # add primitive verify-ssh-credentials to the list after config only when is a vnf or vdu charm
                 initial_config_primitive_list = initial_config_primitive_list.copy()
-                if initial_config_primitive_list and vnf_index:
+                if initial_config_primitive_list and vnf_index and vca_deployed.get("ssh-public-key"):
                     initial_config_primitive_list.insert(1, {"name": "verify-ssh-credentials", "parameter": []})
 
                 for initial_config_primitive in initial_config_primitive_list: