[ovs-discuss] any help from Python experts? (was: Re: Branch v2.6.1 repo does not make (github))

Robert Wojciechowicz robertx.wojciechowicz at intel.com
Wed Feb 1 14:45:56 UTC 2017


On Tue, Jan 31, 2017 at 03:45:48PM -0800, Ben Pfaff wrote:
> OK, so looking closer...
> 
> The OVS build process runs a few Python programs using syntax like this:
>         PYTHONPATH=$(srcdir)/python:$(PYTHONPATH) python program.py
> 
> This means that sys.path ends up looking like:
> 
> ['/dir/for/program.py', ..., '/usr/lib/python2.7/dist-packages', ...
>  '$(srcdir)/python', ...]

Not really, sys.path is initialized by current working dir, PYTHONPATH 
and then followed by installation-dependent default paths.

https://docs.python.org/2/library/sys.html#sys.path

$ python -V
Python 2.7.5

$ python -c "import sys; print '\n'.join(sys.path)"

/usr/lib64/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/site-packages
/usr/lib/python2.7/site-packages

$ PYTHONPATH=./python python -c "import sys; print '\n'.join(sys.path)"

/home/rwojciex/src/ovs/python
/usr/lib64/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/site-packages
/usr/lib/python2.7/site-packages

$ PYTHONPATH=./python:/tmp/old_python python -c "import sys; print '\n'.join(sys.path)"

/home/rwojciex/src/ovs/python
/tmp/old_python
/usr/lib64/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/site-packages
/usr/lib/python2.7/site-packages

So PYTHONPATH directories are always searched after current working directory,
but before system default paths.


> 
> where /usr/lib/python2.7/dist-packages is the distro's Python package
> installation directory, which is where the python-openvswitch package
> installs its .py files.  This has the effect that these installed files
> override the ones in the source directory.
> 
> Python experts, what's the best way to get $(srcdir)/python ahead of
> /usr/lib/python2.7/dist-packages in sys.path?

In such strange cases like this I always use python "-v" option
which shows exactly from what directory modules I loaded (in error stream) e.g.:


$ PYTHONPATH=./python:/tmp/old_python /usr/bin/python -v ./ovsdb/ovsdb-idlc.in c-idl-source lib/vswitch-idl.ovsidl 2>&1 | grep ovs.db.types
# /home/rwojciex/src/ovs/python/ovs/db/types.pyc matches /home/rwojciex/src/ovs/python/ovs/db/types.py
import ovs.db.types # precompiled from /home/rwojciex/src/ovs/python/ovs/db/types.pyc
# cleanup[2] ovs.db.types

$ PYTHONPATH=/tmp/old_python:./python /usr/bin/python -v ./ovsdb/ovsdb-idlc.in c-idl-source lib/vswitch-idl.ovsidl 2>&1 | grep ovs.db.types
# /tmp/old_python/ovs/db/types.pyc matches /tmp/old_python/ovs/db/types.py
import ovs.db.types # precompiled from /tmp/old_python/ovs/db/types.pyc
# cleanup[2] ovs.db.types

Somehow in this case ovs.db.types module was loaded from different location than expected.


> 
> Thanks,
> 
> Ben.

HTH,
Robert

> 
> On Sun, Jan 29, 2017 at 05:16:29PM +0000, Logu J wrote:
> > Ben,
> > 
> > Thanks for the tip. make succeeded after removing 'python-openvswitch'
> > package.
> > 
> > ubuntu at sdnhubvm:openvswitch[22:32] (master)$ dpkg -l | grep openvswitch
> > rc  openvswitch-controller                2.0.1+git20140120-0ubuntu2
> >        amd64        Open vSwitch controller implementation
> > ii  openvswitch-datapath-source           2.3.90-1
> >        all          Open vSwitch datapath module source - module-assistant
> > version
> > rc  openvswitch-ipsec                     2.1.0-1
> >       amd64        Open vSwitch GRE-over-IPsec support
> > rc  openvswitch-pki                       2.3.90-1
> >        all          Open vSwitch public key infrastructure dependency
> > package
> > rc  openvswitch-switch                    2.3.90-1
> >        amd64        Open vSwitch switch implementations
> > rc  openvswitch-vtep                      2.1.0-1
> >       amd64        Open vSwitch VTEP utilities
> > ii  python-openvswitch                    2.3.90-1
> >        all          Python bindings for Open vSwitch
> > 
> > Regards,
> > Logu
> > 
> > On Sun, Jan 29, 2017 at 10:16 AM Ben Pfaff <blp at ovn.org> wrote:
> > 
> > Perhaps you have some old version of the Python libraries for Open
> > vSwitch installed somewhere?  In older versions of OVS, the function in
> > question did have fewer arguments.
> > 
> > I don't know why a system installation of a Python library would
> > override the version in the OVS tree.  Probably need help from a Python
> > expert on that.
> > 
> > On Sun, Jan 29, 2017 at 03:27:52AM +0000, Logu J wrote:
> > > Ben,
> > >
> > > checked out latest code from github and compiling.
> > >
> > > I was getting same error on master branch, so I was trying to compile with
> > > v2.6.1. Thanks for pointing out my mistake.
> > >
> > > Now I switched to v2.6.1 with 'git checkout tags/v2.6.1', still make fails
> > > with same error. (I've attached make terminal output).
> > >
> > > My environment:
> > >
> > > ubuntu at sdnhubvm:openvswitch[08:50] ((detached from v2.6.1))$ lsb_release
> > -a
> > > No LSB modules are available.
> > > Distributor ID: Ubuntu
> > > Description: *Ubuntu 14.04.5 LTS*
> > > Release: 14.04
> > > Codename: trusty
> > > ubuntu at sdnhubvm:openvswitch[08:50] ((detached from v2.6.1))$ uname -a
> > > Linux sdnhubvm *3.13.0-24-generic* #47-Ubuntu SMP Fri May 2 23:30:00 UTC
> > > 2014 x86_64 x86_64 x86_64 GNU/Linux
> > > ubuntu at sdnhubvm:openvswitch[08:50] ((detached from v2.6.1))$ gcc --version
> > > *gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4*
> > > Copyright (C) 2013 Free Software Foundation, Inc.
> > > This is free software; see the source for copying conditions.  There is NO
> > > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
> > PURPOSE.
> > >
> > > Regards,
> > > Logu
> > >
> > > On Sat, Jan 28, 2017 at 11:33 PM Ben Pfaff <blp at ovn.org> wrote:
> > >
> > > > On Sat, Jan 28, 2017 at 03:36:22AM +0000, Logu J wrote:
> > > > > I'm stuck at below error (on Ubuntu 14.04.5 LTS). Any clue please?
> > > > >
> > > > > ubuntu at sdnhubvm:openvswitch[09:00] (master)$ git checkout -b v2.6.1
> > > > > Switched to a new branch 'v2.6.1'
> > > >
> > > > You were on master, which is presumably a clone of the OVS master
> > > > branch, and then you typed "git checkout -b v2.6.1".  This does not
> > > > switch to v2.6.1 or to any other commit or branch or tag.  Rather, it
> > > > creates a new branch from the *current* commit, which is presumably some
> > > > commit along the OVS master branch.  So this bug report is probably not
> > > > for v2.6.1 or even for branch-2.6 (the OVS 2.6.x branch).
> > > >
> > > > What commit did you actually compile?
> > > >
> _______________________________________________
> discuss mailing list
> discuss at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


More information about the discuss mailing list