Exemple #1
0
def pytest_configure(config):
    # Lab install params
    lab = config.getoption('lab')
    use_usb = config.getoption('use_usb')
    backup_src_path = config.getoption('backup_path')
    backup_build_id = config.getoption('backup_build_id')
    backup_src = 'usb' if use_usb else 'local'
    skip_setup_feed = config.getoption('skip_setup_feed')
    skip_reinstall = config.getoption('skip_reinstall')
    low_latency = config.getoption('low_latency')
    cinder_backup = config.getoption('cinder_backup')
    # build_server = config.getoption('build_server')

    backup_builds_dir = config.getoption('backup_builds_dir')
    build_server = config.getoption('build_server')
    # tis_build_dir = config.getoption('tis_build_dir')

    setups.set_install_params(lab=lab, skip='feed' if skip_setup_feed else None, resume=None, installconf_path=None,
                              drop=None, boot='usb' if use_usb else 'feed', controller0_ceph_mon_device=None,
                              iso_path=None, controller1_ceph_mon_device=None, ceph_mon_gib=None,
                              low_latency=low_latency, security='standard',
                              stop=None, wipedisk=False, ovs=False, patch_dir=None, boot_server=None)

    if backup_src == 'usb':
        if (not backup_src_path) or (BackupRestore.USB_MOUNT_POINT not in backup_src_path):
            backup_src_path = BackupRestore.USB_BACKUP_PATH
    elif not backup_src_path:
        backup_src_path = BackupRestore.LOCAL_BACKUP_PATH

    if not backup_builds_dir:
        backup_builds_dir = os.path.basename(BuildServerPath.DEFAULT_HOST_BUILDS_DIR)

    RestoreVars.set_restore_vars(backup_src=backup_src, backup_src_path=backup_src_path, build_server=build_server,
                                 backup_build_id=backup_build_id,  backup_builds_dir=backup_builds_dir)

    reinstall_storage = config.getoption('reinstall_storage')
    RestoreVars.set_restore_var(reinstall_storage=reinstall_storage)

    RestoreVars.set_restore_var(skip_setup_feed=skip_setup_feed)
    RestoreVars.set_restore_var(skip_reinstall=skip_reinstall)
    RestoreVars.set_restore_var(low_latency=low_latency)
    RestoreVars.set_restore_var(cinder_backup=cinder_backup)

    ProjVar.set_var(always_collect=True)
    ProjVar.set_var(SOURCE_OPENRC=True)
Exemple #2
0
def pytest_configure(config):

    # Lab fresh_install params
    lab_arg = config.getoption('lab')
    resume_install = config.getoption('resumeinstall')
    skiplist = config.getoption('skiplist')
    wipedisk = config.getoption('wipedisk')
    controller0_ceph_mon_device = config.getoption('ceph_mon_dev_controller_0')
    controller1_ceph_mon_device = config.getoption('ceph_mon_dev_controller_1')
    ceph_mon_gib = config.getoption('ceph_mon_gib')
    install_conf = config.getoption('installconf')
    lab_file_dir = config.getoption('file_dir')
    build_server = config.getoption('build_server')
    boot_server = config.getoption('boot_server')
    tis_build_dir = config.getoption('tis_build_dir')
    tis_builds_dir = config.getoption('tis_builds_dir')
    install_license = config.getoption('upgrade_license')
    heat_templates = config.getoption('heat_templates')
    guest_image = config.getoption('guest_image_path')
    boot_type = config.getoption('boot_list')
    iso_path = config.getoption('iso_path')
    low_lat = config.getoption('low_latency')
    security = config.getoption('security')
    controller = config.getoption('controller')
    compute = config.getoption('compute')
    storage = config.getoption('storage')
    stop_step = config.getoption('stop_step')
    drop_num = config.getoption('drop_num')
    patch_dir = config.getoption('patch_dir')
    kubernetes = config.getoption('kubernetes_config')
    no_openstack = config.getoption('no_openstack')
    deploy_openstack_from_controller_1 = config.getoption(
        'deploy_openstack_from_controller_1')
    dc_ipv6 = config.getoption('dc_ipv6')
    helm_chart_path = config.getoption('helm_chart_path')
    no_manage = config.getoption('no_manage')
    extract_deploy_config = config.getoption('extract_deploy_config')
    vswitch_type = config.getoption('vswitch_type')
    ipv6_oam = config.getoption('ipv6_oam')
    subcloud_host = config.getoption('subcloud_host')

    # Restore parameters
    backup_src_path = config.getoption('backup_path')
    has_wipe_ceph_osds = config.getoption('has_wipe_ceph_osds')
    wipe_ceph_osds = config.getoption('wipe_ceph_osds')
    restore_pre_boot_controller0 = config.getoption(
        'restore_pre_boot_controller0')
    stop_before_ansible_restore = config.getoption(
        'stop_before_ansible_restore')

    RestoreVars.set_restore_var(backup_src_path=backup_src_path)
    RestoreVars.set_restore_var(has_wipe_ceph_osds=has_wipe_ceph_osds)
    RestoreVars.set_restore_var(wipe_ceph_osds=wipe_ceph_osds)
    RestoreVars.set_restore_var(
        restore_pre_boot_controller0=restore_pre_boot_controller0)
    RestoreVars.set_restore_var(
        stop_before_ansible_restore=stop_before_ansible_restore)

    if not lab_arg:
        raise ValueError("Lab name must be provided")

    vswitch_types = [
        VSwitchType.OVS, VSwitchType.OVS_DPDK, VSwitchType.AVS,
        VSwitchType.NONE
    ]
    if vswitch_type not in vswitch_types:
        raise ValueError(
            "Invalid vswitch type {}; Valid types are: {} ".format(
                vswitch_type, vswitch_types))

    lab_dict = setups.get_lab_dict(lab_arg)
    lab_name = lab_dict['name']
    if 'yow' in lab_name:
        lab_name = lab_name[4:]

    if subcloud_host:
        is_subcloud = False
        sublcoud_name = None
        dc_float_ip = None
        dc_lab_name = None
    else:
        is_subcloud, sublcoud_name, dc_float_ip, dc_lab_name = setups.is_lab_subcloud(
            lab_dict, ipv6=ipv6_oam)
        if is_subcloud and 'yow' in dc_lab_name:
            dc_lab_name = dc_lab_name[4:]

    if resume_install is True:
        resume_install = fresh_install_helper.get_resume_step(lab_dict)
        LOG.info("Resume Install step at {}".format(resume_install))

    if not install_conf:
        build_server = build_server if build_server else BuildServerPath.DEFAULT_BUILD_SERVER
        if not tis_builds_dir and not tis_build_dir:
            # Take latest master load from cengn
            host_build_dir_path = BuildServerPath.DEFAULT_HOST_BUILD_PATH
        elif tis_build_dir and os.path.isabs(tis_build_dir):
            host_build_dir_path = tis_build_dir
        else:
            # Take in-house StarlingX_Upstream_build
            tis_builds_dir = tis_builds_dir if tis_builds_dir else ''
            tis_build_dir = tis_build_dir if tis_build_dir else BuildServerPath.LATEST_BUILD
            host_build_dir_path = os.path.join(
                BuildServerPath.DEFAULT_WORK_SPACE, tis_builds_dir,
                tis_build_dir)

        host_build_dir_path = os.path.normpath(host_build_dir_path)
        if host_build_dir_path.endswith('/latest_build'):
            build_id = build_info.get_latest_host_build_dir(
                build_server=build_server,
                latest_build_simlink=host_build_dir_path)
            host_build_dir_path = host_build_dir_path[:-len('latest_build'
                                                            )] + build_id

        files_server = build_server
        if lab_file_dir:
            if lab_file_dir.find(":/") != -1:
                files_server = lab_file_dir[:lab_file_dir.find(":/")]
                lab_file_dir = lab_file_dir[lab_file_dir.find(":") + 1:]
            if not os.path.isabs(lab_file_dir):
                lab_file_dir = "{}/lab/yow/{}".format(host_build_dir_path,
                                                      lab_file_dir)
        else:
            lab_file_dir = "{}/lab/yow/{}".format(host_build_dir_path, lab_name if lab_name else '') \
                if not is_subcloud else "{}/lab/yow/{}".format(host_build_dir_path, dc_lab_name if dc_lab_name else '')

        if not heat_templates:
            if BuildServerPath.BldsDirNames.TC_19_05_BUILD in host_build_dir_path:
                heat_templates = os.path.join(
                    BuildServerPath.EAR_HOST_BUILD_PATH,
                    BuildServerPath.HEAT_TEMPLATES)
            else:
                heat_templates = os.path.join(
                    BuildServerPath.STX_HOST_BUILDS_DIR, 'latest_full_build',
                    BuildServerPath.HEAT_TEMPLATES)
        elif not os.path.isabs(heat_templates):
            heat_templates = os.path.join(host_build_dir_path, heat_templates)

        if not helm_chart_path:
            helm_path_in_build = BuildServerPath.STX_HELM_CHARTS_CENGN \
                if '/import/' in host_build_dir_path or '19.05' \
                in host_build_dir_path else BuildServerPath.TITANIUM_HELM_CHARTS

            helm_chart_path = os.path.join(host_build_dir_path,
                                           helm_path_in_build)

        if boot_type.lower() in ('usb_burn', 'pxe_iso',
                                 'iso_feed') and not iso_path:
            iso_path_in_build = BuildServerPath.ISO_PATH_CENGN \
                if '/import/' in host_build_dir_path \
                else BuildServerPath.ISO_PATH
            iso_path = os.path.join(host_build_dir_path, iso_path_in_build)

        install_conf = setups.write_installconf(
            lab=lab_arg,
            controller=controller,
            compute=compute,
            storage=storage,
            lab_files_dir=lab_file_dir,
            patch_dir=patch_dir,
            tis_build_dir=host_build_dir_path,
            build_server=build_server,
            files_server=files_server,
            license_path=install_license,
            guest_image=guest_image,
            heat_templates=heat_templates,
            boot=boot_type,
            iso_path=iso_path,
            security=security,
            low_latency=low_lat,
            stop=stop_step,
            vswitch_type=vswitch_type,
            boot_server=boot_server,
            resume=resume_install,
            skip=skiplist,
            kubernetes=kubernetes,
            helm_chart_path=helm_chart_path)

        setups.set_install_params(
            lab=lab_arg,
            skip=skiplist,
            resume=resume_install,
            wipedisk=wipedisk,
            drop=drop_num,
            installconf_path=install_conf,
            controller0_ceph_mon_device=controller0_ceph_mon_device,
            controller1_ceph_mon_device=controller1_ceph_mon_device,
            ceph_mon_gib=ceph_mon_gib,
            boot=boot_type,
            iso_path=iso_path,
            security=security,
            low_latency=low_lat,
            stop=stop_step,
            patch_dir=patch_dir,
            vswitch_type=vswitch_type,
            boot_server=boot_server,
            dc_float_ip=dc_float_ip,
            ipv6_oam=ipv6_oam,
            install_subcloud=sublcoud_name,
            kubernetes=kubernetes,
            no_openstack=no_openstack,
            dc_ipv6=dc_ipv6,
            helm_chart_path=helm_chart_path,
            no_manage=no_manage,
            deploy_openstack_from_controller_1=
            deploy_openstack_from_controller_1,
            extract_deploy_config=extract_deploy_config,
            subcloud_host=subcloud_host)

    frame_str = '*' * len('Install Arguments:')
    args = "\n\n{}\nInstall Arguments:\n{}\n".format(frame_str, frame_str)
    install_vars = InstallVars.get_install_vars()
    bs = install_vars['BUILD_SERVER']
    for var, value in install_vars.items():
        if (not value and value != 0) or (value == bs
                                          and var != 'BUILD_SERVER'):
            continue
        elif var == 'LAB':
            for k, v in dict(value).items():
                if re.search('_nodes| ip', k):
                    args += "\n{:<20}: {}".format(k, v)
        else:
            args += "\n{:<20}: {}".format(var, value)
    args += "\n{:<20}: {}\n".format('LOG_DIR', ProjVar.get_var('LOG_DIR'))
    LOG.info(args)

    if resume_install:
        try:
            con0_ip = install_vars.get('LAB', {}).get('controller-0 ip')
            if con0_ip:
                with host_helper.ssh_to_host(con0_ip, timeout=60) as con0_ssh:
                    setups.set_build_info(con_ssh=con0_ssh)
                    setups.set_session(con_ssh=con0_ssh)
        except:
            pass
Exemple #3
0
def pre_restore_checkup():
    """
    Fixture to check the system states before doing system restore, including:
        - collect logs
        - check if backup files exist on the backup media
        - check if the build-ids match with each other
        - wipe disks

    Args:

    Return:
        backup files:
            - the backup files to restore with
    """

    lab = InstallVars.get_install_var('LAB')
    LOG.info("Lab info; {}".format(lab))
    backup_build_id = RestoreVars.get_restore_var("BACKUP_BUILD_ID")
    controller_node = lab['controller-0']
    backup_src = RestoreVars.get_restore_var('backup_src'.upper())
    backup_src_path = RestoreVars.get_restore_var('backup_src_path'.upper())
    tis_backup_files = []
    extra_controller_prompt = Prompt.TIS_NODE_PROMPT_BASE.format(lab['name'].
                                                                 split('_')[0]) + '|' + \
                              Prompt.CONTROLLER_0
    controller_conn = install_helper.ssh_to_controller(
        controller_node.host_ip,
        initial_prompt=extra_controller_prompt,
        fail_ok=True)

    LOG.info('Collect logs before restore')
    if controller_conn:
        collect_logs(controller_conn)
        ControllerClient.set_active_controller(controller_conn)
    else:
        LOG.info('Cannot collect logs because no ssh connection to the lab')

    if not controller_conn:
        LOG.warn(
            'failed to collect logs because no ssh connection established to '
            'controller-0 of lab:{}'.format(controller_node.host_ip))
    else:
        pass

    LOG.info('backup_src={}, backup_src_path={}'.format(
        backup_src, backup_src_path))
    if backup_src.lower() == 'usb':
        if controller_conn:
            LOG.info("Connection established with controller-0 ....")
            ControllerClient.set_active_controller(ssh_client=controller_conn)

            LOG.info(
                "Checking if a USB flash drive with backup files is plugged in... "
            )
            usb_device_name = install_helper.get_usb_device_name(
                con_ssh=controller_conn)
            assert usb_device_name, "No USB found "
            LOG.info("USB flash drive found, checking for backup files ... ")
            usb_part_info = install_helper.get_usb_device_partition_info(
                usb_device=usb_device_name, con_ssh=controller_conn)
            assert usb_part_info and len(
                usb_part_info) > 0, "No USB or partition found"

            usb_part_name = "{}2".format(usb_device_name)
            assert usb_part_name in usb_part_info.keys(
            ), "No {} partition exist in USB"
            result, mount_point = install_helper.is_usb_mounted(
                usb_device=usb_part_name, con_ssh=controller_conn)
            if not result:
                assert install_helper.mount_usb(usb_device=usb_part_name, con_ssh=controller_conn), \
                    "Unable to mount USB partition {}".format(usb_part_name)

            tis_backup_files = install_helper.get_titanium_backup_filenames_usb(
                usb_device=usb_part_name, con_ssh=controller_conn)
            assert len(
                tis_backup_files) >= 2, "Missing backup files: {}".format(
                    tis_backup_files)

            # extract build id from the file name
            file_parts = tis_backup_files[0].split('_')

            file_backup_build_id = '_'.join([file_parts[3], file_parts[4]])

            assert re.match(TIS_BLD_DIR_REGEX,
                            file_backup_build_id), " Invalid build id format {} extracted from " \
                                                   "backup_file {}".format(
                file_backup_build_id, tis_backup_files[0])

            if backup_build_id is not None:
                if backup_build_id != file_backup_build_id:
                    LOG.info(
                        " The build id extracted from backup file is different than "
                        "specified; Using the extracted build id {} ....".
                        format(file_backup_build_id))

                    backup_build_id = file_backup_build_id

            else:
                backup_build_id = file_backup_build_id

            RestoreVars.set_restore_var(backup_build_id=backup_build_id)

        else:

            LOG.info(" SSH connection not available yet with controller-0;  "
                     "USB will be checked after controller boot ....")
    else:
        test_server_attr = dict()
        test_server_attr['name'] = TestFileServer.get_hostname().split('.')[0]
        test_server_attr['server_ip'] = TestFileServer.get_server()
        test_server_attr['prompt'] = r'\[{}@{} {}\]\$ ' \
            .format(TestFileServer.get_user(), test_server_attr['name'], TestFileServer.get_user())

        test_server_conn = install_helper.establish_ssh_connection(
            test_server_attr['name'],
            user=TestFileServer.get_user(),
            password=TestFileServer.get_password(),
            initial_prompt=test_server_attr['prompt'])

        test_server_conn.set_prompt(test_server_attr['prompt'])
        test_server_conn.deploy_ssh_key(install_helper.get_ssh_public_key())
        test_server_attr['ssh_conn'] = test_server_conn
        test_server_obj = Server(**test_server_attr)
        RestoreVars.set_restore_var(backup_src_server=test_server_obj)

        # test if backup path for the lab exist in Test server
        if os.path.basename(backup_src_path) != lab['short_name']:
            backup_src_path += '/{}'.format(lab['short_name'])
            RestoreVars.set_restore_var(backup_src_path=backup_src_path)

        assert not test_server_conn.exec_cmd("test -e {}".format(backup_src_path))[0], \
            "Missing backup files from source {}: {}".format(test_server_attr['name'],
                                                             backup_src_path)

        tis_backup_files = install_helper.get_backup_files(
            TITANIUM_BACKUP_FILE_PATTERN, backup_src_path, test_server_conn)

        assert len(tis_backup_files) >= 2, "Missing backup files: {}".format(
            tis_backup_files)

        # extract build id from the file name
        file_parts = tis_backup_files[0].split('_')

        file_backup_build_id = '_'.join([file_parts[3], file_parts[4]])

        assert re.match(TIS_BLD_DIR_REGEX,
                        file_backup_build_id), "Invalid build id format {} extracted from " \
                                               "backup_file {}".format(
            file_backup_build_id, tis_backup_files[0])

        if backup_build_id is not None:
            if backup_build_id != file_backup_build_id:
                LOG.info(
                    " The build id extracted from backup file is different than specified; "
                    "Using the extracted build id {} ....".format(
                        file_backup_build_id))

                backup_build_id = file_backup_build_id

        else:
            backup_build_id = file_backup_build_id

        RestoreVars.set_restore_var(backup_build_id=backup_build_id)

        if controller_conn:
            # Wipe disks in order to make controller-0 NOT boot from hard-disks
            # hosts = [k for k , v in lab.items() if isinstance(v, node.Node)]
            # install_helper.wipe_disk_hosts(hosts)
            if not RestoreVars.get_restore_var('skip_reinstall'):
                LOG.info('Try to do wipedisk_via_helper on controller-0')
                install_helper.wipedisk_via_helper(controller_conn)

    assert backup_build_id, "The Build id of the system backup must be provided."

    return tis_backup_files