public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Rohan Sable <rsable@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: steved@redhat.com, rsable@redhat.com
Subject: [PATCH v1] mountstats: handle KeyError in display_raw_stats
Date: Wed, 28 Oct 2020 18:29:11 +0530	[thread overview]
Message-ID: <20201028125911.GA140323@fedora.rsable.com> (raw)

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


             reply	other threads:[~2020-10-29  1:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 12:59 Rohan Sable [this message]
2020-10-31 16:16 ` [PATCH v1] mountstats: handle KeyError in display_raw_stats Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201028125911.GA140323@fedora.rsable.com \
    --to=rsable@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox