fix 1023. Issue getting ip from pdu instances 78/8678/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Thu, 12 Mar 2020 17:18:21 +0000 (17:18 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Thu, 12 Mar 2020 23:00:49 +0000 (23:00 +0000)
Change-Id: I003573acf92007aabba1f2c86e3b47234612ea05
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_lcm/ns.py
osm_lcm/tests/test_ns.py

index c9bcc9d..0bee4a1 100644 (file)
@@ -964,12 +964,13 @@ class NsLcm(LcmBase):
                     vdur = next((x for x in get_iterable(db_vnfr, "vdur")
                                  if x.get("vdu-id-ref") == vdu_id and x.get("count-index") == vdu_index), None)
 
+                if not vdur and len(db_vnfr.get("vdur", ())) == 1:  # If only one, this should be the target vdu
+                    vdur = db_vnfr["vdur"][0]
                 if not vdur:
-                    raise LcmException("Not found vnfr_id={}, vdu_index={}, vdu_index={}".format(
-                        vnfr_id, vdu_id, vdu_index
-                    ))
+                    raise LcmException("Not found vnfr_id={}, vdu_id={}, vdu_index={}".format(vnfr_id, vdu_id,
+                                                                                              vdu_index))
 
-                if vdur.get("status") == "ACTIVE":
+                if vdur.get("pdu-type") or vdur.get("status") == "ACTIVE":
                     ip_address = vdur.get("ip-address")
                     if not ip_address:
                         continue
@@ -980,11 +981,12 @@ class NsLcm(LcmBase):
             if not target_vdu_id:
                 continue
 
-            # self.logger.debug(logging_text + "IP address={}".format(ip_address))
-
             # inject public key into machine
             if pub_key and user:
                 # self.logger.debug(logging_text + "Inserting RO key")
+                if vdur.get("pdu-type"):
+                    self.logger.error(logging_text + "Cannot inject ssh-ky to a PDU")
+                    return ip_address
                 try:
                     ro_vm_id = "{}-{}".format(db_vnfr["member-vnf-index-ref"], target_vdu_id)  # TODO add vdu_index
                     result_dict = await self.RO.create_action(
@@ -1802,6 +1804,7 @@ class NsLcm(LcmBase):
                                  exc_info=True)
         finally:
             if exc:
+                instantiated_ok = False
                 if db_nsr:
                     db_nsr_update["detailed-status"] = "ERROR {}: {}".format(step, exc)
                     db_nsr_update["operational-status"] = "failed"
index 8b70003..e54179b 100644 (file)
@@ -507,6 +507,33 @@ class TestMyNS(asynctest.TestCase):
         k8s_instace_info["kdu-model"] = "stable/mongodb"
         self.assertEqual(db_nsr["_admin"]["deployed"]["K8s"][1], k8s_instace_info)
 
+    async def test_instantiate_pdu(self):
+        nsr_id = descriptors.test_ids["TEST-A"]["ns"]
+        nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
+        # Modify vnfd/vnfr to change KDU for PDU. Adding keys that NBI will already set
+        self.db.set_one("vnfrs", {"nsr-id-ref": nsr_id, "member-vnf-index-ref": "1"},
+                        update_dict={"ip-address": "10.205.1.46",
+                                     "vdur.0.pdu-id": "53e1ec21-2464-451e-a8dc-6e311d45b2c8",
+                                     "vdur.0.pdu-type": "PDU-TYPE-1",
+                                     "vdur.0.ip-address": "10.205.1.46",
+                                     },
+                        unset={"vdur.status": None})
+        self.db.set_one("vnfrs", {"nsr-id-ref": nsr_id, "member-vnf-index-ref": "2"},
+                        update_dict={"ip-address": "10.205.1.47",
+                                     "vdur.0.pdu-id": "53e1ec21-2464-451e-a8dc-6e311d45b2c8",
+                                     "vdur.0.pdu-type": "PDU-TYPE-1",
+                                     "vdur.0.ip-address": "10.205.1.47",
+                                     },
+                        unset={"vdur.status": None})
+
+        await self.my_ns.instantiate(nsr_id, nslcmop_id)
+        db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
+        self.assertEqual(db_nsr.get("nsState"), "READY", str(db_nsr.get("errorDescription ")))
+        self.assertEqual(db_nsr.get("currentOperation"), "IDLE", "currentOperation different than 'IDLE'")
+        self.assertEqual(db_nsr.get("currentOperationID"), None, "currentOperationID different than None")
+        self.assertEqual(db_nsr.get("errorDescription "), None, "errorDescription different than None")
+        self.assertEqual(db_nsr.get("errorDetail"), None, "errorDetail different than None")
+
 
 if __name__ == '__main__':
     asynctest.main()