The get_conn function return connection object from libvirt module. This function could be used by both framework and testcases. The patch includes: * get_conn in utils/utils.py * sync env_inspect.py using the new function Signed-off-by: Wayne Sun <gsun@xxxxxxxxxx> --- src/env_inspect.py | 22 ++-------------------- utils/utils.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/env_inspect.py b/src/env_inspect.py index b260ff8..2c1a701 100644 --- a/src/env_inspect.py +++ b/src/env_inspect.py @@ -20,6 +20,7 @@ import commands import libvirt import sharedmod +from utils import utils def check_libvirt(logger): virsh = 'virsh -v' @@ -68,20 +69,6 @@ def hostinfo(logger): return 1 return 0 -def request_credentials(credentials, user_data): - for credential in credentials: - if credential[0] == libvirt.VIR_CRED_AUTHNAME: - credential[4] = user_data[0] - - if len(credential[4]) == 0: - credential[4] = credential[3] - elif credential[0] == libvirt.VIR_CRED_PASSPHRASE: - credential[4] = user_data[1] - else: - return -1 - - return 0 - def sharemod_init(env_parser, logger): """ get connection object from libvirt module initialize sharemod for use by testcases @@ -89,12 +76,7 @@ def sharemod_init(env_parser, logger): uri = env_parser.get_value('variables', 'defaulturi') username = env_parser.get_value('variables', 'username') password = env_parser.get_value('variables', 'password') - user_data = [username, password] - auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], request_credentials, user_data] - conn = libvirt.openAuth(uri, auth, 0) - if not conn: - logger.error("Failed to setup libvirt connection"); - return 1 + conn = utils.get_conn(uri, username, password) # initialize conn object in sharedmod sharedmod.libvirtobj.clear() diff --git a/utils/utils.py b/utils/utils.py index be87cdc..eade10d 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -29,6 +29,7 @@ import struct import pexpect import string import subprocess +import libvirt from xml.dom import minidom from urlparse import urlparse @@ -57,6 +58,32 @@ def get_uri(ip): uri = "qemu+ssh://%s/system" % ip return uri +def request_credentials(credentials, user_data): + for credential in credentials: + if credential[0] == libvirt.VIR_CRED_AUTHNAME: + credential[4] = user_data[0] + + if len(credential[4]) == 0: + credential[4] = credential[3] + elif credential[0] == libvirt.VIR_CRED_PASSPHRASE: + credential[4] = user_data[1] + else: + return -1 + + return 0 + +def get_conn(uri='', username='', password=''): + """ get connection object from libvirt module + """ + user_data = [username, password] + auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], request_credentials, user_data] + conn = libvirt.openAuth(uri, auth, 0) + if not conn: + logger.error("Failed to setup libvirt connection"); + sys.exit(1) + else: + return conn + def parse_uri(uri): # This is a simple parser for uri return urlparse(uri) -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list