Esempio n. 1
0
    def test_post_user_scenario_capsule_sync_yum_repo(self, request,
                                                      default_sat,
                                                      default_org):
        """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

        """
        request.addfinalizer(lambda: cleanup(content_view, repo, product))
        repo_name = gen_string('alpha')
        rpm_name = rpm2.split('/')[-1]
        activation_key = (
            settings.upgrade.capsule_ak[settings.upgrade.os]
            or settings.upgrade.custom_capsule_ak[settings.upgrade.os])
        cap_host = settings.upgrade.capsule_hostname
        ak = default_sat.api.ActivationKey(organization=default_org.id).search(
            query={'search': f'name={activation_key}'})[0]
        ak_env = ak.environment.read()
        repo_url = f'http://{default_sat.hostname}/pub/{repo_name}/'
        product = default_sat.api.Product(organization=default_org.id).create()
        repo_path = f'/var/www/html/pub/{repo_name}/'
        create_repo(rpm2, repo_path)

        repo = default_sat.api.Repository(product=product.id,
                                          name=f'{repo_name}',
                                          url=repo_url).create()
        repo.sync()
        content_view = default_sat.api.ContentView(
            organization=default_org.id).create()
        content_view.repository = [repo]
        content_view = content_view.update(['repository'])
        content_view.publish()
        promote(content_view.read().version[0], ak_env.id)
        content_view_env = [env.id for env in content_view.read().environment]
        assert ak_env.id in content_view_env

        wait_untill_capsule_sync(cap_host)
        result = execute(
            lambda: run(
                f'[ -f /var/lib/pulp/published/yum/http/repos/{default_org.label}/{ak_env.name}/'
                f'{content_view.name}/custom/{product.name}/{repo_name}/Packages/c/{rpm_name} ];'
                f' echo $?'),
            host=cap_host,
        )[cap_host]
        assert '0' == result
Esempio n. 2
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

        """
        ak = entities.ActivationKey(organization=self.org_id).search(
            query={'search': 'name={}'.format(self.activation_key)})[0]
        ak_env = ak.environment.read()
        product = entities.Product(name=self.prod_name,
                                   organization=self.org_id).create()
        create_repo(rpm2, self.repo_path)
        repo = entities.Repository(product=product.id,
                                   name=self.repo_name,
                                   url=self.repo_url).create()
        repo.sync()
        content_view = entities.ContentView(name=self.cv_name,
                                            organization=self.org_id).create()
        content_view.repository = [repo]
        content_view = content_view.update(['repository'])
        content_view.publish()
        promote(content_view.read().version[0], ak_env.id)
        self.assertEqual(content_view.read().environment[-1].id, ak_env.id)
        wait_untill_capsule_sync(self.cap_host)
        org_name = (entities.Organization().search(
            query={'search': 'id={}'.format(self.org_id)})[0].label)
        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,
                            ak_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)
Esempio n. 3
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

        """
        ak = entities.ActivationKey(organization=self.org_id).search(
            query={'search': 'name={}'.format(self.activation_key)})[0]
        ak_env = ak.environment.read()
        product = entities.Product(
            name=self.prod_name, organization=self.org_id).create()
        self.create_repo()
        repo = entities.Repository(
            product=product.id, name=self.repo_name,
            url=self.repo_url).create()
        repo.sync()
        content_view = entities.ContentView(
            name=self.cv_name, organization=self.org_id).create()
        content_view.repository = [repo]
        content_view = content_view.update(['repository'])
        content_view.publish()
        promote(content_view.read().version[0], ak_env.id)
        self.assertEqual(content_view.read().environment[-1].id, ak_env.id)
        wait_untill_capsule_sync(self.cap_host)
        org_name = entities.Organization().search(
            query={'search': 'id={}'.format(self.org_id)})[0].label
        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, ak_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)
Esempio n. 4
0
def satellite_capsule_upgrade(cap_host, sat_host):
    """Upgrades capsule from existing version to latest version.

    :param string cap_host: Capsule hostname onto which the capsule upgrade
    will run
    :param string sat_host : Satellite hostname from which capsule certs are to
    be generated

    The following environment variables affect this command:

    CAPSULE_URL
        Optional, defaults to available capsule version in CDN.
        URL for capsule of latest compose to upgrade.
    FROM_VERSION
        Capsule current version, to disable repos while upgrading.
        e.g '6.1','6.0'
    TO_VERSION
        Capsule version to upgrade to and enable repos while upgrading.
        e.g '6.1','6.2'

    """
    logger.highlight('\n========== CAPSULE UPGRADE =================\n')
    # Check the capsule sync before upgrade.
    logger.info("Check the capsule sync after satellite upgrade to verify sync operation "
                "with n-1 combination")
    execute(capsule_sync, cap_host, host=sat_host)
    wait_untill_capsule_sync(cap_host)
    from_version = settings.upgrade.from_version
    to_version = settings.upgrade.to_version
    setup_capsule_firewall()
    major_ver = settings.upgrade.os[-1]
    ak_name = settings.upgrade.capsule_ak[settings.upgrade.os]
    run(f'subscription-manager register --org="Default_Organization" '
        f'--activationkey={ak_name} --force')
    logger.info(f"Activation key {ak_name} registered capsule's all available repository")
    run("subscription-manager repos --list")
    maintenance_repo = [RHEL_CONTENTS["maintenance"]["label"]]
    capsule_repos = [
        RHEL_CONTENTS["tools"]["label"],
        RHEL_CONTENTS["capsule"]["label"],
    ]
    with fabric_settings(warn_only=True):
        if settings.upgrade.distribution == "cdn":
            enable_disable_repo(enable_repos_name=capsule_repos + maintenance_repo)
        else:
            enable_disable_repo(disable_repos_name=maintenance_repo)

    if from_version != to_version:
        with fabric_settings(warn_only=True):
            enable_disable_repo(disable_repos_name=capsule_repos)
    with fabric_settings(warn_only=True):
        enable_disable_repo(enable_repos_name=[
            f"rhel-{major_ver}-server-ansible-{settings.upgrade.ansible_repo_version}-rpms"])

    if settings.upgrade.foreman_maintain_capsule_upgrade:
        foreman_maintain_package_update()
        if settings.upgrade.from_version == '6.10':
            # capsule certs regeneration required prior 6.11 ystream capsule upgrade BZ#2049893
            execute(capsule_certs_update, cap_host, host=sat_host)
        upgrade_using_foreman_maintain(sat_host=False)
    else:
        nonfm_upgrade(satellite_upgrade=False,
                      cap_host=cap_host,
                      sat_host=sat_host)
    # Rebooting the capsule for kernel update if any
    reboot(160)
    host_ssh_availability_check(cap_host)
    # Check if Capsule upgrade is success
    upgrade_validation(upgrade_type="capsule", satellite_services_action="restart")
    # Check the capsule sync after upgrade.
    logger.info("check the capsule sync after capsule upgrade")
    execute(capsule_sync, cap_host, host=sat_host)
    wait_untill_capsule_sync(cap_host)