Ejemplo n.º 1
0
def dockerize(ak_name=None, distro=None, org_label=None):
    """Creates Docker Container's of specified distro and subscribes them to
    given AK

    :param string ak_name : Activation Key name, to be used to subscribe
    the docker container's
    :param string distro : The OS of the VM to be created.
        Supported are 'rhel7' and 'rhel6'
    :returns dict clients : A dictonary which contain's container name
    and id.

    Environment Variable:

    DOCKER_VM
        The Docker VM IP/Hostname on rhevm to create clients
    RHEV_CLIENT_AK
        The AK using which client will be registered to satellite
    """
    ak_name = ak_name or os.environ.get(
        'RHEV_CLIENT_AK_{}'.format(distro.upper()))
    docker_vm = os.environ.get('DOCKER_VM')
    # Check if the VM containing docker images is up, else turn on
    with get_rhevm4_client().build() as rhevm_client:
        instance_name = 'sat6-docker-upgrade'
        template_name = 'sat6-docker-upgrade-template'
        vm = rhevm_client.system_service().vms_service(
            ).list(search='name={}'.format(instance_name))
        if not vm:
            logger.info('Docker VM for generating Content Host is not created.'
                        'Creating it, please wait..')
            create_rhevm4_instance(instance_name, template_name)
            execute(manage_daemon, 'restart', 'docker', host=docker_vm)
        elif vm[0].status.name.lower() == 'down':
            logger.info('Docker VM for generating Content Host is not up. '
                        'Turning on, please wait ....')
            rhevm_client.vms.get(name=instance_name).start()
            wait_till_rhevm4_instance_status(instance_name, 'up', 5)
            execute(manage_daemon, 'restart', 'docker', host=docker_vm)
    time.sleep(5)
    logger.info('Generating katello client on RHEL7 on Docker. '
                'Please wait .....')
    # Generate Clients on RHEL 7
    time.sleep(30)
    clients = execute(
        generate_satellite_docker_clients_on_rhevm,
        distro,
        1,
        ak_name,
        org_label,
        host=docker_vm,
    )[docker_vm]
    return clients
Ejemplo n.º 2
0
def satellite6_client_setup():
    """Sets up required things on upgrade running machine and on Client to
    perform client upgrade later

    If not personal clients, then it creates docker containers as clients on
    rhevm vm.

    Environment Variable:

    DOCKER_VM
        The Docker VM IP/Hostname on rhevm to create clients
    """
    # If User Defined Clients Hostname provided
    clients6 = os.environ.get('CLIENT6_HOSTS')
    clients7 = os.environ.get('CLIENT7_HOSTS')
    puppet_clients6 = puppet_clients7 = None
    docker_vm = os.environ.get('DOCKER_VM')
    clients_count = os.environ.get('CLIENTS_COUNT')
    from_version = os.environ.get('FROM_VERSION')
    sat_host = env.get('satellite_host')
    if clients6:
        clients6 = [client.strip() for client in str(clients6).split(',')]
        # Sync latest sat tools repo to clients if downstream
        if os.environ.get('TOOLS_URL_RHEL6'):
            logger.info('Syncing Tools repos of rhel6 in Satellite:')
            execute(sync_tools_repos_to_upgrade,
                    'rhel6',
                    clients6,
                    host=sat_host)
    if clients7:
        clients7 = [client.strip() for client in str(clients7).split(',')]
        # Sync latest sat tools repo to clients if downstream
        if os.environ.get('TOOLS_URL_RHEL7'):
            logger.info('Syncing Tools repos of rhel7 in Satellite:')
            execute(sync_tools_repos_to_upgrade,
                    'rhel7',
                    clients7,
                    host=sat_host)
    # Run upgrade on Docker Containers
    if not all([clients6, clients7]):
        if not clients_count:
            logger.warning('Clients Count is not set, please set and rerun !')
            sys.exit(1)
        elif int(clients_count) < 2:
            logger.warning('Clients Count should be atleast 2, please rerun !')
            sys.exit(1)
        # Check if the VM containing docker images is up, else turn on
        with get_rhevm4_client().build() as rhevm_client:
            instance_name = 'sat6-docker-upgrade'
            template_name = 'sat6-docker-upgrade-template'
            vm = rhevm_client.system_service().vms_service().list(
                search='name={}'.format(instance_name))
            if not vm:
                logger.info(
                    'Docker VM for generating Content Host is not created. '
                    'Creating it, please wait..')
                create_rhevm4_instance(instance_name, template_name)
                execute(manage_daemon, 'restart', 'docker', host=docker_vm)
            elif vm[0].status.name.lower() == 'down':
                logger.info('Docker VM for generating Content Host is not up. '
                            'Turning on, please wait ....')
                rhevm_client.vms.get(name=instance_name).start()
                wait_till_rhevm4_instance_status(instance_name, 'up', 5)
                execute(manage_daemon, 'restart', 'docker', host=docker_vm)
        time.sleep(5)
        logger.info('Generating {} clients on RHEL6 and RHEL7 on Docker. '
                    'Please wait .....'.format(clients_count))
        # Generate Clients on RHEL 7 and RHEL 6
        clients6 = execute(generate_satellite_docker_clients_on_rhevm,
                           'rhel6',
                           int(clients_count) / 2,
                           host=docker_vm)[docker_vm]
        clients7 = execute(generate_satellite_docker_clients_on_rhevm,
                           'rhel7',
                           int(clients_count) / 2,
                           host=docker_vm)[docker_vm]
        # Allow all puppet clients to be signed automatically
        execute(puppet_autosign_hosts, from_version, ['*'], host=sat_host)
        puppet_clients7 = execute(generate_satellite_docker_clients_on_rhevm,
                                  'rhel7',
                                  2,
                                  puppet=True,
                                  host=docker_vm)[docker_vm]
        puppet_clients6 = execute(generate_satellite_docker_clients_on_rhevm,
                                  'rhel6',
                                  2,
                                  puppet=True,
                                  host=docker_vm)[docker_vm]
        # Sync latest sat tools repo to clients if downstream
        if all([
                os.environ.get('TOOLS_URL_RHEL6'),
                os.environ.get('TOOLS_URL_RHEL7')
        ]):
            time.sleep(10)
            vers = ['6.0', '6.1']
            logger.info('Syncing Tools repos of rhel7 in Satellite..')
            if from_version in vers:
                all_clients7 = clients7.values() + puppet_clients7.values()
                all_clients6 = clients6.values() + puppet_clients6.values()
            else:
                all_clients7 = clients7.keys() + puppet_clients7.keys()
                all_clients6 = clients6.keys() + puppet_clients6.keys()
            execute(
                sync_tools_repos_to_upgrade,
                'rhel7',
                # Containers_ids are not required from sat version > 6.1 to
                # attach the subscription to client
                all_clients7,
                host=sat_host)
            time.sleep(10)
            logger.info('Syncing Tools repos of rhel6 in Satellite..')
            execute(
                sync_tools_repos_to_upgrade,
                'rhel6',
                # Containers_ids are not requied from sat version > 6.1 to
                # attach the subscriprion to client
                all_clients6,
                host=sat_host)
        # Refresh subscriptions on clients
        time.sleep(30)
        execute(refresh_subscriptions_on_docker_clients,
                clients6.values() + puppet_clients6.values(),
                host=docker_vm)
        time.sleep(30)
        execute(refresh_subscriptions_on_docker_clients,
                clients7.values() + puppet_clients7.values(),
                host=docker_vm)
        # Resetting autosign conf
        execute(puppet_autosign_hosts,
                from_version, [''],
                False,
                host=sat_host)
    logger.info('Clients are ready for Upgrade.')
    return clients6, clients7, puppet_clients7, puppet_clients6