[libvirt] [PATCH 1/2] make remote_exec_pexpect return the output of command

*utils/Python/utils.py return 0,child.before intead *repos/remoteAccess/tcp_setup.py repos/remoteAccess/tls_setup.py switch over to use new remote_exec_pexpect() --- repos/remoteAccess/tcp_setup.py | 18 +++++++++--------- repos/remoteAccess/tls_setup.py | 20 ++++++++++---------- utils/Python/utils.py | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/repos/remoteAccess/tcp_setup.py b/repos/remoteAccess/tcp_setup.py index 8f88810..b3877f7 100644 --- a/repos/remoteAccess/tcp_setup.py +++ b/repos/remoteAccess/tcp_setup.py @@ -56,7 +56,7 @@ def sasl_user_add(target_machine, username, password, util, logger): """ execute saslpasswd2 to add sasl user """ logger.info("add sasl user on server side") saslpasswd2_add = "echo %s | %s -a libvirt %s" % (password, SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_add) if ret: logger.error("failed to add sasl user") @@ -70,7 +70,7 @@ def tcp_libvirtd_set(target_machine, username, password, logger.info("setting libvirtd.conf on libvirt server") # open libvirtd --listen option listen_open_cmd = "echo 'LIBVIRTD_ARGS=\"--listen\"' >> %s" % SYSCONFIG_LIBVIRTD - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_open_cmd) if ret: logger.error("failed to uncomment --listen in %s" % SYSCONFIG_LIBVIRTD) @@ -79,7 +79,7 @@ def tcp_libvirtd_set(target_machine, username, password, # set listen_tls logger.info("set listen_tls to 0 in %s" % LIBVIRTD_CONF) listen_tls_disable = "echo \"listen_tls = 0\" >> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_tls_disable) if ret: logger.error("failed to set listen_tls to 0 in %s" % LIBVIRTD_CONF) @@ -89,7 +89,7 @@ def tcp_libvirtd_set(target_machine, username, password, if listen_tcp == 'enable': logger.info("enable listen_tcp = 1 in %s" % LIBVIRTD_CONF) listen_tcp_set = "echo 'listen_tcp = 1' >> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_tcp_set) if ret: logger.error("failed to set listen_tcp in %s" % LIBVIRTD_CONF) @@ -98,7 +98,7 @@ def tcp_libvirtd_set(target_machine, username, password, # set auth_tcp logger.info("set auth_tcp to \"%s\" in %s" % (auth_tcp, LIBVIRTD_CONF)) auth_tcp_set = "echo 'auth_tcp = \"%s\"' >> %s" % (auth_tcp, LIBVIRTD_CONF) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, auth_tcp_set) if ret: logger.error("failed to set auth_tcp in %s" % LIBVIRTD_CONF) @@ -107,7 +107,7 @@ def tcp_libvirtd_set(target_machine, username, password, # restart remote libvirtd service libvirtd_restart_cmd = "service libvirtd restart" logger.info("libvirtd restart") - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirtd_restart_cmd) if ret: logger.error("failed to restart libvirtd service") @@ -225,18 +225,18 @@ def tcp_setup_clean(params): if auth_tcp == 'sasl': saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_delete) if ret: logger.error("failed to delete sasl user") libvirtd_conf_retore = "sed -i -n '/^[ #]/p' %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirtd_conf_retore) if ret: logger.error("failed to restore %s" % LIBVIRTD_CONF) sysconfig_libvirtd_restore = "sed -i -n '/^[ #]/p' %s" % SYSCONFIG_LIBVIRTD - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, sysconfig_libvirtd_restore) if ret: logger.error("failed to restore %s" % SYSCONFIG_LIBVIRTD) diff --git a/repos/remoteAccess/tls_setup.py b/repos/remoteAccess/tls_setup.py index 4e7f24e..27bb8a7 100644 --- a/repos/remoteAccess/tls_setup.py +++ b/repos/remoteAccess/tls_setup.py @@ -213,7 +213,7 @@ def deliver_cert(target_machine, username, password, pkipath, util, logger): # mkdir /etc/pki/libvirt/private on remote host libvirt_priv_cmd = "mkdir -p %s" % PRIVATE_KEY_FOLDER - ret = util.remote_exec_pexpect(target_machine, username, password, libvirt_priv_cmd) + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirt_priv_cmd) if ret: logger.error("failed to make /etc/pki/libvirt/private on %s" % target_machine) return 1 @@ -257,7 +257,7 @@ def sasl_user_add(target_machine, username, password, util, logger): """ execute saslpasswd2 to add sasl user """ logger.info("add sasl user on server side") saslpasswd2_add = "echo %s | %s -a libvirt %s" % (password, SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_add) if ret: logger.error("failed to add sasl user") @@ -271,7 +271,7 @@ def tls_libvirtd_set(target_machine, username, password, logger.info("setting libvirtd.conf on tls server") # open libvirtd --listen option listen_open_cmd = "echo 'LIBVIRTD_ARGS=\"--listen\"' >> /etc/sysconfig/libvirtd" - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_open_cmd) if ret: logger.error("failed to uncomment --listen in /etc/sysconfig/libvirtd") @@ -280,7 +280,7 @@ def tls_libvirtd_set(target_machine, username, password, if listen_tls == 'disable': logger.info("set listen_tls to 0 in %s" % LIBVIRTD_CONF) listen_tls_disable = "echo \"listen_tls = 0\" >> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_tls_disable) if ret: logger.error("failed to set listen_tls to 0 in %s" % LIBVIRTD_CONF) @@ -289,7 +289,7 @@ def tls_libvirtd_set(target_machine, username, password, if auth_tls == 'sasl': logger.info("enable auth_tls = sasl in %s" % LIBVIRTD_CONF) auth_tls_set = "echo 'auth_tls = \"sasl\"' >> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, auth_tls_set) if ret: logger.error("failed to set auth_tls to sasl in %s" % LIBVIRTD_CONF) @@ -298,7 +298,7 @@ def tls_libvirtd_set(target_machine, username, password, # restart remote libvirtd service libvirtd_restart_cmd = "service libvirtd restart" logger.info("libvirtd restart") - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirtd_restart_cmd) if ret: logger.error("failed to restart libvirtd service") @@ -311,7 +311,7 @@ def iptables_stop(target_machine, username, password, util, logger): """ This is a temprory method in favor of migration """ logger.info("stop local and remote iptables temprorily") iptables_stop_cmd = "service iptables stop" - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, iptables_stop_cmd) if ret: logger.error("failed to stop remote iptables service") @@ -466,13 +466,13 @@ def tls_setup_clean(params): util = utils.Utils() cacert_rm = "rm -f %s/cacert.pem" % CA_FOLDER - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, cacert_rm) if ret: logger.error("failed to remove cacert.pem on remote machine") ca_libvirt_rm = "rm -rf %s" % CERTIFICATE_FOLDER - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, ca_libvirt_rm) if ret: logger.error("failed to remove libvirt folder") @@ -482,7 +482,7 @@ def tls_setup_clean(params): if auth_tls == 'sasl': saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_delete) if ret: logger.error("failed to delete sasl user") diff --git a/utils/Python/utils.py b/utils/Python/utils.py index 6787e87..d521254 100644 --- a/utils/Python/utils.py +++ b/utils/Python/utils.py @@ -406,10 +406,10 @@ class Utils(object): child.sendline(password) elif index == 2: child.close() - return 0 + return 0, child.before elif index == 3: child.close() - return 1 + return 1, "" return 0 -- 1.7.1

*repos/domain/cpu_topology.py --- repos/domain/cpu_topology.py | 248 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 248 insertions(+), 0 deletions(-) create mode 100644 repos/domain/cpu_topology.py diff --git a/repos/domain/cpu_topology.py b/repos/domain/cpu_topology.py new file mode 100644 index 0000000..7202559 --- /dev/null +++ b/repos/domain/cpu_topology.py @@ -0,0 +1,248 @@ +#!/usr/bin/env python +""" To test guest cpu topology + domain:cpu_topology + guestname + xxx + username + root + password + xxxxxx + sockets + 2 + cores + 1 + threads + 2 +""" + +__author__ = 'Guannan Ren: gren@redhat.com' +__date__ = 'Tue Aug 30, 2011' +__version__ = '0.1.0' +__credits__ = 'Copyright (C) 2011 Red Hat, Inc.' +__all__ = [] + +import os +import re +import sys +import time +from xml.dom import minidom + +def append_path(path): + """Append root path of package""" + if path in sys.path: + pass + else: + sys.path.append(path) + +pwd = os.getcwd() +result = re.search('(.*)libvirt-test-API', pwd) +append_path(result.group(0)) + +from lib import connectAPI +from lib import domainAPI +from utils.Python import utils +from exception import LibvirtAPI + +def check_params(params): + """check out the arguments requried for testing""" + logger = params['logger'] + keys = ['guestname', 'username', 'password', + 'sockets', 'cores', 'threads'] + for key in keys: + if key not in params: + logger.error("Argument %s is required" % key) + return 1 + return 0 + +def check_domain_running(domobj, guestname, logger): + """check if the domain exists, may or may not be active""" + defined_guest_names = domobj.get_defined_list() + + if guestname not in defined_guest_names: + logger.error("%s doesn't exist or still in running" % guestname) + return 1 + else: + return 0 + +def add_cpu_xml(domobj, guestname, sockets, cores, threads, logger): + """edit domain xml description and insert <cpu> element""" + + guestxml = domobj.get_xml_desc(guestname) + logger.debug('''original guest %s xml :\n%s''' %(guestname, guestxml)) + + doc = minidom.parseString(guestxml) + cpu = doc.createElement('cpu') + topology = doc.createElement('topology') + topology.setAttribute('sockets', sockets) + topology.setAttribute('cores', cores) + topology.setAttribute('threads', threads) + cpu.appendChild(topology) + + vcpuval = int(sockets) * int(cores) * int(threads) + newvcpu = doc.createElement('vcpu') + newvcpuval = doc.createTextNode(str(vcpuval)) + newvcpu.appendChild(newvcpuval) + oldvcpu = doc.getElementsByTagName('vcpu')[0] + + domain = doc.getElementsByTagName('domain')[0] + domain.appendChild(cpu) + domain.replaceChild(newvcpu, oldvcpu) + + return doc.toxml() + +def guest_undefine(domobj, guestname, logger): + """undefine original guest""" + try: + logger.info("undefine guest") + domobj.undefine(guestname) + logger.info("undefine the domain is successful") + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("fail to undefine domain") + return 1 + + return 0 + +def guest_define(domobj, domxml, logger): + """define new guest xml""" + try: + logger.info("define guest") + domobj.define(domxml) + logger.info("success to define new domain xml description") + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("fail to define domain") + return 1 + + return 0 + +def guest_start(domobj, guestname, util, logger): + """start guest""" + timeout = 600 + ip = '' + mac = util.get_dom_mac_addr(guestname) + + try: + logger.info("start guest") + domobj.start(guestname) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("fail to start domain") + return 1 + + while timeout: + time.sleep(10) + timeout -= 10 + + ip = util.mac_to_ip(mac, 180) + + if not ip: + logger.info(str(timeout) + "s left") + else: + logger.info("vm %s power on successfully" % guestname) + logger.info("the ip address of vm %s is %s" % (guestname, ip)) + break + + if timeout <= 0: + logger.info("fail to power on vm %s" % guestname) + return 1, ip + + return 0, ip + +def cpu_topology_check(ip, username, password, + sockets, cores, threads, util, logger): + """login the guest, run lscpu command to check the result""" + lscpu = "lscpu" + # sleep for 5 seconds + time.sleep(40) + ret, output = util.remote_exec_pexpect(ip, username, password, lscpu) + logger.debug("lscpu:") + logger.debug(output) + if ret: + logger.error("failed to run lscpu on guest OS") + return 1 + + int = 0 + actual_thread = actual_core = actual_socket = '' + + for item in output.strip().split('\r'): + if int == 5: + actual_thread = item.split()[-1] + logger.info("the actual thread in the guest is %s" % actual_thread) + if int == 6: + actual_core = item.split()[-1] + logger.info("the actual core in the guest is %s" % actual_core) + if int == 7: + actual_socket = item.split()[-1] + logger.info("the actual socket in the guest is %s" % actual_socket) + + int += 1 + + if actual_thread == '' or actual_core == '' or actual_socket == '': + logger.error("No data was retrieved") + return 1 + + if actual_thread == threads and actual_core == cores and actual_socket == sockets: + return 0 + else: + logger.error("The data doesn't match!!!") + return 1 + +def cpu_topology(params): + """ edit domain xml description according to the values + and login to the guest to check the results + """ + logger = params['logger'] + params_check_result = check_params(params) + if params_check_result: + return 1 + + guestname = params['guestname'] + username = params['username'] + password = params['password'] + sockets = params['sockets'] + cores = params['cores'] + threads = params['threads'] + + logger.info("guestname is %s" % guestname) + logger.info("sockets is %s" % sockets) + logger.info("cores is %s" % cores) + logger.info("threads is %s" % threads) + + util = utils.Utils() + uri = util.get_uri('127.0.0.1') + + logger.info("the uri is %s" % uri) + conn = connectAPI.ConnectAPI() + virconn = conn.open(uri) + domobj = domainAPI.DomainAPI(virconn) + + if check_domain_running(domobj, guestname, logger): + conn.close() + return 1 + + domxml = add_cpu_xml(domobj, guestname, sockets, cores, threads, logger) + + if guest_undefine(domobj, guestname, logger): + conn.close() + return 1 + + if guest_define(domobj, domxml, logger): + conn.close() + return 1 + + ret, ip = guest_start(domobj, guestname, util, logger) + if ret: + conn.close() + return 1 + + if cpu_topology_check(ip, username, password, + sockets, cores, threads, util, logger): + conn.close() + return 1 + + conn.close() + return 0 -- 1.7.1

On 09/01/2011 10:19 AM, Guannan Ren wrote:
*repos/domain/cpu_topology.py --- repos/domain/cpu_topology.py | 248 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 248 insertions(+), 0 deletions(-) create mode 100644 repos/domain/cpu_topology.py
diff --git a/repos/domain/cpu_topology.py b/repos/domain/cpu_topology.py new file mode 100644 index 0000000..7202559 --- /dev/null +++ b/repos/domain/cpu_topology.py @@ -0,0 +1,248 @@ +#!/usr/bin/env python +""" To test guest cpu topology + domain:cpu_topology + guestname + xxx + username + root + password + xxxxxx + sockets + 2 + cores + 1 + threads + 2 +""" + +__author__ = 'Guannan Ren: gren@redhat.com' +__date__ = 'Tue Aug 30, 2011' +__version__ = '0.1.0' +__credits__ = 'Copyright (C) 2011 Red Hat, Inc.' +__all__ = [] + +import os +import re +import sys +import time +from xml.dom import minidom + +def append_path(path): + """Append root path of package""" + if path in sys.path: + pass + else: + sys.path.append(path) + +pwd = os.getcwd() +result = re.search('(.*)libvirt-test-API', pwd) +append_path(result.group(0)) + +from lib import connectAPI +from lib import domainAPI +from utils.Python import utils +from exception import LibvirtAPI + +def check_params(params): + """check out the arguments requried for testing""" + logger = params['logger'] + keys = ['guestname', 'username', 'password', + 'sockets', 'cores', 'threads'] + for key in keys: + if key not in params: + logger.error("Argument %s is required" % key) + return 1 + return 0 + +def check_domain_running(domobj, guestname, logger): + """check if the domain exists, may or may not be active""" + defined_guest_names = domobj.get_defined_list() + + if guestname not in defined_guest_names: + logger.error("%s doesn't exist or still in running" % guestname) + return 1 + else: + return 0 + +def add_cpu_xml(domobj, guestname, sockets, cores, threads, logger): + """edit domain xml description and insert<cpu> element""" + + guestxml = domobj.get_xml_desc(guestname) + logger.debug('''original guest %s xml :\n%s''' %(guestname, guestxml)) + + doc = minidom.parseString(guestxml) + cpu = doc.createElement('cpu') + topology = doc.createElement('topology') + topology.setAttribute('sockets', sockets) + topology.setAttribute('cores', cores) + topology.setAttribute('threads', threads) + cpu.appendChild(topology) + + vcpuval = int(sockets) * int(cores) * int(threads) + newvcpu = doc.createElement('vcpu') + newvcpuval = doc.createTextNode(str(vcpuval)) + newvcpu.appendChild(newvcpuval) + oldvcpu = doc.getElementsByTagName('vcpu')[0] + + domain = doc.getElementsByTagName('domain')[0] + domain.appendChild(cpu) + domain.replaceChild(newvcpu, oldvcpu) + + return doc.toxml() + +def guest_undefine(domobj, guestname, logger): + """undefine original guest""" + try: + logger.info("undefine guest") + domobj.undefine(guestname) + logger.info("undefine the domain is successful") + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("fail to undefine domain") + return 1 + + return 0 + +def guest_define(domobj, domxml, logger): + """define new guest xml""" + try: + logger.info("define guest") + domobj.define(domxml) + logger.info("success to define new domain xml description") + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("fail to define domain") + return 1 + + return 0 + +def guest_start(domobj, guestname, util, logger): + """start guest""" + timeout = 600 + ip = '' + mac = util.get_dom_mac_addr(guestname) + + try: + logger.info("start guest") + domobj.start(guestname) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("fail to start domain") + return 1 + + while timeout: + time.sleep(10) + timeout -= 10 + + ip = util.mac_to_ip(mac, 180) + + if not ip: + logger.info(str(timeout) + "s left") + else: + logger.info("vm %s power on successfully" % guestname) + logger.info("the ip address of vm %s is %s" % (guestname, ip)) + break + + if timeout<= 0: + logger.info("fail to power on vm %s" % guestname) + return 1, ip + + return 0, ip + +def cpu_topology_check(ip, username, password, + sockets, cores, threads, util, logger): + """login the guest, run lscpu command to check the result""" + lscpu = "lscpu" + # sleep for 5 seconds + time.sleep(40) + ret, output = util.remote_exec_pexpect(ip, username, password, lscpu) + logger.debug("lscpu:") + logger.debug(output) + if ret: + logger.error("failed to run lscpu on guest OS") + return 1 + + int = 0 + actual_thread = actual_core = actual_socket = '' + + for item in output.strip().split('\r'): + if int == 5: + actual_thread = item.split()[-1] + logger.info("the actual thread in the guest is %s" % actual_thread) + if int == 6: + actual_core = item.split()[-1] + logger.info("the actual core in the guest is %s" % actual_core) + if int == 7: + actual_socket = item.split()[-1] + logger.info("the actual socket in the guest is %s" % actual_socket) + + int += 1 + + if actual_thread == '' or actual_core == '' or actual_socket == '': + logger.error("No data was retrieved") + return 1 + + if actual_thread == threads and actual_core == cores and actual_socket == sockets: + return 0 + else: + logger.error("The data doesn't match!!!") + return 1 + +def cpu_topology(params): + """ edit domain xml description according to the values + and login to the guest to check the results + """ + logger = params['logger'] + params_check_result = check_params(params) + if params_check_result: + return 1 + + guestname = params['guestname'] + username = params['username'] + password = params['password'] + sockets = params['sockets'] + cores = params['cores'] + threads = params['threads'] + + logger.info("guestname is %s" % guestname) + logger.info("sockets is %s" % sockets) + logger.info("cores is %s" % cores) + logger.info("threads is %s" % threads) + + util = utils.Utils() + uri = util.get_uri('127.0.0.1') + + logger.info("the uri is %s" % uri) + conn = connectAPI.ConnectAPI() + virconn = conn.open(uri) + domobj = domainAPI.DomainAPI(virconn) + + if check_domain_running(domobj, guestname, logger): + conn.close() + return 1 + + domxml = add_cpu_xml(domobj, guestname, sockets, cores, threads, logger) + + if guest_undefine(domobj, guestname, logger): + conn.close() + return 1 + + if guest_define(domobj, domxml, logger): + conn.close() + return 1 + + ret, ip = guest_start(domobj, guestname, util, logger) + if ret: + conn.close() + return 1 + + if cpu_topology_check(ip, username, password, + sockets, cores, threads, util, logger): + conn.close() + return 1 + + conn.close() + return 0
ACK. - nzhang

On 09/01/2011 10:19 AM, Guannan Ren wrote:
*utils/Python/utils.py return 0,child.before intead *repos/remoteAccess/tcp_setup.py repos/remoteAccess/tls_setup.py switch over to use new remote_exec_pexpect() --- repos/remoteAccess/tcp_setup.py | 18 +++++++++--------- repos/remoteAccess/tls_setup.py | 20 ++++++++++---------- utils/Python/utils.py | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-)
This belongs to libvirt-test-API patches, sorry for the mistake. Guannan Ren

On 09/01/2011 10:19 AM, Guannan Ren wrote:
*utils/Python/utils.py return 0,child.before intead *repos/remoteAccess/tcp_setup.py repos/remoteAccess/tls_setup.py switch over to use new remote_exec_pexpect() --- repos/remoteAccess/tcp_setup.py | 18 +++++++++--------- repos/remoteAccess/tls_setup.py | 20 ++++++++++---------- utils/Python/utils.py | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/repos/remoteAccess/tcp_setup.py b/repos/remoteAccess/tcp_setup.py index 8f88810..b3877f7 100644 --- a/repos/remoteAccess/tcp_setup.py +++ b/repos/remoteAccess/tcp_setup.py @@ -56,7 +56,7 @@ def sasl_user_add(target_machine, username, password, util, logger): """ execute saslpasswd2 to add sasl user """ logger.info("add sasl user on server side") saslpasswd2_add = "echo %s | %s -a libvirt %s" % (password, SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_add) if ret: logger.error("failed to add sasl user") @@ -70,7 +70,7 @@ def tcp_libvirtd_set(target_machine, username, password, logger.info("setting libvirtd.conf on libvirt server") # open libvirtd --listen option listen_open_cmd = "echo 'LIBVIRTD_ARGS=\"--listen\"'>> %s" % SYSCONFIG_LIBVIRTD - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_open_cmd) if ret: logger.error("failed to uncomment --listen in %s" % SYSCONFIG_LIBVIRTD) @@ -79,7 +79,7 @@ def tcp_libvirtd_set(target_machine, username, password, # set listen_tls logger.info("set listen_tls to 0 in %s" % LIBVIRTD_CONF) listen_tls_disable = "echo \"listen_tls = 0\">> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_tls_disable) if ret: logger.error("failed to set listen_tls to 0 in %s" % LIBVIRTD_CONF) @@ -89,7 +89,7 @@ def tcp_libvirtd_set(target_machine, username, password, if listen_tcp == 'enable': logger.info("enable listen_tcp = 1 in %s" % LIBVIRTD_CONF) listen_tcp_set = "echo 'listen_tcp = 1'>> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_tcp_set) if ret: logger.error("failed to set listen_tcp in %s" % LIBVIRTD_CONF) @@ -98,7 +98,7 @@ def tcp_libvirtd_set(target_machine, username, password, # set auth_tcp logger.info("set auth_tcp to \"%s\" in %s" % (auth_tcp, LIBVIRTD_CONF)) auth_tcp_set = "echo 'auth_tcp = \"%s\"'>> %s" % (auth_tcp, LIBVIRTD_CONF) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, auth_tcp_set) if ret: logger.error("failed to set auth_tcp in %s" % LIBVIRTD_CONF) @@ -107,7 +107,7 @@ def tcp_libvirtd_set(target_machine, username, password, # restart remote libvirtd service libvirtd_restart_cmd = "service libvirtd restart" logger.info("libvirtd restart") - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirtd_restart_cmd) if ret: logger.error("failed to restart libvirtd service") @@ -225,18 +225,18 @@ def tcp_setup_clean(params):
if auth_tcp == 'sasl': saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_delete) if ret: logger.error("failed to delete sasl user") libvirtd_conf_retore = "sed -i -n '/^[ #]/p' %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirtd_conf_retore) if ret: logger.error("failed to restore %s" % LIBVIRTD_CONF)
sysconfig_libvirtd_restore = "sed -i -n '/^[ #]/p' %s" % SYSCONFIG_LIBVIRTD - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, sysconfig_libvirtd_restore) if ret: logger.error("failed to restore %s" % SYSCONFIG_LIBVIRTD) diff --git a/repos/remoteAccess/tls_setup.py b/repos/remoteAccess/tls_setup.py index 4e7f24e..27bb8a7 100644 --- a/repos/remoteAccess/tls_setup.py +++ b/repos/remoteAccess/tls_setup.py @@ -213,7 +213,7 @@ def deliver_cert(target_machine, username, password, pkipath, util, logger):
# mkdir /etc/pki/libvirt/private on remote host libvirt_priv_cmd = "mkdir -p %s" % PRIVATE_KEY_FOLDER - ret = util.remote_exec_pexpect(target_machine, username, password, libvirt_priv_cmd) + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirt_priv_cmd) if ret: logger.error("failed to make /etc/pki/libvirt/private on %s" % target_machine) return 1 @@ -257,7 +257,7 @@ def sasl_user_add(target_machine, username, password, util, logger): """ execute saslpasswd2 to add sasl user """ logger.info("add sasl user on server side") saslpasswd2_add = "echo %s | %s -a libvirt %s" % (password, SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_add) if ret: logger.error("failed to add sasl user") @@ -271,7 +271,7 @@ def tls_libvirtd_set(target_machine, username, password, logger.info("setting libvirtd.conf on tls server") # open libvirtd --listen option listen_open_cmd = "echo 'LIBVIRTD_ARGS=\"--listen\"'>> /etc/sysconfig/libvirtd" - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_open_cmd) if ret: logger.error("failed to uncomment --listen in /etc/sysconfig/libvirtd") @@ -280,7 +280,7 @@ def tls_libvirtd_set(target_machine, username, password, if listen_tls == 'disable': logger.info("set listen_tls to 0 in %s" % LIBVIRTD_CONF) listen_tls_disable = "echo \"listen_tls = 0\">> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, listen_tls_disable) if ret: logger.error("failed to set listen_tls to 0 in %s" % LIBVIRTD_CONF) @@ -289,7 +289,7 @@ def tls_libvirtd_set(target_machine, username, password, if auth_tls == 'sasl': logger.info("enable auth_tls = sasl in %s" % LIBVIRTD_CONF) auth_tls_set = "echo 'auth_tls = \"sasl\"'>> %s" % LIBVIRTD_CONF - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, auth_tls_set) if ret: logger.error("failed to set auth_tls to sasl in %s" % LIBVIRTD_CONF) @@ -298,7 +298,7 @@ def tls_libvirtd_set(target_machine, username, password, # restart remote libvirtd service libvirtd_restart_cmd = "service libvirtd restart" logger.info("libvirtd restart") - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, libvirtd_restart_cmd) if ret: logger.error("failed to restart libvirtd service") @@ -311,7 +311,7 @@ def iptables_stop(target_machine, username, password, util, logger): """ This is a temprory method in favor of migration """ logger.info("stop local and remote iptables temprorily") iptables_stop_cmd = "service iptables stop" - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, iptables_stop_cmd) if ret: logger.error("failed to stop remote iptables service") @@ -466,13 +466,13 @@ def tls_setup_clean(params):
util = utils.Utils() cacert_rm = "rm -f %s/cacert.pem" % CA_FOLDER - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, cacert_rm) if ret: logger.error("failed to remove cacert.pem on remote machine")
ca_libvirt_rm = "rm -rf %s" % CERTIFICATE_FOLDER - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, ca_libvirt_rm) if ret: logger.error("failed to remove libvirt folder") @@ -482,7 +482,7 @@ def tls_setup_clean(params):
if auth_tls == 'sasl': saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) - ret = util.remote_exec_pexpect(target_machine, username, + ret, output = util.remote_exec_pexpect(target_machine, username, password, saslpasswd2_delete) if ret: logger.error("failed to delete sasl user") diff --git a/utils/Python/utils.py b/utils/Python/utils.py index 6787e87..d521254 100644 --- a/utils/Python/utils.py +++ b/utils/Python/utils.py @@ -406,10 +406,10 @@ class Utils(object): child.sendline(password) elif index == 2: child.close() - return 0 + return 0, child.before elif index == 3: child.close() - return 1 + return 1, ""
return 0
ACK. - nzhang
participants (2)
-
Guannan Ren
-
Nan Zhang