[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [test-API PATCH 3/7] domainAPI: Add wrapper method to work with domain's console connections



On 03/21/2012 05:02 PM, Guannan Ren wrote:
On 03/21/2012 08:46 PM, Peter Krempa wrote:
This patch adds a wrapper that enables work with consoles in the
test-API.
---
lib/domainAPI.py | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/lib/domainAPI.py b/lib/domainAPI.py
index 91f2ba3..bc0069b 100644
--- a/lib/domainAPI.py
+++ b/lib/domainAPI.py
@@ -878,6 +878,15 @@ class DomainAPI(object):
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)

+ def openConsole(self, domname, device, stream, flags = 0):
+ try:
+ dom_obj = self.get_domain_by_name(domname)
+ st_obj = stream.getStream()


we could get the st_obj in testcase then pass it into openConsole
If so, st_obj could be reused in the following statement in testcase
like:

st_obj = stream.getStream()
dom.openConsole(domname, None, st_obj)
receivedData = st_obj.recv(1024)
(the last statement probably resides in a registered stream callback
function via eventAddCallback API)

Wouldn't this actualy defeat the encapsulation that is provided in the StreamAPI class? With this change you can reuse the StreamAPI object for other actions later on too, without loosing the abstraction.

With the chagne you pushed:
diff --git a/lib/domainAPI.py b/lib/domainAPI.py
index 91f2ba3..ddcdc91 100644
--- a/lib/domainAPI.py
+++ b/lib/domainAPI.py
@@ -878,6 +878,14 @@ class DomainAPI(object):
             code = e.get_error_code()
             raise exception.LibvirtAPI(message, code)

+    def openConsole(self, domname, device, st_obj, flags = 0):
+        try:
+            dom_obj = self.get_domain_by_name(domname)
+            return dom_obj.openConsole(device, st_obj, flags)
+        except libvirt.libvirtError, e:
+            message = e.get_error_message()
+            code = e.get_error_code()
+            raise exception.LibvirtAPI(message, code)

You have to create a new StreamAPI object with DomainAPI.newStream() and then you have to extract the virStream object from that to pass it manualy to DomainAPI.openConsole(). IMO this will encourage to use the virStream object directly without the encapsulation that is provided by the StreamAPI class.

Peter




Thanks for the patch.

Guannan Ren

--
libvir-list mailing list
libvir-list redhat com
https://www.redhat.com/mailman/listinfo/libvir-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]