示例#1
0
def setup_products_for_upgrade(product, os_version):
    """Sets up product(s) to perform upgrade on

    :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
    """
    if check_necessary_env_variables_for_upgrade(product):
        sat_host = cap_hosts = clients6 = clients7 = None
        logger.info('Setting up Satellite ....')
        sat_host = satellite6_setup(os_version)
        if product == 'capsule' or product == 'n-1' or product == 'longrun':
            logger.info('Setting up Capsule ....')
            cap_hosts = satellite6_capsule_setup(
                sat_host, os_version, False if product == 'n-1' else True)
        if product == 'client' or product == 'longrun':
            logger.info('Setting up Clients ....')
            clients6, clients7 = satellite6_client_setup()
        setups_dict = {
            'sat_host': sat_host,
            'capsule_hosts': cap_hosts,
            'clients6': clients6,
            'clients7': clients7
        }
        create_setup_dict(setups_dict)
        if os.environ.get('RUN_EXISTANCE_TESTS', 'false').lower() == 'true':
            logger.info('Setting up preupgrade datastore for existance tests')
            set_datastore('preupgrade')
        return sat_host, cap_hosts, clients6, clients7
示例#2
0
def setup_products_for_upgrade(product, os_version):
    """Sets up product(s) to perform upgrade on

    :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
    """
    if check_necessary_env_variables_for_upgrade(product):
        sat_host = cap_hosts = clients6 = clients7 = None
        logger.info('Setting up Satellite ....')
        sat_host = satellite6_setup(os_version)
        if product == 'capsule' or product == 'n-1' or product == 'longrun':
            logger.info('Setting up Capsule ....')
            cap_hosts = satellite6_capsule_setup(
                sat_host, os_version, False if product == 'n-1' else True)
        if product == 'client' or product == 'longrun':
            logger.info('Setting up Clients ....')
            clients6, clients7, puppet_clients7 = satellite6_client_setup()
        setups_dict = {
            'sat_host': sat_host,
            'capsule_hosts': cap_hosts,
            'clients6': clients6,
            'clients7': clients7,
            'puppet_clients7': puppet_clients7
        }
        create_setup_dict(setups_dict)
        return sat_host, cap_hosts, clients6, clients7, puppet_clients7
示例#3
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)
示例#4
0
def validate_and_create_product_templates(product):
    """Task to do a sanity check on the satellite and capsule and then
    create their templates after z-stream upgrade

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

    RHEV_SAT_HOST
        The rhevm satellite hostname to run upgrade on
    RHEV_CAP_HOST
        The rhevm capsule hostname to run upgrade on
    RHEV_STORAGE
        The storage domain on the rhevm used to create templates
    RHEV_CLUSTER
        Cluster name in RHEV where instance is created
    RHEV_SAT_IMAGE
        The satellite Image from which satellite instance will be created
    RHEV_CAP_IMAGE
        The capsule Image from which capsule instance will be created
    RHEV_SAT_INSTANCE
        The satellite instance name in rhevm of which template is to be
        created, generally the upgraded box
    RHEV_CAP_INSTANCE
        The capsule instance name in rhevm of which template is to be
        created, generally the upgraded box
    """
    # Get the instances name, specified in the jenkins job
    if product not in ['satellite', 'n-1']:
        os_version = os.environ.get('OS_VERSION')
        sat_instance = 'upgrade_satellite_auto_rhel{0}'.format(os_version)
        logger.info('Satellite Instance name {0}'.format(sat_instance))
        cap_instance = 'upgrade_capsule_auto_rhel{0}'.format(os_version)
        logger.info('Capsule Instance name {0}'.format(cap_instance))
        cluster = os.environ.get('RHEV_CLUSTER')
        storage = os.environ.get('RHEV_STORAGE')
        sat_host = os.environ.get('RHEV_SAT_HOST')
        new_sat_template = os.environ.get('RHEV_SAT_IMAGE') + "_new"
        cap_host = os.environ.get('RHEV_CAP_HOST')
        new_cap_template = os.environ.get('RHEV_CAP_IMAGE') + "_new"
        if check_necessary_env_variables_for_upgrade('capsule'):
            execute(check_ntpd, host=sat_host)
            execute(katello_restart, host=sat_host)
            execute(capsule_sync, cap_host, host=sat_host)
            execute(check_ntpd, host=cap_host)
            execute(katello_restart, host=cap_host)
            thread.start_new_thread(
                create_rhevm_template,
                (sat_instance, cluster, new_sat_template, storage))
            thread.start_new_thread(
                create_rhevm_template,
                (cap_instance, cluster, new_cap_template, storage))
            wait_till_rhevm_instance_status(sat_instance,
                                            'Image Locked',
                                            timeout=30)
            wait_till_rhevm_instance_status(sat_instance, 'down', timeout=240)
示例#5
0
def validate_and_create_product_templates():
    """Task to do a sanity check on the satellite and capsule and then
    create their templates after z-stream upgrade

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

    RHEV_SAT_HOST
        The rhevm satellite hostname to run upgrade on
    RHEV_CAP_HOST
        The rhevm capsule hostname to run upgrade on
    RHEV_STORAGE
        The storage domain on the rhevm used to create templates
    RHEV_SAT_IMAGE
        The satellite Image from which satellite instance will be created
    RHEV_CAP_IMAGE
        The capsule Image from which capsule instance will be created
    RHEV_SAT_INSTANCE
        The satellite instance name in rhevm of which template is to be
        created, generally the upgraded box
    RHEV_CAP_INSTANCE
        The capsule instance name in rhevm of which template is to be
        created, generally the upgraded box
    """
    # Get the instances name, specified in the jenkins job
    sat_instance = os.environ.get('RHEV_SAT_INSTANCE')
    cap_instance = os.environ.get('RHEV_CAP_INSTANCE')
    cluster = 'Default'
    storage = os.environ.get('RHEV_STORAGE')
    if sat_instance and cap_instance:
        sat_host = os.environ.get('RHEV_SAT_HOST')
        new_sat_template = os.environ.get('RHEV_SAT_IMAGE') + "_new"
        cap_host = os.environ.get('RHEV_CAP_HOST')
        new_cap_template = os.environ.get('RHEV_CAP_IMAGE') + "_new"
        if check_necessary_env_variables_for_upgrade('capsule'):
            execute(check_ntpd, host=sat_host)
            execute(katello_restart, host=sat_host)
            execute(capsule_sync, cap_host, host=sat_host)
            execute(check_ntpd, host=cap_host)
            execute(katello_restart, host=cap_host)
            try:
                create_rhevm_template(sat_instance, cluster, new_sat_template,
                                      storage)
                create_rhevm_template(cap_instance, cluster, new_cap_template,
                                      storage)
            except Exception as ex:
                logger.error('Failed to Create thread :\n%s' % str(ex))
示例#6
0
def product_upgrade(product, upgrade_type, satellite=None):
    """
    Used to drive the satellite, Capsule and Content-host upgrade based on their
    product type and upgrade type

    :param product: Product can be satellite, capsule, longrun and n-1

        1- If product is satellite then upgrade only satellite
        2- If product is capsule then upgrade satellite and capsule
        3- If product is client then upgrade satellite and client
        4- If product is longrun then upgrade satellite, capsule and client
        5- If product is n-1 then upgrades only satellite by keeping capsule at last
        z-stream released version

    :param upgrade_type: Upgrade_type can be satellite, capsule and client


    """
    def product_upgrade_satellite(sat_host):
        try:
            with LogAnalyzer(sat_host):
                current = execute(get_sat_cap_version, 'sat',
                                  host=sat_host)[sat_host]
                if settings.upgrade.from_version != settings.upgrade.to_version:
                    execute(satellite_upgrade, host=sat_host)
                else:
                    execute(satellite_upgrade, True, host=sat_host)
                upgraded = execute(get_sat_cap_version, 'sat',
                                   host=sat_host)[sat_host]
                check_upgrade_compatibility(upgrade_type, current, upgraded)
                execute(foreman_debug, f'satellite_{sat_host}', host=sat_host)
        except Exception:
            execute(foreman_debug, f'satellite_{sat_host}', host=sat_host)
            raise

    def product_upgrade_capsule(cap_host):
        try:
            with LogAnalyzer(cap_host):
                current = execute(get_sat_cap_version, 'cap',
                                  host=cap_host)[cap_host]
                if settings.upgrade.from_version != settings.upgrade.to_version:
                    execute(satellite_capsule_upgrade,
                            cap_host,
                            sat_host,
                            host=cap_host)
                elif settings.upgrade.from_version == settings.upgrade.to_version:
                    execute(satellite_capsule_zstream_upgrade,
                            cap_host,
                            host=cap_host)
                upgraded = execute(get_sat_cap_version, 'cap',
                                   host=cap_host)[cap_host]
                check_upgrade_compatibility(upgrade_type, current, upgraded)
                # Generate foreman debug on capsule postupgrade
                execute(foreman_debug, f'capsule_{cap_host}', host=cap_host)
                # Execute tasks as post upgrade tier1 tests
                # are dependent
            if product == 'longrun':
                post_upgrade_test_tasks(sat_host, cap_host)
        except Exception:
            execute(foreman_debug, f'capsule_{cap_host}', host=cap_host)
            raise

    def product_upgrade_client():
        clients6 = setup_dict['clients6']
        clients7 = setup_dict['clients7']
        puppet_clients7 = setup_dict['puppet_clients7']
        puppet_clients6 = setup_dict['puppet_clients6']
        satellite6_client_upgrade('rhel6', clients6)
        satellite6_client_upgrade('rhel7', clients7)
        satellite6_client_upgrade('rhel7', puppet_clients7, puppet=True)
        satellite6_client_upgrade('rhel6', puppet_clients6, puppet=True)

    env.disable_known_hosts = True
    check_necessary_env_variables_for_upgrade(product)
    logger.info(f'performing upgrade from {settings.upgrade.from_version} TO '
                f'{settings.upgrade.to_version}')
    # Get the setup dict returned by setup_products_for_upgrade
    setup_dict = get_setup_data(sat_hostname=satellite)
    sat_host = setup_dict['sat_host']
    cap_hosts = setup_dict['capsule_hosts']
    pre_upgrade_system_checks(cap_hosts)
    env['satellite_host'] = sat_host

    if upgrade_type == "satellite":
        product_upgrade_satellite(sat_host)
    elif (product == 'capsule' or product == 'longrun')\
            and upgrade_type == 'capsule':
        for cap_host in cap_hosts:
            settings.upgrade.capsule_hostname = cap_host
            product_upgrade_capsule(cap_host)
    elif (product == 'client'
          or product == 'longrun') and upgrade_type == 'client':
        product_upgrade_client()
    execute(unsubscribe, host=sat_host)
示例#7
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