コード例 #1
0
    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_data = hammer.hammer('capsule list')
        cap_id = hammer.get_attribute_value(cap_data, self.cap_host, 'id')
        org_data = hammer.hammer('organization list')
        org_name = hammer.get_attribute_value(org_data, int(self.org_id),
                                              'name')
        print hammer.hammer(
            'capsule content synchronize --id {0}'.format(cap_id))
        result = execute(
            lambda: run('[ -f /var/lib/pulp/published/yum/http/repos/'
                        '{0}/{1}/{2}/custom/{3}/{4}/Packages/b/{5} ]; echo $?'.
                        format(org_name, self.env_name, self.cv_name, self.
                               prod_name, self.repo_name, self.rpm_name)),
            host=self.cap_host)[self.cap_host]
        self.assertEqual('0', result)
コード例 #2
0
ファイル: test_capsule.py プロジェクト: vijay8451/robottelo
    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

         """
        _, env_name = hammer.hammer_determine_cv_and_env_from_ak(
            self.activation_key, '1')
        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, env_name))
        env_id = hammer.get_attribute_value(env_data, 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__: {'env_name': env_name}}
        create_dict(global_dict)
コード例 #3
0
    def test_pre_user_scenario_bug_1429201(self):
        """This is pre-upgrade scenario test to verify if we can create a
         custom repository and consume it via client

         :id: 8fb8ec87-efa5-43ed-8cb3-960ef9cd6df2

         :steps:
             1. Create repository RepoFoo that you will later add to your
                Satellite. This repository should contain PackageFoo-1.0.rpm
             2. Install satellite 6.1
             3. Create custom product ProductFoo pointing to repository RepoFoo
             4. Sync RepoFoo
             5. Create content view CVFoo
             6. Add RepoFoo to CVFoo
             7. Publish version 1 of CVFoo

         :expectedresults: The client and product is created successfully

         :BZ: 1429201
         """
        self.create_repo()
        # End to End product + ak association
        print(hammer.hammer_product_create(self.prd_name, self.org_id))
        print(
            hammer.hammer_repository_create(self.repo_name, self.org_id,
                                            self.prd_name, self.custom_repo))
        print(
            hammer.hammer('lifecycle-environment create --name "{0}" '
                          '--organization-id {1} --prior-id "{2}"'.format(
                              self.lc_name, self.org_id, 1)))
        print(
            hammer.hammer_repository_synchronize(self.repo_name, self.org_id,
                                                 self.prd_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.prd_name,
                                                      self.repo_name))
        print(hammer.hammer_content_view_publish(self.cv_name, self.org_id))
        latest_repo_version = hammer.get_latest_cv_version(self.cv_name)
        lc_result = hammer.hammer('"{0}" info --name "{1}" --organization-id '
                                  '{2}'.format('lifecycle-environment',
                                               self.lc_name, self.org_id))
        lifecycle_id = hammer.get_attribute_value(lc_result, self.lc_name,
                                                  'id')
        print(
            hammer.hammer_content_view_promote_version(self.cv_name,
                                                       latest_repo_version,
                                                       lifecycle_id,
                                                       self.org_id))
        print(
            hammer.hammer_activation_key_create(self.ak_name, self.org_id,
                                                self.cv_name, self.lc_name))
        print(
            hammer.hammer_activation_key_add_subscription(
                self.ak_name, self.org_id, self.prd_name))
        time.sleep(5)
        # Creating a rhel7 vm and subscribing to AK
        container_ids = dockerize(self.ak_name, 'rhel7')
        # Subscription manager needs time to register
        execute(docker_wait_until_repo_list,
                list(container_ids.values())[0],
                host=self.docker_vm)
        result = execute(docker_execute_command,
                         list(container_ids.values())[0],
                         'yum list {0} | grep {0}'.format(
                             self.rpm1_name.split('-')[0]),
                         host=self.docker_vm)
        # Info on created entities to assert the test case using hammer info
        prd_info = hammer.hammer('"{0}" info --name "{1}" --organization-id '
                                 '{2}'.format('product', self.prd_name,
                                              self.org_id))
        self.assertEqual(
            self.prd_name,
            hammer.get_attribute_value(prd_info, self.prd_name, 'name'))
        self.assertIsNotNone(container_ids)
        self.assertIn(self.repo_name, list(result.values())[0])
        global_dict = {
            self.__class__.__name__: {
                'prd_name': self.prd_name,
                'ak_name': self.ak_name,
                'repo_name': self.repo_name,
                'container_ids': container_ids
            }
        }
        create_dict(global_dict)
コード例 #4
0
    def test_post_user_scenario_bug_1429201(self):
        """This is post-upgrade scenario test to verify if we can alter the
        created custom repository and satellite will be able to sync back
        the repo

        :id: 9415c3e5-4699-462f-81bc-4143d8b820f1

        :steps:
            1. Remove PackageFoo-1.0.rpm from RepoFoo
            2. Add PackageFoo-2.0.rpm to RepoFoo
            3. Sync RepoFoo
            4. Publish version 2 of CVFoo
            5. Delete version 1 of CVFoo
            6. run /etc/cron.weekly/katello-remove-orphans
            7. Subscribe ClientA to CVFoo
            8. Try to install PackageFoo-1.0.rpm on ClientA
            9. Notice that yum thinks it's there based on the repo metadata
               but then fails to download it with 404
            10. Try to install PackageFoo-2.0.rpm

        :expectedresults: The clients is present after upgrade and deleted
            rpm is unable to be fetched, while new rpm is pulled and installed
            on client

        :BZ: 1429201
        """
        entity_data = get_entity_data(self.__class__.__name__)
        run('wget {0} -P {1}'.format(rpm2, self.file_path))
        run('rm -rf {0}'.format(self.file_path + self.rpm1_name))
        run('createrepo --update {0}'.format(self.file_path))
        # get entities from pickle
        pkcl_ak_name = entity_data['ak_name']
        container_ids = entity_data['container_ids']
        repo_name = entity_data['repo_name']
        prd_name = entity_data['prd_name']
        cv_name, lc_name = hammer.hammer_determine_cv_and_env_from_ak(
            pkcl_ak_name, self.org_id)
        # Info on created entities to assert the test case using hammer info
        ak_info = hammer.hammer('"{0}" info --name "{1}" --organization-id '
                                '{2}'.format('activation-key', pkcl_ak_name,
                                             self.org_id))
        print(
            hammer.hammer_repository_synchronize(repo_name, self.org_id,
                                                 prd_name))
        print(hammer.hammer_content_view_publish(cv_name, self.org_id))
        latest_repo_version = hammer.get_latest_cv_version(cv_name)

        result = hammer.hammer('"{0}" info --name "{1}" --organization-id '
                               '{2}'.format('lifecycle-environment', lc_name,
                                            self.org_id))
        lifecycle_id = hammer.get_attribute_value(result, lc_name, 'id')
        print(
            hammer.hammer_content_view_promote_version(cv_name,
                                                       latest_repo_version,
                                                       lifecycle_id,
                                                       self.org_id))
        hammer.hammer('content-view remove --content-view-version-ids {0}'
                      ' --name "{1}" --organization-id {2}'.format(
                          latest_repo_version, cv_name, self.org_id))
        run('foreman-rake katello:delete_orphaned_content')
        execute(refresh_subscriptions_on_docker_clients,
                list(container_ids.values()),
                host=self.docker_vm)
        # Subscription manager needs time to register
        execute(docker_wait_until_repo_list,
                list(container_ids.values())[0],
                host=self.docker_vm)
        result_fail = execute(docker_execute_command,
                              list(container_ids.values())[0],
                              'yum list {0} | grep {0}'.format(
                                  self.rpm1_name.split('-')[0]),
                              quiet=True,
                              host=self.docker_vm)  # should be error
        result_pass = execute(docker_execute_command,
                              list(container_ids.values())[0],
                              'yum install -y {0}'.format(
                                  self.rpm2_name.split('-')[0]),
                              host=self.docker_vm)  # should be successful
        self.assertEqual(
            pkcl_ak_name,
            hammer.get_attribute_value(ak_info, pkcl_ak_name, 'name'))
        self.assertIsNotNone(container_ids)
        self.assertIn('Error', list(result_fail.values())[0])
        self.assertIn('Complete', list(result_pass.values())[0])
コード例 #5
0
    def test_post_user_scenario_capsule_sync_2(self):
        """Post-upgrade scenario that creates and sync repository with
        rpm, sync capsule with satellite and verifies if the repo/rpm in
        satellite is synced to capsule.


        :id: postupgrade-7c1d3441-3e8d-4ac2-8102-30e18274658c

        :steps:
            1. Post Upgrade , Sync a repo/rpm in satellite.
            2. Run capsule sync.
            3. Check if the repo/rpm is been synced to capsule.

        :expectedresults:
            1. The repo/rpm should be synced to satellite
            2. Capsule sync should be successful
            3. The repo/rpm from satellite should be synced to capsule

        """
        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)
        cap_data = hammer.hammer('capsule list')
        cap_id = hammer.get_attribute_value(cap_data, self.cap_host, 'id')
        org_data = hammer.hammer('organization list')
        org_name = hammer.get_attribute_value(org_data, int(self.org_id),
                                              'name')
        print hammer.hammer(
            'capsule content synchronize --id {0}'.format(cap_id))
        result = execute(lambda: run(
            '[ -f /var/lib/pulp/published/yum/http/repos/'
            '{0}/{1}/{2}/custom/{3}/{4}/Packages/c/{5} ]; '
            'echo $?'.format(org_name, self.env_name, self.cv_name, self.
                             prod_name, self.repo_name, self.rpm_name)),
                         host=self.cap_host)[self.cap_host]
        self.assertEqual('0', result)
コード例 #6
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'))
コード例 #7
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
コード例 #8
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)
コード例 #9
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)
コード例 #10
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
コード例 #11
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)
コード例 #12
0
ファイル: test_contentview.py プロジェクト: jhutar/robottelo
    def test_pre_user_scenario_bug_1429201(self):
        """This is pre-upgrade scenario test to verify if we can create a
         custom repository and consume it via client

         :id: 8fb8ec87-efa5-43ed-8cb3-960ef9cd6df2

         :steps:
             1. Create repository RepoFoo that you will later add to your
                Satellite. This repository should contain PackageFoo-1.0.rpm
             2. Install satellite 6.1
             3. Create custom product ProductFoo pointing to repository RepoFoo
             4. Sync RepoFoo
             5. Create content view CVFoo
             6. Add RepoFoo to CVFoo
             7. Publish version 1 of CVFoo

         :expectedresults: The client and product is created successfully

         :BZ: 1429201
         """
        self.create_repo()
        # End to End product + ak association
        print(hammer.hammer_product_create(self.prd_name, self.org_id))
        print(hammer.hammer_repository_create(
            self.repo_name,
            self.org_id,
            self.prd_name,
            self.custom_repo))
        print(hammer.hammer(
            'lifecycle-environment create --name "{0}" '
            '--organization-id {1} --prior-id "{2}"'.format(
                self.lc_name, self.org_id, 1)))
        print(hammer.hammer_repository_synchronize(
            self.repo_name,
            self.org_id,
            self.prd_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.prd_name,
            self.repo_name))
        print(hammer.hammer_content_view_publish(self.cv_name, self.org_id))
        latest_repo_version = hammer.get_latest_cv_version(self.cv_name)
        lc_result = hammer.hammer(
            '"{0}" info --name "{1}" --organization-id '
            '{2}'.format('lifecycle-environment',
                         self.lc_name,
                         self.org_id
                         )
                                  )
        lifecycle_id = hammer.get_attribute_value(
            lc_result,
            self.lc_name,
            'id'
            )
        print(hammer.hammer_content_view_promote_version(
            self.cv_name,
            latest_repo_version,
            lifecycle_id,
            self.org_id
            ))
        print(hammer.hammer_activation_key_create(
            self.ak_name,
            self.org_id,
            self.cv_name,
            self.lc_name
            ))
        print(hammer.hammer_activation_key_add_subscription(
            self.ak_name,
            self.org_id,
            self.prd_name
            ))
        time.sleep(5)
        # Creating a rhel7 vm and subscribing to AK
        container_ids = dockerize(self.ak_name, 'rhel7')
        # Subscription manager needs time to register
        execute(docker_wait_until_repo_list,
                list(container_ids.values())[0],
                host=self.docker_vm)
        result = execute(
            docker_execute_command,
            list(container_ids.values())[0],
            'yum list {0} | grep {0}'.format(self.rpm1_name.split('-')[0]),
            host=self.docker_vm
            )
        # Info on created entities to assert the test case using hammer info
        prd_info = hammer.hammer(
            '"{0}" info --name "{1}" --organization-id '
            '{2}'.format('product', self.prd_name, self.org_id)
        )
        self.assertEqual(
            self.prd_name,
            hammer.get_attribute_value(prd_info, self.prd_name, 'name')
        )
        self.assertIsNotNone(container_ids)
        self.assertIn(self.repo_name, list(result.values())[0])
        global_dict = {self.__class__.__name__: {
            'prd_name': self.prd_name,
            'ak_name': self.ak_name,
            'repo_name': self.repo_name,
            'container_ids': container_ids
        }
        }
        create_dict(global_dict)
コード例 #13
0
ファイル: test_contentview.py プロジェクト: jhutar/robottelo
    def test_post_user_scenario_bug_1429201(self):
        """This is post-upgrade scenario test to verify if we can alter the
        created custom repository and satellite will be able to sync back
        the repo

        :id: 9415c3e5-4699-462f-81bc-4143d8b820f1

        :steps:
            1. Remove PackageFoo-1.0.rpm from RepoFoo
            2. Add PackageFoo-2.0.rpm to RepoFoo
            3. Sync RepoFoo
            4. Publish version 2 of CVFoo
            5. Delete version 1 of CVFoo
            6. run /etc/cron.weekly/katello-remove-orphans
            7. Subscribe ClientA to CVFoo
            8. Try to install PackageFoo-1.0.rpm on ClientA
            9. Notice that yum thinks it's there based on the repo metadata
               but then fails to download it with 404
            10. Try to install PackageFoo-2.0.rpm

        :expectedresults: The clients is present after upgrade and deleted
            rpm is unable to be fetched, while new rpm is pulled and installed
            on client

        :BZ: 1429201
        """
        entity_data = get_entity_data(self.__class__.__name__)
        run('wget {0} -P {1}'.format(rpm2, self.file_path))
        run('rm -rf {0}'.format(self.file_path + self.rpm1_name))
        run('createrepo --update {0}'.format(self.file_path))
        # get entities from pickle
        pkcl_ak_name = entity_data['ak_name']
        container_ids = entity_data['container_ids']
        repo_name = entity_data['repo_name']
        prd_name = entity_data['prd_name']
        cv_name, lc_name = hammer.hammer_determine_cv_and_env_from_ak(
            pkcl_ak_name,
            self.org_id
        )
        # Info on created entities to assert the test case using hammer info
        ak_info = hammer.hammer(
            '"{0}" info --name "{1}" --organization-id '
            '{2}'.format('activation-key', pkcl_ak_name, self.org_id)
        )
        print(hammer.hammer_repository_synchronize(
            repo_name,
            self.org_id,
            prd_name
        ))
        print(hammer.hammer_content_view_publish(cv_name, self.org_id))
        latest_repo_version = hammer.get_latest_cv_version(cv_name)

        result = hammer.hammer(
            '"{0}" info --name "{1}" --organization-id '
            '{2}'.format('lifecycle-environment', lc_name, self.org_id)
        )
        lifecycle_id = hammer.get_attribute_value(result, lc_name, 'id')
        print(hammer.hammer_content_view_promote_version(
            cv_name,
            latest_repo_version,
            lifecycle_id,
            self.org_id
        ))
        hammer.hammer(
            'content-view remove --content-view-version-ids {0}'
            ' --name "{1}" --organization-id {2}'.format(
                latest_repo_version,
                cv_name,
                self.org_id
            )
        )
        run('foreman-rake katello:delete_orphaned_content')
        execute(refresh_subscriptions_on_docker_clients,
                list(container_ids.values()),
                host=self.docker_vm
                )
        # Subscription manager needs time to register
        execute(docker_wait_until_repo_list,
                list(container_ids.values())[0],
                host=self.docker_vm)
        result_fail = execute(
            docker_execute_command,
            list(container_ids.values())[0],
            'yum list {0} | grep {0}'.format(self.rpm1_name.split('-')[0]),
            quiet=True,
            host=self.docker_vm
        )  # should be error
        result_pass = execute(
            docker_execute_command,
            list(container_ids.values())[0],
            'yum install -y {0}'.format(self.rpm2_name.split('-')[0]),
            host=self.docker_vm
        )  # should be successful
        self.assertEqual(
            pkcl_ak_name,
            hammer.get_attribute_value(ak_info, pkcl_ak_name, 'name')
        )
        self.assertIsNotNone(container_ids)
        self.assertIn('Error', list(result_fail.values())[0])
        self.assertIn('Complete', list(result_pass.values())[0])
コード例 #14
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)
コード例 #15
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)