Whamcloud - gitweb
EX-5347 lipe: update lpcc to python3
authorJohn L. Hammond <jhammond@whamcloud.com>
Wed, 8 Jun 2022 22:29:55 +0000 (15:29 -0700)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 10 Jun 2022 22:40:48 +0000 (22:40 +0000)
Update the lpcc utility to use python 3.

Test-Parameters: trivial clientdistro=ubuntu2204 env=SANITY_PCC_EXCEPT="15 16 27 39 101a 201" testlist=sanity-pcc
Test-Parameters: trivial clientdistro=ubuntu2004 env=SANITY_PCC_EXCEPT="101a" testlist=sanity-pcc
Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Signed-off-by: Lei Feng <flei@whamcloud.com>
Change-Id: I690ef4362cbdd0118419ab37a15127619a860178
Reviewed-on: https://review.whamcloud.com/47553
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lipe/debian/control
lipe/debian/control.main
lipe/lpcc

index 39ae314..292be7a 100644 (file)
@@ -12,5 +12,5 @@ Package: lipe-lpcc
 Section: utils
 Architecture: all
 Priority: optional
-Depends: ${shlibs:Depends}, ${misc:Depends}, e2fsprogs (>= 1.42.13.wc6), python-yaml
+Depends: ${shlibs:Depends}, ${misc:Depends}, e2fsprogs (>= 1.42.13.wc6), python3-yaml
 Description: Tools for LPCC (Lustre Persisted Client Cache)
index 39ae314..292be7a 100644 (file)
@@ -12,5 +12,5 @@ Package: lipe-lpcc
 Section: utils
 Architecture: all
 Priority: optional
-Depends: ${shlibs:Depends}, ${misc:Depends}, e2fsprogs (>= 1.42.13.wc6), python-yaml
+Depends: ${shlibs:Depends}, ${misc:Depends}, e2fsprogs (>= 1.42.13.wc6), python3-yaml
 Description: Tools for LPCC (Lustre Persisted Client Cache)
index 05a8a7a..462efff 100755 (executable)
--- a/lipe/lpcc
+++ b/lipe/lpcc
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # Copyright (c) 2021 DataDirect Networks, Inc.
 # All Rights Reserved.
 # Author: flei@ddn.com
@@ -7,7 +7,6 @@
 Manage all PCC devices and services
 """
 
-from __future__ import print_function
 
 import argparse
 import errno
@@ -218,7 +217,7 @@ class LpccService:
 
         cmdline = ['lctl', 'pcc', 'list', self.lpcc_mount]
         try:
-            output = subprocess.check_output(cmdline)
+            output = subprocess.check_output(cmdline).decode()
         except subprocess.CalledProcessError as err:
             result['status'] = "error"
             result['error_msg'] = os.strerror(err.returncode)
@@ -388,13 +387,13 @@ class LpccMonitor:
         result = {}
 
         try:
-            fsname = subprocess.check_output(['lfs', 'getname', mount]).split()[0]
+            fsname = subprocess.check_output(['lfs', 'getname', mount]).split()[0].decode()
         except subprocess.CalledProcessError as err:
             result['error_msg'] = os.strerror(err.returncode)
             return result
 
         cmdline = ['lctl', 'get_param', '-n', 'llite.%s.stats' % fsname]
-        output = subprocess.check_output(cmdline)
+        output = subprocess.check_output(cmdline).decode()
         for line in output.splitlines():
             words = line.split()
             if (words[0] == "open"):
@@ -445,13 +444,13 @@ class LpccMonitor:
         groups = {}
         for lpcc_status in status_list:
             mount = lpcc_status['mount']
-            if groups.has_key(mount):
+            if mount in groups:
                 groups[mount]['pcc'].append(lpcc_status)
             else:
                 groups[mount] = {}
                 groups[mount]['pcc'] = [lpcc_status,]
 
-        for mount in groups.keys():
+        for mount in groups:
             fs_stats = self._get_fs_stats(mount)
             groups[mount]['fs_stats'] = fs_stats
 
@@ -507,7 +506,7 @@ class LpccMonitor:
         eprint("Response:", response)
 
         try:
-            conn.sendall(json.dumps(response))
+            conn.sendall(json.dumps(response).encode())
             conn.shutdown(socket.SHUT_WR)
         except Exception as ex:
             eprint(ex)
@@ -574,7 +573,7 @@ class LpccCli:
                 "please check whether the monitor service started!")
             sys.exit(1)
 
-        sock.sendall(json.dumps(cmd))
+        sock.sendall(json.dumps(cmd).encode())
         sock.shutdown(socket.SHUT_WR)
         response = sock.makefile().readline()
         sock.close()