Dan Kenigsberg has submitted this change and it was merged.
Change subject: tests: fix AttributeError: 'module' object has no attribute
'ifcfg'
......................................................................
tests: fix AttributeError: 'module' object has no attribute 'ifcfg'
... when running unit tests with other network configurators than ifcfg.
In configNetworkTests, ifcfg configurator's functions that would have
an effect on host networking (had network.api validation been broken)
are disabled by monkey patching.
This targets only ifcfg configurator (whose ifup and ifdown functions
are very dangerous), and it also works only when net_configurator
is set to 'ifcfg' (which is the default) in /etc/vdsm/vdsm.conf
It ends up with AttributeError when other configurators are chosen.
Why?
Consider first how the following code could work, given that only 'api'
module and 'configurators' package used to be imported from 'network'
package in configNetworkTests:
@MonkeyPatch(configurators.ifcfg, 'ifdown', lambda *x:
_raiseInvalidOpException())
The answer is, a side effect of importing 'api', which itself imports
the chosen network configurator in a module-level call to its
_getConfiguratorClass() function.
It is probably more clear now, that network.configurators.ifcfg (or iproute2)
can only be used after it is imported. We got ifcfg configurator imported
"for free", but this doesn't work when it is now configured in vdsm.conf
The example below makes the point.
>> import network.configurators
>> network.configurators.ifcfg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ifcfg'
>> import network.configurators.ifcfg
(This is what
network.api does when ifcfg configurator is configured,
and what importing of network.api indirectly causes.)
>> network.configurators.ifcfg
<module
'network.configurators.ifcfg' from 'network/configurators/ifcfg.pyc'>
Change-Id: Ibe715c9f4c0f6b2b832f897467ba551416c52432
Signed-off-by: Ondřej Svoboda <osvoboda(a)redhat.com>
Reviewed-on:
https://gerrit.ovirt.org/31108
Continuous-Integration: Jenkins CI
Reviewed-by: Ido Barkan <ibarkan(a)redhat.com>
Reviewed-by: Dan Kenigsberg <danken(a)redhat.com>
---
M tests/configNetworkTests.py
1 file changed, 4 insertions(+), 5 deletions(-)
Approvals:
Ido Barkan: Looks good to me, but someone else must approve
Ondřej Svoboda: Verified
Jenkins CI: Passed CI tests
Dan Kenigsberg: Looks good to me, approved
--
To view, visit
https://gerrit.ovirt.org/31108
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe715c9f4c0f6b2b832f897467ba551416c52432
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda(a)redhat.com>
Gerrit-Reviewer: Antoni Segura Puimedon <toni+ovirt(a)midokura.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Ido Barkan <ibarkan(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Ondřej Svoboda <osvoboda(a)redhat.com>
Gerrit-Reviewer: Petr Horáček <phoracek(a)redhat.com>
Gerrit-Reviewer: automation(a)ovirt.org