Exemple #1
0
def pytest_generate_tests(metafunc):
    new_idlist = []
    new_argvalues = []

    argnames, argvalues, idlist = testgen.provider_by_type(
        metafunc, PROVIDER_TYPES, required_fields=['datastores'])
    argnames += ['datastore']

    for i, argvalue_tuple in enumerate(argvalues):
        args = dict(zip(argnames, argvalue_tuple))
        datastores = args['provider'].data.get('datastores', {})
        if not datastores:
            continue
        for ds in datastores:
            if not ds.get('test_fleece', False):
                continue
            assert ds.get('type', None) in DATASTORE_TYPES,\
                'datastore type must be set to [{}] for smartstate analysis tests'\
                .format('|'.join(DATASTORE_TYPES))
            argvs = argvalues[i][:]
            new_argvalues.append(argvs + [
                datastore.Datastore(ds['name'], args['provider'].key,
                                    ds['type'])
            ])
            test_id = '{}-{}'.format(args['provider'].key, ds['type'])
            new_idlist.append(test_id)
    testgen.parametrize(metafunc,
                        argnames,
                        new_argvalues,
                        ids=new_idlist,
                        scope="module")
def test_delete_datastore_appear_after_refresh(setup_provider, provider):
    """ Tests delete datastore

    Metadata:
        test_flag: delete_object
    """
    data_store = provider.data['remove_test']['datastore']
    test_datastore = datastore.Datastore(name=data_store, provider=provider)
    details_view = navigate_to(test_datastore, 'Details')

    host_count = int(details_view.contents.relationships.get_text_of('Hosts'))
    vm_count = int(
        details_view.contents.relationships.get_text_of('Managed VMs'))
    if host_count != "0":
        test_datastore.delete_all_attached_hosts()
    if vm_count != "0":
        test_datastore.delete_all_attached_vms()

    test_datastore.delete(cancel=False)
    wait_for(lambda: not test_datastore.exists,
             fail_condition=False,
             message="Wait datastore to disappear",
             num_sec=500,
             fail_func=test_datastore.browser.refresh)

    provider.refresh_provider_relationships()
    wait_for(lambda: test_datastore.exists,
             fail_condition=False,
             message="Wait datastore to appear",
             num_sec=1000,
             fail_func=test_datastore.browser.refresh)
Exemple #3
0
def test_delete_datastore_appear_after_refresh(setup_provider, provider):
    """ Tests delete datastore

    Metadata:
        test_flag: delete_object
    """
    data_store = provider.data['remove_test']['datastore']
    test_datastore = datastore.Datastore(name=data_store)
    host_count = test_datastore.get_detail('Relationships', 'Hosts')
    vm_count = test_datastore.get_detail('Relationships', 'Managed VMs')
    if host_count != "0":
        test_datastore.delete_all_attached_hosts()
        test_datastore.wait_for_delete_all()
    if vm_count != "0":
        test_datastore.delete_all_attached_vms()
        test_datastore.wait_for_delete_all()
    test_datastore.delete(cancel=False)
    test_datastore.wait_for_delete()
    provider.refresh_provider_relationships()
    test_datastore.wait_for_appear()
def test_delete_datastore(setup_provider, provider, remove_test):
    """ Tests delete datastore

    Metadata:
        test_flag: delete_object
    """
    data_store = remove_test['datastore']
    test_datastore = datastore.Datastore(name=data_store)
    host_count = len(test_datastore.get_hosts())
    vm_count = len(test_datastore.get_vms())
    if host_count != 0:
        test_datastore.delete_all_attached_hosts()
        test_datastore.wait_for_delete_all()
    if vm_count != 0:
        test_datastore.delete_all_attached_vms()
        test_datastore.wait_for_delete_all()
    test_datastore.delete(cancel=False)
    test_datastore.wait_for_delete()
    provider.refresh_provider_relationships()
    test_datastore.wait_for_appear()
def test_run_datastore_analysis(request, provider_key, datastore_type,
                                datastore_name):
    """ Run host SmartState analysis
    """
    test_datastore = datastore.Datastore(datastore_name, provider_key)

    # Check if there is a host with valid credentials
    host_qis = test_datastore.get_hosts()
    assert len(host_qis) != 0, "No hosts attached to this datastore found"
    for host_qi in host_qis:
        if host_qi.creds == 'checkmark':
            break
    else:
        # If not, get credentials for one of the present hosts
        found_host = False
        for host_qi in host_qis:
            host_data = get_host_data_by_name(provider_key, host_qi._name)
            if host_data is None:
                continue

            found_host = True
            test_host = host.Host(name=host_qi._name)

            # Add them to the host
            wait_for(lambda: test_host.exists,
                     delay=10,
                     num_sec=120,
                     fail_func=sel.refresh)
            if not test_host.has_valid_credentials:
                test_host.update(
                    updates={
                        'credentials':
                        host.get_credentials_from_config(
                            host_data['credentials'])
                    })
                wait_for(lambda: test_host.has_valid_credentials,
                         delay=10,
                         num_sec=120,
                         fail_func=sel.refresh)

                # And remove them again when the test is finished
                def test_host_remove_creds():
                    test_host.update(
                        updates={
                            'credentials':
                            host.Host.Credential(
                                principal="", secret="", verify_secret="")
                        })

                request.addfinalizer(test_host_remove_creds)
            break

        assert found_host,\
            "No credentials found for any of the hosts attached to datastore {}"\
            .format(datastore_name)

    # TODO add support for events
    # register_event(
    #     None,
    #     "datastore",
    #     datastore_name,
    #     ["datastore_analysis_request_req", "datastore_analysis_complete_req"]
    # )

    # Initiate analysis
    sel.force_navigate('infrastructure_datastore',
                       context={
                           'datastore': test_datastore,
                           'provider': test_datastore.provider
                       })
    tb.select('Configuration',
              'Perform SmartState Analysis',
              invokes_alert=True)
    sel.handle_alert()
    flash.assert_message_contain(
        '"{}": scan successfully initiated'.format(datastore_name))

    # Wait for the task to finish
    def is_datastore_analysis_finished():
        """ Check if analysis is finished - if not, reload page
        """
        if not sel.is_displayed(tasks.tasks_table) or not tabs.is_tab_selected(
                'All Other Tasks'):
            sel.force_navigate('tasks_all_other')
        host_analysis_finished = tasks.tasks_table.find_row_by_cells({
            'task_name':
            "SmartState Analysis for [{}]".format(datastore_name),
            'state':
            'Finished'
        })
        return host_analysis_finished is not None

    wait_for(is_datastore_analysis_finished,
             delay=10,
             num_sec=300,
             fail_func=lambda: tb.select('Reload'))

    # Delete the task
    tasks.tasks_table.select_row_by_cells({
        'task_name':
        "SmartState Analysis for [{}]".format(datastore_name),
        'state':
        'Finished'
    })
    tb.select('Delete Tasks', 'Delete', invokes_alert=True)
    sel.handle_alert()

    # Check results of the analysis and the datastore type
    assert test_datastore.get_detail('Properties', 'Datastore Type') == datastore_type.upper(),\
        'Datastore type does not match the type defined in yaml'
    for row_name in CONTENT_ROWS_TO_CHECK:
        assert test_datastore.get_detail('Content', row_name) != '0',\
            '{} in Content infoblock should not be 0'.format(row_name)
def test_ssa_template(request, local_setup_provider, provider, soft_assert,
                      vm_analysis_data):
    """ Tests SSA can be performed on a template

    Metadata:
        test_flag: vm_analysis
    """

    template_name = vm_analysis_data['image']
    template = Template.factory(template_name, provider, template=True)

    # Set credentials to all hosts set for this datastore
    if provider.type in ['virtualcenter', 'rhevm']:
        datastore_name = vm_analysis_data['datastore']
        test_datastore = datastore.Datastore(datastore_name, provider.key)
        host_list = cfme_data.get('management_systems',
                                  {})[provider.key].get('hosts', [])
        host_names = test_datastore.get_hosts()
        for host_name in host_names:
            test_host = host.Host(name=host_name, provider=provider)
            hosts_data = [x for x in host_list if x.name == host_name]
            if len(hosts_data) > 0:
                host_data = hosts_data[0]

                if not test_host.has_valid_credentials:
                    creds = host.get_credentials_from_config(
                        host_data['credentials'])
                    test_host.update(updates={'credentials': creds},
                                     validate_credentials=True)

    template.smartstate_scan()
    wait_for(lambda: is_vm_analysis_finished(template_name),
             delay=15,
             timeout="35m",
             fail_func=lambda: toolbar.select('Reload'))

    # Check release and quadricon
    quadicon_os_icon = template.find_quadicon().os
    details_os_icon = template.get_detail(properties=('Properties',
                                                      'Operating System'),
                                          icon_href=True)
    logger.info("Icons: {}, {}".format(details_os_icon, quadicon_os_icon))

    # We shouldn't use get_detail anymore - it takes too much time
    c_users = InfoBlock.text('Security', 'Users')
    c_groups = InfoBlock.text('Security', 'Groups')
    c_packages = 0
    if vm_analysis_data['fs-type'] not in ['ntfs', 'fat32']:
        c_packages = InfoBlock.text('Configuration', 'Packages')

    logger.info("SSA shows {} users, {} groups and {} packages".format(
        c_users, c_groups, c_packages))

    if vm_analysis_data['fs-type'] not in ['ntfs', 'fat32']:
        soft_assert(c_users != '0', "users: '{}' != '0'".format(c_users))
        soft_assert(c_groups != '0', "groups: '{}' != '0'".format(c_groups))
        soft_assert(c_packages != '0',
                    "packages: '{}' != '0'".format(c_packages))
    else:
        # Make sure windows-specific data is not empty
        c_patches = InfoBlock.text('Security', 'Patches')
        c_applications = InfoBlock.text('Configuration', 'Applications')
        c_win32_services = InfoBlock.text('Configuration', 'Win32 Services')
        c_kernel_drivers = InfoBlock.text('Configuration', 'Kernel Drivers')
        c_fs_drivers = InfoBlock.text('Configuration', 'File System Drivers')

        soft_assert(c_patches != '0', "patches: '{}' != '0'".format(c_patches))
        soft_assert(c_applications != '0',
                    "applications: '{}' != '0'".format(c_applications))
        soft_assert(c_win32_services != '0',
                    "win32 services: '{}' != '0'".format(c_win32_services))
        soft_assert(c_kernel_drivers != '0',
                    "kernel drivers: '{}' != '0'".format(c_kernel_drivers))
        soft_assert(c_fs_drivers != '0',
                    "fs drivers: '{}' != '0'".format(c_fs_drivers))
def test_run_datastore_analysis(request, setup_provider, provider,
                                datastore_type, datastore_name, soft_assert):
    """Tests smarthost analysis

    Metadata:
        test_flag: datastore_analysis
    """
    test_datastore = datastore.Datastore(datastore_name, provider.key)

    # Check if there is a host with valid credentials
    host_names = test_datastore.get_hosts()
    assert len(host_names) != 0, "No hosts attached to this datastore found"
    for host_name in host_names:
        host_qi = Quadicon(host_name, 'host')
        if host_qi.creds == 'checkmark':
            break
    else:
        # If not, get credentials for one of the present hosts
        found_host = False
        for host_name in host_names:
            host_data = get_host_data_by_name(provider.key, host_name)
            if host_data is None:
                continue

            found_host = True
            test_host = host.Host(name=host_name)

            # Add them to the host
            wait_for(lambda: test_host.exists,
                     delay=10,
                     num_sec=120,
                     fail_func=sel.refresh)
            if not test_host.has_valid_credentials:
                test_host.update(
                    updates={
                        'credentials':
                        host.get_credentials_from_config(
                            host_data['credentials'])
                    })
                wait_for(lambda: test_host.has_valid_credentials,
                         delay=10,
                         num_sec=120,
                         fail_func=sel.refresh)

                # And remove them again when the test is finished
                def test_host_remove_creds():
                    test_host.update(
                        updates={
                            'credentials':
                            host.Host.Credential(
                                principal="", secret="", verify_secret="")
                        })

                request.addfinalizer(test_host_remove_creds)
            break

        assert found_host,\
            "No credentials found for any of the hosts attached to datastore {}"\
            .format(datastore_name)

    # TODO add support for events
    # register_event(
    #     None,
    #     "datastore",
    #     datastore_name,
    #     ["datastore_analysis_request_req", "datastore_analysis_complete_req"]
    # )

    # Initiate analysis
    test_datastore.run_smartstate_analysis()
    wait_for(lambda: is_datastore_analysis_finished(datastore_name),
             delay=15,
             timeout="10m",
             fail_func=lambda: toolbar.select('Reload'))

    c_datastore = test_datastore.get_detail('Properties', 'Datastore Type')
    # Check results of the analysis and the datastore type
    soft_assert(
        c_datastore == datastore_type.upper(),
        'Datastore type does not match the type defined in yaml:' +
        'expected "{}" but was "{}"'.format(datastore_type.upper(),
                                            c_datastore))
    for row_name in CONTENT_ROWS_TO_CHECK:
        value = InfoBlock('Content', row_name).text
        soft_assert(value != '0',
                    'Expected value for {} to be non-empty'.format(row_name))