示例#1
0
def setup_satellite_clone():
    """Task which install satellite-clone tool.

    Environment Variables necessary to proceed Setup:
    -----------------------------------------------------

    DISTRIBUTION
        The satellite upgrade using internal or CDN distribution.
        e.g 'CDN','DOWNSTREAM'

    MAINTAIN_REPO
        URL of repo if distribution is DOWNSTREAM

    BASE_URL
        URL for the compose repository if distribution is DOWNSTREAM
    """
    env.disable_known_hosts = True
    # setting up foreman-maintain repo
    if os.environ.get('DISTRIBUTION') == 'CDN':
        enable_repos('rhel-7-server-satellite-maintenance-6-rpms')
    else:
        repository_setup("maintainrepo", "maintain",
                         "{}".format(os.environ.get('MAINTAIN_REPO')), 1, 0)

    # repolist
    run('yum repolist')
    # install foreman-maintain
    run('yum install satellite-clone -y')
def upgrade_puppet3_to_puppet4():
    """Task which upgrade satellite 6.3 from puppet3 to puppet4.

    Environment Variables necessary to proceed Setup:
    -----------------------------------------------------

    DISTRIBUTION
        The satellite upgrade using internal or CDN distribution.
        e.g 'CDN','DOWNSTREAM'

    PUPPET4_REPO
        URL of puppet4 repo if distribution is DOWNSTREAM
    """
    env.disable_known_hosts = True
    # setting up puppet4 repo
    if os.environ.get('DISTRIBUTION') == 'CDN':
        enable_repos('rhel-7-server-satellite-6.3-puppet4-rpms')
    else:
        satellite_repo = StringIO()
        satellite_repo.write('[Puppet4]\n')
        satellite_repo.write('name=puppet4\n')
        satellite_repo.write('baseurl={0}\n'.format(
            os.environ.get('PUPPET4_REPO')
        ))
        satellite_repo.write('enabled=1\n')
        satellite_repo.write('gpgcheck=0\n')
        put(local_path=satellite_repo,
            remote_path='/etc/yum.repos.d/puppet4.repo')
        satellite_repo.close()

    # repolist
    run('yum repolist')
    # upgrade puppet
    run('satellite-installer --upgrade-puppet')
示例#3
0
def setup_foreman_maintain_repo():
    """Task which setup repo for foreman-maintain.

    Environment Variables necessary to proceed Setup:
    -----------------------------------------------------

    DISTRIBUTION
        The satellite upgrade using internal or CDN distribution.
        e.g 'CDN','DOWNSTREAM'

    MAINTAIN_REPO
        URL of repo if distribution is DOWNSTREAM
    """
    # setting up foreman-maintain repo
    if os.environ.get('DISTRIBUTION') == 'CDN':
        enable_repos('rhel-7-server-satellite-maintenance-6-rpms')
    else:
        maintain_repo = StringIO()
        maintain_repo.write('[foreman-maintain]\n')
        maintain_repo.write('name=foreman-maintain\n')
        maintain_repo.write('baseurl={0}\n'.format(
            os.environ.get('MAINTAIN_REPO')
        ))
        maintain_repo.write('enabled=1\n')
        maintain_repo.write('gpgcheck=0\n')
        put(local_path=maintain_repo,
            remote_path='/etc/yum.repos.d/foreman-maintain.repo')
        maintain_repo.close()
示例#4
0
def upgrade_puppet3_to_puppet4():
    """Task which upgrade satellite 6.3 from puppet3 to puppet4.

    Environment Variables necessary to proceed Setup:
    -----------------------------------------------------

    DISTRIBUTION
        The satellite upgrade using internal or CDN distribution.
        e.g 'CDN','DOWNSTREAM'

    PUPPET4_REPO
        URL of puppet4 repo if distribution is DOWNSTREAM
    """
    env.disable_known_hosts = True
    # setting up puppet4 repo
    if os.environ.get('DISTRIBUTION') == 'CDN':
        enable_repos('rhel-7-server-satellite-6.3-puppet4-rpms')
    else:
        repository_setup("Puppet4", "puppet4",
                         "{}".format(os.environ.get('PUPPET4_REPO')), 1, 0)

    # repolist
    run('yum repolist')
    # upgrade puppet
    run('satellite-installer --upgrade-puppet')
示例#5
0
def satellite6_capsule_zstream_upgrade():
    """Upgrades Capsule 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========== 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]
    set_yum_debug_level()
    if os.environ.get('CAPSULE_URL'):
        disable_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.1' and major_ver == '6':
        enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver))
    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')
    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)))
    # Rebooting the system to see possible errors
    if os.environ.get('RHEV_CAP_HOST'):
        reboot(120)
        if from_version == '6.0':
            # Stopping the services again which started in reboot
            run('for i in qpidd pulp_workers pulp_celerybeat '
                'pulp_resource_manager httpd; do service $i stop; done')
    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)))
    run('katello-service status', warn_only=True)
def setup_foreman_maintain():
    """Task which install foreman-maintain tool.

    Environment Variables necessary to proceed Setup:
    -----------------------------------------------------

    DISTRIBUTION
        The satellite upgrade using internal or CDN distribution.
        e.g 'CDN','DOWNSTREAM'

    MAINTAIN_REPO
        URL of repo if distribution is DOWNSTREAM

    BASE_URL
        URL for the compose repository if distribution is DOWNSTREAM
    """
    env.disable_known_hosts = True
    # setting up foreman-maintain repo
    if os.environ.get('DISTRIBUTION') == 'CDN':
        enable_repos('rhel-7-server-satellite-maintenance-6-rpms')
    else:
        satellite_repo = StringIO()
        satellite_repo.write('[foreman-maintain]\n')
        satellite_repo.write('name=foreman-maintain\n')
        satellite_repo.write('baseurl={0}\n'.format(
            os.environ.get('MAINTAIN_REPO')
        ))
        satellite_repo.write('enabled=1\n')
        satellite_repo.write('gpgcheck=0\n')
        put(local_path=satellite_repo,
            remote_path='/etc/yum.repos.d/foreman-maintain.repo')
        satellite_repo.close()

        # 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(
            os.environ.get('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()

    # repolist
    run('yum repolist')
    # install foreman-maintain
    run('yum install rubygem-foreman_maintain -y')
示例#7
0
def setup_foreman_maintain_repo():
    """Task which setup repo for foreman-maintain.

    Environment Variables necessary to proceed Setup:
    -----------------------------------------------------

    DISTRIBUTION
        The satellite upgrade using internal or CDN distribution.
        e.g 'CDN','DOWNSTREAM'

    MAINTAIN_REPO
        URL of repo if distribution is DOWNSTREAM
    """
    # setting up foreman-maintain repo
    if os.environ.get('DISTRIBUTION') == 'CDN':
        enable_repos('rhel-7-server-satellite-maintenance-6-rpms')
    else:
        repository_setup("foreman-maintain", "foreman-maintain",
                         "{}".format(os.environ.get('MAINTAIN_REPO')), 1, 0)
示例#8
0
def enable_disable_repo(enable_repo_name, disable_repo_name):
    """
    The purpose of this function is to enable and disable the
    repository as per requirements.
    :param list enable_repo_name: This will take the list of
    repository which you are going to enable
    :param list disable_repo_name: This will take the
    list of repository which you are going to disable
    """
    if disable_repo_name:
        [
            disable_repos('{}'.format(repo), silent=True)
            for repo in disable_repo_name
        ]
    if enable_repo_name:
        [enable_repos('{}'.format(repo)) for repo in disable_repo_name]
示例#9
0
def satellite6_upgrade():
    """Upgrades satellite from old version to latest version.

    :param admin_password: A string. Defaults to 'changeme'.
        Foreman admin password for hammer commands.

    The following environment variables affect this command:

    ADMIN_PASSWORD
        Optional, defaults to 'changeme'. Foreman admin password.
    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'
    """
    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']:
        print('Wrong Satellite Version Provided to upgrade to. '
              'Provide one of 6.1, 6.2')
        sys.exit(1)
    # Sync capsule and tools repo
    admin_password = os.environ.get('ADMIN_PASSWORD', 'changeme')
    # Setting yum stdout log level to be less verbose
    set_yum_debug_level()
    # Setup firewall rules on Satellite
    setup_satellite_firewall()
    # Removing rhel-released and rhel-optional repo
    run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
    print('Wait till Packages update ... ')
    update_packages(quiet=True)
    # Rebooting the system to see possible errors
    if rhev_sat_host:
        reboot(120)
    # 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))
    # 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()
    # 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
    print('Wait till packages update ... ')
    print('YUM UPDATE started at: {0}'.format(time.ctime()))
    update_packages(quiet=False)
    print('YUM UPDATE finished at: {0}'.format(time.ctime()))
    # Rebooting the system again for possible errors
    # Only for RHEV based satellite and not for personal one
    if 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')
    # Verifying impact of BZ #1357655 on upgrade
    if rhev_sat_host:
        run('katello-installer --help', quiet=True)
    # Running Upgrade
    print('SATELLITE UPGRADE started at: {0}'.format(time.ctime()))
    if to_version == '6.1':
        run('katello-installer --upgrade')
    else:
        run('satellite-installer --scenario satellite --upgrade')
    print('SATELLITE UPGRADE finished at: {0}'.format(time.ctime()))
    # Test the Upgrade is successful
    run('hammer -u admin -p {0} ping'.format(admin_password), warn_only=True)
    # Test The status of all katello services
    run('katello-service status', warn_only=True)
示例#10
0
def satellite6_capsule_upgrade():
    """Upgrades capsule from existing version to latest version.

    The following environment variables affect this command:

    ADMIN_PASSWORD
        Optional, defaults to 'changeme'. Foreman admin password.
    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'

    """
    sat_host = env.get('satellite_host')
    cap_host = env.get('capsule_host')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    # Setup firewall rules on capsule node
    setup_capsule_firewall()
    # Setting Capsule61 Repos
    major_ver = distro_info()[1]
    # Re-register Capsule for 6.2
    # 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 == '6.2':
        ak_name = os.environ.get('CAPSULE_SUBSCRIPTION').split(',')[2].strip(
            ) if os.environ.get('CAPSULE_SUBSCRIPTION') else os.environ.get(
            'RHEV_CAPSULE_AK')
        run('subscription-manager register --org="Default_Organization" '
            '--activationkey={0} --force'.format(ak_name))
    # if CDN Upgrade enable cdn repo
    if os.environ.get('CAPSULE_URL') is None:
        enable_repos('rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
            major_ver, to_version))
    disable_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))
    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')
    run('yum clean all', warn_only=True)
    print('Wait till packages update ... ')
    print('YUM UPDATE started at: {0}'.format(time.ctime()))
    update_packages(quiet=False)
    print('YUM UPDATE finished at: {0}'.format(time.ctime()))
    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)
    # Generates Capsule Certs file on satelltie and copies in capsule
    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)
    # Rebooting the system to see possible errors
    if os.environ.get('RHEV_CAP_HOST'):
        reboot(120)
        if to_version == '6.1':
            # Stopping the services again which started in reboot
            run('for i in qpidd pulp_workers pulp_celerybeat '
                'pulp_resource_manager httpd; do service $i stop; done')
    # Setting Up firewall rules
    setup_capsule_firewall()
    # Upgrading Katello installer
    print('CAPSULE UPGRADE started at: {0}'.format(time.ctime()))
    if to_version == '6.1':
        run('capsule-installer --upgrade --certs-tar '
            '/home/{0}-certs.tar'.format(cap_host))
    else:
        run('satellite-installer --scenario capsule --upgrade '
            '--certs-tar /home/{0}-certs.tar'.format(cap_host))
    print('CAPSULE UPGRADE finished at: {0}'.format(time.ctime()))
    # Test The status of all katello services
    run('katello-service status', warn_only=True)
示例#11
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'
    """
    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']:
        print('Wrong Satellite Version Provided to upgrade to. '
              'Provide one of 6.1, 6.2')
        sys.exit(1)
    # Setting yum stdout log level to be less verbose
    set_yum_debug_level()
    setup_satellite_firewall()
    run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
    print('Wait till Packages update ... ')
    update_packages(quiet=True)
    # Rebooting the system to see possible errors
    if rhev_sat_host:
        reboot(120)
    # 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))
    # 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()
    # 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
    print('Wait till packages update ... ')
    print('YUM UPDATE started at: {0}'.format(time.ctime()))
    update_packages(quiet=False)
    print('YUM UPDATE finished at: {0}'.format(time.ctime()))
    # Rebooting the system again for possible errors
    # Only for RHEV based satellite and not for personal one
    if 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')
    # Verifying impact of BZ #1357655 on upgrade
    if rhev_sat_host:
        run('katello-installer --help', quiet=True)
    # Running Upgrade
    print('SATELLITE UPGRADE started at: {0}'.format(time.ctime()))
    if to_version == '6.1':
        run('katello-installer --upgrade')
    else:
        run('satellite-installer --scenario satellite --upgrade')
    print('SATELLITE UPGRADE finished at: {0}'.format(time.ctime()))
    # Test the Upgrade is successful
    set_hammer_config()
    hammer('ping')
    run('katello-service status', warn_only=True)
示例#12
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)
示例#13
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')
示例#14
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)
示例#15
0
def satellite6_capsule_upgrade(cap_host):
    """Upgrades capsule from existing version to latest version.

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

    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')
    sat_host = env.get('satellite_host')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    set_yum_debug_level()
    setup_capsule_firewall()
    major_ver = distro_info()[1]
    # Re-register Capsule for 6.2
    # 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 == '6.2':
        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_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))
    # 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')
    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)
    # Rebooting the system to see possible errors
    if os.environ.get('RHEV_CAP_HOST'):
        reboot(120)
        if from_version == '6.0':
            # Stopping the services again which started in reboot
            run('for i in qpidd pulp_workers pulp_celerybeat '
                'pulp_resource_manager httpd; do service $i stop; done')
    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))
    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)))
    run('katello-service status', warn_only=True)
示例#16
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'
    """
    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']:
        logger.warning('Wrong Satellite Version Provided to upgrade to. '
                       'Provide one of 6.1, 6.2')
        sys.exit(1)
    # Setting yum stdout log level to be less verbose
    set_yum_debug_level()
    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')
示例#17
0
def satellite6_capsule_upgrade(admin_password=None):
    """Upgrades capsule from existing version to latest version.

    :param admin_password: A string. Defaults to 'changeme'.
        Foreman admin password for hammer commands.

    The following environment variables affect this command:

    ADMIN_PASSWORD
        Optional, defaults to 'changeme'. Foreman admin password.
    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'

    """
    sat_host = env.get('satellite_host')
    cap_host = env.get('capsule_host')
    from_version = os.environ.get('FROM_VERSION')
    if from_version not in ['6.1', '6.0']:
        print('Wrong Capsule Version Provided. Provide one of 6.1, 6.0.')
        sys.exit(1)
    to_version = os.environ.get('TO_VERSION')
    if to_version not in ['6.1', '6.2']:
        print('Wrong Capsule Version Provided to upgrade to. '
              'Provide one of 6.1, 6.2')
        sys.exit(1)
    if admin_password is None:
        admin_password = os.environ.get('ADMIN_PASSWORD', 'changeme')
    # Setting Capsule61 Repos
    major_ver = distro_info()[1]
    if os.environ.get('CAPSULE_URL') is None:
        enable_repos('rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
            major_ver, to_version))
    disable_repos('rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
        major_ver, from_version))
    # Stop katello services, except mongod
    run('for i in qpidd pulp_workers pulp_celerybeat '
        'pulp_resource_manager httpd; do service $i stop; done')
    run('yum clean all', warn_only=True)
    print('Wait till packages update ... ')
    print('YUM UPDATE started at: {0}'.format(time.ctime()))
    update_packages(quiet=False)
    print('YUM UPDATE finished at: {0}'.format(time.ctime()))
    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)
    # Generates Capsule Certs file on satelltie and copies in capsule
    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)
    # Rebooting the system again to see possible errors
    if os.environ.get('RHEV_CAPSULE'):
        reboot(120)
    # Stopping the services again which started in reboot
    run('for i in qpidd pulp_workers pulp_celerybeat '
        'pulp_resource_manager httpd; do service $i stop; done')
    # Upgrading Katello installer
    print('CAPSULE UPGRADE started at: {0}'.format(time.ctime()))
    if to_version == '6.1':
        run('capsule-installer --upgrade --certs-tar '
            '/home/{0}-certs.tar'.format(cap_host))
    else:
        run('satellite-installer --scenario capsule --upgrade --certs-tar '
            '/home/{0}-certs.tar'.format(cap_host))
    print('CAPSULE UPGRADE finished at: {0}'.format(time.ctime()))
    # Test The status of all katello services
    run('katello-service status', warn_only=True)
示例#18
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')
示例#19
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')
示例#20
0
def satellite6_upgrade(admin_password=None):
    """Upgrades satellite from old version to latest version.

    :param admin_password: A string. Defaults to 'changeme'.
        Foreman admin password for hammer commands.

    The following environment variables affect this command:

    ADMIN_PASSWORD
        Optional, defaults to 'changeme'. Foreman admin password.
    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'
    """
    to_version = os.environ.get('TO_VERSION')
    if to_version not in ['6.1', '6.2']:
        print('Wrong Satellite Version Provided to upgrade to. '
              'Provide one of 6.1, 6.2')
        sys.exit(1)
    # Sync capsule and tools repo
    if admin_password is None:
        admin_password = os.environ.get('ADMIN_PASSWORD', 'changeme')
    # Setting yum stdout log level to be less verbose
    set_yum_debug_level()
    # Removing rhel-released and rhel-optional repo
    run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo')
    print('Wait till Packages update ... ')
    update_packages(quiet=True)
    # Rebooting the system to see possible errors
    if os.environ.get('RHEV_SATELLITE'):
        reboot(120)
    # Setting Satellite61 Repos
    major_ver = distro_info()[1]
    base_url = os.environ.get('BASE_URL')
    # Following disables the old satellite repo and extra repos enabled
    # during subscribe e.g Load balancer
    disable_repos('*', silent=True)
    enable_repos('rhel-{0}-server-rpms'.format(major_ver))
    enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver))
    if base_url is None:
        enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format(
            major_ver, to_version))
    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()
    # 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
    print('Wait till packages update ... ')
    print('YUM UPDATE started at: {0}'.format(time.ctime()))
    update_packages(quiet=False)
    print('YUM UPDATE finished at: {0}'.format(time.ctime()))
    # Rebooting the system again for possible errors
    if os.environ.get('RHEV_SATELLITE'):
        reboot(120)
    # Stop the service again which started in restart
    run('katello-service stop')
    if to_version == '6.1':
        run('service-wait mongod start')
    # Running Upgrade
    print('SATELLITE UPGRADE started at: {0}'.format(time.ctime()))
    if to_version == '6.1':
        run('katello-installer --upgrade')
    else:
        run('satellite-installer --scenario satellite --upgrade')
    print('SATELLITE UPGRADE finished at: {0}'.format(time.ctime()))
    # Test the Upgrade is successful
    run('hammer -u admin -p {0} ping'.format(admin_password), warn_only=True)
    # Test The status of all katello services
    run('katello-service status', warn_only=True)
示例#21
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')
    # Setting yum stdout log level to be less verbose
    set_yum_debug_level()
    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')