コード例 #1
0
def check_install(host):
    con_ssh = ControllerClient.get_active_controller()
    code, out = con_ssh.exec_sudo_cmd('sw-patch query-hosts')
    out = out.split('\n')
    search_for = [host, 'Yes']
    found = search_query_table(out, search_for)
    return len(search_for) == len(found)
コード例 #2
0
def setup_host_install(request, get_patch_name):
    con_ssh = ControllerClient.get_active_controller()
    hosts = host_helper.get_up_hypervisors()
    host = hosts[len(hosts) - 1]
    if host == system_helper.get_active_controller_name():
        host = hosts[len(hosts) - 2]
    host_helper.lock_host(host)

    patch_name = get_patch_name
    LOG.fixture_step("Applying {} to patching controller".format(patch_name))
    con_ssh.exec_sudo_cmd('sw-patch upload test_patches/{}.patch'.format(
        patch_name))
    con_ssh.exec_sudo_cmd('sw-patch apply {}'.format(patch_name))

    def delete_patch():
        LOG.fixture_step("Removing {} from patching controller".format(
            patch_name))
        con_ssh.exec_sudo_cmd('sw-patch remove {}'.format(patch_name))
        con_ssh.exec_sudo_cmd('sw-patch delete {}'.format(patch_name))
        LOG.fixture_step("Reinstalling {} to revert the patch".format(patch_name))
        con_ssh.exec_sudo_cmd('sw-patch host-install {}'.format(host),
                              expect_timeout=timeout.CLI_TIMEOUT)
        host_helper.unlock_host(host)

    request.addfinalizer(delete_patch)
    return patch_name, host
コード例 #3
0
def check_logs(search_for, lines=10, api=False):
    """
    Searches through /var/log/patching.log or /var/log/patching-api.log for the strings given in search_for
    Args:
        lines (int): the number of lines to look through
        api (bool): Whether to search in patching.log or patching-api.log
        search_for (list): list of regular expressions to look for in the logs

    Returns (bool):
        True  - if all the logs were found
        False - otherwise

    """
    cmd = 'tail --lines={} '.format(lines)
    if api:
        cmd += '/var/log/patching-api.log'
    else:
        cmd += '/var/log/patching.log'

    con_ssh = ControllerClient.get_active_controller()
    code, out = con_ssh.exec_cmd(cmd)
    out = out.split('\n')
    found = []

    for i in range(0, len(search_for)):
        LOG.tc_step("Searching for logs containing: {}".format(search_for[i]))
        regex = re.compile(search_for[i])
        for line in out:
            if search_for[i] not in found and re.search(regex, line):
                found.append(search_for[i])
                LOG.info('Found: {}'.format(line))
                break

    return len(search_for) == len(found)
コード例 #4
0
def test_patch_log_what_requires(get_patch_name):
    """
    Checks that the what_requires query is logged

    Test Steps:
        - Upload a patch and execute 'sw-patch what-requires'
        - Check log files for the expected logs

    """
    patch_name = get_patch_name
    con_ssh = ControllerClient.get_active_controller()
    LOG.tc_step("Uploading patch {}".format(patch_name))
    con_ssh.exec_sudo_cmd('sw-patch upload test_patches/{}.patch'.format(patch_name))
    con_ssh.exec_sudo_cmd('sw-patch what-requires {}'.format(patch_name))

    user = HostLinuxUser.get_user()
    search_for = ['sw-patch-controller-daemon.*INFO: Querying what requires patches:.*{}'.format(patch_name)]
    res_1 = check_logs(search_for, lines=10, api=False)

    search_for = ['sw-patch-controller-daemon.*INFO: User: {}/admin Action: '
                  'Querying what requires patches:.*{}'.format(user,
                                                               patch_name)]
    res_2 = check_logs(search_for, lines=10, api=True)

    LOG.tc_step("Deleting patch {}".format(patch_name))
    con_ssh.exec_sudo_cmd('sw-patch delete {}'.format(patch_name))

    assert res_1, "FAIL: uploading patches did not generate the expected " \
                  "logs in patching.log"
    assert res_2, "FAIL: uploading patches did not generate the expected logs " \
                  "in patching-api.log"
コード例 #5
0
def set_ldap_user_password(user_name, new_password, check_if_existing=True,
                           fail_ok=False):
    """
    Set ldap user password use ldapsetpasswd

    Args:
        user_name (str):
            -   name of the LDAP User

        new_password (str):
            -   new password to change to

        check_if_existing (bool):
            -   True:   check if the user already existing first
                False:  change the password without checking the existence of
                    the user

        fail_ok (bool)

    Returns (bool):
            True if successful, False otherwise
    """

    if check_if_existing:
        found, user_info = LdapUserManager().find_ldap_user(user_name=user_name)
        if not found:
            return False

    ssh_client = ControllerClient.get_active_controller()
    rc, output = ssh_client.exec_sudo_cmd(
        'ldapsetpasswd {} {}'.format(user_name, new_password), fail_ok=fail_ok)
    if rc > 1:
        return 1, output

    return rc, output
コード例 #6
0
ファイル: container_helper.py プロジェクト: pvaduva/auto_test
def exec_helm_upload_cmd(tarball,
                         repo=None,
                         timeout=120,
                         con_ssh=None,
                         fail_ok=False):
    if not con_ssh:
        con_ssh = ControllerClient.get_active_controller()

    if not repo:
        repo = 'starlingx'
    cmd = 'helm-upload {} {}'.format(repo, tarball)
    con_ssh.send(cmd)
    pw_prompt = Prompt.PASSWORD_PROMPT
    prompts = [con_ssh.prompt, pw_prompt]

    index = con_ssh.expect(prompts,
                           timeout=timeout,
                           searchwindowsize=100,
                           fail_ok=fail_ok)
    if index == 1:
        con_ssh.send(con_ssh.password)
        prompts.remove(pw_prompt)
        con_ssh.expect(prompts,
                       timeout=timeout,
                       searchwindowsize=100,
                       fail_ok=fail_ok)

    code, output = con_ssh._process_exec_result(rm_date=True,
                                                get_exit_code=True)
    if code != 0 and not fail_ok:
        raise exceptions.SSHExecCommandFailed(
            "Non-zero return code for cmd: {}. Output: {}".format(cmd, output))

    return code, output
コード例 #7
0
def test_dc_alarm_aggregation_managed(subcloud_to_test):
    """
    Test Alarm Aggregation on Distributed Cloud
    Args:
        subcloud_to_test (str): module fixture

    Setups:
        - Make sure there is consistency between alarm summary on
        Central Cloud and on subclouds

    Test Steps:
        - Raise an alarm at subcloud;
        - Ensure relative alarm raised on subcloud
        - Ensure system alarm-summary on subcloud matches dcmanager alarm summary on system
        - Clean alarm at subcloud
        - Ensure relative alarm cleared on subcloud
        - Ensure system alarm-summary on subcloud matches dcmanager alarm summary on system
    """

    ssh_client = ControllerClient.get_active_controller(name=subcloud_to_test)
    LOG.tc_step("Raise alarm on subcloud: {}".format(subcloud_to_test))
    ssh_client.exec_cmd(
        "fmClientCli -c \"### ###300.005###clear###system.vm###host=testhost-0"
        "### ###critical### ###processing-error###cpu-cycles-limit-exceeded### ###"
        "True###True###'\"",
        fail_ok=False)

    alarm_summary_add_and_del(subcloud_to_test)
コード例 #8
0
ファイル: large_heat.py プロジェクト: pvaduva/auto_test
def test_heat_stack_update():
    """
    Update heat stack that was already launched.
    It checks if the heat stack is already launched if not it will launch  the heat stack.
    It will check the status of the heat stack to be in good state (create complete/update complete)
    It will update the heat stack
    """
    file_dir = StxPath.CUSTOM_HEAT_TEMPLATES
    file_name = HeatTemplate.LARGE_HEAT
    file_path = file_dir + file_name + '/update_env.sh'

    launch_heat_stack()

    heat_status = [HeatStackStatus.CREATE_COMPLETE, HeatStackStatus.UPDATE_COMPLETE]
    current_status = heat_helper.get_stack_status(stack=HeatTemplate.LARGE_HEAT_NAME)[0]

    if current_status not in heat_status:
        skip("Heat stack Status is not in create_complete or update_complete")

    con_ssh = ControllerClient.get_active_controller()

    LOG.info("Check if file already exists on TiS")
    if con_ssh.file_exists(file_path=file_path):
        cmd1 = 'chmod 755 ' + file_path
        con_ssh.exec_cmd(cmd1)
        con_ssh.exec_cmd(file_path, fail_ok=False)

    stack_template = file_dir + file_name + '/rnc_heat.yaml'
    env_file = file_dir + file_name + '/rnc_heat.env'
    params_string = '-e {} -f {} {}'.format(env_file, stack_template, HeatTemplate.LARGE_HEAT_NAME)
    LOG.tc_step("Updating heat stack")
    heat_helper.update_stack(stack_name=HeatTemplate.LARGE_HEAT_NAME, params_string=params_string, fail_ok=False)
コード例 #9
0
def launch_lab_setup_tenants_vms():
    home_dir = HostLinuxUser.get_home()
    stack1 = "{}/lab_setup-tenant1-resources.yaml".format(home_dir)
    stack1_name = "lab_setup-tenant1-resources"
    stack2 = "{}/lab_setup-tenant2-resources.yaml".format(home_dir)
    stack2_name = "lab_setup-tenant2-resources"
    script_name = "{}/create_resource_stacks.sh".format(home_dir)

    con_ssh = ControllerClient.get_active_controller()
    if con_ssh.file_exists(file_path=script_name):
        cmd1 = 'chmod 755 ' + script_name
        con_ssh.exec_cmd(cmd1)
        con_ssh.exec_cmd(script_name, fail_ok=False)

    stack_id_t1 = heat_helper.get_stacks(name=stack1_name,
                                         auth_info=Tenant.get('tenant1'))
    # may be better to delete all tenant stacks if any
    if not stack_id_t1:
        heat_helper.create_stack(stack_name=stack1_name,
                                 template=stack1,
                                 auth_info=Tenant.get('tenant1'),
                                 timeout=1000,
                                 cleanup=None)
    stack_id_t2 = heat_helper.get_stacks(name=stack2_name,
                                         auth_info=Tenant.get('tenant2'))
    if not stack_id_t2:
        heat_helper.create_stack(stack_name=stack2_name,
                                 template=stack2,
                                 auth_info=Tenant.get('tenant2'),
                                 timeout=1000,
                                 cleanup=None)

    LOG.info("Checking all VMs are in active state")
    vms = get_all_vms()
    vm_helper.wait_for_vms_values(vms=vms, fail_ok=False)
コード例 #10
0
def test_ping_hosts():
    con_ssh = ControllerClient.get_active_controller()

    ping_failed_list = []
    for hostname in system_helper.get_hosts():
        LOG.tc_step(
            "Send 100 pings to {} from Active Controller".format(hostname))
        ploss_rate, untran_p = network_helper.ping_server(hostname, con_ssh,
                                                          num_pings=100,
                                                          timeout=300,
                                                          fail_ok=True)
        if ploss_rate > 0:
            if ploss_rate == 100:
                ping_failed_list.append(
                    "{}: Packet loss rate: {}/100\n".format(hostname,
                                                            ploss_rate))
            else:
                ping_failed_list.append(
                    "{}: All packets dropped.\n".format(hostname))
        if untran_p > 0:
            ping_failed_list.append(
                "{}: {}/100 pings are untransmitted within 300 seconds".format(
                    hostname, untran_p))

    LOG.tc_step("Ensure all packets are received.")
    assert not ping_failed_list, "Dropped/Un-transmitted packets detected " \
                                 "when ping hosts. " \
                                 "Details:\n{}".format(ping_failed_list)
コード例 #11
0
ファイル: large_heat.py プロジェクト: pvaduva/auto_test
def _get_large_heat(con_ssh=None):
    """
    copy the heat templates to TiS server.

    Args:
        con_ssh (SSHClient):

    Returns (str): TiS file path of the heat template

    """
    file_dir = StxPath.CUSTOM_HEAT_TEMPLATES
    file_name = HeatTemplate.LARGE_HEAT
    file_path = file_dir + file_name
    source_file = TestServerPath.CUSTOM_HEAT_TEMPLATES + file_name

    if con_ssh is None:
        con_ssh = ControllerClient.get_active_controller()

    LOG.info('Check if file already exists on TiS')
    if con_ssh.file_exists(file_path=file_path):
        LOG.info('dest path {} already exists. Return existing path'.format(file_path))
        return file_path

    with host_helper.ssh_to_test_server() as ssh_to_server:
        ssh_to_server.rsync(source_file, html_helper.get_ip_addr(), file_dir, dest_user=HostLinuxUser.get_user(),
                            dest_password=HostLinuxUser.get_password(), timeout=1200)
    return file_path
コード例 #12
0
    def delete_test_users():
        global _host_users

        restore_sysadmin_password(target_password=TARGET_PASSWORD)

        LOG.info('Deleting users created for testing\n')
        conn_to_ac = ControllerClient.get_active_controller()
        count = 0
        for (host, user), _ in _host_users.items():
            if user == 'sysadmin' or user == HostLinuxUser.get_user():
                LOG.info('-do not delete user:{} on host:{}\n'.format(
                    user, host))
                continue

            LOG.info('-deleting user:{} on host:{}\n'.format(user, host))

            count += 1
            if host == 'active-controller':
                conn_to_ac.exec_sudo_cmd('userdel -r {}'.format(user))
            else:
                # sleep a bit so controller-1 have same password as controller-0
                time.sleep(30)
                with host_helper.ssh_to_host(host,
                                             password='******') as conn:
                    LOG.info(
                        'TODO: delete user:{} on host:{} by CLI: userdel -r {}\n'
                        .format(user, host, user))
                    conn.exec_sudo_cmd("userdel -r '{}'".format(user))

        LOG.info('{} test user deleted'.format(count))
コード例 #13
0
    def __init__(self, ssh_con=None):
        if ssh_con is not None:
            self.ssh_con = ssh_con
        else:
            self.ssh_con = ControllerClient.get_active_controller()

        self.users_info = {}
コード例 #14
0
def test_upload_charts_via_helm_upload(copy_test_apps):
    """
    Test upload helm charts via helm-upload cmd directly. i.e., without
    using sysinv cmd.
    Args:
        copy_test_apps:

    Setups:
        - Copy test files from test server to stx system (module)

    Test Steps:
        - Upload helm charts from given controller via 'helm-upload <tar_file>'
        - Verify the charts appear at /www/pages/helm_charts/ on both
            controllers (if applicable)

    """
    app_dir = copy_test_apps

    LOG.tc_step(
        "Upload helm charts via helm-upload cmd from active controller "
        "and check charts are in /www/pages/")
    file_path = container_helper.upload_helm_charts(tar_file=os.path.join(
        app_dir, HELM_TAR),
                                                    delete_first=True)[1]

    if system_helper.get_standby_controller_name():
        LOG.tc_step("Swact active controller and verify uploaded charts "
                    "are synced over")
        host_helper.swact_host()
        con_ssh = ControllerClient.get_active_controller()
        charts_exist = con_ssh.file_exists(file_path)
        assert charts_exist, "{} does not exist after swact to {}".format(
            file_path, con_ssh.get_hostname())
        LOG.info("{} successfully synced after swact".format(file_path))
コード例 #15
0
def fetch_cert_file(cert_file=None, scp_to_local=True, con_ssh=None):
    """
    fetch cert file from build server. scp to TiS.
    Args:
        cert_file (str): valid values: ca-cert, server-with-key
        scp_to_local (bool): Whether to scp cert file to localhost as well.
        con_ssh (SSHClient): active controller ssh client

    Returns (str|None):
        cert file path on localhost if scp_to_local=True, else cert file path
        on TiS system. If no certificate found, return None.

    """
    if not cert_file:
        cert_file = '{}/ca-cert.pem'.format(HostLinuxUser.get_home())

    if not con_ssh:
        con_ssh = ControllerClient.get_active_controller()

    if not con_ssh.file_exists(cert_file):
        raise FileNotFoundError(
            '{} not found on active controller'.format(cert_file))

    if scp_to_local:
        cert_name = os.path.basename(cert_file)
        dest_path = os.path.join(ProjVar.get_var('TEMP_DIR'), cert_name)
        common.scp_from_active_controller_to_localhost(source_path=cert_file,
                                                       dest_path=dest_path,
                                                       timeout=120)
        cert_file = dest_path
        LOG.info("Cert file copied to {} on localhost".format(dest_path))

    return cert_file
コード例 #16
0
ファイル: test_restore.py プロジェクト: pvaduva/auto_test
def restore_volumes(con_ssh=None):
    LOG.info('Restore cinder volumes using new (UPSTREAM) cinder-backup CLIs')
    # Getting all registered cinder volumes

    if con_ssh is None:
        con_ssh = ControllerClient.get_active_controller()

    using_cinder_backup = RestoreVars.get_restore_var('cinder_backup')
    volumes = cinder_helper.get_volumes()

    in_use_volumes = []
    if len(volumes) > 0:
        LOG.info("System has {} registered volumes: {}".format(
            len(volumes), volumes))
        if not using_cinder_backup:
            rc, restored_vols = install_helper.restore_cinder_volumes_from_backup(
            )
        else:
            in_use_volumes = create_dummy_rbd_images(volumes, con_ssh=con_ssh)
            rc, restored_vols = restore_from_cinder_backups(volumes, con_ssh)

        assert rc == 0, "All or some volumes has failed import: Restored volumes {};" \
                        " Expected volumes {}".format(restored_vols, volumes)
        LOG.info('all {} volumes are imported'.format(len(restored_vols)))

        LOG.info(
            'set back their original status for all in-use volumes: {}'.format(
                in_use_volumes))
        for volume_id in in_use_volumes:
            con_ssh.exec_cmd('cinder reset-state --state in-use ' + volume_id)
    else:
        LOG.info(
            "System has {} NO registered volumes; skipping cinder volume restore"
        )
コード例 #17
0
ファイル: glance_helper.py プロジェクト: pvaduva/auto_test
def is_image_conversion_sufficient(img_file_path=None,
                                   guest_os=None,
                                   min_diff=0.05,
                                   con_ssh=None,
                                   img_host_ssh=None):
    """
    Check if image conversion space is sufficient to convert given image to
    raw format
    Args:
        img_file_path (str): e.g., ~/images/tis-centos-guest.img
        guest_os (str): has to be specified if img_file_path is unspecified.
        e.g., 'tis-centos-guest'
        min_diff (int): in GB
        con_ssh:
        img_host_ssh

    Returns (bool):

    """
    if con_ssh is None:
        con_ssh = ControllerClient.get_active_controller()

    if not system_helper.get_storage_nodes(con_ssh=con_ssh):
        return True

    avail_size = get_avail_image_conversion_space(con_ssh=con_ssh)
    file_size = get_image_size(img_file_path=img_file_path,
                               guest_os=guest_os,
                               virtual_size=True,
                               ssh_client=img_host_ssh)

    return avail_size - file_size >= min_diff
コード例 #18
0
def test_patch_log_upload_dir(get_patch_name):
    """
    Checks that the correct logs are added when uploading a directory of patches

    Test Steps:
        - Upload patches from a directory
        - Check the log files for the expected logs

    """

    patch_name = get_patch_name
    con_ssh = ControllerClient.get_active_controller()
    LOG.tc_step("Uploading patches from directory")
    code = con_ssh.exec_sudo_cmd('sw-patch upload-dir test_patches')[0]
    if code is not 0:
        skip("No patches found. Cannot test.")
    res_1 = check_dir(patch_name)

    search_for = ['sw-patch-controller-daemon.*INFO: Importing patches:.*{}'.format(patch_name),
                  'sw-patch-controller-daemon.*INFO: Importing patch:.*{}'.format(patch_name)]
    res_2 = check_logs(search_for, lines=20, api=False)

    user = HostLinuxUser.get_user()
    search_for = ['sw-patch-controller-daemon.*INFO: User: {}/admin Action: '
                  'Importing patches:.*{}.patch'.format(user, patch_name),
                  'sw-patch-controller-daemon.*INFO: User: {}/admin Action: '
                  'Importing patch:.*{}.patch'.format(user, patch_name)]
    res_3 = check_logs(search_for, lines=10, api=True)

    LOG.tc_step("Deleting patch {}".format(patch_name))
    con_ssh.exec_sudo_cmd('sw-patch delete {}'.format(patch_name))

    assert res_1, "FAIL: The patch was not in \"sw-patch query\""
    assert res_2, "FAIL: uploading patches did not generate the expected logs in patching.log"
    assert res_3, "FAIL: uploading patches did not generate the expected logs in patching-api.log"
コード例 #19
0
ファイル: container_helper.py プロジェクト: pvaduva/auto_test
def upload_helm_charts(tar_file,
                       repo=None,
                       delete_first=False,
                       con_ssh=None,
                       timeout=120,
                       fail_ok=False):
    """
    Upload helm charts via helm-upload cmd
    Args:
        tar_file:
        repo
        delete_first:
        con_ssh:
        timeout:
        fail_ok:

    Returns (tuple):
        (0, <path_to_charts>)
        (1, <std_err>)
        (2, <hostname for host that does not have helm charts in expected dir>)

    """
    if not con_ssh:
        con_ssh = ControllerClient.get_active_controller()

    helm_dir = os.path.normpath(StxPath.HELM_CHARTS_DIR)
    if not repo:
        repo = 'starlingx'
    file_path = os.path.join(helm_dir, repo, os.path.basename(tar_file))
    current_host = con_ssh.get_hostname()
    controllers = [current_host]
    if not system_helper.is_aio_simplex(con_ssh=con_ssh):
        con_name = 'controller-1' if controllers[
            0] == 'controller-0' else 'controller-0'
        controllers.append(con_name)

    if delete_first:
        for host in controllers:
            with host_helper.ssh_to_host(hostname=host,
                                         con_ssh=con_ssh) as host_ssh:
                if host_ssh.file_exists(file_path):
                    host_ssh.exec_sudo_cmd('rm -f {}'.format(file_path))

    code, output = exec_helm_upload_cmd(tarball=tar_file,
                                        repo=repo,
                                        timeout=timeout,
                                        con_ssh=con_ssh,
                                        fail_ok=fail_ok)
    if code != 0:
        return 1, output

    file_exist = con_ssh.file_exists(file_path)
    if not file_exist:
        raise exceptions.ContainerError(
            "{} not found on {} after helm-upload".format(
                file_path, current_host))

    LOG.info("Helm charts {} uploaded successfully".format(file_path))
    return 0, file_path
コード例 #20
0
    def get_current_user_password(cls, con_ssh=None):
        if not con_ssh:
            con_ssh = ControllerClient.get_active_controller()
        user = con_ssh.get_current_user()
        if user == HostLinuxUser.get_user():
            return user, HostLinuxUser.get_password()

        return user, cls.__users[user]
コード例 #21
0
def check_dir(patch_name):
    con_ssh = ControllerClient.get_active_controller()
    code, out = con_ssh.exec_sudo_cmd('sw-patch query')
    out = out.split('\n')

    search_for = [patch_name, 'Available']
    found = search_query_table(out, search_for)
    return len(search_for) == len(found)
コード例 #22
0
ファイル: test_stx_monitor.py プロジェクト: starlingx/test
def stx_monitor_file_exist():
    con_ssh = ControllerClient.get_active_controller()
    home_dir = HostLinuxUser.get_home()
    stx_mon_file = '{}/{}'.format(home_dir, STX_MONITOR_TAR)

    LOG.info("Check if file %s is present" % stx_mon_file)

    return con_ssh.file_exists(stx_mon_file)
コード例 #23
0
ファイル: test_ima.py プロジェクト: starlingx/test
def _exec_cmd(cmd, con_ssh=None, sudo=False, fail_ok=True):
    if not con_ssh:
        con_ssh = ControllerClient.get_active_controller()

    if sudo:
        return con_ssh.exec_sudo_cmd(cmd, fail_ok=fail_ok)
    else:
        return con_ssh.exec_cmd(cmd, fail_ok=fail_ok)
コード例 #24
0
def exec_docker_cmd(sub_cmd, args, timeout=120, con_ssh=None, fail_ok=False):
    if not con_ssh:
        con_ssh = ControllerClient.get_active_controller()

    cmd = 'docker {} {}'.format(sub_cmd, args)
    code, output = con_ssh.exec_sudo_cmd(cmd, expect_timeout=timeout,
                                         fail_ok=fail_ok)

    return code, output
コード例 #25
0
ファイル: keystone_helper.py プロジェクト: starlingx/test
def set_user(user, name=None, project=None, password=None, project_doamin=None,
             email=None, description=None,
             enable=None, fail_ok=False, auth_info=Tenant.get('admin'),
             con_ssh=None):
    LOG.info("Updating {}...".format(user))
    arg = ''
    optional_args = {
        'name': name,
        'project': project,
        'password': password,
        'project-domain': project_doamin,
        'email': email,
        'description': description,
    }
    for key, val in optional_args.items():
        if val is not None:
            arg += "--{} '{}' ".format(key, val)

    if enable is not None:
        arg += '--{} '.format('enable' if enable else 'disable')

    if not arg.strip():
        raise ValueError(
            "Please specify the param(s) and value(s) to change to")

    arg += user

    code, output = cli.openstack('user set', arg, ssh_client=con_ssh, timeout=120,
                                 fail_ok=fail_ok, auth_info=auth_info)

    if code > 0:
        return 1, output

    if name or project or password:
        tenant_dictname = user
        if auth_info and auth_info.get('platform'):
            tenant_dictname += '_platform'
        Tenant.update(tenant_dictname, username=name, password=password,
                      tenant=project)

    if password and user == 'admin':
        from consts.proj_vars import ProjVar
        if ProjVar.get_var('REGION') != 'RegionOne':
            LOG.info(
                "Run openstack_update_admin_password on secondary region "
                "after admin password change")
            if not con_ssh:
                con_ssh = ControllerClient.get_active_controller()
            with con_ssh.login_as_root(timeout=30) as con_ssh:
                con_ssh.exec_cmd(
                    "echo 'y' | openstack_update_admin_password '{}'".format(
                        password))

    msg = 'User {} updated successfully'.format(user)
    LOG.info(msg)
    return 0, output
コード例 #26
0
def scp_from_active_controller_to_test_server(source_path,
                                              dest_dir,
                                              dest_name=None,
                                              timeout=900,
                                              is_dir=False,
                                              con_ssh=None):
    """
    SCP file or files under a directory from test server to TiS server

    Args:
        source_path (str): test server file path or directory path
        dest_dir (str): destination directory. should end with '/'
        dest_name (str): destination file name if not dir
        timeout (int):
        is_dir (bool):
        con_ssh:

    Returns (str|None): destination file/dir path if scp successful else None

    """
    skip('Shared Test File Server is not ready')
    if con_ssh is None:
        con_ssh = ControllerClient.get_active_controller()

    dir_option = '-r ' if is_dir else ''
    dest_server = TestFileServer.SERVER
    dest_user = TestFileServer.USER
    dest_password = TestFileServer.PASSWORD

    dest_path = dest_dir if not dest_name else os.path.join(
        dest_dir, dest_name)

    scp_cmd = 'scp -oStrictHostKeyChecking=no -o ' \
              'UserKnownHostsFile=/dev/null ' \
              '{}{} {}@{}:{}'.\
        format(dir_option, source_path, dest_user, dest_server, dest_path)

    LOG.info("scp file(s) from tis server to test server")
    con_ssh.send(scp_cmd)
    index = con_ssh.expect(
        [con_ssh.prompt, Prompt.PASSWORD_PROMPT, Prompt.ADD_HOST],
        timeout=timeout)
    if index == 2:
        con_ssh.send('yes')
        index = con_ssh.expect([con_ssh.prompt, Prompt.PASSWORD_PROMPT],
                               timeout=timeout)
    if index == 1:
        con_ssh.send(dest_password)
        index = con_ssh.expect(timeout=timeout)

    assert index == 0, "Failed to scp files"

    exit_code = con_ssh.get_exit_code()
    assert 0 == exit_code, "scp not fully succeeded"

    return dest_path
コード例 #27
0
def generate_alarm_log(alarm_str, maxi=0):
    con_ssh = ControllerClient.get_active_controller()
    for i in range(maxi):
        rtn_code, output = con_ssh.exec_cmd(cmd=alarm_str)
        # check UUID returned.
        uuid_in_output = re.search(UUID, output)
        if not uuid_in_output:
            return False
    else:
        return True
コード例 #28
0
ファイル: setups.py プロジェクト: ashishshah1/test
def setup_tis_ssh(lab):
    con_ssh = ControllerClient.get_active_controller(fail_ok=True)

    if con_ssh is None:
        con_ssh = SSHClient(lab['floating ip'], HostLinuxUser.get_user(),
                            HostLinuxUser.get_password(), CONTROLLER_PROMPT)
        con_ssh.connect(retry=True, retry_timeout=30)
        ControllerClient.set_active_controller(con_ssh)

    return con_ssh
コード例 #29
0
def heat_precheck():
    """
    Skip test on systems that don't use heat stacks to setup the lab.
    """
    con_ssh = ControllerClient.get_active_controller()
    cmd = "test -f /home/sysadmin/.heat_resources"
    rc, out = con_ssh.exec_cmd(cmd)

    if rc != 0:
        skip("Heat is not used to setup this lab")
コード例 #30
0
def _test_firewall_rules_default():
    """
    Verify default ports are open.

    Test Steps:
        - Confirm iptables service is running on active controller
        - Check if lab is http(s), add corresponding port to check
        - Confirm the default ports are open
        - Swact and repeat the above steps
    """
    # Cannot test connecting to the ports as they are in use.

    default_ports = [
        123, 161, 199, 5000, 6080, 6385, 8000, 8003, 8004, 8041, 8774, 8776,
        8778, 9292, 9696, 15491
    ]

    from consts.proj_vars import ProjVar
    region = ProjVar.get_var('REGION')
    if region != 'RegionOne' and region in MULTI_REGION_MAP:
        default_ports.remove(5000)
        default_ports.remove(9292)

    default_ports.append(8443) if CliAuth.get_var(
        'HTTPS') else default_ports.append(8080)

    active_controller = system_helper.get_active_controller_name()
    con_ssh = ControllerClient.get_active_controller()

    _verify_iptables_status(con_ssh, active_controller)
    _check_ports_with_netstat(con_ssh, active_controller, default_ports)

    active_controller, new_active = system_helper.get_active_standby_controllers(
    )
    if new_active:
        LOG.tc_step(
            "Swact {} and verify firewall rules".format(active_controller))
        host_helper.swact_host(active_controller)
        con_ssh = ControllerClient.get_active_controller()

        _verify_iptables_status(con_ssh, new_active)
        _check_ports_with_netstat(con_ssh, new_active, default_ports)