[libvirt] [PATCH test-API 1/2] lib: pass instance of ConnectAPI into other lib modules

Guannan Ren gren at redhat.com
Mon Mar 26 17:18:08 UTC 2012


     This change make any instance of subclasses in libvirt.py
     invisible to testcases in order to catch libvirtError.

       connectAPI.py
       domainAPI.py
       interfaceAPI.py
       networkAPI.py
       nodedevAPI.py
       nwfilterAPI.py
       secretAPI.py
       snapshotAPI.py
       storageAPI.py
       streamAPI.py
---
 lib/connectAPI.py   |   21 +++++++++++----------
 lib/domainAPI.py    |    2 +-
 lib/interfaceAPI.py |    2 +-
 lib/networkAPI.py   |    2 +-
 lib/nodedevAPI.py   |    2 +-
 lib/nwfilterAPI.py  |    2 +-
 lib/secretAPI.py    |    2 +-
 lib/snapshotAPI.py  |    2 +-
 lib/storageAPI.py   |    2 +-
 lib/streamAPI.py    |    5 +++--
 10 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/lib/connectAPI.py b/lib/connectAPI.py
index 9f2b728..796df33 100644
--- a/lib/connectAPI.py
+++ b/lib/connectAPI.py
@@ -39,36 +39,37 @@ append_path(result.group(0))
 import exception
 
 class ConnectAPI(object):
-    def __init__(self):
+    def __init__(self, uri):
+        self.uri = uri
         self.conn = None
 
-    def open(self, uri):
+    def open(self):
         try:
-            self.conn = libvirt.open(uri)
-            return self.conn
+            self.conn = libvirt.open(self.uri)
         except libvirt.libvirtError, e:
             message = e.get_error_message()
             code = e.get_error_code()
             raise exception.LibvirtAPI(message, code)
 
-    def open_read_only(self, uri):
+    def open_read_only(self):
         try:
-            self.conn = libvirt.openReadOnly(uri)
-            return self.conn
+            self.conn = libvirt.openReadOnly(self.uri)
         except libvirt.libvirtError, e:
             message = e.get_error_message()
             code = e.get_error_code()
             raise exception.LibvirtAPI(message, code)
 
-    def openAuth(self, uri, auth, flags = 0):
+    def openAuth(self, auth, flags = 0):
         try:
-            self.conn = libvirt.openAuth(uri, auth, flags)
-            return self.conn
+            self.conn = libvirt.openAuth(self.uri, auth, flags)
         except libvirt.libvirtError, e:
             message = e.get_error_message()
             code = e.get_error_code()
             raise exception.LibvirtAPI(message, code)
 
+    def get_conn(self):
+        return self.conn
+
     def get_caps(self):
         try:
             caps = self.conn.getCapabilities()
diff --git a/lib/domainAPI.py b/lib/domainAPI.py
index 43565c2..e38acb6 100644
--- a/lib/domainAPI.py
+++ b/lib/domainAPI.py
@@ -42,7 +42,7 @@ import exception
 
 class DomainAPI(object):
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def get_list(self):
         dom_list = []
diff --git a/lib/interfaceAPI.py b/lib/interfaceAPI.py
index 1abf861..2f4c13b 100644
--- a/lib/interfaceAPI.py
+++ b/lib/interfaceAPI.py
@@ -44,7 +44,7 @@ VIR_INTERFACE_ERROR = -1
 
 class InterfaceAPI(object):
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def get_active_list(self):
         try:
diff --git a/lib/networkAPI.py b/lib/networkAPI.py
index d28f699..e0f0721 100644
--- a/lib/networkAPI.py
+++ b/lib/networkAPI.py
@@ -39,7 +39,7 @@ import exception
 
 class NetworkAPI(object):
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def define(self, netxmldesc):
         try:
diff --git a/lib/nodedevAPI.py b/lib/nodedevAPI.py
index 64fc4b8..4ce3cf1 100644
--- a/lib/nodedevAPI.py
+++ b/lib/nodedevAPI.py
@@ -40,7 +40,7 @@ import exception
 
 class NodedevAPI:
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def create(self, device_xml):
         try:
diff --git a/lib/nwfilterAPI.py b/lib/nwfilterAPI.py
index 9cf7050..4f5c58f 100644
--- a/lib/nwfilterAPI.py
+++ b/lib/nwfilterAPI.py
@@ -39,7 +39,7 @@ import exception
 
 class nwfilterAPI(object):
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def get_list(self):
         try:
diff --git a/lib/secretAPI.py b/lib/secretAPI.py
index 4aac27f..149517c 100644
--- a/lib/secretAPI.py
+++ b/lib/secretAPI.py
@@ -39,7 +39,7 @@ import exception
 
 class SecretAPI(object):
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def get_defined_list(self):
         try:
diff --git a/lib/snapshotAPI.py b/lib/snapshotAPI.py
index d363992..865f18b 100644
--- a/lib/snapshotAPI.py
+++ b/lib/snapshotAPI.py
@@ -39,7 +39,7 @@ import exception
 
 class SnapshotAPI(object):
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def create(self, domname, xml_desc, flag = 0):
 	try:
diff --git a/lib/storageAPI.py b/lib/storageAPI.py
index 6c9d286..9902107 100644
--- a/lib/storageAPI.py
+++ b/lib/storageAPI.py
@@ -45,7 +45,7 @@ VIR_STORAGE_POOL_DEGRADED = 3
 
 class StorageAPI(object):
     def __init__(self, connection):
-        self.conn = connection
+        self.conn = connection.get_conn()
 
     def define_pool(self, storage_xml):
         try:
diff --git a/lib/streamAPI.py b/lib/streamAPI.py
index 0dfda28..972337d 100644
--- a/lib/streamAPI.py
+++ b/lib/streamAPI.py
@@ -38,9 +38,10 @@ append_path(result.group(0))
 import exception
 
 class StreamAPI(object):
-    def __init__(self, conn, flags = 0):
+    def __init__(self, connection, flags = 0):
         try:
-            self.stream = conn.newStream(flags)
+            self.conn = connection.get_conn()
+            self.stream = self.conn.newStream(flags)
         except libvirt.libvirtError, e:
             message = e.get_error_message()
             code = e.get_error_code()
-- 
1.7.7.5




More information about the libvir-list mailing list