[ovs-dev] [PATCH v2] bugtool: Fix for Python3

William Tu u9012063 at gmail.com
Thu Apr 9 22:03:45 UTC 2020


On Wed, Mar 25, 2020 at 05:33:51PM -0700, William Tu wrote:
> On Thu, Mar 19, 2020 at 12:20:19PM -0700, William Tu wrote:
> > On Thu, Mar 19, 2020 at 12:05 PM Timothy Redaelli <tredaelli at redhat.com> wrote:
> > >
> > > Currently ovs-bugtool tool doesn't start on Python 3.
> > > This commit fixes ovs-bugtool to make it works on Python 3.
> > >
> > > Replaced StringIO.StringIO with io.BytesIO since the script is
> > > processing binary data.
> > >
> > > Reported-at: https://bugzilla.redhat.com/1809241
> > > Reported-by: Flavio Leitner <fbl at sysclose.org>
> > > Signed-off-by: Timothy Redaelli <tredaelli at redhat.com>
> > > ---
> > > Changes since v1:
> > >   * Converted StringIO to BytesIO
> > >   * Fix some other string/bytes conversion
> > > ---
> > 
> > Thanks for sending out v2. Hit an error below:
> > ~/ovs# python3
> > Python 3.5.2 (default, Oct  8 2019, 13:06:37)
> > 
> > ~/ovs# ./utilities/bugtool/ovs-bugtool -y -s --output=tar.gz
> > --outfile=/tmp/t.tgz
> > Traceback (most recent call last):
> >   File "./utilities/bugtool/ovs-bugtool", line 1405, in <module>
> >     sys.exit(main())
> >   File "./utilities/bugtool/ovs-bugtool", line 717, in main
> >     collect_data()
> >   File "./utilities/bugtool/ovs-bugtool", line 388, in collect_data
> >     v['output'] = BytesIOmtime(s)
> >   File "./utilities/bugtool/ovs-bugtool", line 1395, in __init__
> >     BytesIO.__init__(self, buf)
> > TypeError: a bytes-like object is required, not 'str'
> > 
> > I think sometimes 's' is bytes type, sometimes 's' is a str type...
> > William
> 
> Hi Timothy,
> 
> How about adding this to your patch?
> I tested it and works ok.
> 
> diff --git a/utilities/bugtool/ovs-bugtool.in b/utilities/bugtool/ovs-bugtool.in
> index c26c2be7a4eb..47f3c4629f70 100755
> --- a/utilities/bugtool/ovs-bugtool.in
> +++ b/utilities/bugtool/ovs-bugtool.in
> @@ -385,7 +385,10 @@ def collect_data():
>              except Exception as e:
>                  s = str(e).encode()
>              if check_space(cap, k, len(s)):
> -                v['output'] = BytesIOmtime(s)
> +                if isinstance(s, str):
> +                    v['output'] = BytesIOmtime(s.encode())
> +                else:
> +                    v['output'] = BytesIOmtime(s)
>  
>  
>  def main(argv=None):
> 
I applied to master with the diff above.
Thanks!
William



More information about the dev mailing list