Skip to contentSkip to conversation

merge python3 patch from fedora nfsometer package

PATCH In review Jianhong Yin 2 participants 2 messages Oct 18, 2022 – Oct 19, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 merge python3 patch from fedora nfsometer package

see: https://src.fedoraproject.org/rpms/nfsometer/tree/rawhide

nfsometer upstream can not work on latest linux with python3, just copy the python3 patch from fedora nfsometer pkg back to upstream

---
 README                     |  17 +++--
 nfsometer.py               |  23 +++----
 nfsometerlib/cmd.py        |  12 ++--
 nfsometerlib/collection.py |  76 +++++++++++----------
 nfsometerlib/config.py     |  10 +--
 nfsometerlib/graph.py      |  46 ++++++-------
 nfsometerlib/options.py    |  35 +++++-----
 nfsometerlib/parse.py      | 131 +++++++++++++++++++------------------
 nfsometerlib/report.py     |  82 +++++++++++++----------
 nfsometerlib/selector.py   |  34 ++++++----
 nfsometerlib/trace.py      | 103 +++++++++++++++--------------
 nfsometerlib/workloads.py  |  47 ++++++-------
 setup.py                   |   8 +--
 13 files changed, 330 insertions(+), 294 deletions(-)
README +10 -7
index 750db9e..f9cdacf 100644
@@ -17,15 +17,18 @@ Dependencies
   nfsometer depends on several third-party packages and will not run without
   them installed.
 
-   - matplotlib - used for graph plotting
-   - numpy      - used by matplotlib, stats functions
-   - mako       - used for html templating of reports
-   - nfs-utils  - mount.nfs, mountstats, etc
-   - time       - /bin/time
+   - python3-setuptools - as you known
+   - python3-matplotlib - used for graph plotting
+   - python3-numpy      - used by matplotlib, stats functions
+   - python3-mako       - used for html templating of reports
+   - python3-devel      - used for build from source code
+   - nfs-utils          - mount.nfs, mountstats, etc
+   - time               - /bin/time
+   - filebench          - /usr/bin/filebench
 
   On a fedora system the following command will install these packages:
 
-  # sudo yum install python-matplotlib numpy python-mako nfs-utils time
+  # sudo yum install python3-{setuptools,matplotlib,numpy,mako,devel} nfs-utils time filebench
 
   Other distros will have a similar command.
 
@@ -40,7 +43,7 @@ Installation
   nfsometer can also be installed to standard python site-packages and
   executable directories (must be run as root):
 
-  # python setup.py install
+  # python3 setup.py install
   # nfsometer --help
 
 
nfsometer.py +12 -11
index cbd544b..9dd2faa 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Copyright 2012 NetApp, Inc. All Rights Reserved,
 contribution by Weston Andros Adamson <[email protected]>
@@ -15,6 +15,7 @@ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 import posix
 import sys
 import os
+import six
 
 from nfsometerlib import trace
 from nfsometerlib import options
@@ -46,19 +47,19 @@ def mode_notes(opts):
     collection = TraceCollection(opts.resultdir)
     collection.notes_edit()
 
-    print 'Saved notes for results %s' % (opts.resultdir)
+    print('Saved notes for results %s' % (opts.resultdir))
 
 def mode_list(opts):
     collection = TraceCollection(opts.resultdir)
 
-    print 'Result directory \'%s\' contains:\n\n%s' % \
-        (opts.resultdir, '\n'.join(collection.show_contents(pre='')))
+    print('Result directory \'%s\' contains:\n\n%s' % \
+        (opts.resultdir, '\n'.join(collection.show_contents(pre=''))))
 
 def mode_workloads(opts):
-    print "Available workloads:"
-    print "  %s" % '\n  '.join(available_workloads())
-    print "Unavailable workloads:"
-    print "  %s" % '\n  '.join(unavailable_workloads())
+    print("Available workloads:")
+    print("  %s" % '\n  '.join(available_workloads()))
+    print("Unavailable workloads:")
+    print("  %s" % '\n  '.join(unavailable_workloads()))
 
 def mode_loadgen(opts):
     # XXX check idle?
@@ -75,7 +76,7 @@ def mode_fetch_trace(opts, fetch_only=False):
     check_idle_before_start(opts)
     collection = TraceCollection(opts.resultdir)
     trace.run_traces(collection, opts, fetch_only=fetch_only)
-    print
+    print('')
 
 def mode_report(opts):
     collection = TraceCollection(opts.resultdir)
@@ -83,7 +84,7 @@ def mode_report(opts):
         rpt = ReportSet(collection, opts.serial_graph_gen)
         rpt.generate_reports()
     else:
-        print "No tracedirs found"
+        print("No tracedirs found")
 
 def main():
     opts = options.Options()
@@ -129,5 +130,5 @@ if __name__ == '__main__':
     try:
         main()
     except KeyboardInterrupt:
-        print >>sys.stderr, "\nCancelled by user...\n"
+        six.print_("\nCancelled by user...\n", file=sys.stderr)
 
nfsometerlib/cmd.py +7 -5
index a2ebcef..32ddcd0 100644
@@ -12,9 +12,9 @@ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 """
 
 import os
-import posix
 import sys
 import subprocess
+import six
 
 # command wrappers
 def simplecmd(args):
@@ -41,11 +41,11 @@ class CmdErrorOut(CmdError):
 def cmd(args, raiseerrorcode=True, raiseerrorout=True, instr='',
         env=None, pass_output=False):
 
-    #print "command> %s" % args
+    #print("command> %s" % args)
 
     if env:
-        curenv = dict(posix.environ)
-        for k,v in env.iteritems():
+        curenv = dict(os.environ)
+        for k,v in six.iteritems(env):
             curenv[k] = v
         env = curenv
 
@@ -82,11 +82,13 @@ def cmd(args, raiseerrorcode=True, raiseerrorout=True, instr='',
                             (args, errstr))
 
     if outstr:
-        o_str = outstr.split('\n')
+        o_str = outstr.decode('utf-8').split('\n')
     else:
         o_str = ''
 
     if errstr:
+        if isinstance(errstr, six.binary_type):
+          errstr = errstr.decode('utf-8')
         e_str = errstr.split('\n')
     else:
         e_str = ''
nfsometerlib/collection.py +41 -35

241 lines not on this page · raw message

nfsometerlib/config.py +5 -5
index 76d74d9..8439c44 100644
@@ -12,7 +12,7 @@ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 """
 
 import re
-import os, posix, stat, sys
+import os, stat, sys
 import socket
 
 NFSOMETER_VERSION='1.9'
@@ -20,7 +20,7 @@ NFSOMETER_VERSION='1.9'
 NFSOMETER_MANPAGE='nfsometer.1'
 
 NFSOMETERLIB_DIR=os.path.split(__file__)[0]
-NFSOMETER_DIR=os.path.join(posix.environ['HOME'], '.nfsometer')
+NFSOMETER_DIR=os.path.join(os.environ['HOME'], '.nfsometer')
 
 
 #
@@ -47,7 +47,7 @@ TRACE_LOADGEN_STAGGER_MAX = 60
 #
 MOUNTDIR=os.path.join(RUNNING_TRACE_DIR, 'mnt')
 WORKLOADFILES_ROOT=os.path.join(NFSOMETER_DIR, 'workload_files')
-RESULTS_DIR=os.path.join(posix.environ['HOME'], 'nfsometer_results')
+RESULTS_DIR=os.path.join(os.environ['HOME'], 'nfsometer_results')
 HOSTNAME=socket.getfqdn()
 RUNROOT='%s/nfsometer_runroot_%s' % (MOUNTDIR, HOSTNAME)
 HTML_DIR="%s/html" % NFSOMETERLIB_DIR
@@ -139,7 +139,7 @@ TEMPLATE_REPORTINFO='%s/report_info.html' % HTML_DIR
 _TEMPLATE_CACHE={}
 def html_template(filename):
     global _TEMPLATE_CACHE
-    if not _TEMPLATE_CACHE.has_key(filename):
+    if filename not in _TEMPLATE_CACHE:
         _TEMPLATE_CACHE[filename] = Template(filename=filename)
     return _TEMPLATE_CACHE[filename]
 
@@ -244,7 +244,7 @@ def groups_by_nfsvers(groups):
     gmap = {}
     for g in groups:
         vers = mountopts_version(g.mountopt)
-        if not gmap.has_key(vers):
+        if vers not in gmap:
             gmap[vers] = []
         gmap[vers].append(g)
     return gmap
nfsometerlib/graph.py +23 -23

122 lines not on this page · raw message

nfsometerlib/options.py +18 -17
index 43c41ed..af3cf96 100644
@@ -14,8 +14,9 @@ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 import os, posix, sys
 import getopt
 import re
+import six
 
-from config import *
+from .config import *
 
 _progname = sys.argv[0]
 
@@ -356,7 +357,7 @@ Example 8: Long running nfsometer trace
         try:
             opts, args = getopt.getopt(sys.argv[1:], shortstr, longlist)
 
-        except getopt.GetoptError, err:
+        except getopt.GetoptError as err:
             self.usage(str(err))
 
         # parse options
@@ -464,7 +465,7 @@ Example 8: Long running nfsometer trace
         for x in mountopts:
             try:
                 vers = mountopts_version(x)
-            except ValueError, e:
+            except ValueError as e:
                 self.usage(str(e))
             self.mountopts.append(x)
 
@@ -490,7 +491,7 @@ Example 8: Long running nfsometer trace
             err = False
             for name in ('NFSOMETER_CMD', 'NFSOMETER_NAME', 'NFSOMETER_DESC',):
                 if not name in posix.environ:
-                    print >>sys.stderr, "%s not set" % name
+                    six.print_("%s not set" % name, file=sys.stderr)
                     err = True
 
             if err:
@@ -564,10 +565,9 @@ Example 8: Long running nfsometer trace
         return lines
 
     def error(self, msg=''):
-        print >>sys.stderr, msg
-        print >>sys.stderr, \
-            '\nrun "%s --help" and "%s examples" for more info' % \
-            (_progname, _progname)
+        six.print_(msg, file=sys.stderr)
+        six.print_('\nrun "%s --help" and "%s examples" for more info' % \
+            (_progname, _progname), file=sys.stderr)
         sys.stderr.flush()
         sys.exit(1)
 
@@ -593,19 +593,19 @@ Example 8: Long running nfsometer trace
         return self._synopsis_fmt % script
 
     def examples(self):
-        print >>sys.stdout, self._examples()
+        print(self._examples())
 
     def usage(self, msg=''):
-        print >>sys.stderr, "usage: %s" % self._synopsis(_progname)
-        print >>sys.stderr, self._modes_description(_progname)
+        six.print_("usage: %s" % self._synopsis(_progname), file=sys.stderr)
+        six.print_(self._modes_description(_progname), file=sys.stderr)
 
-        print >>sys.stderr
-        print >>sys.stderr, "Options:"
-        print >>sys.stderr, '  %s' % '\n  '.join(self._option_help())
+        six.print_("", file=sys.stderr)
+        six.print_("Options:", file=sys.stderr)
+        six.print_('  %s' % '\n  '.join(self._option_help()), file=sys.stderr)
 
         if msg:
-            print >>sys.stderr
-            print >>sys.stderr, "Error: " + msg
+            six.print_('', file=sys.stderr)
+            six.print_("Error: " + msg, file=sys.stderr);
 
         sys.exit(1)
 
@@ -635,5 +635,6 @@ Example 8: Long running nfsometer trace
         for i in range(len(o)):
             o[i] = o[i].strip().replace('-', '\\-')
 
-        file(output_path, 'w+').write('\n'.join(o))
+        with open(output_path, 'w+') as f:
+          f.write('\n'.join(o))
 
nfsometerlib/parse.py +67 -64

483 lines not on this page · raw message

nfsometerlib/report.py +46 -36

210 lines not on this page · raw message

nfsometerlib/selector.py +22 -12
index c20361e..37eb54a 100644
@@ -11,7 +11,7 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 """
 
-from config import *
+from .config import *
 
 SELECTOR_ORDER=(
     'workload',
@@ -70,19 +70,29 @@ class Selector(object):
 
         return hash(tuple(args))
 
-    def __cmp__(self, other):
+    def __eq__(self, other):
         for name in SELECTOR_ORDER:
-            r = cmp(getattr(self, name + 's'), getattr(other, name + 's'))
-            if r:
-                return r
-        return 0
+            if getattr(self, name + 's') != getattr(other, name + 's'):
+                return False
+        return True
+
+    def __lt__(self, other):
+        return NotImplemented
+
+    def __le__(self, other):
+        return NotImplemented
 
-    def compare_order(self, other, order):
+    def __gt__(self, other):
+        return NotImplemented
+
+    def __ge__(self, other):
+        return NotImplemented
+
+    def match_order(self, other, order):
         for name in order:
-            r = cmp(getattr(self, name + 's'), getattr(other, name + 's'))
-            if r != 0:
-                return r
-        return 0
+            if getattr(self, name + 's') != getattr(other, name + 's'):
+                return False
+        return True
 
     def __repr__(self):
         args = []
@@ -102,7 +112,7 @@ class Selector(object):
         elif hasattr(superself, attr):
             return getattr(superself, attr)
         else:
-            raise AttributeError, "invalid attribute: %r" % attr
+            raise AttributeError("invalid attribute: %r" % attr)
 
     def __add__(self, other):
         new = Selector()
nfsometerlib/trace.py +51 -52

296 lines not on this page · raw message

nfsometerlib/workloads.py +24 -23

167 lines not on this page · raw message

setup.py +4 -4
index 51e7d34..a0cca64 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Copyright 2012 NetApp, Inc. All Rights Reserved,
 contribution by Weston Andros Adamson <[email protected]>
@@ -21,7 +21,7 @@ import nfsometerlib.options
 class sdist(_sdist):
     def run(self):
         if not self.dry_run:
-            print "generating manpage %s" % NFSOMETER_MANPAGE
+            print("generating manpage %s" % NFSOMETER_MANPAGE)
             o = nfsometerlib.options.Options()
             o.generate_manpage(NFSOMETER_MANPAGE)
 
@@ -37,7 +37,7 @@ class install(_install):
             manpath = self.root + manpath
             gzpath = self.root + gzpath
 
-        print "gzipping manpage %s" % (gzpath,)
+        print("gzipping manpage %s" % (gzpath,))
         os.system('mkdir -p %s' % manpath)
         os.system('gzip -f --stdout "%s" > "%s"' % (manpage, gzpath))
 
@@ -52,7 +52,7 @@ class install(_install):
             old = self.root + old
             new = self.root + new
 
-        print "stripping .py from script %s" % (old,)
+        print("stripping .py from script %s" % (old,))
         os.rename(old, new)
 
     def run(self):
Signature · 1 line
2.37.3
#1 lore raw
Quoted 7 lines · Jianhong Yin

see: https://src.fedoraproject.org/rpms/nfsometer/tree/rawhide

nfsometer upstream can not work on latest linux with python3, just copy the python3 patch from fedora nfsometer pkg back to upstream

---

Hi,

I am afraid this patch will be ignored. It seems the maintainer has not
responded to contributions at all in the past 5 years. The upstream tree
seems not maintained any longer. There was another developer who tried to
send a patch two years ago, but he got no response.
Cf. https://lore.kernel.org/all/OSBPR01MB294973D46ADE4ED7A7D3E19AEF880@OSBPR01MB2949.jpnprd01.prod.outlook.com/

I believe nfsometer is still useful in measuring performance of various NFS settings. I think this patch should go into the tree to let people continue to it as python2 is already removed from some distros such as CentOS/RHEL 9.

Does anybody has any idea? As the software is licensed under GPLv2, I think it is possible that someone create a fork and take over the project. Is it possible to contact Dros (Weston Andros Adamson) to ask if he is still willing to continue maintaining nfsometer?

Daisuke