<div dir="ltr">On Fri, Nov 24, 2017 at 5:34 PM Piotr Kliczewski <<a href="mailto:piotr.kliczewski@gmail.com">piotr.kliczewski@gmail.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Nov 24, 2017 at 4:00 PM, Piotr Kliczewski<br>
<<a href="mailto:piotr.kliczewski@gmail.com" target="_blank">piotr.kliczewski@gmail.com</a>> wrote:<br>
> On Fri, Nov 24, 2017 at 2:20 PM, Nir Soffer <<a href="mailto:nsoffer@redhat.com" target="_blank">nsoffer@redhat.com</a>> wrote:<br>
>> Adding devel@ovirt, the proper mailing list<br>
>><br>
>> בתאריך יום ו׳, 24 בנוב׳ 2017, 7:42, מאת Germano Veit Michel<br>
>> <<a href="mailto:germano@redhat.com" target="_blank">germano@redhat.com</a>>:<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> I'm trying to write a test for a hook. The test will fail if the hook does<br>
>>> "import hooking", which seems to be the norm for vdsm hooks.<br>
>>><br>
>>> [vdsm_hooks]$ grep -rn "import hooking" | wc -l<br>
>>> 55<br>
>>><br>
>>> Not sure if I'm doing something wrong, but it looks like I would need vdsm<br>
>>> installed on my development machine in order for this import to work.<br>
>>><br>
>>> ======================================================================<br>
>>> ERROR: test suite for <class<br>
>>> 'virttests.boot_hostdev_test.BootHostdevHookTests'><br>
>>> ----------------------------------------------------------------------<br>
>>> Traceback (most recent call last):<br>
>>> File "/usr/lib/python2.7/site-packages/nose/suite.py", line 209, in run<br>
>>> self.setUp()<br>
>>> File "/usr/lib/python2.7/site-packages/nose/suite.py", line 292, in<br>
>>> setUp<br>
>>> self.setupContext(ancestor)<br>
>>> File "/usr/lib/python2.7/site-packages/nose/suite.py", line 315, in<br>
>>> setupContext<br>
>>> try_run(context, names)<br>
>>> File "/usr/lib/python2.7/site-packages/nose/util.py", line 471, in<br>
>>> try_run<br>
>>> return func()<br>
>>> File<br>
>>> "/home/gveitmic/Source/upstream/vdsm/tests/virttests/boot_hostdev_test.py",<br>
>>> line 127, in setUpClass<br>
>>> import before_vm_start as boot_hostdev_hook<br>
>>> File "../vdsm_hooks/boot_hostdev/before_vm_start.py", line 24, in<br>
>>> <module><br>
>>> import hooking<br>
>>> ImportError: No module named hooking<br></blockquote><div><br></div><div>This is expected, hooking is not install in the pyhton path by default.</div><div><br></div><div>All the hooks are using wrong import. Vdsm is "fixing" the bad</div><div>import by modifying the python path.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>>><br>
>>> I can make it go away by using this in my hook:<br>
>>><br>
>>> from vdsm.hook import hooking<br></blockquote><div><br></div><div>This is correct import - I would use this.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>>><br>
>>> Then the test succeeds fine. But then I see all hooks use "import hooking"<br>
>>> instead of "from vdsm.hook import hooking".<br>
>>><br>
>>> [vdsm_hooks]$ grep -rn "from vdsm.hook import hooking" | wc -l<br>
>>> 0<br>
>>><br>
>>> Am I doing something wrong? Can someone put a light here? What is the<br>
>>> correct way to do this import?<br>
><br>
> Our approach for it is to modify PYTHONPATH [1] where we add vdsm.hook.<br>
> It looks like we do not have similar update in [2] - script which run the tests.<br>
><br>
> I will push a patch to fix it.<br>
<br>
<a href="https://gerrit.ovirt.org/#/c/84638/" rel="noreferrer" target="_blank">https://gerrit.ovirt.org/#/c/84638/</a><br>
<br>
Please check whether it would work for you now.<br></blockquote><div><br></div><div>This can be handy for testing legacy hooks, but I think we should</div><div>fix the imports instead, so no manipulation of python path is needed.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
><br>
> [1] <a href="https://github.com/oVirt/vdsm/blob/master/lib/vdsm/hooks.py#L98" rel="noreferrer" target="_blank">https://github.com/oVirt/vdsm/blob/master/lib/vdsm/hooks.py#L98</a><br>
> [2] <a href="https://github.com/oVirt/vdsm/blob/master/tests/run_tests_local.sh.in#L21" rel="noreferrer" target="_blank">https://github.com/oVirt/vdsm/blob/master/tests/run_tests_local.sh.in#L21</a><br>
><br>
>>><br>
>>> Thanks,<br>
>>> Germano<br>
>><br>
>><br>
>> _______________________________________________<br>
>> Devel mailing list<br>
>> <a href="mailto:Devel@ovirt.org" target="_blank">Devel@ovirt.org</a><br>
>> <a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>