Francesco Romani has uploaded a new change for review.

Change subject: tests: clear libvirtconnection cache
......................................................................

tests: clear libvirtconnection cache

the libvirtconnection has a connection cache,
and this caching doesn't playe well with the monkeypatching
which we do in tests. This leads to fake libvirt objects
persist in the python process.

This failure is evident only during 'make check'-like runs,
when global state is preserved across test suites.

The failure presents itself like the following:

Traceback (most recent call last):
  File "/root/src/vdsm/tests/testValidation.py", line 105, in wrapper
    return f(*args, **kwargs)
  File "/root/src/vdsm/tests/samplingTests.py", line 172, in
testHostSampleHandlesDisappearingVlanInterfaces
    hs = sampling.HostSample(os.getpid())
  File "/root/src/vdsm/vdsm/virt/sampling.py", line 281, in __init__
    self.numaNodeMem = NumaNodeMemorySample()
  File "/root/src/vdsm/vdsm/virt/sampling.py", line 173, in __init__
    memInfo = caps.getMemoryStatsByNumaCell(int(nodeIndex))
  File "/root/src/vdsm/vdsm/caps.py", line 358, in
getMemoryStatsByNumaCell
    cellMemInfo = conn.getMemoryStats(cell, 0)
AttributeError: 'virConnect' object has no attribute 'getMemoryStats'

This patch fixes this error clearing the libvirtconnection cache
when its tests are completed.

Change-Id: If4d64920e5f26c276accf26b7a532461d04f02df
Signed-off-by: Francesco Romani <[email protected]>
---
M lib/vdsm/libvirtconnection.py
M tests/libvirtconnectionTests.py
2 files changed, 13 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/47/37747/1

diff --git a/lib/vdsm/libvirtconnection.py b/lib/vdsm/libvirtconnection.py
index 492a02e..56f48ae 100644
--- a/lib/vdsm/libvirtconnection.py
+++ b/lib/vdsm/libvirtconnection.py
@@ -102,6 +102,14 @@
     return utils.retry(libvirtOpen, timeout=10, sleep=0.2)
 
 
+def clear():
+    """
+    for debug purposes only
+    """
+    with __connectionLock:
+        __connections.clear()
+
+
 def get(target=None, killOnFailure=True):
     """Return current connection to libvirt or open a new one.
     Use target to get/create the connection object linked to that object.
diff --git a/tests/libvirtconnectionTests.py b/tests/libvirtconnectionTests.py
index 43fde60..2fa781c 100644
--- a/tests/libvirtconnectionTests.py
+++ b/tests/libvirtconnectionTests.py
@@ -104,6 +104,11 @@
 
 
 class testLibvirtconnection(TestCaseBase):
+
+    @classmethod
+    def tearDownClass(cls):
+        libvirtconnection.clear()
+
     @MonkeyPatch(libvirtconnection, 'libvirt', LibvirtMock())
     @MonkeyPatch(constants, 'P_VDSM_LIBVIRT_PASSWD', '/dev/null')
     def testCallSucceeded(self):


-- 
To view, visit http://gerrit.ovirt.org/37747
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If4d64920e5f26c276accf26b7a532461d04f02df
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to