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

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

 



    *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

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]