• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python remote.remote_login函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中virttest.remote.remote_login函数的典型用法代码示例。如果您正苦于以下问题:Python remote_login函数的具体用法?Python remote_login怎么用?Python remote_login使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了remote_login函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setup_remote_ssh_key

def setup_remote_ssh_key(hostname1, user1, password1,
                         hostname2=None, user2=None, password2=None,
                         port=22, config_options=None, public_key="rsa"):
    """
    Setup up remote to remote login in another server by using public key
    If hostname2 is not supplied, setup to local.

    :param hostname1: the server wants to login other host
    :param hostname2: the server to be logged in
    :type hostname: str
    :param user: user to login
    :type user: str
    :param password: password
    :type password: str
    :param port: port number
    :type port: int
    :param config_options: list of options eg: ["StrictHostKeyChecking=no"]
    :type config_options: list of str
    """
    logging.debug('Performing SSH key setup on %s:%d as %s.' %
                  (hostname1, port, user1))

    try:
        session1 = remote.remote_login(client='ssh', host=hostname1, port=port,
                                       username=user1, password=password1,
                                       prompt=r'[$#%]')
        public_key = get_remote_public_key(session1, public_key=public_key)

        if hostname2 is None:
            # Simply create a session to local
            session2 = aexpect.ShellSession("sh", linesep='\n', prompt='#')
            # set config in local machine
            if config_options:
                for each_option in config_options:
                    session2.cmd_output("echo '%s' >> ~/.ssh/config" %
                                        each_option)
        else:
            session2 = remote.remote_login(client='ssh', host=hostname2,
                                           port=port, username=user2,
                                           password=password2,
                                           prompt=r'[$#%]')
            # set config in remote machine
            if config_options:
                for each_option in config_options:
                    session1.cmd_output("echo '%s' >> ~/.ssh/config" %
                                        each_option)
        session2.cmd_output('mkdir -p ~/.ssh')
        session2.cmd_output('chmod 700 ~/.ssh')
        session2.cmd_output("echo '%s' >> ~/.ssh/authorized_keys; " %
                            public_key)
        session2.cmd_output('chmod 600 ~/.ssh/authorized_keys')
        logging.debug('SSH key setup on %s complete.', session2)
    except Exception as err:
        logging.debug('SSH key setup has failed: %s', err)
        try:
            session1.close()
            session2.close()
        except Exception:
            pass
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:59,代码来源:ssh_key.py


示例2: test

 def test(self):
     log_file = os.path.join(self.srcdir, "file")
     session_int = remote.RemoteRunner("ssh", self.ip, 22, self.user_name, self.password,
                                       self.prompt, "\n", log_file, 100, 10, None)
     session_int.run("cat /etc/os-release", 600, "True")
     if "Ubuntu" in open(log_file).read():
         file_list = ['dmesg', 'dump']
         f_val = 12
         session_int.run("DEBIAN_FRONTEND=noninteractive apt-get install -y  linux-crashdump;", 600, "True")
         crashkernel_value = 'GRUB_CMDLINE_LINUX_DEFAULT=\"$GRUB_CMDLINE_LINUX_DEFAULT\
                              crashkernel=2G-4G:320M,4G-32G:512M,32G-64G:1024M,64G-128G:2048M,128G-:4096M\"'
         cmd = "echo \'%s\' > /etc/default/grub.d/kexec-tools.cfg;" % crashkernel_value
         session_int.run(cmd, 600, "True")
         session_int.run("sudo update-grub;", 600, "True")
         session_reboot = remote.remote_login("ssh", self.ip, 22, self.user_name, self.password,
                                              self.prompt, "\n", None, 100, None, None, False)
         session_reboot.sendline('reboot;')
         time.sleep(600)
         self.log.info("Connecting after reboot")
         session_status = remote.RemoteRunner("ssh", self.ip, 22, self.user_name, self.password,
                                              self.prompt, "\n", log_file, 100, 10, None)
         session_status.run("kdump-config show", 600, "True")
         if self.run_cmd_out("cat %s | grep -Eai 'Not ready to'" % log_file):
             self.fail("Kdump is not operational")
         else:
             self.log.info("Kdump status is operational")
     if "rhel" in open(log_file).read():
         file_list = ['vmcore-dmesg.txt', 'vmcore']
         f_val = 11
         session_int.run("kdumpctl status", 600, "True")
         if self.run_cmd_out("cat %s | grep -Eai 'Kdump is not operational'" % log_file):
             self.fail("Kdump is not operational")
         else:
             self.log.info("Kdump status is operational")
     session_crash = remote.remote_login("ssh", self.ip, 22, self.user_name, self.password,
                                         self.prompt, "\n", None, 100, None, None, False)
     session_crash.sendline('echo 1 > /proc/sys/kernel/sysrq;')
     session_crash.sendline('echo "c" > /proc/sysrq-trigger;')
     time.sleep(600)
     self.log.info("Connecting after reboot")
     session_check = remote.RemoteRunner("ssh", self.ip, 22, self.user_name, self.password,
                                         self.prompt, "\n", log_file, 100, 10, None)
     session_check.run("ls -lrt /var/crash", 100, "True")
     crash_dir = self.run_cmd_out("cat %s | grep drwxr | tail -1 | cut -d' ' -f%s" % (log_file, f_val))
     path_crash_dir = os.path.join("/var/crash", crash_dir)
     print path_crash_dir
     session_check.run("ls -lrt %s" % path_crash_dir, 100, "True")
     for files in file_list:
         if files not in open(log_file).read():
             self.fail("%s is not saved" % files)
开发者ID:balamuruhans,项目名称:avocado-misc-tests,代码行数:50,代码来源:kdump.py


示例3: test

 def test(self):
     log_file_server = os.path.join(self.workdir, "file_server")
     self.configure_kdump()
     self.configure_nfs()
     session_check = remote.RemoteRunner("ssh", self.ip_server, 22, self.user_name_server, self.password_server,
                                         self.prompt_server, "\n", log_file_server, 100, 10, None)
     session_check.run("date +%s", 100, "True")
     time_init = self.run_cmd_out("cat %s | tail -3 | head -1 | cut -d' ' -f3" % log_file_server).strip()
     session_crash = remote.remote_login("ssh", self.ip, 22, self.user_name, self.password,
                                         self.prompt, "\n", None, 100, None, None, False)
     session_crash.sendline('echo 1 > /proc/sys/kernel/sysrq;')
     session_crash.sendline('echo "c" > /proc/sysrq-trigger;')
     time.sleep(300)
     self.log.info("Connecting to nfs server")
     session_check = remote.RemoteRunner("ssh", self.ip_server, 22, self.user_name_server, self.password_server,
                                         self.prompt_server, "\n", log_file_server, 100, 10, None)
     if self.distro == "rhel":
         nfs_dir_path = os.path.join(self.nfs_path, "var", "crash")
     print nfs_dir_path
     session_check.run("ls -lrt %s;" % nfs_dir_path, 100, "True")
     crash_dir = self.run_cmd_out("cat %s | grep drwxr | awk '{print $NF}' | tail -1" % log_file_server)
     path_crash_dir = os.path.join(nfs_dir_path, crash_dir)
     session_check.run("stat -c%%Z %s" % path_crash_dir, 100, "True")
     time_created = self.run_cmd_out("cat %s | tail -3 | head -1 | cut -d' ' -f3" % log_file_server).strip()
     if time_created < time_init:
         self.fail("Dump is not saved in ssh server")
     session_check.run("ls -lrt %s" % path_crash_dir, 100, "True")
     for files in self.file_list:
         if files not in open(log_file_server).read():
             self.fail("%s is not saved" % files)
开发者ID:Naresh-ibm,项目名称:avocado-misc-tests,代码行数:30,代码来源:kdump_nfs.py


示例4: receiver

 def receiver():
     """ Receive side """
     logging.info("Starting receiver process on %s", receiver_addr)
     if vm_receiver:
         session = vm_receiver.wait_for_login(timeout=login_timeout)
     else:
         username = params.get("username", "")
         password = params.get("password", "")
         prompt = params.get("shell_prompt", "[\#\$]")
         linesep = eval("'%s'" % params.get("shell_linesep", r"\n"))
         client = params.get("shell_client")
         port = int(params.get("shell_port"))
         log_filename = ("session-%s-%s.log" % (receiver_addr,
                         utils_misc.generate_random_string(4)))
         session = remote.remote_login(client, receiver_addr, port,
                                       username, password, prompt,
                                       linesep, log_filename, timeout)
         session.set_status_test_command("echo %errorlevel%")
     install_ntttcp(session)
     ntttcp_receiver_cmd = params.get("ntttcp_receiver_cmd")
     global _receiver_ready
     f = open(results_path + ".receiver", 'a')
     for b in buffers:
         utils_misc.wait_for(lambda: not _wait(), timeout)
         _receiver_ready = True
         rbuf = params.get("fixed_rbuf", b)
         cmd = ntttcp_receiver_cmd % (
             session_num, receiver_addr, rbuf, buf_num)
         r = session.cmd_output(cmd, timeout=timeout,
                                print_func=logging.debug)
         f.write("Send buffer size: %s\n%s\n%s" % (b, cmd, r))
     f.close()
     session.close()
开发者ID:ayiyaliing,项目名称:virt-test,代码行数:33,代码来源:ntttcp.py


示例5: start_ip_sniffing

    def start_ip_sniffing(self, params):
        """
        Start ip sniffing.

        :param params: Params object.
        """
        self.data.setdefault("address_cache", ip_sniffing.AddrCache())
        sniffers = ip_sniffing.Sniffers

        if not self._sniffer:
            remote_pp = params.get("remote_preprocess") == "yes"
            remote_opts = None
            session = None
            if remote_pp:
                client = params.get('remote_shell_client', 'ssh')
                remote_opts = (params['remote_node_address'],
                               params.get('remote_shell_port', '22'),
                               params['remote_node_user'],
                               params['remote_node_password'],
                               params.get('remote_shell_prompt', '#'))
                session = remote.remote_login(client, *remote_opts)
            for s_cls in sniffers:
                if s_cls.is_supported(session):
                    self._sniffer = s_cls(self.data["address_cache"],
                                          "ip-sniffer.log",
                                          remote_opts)
                    break
            if session:
                session.close()

        if not self._sniffer:
            raise exceptions.TestError("Can't find any supported ip sniffer! "
                                       "%s" % [s.command for s in sniffers])

        self._sniffer.start()
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:35,代码来源:utils_env.py


示例6: remote_test

def remote_test(remote_ip, local_ip, remote_pwd, remote_prompt,
                vm_name, status_error_test):
    """
    Test remote case
    """
    err = ""
    status = 1
    status_error = status_error_test
    try:
        remote_uri = libvirt_vm.complete_uri(local_ip)
        session = remote.remote_login("ssh", remote_ip, "22",
                                      "root", remote_pwd, remote_prompt)
        session.cmd_output('LANG=C')
        command = "virsh -c %s setvcpus %s 1 --live" % (remote_uri, vm_name)
        if virsh.has_command_help_match("setvcpus", "--live") is None:
            raise error.TestNAError("The current libvirt doesn't support"
                                    " '--live' option for setvcpus")
        status, output = session.cmd_status_output(command, internal_timeout=5)
        session.close()
        if status != 0:
            err = output
    except error.CmdError:
        status = 1
        err = "remote test failed"
    return status, status_error, err
开发者ID:Acidburn0zzz,项目名称:tp-libvirt,代码行数:25,代码来源:virsh_setvcpus.py


示例7: list_local_domains_on_remote

    def list_local_domains_on_remote(options_ref, remote_ip, remote_passwd,
                                     local_ip, remote_user, local_user,
                                     local_pwd):
        """
        Create a virsh list command and execute it on remote host.
        It will list local domains on remote host.

        :param options_ref:options in virsh list command.
        :param remote_ip:remote host's ip.
        :param remote_passwd:remote host's password.
        :param local_ip:local ip, to create uri in virsh list.
        :return:return status and output of the virsh list command.
        """
        complete_uri = libvirt_vm.complete_uri(local_ip)
        command_on_remote = ("virsh -c %s list %s"
                             % (complete_uri, options_ref))
        try:
            # setup autologin for ssh from remote machine to execute commands
            # remotely
            config_opt = ["StrictHostKeyChecking=no"]
            ssh_key.setup_remote_ssh_key(remote_ip, remote_user,
                                         remote_passwd, hostname2=local_ip,
                                         user2=local_user,
                                         password2=local_pwd,
                                         config_options=config_opt)
            session = remote.remote_login("ssh", remote_ip, "22", remote_user,
                                          remote_passwd, "#")
            time.sleep(5)
            status, output = session.cmd_status_output(
                command_on_remote, internal_timeout=30)
        except Exception, info:
            logging.error("Shell failed to execute command from"
                          " remote")
            return 1, info
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:34,代码来源:virsh_list.py


示例8: remote_test

 def remote_test(params, vm_name):
     """
     Test remote case.
     """
     remote_ip = params.get("remote_ip", "REMOTE.EXAMPLE.COM")
     local_ip = params.get("local_ip", "LOCAL.EXAMPLE.COM")
     remote_pwd = params.get("remote_pwd", "")
     status = 0
     output = ""
     err = ""
     try:
         if remote_ip.count("EXAMPLE.COM") or local_ip.count("EXAMPLE.COM"):
             raise error.TestNAError("remote_ip and/or local_ip parameters "
                                     "not changed from default values.")
         uri = libvirt_vm.complete_uri(local_ip)
         session = remote.remote_login("ssh", remote_ip, "22", "root",
                                       remote_pwd, "#")
         session.cmd_output('LANG=C')
         command = "virsh -c %s dominfo %s" % (uri, vm_name)
         status, output = session.cmd_status_output(command,
                                                    internal_timeout=5)
         if status != 0:
             err = output
         session.close()
     except error.CmdError:
         status = 1
         output = ""
         err = "remote test failed"
     return status, output, err
开发者ID:LeiCui,项目名称:virt-test,代码行数:29,代码来源:virsh_dominfo.py


示例9: get_remote_host_session

 def get_remote_host_session():
     dsthostssh = remote.remote_login("ssh", dsthost, 22, "root",
                                      passwd, "#", timeout=30)
     if dsthostssh:
         dsthostssh.set_status_test_command("echo $?")
         return dsthostssh
     else:
         return None
开发者ID:FengYang,项目名称:virt-test,代码行数:8,代码来源:netperf_udp.py


示例10: run_virsh_reboot

def run_virsh_reboot(test, params, env):
    """
    Test command: virsh reboot.

    Run a reboot command in the target domain.
    1.Prepare test environment.
    2.When the libvirtd == "off", stop the libvirtd service.
    3.Perform virsh reboot operation.
    4.Recover test environment.(libvirts service)
    5.Confirm the test result.
    """

    vm_name = params.get("main_vm")
    vm = env.get_vm(vm_name)

    # run test case
    libvirtd = params.get("libvirtd", "on")
    vm_ref = params.get("reboot_vm_ref")
    status_error = params.get("status_error")
    extra = params.get("reboot_extra")
    remote_ip = params.get("remote_ip", "REMOTE.EXAMPLE.COM")
    local_ip = params.get("local_ip", "LOCAL.EXAMPLE.COM")
    remote_pwd = params.get("remote_pwd", "password")
    domid = vm.get_id()
    domuuid = vm.get_uuid()
    if libvirtd == "off":
        utils_libvirtd.libvirtd_stop()

    if vm_ref == "id":
        vm_ref = domid
    elif vm_ref == "name":
        vm_ref = vm_name
    elif vm_ref == "uuid":
        vm_ref = domuuid
    elif vm_ref == "hex_id":
        vm_ref = hex(int(domid))
    elif vm_ref.find("invalid") != -1:
        vm_ref = params.get(vm_ref)
    elif vm_ref == "remote_name":
        if remote_ip.count("EXAMPLE.COM") or local_ip.count("EXAMPLE.COM"):
            raise error.TestNAError("remote_ip and/or local_ip parameters not "
                                    "changed from default values")
        complete_uri = libvirt_vm.complete_uri(local_ip)
        try:
            session = remote.remote_login("ssh", remote_ip, "22", "root",
                                          remote_pwd, "#")
            session.cmd_output('LANG=C')
            command = "virsh -c %s reboot %s" % (complete_uri, vm_name)
            status, output = session.cmd_status_output(command,
                                                       internal_timeout=5)
            session.close()
        # FIXME: Catch specific exception
        except Exception, detail:
            logging.error("Exception: %s", str(detail))
            status = -1
开发者ID:Antique,项目名称:virt-test,代码行数:55,代码来源:virsh_reboot.py


示例11: test

 def test(self):
     log_file = os.path.join(self.workdir, "file")
     session_init = remote.RemoteRunner("ssh", self.ip, 22, self.user_name, self.password,
                                        self.prompt, "\n", log_file, 100, 10, None)
     session_init.run("cat /boot/config-`uname -r` | grep PSTORE", 600, "True")
     if not self.run_cmd_out("cat %s | grep -Eai 'CONFIG_PSTORE=y'" % log_file):
         self.fail("Pstore in not configured")
     session_init.run("mount", 600, "True")
     if not self.run_cmd_out("cat %s | grep -Eai 'debugfs on /sys/kernel/debug'" % log_file):
         self.fail("debugfs is not mounted")
     session_init.run("ls -lrt /sys/fs/pstore", 100, "True")
     file_list = ['common-nvram', 'dmesg-nvram']
     for files in file_list:
         if files not in open(log_file).read():
             self.fail("%s is not saved" % files)
     process.run("echo "" > %s" % log_file, ignore_status=True, sudo=True, shell=True)
     session_init.run("date +%s", 100, "True")
     time_init = self.run_cmd_out("cat %s | tail -3 | head -1 | cut -d' ' -f3" % log_file).strip()
     session1 = remote.remote_login("ssh", self.ip, 22, self.user_name, self.password,
                                    self.prompt, "\n", None, 100, None, None, False)
     session1.sendline('echo "c" > /proc/sysrq-trigger;')
     time.sleep(600)
     self.log.info("Connecting after reboot")
     session2 = remote.RemoteRunner("ssh", self.ip, 22, self.user_name, self.password,
                                    self.prompt, "\n", log_file, 100, 10, None)
     session2.run("ls -lrt /sys/fs/pstore", 100, "True")
     for files in file_list:
         if files not in open(log_file).read():
             self.fail("%s is not saved" % files)
         file_path = os.path.join('/sys/fs/pstore', "*%s*" % files)
         session2.run("stat -c%%Z %s" % file_path, 100, "True")
         time_created = self.run_cmd_out("cat %s | tail -3 | head -1 | cut -d' ' -f3" % log_file).strip()
         if time_created < time_init:
             self.fail("New %s is not saved" % files)
     process.run("echo "" > %s" % log_file, ignore_status=True, sudo=True, shell=True)
     session2.run("cat /etc/os-release", 600, "True")
     if "rhel" in open(log_file).read():
         session2.run("yum install sos", 600, "True")
     if "Ubuntu" in open(log_file).read():
         session2.run("yum install sosreport", 600, "True")
     session2.run("sosreport --no-report --batch --build", 100, "True")
     dir_name = self.run_cmd_out("cat %s | grep located | cut -d':' -f2" % log_file).strip()
     sosreport_dir = os.path.join(dir_name, '/sys/fs/pstore/')
     session2.run("ls -lrt %s" % sosreport_dir, 100, "True")
     for files in file_list:
         if files not in open(log_file).read():
             self.fail("%s is not saved" % files)
         file_path = os.path.join(sosreport_dir, "*%s*" % files)
         session2.run("stat -c%%Z %s" % file_path, 100, "True")
         time_created = self.run_cmd_out("cat %s | tail -3 | head -1 | cut -d' ' -f3" % log_file).strip()
         if time_created < time_init:
             self.fail("sosreport contains wrong %s file" % files)
开发者ID:Naresh-ibm,项目名称:avocado-misc-tests,代码行数:52,代码来源:pstore.py


示例12: __init__

    def __init__(self, test, params):
        self.vm_name = params.get("main_vm", "test-vm1")
        self.test = test
        self.env = params.get('env')
        self.time_out = int(params.get('time_out'))
        self.time_out_test = "yes" == params.get('time_out_test')
        self.remote_ip = params.get('remote_ip')
        self.remote_user = params.get('remote_user')
        self.local_ip = params.get('local_ip')
        if self.remote_ip.count("ENTER") or self.local_ip.count("ENTER"):
            self.test.cancel("Please set remote/local ip in base.cfg")
        self.remote_pwd = params.get('remote_pwd')
        self.local_mnt = params.get('local_mnt')
        self.remote_mnt = params.get('remote_mnt')
        self.session = remote.remote_login("ssh", self.remote_ip, "22",
                                           self.remote_user,
                                           self.remote_pwd, "#")
        self.session.cmd("setsebool virt_use_nfs on")
        local_hostname = process.run("hostname", shell=True).stdout_text.strip()
        remote_hostname = self.session.cmd_output("hostname")

        def file_add(a_str, a_file, session=None):
            """
            Add detail to a file
            """
            write_cmd = "echo '%s' >> %s" % (a_str, a_file)
            if session:
                session.cmd(write_cmd)
            else:
                process.run(write_cmd, shell=True)

        # Edit /etc/hosts file on local and remote host
        backup_hosts_cmd = "cat /etc/hosts > /etc/hosts.bak"
        process.run(backup_hosts_cmd, shell=True)
        self.session.cmd(backup_hosts_cmd)
        hosts_local_str = "%s %s" % (self.local_ip, local_hostname)
        hosts_remote_str = "%s %s" % (self.remote_ip, remote_hostname)
        file_add(hosts_local_str, "/etc/hosts")
        file_add(hosts_remote_str, "/etc/hosts")
        file_add(hosts_local_str, "/etc/hosts", self.session)
        file_add(hosts_remote_str, "/etc/hosts", self.session)

        # Edit /etc/exports file on local host
        process.run("cat /etc/exports > /etc/exports.bak", shell=True)
        exports_str = "%s *(insecure,rw,sync,no_root_squash)" % self.local_mnt
        file_add(exports_str, "/etc/exports")
        nfs_mount_cmd = "mount -t nfs %s:%s %s"\
                        % (self.local_ip, self.local_mnt, self.remote_mnt)
        self.session.cmd(nfs_mount_cmd)
        vm = self.env.get_vm(self.vm_name)
        vm.wait_for_login()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:51,代码来源:resource_abnormal.py


示例13: setup_esx_ssh_key

 def setup_esx_ssh_key(hostname, user, password, port=22):
     """
     Setup up remote login in esx server by using public key
     """
     logging.debug('Performing SSH key setup on %s:%d as %s.' %
                   (hostname, port, user))
     try:
         session = remote.remote_login(client='ssh', host=hostname,
                                       username=user, port=port,
                                       password=password, prompt=r'[ $#%]')
         public_key = ssh_key.get_public_key()
         session.cmd("echo '%s' >> /etc/ssh/keys-root/authorized_keys; " %
                     public_key)
         logging.debug('SSH key setup complete.')
         session.close()
     except Exception as err:
         logging.debug('SSH key setup has failed. %s', err)
开发者ID:nasastry,项目名称:tp-libvirt,代码行数:17,代码来源:v2v_options.py


示例14: list_local_domains_on_remote

    def list_local_domains_on_remote(options_ref, remote_ip, remote_passwd, local_ip):
        """
        Create a virsh list command and execute it on remote host.
        It will list local domains on remote host.

        @param options_ref:options in virsh list command.
        @param remote_ip:remote host's ip.
        @param remote_passwd:remote host's password.
        @param local_ip:local ip, to create uri in virsh list.
        @return:return status and output of the virsh list command.
        """
        command_on_remote = "virsh -c qemu+ssh://%s/system list %s" % (local_ip, options_ref)
        session = remote.remote_login("ssh", remote_ip, "22", "root", remote_passwd, "#")
        time.sleep(5)
        status, output = session.cmd_status_output(command_on_remote, internal_timeout=5)
        time.sleep(5)
        session.close()
        return int(status), output
开发者ID:LaneWolf,项目名称:virt-test,代码行数:18,代码来源:virsh_list.py


示例15: network_restart

def network_restart(test, params):
    """
    Restart remote network
    """
    time_out = int(params.get('time_out'))
    remote_ip = params.get('remote_ip')
    remote_user = params.get('remote_user')
    remote_pwd = params.get('remote_pwd')
    session = remote.remote_login("ssh", remote_ip, "22", remote_user,
                                  remote_pwd, "#")
    runner = remote.RemoteRunner(session=session)
    net_service = service.Factory.create_service("network", runner.run)
    net_service.restart()
    session.close()
    try:
        remote.wait_for_login("ssh", remote_ip, "22", remote_user,
                              remote_pwd, "#", timeout=time_out)
    except remote.LoginTimeoutError as detail:
        test.error(str(detail))
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:19,代码来源:resource_abnormal.py


示例16: check_dest_vm_network

def check_dest_vm_network(vm, remote_host, username, password,
                          shell_prompt):
    """
    Ping migrated vms on remote host.
    """
    session = remote.remote_login("ssh", remote_host, 22, username,
                                  password, shell_prompt)
    # Timeout to wait vm's network
    logging.debug("Getting vm's IP...")
    timeout = 60
    while timeout > 0:
        try:
            ping_cmd = "ping -c 4 %s" % vm.get_address()
            break
        except virt_vm.VMAddressError:
            time.sleep(5)
            timeout -= 5
    if timeout <= 0:
        raise error.TestFail("Can not get remote vm's IP.")
    status, output = session.cmd_status_output(ping_cmd)
    if status:
        raise error.TestFail("Check %s IP failed:%s" % (vm.name, output))
开发者ID:FengYang,项目名称:tp-libvirt,代码行数:22,代码来源:virsh_migrate_stress.py


示例17: remote_test

def remote_test(remote_ip, local_ip, remote_pwd, remote_prompt, vm_name):
    """
    Test remote case
    """
    err = ""
    try:
        remote_uri = libvirt_vm.complete_uri(local_ip)
        session = remote.remote_login("ssh", remote_ip, "22",
                                      "root", remote_pwd, remote_prompt)
        session.cmd_output('LANG=C')
        command = "virsh -c %s setvcpus %s 1 --live" % (remote_uri, vm_name)
        if virsh.has_command_help_match(command, "--live") is None:
            status_error = "yes"
        status, output = session.cmd_status_output(command, internal_timeout=5)
        session.close()
        if status != 0:
            err = output
    except error.CmdError:
        status = 1
        status_error = "yes"
        err = "remote test failed"
    return status, status_error, err
开发者ID:Guannan-Ren,项目名称:tp-libvirt,代码行数:22,代码来源:virsh_setvcpus.py


示例18: check_dest_vm_network

def check_dest_vm_network(vm, ip, remote_host, username, password,
                          shell_prompt):
    """
    Ping migrated vms on remote host.
    """
    session = remote.remote_login("ssh", remote_host, 22, username,
                                  password, shell_prompt)
    # Timeout to wait vm's network
    logging.debug("verifying VM's IP...")
    timeout = 60
    ping_failed = True
    ping_cmd = "ping -c 4 %s" % ip
    while timeout > 0:
        ps, po = session.cmd_status_output(ping_cmd)
        if ps:
            time.sleep(5)
            timeout -= 5
            continue
        logging.error(po)
        ping_failed = False
        break
    if ping_failed:
        raise error.TestFail("Check %s IP failed." % vm.name)
开发者ID:PandaWei,项目名称:tp-libvirt,代码行数:23,代码来源:virsh_migrate_stress.py


示例19: setup_ssh_key

def setup_ssh_key(hostname, user, password, port=22):
    """
    Setup up remote login in another server by using public key

    :param hostname: the server to login
    :type hostname: str
    :param user: user to login
    :type user: str
    :param password: password
    :type password: str
    :param port: port number
    :type port: int
    """
    logging.debug('Performing SSH key setup on %s:%d as %s.' %
                  (hostname, port, user))

    try:
        session = remote.remote_login(client='ssh', host=hostname,
                                      username=user, port=port,
                                      password=password, prompt=r'[$#%]')
        public_key = get_public_key()

        session.cmd('mkdir -p ~/.ssh')
        session.cmd('chmod 700 ~/.ssh')
        session.cmd("echo '%s' >> ~/.ssh/authorized_keys; " %
                    public_key)
        session.cmd('chmod 600 ~/.ssh/authorized_keys')
        logging.debug('SSH key setup complete.')

    except Exception:
        logging.debug('SSH key setup has failed.')

    finally:
        try:
            session.close()
        except Exception:
            pass
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:37,代码来源:ssh_key.py


示例20: configure_kdump

    def configure_kdump(self):
        log_file_init = os.path.join(self.workdir, "file1")
        session_int = remote.RemoteRunner("ssh", self.ip, 22, self.user_name, self.password,
                                          self.prompt, "\n", log_file_init, 100, 10, None)
        session_int.run("cat /etc/os-release", 20, "True")

        if "Ubuntu" in open(log_file_init).read():
            self.distro = "Ubuntu"
            self.file_list = ['dmesg', 'dump']
            session_int.run("DEBIAN_FRONTEND=noninteractive apt-get install -y  linux-crashdump;", 600, "True")
            crashkernel_value = 'GRUB_CMDLINE_LINUX_DEFAULT=\"$GRUB_CMDLINE_LINUX_DEFAULT\
                                 crashkernel=2G-4G:320M,4G-32G:512M,32G-64G:1024M,64G-128G:2048M,128G-:4096M\"'
            cmd = "echo \'%s\' > /etc/default/grub.d/kexec-tools.cfg;" % crashkernel_value
            session_int.run(cmd, 60, "True")
            session_int.run("sudo update-grub;", 600, "True")
            session_reboot = remote.remote_login("ssh", self.ip, 22, self.user_name, self.password,
                                                 self.prompt, "\n", None, 100, None, None, False)
            session_reboot.sendline('reboot;')
            time.sleep(600)
            self.log.info("Connecting after reboot")
            session_status = remote.RemoteRunner("ssh", self.ip, 22, self.user_name, self.password,
                                                 self.prompt, "\n", log_file_init, 100, 10, None)
            session_status.run("kdump-config show", 60, "True")
            if self.run_cmd_out("cat %s | grep -Eai 'Not ready to'" % log_file_init):
                self.fail("Kdump is not operational")
            else:
                self.log.info("Kdump status is operational")
            session_status.session.kill()
        if "rhel" in open(log_file_init).read():
            self.distro = "rhel"
            self.file_list = ['vmcore-dmesg.txt', 'vmcore']
            session_int.run("kdumpctl status", 60, "True")
            if self.run_cmd_out("cat %s | grep -Eai 'Kdump is not operational'" % log_file_init):
                self.fail("Kdump is not operational")
            else:
                self.log.info("Kdump status is operational")
开发者ID:Naresh-ibm,项目名称:avocado-misc-tests,代码行数:36,代码来源:kdump_nfs.py



注:本文中的virttest.remote.remote_login函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python remote.wait_for_login函数代码示例发布时间:2022-05-26
下一篇:
Python remote.handle_prompts函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap