fix tests for feature7928 88/8188/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 18 Nov 2019 17:33:27 +0000 (17:33 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 18 Nov 2019 17:33:27 +0000 (17:33 +0000)
Change-Id: I04d29b563123637cf52d69e756fade1f0bb8aaa6
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_lcm/ns.py
osm_lcm/tests/test_ns.py

index 2c603f4..ce5dcf3 100644 (file)
@@ -138,23 +138,23 @@ class NsLcm(LcmBase):
                           .format(table, filter, path, updated_data))
 
         # write NS status to database
-        try:
-            nsrs_id = filter.get('_id')
-            # get ns record
-            nsr = self.db.get_one(table=table, q_filter=filter)
-            # get VCA deployed list
-            vca_list = deep_get(target_dict=nsr, key_list=('_admin', 'deployed', 'VCA'))
-            # get RO deployed
-            ro_list = deep_get(target_dict=nsr, key_list=('_admin', 'deployed', 'RO'))
-            for vca in vca_list:
-                status = vca.get('status')
-                detailed_status = vca.get('detailed-status')
-            for ro in ro_list:
-                pass
-
-        except Exception as e:
-            self.logger.error('_on_update_n2vc_db(table={},filter={},path={},updated_data={}) Error updating db: {}'
-                          .format(table, filter, path, updated_data, e))
+        try:
+        #     # nsrs_id = filter.get('_id')
+            # get ns record
+            nsr = self.db.get_one(table=table, q_filter=filter)
+            # get VCA deployed list
+            vca_list = deep_get(target_dict=nsr, key_list=('_admin', 'deployed', 'VCA'))
+            # get RO deployed
+            ro_list = deep_get(target_dict=nsr, key_list=('_admin', 'deployed', 'RO'))
+            for vca in vca_list:
+                status = vca.get('status')
+                detailed_status = vca.get('detailed-status')
+            for ro in ro_list:
+                pass
+        #
+        except Exception as e:
+            self.logger.error('_on_update_n2vc_db(table={},filter={},path={},updated_data={}) Error updating db: {}'
+        #                       .format(table, filter, path, updated_data, e))
 
     def vnfd2RO(self, vnfd, new_id=None, additionalParams=None, nsrId=None):
         """
@@ -1673,6 +1673,7 @@ class NsLcm(LcmBase):
         db_nslcmop_update = {}
         nslcmop_operation_state = None
         autoremove = False  # autoremove after terminated
+        pending_tasks = []
         try:
             # wait for any previous tasks in process
             await self.lcm_tasks.waitfor_related_HA("ns", 'nslcmops', nslcmop_id)
@@ -1690,8 +1691,6 @@ class NsLcm(LcmBase):
             # Call internal terminate action
             await self._terminate_action(db_nslcmop, nslcmop_id, nsr_id)
 
-            pending_tasks = []
-
             db_nsr_update["operational-status"] = "terminating"
             db_nsr_update["config-status"] = "terminating"
 
@@ -1923,7 +1922,7 @@ class NsLcm(LcmBase):
         return calculated_params
 
     async def _ns_execute_primitive(self, db_deployed, member_vnf_index, vdu_id, vdu_name, vdu_count_index,
-                                    primitive, primitive_params, retries=0, retries_interval=30) -> str, str:
+                                    primitive, primitive_params, retries=0, retries_interval=30) -> (str, str):
 
         # find vca_deployed record for this action
         try:
@@ -1962,13 +1961,13 @@ class NsLcm(LcmBase):
                     # execution was OK
                     break
                 except Exception as e:
-                    self.logger.debug('Error executing action {} on {} -> {}'.format(primitive, ee_id, e))
                     retries -= 1
                     if retries >= 0:
+                        self.logger.debug('Error executing action {} on {} -> {}'.format(primitive, ee_id, e))
                         # wait and retry
                         await asyncio.sleep(retries_interval, loop=self.loop)
-            else:
-                return 'Cannot execute action {} on {}: {}'.format(primitive, ee_id, e), 'FAIL'
+                    else:
+                        return 'Cannot execute action {} on {}: {}'.format(primitive, ee_id, e), 'FAIL'
 
             return output, 'OK'
 
index 07cc1a1..0e842cb 100644 (file)
@@ -980,7 +980,7 @@ class TestMyNS(asynctest.TestCase):
             yield "app_name-{}".format(num_calls)
             num_calls += 1
 
-    def _n2vc_CreateExecutionEnvironment(self, namespace):
+    def _n2vc_CreateExecutionEnvironment(self, namespace, reuse_ee_id, db_dict):
         k_list = namespace.split(".")
         ee_id = k_list[1] + "."
         if len(k_list) >= 2:
@@ -988,7 +988,7 @@ class TestMyNS(asynctest.TestCase):
                 ee_id += k[:8]
         else:
             ee_id += "_NS_"
-        return ee_id
+        return ee_id, {}
 
     def _ro_show(self, *args, **kwargs):
         ro_ns_desc = yaml.load(ro_ns_text)
@@ -1074,13 +1074,16 @@ class TestMyNS(asynctest.TestCase):
             # allow several versions of n2vc
             self.my_ns.n2vc.FormatApplicationName = asynctest.Mock(side_effect=self._n2vc_FormatApplicationName())
             self.my_ns.n2vc.DeployCharms = asynctest.CoroutineMock(side_effect=self._n2vc_DeployCharms)
-            self.my_ns.n2vc.CreateExecutionEnvironment = asynctest.CoroutineMock(
+            self.my_ns.n2vc.create_execution_environment = asynctest.CoroutineMock(
                 side_effect=self._n2vc_CreateExecutionEnvironment)
-            self.my_ns.n2vc.InstallConfigurationSW = asynctest.CoroutineMock(return_value=pub_key)
-            self.my_ns.n2vc.ExecutePrimitive = asynctest.CoroutineMock(side_effect=self._return_uuid)
+            self.my_ns.n2vc.install_configuration_sw = asynctest.CoroutineMock(return_value=pub_key)
+            self.my_ns.n2vc.get_ee_ssh_public__key = asynctest.CoroutineMock(return_value=pub_key)
+            self.my_ns.n2vc.exec_primitive = asynctest.CoroutineMock(side_effect=self._return_uuid)
             self.my_ns.n2vc.GetPrimitiveStatus = asynctest.CoroutineMock(return_value="completed")
             self.my_ns.n2vc.GetPrimitiveOutput = asynctest.CoroutineMock(return_value={"result": "ok",
                                                                                        "pubkey": pub_key})
+            self.my_ns.n2vc.get_public_key = asynctest.CoroutineMock(
+                return_value=getenv("OSMLCM_VCA_PUBKEY", "public_key"))
 
         # Mock RO
         if not getenv("OSMLCMTEST_RO_NOMOCK"):