Пример #1
0
def test_ntp_server_check(request):
    request.addfinalizer(clear_ntp_settings)
    orig_date = appliance_date()
    past_date = orig_date - timedelta(days=10)
    logger.info("dates: orig_date - %s, past_date - %s", orig_date, past_date)
    status, result = store.current_appliance.ssh_client.run_command(
        "date +%Y%m%d -s \"{}\"".format(past_date.strftime('%Y%m%d')))
    new_date = appliance_date()
    if new_date != orig_date:
        logger.info("Successfully modified the date in the appliance")
        # Configuring the ntp server and restarting the appliance
        # checking if ntp property is available, adding if it is not available
        configuration.set_ntp_servers(*cfme_data['clock_servers'])
        yaml_config = store.current_appliance.get_yaml_config("vmdb")
        ntp = yaml_config.get("ntp", None)
        if not ntp:
            yaml_config["ntp"] = {}
        # adding the ntp interval to 1 minute and updating the configuration
        yaml_config["ntp"]["interval"] = '1.minutes'
        store.current_appliance.set_yaml_config("vmdb", yaml_config)
        # restarting the evmserverd for NTP to work
        store.current_appliance.restart_evm_service(rude=True)
        store.current_appliance.wait_for_web_ui(timeout=1200)
        # Incase if ntpd service is stopped
        store.current_appliance.ssh_client.run_command("service ntpd restart")
        # Providing two hour runtime for the test run to avoid day changing problem
        # (in case if the is triggerred in the midnight)
        wait_for(lambda:
                 (orig_date - appliance_date()).total_seconds() <= 7200,
                 num_sec=300)
    else:
        raise Exception("Failed modifying the system date")
    # Calling the browser quit() method to compensate the session after the evm service restart
    quit()
Пример #2
0
def test_ntp_server_check(request, appliance):
    request.addfinalizer(partial(clear_ntp_settings, appliance))
    orig_date = appliance_date(appliance)
    past_date = orig_date - timedelta(days=10)
    logger.info("dates: orig_date - %s, past_date - %s", orig_date, past_date)
    status, result = appliance.ssh_client.run_command(
        "date +%Y%m%d -s \"{}\"".format(past_date.strftime('%Y%m%d')))
    new_date = appliance_date(appliance)
    if new_date != orig_date:
        logger.info("Successfully modified the date in the appliance")
        # Configuring the ntp server and restarting the appliance
        # checking if ntp property is available, adding if it is not available
        configuration.set_ntp_servers(*cfme_data['clock_servers'])
        yaml_config = appliance.get_yaml_config()
        ntp = yaml_config.get("ntp")
        if not ntp:
            yaml_config["ntp"] = {}
        # adding the ntp interval to 1 minute and updating the configuration
        yaml_config["ntp"]["interval"] = '1.minutes'
        appliance.set_yaml_config(yaml_config)
        # restarting the evmserverd for NTP to work
        appliance.restart_evm_service(rude=True)
        appliance.wait_for_web_ui(timeout=1200)
        # Incase if ntpd service is stopped
        appliance.ssh_client.run_command("service chronyd restart")
        # Providing two hour runtime for the test run to avoid day changing problem
        # (in case if the is triggerred in the midnight)
        wait_for(
            lambda: (orig_date - appliance_date(appliance)).total_seconds() <= 7200, num_sec=300)
    else:
        raise Exception("Failed modifying the system date")
    # Calling the browser quit() method to compensate the session after the evm service restart
    quit()
Пример #3
0
def test_ntp_conf_file_update_check(request):
    request.addfinalizer(configuration.set_ntp_servers)
    ntp_file_date_stamp = store.current_appliance.ssh_client.run_command(
        "stat --format '%y' /etc/ntp.conf")[1]
    # Adding the ntp server values
    configuration.set_ntp_servers(*cfme_data['clock_servers'])
    wait_for(lambda: ntp_file_date_stamp != store.current_appliance.ssh_client.
             run_command("stat --format '%y' /etc/ntp.conf")[1],
             num_sec=60,
             delay=10)
    for clock in cfme_data['clock_servers']:
        status, wait_time = wait_for(lambda: check_ntp_grep(clock),
                                     fail_condition=False,
                                     num_sec=60,
                                     delay=5)
        assert status[
            0] is True, "Clock value {} not update in /etc/ntp.conf file".format(
                clock)

    # Unsetting the ntp server values
    ntp_file_date_stamp = store.current_appliance.ssh_client.run_command(
        "stat --format '%y' /etc/ntp.conf")[1]
    configuration.set_ntp_servers()
    wait_for(lambda: ntp_file_date_stamp != store.current_appliance.ssh_client.
             run_command("stat --format '%y' /etc/ntp.conf")[1],
             num_sec=60,
             delay=10)
    for clock in cfme_data['clock_servers']:
        status, wait_time = wait_for(lambda: check_ntp_grep(clock),
                                     fail_condition=True,
                                     num_sec=60,
                                     delay=5)
        assert status[
            0] is False, "Found clock record '{}' in /etc/ntp.conf file".format(
                clock)
Пример #4
0
def setup_external_auth_ipa(**data):
    """Sets up the appliance for an external authentication with IPA.

    Keywords:
        get_groups: Get User Groups from External Authentication (httpd).
        ipaserver: IPA server address.
        iparealm: Realm.
        credentials: Key of the credential in credentials.yaml
    """
    ssh = SSHClient()
    ensure_browser_open()
    login_admin()
    if data["ipaserver"] not in get_ntp_servers():
        set_ntp_servers(data["ipaserver"])
        sleep(120)
    auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False))
    auth.setup()
    logout()
    creds = credentials.get(data.pop("credentials"), {})
    data.update(**creds)
    rc, out = ssh.run_command(
        "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} "
        "--ipaprincipal {principal} --ipapassword {password}".format(**data))
    assert rc == 0, out
    assert "failed" not in out.lower(
    ), "External auth setup failed:\n{}".format(out)
    login_admin()
Пример #5
0
def test_ntp_conf_file_update_check(request):
    request.addfinalizer(configuration.set_ntp_servers)
    ntp_file_date_stamp = store.current_appliance.ssh_client.run_command("stat --format '%y' /etc/ntp.conf")[1]
    # Adding the ntp server values
    configuration.set_ntp_servers(*cfme_data["clock_servers"])
    wait_for(
        lambda: ntp_file_date_stamp
        != store.current_appliance.ssh_client.run_command("stat --format '%y' /etc/ntp.conf")[1],
        num_sec=60,
        delay=10,
    )
    for clock in cfme_data["clock_servers"]:
        status, wait_time = wait_for(lambda: check_ntp_grep(clock), fail_condition=False, num_sec=60, delay=5)
        assert status[0] is True, "Clock value {} not update in /etc/ntp.conf file".format(clock)

    # Unsetting the ntp server values
    ntp_file_date_stamp = store.current_appliance.ssh_client.run_command("stat --format '%y' /etc/ntp.conf")[1]
    configuration.set_ntp_servers()
    wait_for(
        lambda: ntp_file_date_stamp
        != store.current_appliance.ssh_client.run_command("stat --format '%y' /etc/ntp.conf")[1],
        num_sec=60,
        delay=10,
    )
    for clock in cfme_data["clock_servers"]:
        status, wait_time = wait_for(lambda: check_ntp_grep(clock), fail_condition=True, num_sec=60, delay=5)
        assert status[0] is False, "Found clock record '{}' in /etc/ntp.conf file".format(clock)
Пример #6
0
def test_ntp_server_max_character(request, appliance):
    request.addfinalizer(partial(clear_ntp_settings, appliance))
    ntp_file_date_stamp = appliance.ssh_client.run_command(
        "stat --format '%y' /etc/chrony.conf")[1]
    configuration.set_ntp_servers(*(fauxfactory.gen_alphanumeric(255) for _ in range(3)))
    wait_for(lambda: ntp_file_date_stamp != appliance.ssh_client.run_command(
        "stat --format '%y' /etc/chrony.conf")[1], num_sec=60, delay=10)
Пример #7
0
def setup_external_auth_ipa(**data):
    """Sets up the appliance for an external authentication with IPA.

    Keywords:
        get_groups: Get User Groups from External Authentication (httpd).
        ipaserver: IPA server address.
        iparealm: Realm.
        credentials: Key of the credential in credentials.yaml
    """
    ssh = SSHClient()
    ensure_browser_open()
    login_admin()
    if data["ipaserver"] not in get_ntp_servers():
        set_ntp_servers(data["ipaserver"])
        sleep(120)
    auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False))
    auth.setup()
    logout()
    creds = credentials.get(data.pop("credentials"), {})
    data.update(**creds)
    rc, out = ssh.run_command(
        "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} "
        "--ipaprincipal {principal} --ipapassword {password}".format(**data)
    )
    assert rc == 0, out
    assert "failed" not in out.lower(), "External auth setup failed:\n{}".format(out)
    login_admin()
Пример #8
0
def clear_ntp_settings():
    ntp_file_date_stamp = store.current_appliance.ssh_client.run_command(
        "stat --format '%y' /etc/ntp.conf")[1]
    configuration.set_ntp_servers()
    wait_for(lambda: ntp_file_date_stamp != store.current_appliance.ssh_client.
             run_command("stat --format '%y' /etc/ntp.conf")[1],
             num_sec=60,
             delay=10)
Пример #9
0
def clear_ntp_settings():
    ntp_file_date_stamp = store.current_appliance.ssh_client.run_command("stat --format '%y' /etc/ntp.conf")[1]
    configuration.set_ntp_servers()
    wait_for(
        lambda: ntp_file_date_stamp
        != store.current_appliance.ssh_client.run_command("stat --format '%y' /etc/ntp.conf")[1],
        num_sec=60,
        delay=10,
    )
Пример #10
0
def test_ntp_server_max_character(request):
    request.addfinalizer(clear_ntp_settings)
    ntp_file_date_stamp = store.current_appliance.ssh_client.run_command(
        "stat --format '%y' /etc/ntp.conf")[1]
    configuration.set_ntp_servers(*(fauxfactory.gen_alphanumeric(255)
                                    for _ in range(3)))
    wait_for(lambda: ntp_file_date_stamp != store.current_appliance.ssh_client.
             run_command("stat --format '%y' /etc/ntp.conf")[1],
             num_sec=60,
             delay=10)
Пример #11
0
def setup_external_auth_ipa(**data):
    """Sets up the appliance for an external authentication with IPA.

    Keywords:
        get_groups: Get User Groups from External Authentication (httpd).
        ipaserver: IPA server address.
        iparealm: Realm.
        credentials: Key of the credential in credentials.yaml
    """
    connect_kwargs = {
        'username': credentials['host_default']['username'],
        'password': credentials['host_default']['password'],
        'hostname': data['ipaserver'],
    }
    current_appliance = get_or_create_current_appliance()
    appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower())
    appliance_address = current_appliance.address
    appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower())
    with SSHClient(**connect_kwargs) as ipaserver_ssh:
        ipaserver_ssh.run_command('cp /etc/hosts /etc/hosts_bak')
        ipaserver_ssh.run_command(
            "sed -i -r '/^{}/d' /etc/hosts".format(appliance_address))
        command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address,
                                                       appliance_fqdn)
        ipaserver_ssh.run_command(command)
    with current_appliance.ssh_client as ssh:
        result = ssh.run_command(
            'appliance_console_cli --host {}'.format(appliance_fqdn)).success
        if not current_appliance.is_pod:
            assert result
        else:
            # appliance_console_cli fails when calls hostnamectl --host. it seems docker issue
            # raise BZ ?
            assert str(ssh.run_command('hostname')).rstrip() == appliance_fqdn

        ensure_browser_open()
        appliance.current_appliance.server.login_admin()
        if data["ipaserver"] not in get_ntp_servers():
            set_ntp_servers(data["ipaserver"])
            sleep(120)
        auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False))
        auth.setup()
        creds = credentials.get(data.pop("credentials"), {})
        data.update(**creds)
        assert ssh.run_command(
            "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} "
            "--ipaprincipal {principal} --ipapassword {password}".format(
                **data))
    appliance.current_appliance.server.login_admin()
Пример #12
0
def setup_external_auth_ipa(**data):
    """Sets up the appliance for an external authentication with IPA.

    Keywords:
        get_groups: Get User Groups from External Authentication (httpd).
        ipaserver: IPA server address.
        iparealm: Realm.
        credentials: Key of the credential in credentials.yaml
    """
    connect_kwargs = {
        'username': credentials['host_default']['username'],
        'password': credentials['host_default']['password'],
        'hostname': data['ipaserver'],
    }
    current_appliance = get_or_create_current_appliance()
    appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower())
    appliance_address = current_appliance.address
    appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower())
    with SSHClient(**connect_kwargs) as ipaserver_ssh:
        ipaserver_ssh.run_command('cp /etc/hosts /etc/hosts_bak')
        ipaserver_ssh.run_command("sed -i -r '/^{}/d' /etc/hosts".format(appliance_address))
        command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn)
        ipaserver_ssh.run_command(command)
    with current_appliance.ssh_client as ssh:
        result = ssh.run_command('appliance_console_cli --host {}'.format(appliance_fqdn)).success
        if not current_appliance.is_pod:
            assert result
        else:
            # appliance_console_cli fails when calls hostnamectl --host. it seems docker issue
            # raise BZ ?
            assert str(ssh.run_command('hostname')).rstrip() == appliance_fqdn

        ensure_browser_open()
        appliance.current_appliance.server.login_admin()
        if data["ipaserver"] not in get_ntp_servers():
            set_ntp_servers(data["ipaserver"])
            sleep(120)
        auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False))
        auth.setup()
        creds = credentials.get(data.pop("credentials"), {})
        data.update(**creds)
        assert ssh.run_command(
            "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} "
            "--ipaprincipal {principal} --ipapassword {password}".format(**data)
        )
    appliance.current_appliance.server.login_admin()
Пример #13
0
def setup_external_auth_ipa(**data):
    """Sets up the appliance for an external authentication with IPA.

    Keywords:
        get_groups: Get User Groups from External Authentication (httpd).
        ipaserver: IPA server address.
        iparealm: Realm.
        credentials: Key of the credential in credentials.yaml
    """
    connect_kwargs = {
        'username': credentials['host_default']['username'],
        'password': credentials['host_default']['password'],
        'hostname': data['ipaserver'],
    }
    import fauxfactory
    appliance_name = 'cfmeappliance'.format(fauxfactory.gen_alpha(7).lower())
    appliance_address = appliance.IPAppliance().address
    appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower())
    ipaserver_ssh = SSHClient(**connect_kwargs)
    # updating the /etc/hosts is a workaround due to the
    # https://bugzilla.redhat.com/show_bug.cgi?id=1360928
    command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn)
    ipaserver_ssh.run_command(command)
    ipaserver_ssh.close()
    ssh = SSHClient()
    rc, out = ssh.run_command('appliance_console_cli --host {}'.format(appliance_fqdn))
    assert rc == 0, out
    ssh.run_command('echo "127.0.0.1\t{}" > /etc/hosts'.format(appliance_fqdn))
    ensure_browser_open()
    login_admin()
    if data["ipaserver"] not in get_ntp_servers():
        set_ntp_servers(data["ipaserver"])
        sleep(120)
    auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False))
    auth.setup()
    logout()
    creds = credentials.get(data.pop("credentials"), {})
    data.update(**creds)
    rc, out = ssh.run_command(
        "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} "
        "--ipaprincipal {principal} --ipapassword {password}".format(**data)
    )
    assert rc == 0, out
    assert "failed" not in out.lower(), "External auth setup failed:\n{}".format(out)
    login_admin()
Пример #14
0
def setup_external_auth_ipa(**data):
    """Sets up the appliance for an external authentication with IPA.

    Keywords:
        get_groups: Get User Groups from External Authentication (httpd).
        ipaserver: IPA server address.
        iparealm: Realm.
        credentials: Key of the credential in credentials.yaml
    """
    connect_kwargs = {
        'username': credentials['host_default']['username'],
        'password': credentials['host_default']['password'],
        'hostname': data['ipaserver'],
    }
    appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower())
    appliance_address = appliance.IPAppliance().address
    appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower())
    ipaserver_ssh = SSHClient(**connect_kwargs)
    ipaserver_ssh.run_command('cp /etc/hosts /etc/hosts_bak')
    ipaserver_ssh.run_command(
        "sed -i -r '/^{}/d' /etc/hosts".format(appliance_address))
    command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address,
                                                   appliance_fqdn)
    ipaserver_ssh.run_command(command)
    ipaserver_ssh.close()
    ssh = SSHClient()
    assert ssh.run_command(
        'appliance_console_cli --host {}'.format(appliance_fqdn))
    ensure_browser_open()
    login_admin()
    if data["ipaserver"] not in get_ntp_servers():
        set_ntp_servers(data["ipaserver"])
        sleep(120)
    auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False))
    auth.setup()
    creds = credentials.get(data.pop("credentials"), {})
    data.update(**creds)
    assert ssh.run_command(
        "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} "
        "--ipaprincipal {principal} --ipapassword {password}".format(**data))
    login_admin()
Пример #15
0
def setup_external_auth_ipa(**data):
    """Sets up the appliance for an external authentication with IPA.

    Keywords:
        get_groups: Get User Groups from External Authentication (httpd).
        ipaserver: IPA server address.
        iparealm: Realm.
        credentials: Key of the credential in credentials.yaml
    """
    connect_kwargs = {
        'username': credentials['host_default']['username'],
        'password': credentials['host_default']['password'],
        'hostname': data['ipaserver'],
    }
    appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower())
    appliance_address = appliance.IPAppliance().address
    appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower())
    ipaserver_ssh = SSHClient(**connect_kwargs)
    ipaserver_ssh.run_command('cp /etc/hosts /etc/hosts_bak')
    ipaserver_ssh.run_command("sed -i -r '/^{}/d' /etc/hosts".format(appliance_address))
    command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn)
    ipaserver_ssh.run_command(command)
    ipaserver_ssh.close()
    ssh = SSHClient()
    assert ssh.run_command('appliance_console_cli --host {}'.format(appliance_fqdn))
    ensure_browser_open()
    login_admin()
    if data["ipaserver"] not in get_ntp_servers():
        set_ntp_servers(data["ipaserver"])
        sleep(120)
    auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False))
    auth.setup()
    creds = credentials.get(data.pop("credentials"), {})
    data.update(**creds)
    assert ssh.run_command(
        "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} "
        "--ipaprincipal {principal} --ipapassword {password}".format(**data)
    )
    login_admin()
Пример #16
0
def test_ntp_crud(request):
    # Adding finalizer
    request.addfinalizer(configuration.set_ntp_servers)
    """ Insert, Update and Delete the NTP servers """
    # set from yaml file
    configuration.set_ntp_servers(*cfme_data['clock_servers'])
    # Set from random values
    configuration.set_ntp_servers(*(fauxfactory.gen_alphanumeric() for _ in range(3)))
    # Deleting the ntp values
    configuration.set_ntp_servers()
Пример #17
0
def test_ntp_crud(request):
    # Adding finalizer
    request.addfinalizer(configuration.set_ntp_servers)
    """ Insert, Update and Delete the NTP servers """
    # set from yaml file
    configuration.set_ntp_servers(*cfme_data['clock_servers'])
    # Set from random values
    configuration.set_ntp_servers(*(fauxfactory.gen_alphanumeric()
                                    for _ in range(3)))
    # Deleting the ntp values
    configuration.set_ntp_servers()