From: "J. Bruce Fields" <bfields@redhat.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: linux-nfs@vger.kernel.org, "Yong Sun (Sero)" <yosun@suse.com>
Subject: Re: [PATCH pynfs 2/3] server: Allow to print JSON format
Date: Tue, 25 May 2021 10:10:31 -0400 [thread overview]
Message-ID: <YK0FV/mvmbIzSpKJ@pick.fieldses.org> (raw)
In-Reply-To: <20210524144251.30196-2-pvorel@suse.cz>
I've got nothing against this, but I'm curious why you need it.
--b.
On Mon, May 24, 2021 at 04:42:50PM +0200, Petr Vorel wrote:
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> nfs4.0/testserver.py | 7 ++++++-
> nfs4.1/testmod.py | 40 +++++++++++++++++++++++++++++++++++++++-
> nfs4.1/testserver.py | 6 +++++-
> 3 files changed, 50 insertions(+), 3 deletions(-)
>
> diff --git a/nfs4.0/testserver.py b/nfs4.0/testserver.py
> index 0ef010a..f2c4156 100755
> --- a/nfs4.0/testserver.py
> +++ b/nfs4.0/testserver.py
> @@ -85,6 +85,8 @@ def scan_options(p):
> help="Skip final cleanup of test directory")
> p.add_option("--outfile", "--out", default=None, metavar="FILE",
> help="Store test results in FILE [%default]")
> + p.add_option("--jsonout", "--json", default=None, metavar="FILE",
> + help="Store test results in JSON format [%default]")
> p.add_option("--xmlout", "--xml", default=None, metavar="FILE",
> help="Store test results in xml format [%default]")
> p.add_option("--debug_fail", action="store_true", default=False,
> @@ -378,8 +380,11 @@ def main():
> if fail:
> print("\nWARNING: could not clean testdir due to:\n%s\n" % err)
>
> - if opt.xmlout is not None:
> + if opt.jsonout is not None:
> + testmod.json_printresults(tests, opt.jsonout)
> + elif opt.xmlout is not None:
> testmod.xml_printresults(tests, opt.xmlout)
> +
> if nfail < 0:
> sys.exit(3)
> if nfail > 0:
> diff --git a/nfs4.1/testmod.py b/nfs4.1/testmod.py
> index e368853..4b4ed24 100644
> --- a/nfs4.1/testmod.py
> +++ b/nfs4.1/testmod.py
> @@ -13,6 +13,7 @@ import re
> import sys
> import time
> from traceback import format_exception, print_exc
> +import json
> import xml.dom.minidom
> import datetime
>
> @@ -467,6 +468,43 @@ def printresults(tests, opts, file=None):
> (count[SKIP], count[FAIL], count[WARN], count[PASS]), file=file)
> return count[FAIL]
>
> +def json_printresults(tests, file_name, suite='all'):
> + with open(file_name, 'w') as fd:
> + failures = 0
> + skipped = 0
> + total_time = 0
> + data = {}
> + data["tests"] = len(tests)
> + data["errors"] = 0
> + data["timestamp"] = str(datetime.datetime.now())
> + data["name"] = suite
> + data["testcase"] = []
> + for t in tests:
> + test = {
> + "name": t.name,
> + "classname": t.suite,
> + "time": str(t.time_taken),
> + }
> +
> + total_time += t.time_taken
> + if t.result == TEST_FAIL:
> + failures += 1
> + test["failure"] = {
> + "message" : t.result.msg,
> + "err" : ''.join(t.result.tb)
> + }
> + elif t.result == TEST_OMIT:
> + skipped += 1
> + test["skipped"] = 1
> +
> + data["testcase"].append(test)
> +
> + data["failures"] = failures
> + data["skipped"] = skipped
> + data["time"] = total_time
> +
> + fd.write(json.dumps(data, indent=4, sort_keys=True))
> +
> def xml_printresults(tests, file_name, suite='all'):
> with open(file_name, 'w') as fd:
> failures = 0
> @@ -484,7 +522,7 @@ def xml_printresults(tests, file_name, suite='all'):
> testsuite.appendChild(testcase)
> testcase.setAttribute("name", t.name)
> testcase.setAttribute("classname", t.suite)
> - testcase.setAttribute("time", str(t.time_taken))
> + testcase.setAttribute("time", t.time_taken)
>
> total_time += t.time_taken
> if t.result == TEST_FAIL:
> diff --git a/nfs4.1/testserver.py b/nfs4.1/testserver.py
> index d3c44c7..085f007 100755
> --- a/nfs4.1/testserver.py
> +++ b/nfs4.1/testserver.py
> @@ -68,6 +68,8 @@ def scan_options(p):
> help="Skip final cleanup of test directory")
> p.add_option("--outfile", "--out", default=None, metavar="FILE",
> help="Store test results in FILE [%default]")
> + p.add_option("--jsonout", "--json", default=None, metavar="FILE",
> + help="Store test results in JSON format [%default]")
> p.add_option("--xmlout", "--xml", default=None, metavar="FILE",
> help="Store test results in xml format [%default]")
> p.add_option("--debug_fail", action="store_true", default=False,
> @@ -363,7 +365,9 @@ def main():
> if fail:
> print("\nWARNING: could not clean testdir due to:\n%s\n" % err)
>
> - if opt.xmlout is not None:
> + if opt.jsonout is not None:
> + testmod.json_printresults(tests, opt.jsonout)
> + elif opt.xmlout is not None:
> testmod.xml_printresults(tests, opt.xmlout)
>
> if __name__ == "__main__":
> --
> 2.31.1
>
next prev parent reply other threads:[~2021-05-25 14:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-24 14:42 [PATCH pynfs 1/3] remove trailing whitespace Petr Vorel
2021-05-24 14:42 ` [PATCH pynfs 2/3] server: Allow to print JSON format Petr Vorel
2021-05-25 14:10 ` J. Bruce Fields [this message]
2021-05-25 14:32 ` Petr Vorel
2021-05-24 14:42 ` [PATCH pynfs 3/3] server: Add test code to JSON and XML output Petr Vorel
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=YK0FV/mvmbIzSpKJ@pick.fieldses.org \
--to=bfields@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=pvorel@suse.cz \
--cc=yosun@suse.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