CLI: add stop return value and timeout 60/160660/4
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 16 Nov 2017 20:21:10 +0000 (23:21 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Fri, 8 Dec 2017 09:14:17 +0000 (09:14 +0000)
If nc finished during timeout True return, False otherwise

Change-Id: Iae6ae93a11efe095c9e972c207ca526115046e49
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
src/cli/swap_cli/nc.py
src/cli/swap_cli/swap.py

index 1bbb64e..94cb2a8 100644 (file)
@@ -51,12 +51,14 @@ class NetCat:
         self.__nc_t.setDaemon(True)
         self.__nc_t.start()
 
-    def stop(self):
+    def stop(self, timeout):
         self.__nc_t.join(1)
-        for i in range(30):
+        for i in range(timeout):
             if self.__nc_t.isAlive():
-                logging.warning('nc is still running  # %ds', i)
+                logging.debug('nc is still running  # %ds', i)
                 time.sleep(1)
             else:
                 logging.info('nc closed')
-                break
+                return True
+
+        return False
index e3e77d4..e3882ea 100644 (file)
@@ -183,12 +183,22 @@ class Client(object):
         return self.__commands.keep_alive()
 
 
-    def stop(self):
+    def stop(self, timeout=30):
         '''
         Stop profiling
+        :param timeout: timeout for handling stop message
+        :type timeout: seconds (default 30)
+
+        :return: True if SWAP has been stopped, False otherwise
+        :rtype: bool
         '''
         logging.debug('stop() called')
         self.__commands.swap_inst_remove()
         self.__commands.stop()
         self.__disconnect()
-        self.__trace.stop()
+
+        ret = self.__trace.stop(timeout)
+        if ret is False:
+            logging.warning('SWAP is still running')
+
+        return ret