Whamcloud - gitweb
EX-3846 lipe: backport lpcc script to python2
authorLei Feng <flei@whamcloud.com>
Wed, 22 Sep 2021 05:45:00 +0000 (01:45 -0400)
committerLi Xi <lixi@ddn.com>
Fri, 24 Sep 2021 13:30:49 +0000 (13:30 +0000)
Since python2 is used by all other scripts in lipe,
backport lpcc to python2 too.

Change-Id: I5cffef7f4a38fe32ad071070076643814ca53736
Signed-off-by: Lei Feng <flei@whamcloud.com>
Test-Parameters: trivial testlist=sanity-pcc env=ONLY=200-202,ONLY_REPEAT=50 \
                 clientextra_install_params="--packages lipe-lpcc"
Reviewed-on: https://review.whamcloud.com/45015
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
lipe/lpcc

index 765da83..67ab790 100755 (executable)
--- a/lipe/lpcc
+++ b/lipe/lpcc
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python2
 # Copyright (c) 2021 DataDirect Networks, Inc.
 # All Rights Reserved.
 # Author: flei@ddn.com
@@ -7,6 +7,8 @@
 Manage all PCC devices and services
 """
 
+from __future__ import print_function
+
 import argparse
 import errno
 import json
@@ -70,8 +72,8 @@ class LpccService:
         """
         cmdline = ['pkill', '--signal', '0', '--pidfile', pidfile, '--', procname]
         eprint(cmdline)
-        cproc = subprocess.run(cmdline, check=False, stderr=subprocess.DEVNULL)
-        if cproc.returncode != 0:
+        returncode = subprocess.call(cmdline)
+        if returncode != 0:
             return False
 
         return True
@@ -96,8 +98,8 @@ class LpccService:
         """
         cmdline = ['pkill', '--pidfile', pidfile, '--', procname]
         eprint(cmdline)
-        cproc = subprocess.run(cmdline, check=False)
-        return cproc.returncode
+        returncode = subprocess.call(cmdline)
+        return returncode
 
     def _add_pcc(self):
         eprint("Adding PCC...")
@@ -106,15 +108,15 @@ class LpccService:
         cmdline = ['lctl', 'pcc', 'add', self.lpcc_mount, self.lpcc_cache, \
                    '--param', param]
         eprint(cmdline)
-        cproc = subprocess.run(cmdline, check=False)
-        return cproc.returncode
+        returncode = subprocess.call(cmdline)
+        return returncode
 
     def _del_pcc(self):
         eprint("Deleting PCC...")
         cmdline = ['lctl', 'pcc', 'del', self.lpcc_mount, self.lpcc_cache]
         eprint(cmdline)
-        cproc = subprocess.run(cmdline, check=False)
-        return cproc.returncode
+        returncode = subprocess.call(cmdline)
+        return returncode
 
     def _start_lpcc_purge(self):
         eprint("Starting lpcc_purge...")
@@ -152,7 +154,7 @@ class LpccService:
     def _stats_lpcc_purge(self):
         pidfile = '/var/run/lpcc_purge-%d.pid' % self.lpcc_roid
         cmdline = ['pkill', '--signal', 'USR1', '--pidfile', pidfile, '--', 'lpcc_purge']
-        subprocess.run(cmdline, check=True)
+        subprocess.call(cmdline)
 
         statsfile = '/var/run/lpcc_purge-%d.stats' % self.lpcc_roid
         stats_obj = None
@@ -417,7 +419,7 @@ class LpccMonitor:
         try:
             conn, _ = LISTEN_SOCK.accept()
             request_str = conn.makefile().readline()
-            request = json.loads(request_str)
+            request = yaml.safe_load(request_str)
         except Exception as ex:
             eprint(ex)
 
@@ -426,8 +428,8 @@ class LpccMonitor:
         eprint("Response:", response)
 
         try:
-            conn.send(bytes(json.dumps(response), encoding='utf-8'))
-            conn.close()
+            conn.sendall(json.dumps(response))
+            conn.shutdown(socket.SHUT_WR)
         except Exception as ex:
             eprint(ex)
 
@@ -455,6 +457,8 @@ class LpccMonitor:
                 break
             except ValueError:
                 break
+            except select.error:
+                break
 
             if LISTEN_SOCK in rset:
                 self._serve_cmd()
@@ -491,12 +495,12 @@ class LpccCli:
                 "please check whether the monitor service started!")
             sys.exit(1)
 
-        sock.sendall(bytes(json.dumps(cmd), encoding='utf-8'))
+        sock.sendall(json.dumps(cmd))
         sock.shutdown(socket.SHUT_WR)
         response = sock.makefile().readline()
         sock.close()
 
-        return json.loads(response)
+        return yaml.safe_load(response)
 
 
 def sigint_handler(signum, frame):
@@ -505,7 +509,7 @@ def sigint_handler(signum, frame):
     """
     #pylint: disable=unused-argument
     # close the listen socket to notify the monitor service to exit
-    eprint("Received signal %s" % signal.Signals(signum).name)
+    eprint("Received signal %d" % signum)
     LISTEN_SOCK.close()
 
 def main():