overlord: Add TrackConnection flag

We want to track connection even it's disconnected when we want to do
so. For the sake of this, we need a flag stored in overlord server, and
it can be controlled from ghost client.

We'll use this flag in the following CLs.

BUG=b:172784970
TEST=`ghost --track-connection y`
     1. (in dut) print correct log
     2. Use `docker logs {overlord container name} -f` shows correct log

Change-Id: Ic1f5e774ca79d0cb5f888c4d73d2dcf56dcfc985
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory/+/2530866
Reviewed-by: Cheng Yueh <cyueh@chromium.org>
Tested-by: Yilin Yang (kerker) <kerker@chromium.org>
Commit-Queue: Yilin Yang (kerker) <kerker@chromium.org>
diff --git a/py/tools/ghost.py b/py/tools/ghost.py
index c841a16..f6f4c49 100755
--- a/py/tools/ghost.py
+++ b/py/tools/ghost.py
@@ -1187,6 +1187,15 @@
 
     self.SendRequest('update_dut_data', data)
 
+  def TrackConnection(self, enabled, timeout_secs):
+    logging.info('TrackConnection, enabled = %s, timeout_secs = %d', enabled,
+                 timeout_secs)
+
+    self.SendRequest('track_connection', {
+        'enabled': enabled,
+        'timeout_secs': timeout_secs
+    })
+
   def GetStatus(self):
     status = self._register_status
     if self._register_status == SUCCESS:
@@ -1256,6 +1265,7 @@
     rpc_server.register_function(self.GetStatus, 'GetStatus')
     rpc_server.register_function(self.RegisterTTY, 'RegisterTTY')
     rpc_server.register_function(self.RegisterSession, 'RegisterSession')
+    rpc_server.register_function(self.TrackConnection, 'TrackConnection')
     rpc_server.register_function(self.AddToDownloadQueue, 'AddToDownloadQueue')
     t = threading.Thread(target=rpc_server.serve_forever)
     t.daemon = True
@@ -1415,6 +1425,12 @@
   parser.add_argument('--status', dest='status', default=False,
                       action='store_true',
                       help='show status of the client')
+  parser.add_argument('--track-connection', dest='track_connection',
+                      default=None, choices=('y', 'n'),
+                      help="specify 'y' or 'n' to track connection or not")
+  parser.add_argument('--timeout-seconds', dest='timeout_secs', type=int,
+                      default=900,
+                      help='timeout seconds when track the connection')
   parser.add_argument('overlord_ip', metavar='OVERLORD_IP', type=str, nargs='*',
                       help='overlord server address')
   args = parser.parse_args()
@@ -1434,6 +1450,11 @@
     GhostRPCServer().SendData()
     sys.exit()
 
+  if args.track_connection:
+    GhostRPCServer().TrackConnection(args.track_connection == 'y',
+                                     args.timeout_secs)
+    sys.exit()
+
   if args.download:
     DownloadFile(args.download)