def test_action_initiate_smartstate_analysis(
    request, configure_fleecing, vm, vm_off, policy_for_testing
):
    """ This test tests actions 'Initiate SmartState Analysis for VM'.

    This test sets the policy that it analyses VM after it's powered on. Then it checks whether
    that really happened.

    Metadata:
        test_flag: actions, provision

    Polarion:
        assignee: dgaikwad
        initialEstimate: 1/6h
        casecomponent: Control
    """
    # Set up the policy and prepare finalizer
    policy_for_testing.assign_actions_to_event("VM Power On",
        ["Initiate SmartState Analysis for VM"])

    @request.addfinalizer
    def _cleanup():
        policy_for_testing.unassign_events("VM Power On")

    # Start the VM
    vm.power_control_from_cfme(option=vm.POWER_ON, cancel=False, from_details=True)
    wait_for_ssa_enabled(vm)
    try:
        do_scan(vm)
    except TimedOutError:
        pytest.fail(f"CFME did not finish analysing the VM {vm.name}")
示例#2
0
def test_rest_vm_compliance_subcollection(create_policy_profile,
                                          compliance_vm):
    """
    Bugzilla:
        1806660
        1806656

    Polarion:
        assignee: pvala
        casecomponent: Infra
        caseimportance: medium
        initialEstimate: 1/10h
        setup:
            1. Create condition.
            2. Create policy with the condition.
            3. Create a policy profile with the policy.
            4. Provision a VM.
        testSteps:
            1. Assign policy profile to the VM.
            2. Scan the VM.
            3. Check compliance of the VM.
            4. Check if compliance data is available under VM's `compliances` subcollection
    """
    compliance_vm.assign_policy_profiles(create_policy_profile.description)
    do_scan(compliance_vm)
    compliance_vm.check_compliance()
    assert compliance_vm.rest_api_entity.compliances.all
示例#3
0
def test_check_files(request, appliance, compliance_vm, analysis_profile):
    """This test checks presence and contents of a certain file. Due to caching, an existing file
    is checked.

    Metadata:
        test_flag: provision, policy

    Bugzilla:
        1730805

    Polarion:
        assignee: jdupuy
        initialEstimate: 1/4h
        casecomponent: Control
        caseimportance: high
    """
    check_file_name = "/etc/hosts"
    check_file_contents = "127.0.0.1"
    condition = appliance.collections.conditions.create(
        VMCondition,
        fauxfactory.gen_alphanumeric(40,
                                     start="Compliance testing condition "),
        expression=("fill_find(VM and Instance.Files : Name, "
                    "=, {}, Check Any, Contents, INCLUDES, {})".format(
                        check_file_name, check_file_contents)))
    request.addfinalizer(lambda: diaper(condition.delete))
    policy = appliance.collections.policies.create(
        VMCompliancePolicy,
        fauxfactory.gen_alphanumeric(15, start="Compliance "))
    request.addfinalizer(lambda: diaper(policy.delete))
    policy.assign_conditions(condition)
    profile = appliance.collections.policy_profiles.create(
        fauxfactory.gen_alphanumeric(20, start="Compliance PP "),
        policies=[policy])
    request.addfinalizer(lambda: diaper(profile.delete))
    compliance_vm.assign_policy_profiles(profile.description)
    request.addfinalizer(
        lambda: compliance_vm.unassign_policy_profiles(profile.description))

    with update(analysis_profile):
        analysis_profile.files = [{
            "Name": check_file_name,
            "Collect Contents?": True
        }]

    do_scan(compliance_vm, ("Configuration", "Files"))
    compliance_vm.check_compliance()
    assert compliance_vm.compliant
示例#4
0
def test_check_package_presence(request, appliance, compliance_vm,
                                analysis_profile):
    """This test checks compliance by presence of a certain "kernel" package which is expected
    to be present on the full_template.

    Metadata:
        test_flag: provision, policy

    Bugzilla:
        1730805

    Polarion:
        assignee: jdupuy
        initialEstimate: 1/4h
        casecomponent: Control
        caseimportance: high
    """
    condition = appliance.collections.conditions.create(
        VMCondition,
        fauxfactory.gen_alphanumeric(40,
                                     start="Compliance testing condition "),
        expression=
        ("fill_find(field=VM and Instance.Guest Applications : Name, "
         "skey=STARTS WITH, value=kernel, check=Check Count, ckey= = , cvalue=1)"
         ))
    request.addfinalizer(lambda: diaper(condition.delete))
    policy = appliance.collections.policies.create(
        VMCompliancePolicy,
        fauxfactory.gen_alphanumeric(15, start="Compliance "))
    request.addfinalizer(lambda: diaper(policy.delete))
    policy.assign_conditions(condition)
    profile = appliance.collections.policy_profiles.create(
        fauxfactory.gen_alphanumeric(20, start="Compliance PP "),
        policies=[policy])
    request.addfinalizer(lambda: diaper(profile.delete))
    compliance_vm.assign_policy_profiles(profile.description)
    request.addfinalizer(
        lambda: compliance_vm.unassign_policy_profiles(profile.description))
    do_scan(compliance_vm)
    compliance_vm.check_compliance()
    assert compliance_vm.compliant
示例#5
0
def test_action_prevent_ssa(request, configure_fleecing, vm, vm_on,
                            policy_for_testing):
    """Tests preventing Smart State Analysis.

    This test sets the policy that prevents VM analysis.

    Bugzilla:
        1433084

    Metadata:
        test_flag: actions, provision

    Polarion:
        assignee: jdupuy
        initialEstimate: 1/4h
        casecomponent: Control
    """
    policy_for_testing.assign_actions_to_event(
        "VM Analysis Request", ["Prevent current event from proceeding"])

    @request.addfinalizer
    def _cleanup():
        policy_for_testing.unassign_events("VM Analysis Request")

    policy_result = LogValidator(
        "/var/www/miq/vmdb/log/policy.log",
        matched_patterns=[
            '.*Prevent current event from proceeding.*VM Analysis Request.*{}'.
            format(vm.name)
        ])
    policy_result.start_monitoring()

    wait_for_ssa_enabled(vm)

    try:
        do_scan(vm)
    except TimedOutError:
        assert policy_result.validate(wait="120s")
    else:
        pytest.fail("CFME did not prevent analysing the VM {}".format(vm.name))
示例#6
0
def test_alert_hardware_reconfigured(request, appliance, configure_fleecing, smtp_test,
        create_vm, setup_for_alerts):
    """Tests alert based on "Hardware Reconfigured" evaluation.

    According https://bugzilla.redhat.com/show_bug.cgi?id=1396544 Hardware Reconfigured alerts
    require drift history. So here are the steps for triggering hardware reconfigured alerts based
    on CPU Count:
        1. Run VM smart state analysis.
        2. Change CPU count.
        3. Run VM smart state analysis again.
        4. Run VM reconfigure again.
    Then the alert for CPU count change should be triggered. It is either CPU increased or decreased
    depending on what has been done in your step 2, not the result of step 4. Step 4 is just to
    trigger the event.

    Bugzilla:
        1396544
        1730805

    Metadata:
        test_flag: alerts, provision

    Polarion:
        assignee: tpapaioa
        casecomponent: Control
        initialEstimate: 1/4h
    """
    vm = create_vm
    email = fauxfactory.gen_email()
    service_request_desc = ("VM Reconfigure for: {0} - Processor Sockets: {1}, "
        "Processor Cores Per Socket: 1, Total Processors: {1}")
    alert = appliance.collections.alerts.create(
        fauxfactory.gen_alpha(length=36, start="Trigger by hardware reconfigured "),
        active=True,
        based_on="VM and Instance",
        evaluate=(
            "Hardware Reconfigured",
            {
                "hardware_attribute": "Number of CPU Cores",
                "operator": "Increased",
            }
        ),
        notification_frequency="1 Minute",
        emails=email
    )
    request.addfinalizer(alert.delete)
    setup_for_alerts(request, [alert], vm_name=vm.name)
    wait_for_ssa_enabled(vm)
    sockets_count = vm.configuration.hw.sockets

    for i in range(1, 3):
        do_scan(vm, rediscover=False)
        vm.reconfigure(changes={
            "cpu": True, "sockets": str(sockets_count + i),
            "disks": (),
            "network_adapters": ()
        })
        service_request = appliance.collections.requests.instantiate(
            description=service_request_desc.format(vm.name, sockets_count + i))
        service_request.wait_for_request(method="ui", num_sec=300, delay=10)
    wait_for_alert(
        smtp_test,
        alert,
        delay=30 * 60,
        additional_checks={"text": vm.name, "from_address": email}
    )