Skip to contentSkip to conversation

mountstats: handle KeyError in display_raw_stats

PATCH In review Rohan Sable 2 participants 2 messages Oct 29, 2020 – Oct 31, 2020

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

PATCH 1/1 mountstats: handle KeyError in display_raw_stats

While printing Nfsv4ops from older /proc/self/mountstats e.g. in 2.6.32-754.el6.x86_64 from RHEL 6.10,
it will not have all the Keys present leading to a KeyError like below :

Traceback (most recent call last):
File "nfs-utils/tools/mountstats/mountstats.py", line 1131, in <module>
res = main()
File "nfs-utils/tools/mountstats/mountstats.py", line 1120, in main
return args.func(args)
File "nfs-utils/tools/mountstats/mountstats.py", line 860, in mountstats_command
print_mountstats(stats, args.nfs_only, args.rpc_only, args.raw, args.xprt_only)
File "nfs-utils/tools/mountstats/mountstats.py", line 813, in print_mountstats
stats.display_raw_stats()
File "nfs-utils/tools/mountstats/mountstats.py", line 381, in display_raw_stats

    print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))

KeyError: 'FSID_PRESENT'

---
 tools/mountstats/mountstats.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +4 -1
index 25e92a19..23876fc4 100755
@@ -378,7 +378,10 @@ class DeviceData:
                 print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))
         elif vers == '4':
             for op in Nfsv4ops:
-                print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))
+                try:
+                    print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))
+                except KeyError:
+                    continue
         else:
             print('\tnot implemented for version %d' % vers)
         print()
Signature · 1 line
2.26.2
#1 lore raw
Quoted 15 lines · Rohan Sable

While printing Nfsv4ops from older /proc/self/mountstats e.g. in 2.6.32-754.el6.x86_64 from RHEL 6.10,
it will not have all the Keys present leading to a KeyError like below :

Traceback (most recent call last):
File "nfs-utils/tools/mountstats/mountstats.py", line 1131, in <module>
res = main()
File "nfs-utils/tools/mountstats/mountstats.py", line 1120, in main
return args.func(args)
File "nfs-utils/tools/mountstats/mountstats.py", line 860, in mountstats_command
print_mountstats(stats, args.nfs_only, args.rpc_only, args.raw, args.xprt_only)
File "nfs-utils/tools/mountstats/mountstats.py", line 813, in print_mountstats
stats.display_raw_stats()
File "nfs-utils/tools/mountstats/mountstats.py", line 381, in display_raw_stats

Quoted 4 lines
    print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))

KeyError: 'FSID_PRESENT'

I was not able to reproduce this on a RHEL6.10 box but it didn't make either. ;-)

Committed...

steved.

Quoted 21 lines
---
 tools/mountstats/mountstats.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +4 -1
index 25e92a19..23876fc4 100755
@@ -378,7 +378,10 @@ class DeviceData:
                 print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))
         elif vers == '4':
             for op in Nfsv4ops:
-                print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))
+                try:
+                    print('\t%12s: %s' % (op, " ".join(str(x) for x in self.__rpc_data[op])))
+                except KeyError:
+                    continue
         else:
             print('\tnot implemented for version %d' % vers)
         print()