So, if no system packages can be imported, how do you test the "connection" class for the libvirt driver? <div><br></div><div>How does that particular test case wrap around the fact that it requires the libvirt module? The only thing i could find are these lines of code in the driver's __init__ method. Do these somehow detect if this is a unit test environment and import the fakelibvirt driver instead? I'm no expert in python so i'm not sure what's happening there :s<div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">global libvirt<br>if libvirt is None:<br>    libvirt = __import__('libvirt')</blockquote>
<div><br></div><div>Regards,</div><div>Leander </div><br><div class="gmail_quote">On Mon, Jul 2, 2012 at 1:27 PM, Monty Taylor <span dir="ltr"><<a href="mailto:mordred@inaugust.com" target="_blank">mordred@inaugust.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
On 07/02/2012 06:02 AM, Leander Bessa Beernaert wrote:<br>
> Thanks, that let me see the real problem now:<br>
><br>
>     ./tools/with_venv.sh nosetests -svx nova<br>
>     nose.config: INFO: Set working dir to /home/gsd/nova/nova/tests<br>
>     nose.config: INFO: Working directory /home/gsd/nova/nova/tests is a<br>
>     package; adding to sys.path<br>
>     nose.config: INFO: Ignoring files matching ['^\\.', '^_',<br>
>     '^setup\\.py$']<br>
>     nose.plugins.cover: INFO: Coverage report will include only<br>
>     packages: ['nova']<br>
>     nose.selector: INFO: /home/gsd/nova/nova/auth/opendj.sh is<br>
>     executable; skipped<br>
>     nose.selector: INFO: /home/gsd/nova/nova/auth/slap.sh is executable;<br>
>     skipped<br>
>     nose.selector: INFO:<br>
>     /home/gsd/nova/nova/cloudpipe/bootscript.template is executable; skipped<br>
>     Failure: ImportError (No module named libvirt) ... ERROR<br>
>     ======================================================================<br>
>     ERROR: Failure: ImportError (No module named libvirt)<br>
>     ----------------------------------------------------------------------<br>
>     Traceback (most recent call last):<br>
>       File<br>
>     "/home/gsd/nova/.venv/local/lib/python2.7/site-packages/nose/loader.py",<br>
>     line 390, in loadTestsFromName<br>
>         addr.filename, addr.module)<br>
>       File<br>
>     "/home/gsd/nova/.venv/local/lib/python2.7/site-packages/nose/importer.py",<br>
>     line 39, in importFromPath<br>
>         return self.importFromDir(dir_path, fqname)<br>
>       File<br>
>     "/home/gsd/nova/.venv/local/lib/python2.7/site-packages/nose/importer.py",<br>
>     line 86, in importFromDir<br>
>         mod = load_module(part_fqname, fh, filename, desc)<br>
>       File "/home/gsd/nova/nova/test.py", line 41, in <module><br>
>         from nova.tests import fake_flags<br>
>       File "/home/gsd/nova/nova/tests/fake_flags.py", line 24, in <module><br>
>         flags.DECLARE('compute_scheduler_driver', 'nova.scheduler.multi')<br>
>       File "/home/gsd/nova/nova/flags.py", line 52, in DECLARE<br>
>         __import__(module_string, globals(), locals())<br>
>       File "/home/gsd/nova/nova/scheduler/multi.py", line 27, in <module><br>
>         from nova.scheduler import driver<br>
>       File "/home/gsd/nova/nova/scheduler/driver.py", line 53, in <module><br>
</div></div>>         flags..DECLARE('libvirt_type', 'nova.virt.libvirt.connection')<br>
<div class="im">>       File "/home/gsd/nova/nova/flags.py", line 52, in DECLARE<br>
>         __import__(module_string, globals(), locals())<br>
>       File "/home/gsd/nova/nova/virt/libvirt/connection.py", line 73, in<br>
>     <module><br>
>         from nova.virt.libvirt import diagnostics as libvirt_diagnostics<br>
>       File "/home/gsd/nova/nova/virt/libvirt/diagnostics.py", line 75,<br>
>     in <module><br>
>         import libvirt as virt<br>
>     ImportError: No module named libvirt<br>
>     ----------------------------------------------------------------------<br>
>     Ran 1 test in 0.002s<br>
>     FAILED (errors=1)<br>
><br>
><br>
> Libvirt is present on my system, i can import it through the python<br>
> interpreter from any location. Yet, it still says it is not present.<br>
> Could this have to do with the virtual_env or fakelibvirt?<br>
<br>
</div>Yes. Our virtualenvs are currently configured to not allow system<br>
packages to be used (so that they only use python libs installed into<br>
the virtualenv. However, libvirt is not installable via pip, which is a<br>
problem.<br>
<br>
We've recently added a new tox environment to help with this, so try<br>
running:<br>
<br>
tox -v -efull<br>
<br>
Which is set up to allow system site packages.<br>
<br>
However, if you're adding unittests, you should look at the other ones<br>
which test for libvirt existence and skip the tests if they can't find it.<br>
<div class="im"><br>
> On Fri, Jun 29, 2012 at 6:54 PM, Jay Pipes <<a href="mailto:jaypipes@gmail.com">jaypipes@gmail.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:jaypipes@gmail.com">jaypipes@gmail.com</a>>> wrote:<br>
><br>
>     Hi Leander,<br>
><br>
>     I've noticed some weirdness with the openstack.nose_plugin (which is<br>
>     used by default for the Nova test runner) sometimes either throwing<br>
>     errors (particularly errors raised by nosetests) away and/or coming<br>
>     up with a different set of skip tests than when running just with<br>
>     nosetests.<br>
><br>
>     So, I'd recommend running just this:<br>
><br>
>     ./tools/with_venv.sh nosetests -svx nova<br>
><br>
>     That will stop at the first error and probably will give you better<br>
>     insight into the actual errors that are likely being suppressed by<br>
>     the openstack nose plugin.<br>
><br>
>     best,<br>
>     -jay<br>
><br>
><br>
>     On 06/29/2012 09:02 AM, Leander Bessa Beernaert wrote:<br>
><br>
>         Hello,<br>
><br>
>         I'm sorry to restart the topic<br>
</div>>         (<a href="https://lists.launchpad.net/__openstack/msg13621.html" target="_blank">https://lists.launchpad.net/__openstack/msg13621.html</a><br>
>         <<a href="https://lists.launchpad.net/openstack/msg13621.html" target="_blank">https://lists.launchpad.net/openstack/msg13621.html</a>>), but<br>
<div class="im">>         i accidentally deleted the message in my inbox :S.<br>
><br>
>         I'm still having the same problem, each time i add "import<br>
>         libvirt" to<br>
>         the file "diangostics.py"<br>
</div>>         (<a href="https://review.openstack.org/__#/c/8839/" target="_blank">https://review.openstack.org/__#/c/8839/</a><br>
>         <<a href="https://review.openstack.org/#/c/8839/" target="_blank">https://review.openstack.org/#/c/8839/</a>>) the<br>
<div class="im">>         entire test suit won't run.<br>
><br>
>         *With the import* present i get the following output:<br>
><br>
><br>
><br>
</div>>         ------------------------------__------------------------------__----------<br>
<div class="im">>             Ran 0 tests in 0.000s<br>
>             OK Running PEP8 and HACKING compliance check...<br>
>             2 imports missing in this test environment<br>
><br>
><br>
>         *Without the import *present it get this output:<br>
><br>
><br>
><br>
</div>>         ------------------------------__------------------------------__----------<br>
<div class="im">>             Ran 3030 tests in 233.326s<br>
>             OK (SKIP=22) Running PEP8 and HACKING compliance check...<br>
>             11 imports missing in this test environment<br>
><br>
><br>
><br>
>         The problem now is that, according to the OpenStack conventions, the<br>
>         import must be present. However, with the import present i can't<br>
>         get any<br>
>         of the tests to run.<br>
>         I'm no expert in Python, so could someone please help me out here?<br>
><br>
>         Regards,<br>
><br>
>         Leander<br>
><br>
><br>
</div>>         _________________________________________________<br>
>         Mailing list: <a href="https://launchpad.net/~__openstack" target="_blank">https://launchpad.net/~__openstack</a><br>
<div class="im">>         <<a href="https://launchpad.net/~openstack" target="_blank">https://launchpad.net/~openstack</a>><br>
>         Post to     : <a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a><br>
</div>>         <mailto:<a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a>><br>
>         Unsubscribe : <a href="https://launchpad.net/~__openstack" target="_blank">https://launchpad.net/~__openstack</a><br>
>         <<a href="https://launchpad.net/~openstack" target="_blank">https://launchpad.net/~openstack</a>><br>
>         More help   : <a href="https://help.launchpad.net/__ListHelp" target="_blank">https://help.launchpad.net/__ListHelp</a><br>
>         <<a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a>><br>
><br>
><br>
><br>
>     _________________________________________________<br>
>     Mailing list: <a href="https://launchpad.net/~__openstack" target="_blank">https://launchpad.net/~__openstack</a><br>
<div class="im">>     <<a href="https://launchpad.net/~openstack" target="_blank">https://launchpad.net/~openstack</a>><br>
>     Post to     : <a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a><br>
</div>>     <mailto:<a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a>><br>
>     Unsubscribe : <a href="https://launchpad.net/~__openstack" target="_blank">https://launchpad.net/~__openstack</a><br>
>     <<a href="https://launchpad.net/~openstack" target="_blank">https://launchpad.net/~openstack</a>><br>
>     More help   : <a href="https://help.launchpad.net/__ListHelp" target="_blank">https://help.launchpad.net/__ListHelp</a><br>
<div class="HOEnZb"><div class="h5">>     <<a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a>><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Mailing list: <a href="https://launchpad.net/~openstack" target="_blank">https://launchpad.net/~openstack</a><br>
> Post to     : <a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a><br>
> Unsubscribe : <a href="https://launchpad.net/~openstack" target="_blank">https://launchpad.net/~openstack</a><br>
> More help   : <a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>