Ejemplo n.º 1
0
def middleware_evm_log_no_error():
    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            skip_patterns=['.*ERROR.*API.*MIQ(Api::ApiController.api_error).*'],
                            failure_patterns=['.*ERROR.*'])
    evm_tail.fix_before_start()
    yield
    evm_tail.validate_logs()
Ejemplo n.º 2
0
def test_external_auth(auth_type, ipa_crud, app_creds):
    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to true.*'.format(auth_type)],
        hostname=ipa_crud.address,
        username=app_creds['sshlogin'],
        password=app_creds['password'])
    evm_tail.fix_before_start()
    command = 'appliance_console_cli --extauth-opts="/authentication/{}=true"'.format(
        auth_type)
    ipa_crud.ssh_client.run_command(command)
    evm_tail.validate_logs()

    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to false.*'.format(auth_type)],
        hostname=ipa_crud.address,
        username=app_creds['sshlogin'],
        password=app_creds['password'])

    evm_tail.fix_before_start()
    command2 = 'appliance_console_cli --extauth-opts="/authentication/{}=false"'.format(
        auth_type)
    ipa_crud.ssh_client.run_command(command2)
    evm_tail.validate_logs()
Ejemplo n.º 3
0
def test_appliance_console_external_auth(auth_type, app_creds, ipa_crud, configured_appliance):
    """'ap' launches appliance_console, '' clears info screen, '11' change ext auth options,
    'auth_type' auth type to change, '4' apply changes."""
    # TODO this depends on the auth_type options being disabled when the test is run
    # TODO it assumes that first switch is to true, then false.

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to true.*'.format(auth_type.option)],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['sshpass'])
    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', auth_type.index, '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to false.*'.format(auth_type.option)],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['sshpass'])

    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', auth_type.index, '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
Ejemplo n.º 4
0
def test_appliance_console_cli_external_auth(auth_type, ipa_crud, app_creds, configured_appliance):
    """
    Polarion:
        assignee: sbulage
        caseimportance: high
        initialEstimate: 1/4h
    """
    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to true.*'.format(auth_type)],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['sshpass'])
    evm_tail.fix_before_start()
    cmd_set = 'appliance_console_cli --extauth-opts="/authentication/{}=true"'.format(auth_type)
    assert configured_appliance.ssh_client.run_command(cmd_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to false.*'.format(auth_type)],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['sshpass'])

    evm_tail.fix_before_start()
    cmd_unset = 'appliance_console_cli --extauth-opts="/authentication/{}=false"'.format(auth_type)
    assert configured_appliance.ssh_client.run_command(cmd_unset)
    evm_tail.validate_logs()
Ejemplo n.º 5
0
def test_black_console_external_auth(auth_type, app_creds, ipa_crud):
    """'ap' launches appliance_console, '' clears info screen, '12/15' change ext auth options,
    'auth_type' auth type to change, '4' apply changes."""

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to true.*'.format(auth_type.option)],
                            hostname=ipa_crud.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])
    evm_tail.fix_before_start()
    opt = '12' if ipa_crud.version >= "5.8" else '15'
    command_set = ('ap', '', opt, auth_type.index, '4')
    ipa_crud.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to false.*'.format(auth_type.option)],
                            hostname=ipa_crud.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])

    evm_tail.fix_before_start()
    opt = '12' if ipa_crud.version >= "5.8" else '15'
    command_set = ('ap', '', opt, auth_type.index, '4')
    ipa_crud.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
Ejemplo n.º 6
0
def test_appliance_console_external_auth(auth_type, app_creds, ipa_crud):
    """'ap' launches appliance_console, '' clears info screen, '12' change ext auth options,
    'auth_type' auth type to change, '4' apply changes."""

    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to true.*'.format(auth_type.option)],
        hostname=ipa_crud.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])
    evm_tail.fix_before_start()
    command_set = ('ap', '', '12', auth_type.index, '4')
    ipa_crud.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to false.*'.format(auth_type.option)],
        hostname=ipa_crud.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])

    evm_tail.fix_before_start()
    command_set = ('ap', '', '12', auth_type.index, '4')
    ipa_crud.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
def test_appliance_console_cli_external_auth(auth_type, ipa_crud, app_creds,
                                             configured_appliance):
    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to true.*'.format(auth_type)],
        hostname=configured_appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['sshpass'])
    evm_tail.fix_before_start()
    cmd_set = 'appliance_console_cli --extauth-opts="/authentication/{}=true"'.format(
        auth_type)
    assert configured_appliance.ssh_client.run_command(cmd_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to false.*'.format(auth_type)],
        hostname=configured_appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['sshpass'])

    evm_tail.fix_before_start()
    cmd_unset = 'appliance_console_cli --extauth-opts="/authentication/{}=false"'.format(
        auth_type)
    assert configured_appliance.ssh_client.run_command(cmd_unset)
    evm_tail.validate_logs()
def test_appliance_console_external_auth(auth_type, app_creds, ipa_crud, configured_appliance):
    """ Commands:
    1. 'ap' launches appliance_console,
    2. '' clears info screen,
    3. '11' change ext auth options,
    4. 'auth_type' auth type to change,
    5. '4' apply changes."""
    # TODO this depends on the auth_type options being disabled when the test is run
    # TODO it assumes that first switch is to true, then false.

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to true.*'.format(auth_type.option)],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['sshpass'])
    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', auth_type.index, '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to false.*'.format(auth_type.option)],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['sshpass'])

    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', auth_type.index, '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
Ejemplo n.º 9
0
def test_appliance_console_external_auth_all(app_creds, ipa_crud, configured_appliance):
    """'ap' launches appliance_console, '' clears info screen, '12/15' change ext auth options,
    'auth_type' auth type to change, '4' apply changes."""

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*sso_enabled to true.*',
                                              '.*saml_enabled to true.*',
                                              '.*local_login_disabled to true.*'],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])
    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', '1', '2', '3', '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*sso_enabled to false.*',
                                              '.*saml_enabled to false.*',
                                              '.*local_login_disabled to false.*'],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])

    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', '1', '2', '3', '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
def test_appliance_console_external_auth_all(app_creds, ipa_crud, configured_appliance):
    """ Commands:
    1. 'ap' launches appliance_console,
    2. '' clears info screen,
    3. '12/15' change ext auth options,
    4. 'auth_type' auth type to change,
    5. '4' apply changes."""

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*sso_enabled to true.*',
                                              '.*saml_enabled to true.*',
                                              '.*local_login_disabled to true.*'],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])
    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', '1', '2', '3', '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*sso_enabled to false.*',
                                              '.*saml_enabled to false.*',
                                              '.*local_login_disabled to false.*'],
                            hostname=configured_appliance.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])

    evm_tail.fix_before_start()
    command_set = ('ap', '', '11', '1', '2', '3', '4')
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
Ejemplo n.º 11
0
def test_appliance_console_external_auth(auth_type, ipa_crud, configured_appliance):
    """ Commands:
    1. 'ap' launches appliance_console,
    2. RETURN clears info screen,
    3. '13' change ext auth options,
    4. 'auth_type' auth type to change,
    5. '4' apply changes.

    Polarion:
        assignee: mnadeem
        caseimportance: high
        casecomponent: Auth
        initialEstimate: 1/4h
    """
    # TODO this depends on the auth_type options being disabled when the test is run
    # TODO it assumes that first switch is to true, then false.

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to true.*'.format(auth_type.option)],
                            hostname=configured_appliance.hostname)
    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, '13', auth_type.index, '5', RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set, timeout=30)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to false.*'.format(auth_type.option)],
                            hostname=configured_appliance.hostname)

    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, '13', auth_type.index, '5', RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set, timeout=30)
    evm_tail.validate_logs()
Ejemplo n.º 12
0
def test_action_power_on_audit(request, vm, vm_off, appliance, policy_for_testing):
    """ This test tests action 'Generate Audit Event'.

    This test sets the policy that it logs powering on of the VM. Then it powers up the vm and
    checks whether audit logs contain message about that.

    Metadata:
        test_flag: actions, provision

    Polarion:
        assignee: jdupuy
        initialEstimate: 1/6h
        casecomponent: Control
    """
    policy_result = LogValidator(
        "/var/www/miq/vmdb/log/audit.log",
        matched_patterns=[
            r'.*policy: \[{}\], event: \[VM Power On\]'.format(
                policy_for_testing.description
            )
        ]
    )
    policy_result.fix_before_start()
    # Set up the policy and prepare finalizer
    policy_for_testing.assign_actions_to_event("VM Power On", ["Generate Audit Event"])

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

    # Start the VM
    vm.mgmt.ensure_state(VmState.RUNNING)

    # Search the logs and wait for validation
    policy_result.wait_for_log_validation()
Ejemplo n.º 13
0
def test_appliance_console_cli_external_auth(auth_type, ipa_crud,
                                             configured_appliance):
    """
    Polarion:
        assignee: sbulage
        caseimportance: high
        initialEstimate: 1/4h
    """
    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to true.*'.format(auth_type)],
        hostname=configured_appliance.hostname)
    evm_tail.fix_before_start()
    cmd_set = 'appliance_console_cli --extauth-opts="/authentication/{}=true"'.format(
        auth_type)
    assert configured_appliance.ssh_client.run_command(cmd_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to false.*'.format(auth_type)],
        hostname=configured_appliance.hostname)

    evm_tail.fix_before_start()
    cmd_unset = 'appliance_console_cli --extauth-opts="/authentication/{}=false"'.format(
        auth_type)
    assert configured_appliance.ssh_client.run_command(cmd_unset)
    evm_tail.validate_logs()
Ejemplo n.º 14
0
def test_black_console_external_auth_all(app_creds, ipa_crud):
    """'ap' launches appliance_console, '' clears info screen, '12/15' change ext auth options,
    'auth_type' auth type to change, '4' apply changes."""

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=[
                                '.*sso_enabled to true.*',
                                '.*saml_enabled to true.*',
                                '.*local_login_disabled to true.*'
                            ],
                            hostname=ipa_crud.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])
    evm_tail.fix_before_start()
    opt = '12' if ipa_crud.version >= "5.8" else '15'
    command_set = ('ap', '', opt, '1', '2', '3', '4')
    ipa_crud.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=[
                                '.*sso_enabled to false.*',
                                '.*saml_enabled to false.*',
                                '.*local_login_disabled to false.*'
                            ],
                            hostname=ipa_crud.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])

    evm_tail.fix_before_start()
    opt = '12' if ipa_crud.version >= "5.8" else '15'
    command_set = ('ap', '', opt, '1', '2', '3', '4')
    ipa_crud.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
Ejemplo n.º 15
0
def test_action_prevent_host_ssa(request, appliance, host, host_policy):
    """Tests preventing Smart State Analysis on a host.

    This test sets the policy that prevents host analysis.

    Bugzilla:
        1437910

    Metadata:
        test_flag: actions, provision

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

    @request.addfinalizer
    def _cleanup():
        host_policy.unassign_events("Host Analysis Request")

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

    view = navigate_to(host, "Details")

    def _scan():
        return view.entities.summary("Relationships").get_text_of("Drift History")

    original = _scan()
    view.toolbar.configuration.item_select("Perform SmartState Analysis", handle_alert=True)
    view.flash.assert_success_message('"{}": Analysis successfully initiated'.format(host.name))
    try:
        wait_for(
            lambda: _scan() != original,
            num_sec=60,
            delay=5,
            fail_func=view.browser.refresh,
            message="Check if Drift History field is changed",
        )
    except TimedOutError:
        policy_result.validate_logs()
    else:
        pytest.fail("CFME did not prevent analysing the Host {}".format(host.name))
Ejemplo n.º 16
0
def test_configuration_database_garbage_collection(appliance):
    """
        Navigate to Settings -> Configuration -> Diagnostics -> CFME Region -> Database
        Submit Run database Garbage Collection Now a check UI/logs for errors.
    """
    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=[
                                '.*Queued the action: \[Database GC\] being run for user:.*'],
                            failure_patterns=['.*ERROR.*'])
    evm_tail.fix_before_start()
    view = navigate_to(appliance.server.zone.region, 'Database')
    view.submit_db_garbage_collection_button.click()
    view.flash.assert_message('Database Garbage Collection successfully initiated')
    evm_tail.validate_logs()
Ejemplo n.º 17
0
def test_configuration_database_garbage_collection(appliance):
    """
        Navigate to Settings -> Configuration -> Diagnostics -> CFME Region -> Database
        Submit Run database Garbage Collection Now a check UI/logs for errors.
    """
    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=[
                                '.*Queued the action: \[Database GC\] being run for user:.*'],
                            failure_patterns=['.*ERROR.*'])
    evm_tail.fix_before_start()
    view = navigate_to(appliance.server.zone.region, 'Database')
    view.submit_db_garbage_collection_button.click()
    view.flash.assert_message('Database Garbage Collection successfully initiated')
    evm_tail.validate_logs()
Ejemplo n.º 18
0
def test_external_auth(auth_type, ipa_crud, app_creds):
    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to true.*'.format(auth_type)],
                            hostname=ipa_crud.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])
    evm_tail.fix_before_start()
    command = 'appliance_console_cli --extauth-opts="/authentication/{}=true"'.format(auth_type)
    ipa_crud.ssh_client.run_command(command)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*{} to false.*'.format(auth_type)],
                            hostname=ipa_crud.hostname,
                            username=app_creds['sshlogin'],
                            password=app_creds['password'])

    evm_tail.fix_before_start()
    command2 = 'appliance_console_cli --extauth-opts="/authentication/{}=false"'.format(auth_type)
    ipa_crud.ssh_client.run_command(command2)
    evm_tail.validate_logs()
def test_appliance_console_external_auth_all(configured_appliance):
    """ Commands:
    1. 'ap' launches appliance_console,
    2. RETURN clears info screen,
    3. '13' change ext auth options,
    4. 'auth_type' auth type to change,
    5. '5' apply changes.

    Polarion:
        assignee: sbulage
        caseimportance: high
        initialEstimate: 1/4h
    """

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=[
                                '.*sso_enabled to true.*',
                                '.*saml_enabled to true.*',
                                '.*local_login_disabled to true.*'
                            ],
                            hostname=configured_appliance.hostname)
    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, TimedCommand('13', 20), '1', '2',
                   TimedCommand('5', 20), RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=[
                                '.*sso_enabled to false.*',
                                '.*saml_enabled to false.*',
                                '.*local_login_disabled to false.*'
                            ],
                            hostname=configured_appliance.hostname)

    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, TimedCommand('13', 20), '1', '2',
                   TimedCommand('5', 20), RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
Ejemplo n.º 20
0
def test_action_prevent_ssa(request, appliance, 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.fix_before_start()

    wait_for_ssa_enabled(vm)

    try:
        do_scan(vm)
    except TimedOutError:
        policy_result.validate_logs()
    else:
        pytest.fail("CFME did not prevent analysing the VM {}".format(vm.name))
def test_appliance_console_external_auth(auth_type, ipa_crud,
                                         configured_appliance):
    """ Commands:
    1. 'ap' launches appliance_console,
    2. RETURN clears info screen,
    3. '13' change ext auth options,
    4. 'auth_type' auth type to change,
    5. '4' apply changes.

    Polarion:
        assignee: sbulage
        caseimportance: high
        initialEstimate: 1/4h
    """
    # TODO this depends on the auth_type options being disabled when the test is run
    # TODO it assumes that first switch is to true, then false.

    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to true.*'.format(auth_type.option)],
        hostname=configured_appliance.hostname)
    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, '13', auth_type.index, '5', RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set,
                                                        timeout=30)
    evm_tail.validate_logs()

    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*{} to false.*'.format(auth_type.option)],
        hostname=configured_appliance.hostname)

    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, '13', auth_type.index, '5', RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set,
                                                        timeout=30)
    evm_tail.validate_logs()
Ejemplo n.º 22
0
def test_task_id_for_method_automation_log(request, generic_catalog_item):
    """
    Polarion:
        assignee: ghubale
        initialEstimate: 1/30h
        caseimportance: medium
        caseposneg: positive
        testtype: functional
        startsin: 5.10
        casecomponent: Automate
        tags: automate
        setup:
            1. Add existing or new automate method to newly created domain or create generic service
        testSteps:
            1. Run that instance using simulation or order service catalog item
            2. See automation log
        expectedResults:
            1.
            2. Task id should be included in automation log for method logs.

    Bugzilla:
        1592428
    """
    result = LogValidator(
        "/var/www/miq/vmdb/log/automation.log", matched_patterns=[".*Q-task_id.*"]
    )
    result.fix_before_start()
    service_request = generic_catalog_item.appliance.rest_api.collections.service_templates.get(
        name=generic_catalog_item.name
    ).action.order()
    request.addfinalizer(service_request.action.delete)

    # Need to wait until automation logs with 'Q-task_id' are generated, which happens after the
    # service_request becomes active.
    wait_for(lambda: service_request.request_state == "active", fail_func=service_request.reload,
             timeout=60, delay=3)
    result.validate_logs()
Ejemplo n.º 23
0
def test_appliance_console_external_auth_all(configured_appliance):
    """ Commands:
    1. 'ap' launches appliance_console,
    2. RETURN clears info screen,
    3. '13' change ext auth options,
    4. 'auth_type' auth type to change,
    5. '5' apply changes.

    Polarion:
        assignee: mnadeem
        caseimportance: high
        casecomponent: Auth
        initialEstimate: 1/4h
    """

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*sso_enabled to true.*',
                                              '.*saml_enabled to true.*',
                                              '.*local_login_disabled to true.*'],
                            hostname=configured_appliance.hostname)
    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, TimedCommand('13', 20), '1', '2', TimedCommand('5', 20),
                   RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()

    evm_tail = LogValidator('/var/www/miq/vmdb/log/evm.log',
                            matched_patterns=['.*sso_enabled to false.*',
                                              '.*saml_enabled to false.*',
                                              '.*local_login_disabled to false.*'],
                            hostname=configured_appliance.hostname)

    evm_tail.fix_before_start()
    command_set = ('ap', RETURN, TimedCommand('13', 20), '1', '2', TimedCommand('5', 20),
                   RETURN, RETURN)
    configured_appliance.appliance_console.run_commands(command_set)
    evm_tail.validate_logs()
Ejemplo n.º 24
0
def test_codename_in_log(appliance):
    """
    check whether logs contains a mention of appliance codename

    Polarion:
        assignee: jhenner
        casecomponent: Appliance
        initialEstimate: 1/60h
    """
    log = '/var/www/miq/vmdb/log/evm.log'
    lv = LogValidator(log,
                      matched_patterns=[r'.*Codename: \w+$'],
                      hostname=appliance.hostname)
    lv.fix_before_start()
    appliance.ssh_client.run_command('appliance_console_cli --server=restart')

    @wait_for_decorator
    def codename_in_log():
        try:
            lv.validate_logs()
        except pytest.Fail:
            return False
        else:
            return True
Ejemplo n.º 25
0
def test_pause_and_resume_single_provider_api(appliance, provider,
                                              from_collections, app_creds,
                                              soft_assert, request):
    """
    Test enabling and disabling a single provider via the CFME API through the ManageIQ API Client
    collection and entity classes.

    RFE: BZ 1507812

    Polarion:
        assignee: juwatts
        caseimportance: medium
        initialEstimate: 1/6h
    """
    evm_tail_disable = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=[
            '.*Disabling EMS \[{}\] id \[{}\].*'.format(
                provider.name, str(provider.id))
        ],
        hostname=appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])
    evm_tail_disable.fix_before_start()
    if from_collections:
        rep_disable = appliance.collections.containers_providers.pause_providers(
            provider)
        # collections class returns a list of dicts containing the API response.
        soft_assert(rep_disable[0].get('success'),
                    'Disabling provider {} failed'.format(provider.name))
    else:
        rep_disable = provider.pause()
        # entity class returns a dict containing the API response
        soft_assert(rep_disable.get('success'),
                    'Disabling provider {} failed'.format(provider.name))
    soft_assert(not provider.is_provider_enabled,
                'Provider {} is still enabled'.format(provider.name))
    evm_tail_disable.validate_logs()
    # Verify all monitoring workers have been shut down
    assert wait_for(
        lambda: not check_ems_state_in_diagnostics(appliance, provider))
    # Create a project on the OpenShift provider via wrapanapi
    project_name = fauxfactory.gen_alpha(8).lower()
    provider.mgmt.create_project(name=project_name)

    @request.addfinalizer
    def _finalize():
        provider.mgmt.delete_project(name=project_name)

    project = appliance.collections.container_projects.instantiate(
        name=project_name, provider=provider)
    # Trigger an appliance refresh
    provider.refresh_provider_relationships()
    soft_assert(
        not project.exists,
        'Project {} exists even though provider has been disabled'.format(
            project_name))
    evm_tail_enable = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=[
            '.*Enabling EMS \[{}\] id \[{}\].*'.format(provider.name,
                                                       str(provider.id))
        ],
        hostname=appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])
    evm_tail_enable.fix_before_start()
    if from_collections:
        rep_enable = appliance.collections.containers_providers.resume_providers(
            provider)
        soft_assert(rep_enable[0].get('success'),
                    'Enabling provider {} failed'.format(provider.name))
    else:
        rep_enable = provider.resume()
        soft_assert(rep_enable.get('success'),
                    'Enabling provider {} failed'.format(provider.name))
    soft_assert(provider.is_provider_enabled,
                'Provider {} is still disabled'.format(provider.name))
    evm_tail_enable.validate_logs()
    provider.refresh_provider_relationships()
    soft_assert(
        project.exists,
        'Project {} does not exists even though provider has been enabled'.
        format(project_name))
Ejemplo n.º 26
0
def test_send_email_method(smtp_test, klass):
    """
    Polarion:
        assignee: ghubale
        initialEstimate: 1/20h
        startsin: 5.10
        casecomponent: Automate

    Bugzilla:
        1688500
        1702304
    """
    mail_to = fauxfactory.gen_email()
    mail_cc = fauxfactory.gen_email()
    mail_bcc = fauxfactory.gen_email()

    # Ruby code to send emails
    script = (
        'to = "{mail_to}"\n'
        'subject = "Hello"\n'
        'body = "Hi"\n'
        'bcc = "{mail_bcc}"\n'
        'cc = "{mail_cc}"\n'
        'content_type = "message"\n'
        'from = "*****@*****.**"\n'
        "$evm.execute(:send_email, to, from, subject, body, {{:bcc => bcc, :cc => cc,"
        ":content_type => content_type}})"
    )
    script = script.format(mail_cc=mail_cc, mail_bcc=mail_bcc, mail_to=mail_to)

    # Adding schema for executing method - send_email which helps to send emails
    klass.schema.add_fields({'name': 'execute', 'type': 'Method', 'data_type': 'String'})

    # Adding method - send_email for sending mails
    method = klass.methods.create(
        name=fauxfactory.gen_alphanumeric(),
        display_name=fauxfactory.gen_alphanumeric(),
        location='inline',
        script=script)

    # Adding instance to call automate method - send_email
    instance = klass.instances.create(
        name=fauxfactory.gen_alphanumeric(),
        display_name=fauxfactory.gen_alphanumeric(),
        description=fauxfactory.gen_alphanumeric(),
        fields={'execute': {'value': method.name}}
    )

    result = LogValidator(
        "/var/www/miq/vmdb/log/evm.log",
        matched_patterns=[
            '.*:to=>"{mail_to}".*.*:cc=>"{mail_cc}".*.*:bcc=>"{mail_bcc}".*'.format(
                mail_to=mail_to, mail_cc=mail_cc, mail_bcc=mail_bcc
            )
        ],
    )
    result.fix_before_start()

    # Executing automate method - send_email using simulation
    simulate(
        appliance=klass.appliance,
        attributes_values={
            "namespace": klass.namespace.name,
            "class": klass.name,
            "instance": instance.name,
        },
        message="create",
        request="Call_Instance",
        execute_methods=True,
    )
    result.validate_logs()

    # TODO(GH-8820): This issue should be fixed to check mails sent to person in 'cc' and 'bcc'
    # Check whether the mail sent via automate method really arrives
    wait_for(lambda: len(smtp_test.get_emails(to_address=mail_to)) > 0, num_sec=60, delay=10)
Ejemplo n.º 27
0
def test_embedded_ansible_executed_with_data_upon_event(request,
                                                        ansible_repository,
                                                        copy_ae_instance_to_new_domain,
                                                        networks_provider):
    """
    Test that Nuage events trigger Embedded Ansible automation and that playbook has access to
    authentication attributes and event data.

    Specifically, we copy AE Instance 'ManageIQ/System/Event/EmsEvent/Nuage/nuage_enterprise_create'
    from default domain into our own domain and customize it's 'meth5' attribute to invoke
    Embedded Ansible playbook which prints authentication attributes and event data into evm.log.
    This test then triggers a 'nuage_enterprise_create' event and waits for appropriate line
    to appear in evm.log.

    Prerequisites:
    Following content needs to be present in cfme_data.yaml in order to fetch correct
    Ansible repository:

    ansible_links:
      playbook_repositories:
        embedded_ansible: https://github.com/xlab-si/integration-tests-nuage-automation.git
    """
    ae_instance = copy_ae_instance_to_new_domain
    ae_class = ae_instance.klass
    ae_method = ae_class.methods.create(
        name='printout',
        location='playbook',
        repository=ansible_repository.name,
        playbook='printout.yaml',
        machine_credential='CFME Default Credential',
        logging_output='Always')

    username = random_name()
    with update(ae_instance):
        ae_instance.fields = {
            'nuage_username': {'value': username},
            'nuage_enterprise': {'value': 'csp'},
            'nuage_url': {'value': 'https://nuage:8443'},
            'nuage_api_version': {'value': 'v5_0'},
            'meth5': {'value': ae_method.name}
        }

    enterprise = networks_provider.mgmt.create_enterprise()
    request.addfinalizer(lambda: networks_provider.mgmt.delete_enterprise(enterprise))
    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=[
            r'.*I confirm that username is {} and event is raised for {}.*'.format(username,
                                                                                   enterprise.id)
        ]
    )
    evm_tail.fix_before_start()

    # LogValidator.validate_logs throws `Failed` exception which inherits `BaseException`.
    # wait_for function checks for `Exception` which inherits `BaseException` when
    # 'handle_exception' parameter is used. We can't make use of this functionality because
    # `Failed` exception is not caught with `Exception` class, hence the helper function.
    def validate_logs():
        try:
            evm_tail.validate_logs()
            return True
        except Failed:
            return False

    wait_for(validate_logs, timeout=300, delay=10, fail_condition=False)
Ejemplo n.º 28
0
def test_pause_and_resume_single_provider_api(appliance, provider, from_collections, app_creds,
                                              soft_assert, request):
    """
    Test enabling and disabling a single provider via the CFME API through the ManageIQ API Client
    collection and entity classes.

    RFE: BZ 1507812

    Polarion:
        assignee: juwatts
        caseimportance: medium
        initialEstimate: 1/6h
    """
    evm_tail_disable = LogValidator('/var/www/miq/vmdb/log/evm.log',
                                    matched_patterns=['.*Disabling EMS \[{}\] id \[{}\].*'
                                                      .format(provider.name, str(provider.id))],
                                    hostname=appliance.hostname,
                                    username=app_creds['sshlogin'],
                                    password=app_creds['password'])
    evm_tail_disable.fix_before_start()
    if from_collections:
        rep_disable = appliance.collections.containers_providers.pause_providers(provider)
        # collections class returns a list of dicts containing the API response.
        soft_assert(rep_disable[0].get('success'), 'Disabling provider {} failed'
                    .format(provider.name))
    else:
        rep_disable = provider.pause()
        # entity class returns a dict containing the API response
        soft_assert(rep_disable.get('success'), 'Disabling provider {} failed'
                    .format(provider.name))
    soft_assert(not provider.is_provider_enabled, 'Provider {} is still enabled'
                .format(provider.name))
    evm_tail_disable.validate_logs()
    # Verify all monitoring workers have been shut down
    assert wait_for(lambda: not check_ems_state_in_diagnostics(appliance, provider))
    # Create a project on the OpenShift provider via wrapanapi
    project_name = fauxfactory.gen_alpha(8).lower()
    provider.mgmt.create_project(name=project_name)

    @request.addfinalizer
    def _finalize():
        provider.mgmt.delete_project(name=project_name)

    project = appliance.collections.container_projects.instantiate(name=project_name,
                                                                   provider=provider)
    # Trigger an appliance refresh
    provider.refresh_provider_relationships()
    soft_assert(not project.exists, 'Project {} exists even though provider has been disabled'
                .format(project_name))
    evm_tail_enable = LogValidator('/var/www/miq/vmdb/log/evm.log',
                                   matched_patterns=['.*Enabling EMS \[{}\] id \[{}\].*'
                                                     .format(provider.name, str(provider.id))],
                                   hostname=appliance.hostname,
                                   username=app_creds['sshlogin'],
                                   password=app_creds['password'])
    evm_tail_enable.fix_before_start()
    if from_collections:
        rep_enable = appliance.collections.containers_providers.resume_providers(provider)
        soft_assert(rep_enable[0].get('success'), 'Enabling provider {} failed'
                    .format(provider.name))
    else:
        rep_enable = provider.resume()
        soft_assert(rep_enable.get('success'), 'Enabling provider {} failed'.format(provider.name))
    soft_assert(provider.is_provider_enabled, 'Provider {} is still disabled'.format(provider.name))
    evm_tail_enable.validate_logs()
    provider.refresh_provider_relationships()
    soft_assert(project.exists, 'Project {} does not exists even though provider has been enabled'
                .format(project_name))
def test_blacklisted_container_events(request, appliance, provider, app_creds):
    """
        Test that verifies that container events can be blacklisted.

        Polarion:
            assignee: juwatts
            caseimportance: medium
            casecomponent: Containers
            initialEstimate: 1/6h
    """

    project_name = fauxfactory.gen_alpha(8).lower()

    # Create a project namespace
    provider.mgmt.create_project(name=project_name)
    provider.mgmt.wait_project_exist(name=project_name)

    request.addfinalizer(lambda: appliance_cleanup(provider=provider,
                                                   appliance=appliance,
                                                   namespace=project_name))

    evm_tail_no_blacklist = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*event\_type\=\>\"POD\_CREATED\".*'],
        hostname=appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])
    evm_tail_no_blacklist.fix_before_start()

    create_pod(provider=provider, namespace=project_name)

    rails_result_no_blacklist = get_blacklisted_event_names(appliance)

    assert "POD_CREATED" not in rails_result_no_blacklist

    evm_tail_no_blacklist.validate_logs()

    delete_pod(provider=provider, namespace=project_name)

    appliance.update_advanced_settings(
        {"ems": {"ems_openshift": {"blacklisted_event_names": ["POD_CREATED"]}}}
    )
    appliance.evmserverd.restart()
    appliance.wait_for_web_ui()

    rails_result_blacklist = get_blacklisted_event_names(appliance)

    assert "POD_CREATED" in rails_result_blacklist

    evm_tail_blacklist = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        failure_patterns=['.*event\_type\=\>\"POD\_CREATED\".*'],
        hostname=appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])

    evm_tail_blacklist.fix_before_start()

    create_pod(provider=provider, namespace=project_name)

    evm_tail_blacklist.validate_logs()

    delete_pod(provider=provider, namespace=project_name)

    restore_advanced_settings(appliance=appliance)
    rails_destroy_blacklist = appliance.ssh_client.run_rails_console(
        "BlacklistedEvent.where(:event_name => 'POD_CREATED').destroy_all")
    assert rails_destroy_blacklist.success
    rails_result_default = get_blacklisted_event_names(appliance)

    assert "POD_CREATED" not in rails_result_default

    appliance.evmserverd.restart()
    appliance.wait_for_web_ui()

    evm_tail_no_blacklist.fix_before_start()

    create_pod(provider=provider, namespace=project_name)

    # After restarting evm, there was a delay in logging for a brief period. validate_logs() was
    # being called before the log event was created and causing the test to fail. validate_logs()
    # calls pytest.fail, so using wait_for() here was not possible since there is no exception to
    # catch. Only option was to add a short sleep here.
    time.sleep(10)

    evm_tail_no_blacklist.validate_logs()
def test_blacklisted_container_events(request, appliance, provider, app_creds):
    """
        Test that verifies that container events can be blacklisted.

        Polarion:
            assignee: juwatts
            caseimportance: medium
            casecomponent: Containers
            initialEstimate: 1/6h
    """

    project_name = fauxfactory.gen_alpha(8).lower()

    # Create a project namespace
    provider.mgmt.create_project(name=project_name)
    provider.mgmt.wait_project_exist(name=project_name)

    request.addfinalizer(lambda: appliance_cleanup(
        provider=provider, appliance=appliance, namespace=project_name))

    evm_tail_no_blacklist = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=['.*event\_type\=\>\"POD\_CREATED\".*'],
        hostname=appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])
    evm_tail_no_blacklist.fix_before_start()

    create_pod(provider=provider, namespace=project_name)

    rails_result_no_blacklist = get_blacklisted_event_names(appliance)

    assert "POD_CREATED" not in rails_result_no_blacklist

    evm_tail_no_blacklist.validate_logs()

    delete_pod(provider=provider, namespace=project_name)

    appliance.update_advanced_settings({
        "ems": {
            "ems_openshift": {
                "blacklisted_event_names": ["POD_CREATED"]
            }
        }
    })
    appliance.evmserverd.restart()
    appliance.wait_for_web_ui()

    rails_result_blacklist = get_blacklisted_event_names(appliance)

    assert "POD_CREATED" in rails_result_blacklist

    evm_tail_blacklist = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        failure_patterns=['.*event\_type\=\>\"POD\_CREATED\".*'],
        hostname=appliance.hostname,
        username=app_creds['sshlogin'],
        password=app_creds['password'])

    evm_tail_blacklist.fix_before_start()

    create_pod(provider=provider, namespace=project_name)

    evm_tail_blacklist.validate_logs()

    delete_pod(provider=provider, namespace=project_name)

    restore_advanced_settings(appliance=appliance)
    rails_destroy_blacklist = appliance.ssh_client.run_rails_console(
        "BlacklistedEvent.where(:event_name => 'POD_CREATED').destroy_all")
    assert rails_destroy_blacklist.success
    rails_result_default = get_blacklisted_event_names(appliance)

    assert "POD_CREATED" not in rails_result_default

    appliance.evmserverd.restart()
    appliance.wait_for_web_ui()

    evm_tail_no_blacklist.fix_before_start()

    create_pod(provider=provider, namespace=project_name)

    # After restarting evm, there was a delay in logging for a brief period. validate_logs() was
    # being called before the log event was created and causing the test to fail. validate_logs()
    # calls pytest.fail, so using wait_for() here was not possible since there is no exception to
    # catch. Only option was to add a short sleep here.
    time.sleep(10)

    evm_tail_no_blacklist.validate_logs()