コード例 #1
0
def set_post_upgrade_hostname(request, shared_workers):
    """Retrieves worker hostname of pre_upgrade and sets the same to run post_upgrade

    The limitation of this implementation is that the XDIST_BEHAVIOR won't be observed,
    and tests running under xdist will not be isolated.

    This is overriding the session scoped align_to_satellite fixture
    """
    post_upgrade = request.node.get_closest_marker('post_upgrade')
    if post_upgrade:
        depend_test = post_upgrade.kwargs.get('depend_on')
        if depend_test:
            pre_test_name = depend_test.__name__
            pre_hostname = get_worker_hostname_from_testname(
                pre_test_name, shared_workers)
            if (pre_hostname is None) or (pre_hostname
                                          not in settings.server.hostnames):
                pytest.skip(
                    'Skipping the post_upgrade test as the pre_upgrade hostname is not found!'
                )
            # Read the worker id of pre test name
            settings.server.hostname = env.host_string = pre_hostname
            env.user = '******'
            configure_nailgun()
            configure_airgun()
            set_hammer_config()
コード例 #2
0
def csv_reader(component, subcommand):
    """
    Reads all component entities data using hammer csv output and returns the
    dict representation of all the entities.

    Representation: {component_name:
    [{comp1_name:comp1, comp1_id:1}, {comp2_name:comp2, comp2_ip:192.168.0.1}]
    }
    e.g:
    {'host':[{name:host1.ab.com, id:10}, {name:host2.xz.com, ip:192.168.0.1}]}

    :param string component: Satellite component name. e.g host, capsule
    :param string subcommand: subcommand for above component. e.g list, info
    :returns dict: The dict repr of hammer csv output of given command
    """
    comp_dict = {}
    entity_list = []
    sat_host = get_setup_data()['sat_host']
    set_hammer_config()
    data = execute(hammer,
                   '{0} {1}'.format(component, subcommand),
                   'csv',
                   host=sat_host)[sat_host]
    csv_read = csv.DictReader(data.lower().split('\n'))
    for row in csv_read:
        entity_list.append(row)
    comp_dict[component] = entity_list
    return comp_dict
コード例 #3
0
ファイル: tasks.py プロジェクト: jyejare/automation-tools
def csv_reader(component, subcommand):
    """
    Reads all component entities data using hammer csv output and returns the
    dict representation of all the entities.

    Representation: {component_name:
    [{comp1_name:comp1, comp1_id:1}, {comp2_name:comp2, comp2_ip:192.168.0.1}]
    }
    e.g:
    {'host':[{name:host1.ab.com, id:10}, {name:host2.xz.com, ip:192.168.0.1}]}

    :param string component: Satellite component name. e.g host, capsule
    :param string subcommand: subcommand for above component. e.g list, info
    :returns dict: The dict repr of hammer csv output of given command
    """
    comp_dict = {}
    entity_list = []
    sat_host = env.get('satellite_host')
    set_hammer_config()
    data = execute(
        hammer, '{0} {1}'.format(component, subcommand), 'csv', host=sat_host
        )[sat_host]
    csv_read = csv.DictReader(str(data.encode('utf-8')).lower().split('\n'))
    for row in csv_read:
        entity_list.append(row)
    comp_dict[component] = entity_list
    return comp_dict
コード例 #4
0
def pytest_sessionstart(session):
    """Do some setup for automation-tools and satellite6-upgrade"""
    # Fabric Config setup
    env.host_string = settings.server.hostname
    env.user = settings.server.ssh_username
    # Hammer Config Setup
    set_hammer_config(user=settings.server.admin_username, password=settings.server.admin_password)
コード例 #5
0
def delete_manifest(org_name):
    """ Delete manifest from satellite

    :param org_name: Organization name in satellite

    Usage:
        delete_manifest(self.org_name)
    """
    # Sets hammer default configuration
    hammer.set_hammer_config()
    print hammer.hammer('subscription delete-manifest '
                        '--organization "{0}"'.format(org_name))
コード例 #6
0
def template_reader(template_type, template_id, sat_host=None):
    """Hammer read and returns the template dump of template_id

    :param str template_type: The satellite template type
    :param str template_id: The template id
    :return str: The template content as string
    """
    set_hammer_config()
    sat_host = sat_host or get_setup_data()['sat_host']
    template_dump = execute(
        hammer, f'{template_type} dump --id {template_id}', 'base', host=sat_host
    )[sat_host]
    return template_dump
コード例 #7
0
def template_reader(template_type, template_id):
    """Hammer read and returns the template dump of template_id

    :param str template_type: The satellite template type
    :param str template_id: The template id
    :return str: The template content as string
    """
    set_hammer_config()
    sat_host = get_setup_data()['sat_host']
    template_dump = execute(
        hammer, '{0} dump --id {1}'.format(template_type, template_id), 'base', host=sat_host
    )[sat_host]
    return template_dump
コード例 #8
0
def check_capsule(capsule_name):
    """Running capsule sync on external capsule"""
    set_hammer_config()
    if os.environ.get('TO_VERSION') in ['6.2', '6.3']:
        check = hammer(
            'capsule refresh-features --name "{0}"'.format(capsule_name))
        print check[u'message']
        if check.return_code == 0:
            logger.info('Running Capsule sync')
            hammer('capsule content synchronize --name "{0}"'.format(
                capsule_name))
    else:
        logger.info('Running Capsule sync')
        hammer('capsule content synchronize --name "{0}"'.format(capsule_name))
コード例 #9
0
def capsule_sync(cap_host):
    """Run Capsule Sync as a part of job

    :param list cap_host: List of capsules to perform sync
    """
    set_hammer_config()
    if os.environ.get('TO_VERSION') in ['6.2', '6.3', '6.4']:
        logger.info('Refreshing features for capsule host {0}'.
                    format(cap_host))
        print hammer('capsule refresh-features --name "{0}"'.
                     format(cap_host))
    logger.info('Running Capsule sync for capsule host {0}'.
                format(cap_host))
    print hammer('capsule content synchronize --name {0}'.format(cap_host))
コード例 #10
0
def upload_manifest(manifest_url, org_name):
    """ Upload manifest to satellite

    :param manifest_url: URL of manifest hosted over http
    :param org_name: Organization name in satellite

    Usage:
        upload_manifest(self.manifest_url, self.org_name)
    """
    # Sets hammer default configuration
    hammer.set_hammer_config()
    run('wget {0} -O {1}'.format(manifest_url, '/manifest.zip'))
    print hammer.hammer('subscription upload --file {0} '
                        '--organization {1}'.format('/manifest.zip', org_name))
コード例 #11
0
    def __init__(self, path):
        self.path = path
        self.organization_label = None
        self.environment = None
        self.content_view = None
        self.activation_key = None
        self.admin_user = None
        self.admin_password = None
        self.defaults = None
        self.server = None
        self.capsules = []
        self._key_filenames = set()

        self._parse()
        set_hammer_config(self.admin_user, self.admin_password)
コード例 #12
0
    def __init__(self, path):
        self.path = path
        self.organization_label = None
        self.environment = None
        self.content_view = None
        self.activation_key = None
        self.admin_user = None
        self.admin_password = None
        self.defaults = None
        self.server = None
        self.capsules = []
        self._key_filenames = set()

        self._parse()
        set_hammer_config(self.admin_user, self.admin_password)
コード例 #13
0
def sync_capsule_tools_repos_to_upgrade(admin_password=None):
    """This syncs capsule repos in Satellite server.

    Useful for upgrading Capsule in feature.

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

    Following environment variable affects this function:

    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'
    CAPSULE_SUBSCRIPTION
        List of cv_name, environment, ak_name attached to subscription of
        capsule in defined sequence.

    """
    capsule_repo = os.environ.get('CAPSULE_URL')
    if capsule_repo is None:
        print('The Capsule repo URL is not provided '
              'to perform Capsule Upgrade in feature!')
        sys.exit(1)
    cv_name, env_name, ak_name = [
        os.environ.get(env_var)
        for env_var in (
            'RHEV_CAPSULE_CV', 'RHEV_CAPSULE_ENVIRONMENT', 'RHEV_CAPSULE_AK')
    ]
    details = os.environ.get('CAPSULE_SUBSCRIPTION')
    if details is not None:
        cv_name, env_name, ak_name = [
            item.strip() for item in details.split(',')]
    elif not all([cv_name, env_name, ak_name]):
        print('Error! The CV, Env and AK details are not provided for Capsule'
              'upgrade!')
        sys.exit(1)
    set_hammer_config()
    # Create product capsule
    hammer_product_create('capsule6_latest', '1')
    time.sleep(2)
    # Get product uuid to add in AK later
    latest_cap_uuid = get_attribute_value(
        hammer('subscription list --organization-id 1'), 'capsule6_latest',
        'id')
    # create repo
    hammer_repository_create(
        'capsule6_latest_repo', '1', 'capsule6_latest', capsule_repo)
    # Sync repos
    hammer_repository_synchronize(
        'capsule6_latest_repo', '1', 'capsule6_latest')
    # Add repos to CV
    hammer_content_view_add_repository(
        cv_name, '1', 'capsule6_latest', 'capsule6_latest_repo')
    # Publish cv
    hammer_content_view_publish(cv_name, '1')
    # Promote cv
    lc_env_id = get_attribute_value(
        hammer('lifecycle-environment list --organization-id 1 '
               '--name {}'.format(env_name)), env_name, 'id')
    cv_version_data = hammer(
        'content-view version list --content-view {} '
        '--organization-id 1'.format(cv_name))
    latest_cv_ver = sorted([float(data['name'].split(
        '{} '.format(cv_name))[1]) for data in cv_version_data]).pop()
    cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format(
        cv_name, latest_cv_ver), 'id')
    hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1')
    # Add new product subscriptions to AK
    hammer_activation_key_add_subscription(ak_name, '1', latest_cap_uuid)
    # Update subscription on capsule
    execute(
        lambda: run('subscription-manager attach --pool={0}'.format(
            latest_cap_uuid)),
        host=env.get('capsule_host'))
コード例 #14
0
ファイル: satellite.py プロジェクト: jyejare/automation-tools
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')
コード例 #15
0
def sync_capsule_repos_to_upgrade(capsules):
    """This syncs capsule repo in Satellite server and also attaches
    the capsule repo subscription to each capsule

    :param list capsules: The list of capsule hostnames to which new capsule
    repo subscription will be attached

    Following environment variable affects this function:

    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
        If not provided, capsule repo from Red Hat repositories will be enabled
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'
    TO_VERSION
        Upgradable Satellite version - To enable capsule repo
        e.g '6.1', '6.2'
    OS
        OS version to enable next version capsule repo
        e.g 'rhel7', 'rhel6'

    Personal Upgrade Env Vars:

    CAPSULE_AK
        The AK name used in capsule subscription

    Rhevm upgrade Env Vars:

    RHEV_CAPSULE_AK
        The AK name used in capsule subscription
    """
    logger.info('Syncing latest capsule repos in Satellite ...')
    capsule_repo = os.environ.get('CAPSULE_URL')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    os_ver = os.environ.get('OS')[-1]
    if to_version in ['6.4', '6.3']:
        tools_repo_url = os.environ.get('TOOLS_URL_RHEL7')
    activation_key = os.environ.get(
        'CAPSULE_AK', os.environ.get('RHEV_CAPSULE_AK'))
    if activation_key is None:
        logger.warning(
            'The AK name is not provided for Capsule upgrade! Aborting...')
        sys.exit(1)
    # Set hammer configuration
    set_hammer_config()
    cv_name, env_name = hammer_determine_cv_and_env_from_ak(
        activation_key, '1')
    # Fix dead pulp tasks
    if os_ver == '6':
        run('for i in pulp_resource_manager pulp_workers pulp_celerybeat; '
            'do service $i restart; done')
    # If custom capsule repo is not given then
    # enable capsule repo from Redhat Repositories
    product_name = 'capsule6_latest' if capsule_repo \
        else 'Red Hat Satellite Capsule'
    repo_name = 'capsule6_latest_repo' if capsule_repo \
        else 'Red Hat Satellite Capsule {0} (for RHEL {1} Server) ' \
        '(RPMs)'.format(to_version, os_ver)
    try:
        if capsule_repo:
            # Check if the product of latest capsule repo is already created,
            # if not create one and attach the subscription to existing AK
            get_attribute_value(hammer(
                'product list --organization-id 1'), product_name, 'name')
            # If keyError is not thrown as if the product is created already
            logger.info(
                'The product for latest Capsule repo is already created!')
            logger.info('Attaching that product subscription to capsule ....')
        else:
            # In case of CDN Upgrade, the capsule repo has to be resynced
            # and needs to publich/promote those contents
            raise KeyError
    except KeyError:
        # If latest capsule repo is not created already(Fresh Upgrade),
        # So create new....
        if to_version in ['6.4', '6.3']:
            (
                rhscl_prd,
                rhscl_repo_name,
                rhscl_label,
                rh7server_prd,
                rh7server_repo_name,
                rh7server_label
            ) = sync_rh_repos_to_satellite()
            if tools_repo_url:
                capsule_tools = 'Capsule Tools Product'
                capsule_tools_repo = 'Capsule Tools Repo'
                hammer_product_create(capsule_tools, '1')
                time.sleep(2)
                hammer_repository_create(
                    capsule_tools_repo, '1', capsule_tools, tools_repo_url)
            else:
                tools_prd = 'Red Hat Enterprise Linux Server'
                tools_repo = 'Red Hat Satellite Tools {0} ' \
                             '(for RHEL {1} Server) (RPMs)'.format(to_version,
                                                                   os_ver
                                                                   )
                tools_label = 'rhel-{0}-server-satellite-tools-{1}-' \
                              'rpms'.format(os_ver, to_version)
                hammer_repository_set_enable(
                    tools_repo, tools_prd, '1', 'x86_64')
                time.sleep(5)
            hammer_repository_synchronize(capsule_tools_repo,
                                          '1',
                                          capsule_tools
                                          )
            hammer_content_view_add_repository(
                cv_name, '1', rhscl_prd, rhscl_repo_name)
            hammer_content_view_add_repository(
                cv_name, '1', rh7server_prd, rh7server_repo_name)
            hammer_content_view_add_repository(
                cv_name, '1', capsule_tools, capsule_tools_repo)
            hammer_activation_key_content_override(
                activation_key, rhscl_label, '1', '1')
            hammer_activation_key_content_override(
                activation_key, rh7server_label, '1', '1')
            if tools_repo_url:
                hammer_activation_key_add_subscription(
                    activation_key, '1', capsule_tools)
            else:
                hammer_activation_key_content_override(
                    activation_key, tools_label, '1', '1')
        if capsule_repo:
            hammer_product_create(product_name, '1')
            time.sleep(2)
            hammer_repository_create(
                repo_name, '1', product_name, capsule_repo)
        else:
            hammer_repository_set_enable(
                repo_name, product_name, '1', 'x86_64')
            repo_name = repo_name.replace('(', '').replace(')', '') + ' x86_64'
        hammer_repository_synchronize(repo_name, '1', product_name)
        # Add repos to CV
        hammer_content_view_add_repository(
            cv_name, '1', product_name, repo_name)
        hammer_content_view_publish(cv_name, '1')
        # Promote cv
        lc_env_id = get_attribute_value(
            hammer('lifecycle-environment list --organization-id 1 '
                   '--name {}'.format(env_name)), env_name, 'id')
        cv_version_data = hammer(
            'content-view version list --content-view {} '
            '--organization-id 1'.format(cv_name))
        latest_cv_ver = sorted([float(data['name'].split(
            '{} '.format(cv_name))[1]) for data in cv_version_data]).pop()
        cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format(
            cv_name, latest_cv_ver), 'id')
        hammer_content_view_promote_version(
            cv_name, cv_ver_id, lc_env_id, '1',
            False if from_version == '6.0' else True)
        if capsule_repo:
            hammer_activation_key_add_subscription(
                activation_key, '1', product_name)
        else:
            label = 'rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
                os_ver, to_version)
            hammer_activation_key_content_override(
                activation_key, label, '1', '1')
    # Add this latest capsule repo to capsules to perform upgrade later
    # If downstream capsule, Update AK with latest capsule repo subscription
    if capsule_repo:
        for capsule in capsules:
            if from_version == '6.1':
                subscription_id = get_product_subscription_id(
                    '1', product_name)
                execute(
                    attach_subscription_to_host_from_content_host,
                    subscription_id,
                    host=capsule)
            else:
                attach_subscription_to_host_from_satellite(
                    '1', product_name, capsule)
    else:
        # In upgrade to CDN capsule, the subscription will be already attached
        pass
コード例 #16
0
ファイル: satellite.py プロジェクト: jyejare/automation-tools
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 sync_tools_repos_to_upgrade(client_os, hosts):
    """This syncs tools repo in Satellite server and also attaches
    the new tools repo subscription onto each client

    :param string client_os: The client OS of which tools repo to be synced
        e.g: rhel6, rhel7
    :param list hosts: The list of capsule hostnames to which new capsule
        repo subscription will be attached

    Following environment variable affects this function:

    TOOLS_URL_{client_os}
        The url of tools repo from latest satellite compose.
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'

    Personal Upgrade Env Vars:

    CLIENT_AK
        The ak_name attached to subscription of client

    Rhevm upgrade Env Vars:

    RHEV_CLIENT_AK
        The AK name used in client subscription
    """
    client_os = client_os.upper()
    tools_repo_url = os.environ.get('TOOLS_URL_{}'.format(client_os))
    if tools_repo_url is None:
        logger.warning('The Tools Repo URL for {} is not provided '
                       'to perform Client Upgrade !'.format(client_os))
        sys.exit(1)
    activation_key = os.environ.get(
        'CLIENT_AK_{}'.format(client_os),
        os.environ.get('RHEV_CLIENT_AK_{}'.format(client_os))
    )
    if activation_key is None:
        logger.warning('The AK details are not provided for {0} Client '
                       'upgrade!'.format(client_os))
        sys.exit(1)
    # Set hammer configuration
    set_hammer_config()
    cv_name, env_name = hammer_determine_cv_and_env_from_ak(
        activation_key, '1')
    tools_product = 'tools6_latest_{}'.format(client_os)
    tools_repo = 'tools6_latest_repo_{}'.format(client_os)
    # adding sleeps in between to avoid race conditions
    time.sleep(20)
    hammer_product_create(tools_product, '1')
    time.sleep(10)
    hammer_repository_create(tools_repo, '1', tools_product, tools_repo_url)
    time.sleep(10)
    hammer_repository_synchronize(tools_repo, '1', tools_product)
    hammer_content_view_add_repository(cv_name, '1', tools_product, tools_repo)
    hammer_content_view_publish(cv_name, '1')
    # Promote cv
    lc_env_id = get_attribute_value(
        hammer('lifecycle-environment list --organization-id 1 '
               '--name {}'.format(env_name)), env_name, 'id')
    cv_version_data = hammer(
        'content-view version list --content-view {} '
        '--organization-id 1'.format(cv_name))
    latest_cv_ver = sorted([float(data['name'].split(
        '{} '.format(cv_name))[1]) for data in cv_version_data]).pop()
    cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format(
        cv_name, latest_cv_ver), 'id')
    hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1')
    # Add new product subscriptions to AK
    hammer_activation_key_add_subscription(activation_key, '1', tools_product)
    # Add this latest tools repo to hosts to upgrade
    for host in hosts:
        if os.environ.get('FROM_VERSION') in ['6.0', '6.1']:
            subscription_id = get_product_subscription_id('1', tools_product)
            # If not User Hosts then, attach sub to dockered clients
            if not all([
                os.environ.get('CLIENT6_HOSTS'),
                os.environ.get('CLIENT7_HOSTS')
            ]):
                docker_vm = os.environ.get('DOCKER_VM')
                execute(
                    attach_subscription_to_host_from_content_host,
                    subscription_id,
                    True,
                    host,
                    host=docker_vm)
            # Else, Attach subs to user hosts
            else:
                execute(
                    attach_subscription_to_host_from_content_host,
                    subscription_id,
                    host=host)
        else:
            attach_subscription_to_host_from_satellite(
                '1', tools_product, host)
コード例 #18
0
def sync_capsule_repos_to_upgrade(capsules):
    """This syncs capsule repo in Satellite server and also attaches
    the capsule repo subscription to each capsule

    :param list capsules: The list of capsule hostnames to which new capsule
    repo subscription will be attached

    Following environment variable affects this function:

    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'

    Personal Upgrade Env Vars:

    CAPSULE_SUBSCRIPTION
        List of cv_name, environment, ak_name attached to subscription of
        capsule in defined sequence

    Rhevm upgrade Env Vars:

    RHEV_CAPSULE_CV
        The CV name used in capsule subscription
    RHEV_CAPSULE_ENVIRONMENT
        The environment name used in capsule subscription
    RHEV_CAPSULE_AK
        The AK name used in capsule subscription
    """
    capsule_repo = os.environ.get('CAPSULE_URL')
    if capsule_repo is None:
        print('The Capsule repo URL is not provided '
              'to perform Capsule Upgrade in feature!')
        sys.exit(1)
    cv_name, env_name, ak_name = [
        os.environ.get(env_var)
        for env_var in ('RHEV_CAPSULE_CV', 'RHEV_CAPSULE_ENVIRONMENT',
                        'RHEV_CAPSULE_AK')
    ]
    details = os.environ.get('CAPSULE_SUBSCRIPTION')
    if details is not None:
        cv_name, env_name, ak_name = [
            item.strip() for item in details.split(',')
        ]
    elif not all([cv_name, env_name, ak_name]):
        print('Error! The CV, Env and AK details are not provided for Capsule'
              'upgrade!')
        sys.exit(1)
    set_hammer_config()
    # Create product capsule
    hammer_product_create('capsule6_latest', '1')
    time.sleep(2)
    hammer_repository_create('capsule6_latest_repo', '1', 'capsule6_latest',
                             capsule_repo)
    hammer_repository_synchronize('capsule6_latest_repo', '1',
                                  'capsule6_latest')
    # Add repos to CV
    hammer_content_view_add_repository(cv_name, '1', 'capsule6_latest',
                                       'capsule6_latest_repo')
    hammer_content_view_publish(cv_name, '1')
    # Promote cv
    lc_env_id = get_attribute_value(
        hammer('lifecycle-environment list --organization-id 1 '
               '--name {}'.format(env_name)), env_name, 'id')
    cv_version_data = hammer('content-view version list --content-view {} '
                             '--organization-id 1'.format(cv_name))
    latest_cv_ver = sorted([
        float(data['name'].split('{} '.format(cv_name))[1])
        for data in cv_version_data
    ]).pop()
    cv_ver_id = get_attribute_value(cv_version_data,
                                    '{0} {1}'.format(cv_name,
                                                     latest_cv_ver), 'id')
    hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1')
    # Add new product subscriptions to AK
    hammer_activation_key_add_subscription(ak_name, '1', 'capsule6_latest')
    # Add this latest capsule repo to capsules to upgrade
    for capsule in capsules:
        if os.environ.get('FROM_VERSION') == '6.1':
            subscription_id = get_product_subscription_id(
                '1', 'capsule6_latest')
            execute(attach_subscription_to_host_from_content_host,
                    subscription_id,
                    host=capsule)
        else:
            attach_subscription_to_host_from_satellite('1', 'capsule6_latest',
                                                       capsule)
コード例 #19
0
ファイル: tasks.py プロジェクト: jyejare/automation-tools
def sync_tools_repos_to_upgrade(client_os, hosts):
    """This syncs tools repo in Satellite server and also attaches
    the new tools repo subscription onto each client

    :param string client_os: The client OS of which tools repo to be synced
        e.g: rhel6, rhel7
    :param list hosts: The list of capsule hostnames to which new capsule
        repo subscription will be attached

    Following environment variable affects this function:

    TOOLS_URL_{client_os}
        The url of tools repo from latest satellite compose.
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'

    Personal Upgrade Env Vars:

    CLIENT_AK
        The ak_name attached to subscription of client

    Rhevm upgrade Env Vars:

    RHEV_CLIENT_AK
        The AK name used in client subscription
    """
    client_os = client_os.upper()
    tools_repo_url = os.environ.get('TOOLS_URL_{}'.format(client_os))
    if tools_repo_url is None:
        logger.warning('The Tools Repo URL for {} is not provided '
                       'to perform Client Upgrade !'.format(client_os))
        sys.exit(1)
    activation_key = os.environ.get(
        'CLIENT_AK_{}'.format(client_os),
        os.environ.get('RHEV_CLIENT_AK_{}'.format(client_os))
    )
    if activation_key is None:
        logger.warning('The AK details are not provided for {0} Client '
                       'upgrade!'.format(client_os))
        sys.exit(1)
    # Set hammer configuration
    set_hammer_config()
    cv_name, env_name = hammer_determine_cv_and_env_from_ak(
        activation_key, '1')
    tools_product = 'tools6_latest_{}'.format(client_os)
    tools_repo = 'tools6_latest_repo_{}'.format(client_os)
    # adding sleeps in between to avoid race conditions
    time.sleep(20)
    hammer_product_create(tools_product, '1')
    time.sleep(10)
    hammer_repository_create(tools_repo, '1', tools_product, tools_repo_url)
    time.sleep(10)
    hammer_repository_synchronize(tools_repo, '1', tools_product)
    hammer_content_view_add_repository(cv_name, '1', tools_product, tools_repo)
    hammer_content_view_publish(cv_name, '1')
    # Promote cv
    lc_env_id = get_attribute_value(
        hammer('lifecycle-environment list --organization-id 1 '
               '--name {}'.format(env_name)), env_name, 'id')
    cv_version_data = hammer(
        'content-view version list --content-view {} '
        '--organization-id 1'.format(cv_name))
    latest_cv_ver = sorted([float(data['name'].split(
        '{} '.format(cv_name))[1]) for data in cv_version_data]).pop()
    cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format(
        cv_name, latest_cv_ver), 'id')
    hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1')
    # Add new product subscriptions to AK
    hammer_activation_key_add_subscription(activation_key, '1', tools_product)
    # Add this latest tools repo to hosts to upgrade
    for host in hosts:
        if os.environ.get('FROM_VERSION') in ['6.0', '6.1']:
            subscription_id = get_product_subscription_id('1', tools_product)
            # If not User Hosts then, attach sub to dockered clients
            if not all([
                os.environ.get('CLIENT6_HOSTS'),
                os.environ.get('CLIENT7_HOSTS')
            ]):
                docker_vm = os.environ.get('DOCKER_VM')
                execute(
                    attach_subscription_to_host_from_content_host,
                    subscription_id,
                    True,
                    host,
                    host=docker_vm)
            # Else, Attach subs to user hosts
            else:
                execute(
                    attach_subscription_to_host_from_content_host,
                    subscription_id,
                    host=host)
        else:
            attach_subscription_to_host_from_satellite(
                '1', tools_product, host)
コード例 #20
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')
コード例 #21
0
from automation_tools.satellite6.hammer import set_hammer_config
from fabric.api import env
from robottelo.test import TestCase, settings

# Fabric Config setup
TestCase.setUpClass()
env.host_string = settings.server.hostname
env.user = '******'

# Hammer Config Setup
set_hammer_config()
コード例 #22
0
ファイル: tasks.py プロジェクト: omaciel/automation-tools
def sync_tools_repos_to_upgrade(client_os, hosts):
    """This syncs tools repo in Satellite server and also attaches
    the new tools repo subscription onto each client

    :param string client_os: The client OS of which tools repo to be synced
        e.g: rhel6, rhel7
    :param list hosts: The list of capsule hostnames to which new capsule
        repo subscription will be attached

    Following environment variable affects this function:

    TOOLS_URL_{client_os}
        The url of tools repo from latest satellite compose.
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'

    Personal Upgrade Env Vars:

    CLIENT_SUBSCRIPTION
        List of cv_name, environment, ak_name attached to subscription of
        client in defined sequence

    Rhevm upgrade Env Vars:

    RHEV_CLIENT_CV
        The CV name used in client subscription
    RHEV_CLIENT_ENVIRONMENT
        The environment name used in client subscription
    RHEV_CLIENT_AK
        The AK name used in client subscription
    """
    client_os = client_os.upper()
    tools_repo = os.environ.get('TOOLS_URL_{}'.format(client_os))
    if tools_repo is None:
        print('The Tools Repo URL for {} is not provided '
              'to perform Client Upgrade !'.format(client_os))
        sys.exit(1)
    cv_name, env_name, ak_name = [
        os.environ.get(env_var)
        for env_var in (
            'RHEV_CLIENT_CV', 'RHEV_CLIENT_ENVIRONMENT', 'RHEV_CLIENT_AK')
    ]
    details = os.environ.get('CLIENT_SUBSCRIPTION')
    if details is not None:
        cv_name, env_name, ak_name = [
            item.strip() for item in details.split(',')]
    elif not all([cv_name, env_name, ak_name]):
        print('Error! The CV, Env and AK details are not provided for Client'
              'upgrade!')
        sys.exit(1)
    # Set hammer configuration
    set_hammer_config()
    hammer_product_create('tools6_latest', '1')
    time.sleep(2)
    hammer_repository_create(
        'tools6_latest_repo', '1', 'tools6_latest', tools_repo)
    hammer_repository_synchronize(
        'tools6_latest_repo', '1', 'tools6_latest')
    hammer_content_view_add_repository(
        cv_name, '1', 'tools6_latest', 'tools6_latest_repo')
    hammer_content_view_publish(cv_name, '1')
    # Promote cv
    lc_env_id = get_attribute_value(
        hammer('lifecycle-environment list --organization-id 1 '
               '--name {}'.format(env_name)), env_name, 'id')
    cv_version_data = hammer(
        'content-view version list --content-view {} '
        '--organization-id 1'.format(cv_name))
    latest_cv_ver = sorted([float(data['name'].split(
        '{} '.format(cv_name))[1]) for data in cv_version_data]).pop()
    cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format(
        cv_name, latest_cv_ver), 'id')
    hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1')
    # Add new product subscriptions to AK
    hammer_activation_key_add_subscription(ak_name, '1', 'tools6_latest')
    # Add this latest tools repo to hosts to upgrade
    for host in hosts:
        attach_subscription_to_host('1', 'tools6_latest', host)
コード例 #23
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]
    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
    set_hammer_config()
    hammer('ping')
    run('katello-service status', warn_only=True)
コード例 #24
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']:
        logger.warning('Wrong Satellite Version Provided to upgrade to. '
                       'Provide one of 6.1, 6.2, 6.3, 6.4')
        sys.exit(1)
    major_ver = distro_info()[1]
    if os.environ.get('PERFORM_FOREMAN_MAINTAIN_UPGRADE') == 'true' \
            and os.environ.get('OS') == 'rhel7' and to_version != '6.4':
        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)))
    set_hammer_config()
    # Rebooting the satellite for kernel update if any
    reboot(180)
    host_ssh_availability_check(env.get('satellite_host'))
    # Test the Upgrade is successful
    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')
コード例 #25
0
 def setUp(self):
     hammer.set_hammer_config()
     env.host_string = self.sat_host
     env.user = '******'
コード例 #26
0
ファイル: satellite.py プロジェクト: san7ket/automation-tools
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)
コード例 #27
0
class Scenario_capsule_sync(TestCase):
    """The test class contains pre-upgrade and post-upgrade scenarios to test if
    package added to satellite preupgrade is synced to capsule post upgrade.

    Test Steps:

    1. Before Satellite upgrade, Sync a repo/rpm in satellite.
    2. Upgrade satellite/capsule.
    3. Run capsule sync post upgrade.
    4. Check if the repo/rpm is been synced to capsule.

    """
    cls_name = 'Scenario_capsule_sync'
    sat_host = get_satellite_host()
    env.host_string = sat_host
    env.user = '******'
    hammer.set_hammer_config()
    repo_name = 'capsulesync_TestRepo_' + cls_name
    repo_path = '/var/www/html/pub/preupgradeCapSync_repo/'
    rpm_name = rpm1.split('/')[-1]
    prod_name = 'Scenario_preUpgradeCapSync_' + cls_name
    activation_key = os.environ.get('CAPSULE_AK',
                                    os.environ.get('RHEV_CAPSULE_AK'))
    cv_name = 'Scenario_precapSync_' + cls_name
    _, env_name = hammer.hammer_determine_cv_and_env_from_ak(
        activation_key, '1')
    org_id = '1'
    repo_url = 'http://' + sat_host + '/pub/preupgradeCapSync_repo/'

    def create_repo(self):
        """ Creates a custom yum repository, that will be synced to satellite
        and later to capsule from satellite
        """
        run('rm -rf {}'.format(self.repo_path))
        run('mkdir {}'.format(self.repo_path))
        run('wget {0} -P {1}'.format(rpm1, self.repo_path))
        # Renaming custom rpm to preRepoSync.rpm
        run('createrepo --database {0}'.format(self.repo_path))

    @pre_upgrade
    def test_pre_user_scenario_capsule_sync(self):
        """Pre-upgrade scenario that creates and sync repository with
        rpm in satellite which will be synced in post upgrade scenario.


        :id: preupgrade-eb8970fa-98cc-4a99-99fb-1c12c4e319c9

        :steps:
            1. Before Satellite upgrade, Sync a repo/rpm in satellite.

        :expectedresults: The repo/rpm should be synced to satellite

         """
        self.create_repo()
        print hammer.hammer_product_create(self.prod_name, self.org_id)
        prod_list = hammer.hammer('product list --organization-id {}'.format(
            self.org_id))
        self.assertEqual(
            self.prod_name,
            hammer.get_attribute_value(prod_list, self.prod_name, 'name'))
        print hammer.hammer_repository_create(self.repo_name, self.org_id,
                                              self.prod_name, self.repo_url)
        repo_list = hammer.hammer(
            'repository list --product {0} --organization-id {1}'.format(
                self.prod_name, self.org_id))
        self.assertEqual(
            self.repo_name,
            hammer.get_attribute_value(repo_list, self.repo_name, 'name'))
        print hammer.hammer_repository_synchronize(self.repo_name, self.org_id,
                                                   self.prod_name)
        print hammer.hammer_content_view_create(self.cv_name, self.org_id)
        print hammer.hammer_content_view_add_repository(
            self.cv_name, self.org_id, self.prod_name, self.repo_name)
        print hammer.hammer_content_view_publish(self.cv_name, self.org_id)
        cv_ver = hammer.get_latest_cv_version(self.cv_name)
        env_data = hammer.hammer(
            'lifecycle-environment list --organization-id {0} '
            '--name {1}'.format(self.org_id, self.env_name))
        env_id = hammer.get_attribute_value(env_data, self.env_name, 'id')
        print hammer.hammer_content_view_promote_version(
            self.cv_name, cv_ver, env_id, self.org_id)
        global_dict = {self.__class__.__name__: {'rpm_name': self.rpm_name}}
        create_dict(global_dict)

    @post_upgrade
    def test_post_user_scenario_capsule_sync(self):
        """Post-upgrade scenario that sync capsule from satellite and then
        verifies if the repo/rpm of pre-upgrade scenario is synced to capsule


        :id: postupgrade-eb8970fa-98cc-4a99-99fb-1c12c4e319c9

        :steps:
            1. Run capsule sync post upgrade.
            2. Check if the repo/rpm is been synced to capsule.

        :expectedresults:
            1. The capsule sync should be successful
            2. The repos/rpms from satellite should be synced to satellite

         """
        cap_host = os.environ.get('RHEV_CAP_HOST',
                                  os.environ.get('CAPSULE_HOSTNAME'))
        cap_data = hammer.hammer('capsule list')
        cap_id = hammer.get_attribute_value(cap_data, cap_host, 'id')
        cap_info = {'id': cap_id, 'name': cap_host}
        org_data = hammer.hammer('organization list')
        org_name = hammer.get_attribute_value(org_data, int(self.org_id),
                                              'name')
        print hammer.sync_capsule_content(cap_info, async=False)
        result = execute(
            lambda: run('[ -f /var/lib/pulp/published/yum/http/repos/'
                        '{0}/{1}/{2}/custom/{3}/{4}/{5} ]; echo $?'.format(
                            org_name, self.env_name, self.cv_name, self.
                            prod_name, self.repo_name, self.rpm_name)),
            host=cap_host)[cap_host]
        self.assertEqual('0', result)
コード例 #28
0
ファイル: tasks.py プロジェクト: jyejare/automation-tools
def sync_capsule_repos_to_upgrade(capsules):
    """This syncs capsule repo in Satellite server and also attaches
    the capsule repo subscription to each capsule

    :param list capsules: The list of capsule hostnames to which new capsule
    repo subscription will be attached

    Following environment variable affects this function:

    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
        If not provided, capsule repo from Red Hat repositories will be enabled
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'
    TO_VERSION
        Upgradable Satellite version - To enable capsule repo
        e.g '6.1', '6.2'
    OS
        OS version to enable next version capsule repo
        e.g 'rhel7', 'rhel6'

    Personal Upgrade Env Vars:

    CAPSULE_AK
        The AK name used in capsule subscription

    Rhevm upgrade Env Vars:

    RHEV_CAPSULE_AK
        The AK name used in capsule subscription
    """
    logger.info('Syncing latest capsule repos in Satellite ...')
    capsule_repo = os.environ.get('CAPSULE_URL')
    from_version = os.environ.get('FROM_VERSION')
    to_version = os.environ.get('TO_VERSION')
    os_ver = os.environ.get('OS')[-1]
    activation_key = os.environ.get(
        'CAPSULE_AK', os.environ.get('RHEV_CAPSULE_AK'))
    if activation_key is None:
        logger.warning(
            'The AK name is not provided for Capsule upgrade! Aborting...')
        sys.exit(1)
    # Set hammer configuration
    set_hammer_config()
    cv_name, env_name = hammer_determine_cv_and_env_from_ak(
        activation_key, '1')
    # If custom capsule repo is not given then
    # enable capsule repo from Redhat Repositories
    product_name = 'capsule6_latest' if capsule_repo \
        else 'Red Hat Satellite Capsule'
    repo_name = 'capsule6_latest_repo' if capsule_repo \
        else 'Red Hat Satellite Capsule {0} (for RHEL {1} Server) ' \
        '(RPMs)'.format(to_version, os_ver)
    try:
        if capsule_repo:
            # Check if the product of latest capsule repo is already created,
            # if not create one and attach the subscription to existing AK
            get_attribute_value(hammer(
                'product list --organization-id 1'), product_name, 'name')
            # If keyError is not thrown as if the product is created already
            logger.info(
                'The product for latest Capsule repo is already created!')
            logger.info('Attaching that product subscription to capsule ....')
        else:
            # In case of CDN Upgrade, the capsule repo has to be resynced
            # and needs to publich/promote those contents
            raise KeyError
    except KeyError:
        # If latest capsule repo is not created already(Fresh Upgrade),
        # So create new....
        if capsule_repo:
            hammer_product_create(product_name, '1')
            time.sleep(2)
            hammer_repository_create(
                repo_name, '1', product_name, capsule_repo)
        else:
            hammer_repository_set_enable(
                repo_name, product_name, '1', 'x86_64')
            repo_name = repo_name.replace('(', '').replace(')', '') + ' x86_64'
        hammer_repository_synchronize(repo_name, '1', product_name)
        # Add repos to CV
        hammer_content_view_add_repository(
            cv_name, '1', product_name, repo_name)
        hammer_content_view_publish(cv_name, '1')
        # Promote cv
        lc_env_id = get_attribute_value(
            hammer('lifecycle-environment list --organization-id 1 '
                   '--name {}'.format(env_name)), env_name, 'id')
        cv_version_data = hammer(
            'content-view version list --content-view {} '
            '--organization-id 1'.format(cv_name))
        latest_cv_ver = sorted([float(data['name'].split(
            '{} '.format(cv_name))[1]) for data in cv_version_data]).pop()
        cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format(
            cv_name, latest_cv_ver), 'id')
        hammer_content_view_promote_version(
            cv_name, cv_ver_id, lc_env_id, '1',
            False if from_version == '6.0' else True)
        if capsule_repo:
            hammer_activation_key_add_subscription(
                activation_key, '1', product_name)
        else:
            label = 'rhel-{0}-server-satellite-capsule-{1}-rpms'.format(
                os_ver, to_version)
            hammer_activation_key_content_override(
                activation_key, label, '1', '1')
    # Add this latest capsule repo to capsules to perform upgrade later
    # If downstream capsule, Update AK with latest capsule repo subscription
    if capsule_repo:
        for capsule in capsules:
            if from_version == '6.1':
                subscription_id = get_product_subscription_id(
                    '1', product_name)
                execute(
                    attach_subscription_to_host_from_content_host,
                    subscription_id,
                    host=capsule)
            else:
                attach_subscription_to_host_from_satellite(
                    '1', product_name, capsule)
    else:
        # In upgrade to CDN capsule, the subscription will be already attached
        pass
コード例 #29
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')
コード例 #30
0
ファイル: tasks.py プロジェクト: omaciel/automation-tools
def sync_capsule_repos_to_upgrade(capsules):
    """This syncs capsule repo in Satellite server and also attaches
    the capsule repo subscription to each capsule

    :param list capsules: The list of capsule hostnames to which new capsule
    repo subscription will be attached

    Following environment variable affects this function:

    CAPSULE_URL
        The url for capsule repo from latest satellite compose.
    FROM_VERSION
        Current Satellite version - to differentiate default organization.
        e.g. '6.1', '6.0'

    Personal Upgrade Env Vars:

    CAPSULE_SUBSCRIPTION
        List of cv_name, environment, ak_name attached to subscription of
        capsule in defined sequence

    Rhevm upgrade Env Vars:

    RHEV_CAPSULE_CV
        The CV name used in capsule subscription
    RHEV_CAPSULE_ENVIRONMENT
        The environment name used in capsule subscription
    RHEV_CAPSULE_AK
        The AK name used in capsule subscription
    """
    capsule_repo = os.environ.get('CAPSULE_URL')
    if capsule_repo is None:
        print('The Capsule repo URL is not provided '
              'to perform Capsule Upgrade in feature!')
        sys.exit(1)
    cv_name, env_name, ak_name = [
        os.environ.get(env_var)
        for env_var in (
            'RHEV_CAPSULE_CV', 'RHEV_CAPSULE_ENVIRONMENT', 'RHEV_CAPSULE_AK')
    ]
    details = os.environ.get('CAPSULE_SUBSCRIPTION')
    if details is not None:
        cv_name, env_name, ak_name = [
            item.strip() for item in details.split(',')]
    elif not all([cv_name, env_name, ak_name]):
        print('Error! The CV, Env and AK details are not provided for Capsule'
              'upgrade!')
        sys.exit(1)
    set_hammer_config()
    # Create product capsule
    hammer_product_create('capsule6_latest', '1')
    time.sleep(2)
    hammer_repository_create(
        'capsule6_latest_repo', '1', 'capsule6_latest', capsule_repo)
    hammer_repository_synchronize(
        'capsule6_latest_repo', '1', 'capsule6_latest')
    # Add repos to CV
    hammer_content_view_add_repository(
        cv_name, '1', 'capsule6_latest', 'capsule6_latest_repo')
    hammer_content_view_publish(cv_name, '1')
    # Promote cv
    lc_env_id = get_attribute_value(
        hammer('lifecycle-environment list --organization-id 1 '
               '--name {}'.format(env_name)), env_name, 'id')
    cv_version_data = hammer(
        'content-view version list --content-view {} '
        '--organization-id 1'.format(cv_name))
    latest_cv_ver = sorted([float(data['name'].split(
        '{} '.format(cv_name))[1]) for data in cv_version_data]).pop()
    cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format(
        cv_name, latest_cv_ver), 'id')
    hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1')
    # Add new product subscriptions to AK
    hammer_activation_key_add_subscription(ak_name, '1', 'capsule6_latest')
    # Add this latest capsule repo to capsules to upgrade
    for capsule in capsules:
        attach_subscription_to_host('1', 'capsule6_latest', capsule)