def tcp_setup_clean(params): """cleanup testing environment""" logger = params['logger'] target_machine = params['target_machine'] username = params['username'] password = params['password'] listen_tcp = params['listen_tcp'] auth_tcp = params['auth_tcp'] if auth_tcp == 'sasl': saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) ret, output = utils.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, output = utils.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, output = utils.remote_exec_pexpect( target_machine, username, password, sysconfig_libvirtd_restore) if ret: logger.error("failed to restore %s" % SYSCONFIG_LIBVIRTD)
def tls_setup_clean(params): """ cleanup testing enviroment """ if os.path.exists(TEMP_TLS_FOLDER): shutil.rmtree(TEMP_TLS_FOLDER) logger = params["logger"] target_machine = params["target_machine"] username = params["username"] password = params["password"] listen_tls = params["listen_tls"] auth_tls = params["auth_tls"] cacert_rm = "rm -f %s/cacert.pem" % CA_FOLDER ret, output = utils.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, output = utils.remote_exec_pexpect(target_machine, username, password, ca_libvirt_rm) if ret: logger.error("failed to remove libvirt folder") os.remove("%s/cacert.pem" % CA_FOLDER) shutil.rmtree(CERTIFICATE_FOLDER) if auth_tls == "sasl": saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) ret, output = utils.remote_exec_pexpect(target_machine, username, password, saslpasswd2_delete) if ret: logger.error("failed to delete sasl user")
def tls_setup_clean(params): """ cleanup testing enviroment """ if os.path.exists(TEMP_TLS_FOLDER): shutil.rmtree(TEMP_TLS_FOLDER) logger = params['logger'] target_machine = params['target_machine'] username = params['username'] password = params['password'] listen_tls = params['listen_tls'] auth_tls = params['auth_tls'] cacert_rm = "rm -f %s/cacert.pem" % CA_FOLDER ret, output = utils.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, output = utils.remote_exec_pexpect(target_machine, username, password, ca_libvirt_rm) if ret: logger.error("failed to remove libvirt folder") os.remove("%s/cacert.pem" % CA_FOLDER) shutil.rmtree(CERTIFICATE_FOLDER) if auth_tls == 'sasl': saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) ret, output = utils.remote_exec_pexpect(target_machine, username, password, saslpasswd2_delete) if ret: logger.error("failed to delete sasl user")
def tcp_libvirtd_set(target_machine, username, password, listen_tcp, auth_tcp, logger): """ configure libvirtd.conf on libvirt server """ logger.info("setting libvirtd.conf on libvirt server") # open libvirtd --listen option listen_open_cmd = "echo 'LIBVIRTD_ARGS=\"--listen\"' >> %s" % SYSCONFIG_LIBVIRTD ret, output = utils.remote_exec_pexpect(target_machine, username, password, listen_open_cmd) if ret: logger.error("failed to uncomment --listen in %s" % SYSCONFIG_LIBVIRTD) return 1 # 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, output = utils.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) return 1 # set listen_tcp 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, output = utils.remote_exec_pexpect(target_machine, username, password, listen_tcp_set) if ret: logger.error("failed to set listen_tcp in %s" % LIBVIRTD_CONF) return 1 # 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, output = utils.remote_exec_pexpect(target_machine, username, password, auth_tcp_set) if ret: logger.error("failed to set auth_tcp in %s" % LIBVIRTD_CONF) return 1 # restart remote libvirtd service libvirtd_restart_cmd = "service libvirtd restart" logger.info("libvirtd restart") ret, output = utils.remote_exec_pexpect(target_machine, username, password, libvirtd_restart_cmd) if ret: logger.error("failed to restart libvirtd service") return 1 logger.info("done to libvirtd configuration") return 0
def check_fsinfo(ipaddr, username, userpasswd, fsinfo, logger): """ equal the fsinfo from libvirt and we get in guest mountinfo """ cmd = "cat /proc/self/mountinfo" ret, mounts_needparse = utils.remote_exec_pexpect( ipaddr, username, userpasswd, cmd) mounts = utils.parse_mountinfo(mounts_needparse) for n in fsinfo: mountdir = n[0] name = n[1] type1 = n[2] target = n[3][0] found = 0 for i in mounts: if mountdir == i['mountdir']: found = 1 if i['mounttype'] != type1: logger.error( "Fail: mount type is not equal: libvirt: %s but we get: %s" % (type1, i['mounttype'])) return False if found == 0: logger.error("Fail: cannot find %s in guest mount info" % mountdir) return False return True
def check_current_vcpu(domobj, username, password): """dump domain xml description to get current vcpu number """ guestxml = domobj.XMLDesc(1) logger.debug("domain %s xml is :\n%s" % (domobj.name(), guestxml)) xml = minidom.parseString(guestxml) vcpu = xml.getElementsByTagName('vcpu')[0] if vcpu.hasAttribute('current'): attr = vcpu.getAttributeNode('current') current_vcpu = int(attr.nodeValue) else: logger.info("domain did not have 'current' attribute in vcpu element") current_vcpu = int(vcpu.childNodes[0].data) logger.info("check cpu number in domain") ip = utils.mac_to_ip(mac, 180) cmd = "cat /proc/cpuinfo | grep processor | wc -l" ret, output = utils.remote_exec_pexpect(ip, username, password, cmd) if not ret: logger.info("cpu number in domain is %s" % output) if int(output) == current_vcpu: logger.info("cpu number in domain is equal to current vcpu value") return current_vcpu else: logger.error("current vcpu is not equal as check in domain") return False else: logger.error("check in domain fail") return False
def check_define_domain(guestname, virt_type, hostname, username, password, logger): """Check define domain result, if define domain is successful, guestname.xml will exist under /etc/libvirt/qemu/ and can use virt-xml-validate tool to check the file validity """ if "kvm" in virt_type: path = "/etc/libvirt/qemu/%s.xml" % guestname elif "xen" in virt_type: path = "/etc/xen/%s" % guestname else: logger.error("unknown virt type") if hostname: cmd = "ls %s" % path ret, output = utils.remote_exec_pexpect(hostname, username, password, cmd) if ret: logger.error("guest %s xml file doesn't exsits" % guestname) return False else: return True else: if os.access(path, os.R_OK): return True else: return False
def create_new_user(ipaddr, newusername, username, userpasswd, logger): cmd = "useradd %s" % newusername ret, retinfo = utils.remote_exec_pexpect(ipaddr, username, userpasswd, cmd) if ret == 0 or "already exists" in retinfo: return 0 else: logger.error("Fail: cannot create a new user: %s" % retinfo) return 1
def flag_check(params): """ check if the flag file is present or not""" logger = params['logger'] guestname = params['guestname'] username = params['username'] password = params['password'] if 'expectedret' in params: expected_result = params['expectedret'] else: expected_result = "exist" conn = sharedmod.libvirtobj['conn'] if not check_domain_running(conn, guestname, logger): logger.error("need a running guest") return 1 logger.info("get the mac address of vm %s" % guestname) mac = utils.get_dom_mac_addr(guestname) logger.info("the mac address of vm %s is %s" % (guestname, mac)) timeout = 300 while timeout: ipaddr = utils.mac_to_ip(mac, 180) if not ipaddr: logger.info(str(timeout) + "s left") time.sleep(10) timeout -= 10 else: logger.info("the ip address of vm %s is %s" % (guestname, ipaddr)) break if timeout == 0: logger.info("vm %s failed to get ip address" % guestname) return 1 ret, out = utils.remote_exec_pexpect( ipaddr, username, password, FLAG_CHECK) if ret: logger.error("connecting to guest OS timeout") return 1 elif out == FLAG_FILE and expected_result == "exist": logger.info("checking flag %s in guest OS succeeded" % FLAG_FILE) return 0 elif out == FLAG_FILE and expected_result == 'noexist': logger.error("flag %s still exist, FAILED." % FLAG_FILE) return 1 elif out is not None and expected_result == "exist": logger.error( "no flag %s exists in the guest %s " % (FLAG_FILE, guestname)) return 1 elif out is not None and expected_result == 'noexist': logger.info("flag %s is not present, checking succeeded" % FLAG_FILE) return 0 return 0
def tcp_libvirtd_set(target_machine, username, password, listen_tcp, auth_tcp, logger): """ configure libvirtd.conf on libvirt server """ logger.info("setting libvirtd.conf on libvirt server") # open libvirtd --listen option listen_open_cmd = "echo 'LIBVIRTD_ARGS=\"--listen\"' >> %s" % SYSCONFIG_LIBVIRTD ret, output = utils.remote_exec_pexpect(target_machine, username, password, listen_open_cmd) if ret: logger.error("failed to uncomment --listen in %s" % SYSCONFIG_LIBVIRTD) return 1 # 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, output = utils.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) return 1 # set listen_tcp 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, output = utils.remote_exec_pexpect(target_machine, username, password, listen_tcp_set) if ret: logger.error("failed to set listen_tcp in %s" % LIBVIRTD_CONF) return 1 # 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, output = utils.remote_exec_pexpect(target_machine, username, password, auth_tcp_set) if ret: logger.error("failed to set auth_tcp in %s" % LIBVIRTD_CONF) return 1 # restart remote libvirtd service libvirtd_restart_cmd = "service libvirtd restart" logger.info("libvirtd restart") ret, output = utils.remote_exec_pexpect(target_machine, username, password, libvirtd_restart_cmd) if ret: logger.error("failed to restart libvirtd service") return 1 logger.info("done to libvirtd configuration") return 0
def flag_check(params): """ check if the flag file is present or not""" logger = params['logger'] guestname = params['guestname'] username = params['username'] password = params['password'] if 'expectedret' in params: expected_result = params['expectedret'] else: expected_result = "exist" conn = sharedmod.libvirtobj['conn'] if not check_domain_running(conn, guestname, logger): logger.error("need a running guest") return 1 logger.info("get the mac address of vm %s" % guestname) mac = utils.get_dom_mac_addr(guestname) logger.info("the mac address of vm %s is %s" % (guestname, mac)) timeout = 300 while timeout: ipaddr = utils.mac_to_ip(mac, 180) if not ipaddr: logger.info(str(timeout) + "s left") time.sleep(10) timeout -= 10 else: logger.info("the ip address of vm %s is %s" % (guestname, ipaddr)) break if timeout == 0: logger.info("vm %s failed to get ip address" % guestname) return 1 ret, out = utils.remote_exec_pexpect(ipaddr, username, password, FLAG_CHECK) if ret: logger.error("connecting to guest OS timeout") return 1 elif out == FLAG_FILE and expected_result == "exist": logger.info("checking flag %s in guest OS succeeded" % FLAG_FILE) return 0 elif out == FLAG_FILE and expected_result == 'noexist': logger.error("flag %s still exist, FAILED." % FLAG_FILE) return 1 elif out is not None and expected_result == "exist": logger.error("no flag %s exists in the guest %s " % (FLAG_FILE, guestname)) return 1 elif out is not None and expected_result == 'noexist': logger.info("flag %s is not present, checking succeeded" % FLAG_FILE) return 0 return 0
def deliver_cert(target_machine, username, password, pkipath, logger): """ deliver CA, server and client certificates """ # transmit cacert.pem to remote host logger.info("deliver CA, server and client certificates to both local and remote server") ret = utils.scp_file(target_machine, username, password, CA_FOLDER, CACERT) if ret: logger.error("scp cacert.pem to %s error" % target_machine) return 1 # copy cacert.pem to local CA folder cacert_cp = [CP, "-f", CACERT, (pkipath and pkipath) or CA_FOLDER] ret, out = utils.exec_cmd(cacert_cp) if ret: logger.error("copying cacert.pem to %s error" % CA_FOLDER) return 1 # mkdir /etc/pki/libvirt/private on remote host libvirt_priv_cmd = "mkdir -p %s" % PRIVATE_KEY_FOLDER ret, output = utils.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 # transmit serverkey.pem to remote host ret = utils.scp_file(target_machine, username, password, PRIVATE_KEY_FOLDER, SERVERKEY) if ret: logger.error("failed to scp serverkey.pem to %s" % target_machine) return 1 # transmit servercert.pem to remote host ret = utils.scp_file(target_machine, username, password, CERTIFICATE_FOLDER, SERVERCERT) if ret: logger.error("failed to scp servercert.pem to %s" % target_machine) return 1 libvirt_priv_cmd_local = [MKDIR, "-p", PRIVATE_KEY_FOLDER] ret, out = utils.exec_cmd(libvirt_priv_cmd_local) if ret: logger.error("failed to make %s on local" % PRIVATE_KEY_FOLDER) return 1 # copy clientkey.pem to local folder clientkey_cp = [CP, "-f", CLIENTKEY, (pkipath and pkipath) or PRIVATE_KEY_FOLDER] ret, out = utils.exec_cmd(clientkey_cp) if ret: logger.error("failed to copy clientkey.pem to %s" % PRIVATE_KEY_FOLDER) return 1 # copy clientcert.pem to local folder clientcert_cp = [CP, "-f", CLIENTCERT, (pkipath and pkipath) or CERTIFICATE_FOLDER] ret, out = utils.exec_cmd(clientcert_cp) if ret: logger.error("failed to copy clientcert.pem to %s" % CERTIFICATE_FOLDER) return 1 logger.info("done to delivery") return 0
def sasl_user_add(target_machine, username, password, 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, output = utils.remote_exec_pexpect(target_machine, username, password, saslpasswd2_add) if ret: logger.error("failed to add sasl user") return 1 return 0
def tls_libvirtd_set(target_machine, username, password, listen_tls, auth_tls, logger): """ configure libvirtd.conf on tls server """ logger.info("setting libvirtd.conf on tls server") # open libvirtd --listen option listen_open_cmd = "echo 'LIBVIRTD_ARGS=\"--listen\"' >> /etc/sysconfig/libvirtd" ret, output = utils.remote_exec_pexpect(target_machine, username, password, listen_open_cmd) if ret: logger.error("failed to uncomment --listen in /etc/sysconfig/libvirtd") return 1 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, output = utils.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) return 1 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, output = utils.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) return 1 # restart remote libvirtd service libvirtd_restart_cmd = "service libvirtd restart" logger.info("libvirtd restart") ret, output = utils.remote_exec_pexpect(target_machine, username, password, libvirtd_restart_cmd) if ret: logger.error("failed to restart libvirtd service") return 1 logger.info("done to libvirtd configuration") return 0
def make_flag(ipaddr, username, password, logger): """ enter guest OS, create a file in /tmp folder """ ret, out = utils.remote_exec_pexpect(ipaddr, username, password, MAKE_FLAG) if ret: logger.error("connecting to guest OS timeout") return False elif out != '': logger.error("failed to make flag in guest OS, %s" % out) return False else: logger.info("flag %s is created in /tmp folder" % FLAG_FILE) return True
def tcp_setup_clean(params): """cleanup testing environment""" logger = params["logger"] target_machine = params["target_machine"] username = params["username"] password = params["password"] listen_tcp = params["listen_tcp"] auth_tcp = params["auth_tcp"] if auth_tcp == "sasl": saslpasswd2_delete = "%s -a libvirt -d %s" % (SASLPASSWD2, username) ret, output = utils.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, output = utils.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, output = utils.remote_exec_pexpect(target_machine, username, password, sysconfig_libvirtd_restore) if ret: logger.error("failed to restore %s" % SYSCONFIG_LIBVIRTD)
def iptables_stop(target_machine, username, password, 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, output = utils.remote_exec_pexpect(target_machine, username, password, iptables_stop_cmd) if ret: logger.error("failed to stop remote iptables service") return 1 iptables_stop = ["service", "iptables", "stop"] ret, out = utils.exec_cmd(iptables_stop) if ret: logger.error("failed to stop local iptables service") return 1 logger.info("done the iptables stop job") return 0
def get_current_vcpu(domobj, username, password): """dump domain live xml description to get current vcpu number and check in domain to confirm """ try: guestxml = domobj.XMLDesc(1) guestname = domobj.name() logger.debug("domain %s xml is :\n%s" % (guestname, guestxml)) xml = minidom.parseString(guestxml) vcpu = xml.getElementsByTagName('vcpu')[0] if vcpu.hasAttribute('current'): attr = vcpu.getAttributeNode('current') current = int(attr.nodeValue) else: logger.info("no 'current' atrribute for element vcpu") current = int(vcpu.childNodes[0].data) logger.info("domain current vcpu number in live xml is: %s" % current) except libvirtError as e: logger.error("libvirt call failed: " + str(e)) return False logger.debug("get the mac address of vm %s" % guestname) mac = utils.get_dom_mac_addr(guestname) logger.debug("the mac address of vm %s is %s" % (guestname, mac)) logger.info("check cpu number in domain") ip = utils.mac_to_ip(mac, 180) cmd = "cat /proc/cpuinfo | grep processor | wc -l" ret, output = utils.remote_exec_pexpect(ip, username, password, cmd) if not ret: logger.info("cpu number in domain is %s" % output) if int(output) == current: logger.info("cpu in domain is equal to current vcpu value") else: logger.error("current vcpu is not equal as check in domain") return False else: logger.error("check in domain fail") return False return current
def cpu_topology_chk(ip, username, password, sockets, cores, threads, logger): """login the guest, run lscpu command to check the result""" lscpu = "lscpu" # sleep for 5 seconds time.sleep(40) ret, output = utils.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.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 verify_cur_user(ipaddr, username, userpasswd): cmd = "whoami" ret, retinfo = utils.remote_exec_pexpect(ipaddr, username, userpasswd, cmd) return ret
logger.info("domain current vcpu number in live xml is: %s" % current) except libvirtError, e: logger.error("libvirt call failed: " + str(e)) return False logger.debug("get the mac address of vm %s" % guestname) mac = utils.get_dom_mac_addr(guestname) logger.debug("the mac address of vm %s is %s" % (guestname, mac)) logger.info("check cpu number in domain") ip = utils.mac_to_ip(mac, 180) cmd = "cat /proc/cpuinfo | grep processor | wc -l" ret, output = utils.remote_exec_pexpect(ip, username, password, cmd) if not ret: logger.info("cpu number in domain is %s" % output) if int(output) == current: logger.info("cpu in domain is equal to current vcpu value") else: logger.error("current vcpu is not equal as check in domain") return False else: logger.error("check in domain fail") return False return current def set_vcpus_live(params): """set domain vcpu with live flag and check
def deliver_cert(target_machine, username, password, pkipath, logger): """ deliver CA, server and client certificates """ # transmit cacert.pem to remote host logger.info( "deliver CA, server and client certificates to both local and remote server" ) ret = utils.scp_file(target_machine, username, password, CA_FOLDER, CACERT) if ret: logger.error("scp cacert.pem to %s error" % target_machine) return 1 # copy cacert.pem to local CA folder cacert_cp = [CP, '-f', CACERT, (pkipath and pkipath) or CA_FOLDER] ret, out = utils.exec_cmd(cacert_cp) if ret: logger.error("copying cacert.pem to %s error" % CA_FOLDER) return 1 # mkdir /etc/pki/libvirt/private on remote host libvirt_priv_cmd = "mkdir -p %s" % PRIVATE_KEY_FOLDER ret, output = utils.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 # transmit serverkey.pem to remote host ret = utils.scp_file(target_machine, username, password, PRIVATE_KEY_FOLDER, SERVERKEY) if ret: logger.error("failed to scp serverkey.pem to %s" % target_machine) return 1 # transmit servercert.pem to remote host ret = utils.scp_file(target_machine, username, password, CERTIFICATE_FOLDER, SERVERCERT) if ret: logger.error("failed to scp servercert.pem to %s" % target_machine) return 1 libvirt_priv_cmd_local = [MKDIR, '-p', PRIVATE_KEY_FOLDER] ret, out = utils.exec_cmd(libvirt_priv_cmd_local) if ret: logger.error("failed to make %s on local" % PRIVATE_KEY_FOLDER) return 1 # copy clientkey.pem to local folder clientkey_cp = [ CP, '-f', CLIENTKEY, (pkipath and pkipath) or PRIVATE_KEY_FOLDER ] ret, out = utils.exec_cmd(clientkey_cp) if ret: logger.error("failed to copy clientkey.pem to %s" % PRIVATE_KEY_FOLDER) return 1 # copy clientcert.pem to local folder clientcert_cp = [ CP, '-f', CLIENTCERT, (pkipath and pkipath) or CERTIFICATE_FOLDER ] ret, out = utils.exec_cmd(clientcert_cp) if ret: logger.error("failed to copy clientcert.pem to %s" % CERTIFICATE_FOLDER) return 1 logger.info("done to delivery") return 0