コード例 #1
0
def satellite6_client_upgrade(os_version, clients):
    """Upgrades clients from existing version to latest version

    :param string os_version: The rhel os onto which the client is installed or
        to be installed
    :param list clients: The list of clients onto which the upgrade will be
        performed
    """
    logger.highlight(
        '\n========== {} CLIENTS UPGRADE =================\n'.format(
            os_version.upper()))
    old_version = os.environ.get('FROM_VERSION')
    docker_vm = os.environ.get('DOCKER_VM')
    rhel_ver = os_version[-1]
    old_repo = 'rhel-{0}-server-satellite-tools-{1}-rpms'.format(
        rhel_ver, old_version)
    if os.environ.get('CLIENT6_HOSTS') or os.environ.get('CLIENT7_HOSTS'):
        user_clients_upgrade(old_repo, clients)
    elif os.environ.get('DOCKER_VM'):
        execute(docker_clients_upgrade, old_repo, clients, host=docker_vm)
        # Fetching katello-agent version post upgrade from all clients
        # Giving 5 minutes for docker clients to upgrade katello-agent
        time.sleep(300)
        client_vers = execute(docker_clients_katello_agent_version,
                              clients,
                              host=docker_vm)[docker_vm]
        for hostname, version in client_vers.items():
            logger.highlight('The katello-agent on client {0} upgraded '
                             'to version {1}'.format(hostname, version))
コード例 #2
0
def satellite6_capsule_zstream_upgrade(cap_host):
    """Upgrades Capsule to its latest zStream version

    :param string cap_host: Capsule hostname onto which the capsule upgrade
    will run

    Note: For zstream upgrade both 'To' and 'From' version should be same

    FROM_VERSION
        Current satellite version which will be upgraded to latest version
    TO_VERSION
        Next satellite version to which satellite will be upgraded
    """
    logger.highlight('\n========== CAPSULE UPGRADE =================\n')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    if not from_version == to_version:
        logger.warning('zStream Upgrade on Capsule cannot be performed as '
                       'FROM and TO versions are not same!')
        sys.exit(1)
    major_ver = distro_info()[1]
    if os.environ.get('CAPSULE_URL'):
        disable_old_repos('rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
            major_ver, from_version))
    # Check what repos are set
    if os.environ.get("FOREMAN_MAINTAIN_CAPSULE_UPGRADE") == 'true':
        upgrade_using_foreman_maintain(sat_host=False)
    else:
        nonfm_upgrade(satellite_upgrade=False)
    # Rebooting the capsule for kernel update if any
    reboot(160)
    host_ssh_availability_check(cap_host)
    # Check if Capsule upgrade is success
    upgrade_validation()
コード例 #3
0
def satellite6_client_upgrade(os_version, clients):
    """Upgrades clients from existing version to latest version

    :param string os_version: The rhel os onto which the client is installed or
        to be installed
    :param list clients: The list of clients onto which the upgrade will be
        performed
    """
    logger.highlight(
        '\n========== {} CLIENTS UPGRADE =================\n'.format(
            os_version.upper()))
    old_version = os.environ.get('FROM_VERSION')
    docker_vm = os.environ.get('DOCKER_VM')
    rhel_ver = os_version[-1]
    old_repo = 'rhel-{0}-server-satellite-tools-{1}-rpms'.format(
        rhel_ver, old_version)
    if os.environ.get('CLIENT6_HOSTS') or os.environ.get('CLIENT7_HOSTS'):
        user_clients_upgrade(old_repo, clients)
    elif os.environ.get('DOCKER_VM'):
        execute(
            docker_clients_upgrade,
            old_repo,
            clients,
            host=docker_vm
        )
コード例 #4
0
def satellite_capsule_setup(satellite_host,
                            capsule_hosts,
                            os_version,
                            upgradable_capsule=True):
    """
    Setup all pre-requisites for user provided capsule

    :param satellite_host: Satellite hostname to which the capsule registered
    :param capsule_hosts: List of capsule which mapped with satellite host
    :param os_version: The OS version onto which the capsule installed e.g: rhel6, rhel7
    :param upgradable_capsule:Whether to setup capsule to be able to upgrade in future
    :return: capsule_hosts
    """
    if os_version == 'rhel6':
        baseurl = settings.repos.rhel6_os
    elif os_version == 'rhel7':
        baseurl = settings.repos.rhel7_os
    else:
        logger.highlight('No OS Specified. Aborting...')
        sys.exit(1)
    non_responsive_host = []
    for cap_host in capsule_hosts:
        if not host_pings(cap_host):
            non_responsive_host.append(cap_host)
        else:
            execute(host_ssh_availability_check, cap_host)
        # Update the template once 1829115 gets fixed.
        execute(workaround_1829115, host=cap_host)
        if not bz_bug_is_open(1829115):
            logger.warn(
                "Please update the capsule template for fixed capsule version")
        execute(foreman_service_restart, host=cap_host)
        if non_responsive_host:
            logger.highlight(
                str(non_responsive_host) + ' these are non-responsive hosts. '
                'Aborting...')
            sys.exit(1)
        copy_ssh_key(satellite_host, capsule_hosts)
    if upgradable_capsule:
        if settings.upgrade.distribution == "cdn":
            settings.repos.capsule_repo = None
            settings.repos.sattools_repo[settings.upgrade.os] = None
            settings.repos.satmaintenance_repo = None
        execute(update_capsules_to_satellite,
                capsule_hosts,
                host=satellite_host)
        if settings.upgrade.upgrade_with_http_proxy:
            http_proxy_config(capsule_hosts)
        execute(sync_capsule_repos_to_satellite,
                capsule_hosts,
                host=satellite_host)
        for cap_host in capsule_hosts:
            settings.upgrade.capsule_hostname = cap_host
            execute(add_baseOS_repo, baseurl, host=cap_host)
            execute(yum_repos_cleanup, host=cap_host)
            logger.info(f'Capsule {cap_host} is ready for Upgrade')
        return capsule_hosts
コード例 #5
0
def satellite_capsule_zstream_upgrade(cap_host):
    """Upgrades Capsule to its latest zStream version

    :param string cap_host: Capsule hostname onto which the capsule upgrade
    will run

    Note: For zstream upgrade both 'To' and 'From' version should be same

    FROM_VERSION
        Current satellite version which will be upgraded to latest version
    TO_VERSION
        Next satellite version to which satellite will be upgraded
    """
    logger.highlight('\n========== CAPSULE UPGRADE =================\n')
    from_version = settings.upgrade.from_version
    to_version = settings.upgrade.to_version
    if not from_version == to_version:
        logger.highlight(
            'zStream Upgrade on Capsule cannot be performed as FROM and TO '
            'versions are not same. Aborting...')
        sys.exit(1)
    major_ver = settings.upgrade.os[-1]
    ak_name = settings.upgrade.capsule_ak[settings.upgrade.os]
    run(f'subscription-manager register --org="Default_Organization" '
        f'--activationkey={ak_name} --force')
    logger.info(
        f"Activation key {ak_name} registered capsule's all available repository"
    )
    run("subscription-manager repos --list")
    capsule_repos = [
        RHEL_CONTENTS["tools"]["label"], RHEL_CONTENTS["capsule"]["label"],
        RHEL_CONTENTS["maintenance"]["label"]
    ]
    with fabric_settings(warn_only=True):
        if settings.upgrade.distribution == "cdn":
            enable_disable_repo(enable_repos_name=capsule_repos)
        else:
            enable_disable_repo(disable_repos_name=capsule_repos)
        ansible_repos = [
            f"rhel-{major_ver}-server-ansible-"
            f"{settings.upgrade.ansible_repo_version}-rpms"
        ]
        enable_disable_repo(enable_repos_name=ansible_repos)
    # Check what repos are set
    # setup_foreman_maintain_repo()
    if settings.upgrade.foreman_maintain_capsule_upgrade:
        upgrade_using_foreman_maintain(sat_host=False)
    else:
        nonfm_upgrade(satellite_upgrade=False)
    # Rebooting the capsule for kernel update if any
    if settings.upgrade.satellite_capsule_setup_reboot:
        reboot(160)
    host_ssh_availability_check(cap_host)
    # Check if Capsule upgrade is success
    upgrade_validation()
コード例 #6
0
def user_clients_upgrade(old_repo, clients, agent):
    """Helper function to run upgrade on user provided clients

    :param string old_repo: The old tools repo to disable before updating
        katello-agent package
    :param list clients: The list of clients onto which katello-agent package
        will be updated
    :param string agent: puppet-agent / katello-agent
    """
    for client in clients:
        execute(disable_repos, old_repo, host=client)
        execute(lambda: run(f'yum update -y {agent}'), host=client)
        post = version_filter(execute(lambda: run(f'rpm -q {agent}'), host=client)[client])
        logger.highlight(f'{agent} on {client} upgraded to {post}')
コード例 #7
0
def user_clients_upgrade(old_repo, clients):
    """Helper function to run upgrade on user provided clients

    :param string old_repo: The old tools repo to disable before updating
        katello-agent package
    :param list clients: The list of clients onto which katello-agent package
        will be updated
    """
    for client in clients:
        execute(disable_repos, old_repo, host=client)
        execute(lambda: run('yum update -y katello-agent'), host=client)
        post = katello_agent_version_filter(
            execute(lambda: run('rpm -q katello-agent'), host=client)[client])
        logger.highlight('katello-agent on {0} upgraded to {1}'.format(
            client, post))
コード例 #8
0
def product_setup_for_upgrade_on_brokers_machine(product,
                                                 os_version,
                                                 satellite,
                                                 capsule=None):
    """
    Sets up product(s) to perform upgrade on Satellite, Capsule and content host
    :param string product: The product name to setup before upgrade
    :param string os_version: The os version on which product is installed e.g: rhel6, rhel7
    :param satellite: brokers/users provided satellite
    :param capsule: brokers/users provided capsules, if the capsules count more than one then
     we keep them separate by a semicolon examplet: test1.xyz.com;test2.xyz.com
    """
    cap_hosts = None
    clients6 = clients7 = puppet_clients7 = puppet_clients6 = None
    env.disable_known_hosts = True
    check_necessary_env_variables_for_upgrade(product)

    clients6 = clients7 = puppet_clients7 = puppet_clients6 = None
    logger.info('Setting up Satellite ....')
    satellite_setup(satellite)
    if product in ['capsule', 'n-1', 'longrun']:
        cap_hosts = capsule.split()
        if len(cap_hosts) > 0:
            logger.info('Setting up Capsule ....')
            satellite_capsule_setup(satellite, cap_hosts, os_version,
                                    False if product == 'n-1' else True)
        else:
            logger.highlight(
                f'No capsule is available for capsule setup from provided'
                f' capsules: {cap_hosts}. Aborting...')
            sys.exit(1)
    if product in ['client', 'longrun']:
        logger.info('Setting up Clients ....')
        clients6, clients7, puppet_clients7, puppet_clients6 = satellite6_client_setup(
        )

    setups_dict = {
        satellite: {
            'sat_host': satellite,
            'capsule_hosts': cap_hosts,
            'clients6': clients6,
            'clients7': clients7,
            'puppet_clients7': puppet_clients7,
            'puppet_clients6': puppet_clients6
        }
    }
    create_setup_dict(setups_dict)
コード例 #9
0
def satellite6_capsule_upgrade(cap_host, sat_host):
    """Upgrades capsule from existing version to latest version.

    :param string cap_host: Capsule hostname onto which the capsule upgrade
    will run
    :param string sat_host : Satellite hostname from which capsule certs are to
    be generated

    The following environment variables affect this command:

    CAPSULE_URL
        Optional, defaults to available capsule version in CDN.
        URL for capsule of latest compose to upgrade.
    FROM_VERSION
        Capsule current version, to disable repos while upgrading.
        e.g '6.1','6.0'
    TO_VERSION
        Capsule version to upgrade to and enable repos while upgrading.
        e.g '6.1','6.2'

    """
    logger.highlight('\n========== CAPSULE UPGRADE =================\n')
    from_version = os.environ.get('FROM_VERSION')
    setup_capsule_firewall()
    major_ver = distro_info()[1]
    ak_name = os.environ.get('CAPSULE_AK') if os.environ.get(
        'CAPSULE_AK') else os.environ.get('RHEV_CAPSULE_AK')
    run('subscription-manager register --org="Default_Organization" '
        '--activationkey={0} --force'.format(ak_name))
    disable_old_repos('rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
        major_ver, from_version))
    # setup foreman-maintain
    setup_foreman_maintain_repo()
    # Check what repos are set
    if os.environ.get("FOREMAN_MAINTAIN_CAPSULE_UPGRADE") == 'true':
        upgrade_using_foreman_maintain(sat_host=False)
    else:
        nonfm_upgrade(satellite_upgrade=False,
                      cap_host=cap_host,
                      sat_host=sat_host)
    # Rebooting the capsule for kernel update if any
    reboot(160)
    host_ssh_availability_check(cap_host)
    # Check if Capsule upgrade is success
    upgrade_validation()
コード例 #10
0
def foreman_maintain_upgrade(base_url):
    """
    The purpose of this function is to setup the foreman-maintain and perform the
    foreman-mantain upgrade"
    :param str base_url: It is used to check the repository selection whether
    it from CDN or from Downstream
    """
    if base_url is None:
        os.environ['DISTRIBUTION'] = "CDN"
    else:
        os.environ['DISTRIBUTION'] = "DOWNSTREAM"
    # setup foreman-maintain
    setup_foreman_maintain()
    preup_time = datetime.now().replace(microsecond=0)
    # perform upgrade using foreman-maintain
    upgrade_using_foreman_maintain()
    postup_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for Satellite Upgrade - {}'.format(
        str(postup_time - preup_time)))
コード例 #11
0
def docker_clients_upgrade(old_repo, clients):
    """Helper function to run upgrade on docker containers as clients

    :param string old_repo: The old tools repo to disable before updating
        katello-agent package
    :param dict clients: The dictonary containing client_name as key and
        container_id as value
    """
    for hostname, container in clients.items():
        logger.info('Upgrading client {0} on docker container: {1}'.format(
            hostname, container))
        docker_execute_command(
            container, 'subscription-manager repos --disable {}'.format(
                old_repo))
        docker_execute_command(container, 'yum update -y katello-agent', True)
        pst = katello_agent_version_filter(
            docker_execute_command(container, 'rpm -q katello-agent'))
        logger.highlight(
            'katello-agent on {0} upgraded to {1}'.format(hostname, pst))
コード例 #12
0
def satellite6_client_upgrade(os_version, clients, puppet=False):
    """Upgrades clients from existing version to latest version

    :param string os_version: The rhel os onto which the client is installed or
        to be installed
    :param list clients: The list of clients onto which the upgrade will be
        performed
    :param bool puppet: clients are puppet clients or not, default no
    """
    logger.highlight(
        '\n========== {0} {1} CLIENTS UPGRADE =================\n'.format(
            os_version.upper(), 'PUPPET' if puppet else 'KATELLO'))
    old_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    docker_vm = os.environ.get('DOCKER_VM')
    rhel_ver = os_version[-1]
    old_repo = 'rhel-{0}-server-satellite-tools-{1}-rpms'.format(
        rhel_ver, old_version)
    puppet_agent = 'puppet' if float(to_version) <= 6.3 else 'puppet-agent'
    agent = puppet_agent if puppet else 'katello-agent'
    if os.environ.get('CLIENT6_HOSTS') or os.environ.get('CLIENT7_HOSTS'):
        user_clients_upgrade(old_repo, clients, agent)
    elif os.environ.get('DOCKER_VM'):
        execute(
            docker_clients_upgrade,
            old_repo,
            clients,
            agent,
            host=docker_vm
        )
        # Fetching katello-agent version post upgrade from all clients
        # Giving 5 minutes for docker clients to upgrade katello-agent
        time.sleep(300)
        client_vers = execute(
            docker_clients_agent_version,
            clients,
            agent,
            host=docker_vm
        )[docker_vm]
        for hostname, version in tuple(client_vers.items()):
            logger.highlight(
                'The {0} on client {1} upgraded '
                'to version {2}'.format(agent, hostname, version))
コード例 #13
0
def user_clients_upgrade(old_repo, clients, puppet=False):
    """Helper function to run upgrade on user provided clients

    :param string old_repo: The old tools repo to disable before updating
        katello-agent package
    :param list clients: The list of clients onto which katello-agent package
        will be updated
    :param bool puppet: clients are puppet clients or not, default no
    """
    for client in clients:
        execute(disable_repos, old_repo, host=client)
        agent = 'puppet' if puppet else 'katello'
        execute(lambda: run('yum update -y {}-agent'.format(agent)),
                host=client)
        post = version_filter(
            execute(lambda: run('rpm -q {}-agent'.format(agent)),
                    host=client)[client])
        logger.highlight('{0}-agent on {1} upgraded to {2}'.format(
            agent, client, post))
コード例 #14
0
def nonfm_upgrade(satellite_upgrade=True, cap_host=None, sat_host=None):
    """
    The purpose of this module to perform the upgrade task without foreman-maintain.
    In this function we setup the repository, stop the katello services,
    cleanup, and execute satellite upgrade task"
    :param bool satellite_upgrade: If satellite_upgrade is True then upgrade
    type satellite otherwise capsule
    :param bool zstream: Capsule zStream upgrade
    :param str cap_host: hostname of capsule it used to generate certificate for
    capsules major version upgrade.
    :param str sat_host: hostname of satellite used to generate certificate for
    capsules major version upgrade.
    :
    """
    # Check what repos are set
    upgrade_type = "satellite" if satellite_upgrade else "capsule"
    run('yum repolist')
    # Stop katello services, except mongod
    run('katello-service stop')
    run('yum clean all', warn_only=True)
    # Updating the packages again after setting sat6 repo
    logger.info('Updating system and {} packages... '.format(upgrade_type))
    preyum_time = datetime.now().replace(microsecond=0)
    update_packages(quiet=False)
    postyum_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for system and {} packages update'
                     ' - {}'.format(upgrade_type,
                                    str(postyum_time - preyum_time)))
    # non zStream capsule upgrade
    if sat_host and cap_host:
        execute(generate_capsule_certs, cap_host, True, host=sat_host)
        execute(lambda: run("scp -o 'StrictHostKeyChecking no' {0}-certs.tar "
                            "root@{0}:/home/".format(cap_host)),
                host=sat_host)
        setup_capsule_firewall()
        preup_time = datetime.now().replace(microsecond=0)
        upgrade_task(upgrade_type, cap_host)
    else:
        preup_time = datetime.now().replace(microsecond=0)
        upgrade_task(upgrade_type)
    postup_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for Satellite Upgrade - {}'.format(
        str(postup_time - preup_time)))
コード例 #15
0
def satellite6_client_upgrade(os_version, clients, puppet=False):
    """Upgrades clients from existing version to latest version

    :param string os_version: The rhel os onto which the client is installed or
        to be installed
    :param list clients: The list of clients onto which the upgrade will be
        performed
    :param bool puppet: clients are puppet clients or not, default no
    """
    docker_vm = settings.upgrade.docker_vm
    logger.highlight(
        '\n========== {0} {1} CLIENTS UPGRADE =================\n'.format(
            os_version.upper(), 'PUPPET' if puppet else 'KATELLO'))
    old_repo = f'rhel-{settings.upgrade.os[-1]}-server-satellite-tools-' \
        f'{settings.upgrade.from_version}-rpms'
    agent = 'puppet-agent' if puppet else 'katello-agent'
    if settings.upgrade.user_defined_client_hosts.rhel6 or \
            settings.upgrade.user_defined_client_hosts.rhel7:
        user_clients_upgrade(old_repo, clients, agent)
    elif settings.upgrade.docker_vm:
        execute(
            docker_clients_upgrade,
            old_repo,
            clients,
            agent,
            host=docker_vm
        )
        # Fetching katello-agent version post upgrade from all clients
        # Giving 5 minutes for docker clients to upgrade katello-agent
        time.sleep(300)
        client_vers = execute(
            docker_clients_agent_version,
            clients,
            agent,
            host=docker_vm
        )[docker_vm]
        for hostname, version in tuple(client_vers.items()):
            logger.highlight(f'The {agent} on client {hostname} upgraded to version {version}')
コード例 #16
0
def satellite6_capsule_zstream_upgrade(cap_host):
    """Upgrades Capsule to its latest zStream version

    :param string cap_host: Capsule hostname onto which the capsule upgrade
    will run

    Note: For zstream upgrade both 'To' and 'From' version should be same

    FROM_VERSION
        Current satellite version which will be upgraded to latest version
    TO_VERSION
        Next satellite version to which satellite will be upgraded
    """
    logger.highlight('\n========== CAPSULE UPGRADE =================\n')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    if not from_version == to_version:
        logger.warning('zStream Upgrade on Capsule cannot be performed as '
                       'FROM and TO versions are not same!')
        sys.exit(1)
    major_ver = distro_info()[1]
    if os.environ.get('CAPSULE_URL'):
        disable_old_repos('rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
            major_ver, from_version))
    # Check what repos are set
    run('yum repolist')
    if from_version == '6.0':
        # Stop katello services, except mongod
        run('for i in qpidd pulp_workers pulp_celerybeat '
            'pulp_resource_manager httpd; do service $i stop; done')
    else:
        # Stop katello services
        run('katello-service stop')
    run('yum clean all', warn_only=True)
    logger.info('Updating system and capsule packages ... ')
    preyum_time = datetime.now().replace(microsecond=0)
    update_packages(quiet=False)
    postyum_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for capsule packages update - {}'.format(
        str(postyum_time - preyum_time)))
    setup_capsule_firewall()
    preup_time = datetime.now().replace(microsecond=0)
    if to_version == '6.0':
        run('katello-installer --upgrade')
    elif to_version == '6.1':
        run('capsule-installer --upgrade')
    else:
        run('satellite-installer --scenario capsule --upgrade ')
    postup_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for Capsule Upgrade - {}'.format(
        str(postup_time - preup_time)))
    # Rebooting the capsule for kernel update if any
    reboot(160)
    host_ssh_availability_check(cap_host)
    # Check if Capsule upgrade is success
    run('katello-service status', warn_only=True)
コード例 #17
0
def check_upgrade_compatibility(upgrade_type, base_version, target_version):
    """
    Use to check the setup is compatible with the selected version or not.
    :param upgrade_type: Upgrade type could be satellite, capsule.
    :param base_version: base version of the satellite, capsule.
    :param target_version: target version of the satellite or capsule.
    """
    if base_version:
        if LooseVersion(target_version) > LooseVersion(base_version):
            logger.highlight(f'The {upgrade_type} is upgraded from {base_version}'
                             f' to {target_version}')
        else:
            logger.highlight(
                f'The {upgrade_type} is NOT upgraded to next version. Now its {target_version}')
    else:
        logger.highlight(
            f'Unable to fetch previous version from {upgrade_type} but after upgrade capsule'
            f' is {target_version}.')
コード例 #18
0
ファイル: capsule.py プロジェクト: lpramuk/satellite6-upgrade
def satellite_capsule_upgrade(cap_host, sat_host):
    """Upgrades capsule from existing version to latest version.

    :param string cap_host: Capsule hostname onto which the capsule upgrade
    will run
    :param string sat_host : Satellite hostname from which capsule certs are to
    be generated

    The following environment variables affect this command:

    CAPSULE_URL
        Optional, defaults to available capsule version in CDN.
        URL for capsule of latest compose to upgrade.
    FROM_VERSION
        Capsule current version, to disable repos while upgrading.
        e.g '6.1','6.0'
    TO_VERSION
        Capsule version to upgrade to and enable repos while upgrading.
        e.g '6.1','6.2'

    """
    logger.highlight('\n========== CAPSULE UPGRADE =================\n')
    # Check the capsule sync before upgrade.
    logger.info("Check the capsule sync after satellite upgrade to verify sync operation "
                "with n-1 combination")
    execute(capsule_sync, cap_host, host=sat_host)
    wait_untill_capsule_sync(cap_host)
    from_version = settings.upgrade.from_version
    to_version = settings.upgrade.to_version
    setup_capsule_firewall()
    major_ver = settings.upgrade.os[-1]
    ak_name = settings.upgrade.capsule_ak[settings.upgrade.os]
    run(f'subscription-manager register --org="Default_Organization" '
        f'--activationkey={ak_name} --force')
    logger.info(f"Activation key {ak_name} registered capsule's all available repository")
    run("subscription-manager repos --list")
    maintenance_repo = [RHEL_CONTENTS["maintenance"]["label"]]
    capsule_repos = [
        RHEL_CONTENTS["tools"]["label"],
        RHEL_CONTENTS["capsule"]["label"],
    ]
    with fabric_settings(warn_only=True):
        if settings.upgrade.distribution == "cdn":
            enable_disable_repo(enable_repos_name=capsule_repos + maintenance_repo)
        else:
            enable_disable_repo(disable_repos_name=maintenance_repo)

    if from_version != to_version:
        with fabric_settings(warn_only=True):
            enable_disable_repo(disable_repos_name=capsule_repos)
    with fabric_settings(warn_only=True):
        enable_disable_repo(enable_repos_name=[
            f"rhel-{major_ver}-server-ansible-{settings.upgrade.ansible_repo_version}-rpms"])

    if settings.upgrade.foreman_maintain_capsule_upgrade:
        foreman_maintain_package_update()
        if settings.upgrade.from_version == '6.10':
            # capsule certs regeneration required prior 6.11 ystream capsule upgrade BZ#2049893
            execute(capsule_certs_update, cap_host, host=sat_host)
        upgrade_using_foreman_maintain(sat_host=False)
    else:
        nonfm_upgrade(satellite_upgrade=False,
                      cap_host=cap_host,
                      sat_host=sat_host)
    # Rebooting the capsule for kernel update if any
    reboot(160)
    host_ssh_availability_check(cap_host)
    # Check if Capsule upgrade is success
    upgrade_validation(upgrade_type="capsule", satellite_services_action="restart")
    # Check the capsule sync after upgrade.
    logger.info("check the capsule sync after capsule upgrade")
    execute(capsule_sync, cap_host, host=sat_host)
    wait_untill_capsule_sync(cap_host)
コード例 #19
0
def satellite_upgrade(zstream=False):
    """This function is used to perform the satellite upgrade of two type based on
    their passed parameter.
    :param zstream:

    if upgrade_type==None:
        - Upgrades Satellite Server from old version to latest
            The following environment variables affect this command:

            SAT_UPGRADE_BASE_URL
                Optional, defaults to available satellite version in CDN.
                URL for the compose repository
            FROM_VERSION
                Current satellite version which will be upgraded to latest version
            TO_VERSION
                Satellite version to upgrade to and enable repos while upgrading.
                e.g '6.1','6.2', '6.3'
            FOREMAN_MAINTAIN_SATELLITE_UPGRADE
                use foreman-maintain for satellite upgrade

    else:
        - Upgrades Satellite Server to its latest zStream version
            Note: For zstream upgrade both 'To' and 'From' version should be same

            FROM_VERSION
                Current satellite version which will be upgraded to latest version
            TO_VERSION
                Next satellite version to which satellite will be upgraded
            FOREMAN_MAINTAIN_SATELLITE_UPGRADE
                use foreman-maintain for satellite upgrade

    """
    logger.highlight('\n========== SATELLITE UPGRADE =================\n')
    if zstream:
        if not settings.upgrade.from_version == settings.upgrade.to_version:
            logger.highlight('zStream Upgrade on Satellite cannot be performed as FROM and TO'
                             ' versions are not same. Aborting...')
            sys.exit(1)
    major_ver = settings.upgrade.os[-1]
    common_sat_cap_repos = [
        RHEL_CONTENTS["rhscl"]["label"],
        RHEL_CONTENTS["server"]["label"]
    ]

    # disable all the repos
    enable_disable_repo(disable_repos_name=["*"])

    if settings.upgrade.downstream_fm_upgrade or settings.upgrade.to_version == "6.11":
        settings.upgrade.whitelist_param = ", repositories-validate, repositories-setup"
        enable_disable_repo(enable_repos_name=common_sat_cap_repos)
    # maintenance repository update for satellite upgrade
    maintenance_repo_update()

    # It is required to enable the tools and server for non-fm upgrade because in
    # fm both the repos enabled by the fm tool.
    if not settings.upgrade.foreman_maintain_satellite_upgrade:
        enable_disable_repo(enable_repos_name=common_sat_cap_repos)
    if settings.upgrade.distribution == 'cdn':
        enable_disable_repo(
            enable_repos_name=[f'rhel-{major_ver}-server-satellite-maintenance-6-rpms']
        )
    else:
        for repo in CUSTOM_SAT_REPO:
            if float(settings.upgrade.to_version) >= 6.11 and repo == "sattools":
                continue
            if float(settings.upgrade.to_version) < 6.11 and \
                    (repo == "satutils" or repo == "satclient"):
                continue
            repository_setup(
                CUSTOM_SAT_REPO[repo]["repository"],
                CUSTOM_SAT_REPO[repo]["repository_name"],
                CUSTOM_SAT_REPO[repo]["base_url"],
                CUSTOM_SAT_REPO[repo]["enable"],
                CUSTOM_SAT_REPO[repo]["gpg"]
            )
        foreman_maintain_package_update()

    if settings.upgrade.from_version == '6.9':
        # To fix the memory related issues for BZ#1989378
        post_migration_failure_fix(100001)
        pulp_migration_status = pulp2_pulp3_migration()
        if not pulp_migration_status:
            logger.highlight("Pulp migration failed. Aborting")
            sys.exit(1)
    if settings.upgrade.foreman_maintain_satellite_upgrade:
        upgrade_using_foreman_maintain()
    else:
        # To install the package using foreman-maintain and it is applicable
        # above 6.7 version.
        setup_satellite_firewall()
        if not zstream:
            run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
            logger.info('Updating system packages ... ')
            foreman_packages_installation_check(state="unlock")
            setup_satellite_repo()
            foreman_maintain_package_update()
            update_packages(quiet=True)

        if settings.upgrade.distribution == "cdn":
            enable_disable_repo(enable_repos_name=[f'rhel-{major_ver}-server-satellite'
                                                   f'-{settings.upgrade.to_version}-rpms'])
        nonfm_upgrade()
        foreman_packages_installation_check(state="lock")
    # Rebooting the satellite for kernel update if any
    if settings.upgrade.satellite_capsule_setup_reboot:
        reboot(180)
    host_ssh_availability_check(env.get('satellite_host'))
    # Test the Upgrade is successful
    upgrade_validation()
    if settings.upgrade.mongodb_upgrade:
        mongo_db_engine_upgrade()
    if settings.upgrade.satellite_backup:
        satellite_backup()
コード例 #20
0
def satellite6_upgrade(zstream=False):
    """This function is used to perform the satellite upgrade of two type based on
    their passed parameter.
    :param zstream:

    if upgrade_type==None:
        - Upgrades Satellite Server from old version to latest
            The following environment variables affect this command:

            BASE_URL
                Optional, defaults to available satellite version in CDN.
                URL for the compose repository
            FROM_VERSION
                Current satellite version which will be upgraded to latest version
            TO_VERSION
                Satellite version to upgrade to and enable repos while upgrading.
                e.g '6.1','6.2', '6.3'
            FOREMAN_MAINTAIN_SATELLITE_UPGRADE
                use foreman-maintain for satellite upgrade

    else:
        - Upgrades Satellite Server to its latest zStream version
            Note: For zstream upgrade both 'To' and 'From' version should be same

            FROM_VERSION
                Current satellite version which will be upgraded to latest version
            TO_VERSION
                Next satellite version to which satellite will be upgraded
            FOREMAN_MAINTAIN_SATELLITE_UPGRADE
                use foreman-maintain for satellite upgrade

    """
    logger.highlight('\n========== SATELLITE UPGRADE =================\n')
    to_version = os.environ.get('TO_VERSION')
    from_version = os.environ.get('FROM_VERSION')
    if zstream:
        if not from_version == to_version:
            logger.warning(
                'zStream Upgrade on Satellite cannot be performed as '
                'FROM and TO versions are not same!')
            sys.exit(1)
    base_url = None if not os.environ.get('BASE_URL') else os.environ.get(
        'BASE_URL')
    major_ver = distro_info()[1]
    disable_repo_name = ["*"]
    enable_repos_name = [
        'rhel-{0}-server-rpms'.format(major_ver),
        'rhel-server-rhscl-{0}-rpms'.format(major_ver)
    ]

    if bz_bug_is_open(1850934):
        run('echo "apache::mod::proxy::proxy_timeout: 120" >> '
            '/etc/foreman-installer/custom-hiera.yaml')

    # This statement will execute only until downstream release not become beta.
    if os.environ.get('DOWNSTREAM_FM_UPGRADE') == 'true' or \
            os.environ.get('FOREMAN_MAINTAIN_SATELLITE_UPGRADE') == 'false':
        # Following disables the old satellite repo and extra repos enabled
        # during subscribe e.g Load balancer Repo

        enable_disable_repo(disable_repo_name, enable_repos_name)
        os.environ[
            "whitelisted_param"] = ", repositories-validate, repositories-setup"
    else:
        os.environ["whitelisted_param"] = ''

    if os.environ.get('FOREMAN_MAINTAIN_SATELLITE_UPGRADE') == 'true' \
            and os.environ.get('OS') == 'rhel7':
        foreman_maintain_upgrade(base_url)
    else:
        # To install the package using foreman-maintain and it is applicable
        # above 6.7 version.
        setup_satellite_firewall()
        if not zstream:
            run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
            logger.info('Updating system packages ... ')
            foreman_packages_installation_check(state="unlock")
            setup_foreman_maintain()
            update_packages(quiet=True)

        if base_url is None:
            enable_disable_repo([], [
                'rhel-{0}-server-satellite-{1}-rpms'.format(
                    major_ver, to_version)
            ])
            # Remove old custom sat repo
            repository_cleanup('sat')
        else:
            repository_setup("sat6", "satellite 6", base_url, 1, 0)
        nonfm_upgrade()
        foreman_packages_installation_check(state="lock")
    # Rebooting the satellite for kernel update if any
    reboot(180)
    host_ssh_availability_check(env.get('satellite_host'))
    # Test the Upgrade is successful
    upgrade_validation(True)
コード例 #21
0
def satellite6_upgrade():
    """Upgrades satellite from old version to latest version.

    The following environment variables affect this command:

    BASE_URL
        Optional, defaults to available satellite version in CDN.
        URL for the compose repository
    TO_VERSION
        Satellite version to upgrade to and enable repos while upgrading.
        e.g '6.1','6.2', '6.3'
    PERFORM_FOREMAN_MAINTAIN_UPGRADE
        use foreman-maintain for satellite upgrade
    """
    logger.highlight('\n========== SATELLITE UPGRADE =================\n')
    to_version = os.environ.get('TO_VERSION')
    base_url = os.environ.get('BASE_URL')
    if to_version not in ['6.1', '6.2', '6.3', '6.4', '6.5']:
        logger.warning('Wrong Satellite Version Provided to upgrade to. '
                       'Provide one of 6.1, 6.2, 6.3, 6.4, 6.5')
        sys.exit(1)
    major_ver = distro_info()[1]
    # remove once BZ 1644354 fixed
    run("yum erase ant-junit -y")
    if os.environ.get('PERFORM_FOREMAN_MAINTAIN_UPGRADE') == 'true' \
            and os.environ.get('OS') == 'rhel7':
        if base_url is None:
            os.environ['DISTRIBUTION'] = "CDN"
        else:
            os.environ['DISTRIBUTION'] = "DOWNSTREAM"
        # setup foreman-maintain
        setup_foreman_maintain()
        preup_time = datetime.now().replace(microsecond=0)
        # perform upgrade using foreman-maintain
        upgrade_using_foreman_maintain()
        postup_time = datetime.now().replace(microsecond=0)
        logger.highlight('Time taken for Satellite Upgrade - {}'.format(
            str(postup_time - preup_time)))
    else:
        setup_satellite_firewall()
        run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
        logger.info('Updating system packages ... ')
        # setup foreman-maintain
        setup_foreman_maintain()
        update_packages(quiet=True)
        # Following disables the old satellite repo and extra repos enabled
        # during subscribe e.g Load balancer Repo
        disable_repos('*', silent=True)
        enable_repos('rhel-{0}-server-rpms'.format(major_ver))
        enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver))
        enable_repos('rhel-{0}-server-extras-rpms'.format(major_ver))
        # If CDN upgrade then enable satellite latest version repo
        if base_url is None:
            enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format(
                major_ver, to_version))
            # Remove old custom sat repo
            for fname in os.listdir('/etc/yum.repos.d/'):
                if 'sat' in fname.lower():
                    os.remove('/etc/yum.repos.d/{}'.format(fname))
        # Else, consider this as Downstream upgrade
        else:
            # Add Sat6 repo from latest compose
            satellite_repo = StringIO()
            satellite_repo.write('[sat6]\n')
            satellite_repo.write('name=satellite 6\n')
            satellite_repo.write('baseurl={0}\n'.format(base_url))
            satellite_repo.write('enabled=1\n')
            satellite_repo.write('gpgcheck=0\n')
            put(local_path=satellite_repo,
                remote_path='/etc/yum.repos.d/sat6.repo')
            satellite_repo.close()
        # Check what repos are set
        run('yum repolist')
        # Stop katello services, except mongod
        run('katello-service stop')
        if to_version == '6.1':
            run('service-wait mongod start')
        run('yum clean all', warn_only=True)
        # Updating the packages again after setting sat6 repo
        logger.info('Updating satellite packages ... ')
        preyum_time = datetime.now().replace(microsecond=0)
        update_packages(quiet=False)
        postyum_time = datetime.now().replace(microsecond=0)
        logger.highlight('Time taken for satellite packages update- {}'.format(
            str(postyum_time - preyum_time)))
        # Running Upgrade
        preup_time = datetime.now().replace(microsecond=0)
        if to_version == '6.1':
            run('katello-installer --upgrade')
        else:
            run('satellite-installer --scenario satellite --upgrade')
        postup_time = datetime.now().replace(microsecond=0)
        logger.highlight('Time taken for Satellite Upgrade - {}'.format(
            str(postup_time - preup_time)))
    # Rebooting the satellite for kernel update if any
    reboot(180)
    host_ssh_availability_check(env.get('satellite_host'))
    # Test the Upgrade is successful
    run('hammer ping', warn_only=True)
    run('katello-service status', warn_only=True)
    # Enable ostree feature only for rhel7 and sat6.2
    if to_version == '6.2' and major_ver == 7:
        enable_ostree(sat_version='6.2')
コード例 #22
0
def satellite6_upgrade(zstream=False):
    """This function is used to perform the satellite upgrade of two type based on
    their passed parameter.
    :param zstream:

    if upgrade_type==None:
        - Upgrades Satellite Server from old version to latest
            The following environment variables affect this command:

            BASE_URL
                Optional, defaults to available satellite version in CDN.
                URL for the compose repository
            FROM_VERSION
                Current satellite version which will be upgraded to latest version
            TO_VERSION
                Satellite version to upgrade to and enable repos while upgrading.
                e.g '6.1','6.2', '6.3'
            PERFORM_FOREMAN_MAINTAIN_UPGRADE
                use foreman-maintain for satellite upgrade

    else:
        - Upgrades Satellite Server to its latest zStream version
            Note: For zstream upgrade both 'To' and 'From' version should be same

            FROM_VERSION
                Current satellite version which will be upgraded to latest version
            TO_VERSION
                Next satellite version to which satellite will be upgraded
            PERFORM_FOREMAN_MAINTAIN_UPGRADE
                use foreman-maintain for satellite upgrade

    """
    logger.highlight('\n========== SATELLITE UPGRADE =================\n')
    to_version = os.environ.get('TO_VERSION')
    from_version = os.environ.get('FROM_VERSION')
    if zstream:
        if not from_version == to_version:
            logger.warning(
                'zStream Upgrade on Satellite cannot be performed as '
                'FROM and TO versions are not same!')
            sys.exit(1)
    base_url = os.environ.get('BASE_URL')
    major_ver = distro_info()[1]
    disable_repo_name = ["*"]
    enable_repos_name = [
        'rhel-{0}-server-rpms'.format(major_ver),
        'rhel-server-rhscl-{0}-rpms'.format(major_ver)
    ]
    if os.environ.get('PERFORM_FOREMAN_MAINTAIN_UPGRADE') == 'true' \
            and os.environ.get('OS') == 'rhel7':
        foreman_maintain_upgrade(base_url)
    else:
        setup_satellite_firewall()
        if not zstream:
            run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
            logger.info('Updating system packages ... ')
            setup_foreman_maintain()
            update_packages(quiet=True)
        # Following disables the old satellite repo and extra repos enabled
        # during subscribe e.g Load balancer Repo
        enable_disable_repo(disable_repo_name, enable_repos_name)
        if base_url is None:
            enable_disable_repo([], [
                'rhel-{0}-server-satellite-{1}-rpms'.format(
                    major_ver, to_version)
            ])
            # Remove old custom sat repo
            repository_cleanup('sat')
        else:
            repository_setup("sat6", "satellite 6", base_url, 1, 0)
        nonfm_upgrade()
    # Rebooting the satellite for kernel update if any
    reboot(180)
    host_ssh_availability_check(env.get('satellite_host'))
    # Test the Upgrade is successful
    upgrade_validation(True)
コード例 #23
0
def satellite6_zstream_upgrade():
    """Upgrades Satellite Server to its latest zStream version

    Note: For zstream upgrade both 'To' and 'From' version should be same

    FROM_VERSION
        Current satellite version which will be upgraded to latest version
    TO_VERSION
        Next satellite version to which satellite will be upgraded
    PERFORM_FOREMAN_MAINTAIN_UPGRADE
        use foreman-maintain for satellite upgrade
    """
    logger.highlight('\n========== SATELLITE UPGRADE =================\n')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    if not from_version == to_version:
        logger.warning('zStream Upgrade on Satellite cannot be performed as '
                       'FROM and TO versions are not same!')
        sys.exit(1)
    base_url = os.environ.get('BASE_URL')
    major_ver = distro_info()[1]
    # remove once BZ 1644354 fixed
    run("yum erase ant-junit -y")
    if os.environ.get('PERFORM_FOREMAN_MAINTAIN_UPGRADE') == "true" \
            and os.environ.get('OS') == 'rhel7':
        if base_url is None:
            os.environ['DISTRIBUTION'] = "CDN"
        else:
            os.environ['DISTRIBUTION'] = "DOWNSTREAM"
        # setup foreman-maintain
        setup_foreman_maintain()
        preup_time = datetime.now().replace(microsecond=0)
        # perform upgrade using foreman-maintain
        upgrade_using_foreman_maintain()
        postup_time = datetime.now().replace(microsecond=0)
        logger.highlight('Time taken for Satellite Upgrade - {}'.format(
            str(postup_time - preup_time)))
    else:
        setup_satellite_firewall()
        # Following disables the old satellite repo and extra repos enabled
        # during subscribe e.g Load balancer Repo
        disable_repos('*', silent=True)
        enable_repos('rhel-{0}-server-rpms'.format(major_ver))
        enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver))
        enable_repos('rhel-{0}-server-extras-rpms'.format(major_ver))
        # If CDN upgrade then enable satellite latest version repo
        if base_url is None:
            enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format(
                major_ver, to_version))
            # Remove old custom sat repo
            for fname in os.listdir('/etc/yum.repos.d/'):
                if 'sat' in fname.lower():
                    os.remove('/etc/yum.repos.d/{}'.format(fname))
        # Else, consider this as Downstream upgrade
        else:
            # Add Sat6 repo from latest compose
            satellite_repo = StringIO()
            satellite_repo.write('[sat6]\n')
            satellite_repo.write('name=satellite 6\n')
            satellite_repo.write('baseurl={0}\n'.format(base_url))
            satellite_repo.write('enabled=1\n')
            satellite_repo.write('gpgcheck=0\n')
            put(local_path=satellite_repo,
                remote_path='/etc/yum.repos.d/sat6.repo')
            satellite_repo.close()
        # Check what repos are set
        run('yum repolist')
        # Stop katello services, except mongod
        run('katello-service stop')
        if to_version == '6.1':
            run('service-wait mongod start')
        run('yum clean all', warn_only=True)
        # Updating the packages again after setting sat6 repo
        logger.info('Updating system and satellite packages... ')
        preyum_time = datetime.now().replace(microsecond=0)
        update_packages(quiet=False)
        postyum_time = datetime.now().replace(microsecond=0)
        logger.highlight('Time taken for system and satellite packages update'
                         ' - {}'.format(str(postyum_time - preyum_time)))
        # Running Upgrade
        preup_time = datetime.now().replace(microsecond=0)
        if to_version == '6.1':
            run('katello-installer --upgrade')
        else:
            run('satellite-installer --scenario satellite --upgrade')
        postup_time = datetime.now().replace(microsecond=0)
        logger.highlight('Time taken for Satellite Upgrade - {}'.format(
            str(postup_time - preup_time)))
    # Rebooting the satellite for kernel update if any
    reboot(180)
    host_ssh_availability_check(env.get('satellite_host'))
    # Test the Upgrade is successful
    run('hammer ping', warn_only=True)
    run('katello-service status', warn_only=True)
コード例 #24
0
def product_upgrade(product):
    """Task which upgrades the product.

    Product is satellite or capsule or client or longrun.
    If product is satellite then upgrade only satellite
    If product is capsule then upgrade satellite and capsule
    If product is client then upgrade satellite and client
    If product is longrun then upgrade satellite, capsule and client
    If product is n-1 then upgrades only satellite by keeping capsule at last
    z-stream released version

    :param string product: product name wanted to upgrade.

    Environment Variables necessary to proceed Upgrade:
    -----------------------------------------------------

    FROM_VERSION
        The satellite/capsule current version to upgrade to latest.
        e.g '6.1','6.0'
    TO_VERSION
        To which Satellite/Capsule version to upgrade.
        e.g '6.1','6.2'
    OS
        The OS Version on which the satellite is installed.
        e.g 'rhel7','rhel6'

    Environment variables populated from jenkins:
    ------------------------------------------------------

    RHN_USERNAME
        Red Hat Network username to register the system.
    RHN_PASSWORD
        Red Hat Network password to register the system.
    RHN_POOLID
        Optional. Red Hat Network pool ID. Determines what software will be
        available from RHN
    BASE_URL
        URL for the compose repository.
    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
        If CDN, defaults to latest available capsule version
    TOOLS_URL_RHEL6
        The url for rhel6 tools repo from latest satellite compose
        If CDN, defaults to latest available tools version
    TOOLS_URL_RHEL7
        The url for rhel7 tools repo from latest satellite compose
        If CDN, defaults to latest available tools version

    Environment variables required to run upgrade on user's own setup:
    --------------------------------------------------------------------

    SATELLITE_HOSTNAME
        The Satellite hostname to run upgrade on
    CAPSULE_HOSTNAME
        The Satellite hostname to run upgrade on
    CLIENT6_HOSTS
        The RHEL6 clients hostnames to run upgrade on
    CLIENT7_HOSTS
        The RHEL7 clients hostnames to run upgrade on.
    CAPSULE_AK
        Activation Key name attached to the subscription of capsule
    CLIENT_AK
        Activation Key name attached to the subscription of client

    Environment variables required to run upgrade on RHEVM Setup and will be
    fetched from Jenkins:
    ----------------------------------------------------------------------

    RHEV_SAT_IMAGE
        The satellite Image from which satellite instance will be created
    RHEV_SAT_HOST
        The rhevm satellite hostname to run upgrade on
    RHEV_CAP_IMAGE
        The capsule Image from which capsule instance will be created
    RHEV_CAP_HOST
        The rhevm capsule hostname to run upgrade on
    DOCKER_VM
        The Docker VM IP/Hostname on rhevm to create and upgrade clients
    CLIENTS_COUNT
        The number of clients(docker containers) to generate to run upgrade
    RHEV_CAPSULE_AK
        The AK name used in capsule subscription
    RHEV_CLIENT_AK
        The AK name used in client subscription
    """
    if check_necessary_env_variables_for_upgrade(product):
        from_version = os.environ.get('FROM_VERSION')
        to_version = os.environ.get('TO_VERSION')
        logger.info('Performing UPGRADE FROM {0} TO {1}'.format(
            from_version, to_version))
        # Get the setup dict returned by setup_products_for_upgrade
        setup_dict = get_setup_data()
        sat_host = setup_dict['sat_host']
        env['satellite_host'] = sat_host
        try:
            with LogAnalyzer(sat_host):
                current = execute(
                    get_sat_cap_version, 'sat', host=sat_host)[sat_host]
                if from_version != to_version:
                    execute(satellite6_upgrade, host=sat_host)
                else:
                    execute(satellite6_zstream_upgrade, host=sat_host)
                upgraded = execute(
                    get_sat_cap_version, 'sat', host=sat_host)[sat_host]
                if LooseVersion(upgraded) > LooseVersion(current):
                    logger.highlight(
                        'The Satellite is upgraded from {0} to {1}'.format(
                            current, upgraded))
                else:
                    logger.highlight(
                        'The Satellite is NOT upgraded to next version. Now '
                        'its {}'.format(upgraded))
                # Generate foreman debug on satellite after upgrade
                execute(foreman_debug, 'satellite_{}'.format(sat_host),
                        host=sat_host)
                # Execute tasks as post upgrade tier1 tests are dependent
                post_upgrade_test_tasks(sat_host)
                if product == 'capsule' or product == 'longrun':
                    cap_hosts = setup_dict['capsule_hosts']
                    for cap_host in cap_hosts:
                        try:
                            with LogAnalyzer(cap_host):
                                current = execute(
                                    get_sat_cap_version, 'cap', host=cap_host
                                    )[cap_host]
                                if from_version != to_version:
                                    execute(satellite6_capsule_upgrade,
                                            cap_host, sat_host, host=cap_host)
                                elif from_version == to_version:
                                    execute(satellite6_capsule_zstream_upgrade,
                                            host=cap_host)
                                upgraded = execute(
                                    get_sat_cap_version, 'cap', host=cap_host
                                    )[cap_host]
                                if current:
                                    if LooseVersion(upgraded) > LooseVersion(
                                            current):
                                        logger.highlight(
                                            'The Capsule is upgraded from {0} '
                                            'to {1}.'.format(current, upgraded)
                                        )
                                    else:
                                        logger.highlight(
                                            'The Capsule is NOT upgraded to '
                                            'next version. Now its {}'.format(
                                                upgraded))
                                else:
                                    logger.highlight(
                                        'Unable to fetch previous version but '
                                        'after upgrade capsule is {}.'.format(
                                            upgraded))
                                # Generate foreman debug on capsule postupgrade
                                execute(
                                    foreman_debug,
                                    'capsule_{}'.format(cap_host),
                                    host=cap_host)
                        except Exception:
                            # Generate foreman debug on failed capsule upgrade
                            execute(
                                foreman_debug, 'capsule_{}'.format(cap_host),
                                host=cap_host)
                            raise
                if product == 'client' or product == 'longrun':
                    clients6 = setup_dict['clients6']
                    clients7 = setup_dict['clients7']
                    satellite6_client_upgrade('rhel6', clients6)
                    satellite6_client_upgrade('rhel7', clients7)
        except Exception:
            # Generate foreman debug on failed satellite upgrade
            execute(foreman_debug, 'satellite_{}'.format(sat_host),
                    host=sat_host)
            raise
コード例 #25
0
def satellite6_capsule_upgrade(cap_host, sat_host):
    """Upgrades capsule from existing version to latest version.

    :param string cap_host: Capsule hostname onto which the capsule upgrade
    will run
    :param string sat_host : Satellite hostname from which capsule certs are to
    be generated

    The following environment variables affect this command:

    CAPSULE_URL
        Optional, defaults to available capsule version in CDN.
        URL for capsule of latest compose to upgrade.
    FROM_VERSION
        Capsule current version, to disable repos while upgrading.
        e.g '6.1','6.0'
    TO_VERSION
        Capsule version to upgrade to and enable repos while upgrading.
        e.g '6.1','6.2'

    """
    logger.highlight('\n========== CAPSULE UPGRADE =================\n')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    setup_capsule_firewall()
    major_ver = distro_info()[1]
    # Re-register Capsule for 6.2 and 6.3
    # AS per host unification feature: if there is a host registered where the
    # Host and Content Host are in different organizations (e.g. host not in
    # org, and content host in one), the content host will be unregistered as
    # part of the upgrade process.
    if to_version in ['6.2', '6.3', '6.4']:
        ak_name = os.environ.get('CAPSULE_AK') if os.environ.get(
            'CAPSULE_AK') else os.environ.get('RHEV_CAPSULE_AK')
        run('subscription-manager register --org="Default_Organization" '
            '--activationkey={0} --force'.format(ak_name))
    disable_old_repos('rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
        major_ver, from_version))
    if from_version == '6.1' and major_ver == '6':
        enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver))
    # setup foreman-maintain
    setup_foreman_maintain() if to_version in ['6.4'] else None
    # Check what repos are set
    run('yum repolist')
    if from_version == '6.0':
        # Stop katello services, except mongod
        run('for i in qpidd pulp_workers pulp_celerybeat '
            'pulp_resource_manager httpd; do service $i stop; done')
    else:
        # Stop katello services
        run('katello-service stop')
    run('yum clean all', warn_only=True)
    logger.info('Updating system and capsule packages ... ')
    preyum_time = datetime.now().replace(microsecond=0)
    update_packages(quiet=False)
    postyum_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for capsule packages update - {}'.format(
        str(postyum_time - preyum_time)))
    if from_version == '6.0':
        run('yum install -y capsule-installer', warn_only=True)
        # Copy answer file from katello to capule installer
        run(
            'cp /etc/katello-installer/answers.capsule-installer.yaml.rpmsave '
            '/etc/capsule-installer/answers.capsule-installer.yaml',
            warn_only=True)
    execute(generate_capsule_certs, cap_host, True, host=sat_host)
    # Copying the capsule cert to capsule
    execute(lambda: run("scp -o 'StrictHostKeyChecking no' {0}-certs.tar "
                        "root@{0}:/home/".format(cap_host)),
            host=sat_host)
    setup_capsule_firewall()
    preup_time = datetime.now().replace(microsecond=0)
    if to_version == '6.1':
        run('capsule-installer --upgrade --certs-tar '
            '/home/{0}-certs.tar'.format(cap_host))
    elif to_version == '6.3' or to_version == '6.4':
        run('satellite-installer --scenario capsule --upgrade '
            '--certs-tar /home/{0}-certs.tar '
            '--certs-update-all --regenerate true '
            '--deploy true'.format(cap_host))
    else:
        run('satellite-installer --scenario capsule --upgrade '
            '--certs-tar /home/{0}-certs.tar'.format(cap_host))
    postup_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for Capsule Upgrade - {}'.format(
        str(postup_time - preup_time)))
    # Rebooting the capsule for kernel update if any
    reboot(160)
    host_ssh_availability_check(cap_host)
    # Check if Capsule upgrade is success
    run('katello-service status', warn_only=True)
コード例 #26
0
def satellite6_zstream_upgrade():
    """Upgrades Satellite Server to its latest zStream version

    Note: For zstream upgrade both 'To' and 'From' version should be same

    FROM_VERSION
        Current satellite version which will be upgraded to latest version
    TO_VERSION
        Next satellite version to which satellite will be upgraded
    """
    logger.highlight('\n========== SATELLITE UPGRADE =================\n')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    if not from_version == to_version:
        logger.warning('zStream Upgrade on Satellite cannot be performed as '
                       'FROM and TO versions are not same!')
        sys.exit(1)
    base_url = os.environ.get('BASE_URL')
    setup_satellite_firewall()
    major_ver = distro_info()[1]
    # Following disables the old satellite repo and extra repos enabled
    # during subscribe e.g Load balancer Repo
    disable_repos('*', silent=True)
    enable_repos('rhel-{0}-server-rpms'.format(major_ver))
    enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver))
    # If CDN upgrade then enable satellite latest version repo
    if base_url is None:
        enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format(
            major_ver, to_version))
        # Remove old custom sat repo
        for fname in os.listdir('/etc/yum.repos.d/'):
            if 'sat' in fname.lower():
                os.remove('/etc/yum.repos.d/{}'.format(fname))
    # Else, consider this as Downstream upgrade
    else:
        # Add Sat6 repo from latest compose
        satellite_repo = StringIO()
        satellite_repo.write('[sat6]\n')
        satellite_repo.write('name=satellite 6\n')
        satellite_repo.write('baseurl={0}\n'.format(base_url))
        satellite_repo.write('enabled=1\n')
        satellite_repo.write('gpgcheck=0\n')
        put(local_path=satellite_repo,
            remote_path='/etc/yum.repos.d/sat6.repo')
        satellite_repo.close()
    # Check what repos are set
    run('yum repolist')
    # Stop katello services, except mongod
    run('katello-service stop')
    if to_version == '6.1':
        run('service-wait mongod start')
    run('yum clean all', warn_only=True)
    # Updating the packages again after setting sat6 repo
    logger.info('Updating system and satellite packages... ')
    preyum_time = datetime.now().replace(microsecond=0)
    update_packages(quiet=False)
    postyum_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for system and satellite packages update - '
                     '{}'.format(str(postyum_time - preyum_time)))
    # Rebooting the system to check the possible issues if kernal is updated
    if os.environ.get('RHEV_SAT_HOST'):
        reboot(120)
        if to_version == '6.1':
            # Stop the service again which started in restart
            # This step is not required with 6.2 upgrade as installer itself
            # stop all the services before upgrade
            run('katello-service stop')
            run('service-wait mongod start')
    # Running Upgrade
    preup_time = datetime.now().replace(microsecond=0)
    if to_version == '6.1':
        run('katello-installer --upgrade')
    else:
        run('satellite-installer --scenario satellite --upgrade')
    postup_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for Satellite Upgrade - {}'.format(
        str(postup_time - preup_time)))
    # Test the Upgrade is successful
    set_hammer_config()
    hammer('ping')
    run('katello-service status', warn_only=True)
    if os.environ.get('RUN_EXISTANCE_TESTS', 'false').lower() == 'true':
        logger.info('Setting up postupgrade datastore for existance tests')
        set_datastore('postupgrade')
コード例 #27
0
def satellite6_upgrade():
    """Upgrades satellite from old version to latest version.

    The following environment variables affect this command:

    BASE_URL
        Optional, defaults to available satellite version in CDN.
        URL for the compose repository
    TO_VERSION
        Satellite version to upgrade to and enable repos while upgrading.
        e.g '6.1','6.2', '6.3'
    """
    logger.highlight('\n========== SATELLITE UPGRADE =================\n')
    to_version = os.environ.get('TO_VERSION')
    rhev_sat_host = os.environ.get('RHEV_SAT_HOST')
    base_url = os.environ.get('BASE_URL')
    if to_version not in ['6.1', '6.2', '6.3']:
        logger.warning('Wrong Satellite Version Provided to upgrade to. '
                       'Provide one of 6.1, 6.2, 6.3')
        sys.exit(1)
    setup_satellite_firewall()
    run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
    logger.info('Updating system packages ... ')
    update_packages(quiet=True)
    # Rebooting the system to see possible errors
    if rhev_sat_host:
        reboot(160)
    # Setting Satellite to_version Repos
    major_ver = distro_info()[1]
    # Following disables the old satellite repo and extra repos enabled
    # during subscribe e.g Load balancer Repo
    disable_repos('*', silent=True)
    enable_repos('rhel-{0}-server-rpms'.format(major_ver))
    enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver))
    # If CDN upgrade then enable satellite latest version repo
    if base_url is None:
        enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format(
            major_ver, to_version))
        # Remove old custom sat repo
        for fname in os.listdir('/etc/yum.repos.d/'):
            if 'sat' in fname.lower():
                os.remove('/etc/yum.repos.d/{}'.format(fname))
    # Else, consider this as Downstream upgrade
    else:
        # Add Sat6 repo from latest compose
        satellite_repo = StringIO()
        satellite_repo.write('[sat6]\n')
        satellite_repo.write('name=satellite 6\n')
        satellite_repo.write('baseurl={0}\n'.format(base_url))
        satellite_repo.write('enabled=1\n')
        satellite_repo.write('gpgcheck=0\n')
        put(local_path=satellite_repo,
            remote_path='/etc/yum.repos.d/sat6.repo')
        satellite_repo.close()
    # Check what repos are set
    run('yum repolist')
    # Stop katello services, except mongod
    run('katello-service stop')
    if to_version == '6.1':
        run('service-wait mongod start')
    run('yum clean all', warn_only=True)
    # Updating the packages again after setting sat6 repo
    logger.info('Updating satellite packages ... ')
    preyum_time = datetime.now().replace(microsecond=0)
    update_packages(quiet=False)
    postyum_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for satellite packages update - {}'.format(
        str(postyum_time - preyum_time)))
    # Rebooting the system again for possible errors
    # Only for RHEV based satellite and not for personal one
    if rhev_sat_host:
        reboot(160)
        if to_version == '6.1':
            # Stop the service again which started in restart
            # This step is not required with 6.2 upgrade as installer itself
            # stop all the services before upgrade
            run('katello-service stop')
            run('service-wait mongod start')
    # Running Upgrade
    preup_time = datetime.now().replace(microsecond=0)
    if to_version == '6.1':
        run('katello-installer --upgrade')
    else:
        run('satellite-installer --scenario satellite --upgrade')
    postup_time = datetime.now().replace(microsecond=0)
    logger.highlight('Time taken for Satellite Upgrade - {}'.format(
        str(postup_time - preup_time)))
    # Test the Upgrade is successful
    set_hammer_config()
    hammer('ping')
    run('katello-service status', warn_only=True)
    # Enable ostree feature only for rhel7 and sat6.2
    if to_version == '6.2' and major_ver == 7:
        enable_ostree(sat_version='6.2')
    if os.environ.get('RUN_EXISTANCE_TESTS', 'false').lower() == 'true':
        logger.info('Setting up postupgrade datastore for existance tests..')
        set_datastore('postupgrade')