[libvirt] [PATCH 11/23] cputest: Avoid calling json_reformat in cpu-parse.sh

Jiri Denemark posted 23 patches 7 years, 7 months ago
There is a newer version of this series
[libvirt] [PATCH 11/23] cputest: Avoid calling json_reformat in cpu-parse.sh
Posted by Jiri Denemark 7 years, 7 months ago
Various version of json_reformat use different number of spaces for
indenting. Let's use a simple python reformatter to gain full control
over the formatting for consistent results.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tests/cputestdata/cpu-parse.sh    | 2 +-
 tests/cputestdata/cpu-reformat.py | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100755 tests/cputestdata/cpu-reformat.py

diff --git a/tests/cputestdata/cpu-parse.sh b/tests/cputestdata/cpu-parse.sh
index cd1ab024b3..96ff1074e0 100755
--- a/tests/cputestdata/cpu-parse.sh
+++ b/tests/cputestdata/cpu-parse.sh
@@ -42,7 +42,7 @@ json()
     while read; do
         $first || echo
         first=false
-        json_reformat <<<"$REPLY" | tr -s '\n'
+        $(dirname $0)/cpu-reformat.py <<<"$REPLY"
     done
 }
 
diff --git a/tests/cputestdata/cpu-reformat.py b/tests/cputestdata/cpu-reformat.py
new file mode 100755
index 0000000000..999ef1698c
--- /dev/null
+++ b/tests/cputestdata/cpu-reformat.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python2
+
+import sys
+import json
+
+dec = json.JSONDecoder()
+data, pos = dec.raw_decode(sys.stdin.read())
+json.dump(data, sys.stdout, indent = 2, separators = (',', ': '))
+print
-- 
2.14.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 11/23] cputest: Avoid calling json_reformat in cpu-parse.sh
Posted by John Ferlan 7 years, 7 months ago

On 10/04/2017 10:58 AM, Jiri Denemark wrote:
> Various version of json_reformat use different number of spaces for
> indenting. Let's use a simple python reformatter to gain full control
> over the formatting for consistent results.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  tests/cputestdata/cpu-parse.sh    | 2 +-
>  tests/cputestdata/cpu-reformat.py | 9 +++++++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
>  create mode 100755 tests/cputestdata/cpu-reformat.py
> 

Looks reasonable - python, formatting, and scripting - not exactly in my
wheel house. Still doesn't 'tr -s '\n' just replace multiple occurrences
of \n with just one?  I suppose that's being done along with some amount
of space adding.

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 11/23] cputest: Avoid calling json_reformat in cpu-parse.sh
Posted by Jiri Denemark 7 years, 7 months ago
On Thu, Oct 12, 2017 at 16:18:20 -0400, John Ferlan wrote:
> 
> 
> On 10/04/2017 10:58 AM, Jiri Denemark wrote:
> > Various version of json_reformat use different number of spaces for
> > indenting. Let's use a simple python reformatter to gain full control
> > over the formatting for consistent results.
> > 
> > Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> > ---
> >  tests/cputestdata/cpu-parse.sh    | 2 +-
> >  tests/cputestdata/cpu-reformat.py | 9 +++++++++
> >  2 files changed, 10 insertions(+), 1 deletion(-)
> >  create mode 100755 tests/cputestdata/cpu-reformat.py
> > 
> 
> Looks reasonable - python, formatting, and scripting - not exactly in my
> wheel house. Still doesn't 'tr -s '\n' just replace multiple occurrences
> of \n with just one?  I suppose that's being done along with some amount
> of space adding.

json_reformat formats empty arrays as

    ...
    "array": [

    ],
    ...

which breaks our test monitor. The python formatting code doesn't do
that so we don't need "tr -s '\n'" anymore.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list