On 03/29/2012 05:14 PM, Martin Kletzander wrote:
On 03/26/2012 07:18 PM, Guannan Ren wrote:
> 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()
>
This is one option how to keep the object, however maybe we can make use
of the encapsulation everywhere, not just in the test cases, but this
would require rewriting a lot more code and is not needed at this point.
yes, I agree.
ACK with the second patch modified as written in it.
Martin
Thanks and pushed.
Guannan Ren