当前位置: 首页>>代码示例>>Python>>正文


Python MyService.launch_vm_console方法代码示例

本文整理汇总了Python中cfme.services.myservice.MyService.launch_vm_console方法的典型用法代码示例。如果您正苦于以下问题:Python MyService.launch_vm_console方法的具体用法?Python MyService.launch_vm_console怎么用?Python MyService.launch_vm_console使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cfme.services.myservice.MyService的用法示例。


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

示例1: test_vm_console

# 需要导入模块: from cfme.services.myservice import MyService [as 别名]
# 或者: from cfme.services.myservice.MyService import launch_vm_console [as 别名]
def test_vm_console(request, appliance, setup_provider, context, configure_websocket,
        configure_console_vnc, order_service, take_screenshot,
        console_template, provider):
    """Test Myservice VM Console in SSUI.

    Metadata:
        test_flag: ssui

    Polarion:
        assignee: apagac
        casecomponent: Infra
        caseimportance: medium
        initialEstimate: 1/2h
    """
    if (provider.one_of(VMwareProvider) and provider.version >= 6.5 or
            'html5_console' in provider.data.get('excluded_test_flags', [])):
        pytest.skip('VNC consoles are unsupported on VMware ESXi 6.5 and later')

    catalog_item = order_service
    service_name = catalog_item.name
    console_vm_username = credentials[provider.data.templates.console_template
                            .creds].username
    console_vm_password = credentials[provider.data.templates.console_template
                            .creds].password
    with appliance.context.use(context):
        myservice = MyService(appliance, service_name)
        vm_obj = myservice.launch_vm_console(catalog_item)
        vm_console = vm_obj.vm_console
        if provider.one_of(OpenStackProvider):
            public_net = provider.data['public_network']
            vm_obj.mgmt.assign_floating_ip(public_net)
        request.addfinalizer(vm_console.close_console_window)
        request.addfinalizer(appliance.server.logout)
        ssh_who_command = ("who --count" if not provider.one_of(OpenStackProvider)
            else "who -aH")
        with ssh.SSHClient(hostname=vm_obj.ip_address, username=console_vm_username,
                password=console_vm_password) as vm_ssh_client:
            try:
                assert vm_console.wait_for_connect(180), ("VM Console did not reach 'connected'"
                    " state")
                user_count_before_login = vm_ssh_client.run_command(ssh_who_command,
                    ensure_user=True)
                logger.info("Output of '{}' is {} before login"
                    .format(ssh_who_command, user_count_before_login))
                assert vm_console.wait_for_text(text_to_find="login:", timeout=200), ("VM Console"
                    " didn't prompt for Login")
                # Enter Username:
                vm_console.send_keys("{}".format(console_vm_username))
                assert vm_console.wait_for_text(text_to_find="Password", timeout=200), ("VM Console"
                " didn't prompt for Password")
                # Enter Password:
                vm_console.send_keys("{}".format(console_vm_password))
                logger.info("Wait to get the '$' prompt")
                if not provider.one_of(OpenStackProvider):
                    vm_console.wait_for_text(text_to_find=provider.data.templates.
                        console_template.prompt_text, timeout=200)

                def _validate_login():
                    # the following try/except is required to handle the exception thrown by SSH
                    # while connecting to VMware VM.It throws "[Error 104]Connection reset by Peer".
                    try:
                        user_count_after_login = vm_ssh_client.run_command(ssh_who_command,
                            ensure_user=True)
                        logger.info("Output of '{}' is {} after login"
                            .format(ssh_who_command, user_count_after_login))
                        return user_count_before_login < user_count_after_login
                    except Exception as e:
                        logger.info("Exception: {}".format(e))
                        logger.info("Trying again to perform 'who --count' over ssh.")
                        return False

                # Number of users before login would be 0 and after login would be 180
                # If below assertion would fail user_count_after_login is also 0,
                # denoting login failed
                wait_for(func=_validate_login, timeout=300, delay=5)
                # create file on system
                vm_console.send_keys("touch blather")
                wait_for(func=vm_ssh_client.run_command, func_args=["ls blather"],
                    func_kwargs={'ensure_user': True},
                    fail_condition=lambda result: result.rc != 0, delay=1, num_sec=10)
                # if file was created in previous steps it will be removed here
                # we will get instance of SSHResult
                command_result = vm_ssh_client.run_command("rm blather", ensure_user=True)
                assert command_result

            except Exception as e:
                # Take a screenshot if an exception occurs
                vm_console.switch_to_console()
                take_screenshot("ConsoleScreenshot")
                vm_console.switch_to_appliance()
                raise e
开发者ID:mkoura,项目名称:cfme_tests,代码行数:93,代码来源:test_ssui_myservice.py

示例2: test_vm_console

# 需要导入模块: from cfme.services.myservice import MyService [as 别名]
# 或者: from cfme.services.myservice.MyService import launch_vm_console [as 别名]
def test_vm_console(request, appliance, setup_provider, context, configure_websocket,
        order_catalog_item_in_ops_ui, take_screenshot, console_template):
    """Test Myservice VM Console in SSUI."""
    catalog_item = order_catalog_item_in_ops_ui
    service_name = catalog_item.name
    console_vm_username = credentials[catalog_item.provider.data.templates.console_template
                            .creds].username
    console_vm_password = credentials[catalog_item.provider.data.templates.console_template
                            .creds].password
    with appliance.context.use(context):
        myservice = MyService(appliance, service_name)
        vm_obj = myservice.launch_vm_console(catalog_item)
        vm_console = vm_obj.vm_console
        request.addfinalizer(vm_console.close_console_window)
        request.addfinalizer(appliance.server.logout)
        with ssh.SSHClient(hostname=vm_obj.ip_address, username=console_vm_username,
                password=console_vm_password) as vm_ssh_client:
            try:
                assert vm_console.wait_for_connect(180), ("VM Console did not reach 'connected'"
                    " state")
                user_count_before_login = vm_ssh_client.run_command("who --count", ensure_user=True)
                logger.info("Output of who --count is {} before login"
                    .format(user_count_before_login))
                assert vm_console.wait_for_text(text_to_find="login:", timeout=200), ("VM Console"
                    " didn't prompt for Login")
                # Enter Username:
                vm_console.send_keys("{}".format(console_vm_username))
                assert vm_console.wait_for_text(text_to_find="Password", timeout=200), ("VM Console"
                " didn't prompt for Password")
                # Enter Password:
                vm_console.send_keys("{}".format(console_vm_password))
                logger.info("Wait to get the '$' prompt")
                vm_console.wait_for_text(text_to_find=catalog_item.provider.data.templates.
                    console_template.prompt_text, timeout=200)

                def _validate_login():
                    # the following try/except is required to handle the exception thrown by SSH
                    # while connecting to VMware VM.It throws "[Error 104]Connection reset by Peer".
                    try:
                        user_count_after_login = vm_ssh_client.run_command("who --count",
                                                    ensure_user=True)
                        logger.info("Output of 'who --count' is {} after login"
                        .format(user_count_after_login))
                        return user_count_before_login < user_count_after_login
                    except Exception as e:
                        logger.info("Exception: {}".format(e))
                        logger.info("Trying again to perform 'who --count' over ssh.")
                        return False

                # Number of users before login would be 0 and after login would be 180
                # If below assertion would fail user_count_after_login is also 0,
                # denoting login failed
                wait_for(func=_validate_login, timeout=300, delay=5)
                # create file on system
                vm_console.send_keys("touch blather")
                wait_for(func=vm_ssh_client.run_command, func_args=["ls blather"],
                    func_kwargs={'ensure_user': True},
                    fail_condition=lambda result: result.rc != 0, delay=1, num_sec=10)
                # if file was created in previous steps it will be removed here
                # we will get instance of SSHResult
                command_result = vm_ssh_client.run_command("rm blather", ensure_user=True)
                assert command_result

            except Exception as e:
                # Take a screenshot if an exception occurs
                vm_console.switch_to_console()
                take_screenshot("ConsoleScreenshot")
                vm_console.switch_to_appliance()
                raise e
开发者ID:hhovsepy,项目名称:cfme_tests,代码行数:71,代码来源:test_ssui_myservice.py


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