public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] mountstats: handle KeyError in display_raw_stats
@ 2020-10-28 12:59 Rohan Sable
  2020-10-31 16:16 ` Steve Dickson
  0 siblings, 1 reply; 2+ messages in thread
From: Rohan Sable @ 2020-10-28 12:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: steved, rsable

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'

Signed-off-by: Rohan Sable <rsable@redhat.com>
---
 tools/mountstats/mountstats.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/mountstats/mountstats.py b/tools/mountstats/mountstats.py
index 25e92a19..23876fc4 100755
--- a/tools/mountstats/mountstats.py
+++ b/tools/mountstats/mountstats.py
@@ -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()
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] mountstats: handle KeyError in display_raw_stats
  2020-10-28 12:59 [PATCH v1] mountstats: handle KeyError in display_raw_stats Rohan Sable
@ 2020-10-31 16:16 ` Steve Dickson
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Dickson @ 2020-10-31 16:16 UTC (permalink / raw)
  To: Rohan Sable, linux-nfs



On 10/28/20 8:59 AM, Rohan Sable wrote:
> 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'
> 
> Signed-off-by: Rohan Sable <rsable@redhat.com>
I was not able to reproduce this on a RHEL6.10 box but it didn't make either. ;-) 

Committed... 

steved.
> ---
>  tools/mountstats/mountstats.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/mountstats/mountstats.py b/tools/mountstats/mountstats.py
> index 25e92a19..23876fc4 100755
> --- a/tools/mountstats/mountstats.py
> +++ b/tools/mountstats/mountstats.py
> @@ -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()
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-31 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-28 12:59 [PATCH v1] mountstats: handle KeyError in display_raw_stats Rohan Sable
2020-10-31 16:16 ` Steve Dickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox