示例#1
0
def product_upgrade(product):
    """Task which upgrades the product.

    Product is satellite or capsule.

    :param product: A string. product name wanted to upgrade.
    :param sat_image: A string. Openstack Satellite image name
        from which instance to create.
    :param cap_image: A string. Openstack Capsule image name
        from which instance to create.

    The following environment variables affect this command:

    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.
    ADMIN_PASSWORD
        Optional, defaults to 'changeme'. Foreman admin password.
    BASE_URL
        URL for the compose repository.
    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
        Optional, defaults to latest available capsule version in CDN.
    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'
    SATELLITE_HOSTNAME
        The Satellite hostname to run upgrade on.
        Optional, If want to run upgrade on specific satellite.
    CAPSULE_HOSTNAME
        The Satellite hostname to run upgrade on.
        Optional, If want to run upgrade on specific capsule.
    CAPSULE_SUBSCRIPTION
        List of cv_name, environment, ak_name attached to subscription of
        capsule in defined sequence.
    """
    products = ['satellite', 'capsule']
    if product not in products:
        print('Product name should be one of {0}'.format(', '.join(products)))
        sys.exit(1)
    from_version = os.environ.get('FROM_VERSION')
    if from_version not in ['6.1', '6.0']:
        print('Wrong Upgrade 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 Upgrade Version Provided to upgrade to. Provide one of '
              '6.1, 6.2')
        sys.exit(1)
    # ----------------- Satellite Upgrade ------------------
    # If Personal Satellite Hostname provided
    if os.environ.get('SATELLITE_HOSTNAME'):
        sat_host = os.environ.get('SATELLITE_HOSTNAME')
    # Else run upgrade on rhevm satellite
    else:
        # Get imamge name and Hostname from Jenkins environment
        missing_vars = [
            var for var in ('RHEV_SAT_IMAGE', 'RHEV_SAT_HOST')
            if var not in os.environ]
        # Check if image name and Hostname in jenkins are set
        if missing_vars:
            print('The following environment variable(s) must be set in jenkin'
                  'environment: {0}.'.format(', '.join(missing_vars)))
            sys.exit(1)
        sat_image = os.environ.get('RHEV_SAT_IMAGE')
        sat_host = os.environ.get('RHEV_SAT_HOST')
        # Check If OS is set for creating an instance name in rhevm
        version = os.environ.get('OS')
        if not version:
            print('Please provide OS version as rhel7 or rhel6, And retry !')
            sys.exit(1)
        sat_instance = 'upgrade_satellite_auto_{0}'.format(version)
        # Deleting Satellite instance if already exists
        execute(delete_rhevm_instance, sat_instance)
        print('Turning on Satellite Instance ....')
        execute(create_rhevm_instance, sat_instance, sat_image)
        # Wait Till Instance gets up
        host_pings(sat_host)
        # Subscribe the instance to CDN
        execute(subscribe, host=sat_host)
        # Rebooting the services
        execute(lambda: run('katello-service restart'), host=sat_host)
    # Set satellite hostname in fabric environment
    env['satellite_host'] = sat_host
    # -------------------- Capsule Upgrade ----------------
    if product == 'capsule':
        # If Personal Capsule Hostname provided
        if os.environ.get('CAPSULE_HOSTNAME'):
            cap_host = os.environ.get('CAPSULE_HOSTNAME')
            # For Personal Satellite CAPSULE_SUBSCRIPTION is must
            cap_subscription = os.environ.get('CAPSULE_SUBSCRIPTION')
            if not cap_subscription:
                print('CAPSULE_SUBSCRIPTION environment variable is not '
                      'defined !')
                sys.exit(1)
            elif len(cap_subscription.split(',')) != 3:
                print('CAPSULE_SUBSCRIPTION environment variable is not '
                      'having all the details!')
        # Else run upgrade on rhevm capsule
        else:
            # Get imamge name and Hostname from Jenkins environment
            missing_vars = [
                var for var in (
                    'RHEV_CAP_IMAGE', 'RHEV_CAP_HOST', 'RHEV_CAPSULE_AK')
                if var not in os.environ]
            # Check if image name and Hostname in jenkins are set
            if missing_vars:
                print('The following jenkins environment variable(s) must be '
                      'set: {0}.'.format(', '.join(missing_vars)))
                sys.exit(1)
            cap_image = os.environ.get('RHEV_CAP_IMAGE')
            cap_host = os.environ.get('RHEV_CAP_HOST')
            cap_instance = 'upgrade_capsule_auto_{0}'.format(version)
            # Deleting Capsule instance if already exists
            execute(delete_rhevm_instance, cap_instance)
            print('Turning on Capsule Instance ....')
            execute(create_rhevm_instance, cap_instance, cap_image)
            # Restarting the services on capsule
            execute(lambda: run('katello-service restart'), host=cap_host)
        # Set capsule hostname in fabric environment
        env['capsule_host'] = cap_host
        # Copy ssh key from satellie to capsule
        copy_ssh_key(sat_host, cap_host)
        if os.environ.get('CAPSULE_URL') is not None:
            execute(sync_capsule_tools_repos_to_upgrade, host=sat_host)
    # Run satellite upgrade
    execute(satellite6_upgrade, host=sat_host)
    # Generate foreman debug on satellite
    execute(foreman_debug, 'satellite', host=sat_host)
    if product == 'capsule':
        print('\nRunning Capsule Upgrade ..........')
        # Run capsule upgrade
        execute(satellite6_capsule_upgrade, host=cap_host)
        # Generate foreman debug on capsule
        execute(foreman_debug, 'capsule', host=cap_host)
示例#2
0
def product_upgrade(
        product, sat_image=None, cap_image=None):
    """Task which upgrades the product.

    Product is satellite or capsule.

    :param product: A string. product name wanted to upgrade.
    :param sat_image: A string. Openstack Satellite image name
        from which instance to create.
    :param cap_image: A string. Openstack Capsule image name
        from which instance to create.

    The following environment variables affect this command:

    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.
    ADMIN_PASSWORD
        Optional, defaults to 'changeme'. Foreman admin password.
    BASE_URL
        URL for the compose repository.
    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
        Optional, defaults to latest available capsule version in CDN.
    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'
    RHEV_USER
        The username of a rhevm project to login.
    RHEV_PASSWD
        The password of a rhevm project to login.
    RHEV_URL
        An url to API of rhevm project.
    SATELLITE_HOSTNAME
        The Satellite hostname to run upgrade on.
        Optional, If want to run upgrade on specific satellite.
    CAPSULE_HOSTNAME
        The Satellite hostname to run upgrade on.
        Optional, If want to run upgrade on specific capsule.
    CAPSULE_SUBSCRIPTION
        List of cv_name, environment, ak_name attached to subscription of
        capsule in defined sequence.
        Optional, for upgrade on specific satellite and capsule.
    RHEV_SATELLITE
        The Satellite hostname on RHEVM instance.
        Optional, If want to run upgrade on RHEVM instance.
    RHEV_CAPSULE
        The Capsule hostname on RHEVM instance.
        Optional, If want to run upgrade on RHEVM instance.

    """
    products = ['satellite', 'capsule']
    if product not in products:
        print('Product name should be one of {0}'.format(', '.join(products)))
        sys.exit(1)
    if not os.environ.get('SATELLITE_HOSTNAME'):
        if not sat_image and not os.environ.get('RHEV_SATELLITE'):
            print('Please provide either Satellite RHEVM template name or '
                  'Satellite HostName to perform upgrade!')
            sys.exit(1)
        version = os.environ.get('OS')
        if not version:
            print('Please provide OS version as rhel7 or rhel6, And retry !')
            sys.exit(1)
        sat_instance = 'upgrade_satellite_auto_{0}'.format(version)
        # Deleting Satellite instance if any
        execute(delete_rhevm_instance, sat_instance)
        print('Turning on Satellite Instance ....')
        execute(
            create_rhevm_instance,
            sat_instance,
            sat_image
        )
        sat_host = os.environ.get('RHEV_SATELLITE')
        # Wait Till Instance gets up
        host_pings(sat_host)
        # Subscribe the instances to CDN
        execute(subscribe, host=sat_host)
    else:
        sat_host = os.environ.get('SATELLITE_HOSTNAME')
        env['satellite_host'] = sat_host
    # Rebooting the services
    execute(lambda: run('katello-service restart'), host=sat_host)
    # For Capsule Upgrade
    if product == 'capsule':
        if not os.environ.get('CAPSULE_HOSTNAME'):
            if not cap_image and not os.environ.get('RHEV_CAPSULE'):
                print('Please provide either Capsule RHEVM template name or '
                      'Capsule HostName to perform upgrade!')
                sys.exit(1)
            cap_instance = 'upgrade_capsule_auto_{0}'.format(version)
            # Deleting Capsule instance if any
            execute(delete_rhevm_instance, cap_instance)
            print('Turning on Capsule Instance ....')
            execute(
                create_rhevm_instance,
                cap_instance, cap_image
            )
            cap_host = os.environ.get('RHEV_CAPSULE')
        else:
            cap_host = os.environ.get('CAPSULE_HOSTNAME')
            env['capsule_host'] = cap_host
        # Copy ssh key from satellie to capsule
        copy_ssh_key(sat_host, cap_host)
        if os.environ.get('CAPSULE_URL') is not None:
            execute(sync_capsule_tools_repos_to_upgrade, host=sat_host)
    # Run satellite upgrade
    execute(satellite6_upgrade, host=sat_host)
    # Generate foreman debug on satellite
    execute(foreman_debug, 'satellite', host=sat_host)
    if product == 'capsule':
        print('\nRunning Capsule Upgrade ..........')
        # Run capsule upgrade
        execute(satellite6_capsule_upgrade, host=cap_host)
        # Generate foreman debug on capsule
        execute(foreman_debug, 'capsule', host=cap_host)
示例#3
0
def product_upgrade(product, sat_image=None, cap_image=None):
    """Task which upgrades the product.

    Product is satellite or capsule.

    :param product: A string. product name wanted to upgrade.
    :param sat_image: A string. Openstack Satellite image name
        from which instance to create.
    :param cap_image: A string. Openstack Capsule image name
        from which instance to create.

    The following environment variables affect this command:

    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.
    ADMIN_PASSWORD
        Optional, defaults to 'changeme'. Foreman admin password.
    BASE_URL
        URL for the compose repository.
    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
        Optional, defaults to latest available capsule version in CDN.
    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'
    RHEV_USER
        The username of a rhevm project to login.
    RHEV_PASSWD
        The password of a rhevm project to login.
    RHEV_URL
        An url to API of rhevm project.
    SATELLITE_HOSTNAME
        The Satellite hostname to run upgrade on.
        Optional, If want to run upgrade on specific satellite.
    CAPSULE_HOSTNAME
        The Satellite hostname to run upgrade on.
        Optional, If want to run upgrade on specific capsule.
    CAPSULE_SUBSCRIPTION
        List of cv_name, environment, ak_name attached to subscription of
        capsule in defined sequence.
    RHEV_SATELLITE
        The Satellite hostname on RHEVM instance.
        Optional, If want to run upgrade on RHEVM instance.
    RHEV_CAPSULE
        The Capsule hostname on RHEVM instance.
        Optional, If want to run upgrade on RHEVM instance.

    """
    products = ['satellite', 'capsule']
    if product not in products:
        print('Product name should be one of {0}'.format(', '.join(products)))
        sys.exit(1)

    missing_vars = [
        var for var in ('SAT_IMAGE', 'SAT_HOST', 'CAP_IMAGE', 'CAP_HOST')
        if var not in os.environ
    ]
    if missing_vars:
        print('The following environment variable(s) must be set: '
              '{0}.'.format(', '.join(missing_vars)))
        sys.exit(1)

    if not os.environ.get('SATELLITE_HOSTNAME'):
        if not sat_image and not os.environ.get('RHEV_SATELLITE'):
            sat_image = os.environ.get('SAT_IMAGE')
            sat_host = os.environ.get('SAT_HOST')
        else:
            sat_host = os.environ.get('RHEV_SATELLITE')
        version = os.environ.get('OS')
        if not version:
            print('Please provide OS version as rhel7 or rhel6, And retry !')
            sys.exit(1)
        sat_instance = 'upgrade_satellite_auto_{0}'.format(version)
        # Deleting Satellite instance if any
        execute(delete_rhevm_instance, sat_instance)
        print('Turning on Satellite Instance ....')
        execute(create_rhevm_instance, sat_instance, sat_image)
        # Wait Till Instance gets up
        host_pings(sat_host)
        # Subscribe the instances to CDN
        execute(subscribe, host=sat_host)
    else:
        sat_host = os.environ.get('SATELLITE_HOSTNAME')
    env['satellite_host'] = sat_host
    # Rebooting the services
    execute(lambda: run('katello-service restart'), host=sat_host)
    # For Capsule Upgrade
    if product == 'capsule':
        if not os.environ.get('CAPSULE_HOSTNAME'):
            if not cap_image and not os.environ.get('RHEV_CAPSULE'):
                cap_image = os.environ.get('CAP_IMAGE')
                cap_host = os.environ.get('CAP_HOST')
            else:
                cap_host = os.environ.get('RHEV_CAPSULE')
            cap_instance = 'upgrade_capsule_auto_{0}'.format(version)
            # Deleting Capsule instance if any
            execute(delete_rhevm_instance, cap_instance)
            print('Turning on Capsule Instance ....')
            execute(create_rhevm_instance, cap_instance, cap_image)
        else:
            cap_host = os.environ.get('CAPSULE_HOSTNAME')
        env['capsule_host'] = cap_host
        # Copy ssh key from satellie to capsule
        copy_ssh_key(sat_host, cap_host)
        if os.environ.get('CAPSULE_URL') is not None:
            execute(sync_capsule_tools_repos_to_upgrade, host=sat_host)
    # Run satellite upgrade
    execute(satellite6_upgrade, host=sat_host)
    # Generate foreman debug on satellite
    execute(foreman_debug, 'satellite', host=sat_host)
    if product == 'capsule':
        print('\nRunning Capsule Upgrade ..........')
        # Run capsule upgrade
        execute(satellite6_capsule_upgrade, host=cap_host)
        # Generate foreman debug on capsule
        execute(foreman_debug, 'capsule', host=cap_host)