diff mbox series

rteval: sysstat: Convert base64 data to text before wrapping

Message ID 20240621021805.2086489-1-crwood@redhat.com
State New
Headers show
Series rteval: sysstat: Convert base64 data to text before wrapping | expand

Commit Message

Crystal Wood June 21, 2024, 2:18 a.m. UTC
As of Python 3, b64encode() returns data, not a string, causing this:

Traceback (most recent call last):
  File "/home/crwood/git/rteval/./rteval-cmd", line 413, in <module>
    ec = rteval.Measure()
         ^^^^^^^^^^^^^^^^
  File "/home/crwood/git/rteval/rteval/__init__.py", line 246, in Measure
    self._report(measure_start, self.__rtevcfg.xslt_report)
  File "/home/crwood/git/rteval/rteval/rtevalReport.py", line 63, in _report
    self.__xmlreport.AppendXMLnodes(self._measuremods.MakeReport())
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/crwood/git/rteval/rteval/modules/measurement/__init__.py", line 190, in MakeReport
    mprep_n = mp.MakeReport()
              ^^^^^^^^^^^^^^^
  File "/home/crwood/git/rteval/rteval/modules/measurement/__init__.py", line 62, in MakeReport
    rep_n = RtEvalModules.MakeReport(self)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/crwood/git/rteval/rteval/modules/__init__.py", line 559, in MakeReport
    modrep_n = mod.MakeReport()
               ^^^^^^^^^^^^^^^^
  File "/home/crwood/git/rteval/rteval/modules/measurement/sysstat.py", line 83, in MakeReport
    data_n = rep_n.newTextChild(None, 'data', "\n"+"\n".join(textwrap.wrap(data, 75))+"\n")
                                                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/textwrap.py", line 384, in wrap
    return w.wrap(text)
           ^^^^^^^^^^^^
  File "/usr/lib64/python3.12/textwrap.py", line 356, in wrap
    chunks = self._split_chunks(text)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/textwrap.py", line 342, in _split_chunks
    text = self._munge_whitespace(text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/textwrap.py", line 153, in _munge_whitespace
    text = text.translate(self.unicode_whitespace_trans)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'dict'

Signed-off-by: Crystal Wood <crwood@redhat.com>
---
 rteval/modules/measurement/sysstat.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

John Kacur June 21, 2024, 5:43 p.m. UTC | #1
On Thu, 20 Jun 2024, Crystal Wood wrote:

> As of Python 3, b64encode() returns data, not a string, causing this:
> 
> Traceback (most recent call last):
>   File "/home/crwood/git/rteval/./rteval-cmd", line 413, in <module>
>     ec = rteval.Measure()
>          ^^^^^^^^^^^^^^^^
>   File "/home/crwood/git/rteval/rteval/__init__.py", line 246, in Measure
>     self._report(measure_start, self.__rtevcfg.xslt_report)
>   File "/home/crwood/git/rteval/rteval/rtevalReport.py", line 63, in _report
>     self.__xmlreport.AppendXMLnodes(self._measuremods.MakeReport())
>                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/crwood/git/rteval/rteval/modules/measurement/__init__.py", line 190, in MakeReport
>     mprep_n = mp.MakeReport()
>               ^^^^^^^^^^^^^^^
>   File "/home/crwood/git/rteval/rteval/modules/measurement/__init__.py", line 62, in MakeReport
>     rep_n = RtEvalModules.MakeReport(self)
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/crwood/git/rteval/rteval/modules/__init__.py", line 559, in MakeReport
>     modrep_n = mod.MakeReport()
>                ^^^^^^^^^^^^^^^^
>   File "/home/crwood/git/rteval/rteval/modules/measurement/sysstat.py", line 83, in MakeReport
>     data_n = rep_n.newTextChild(None, 'data', "\n"+"\n".join(textwrap.wrap(data, 75))+"\n")
>                                                              ^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/lib64/python3.12/textwrap.py", line 384, in wrap
>     return w.wrap(text)
>            ^^^^^^^^^^^^
>   File "/usr/lib64/python3.12/textwrap.py", line 356, in wrap
>     chunks = self._split_chunks(text)
>              ^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/lib64/python3.12/textwrap.py", line 342, in _split_chunks
>     text = self._munge_whitespace(text)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/lib64/python3.12/textwrap.py", line 153, in _munge_whitespace
>     text = text.translate(self.unicode_whitespace_trans)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> TypeError: a bytes-like object is required, not 'dict'
> 
> Signed-off-by: Crystal Wood <crwood@redhat.com>
> ---
>  rteval/modules/measurement/sysstat.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rteval/modules/measurement/sysstat.py b/rteval/modules/measurement/sysstat.py
> index 57194a2b5f45..d4646c1646f4 100644
> --- a/rteval/modules/measurement/sysstat.py
> +++ b/rteval/modules/measurement/sysstat.py
> @@ -79,7 +79,7 @@ class sysstat(rtevalModulePrototype):
>          fp = open(self.__datafile, "rb")
>          compr = bz2.BZ2Compressor(9)
>          cmpr = compr.compress(fp.read())
> -        data = base64.b64encode(cmpr + compr.flush())
> +        data = base64.b64encode(cmpr + compr.flush()).decode('utf-8')
>          data_n = rep_n.newTextChild(None, 'data', "\n"+"\n".join(textwrap.wrap(data, 75))+"\n")
>          data_n.newProp('contents', 'sysstat/sar binary data')
>          data_n.newProp('encoding', 'base64')
> -- 

Signed-off-by: John Kacur <jkacur@redhat.com>
diff mbox series

Patch

diff --git a/rteval/modules/measurement/sysstat.py b/rteval/modules/measurement/sysstat.py
index 57194a2b5f45..d4646c1646f4 100644
--- a/rteval/modules/measurement/sysstat.py
+++ b/rteval/modules/measurement/sysstat.py
@@ -79,7 +79,7 @@  class sysstat(rtevalModulePrototype):
         fp = open(self.__datafile, "rb")
         compr = bz2.BZ2Compressor(9)
         cmpr = compr.compress(fp.read())
-        data = base64.b64encode(cmpr + compr.flush())
+        data = base64.b64encode(cmpr + compr.flush()).decode('utf-8')
         data_n = rep_n.newTextChild(None, 'data', "\n"+"\n".join(textwrap.wrap(data, 75))+"\n")
         data_n.newProp('contents', 'sysstat/sar binary data')
         data_n.newProp('encoding', 'base64')