Modifications for test of feature 7953 07/8507/3
authormagnussonl <lars-goran.magnusson@arctoslabs.com>
Tue, 21 Jan 2020 12:00:51 +0000 (13:00 +0100)
committermagnussonl <lars-goran.magnusson@arctoslabs.com>
Fri, 7 Feb 2020 10:49:43 +0000 (11:49 +0100)
Updated after review
Updated after additional feedback

Change-Id: I0552070b9eb650526e0562657d1bd977eb88a489
Signed-off-by: magnussonl <lars-goran.magnusson@arctoslabs.com>
osm_lcm/lcm.py
osm_lcm/ns.py

index 5b77c5c..6897a94 100644 (file)
@@ -286,6 +286,10 @@ class Lcm:
                 except Exception as e:
                     self.logger.error("Cannot write into '{}' for healthcheck: {}".format(health_check_file, e))
             return
+        elif topic == "pla":
+            if command == "placement":
+                self.ns.update_nsrs_with_pla_result(params)
+            return
         elif topic == "k8scluster":
             if command == "create" or command == "created":
                 k8scluster_id = params.get("_id")
@@ -463,7 +467,7 @@ class Lcm:
         self.first_start = True
         while self.consecutive_errors < 10:
             try:
-                topics = ("ns", "vim_account", "wim_account", "sdn", "nsi", "k8scluster", "k8srepo")
+                topics = ("ns", "vim_account", "wim_account", "sdn", "nsi", "k8scluster", "k8srepo", "pla")
                 topics_admin = ("admin", )
                 await asyncio.gather(
                     self.msg.aioread(topics, self.loop, self.kafka_read_callback),
index 43a08f0..e6dec82 100644 (file)
@@ -738,6 +738,9 @@ class NsLcm(LcmBase):
         else:
             timeout_ns_deploy = self.timeout.get("ns_deploy", self.timeout_ns_deploy)
 
+        # Check for and optionally request placement optimization. Database will be updated if placement activated
+        await self.do_placement(logging_text, db_nslcmop, db_vnfrs)
+
         # deploy RO
 
         # get vnfds, instantiate at RO
@@ -1353,6 +1356,37 @@ class NsLcm(LcmBase):
             self.logger.warn('Error writing configuration status={}, ns={}, vca_index={}: {}'
                              .format(status, nsr_id, vca_index, e))
 
+    async def do_placement(self, logging_text, db_nslcmop, db_vnfrs):
+        placement_engine = deep_get(db_nslcmop, ('operationParams', 'placement-engine'))
+        if placement_engine == "PLA":
+            self.logger.debug(logging_text + "Invoke placement optimization for nslcmopId={}".format(db_nslcmop['id']))
+            await self.msg.aiowrite("pla", "get_placement", {'nslcmopId': db_nslcmop['_id']}, loop=self.loop)
+            db_poll_interval = 5
+            wait = db_poll_interval * 4
+            pla_result = None
+            while not pla_result and wait >= 0:
+                await asyncio.sleep(db_poll_interval)
+                wait -= db_poll_interval
+                db_nslcmop = self.db.get_one("nslcmops", {"_id": db_nslcmop["_id"]})
+                pla_result = deep_get(db_nslcmop, ('_admin', 'pla'))
+
+            if not pla_result:
+                raise LcmException("Placement timeout for nslcmopId={}".format(db_nslcmop['id']))
+
+            for pla_vnf in pla_result['vnf']:
+                vnfr = db_vnfrs.get(pla_vnf['member-vnf-index'])
+                if not pla_vnf.get('vimAccountId') or not vnfr:
+                    continue
+                self.db.set_one("vnfrs", {"_id": vnfr["_id"]}, {"vim-account-id": pla_vnf['vimAccountId']})
+        return
+
+    def update_nsrs_with_pla_result(self, params):
+        try:
+            nslcmop_id = deep_get(params, ('placement', 'nslcmopId'))
+            self.update_db_2("nslcmops", nslcmop_id, {"_admin.pla": params.get('placement')})
+        except Exception as e:
+            self.logger.warn('Update failed for nslcmop_id={}:{}'.format(nslcmop_id, e))
+
     async def instantiate(self, nsr_id, nslcmop_id):
         """