Example #1
0
def get_report(menu_name, candu=False):
    """Queue a report by menu name , wait for finish and return it"""
    path_to_report = ['Configuration Management', 'Containers', menu_name]
    try:
        run_at, queued_at = CannedSavedReport.queue_canned_report(path_to_report)
    except CandidateNotFound:
        pytest.skip('Could not find report "{}" in containers.\nTraceback:\n{}'
                    .format(path_to_report, format_exc()))
    return CannedSavedReport(path_to_report, run_at, queued_at, candu=candu)
def test_providers_summary(soft_assert):
    """Checks some informations about the provider. Does not check memory/frequency as there is
    presence of units and rounding."""
    path = ["Configuration Management", "Providers", "Providers Summary"]
    report = CannedSavedReport.new(path)
    for provider in report.data.rows:
        if any(ptype in provider["MS Type"]
               for ptype in {"ec2", "openstack"}):  # Skip cloud
            continue
        details_view = navigate_to(InfraProvider(name=provider["Name"]),
                                   'Details')
        props = details_view.entities.properties

        hostname = ("Host Name", "Hostname")
        soft_assert(
            props.get_text_of(hostname[0]) == provider[hostname[1]],
            "Hostname does not match at {}".format(provider["Name"]))

        cpu_cores = props.get_text_of("Aggregate Host CPU Cores")
        soft_assert(
            cpu_cores == provider["Total Number of Logical CPUs"],
            "Logical CPU count does not match at {}".format(provider["Name"]))

        host_cpu = props.get_text_of("Aggregate Host CPUs")
        soft_assert(
            host_cpu == provider["Total Number of Physical CPUs"],
            "Physical CPU count does not match at {}".format(provider["Name"]))
Example #3
0
def test_providers_summary(soft_assert, setup_a_provider):
    """Checks some informations about the provider. Does not check memory/frequency as there is
    presence of units and rounding."""
    path = ["Configuration Management", "Providers", "Providers Summary"]
    report = CannedSavedReport.new(path)
    for provider in report.data.rows:
        if any(ptype in provider["MS Type"]
               for ptype in {"ec2", "openstack"}):  # Skip cloud
            continue
        provider_fake_obj = Provider(name=provider["Name"])
        sel.force_navigate("infrastructure_provider",
                           context={"provider": provider_fake_obj})
        hostname = version.pick({
            version.LOWEST: ("Hostname", "Hostname"),
            "5.5": ("Host Name", "Hostname")
        })
        soft_assert(
            provider_props(hostname[0]) == provider[hostname[1]],
            "Hostname does not match at {}".format(provider["Name"]))

        if version.current_version() < "5.4":
            # In 5.4, hostname and IP address are shared under Hostname (above)
            soft_assert(
                provider_props("IP Address") == provider["IP Address"],
                "IP Address does not match at {}".format(provider["Name"]))

        soft_assert(
            provider_props("Aggregate Host CPU Cores") ==
            provider["Total Number of Logical CPUs"],
            "Logical CPU count does not match at {}".format(provider["Name"]))

        soft_assert(
            provider_props("Aggregate Host CPUs") ==
            provider["Total Number of Physical CPUs"],
            "Physical CPU count does not match at {}".format(provider["Name"]))
def test_datastores_summary(soft_assert, appliance):
    """Checks Datastores Summary report with DB data. Checks all data in report, even rounded
    storage sizes."""

    adb = appliance.db.client
    storages = adb['storages']
    vms = adb['vms']
    host_storages = adb['host_storages']

    path = ["Configuration Management", "Storage", "Datastores Summary"]
    report = CannedSavedReport.new(path)

    storages_in_db = adb.session.query(storages.store_type, storages.free_space,
                                       storages.total_space, storages.name, storages.id).all()

    assert len(storages_in_db) == len(list(report.data.rows))
    for store in storages_in_db:

        number_of_vms = adb.session.query(vms.id).filter(
            vms.storage_id == store.id).filter(
                vms.template == 'f').count()
        number_of_hosts = adb.session.query(host_storages.host_id).filter(
            host_storages.storage_id == store.id).count()

        for item in report.data.rows:
            if store.name.encode('utf8') == item['Datastore Name']:
                assert store.store_type.encode('utf8') == item['Type']
                assert round_num(store.free_space) == extract_num(item['Free Space'])
                assert round_num(store.total_space) == extract_num(item['Total Space'])
                assert int(number_of_hosts) == int(item['Number of Hosts'])
                assert int(number_of_vms) == int(item['Number of VMs'])
def test_datastores_summary(soft_assert, appliance):
    """Checks Datastores Summary report with DB data. Checks all data in report, even rounded
    storage sizes."""

    adb = appliance.db.client
    storages = adb['storages']
    vms = adb['vms']
    host_storages = adb['host_storages']

    path = ["Configuration Management", "Storage", "Datastores Summary"]
    report = CannedSavedReport.new(path)

    storages_in_db = adb.session.query(storages.store_type,
                                       storages.free_space,
                                       storages.total_space, storages.name,
                                       storages.id).all()

    assert len(storages_in_db) == len(list(report.data.rows))
    for store in storages_in_db:

        number_of_vms = adb.session.query(vms.id).filter(
            vms.storage_id == store.id).filter(vms.template == 'f').count()
        number_of_hosts = adb.session.query(host_storages.host_id).filter(
            host_storages.storage_id == store.id).count()

        for item in report.data.rows:
            if store.name.encode('utf8') == item['Datastore Name']:
                assert store.store_type.encode('utf8') == item['Type']
                assert round_num(store.free_space) == extract_num(
                    item['Free Space'])
                assert round_num(store.total_space) == extract_num(
                    item['Total Space'])
                assert int(number_of_hosts) == int(item['Number of Hosts'])
                assert int(number_of_vms) == int(item['Number of VMs'])
Example #6
0
def test_operations_vm_on(soft_assert, appliance):

    adb = appliance.db.client
    vms = adb['vms']
    hosts = adb['hosts']
    storages = adb['storages']

    path = ["Operations", "Virtual Machines", "Online VMs (Powered On)"]
    report = CannedSavedReport.new(path)

    vms_in_db = adb.session.query(
        vms.name.label('vm_name'), vms.location.label('vm_location'),
        vms.last_scan_on.label('vm_last_scan'),
        storages.name.label('storages_name'),
        hosts.name.label('hosts_name')).join(
            hosts, vms.host_id == hosts.id).join(
                storages, vms.storage_id == storages.id).filter(
                    vms.power_state == 'on').order_by(vms.name).all()

    assert len(vms_in_db) == len(list(report.data.rows))
    for vm in vms_in_db:
        store_path = '{}/{}'.format(vm.storages_name.encode('utf8'),
                                    vm.vm_location.encode('utf8'))
        for item in report.data.rows:
            if vm.vm_name.encode('utf8') == item['VM Name']:
                assert vm.hosts_name.encode('utf8') == item['Host']
                assert vm.storages_name.encode('utf8') == item['Datastore']
                assert store_path == item['Datastore Path']
                assert (str(vm.vm_last_scan).encode('utf8')
                        == item['Last Analysis Time']
                        or (str(vm.vm_last_scan).encode('utf8') == 'None'
                            and item['Last Analysis Time'] == ''))
def test_operations_vm_on(soft_assert, appliance):

    adb = appliance.db.client
    vms = adb['vms']
    hosts = adb['hosts']
    storages = adb['storages']

    path = ["Operations", "Virtual Machines", "Online VMs (Powered On)"]
    report = CannedSavedReport.new(path)

    vms_in_db = adb.session.query(
        vms.name.label('vm_name'),
        vms.location.label('vm_location'),
        vms.last_scan_on.label('vm_last_scan'),
        storages.name.label('storages_name'),
        hosts.name.label('hosts_name')).join(
            hosts, vms.host_id == hosts.id).join(
                storages, vms.storage_id == storages.id).filter(
                    vms.power_state == 'on').order_by(vms.name).all()

    assert len(vms_in_db) == len(list(report.data.rows))
    for vm in vms_in_db:
        store_path = '{}/{}'.format(vm.storages_name.encode('utf8'),
                                    vm.vm_location.encode('utf8'))
        for item in report.data.rows:
            if vm.vm_name.encode('utf8') == item['VM Name']:
                assert vm.hosts_name.encode('utf8') == item['Host']
                assert vm.storages_name.encode('utf8') == item['Datastore']
                assert store_path == item['Datastore Path']
                assert (str(vm.vm_last_scan).encode('utf8') == item['Last Analysis Time'] or
                 (str(vm.vm_last_scan).encode('utf8') == 'None' and
                 item['Last Analysis Time'] == ''))
Example #8
0
def test_operations_vm_on(soft_assert, appliance):
    adb = appliance.db.client
    vms = adb['vms']
    hosts = adb['hosts']
    storages = adb['storages']

    path = ["Operations", "Virtual Machines", "Online VMs (Powered On)"]
    report = CannedSavedReport.new(path)

    vms_in_db = adb.session.query(
        vms.name.label('vm_name'),
        vms.location.label('vm_location'),
        vms.last_scan_on.label('vm_last_scan'),
        storages.name.label('storages_name'),
        hosts.name.label('hosts_name')).outerjoin(
            hosts, vms.host_id == hosts.id).outerjoin(
                storages, vms.storage_id == storages.id).filter(
                    vms.power_state == 'on').order_by(vms.name).all()
    assert len(vms_in_db) == len(list(report.data.rows))
    vm_names = [vm.vm_name for vm in vms_in_db]
    for vm in vms_in_db:
        # Following check is based on BZ 1504010
        assert vm_names.count(vm.vm_name) == 1, \
            'There is a duplicate entry in DB for VM {}'.format(vm.vm_name)
        store_path = vm.vm_location.encode('utf8')
        if vm.storages_name:
            store_path = '{}/{}'.format(vm.storages_name.encode('utf8'), store_path)
        for item in report.data.rows:
            if vm.vm_name.encode('utf8') == item['VM Name']:
                assert compare(vm.hosts_name, item['Host'])
                assert compare(vm.storages_name, item['Datastore'])
                assert compare(store_path, item['Datastore Path'])
                assert compare(vm.vm_last_scan, item['Last Analysis Time'])
def test_providers_summary(soft_assert, setup_a_provider):
    """Checks some informations about the provider. Does not check memory/frequency as there is
    presence of units and rounding."""
    path = ["Configuration Management", "Providers", "Providers Summary"]
    report = CannedSavedReport.new(path)
    for provider in report.data.rows:
        if any(ptype in provider["MS Type"] for ptype in {"ec2", "openstack"}):  # Skip cloud
            continue
        provider_fake_obj = Provider(name=provider["Name"])
        sel.force_navigate("infrastructure_provider", context={"provider": provider_fake_obj})
        hostname = version.pick({
            version.LOWEST: ("Hostname", "Hostname"),
            "5.5": ("Host Name", "Hostname")})
        soft_assert(
            provider_props(hostname[0]) == provider[hostname[1]],
            "Hostname does not match at {}".format(provider["Name"]))

        if version.current_version() < "5.4":
            # In 5.4, hostname and IP address are shared under Hostname (above)
            soft_assert(
                provider_props("IP Address") == provider["IP Address"],
                "IP Address does not match at {}".format(provider["Name"]))

        soft_assert(
            provider_props("Aggregate Host CPU Cores") == provider["Total Number of Logical CPUs"],
            "Logical CPU count does not match at {}".format(provider["Name"]))

        soft_assert(
            provider_props("Aggregate Host CPUs") == provider["Total Number of Physical CPUs"],
            "Physical CPU count does not match at {}".format(provider["Name"]))
def test_tabular_view(request, setup_a_provider):
    path = [
        "Configuration Management", "Hosts", "Virtual Infrastructure Platforms"
    ]
    report = CannedSavedReport.new(path)
    report.navigate()
    tb.set_vms_tabular_view()
    assert tb.is_vms_tabular_view(), "Tabular view setting failed"
Example #11
0
def test_graph_view(request, setup_a_provider):
    path = [
        "Configuration Management", "Hosts", "Virtual Infrastructure Platforms"
    ]
    report = CannedSavedReport.new(path)
    report.navigate()
    tb.select('Graph View')
    assert tb.is_active('Graph View'), "Graph view setting failed"
Example #12
0
def get_report(menu_name, candu=False):
    """Queue a report by menu name , wait for finish and return it"""
    path_to_report = ['Configuration Management', 'Containers', menu_name]
    try:
        run_at, queued_at = CannedSavedReport.queue_canned_report(path_to_report)
    except CandidateNotFound:
        pytest.skip('Could not find report "{}" in containers.\nTraceback:\n{}'
                    .format(path_to_report, format_exc()))
    return CannedSavedReport(path_to_report, run_at, queued_at, candu=candu)
Example #13
0
def test_reports_generate_report(request, path):
    """ This Tests run one default report for each category

    Steps:
        *Run one default report
        *Delete this Saved Report from the Database
    """

    report = CannedSavedReport.new(path)
    request.addfinalizer(report.delete_if_exists)
Example #14
0
def test_reports_generate_report(request, path):
    """ This Tests run one default report for each category

    Steps:
        *Run one default report
        *Delete this Saved Report from the Database
    """

    report = CannedSavedReport.new(path)
    request.addfinalizer(report.delete_if_exists)
Example #15
0
def test_datastores_summary(soft_assert, appliance, request):
    """Checks Datastores Summary report with DB data. Checks all data in report, even rounded
    storage sizes."""
    adb = appliance.db.client
    storages = adb['storages']
    vms = adb['vms']
    host_storages = adb['host_storages']

    path = ["Configuration Management", "Storage", "Datastores Summary"]
    report = CannedSavedReport.new(path)

    storages_in_db = adb.session.query(storages.store_type,
                                       storages.free_space,
                                       storages.total_space, storages.name,
                                       storages.id).all()

    assert len(storages_in_db) == len(list(report.data.rows))

    @request.addfinalizer
    def _finalize():
        report.delete()

    storages_in_db_list = []
    report_rows_list = []

    for store in storages_in_db:

        number_of_vms = adb.session.query(vms.id).filter(
            vms.storage_id == store.id).filter(vms.template == 'f').count()

        number_of_hosts = adb.session.query(host_storages.host_id).filter(
            host_storages.storage_id == store.id).count()

        store_dict = {
            'Datastore Name': store.name.encode('utf8'),
            'Type': store.store_type.encode('utf8'),
            'Free Space': round_num(store.free_space),
            'Total Space': round_num(store.total_space),
            'Number of Hosts': int(number_of_hosts),
            'Number of VMs': int(number_of_vms)
        }

        storages_in_db_list.append(store_dict)

    for row in report.data.rows:

        row['Free Space'] = extract_num(row['Free Space'])
        row['Total Space'] = extract_num(row['Total Space'])
        row['Number of Hosts'] = int(row['Number of Hosts'])
        row['Number of VMs'] = int(row['Number of VMs'])

        report_rows_list.append(row)

    assert sorted(storages_in_db_list) == sorted(report_rows_list)
def test_report_page_per_item(setup_a_provider, set_report):
    """ Tests report items per page

    Metadata:
        test_flag: visuals
    """
    path = ["Configuration Management", "Virtual Machines", "VMs Snapshot Summary"]
    limit = visual.report_view_limit
    report = CannedSavedReport.new(path)
    report.navigate()
    if int(paginator.rec_total()) >= int(limit):
        assert int(paginator.rec_end()) == int(limit), "Reportview Failed!"
def test_report_page_per_item(setup_a_provider, set_report):
    """ Tests report items per page

    Metadata:
        test_flag: visuals
    """
    path = ["Configuration Management", "Virtual Machines", "VMs Snapshot Summary"]
    limit = visual.report_view_limit
    report = CannedSavedReport.new(path)
    report.navigate()
    if int(paginator.rec_total()) >= int(limit):
        assert int(paginator.rec_end()) == int(limit), "Reportview Failed!"
Example #18
0
def report():
    # TODO parameterize on path, for now test infrastructure reports
    path = ["Configuration Management", "Hosts", "Virtual Infrastructure Platforms"]
    report = CannedSavedReport.new(path)
    report_time = report.datetime
    logger.debug('Created report for path {} and time {}'.format(path, report_time))
    yield report

    try:
        report.delete()
    except Exception:
        logger.warning('Failed to delete report for path {} and time {}'.format(path, report_time))
def test_infra_report_page_per_item(set_report):
    """ Tests report items per page

    Metadata:
        test_flag: visuals
    """
    path = ["Configuration Management", "Virtual Machines", "VMs Snapshot Summary"]
    limit = visual.report_view_limit
    report = CannedSavedReport.new(path)
    view = navigate_to(report, 'Details')
    min_item, max_item, item_amt = view.paginator.paginator.page_info()
    if int(view.paginator.items_amount) >= int(limit):
        assert int(max_item) == int(limit), "Reportview Failed!"
    assert int(max_item) <= int(item_amt)
def test_infra_report_page_per_item(value, set_report):
    """ Tests report items per page

    Metadata:
        test_flag: visuals
    """
    visual.report_view_limit = value
    path = ["Configuration Management", "Virtual Machines", "VMs Snapshot Summary"]
    limit = visual.report_view_limit
    report = CannedSavedReport.new(path)
    view = navigate_to(report, 'Details')
    max_item = view.paginator.max_item
    item_amt = view.paginator.items_amount
    if int(item_amt) >= int(limit):
        assert int(max_item) == int(limit), "Reportview Failed!"
    assert int(max_item) <= int(item_amt)
def test_cluster_relationships(soft_assert, setup_a_provider):
    path = ["Relationships", "Virtual Machines, Folders, Clusters", "Cluster Relationships"]
    report = CannedSavedReport.new(path)
    for relation in report.data.rows:
        name = relation["Name"]
        provider_name = relation["Provider Name"]
        provider = provider_factory_by_name(provider_name)
        host_name = relation["Host Name"]
        soft_assert(name in provider.list_cluster(), "Cluster {} not found in {}".format(
            name, provider_name
        ))
        for host in provider.list_host():
            if host_name in host or host in host_name:  # Tends to get truncated and so
                break
        else:
            soft_assert(False, "Hostname {} not found in {}".format(host_name, provider_name))
Example #22
0
def test_cluster_relationships(soft_assert):
    path = [
        "Relationships", "Virtual Machines, Folders, Clusters",
        "Cluster Relationships"
    ]
    report = CannedSavedReport.new(path)
    for relation in report.data.rows:
        name = relation["Name"]
        provider_name = relation["Provider Name"]
        if not provider_name.strip():
            # If no provider name specified, ignore it
            continue
        provider = get_crud_by_name(provider_name).mgmt
        host_name = relation["Host Name"].strip()
        verified_cluster = [
            item for item in provider.list_cluster() if name in item
        ]
        soft_assert(verified_cluster,
                    "Cluster {} not found in {}".format(name, provider_name))
        if not host_name:
            continue  # No host name
        host_ip = resolve_hostname(host_name, force=True)
        if host_ip is None:
            # Don't check
            continue
        for host in provider.list_host():
            if ip_address.match(host) is None:
                host_is_ip = False
                ip_from_provider = resolve_hostname(host, force=True)
            else:
                host_is_ip = True
                ip_from_provider = host
            if not host_is_ip:
                # Strings first
                if host == host_name:
                    break
                elif host_name.startswith(host):
                    break
                elif ip_from_provider is not None and ip_from_provider == host_ip:
                    break
            else:
                if host_ip == ip_from_provider:
                    break
        else:
            soft_assert(
                False,
                "Hostname {} not found in {}".format(host_name, provider_name))
def test_cluster_relationships(soft_assert, setup_a_provider):
    path = ["Relationships", "Virtual Machines, Folders, Clusters", "Cluster Relationships"]
    report = CannedSavedReport.new(path)
    for relation in report.data.rows:
        name = relation["Name"]
        provider_name = relation["Provider Name"]
        if not provider_name.strip():
            # If no provider name specified, ignore it
            continue
        provider = get_mgmt_by_name(provider_name)
        host_name = relation["Host Name"].strip()
        soft_assert(name in provider.list_cluster(), "Cluster {} not found in {}".format(
            name, provider_name
        ))
        if not host_name:
            continue  # No host name
        host_ip = resolve_hostname(host_name, force=True)
        if host_ip is None:
            # Don't check
            continue
        for host in provider.list_host():
            if ip_address.match(host) is None:
                host_is_ip = False
                ip_from_provider = resolve_hostname(host, force=True)
            else:
                host_is_ip = True
                ip_from_provider = host
            if not host_is_ip:
                # Strings first
                if host == host_name:
                    break
                elif host_name.startswith(host):
                    break
                elif ip_from_provider is not None and ip_from_provider == host_ip:
                    break
            else:
                if host_ip == ip_from_provider:
                    break
        else:
            soft_assert(False, "Hostname {} not found in {}".format(host_name, provider_name))
def test_providers_summary(soft_assert):
    """Checks some informations about the provider. Does not check memory/frequency as there is
    presence of units and rounding."""
    path = ["Configuration Management", "Providers", "Providers Summary"]
    report = CannedSavedReport.new(path)
    for provider in report.data.rows:
        if any(ptype in provider["MS Type"] for ptype in {"ec2", "openstack"}):  # Skip cloud
            continue
        details_view = navigate_to(InfraProvider(name=provider["Name"]), 'Details')
        props = details_view.entities.properties

        hostname = ("Host Name", "Hostname")
        soft_assert(props.get_text_of(hostname[0]) == provider[hostname[1]],
                    "Hostname does not match at {}".format(provider["Name"]))

        cpu_cores = props.get_text_of("Aggregate Host CPU Cores")
        soft_assert(cpu_cores == provider["Total Number of Logical CPUs"],
                    "Logical CPU count does not match at {}".format(provider["Name"]))

        host_cpu = props.get_text_of("Aggregate Host CPUs")
        soft_assert(host_cpu == provider["Total Number of Physical CPUs"],
                    "Physical CPU count does not match at {}".format(provider["Name"]))
def test_tabular_view(request, setup_a_provider):
    path = ["Configuration Management", "Hosts", "Virtual Infrastructure Platforms"]
    report = CannedSavedReport.new(path)
    report.navigate()
    tb.select('Tabular View')
    assert tb.is_active('Tabular View'), "Tabular view setting failed"
def test_graph_view(request, setup_a_provider):
    path = ["Configuration Management", "Hosts", "Virtual Infrastructure Platforms"]
    report = CannedSavedReport.new(path)
    report.navigate()
    tb.set_vms_graph_view()
    assert tb.is_vms_graph_view(), "Graph view setting failed"
Example #27
0
def report():
    path = ["Configuration Management", "Virtual Machines", "Hardware Information for VMs"]
    return CannedSavedReport(path, CannedSavedReport.queue_canned_report(path))
Example #28
0
def get_report(menu_name):
    """Queue a report by menu name , wait for finish and return it"""
    path_to_report = ['Configuration Management', 'Containers', menu_name]
    run_at = CannedSavedReport.queue_canned_report(path_to_report)
    return CannedSavedReport(path_to_report, run_at)
Example #29
0
def report():
    path = [
        "Configuration Management", "Virtual Machines",
        "Hardware Information for VMs"
    ]
    return CannedSavedReport(path, CannedSavedReport.queue_canned_report(path))