Beispiel #1
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)
Beispiel #2
0
def create_openstack_instance(
        product, instance_name, image_name, flavor_name, ssh_key, timeout=5):
    """Creates openstack Instance from Image and Assigns a floating IP
    to instance. Also It ensures that instance is ready for testing.

    :param product: A string. A product name of which, instance to create.
    :param instance_name: A string. Openstack Instance name to create.
    :param image_name: A string. Openstack image name from which instance
        to be created.
    :param flavor_name: A string. Openstack flavor_name for instance.
        e.g m1.small.
    :param ssh_key: A string. ssh_key 'name' that required to add
        into this instance.
    :param int timeout: The polling timeout in minutes to assign IP.

    ssh_key should be added to openstack project before running automation.
    Else the automation will fail.

    The following environment variables affect this command:

    USERNAME
        The username of an openstack project to login.
    PASSWORD
        The password of an openstack project to login.
    AUTH_URL
        The authentication url of the project.
    PROJECT_ID
        Project ID of an openstack project.

    """
    network_name = 'satellite-jenkins'
    openstack_client = get_openstack_client()
    # Validate ssh_key is added into openstack project
    openstack_client.keypairs.find(name=ssh_key)
    image = openstack_client.images.find(name=image_name)
    flavor = openstack_client.flavors.find(name=flavor_name)
    network = openstack_client.networks.find(label=network_name)
    floating_ip = openstack_client.floating_ips.create(
        openstack_client.floating_ip_pools.list()[0].name
    )
    # Create instance from the given parameters
    print('Creating new Openstack instance {0}'.format(instance_name))
    instance = openstack_client.servers.create(
        name=instance_name,
        image=image.id,
        flavor=flavor.id,
        key_name=ssh_key,
        network=network.id
    )
    # Assigning floating ip to instance
    timeup = time.time() + int(timeout) * 60
    while True:
        if time.time() > timeup:
            print('The timeout for assigning the floating IP has reached!')
            sys.exit(1)
        try:
            instance.add_floating_ip(floating_ip)
            print('SUCCESS!! The floating IP {0} has been assigned '
                  'to instance!'.format(floating_ip.ip))
            break
        except novaclient.exceptions.BadRequest:
            time.sleep(5)
    # Wait till DNS resolves the IP
    print('Pinging the Host by IP:{0} ..........'.format(floating_ip.ip))
    host_pings(str(floating_ip.ip))
    print('SUCCESS !! The given IP has been pinged!!\n')
    print('Now, Getting the hostname from IP......\n')
    hostname = get_hostname_from_ip(str(floating_ip.ip))
    env['{0}_host'.format(product)] = hostname
    print('Pinging the Hostname:{0} ..........'.format(hostname))
    host_pings(hostname)
    print('SUCCESS !! The obtained hostname from IP is pinged !!')
    # Update the /etc/hosts file
    execute(lambda: run("echo {0} {1} >> /etc/hosts".format(
        floating_ip.ip, hostname)), host=hostname)
    print('The Instance is ready for further Testing .....!!')
Beispiel #3
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)
Beispiel #4
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)