示例#1
0
    def test_post_user_scenario_capsule_sync(
        self, request, dependent_scenario_name, target_sat, default_org
    ):
        """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

        """
        request.addfinalizer(lambda: cleanup(content_view, repo, product))
        pre_test_name = dependent_scenario_name
        rpm_name = rpm1.split('/')[-1]
        cap_host = settings.upgrade.capsule_hostname
        activation_key = (
            settings.upgrade.capsule_ak[settings.upgrade.os]
            or settings.upgrade.custom_capsule_ak[settings.upgrade.os]
        )
        ak = target_sat.api.ActivationKey(organization=default_org.id).search(
            query={'search': f'name={activation_key}'}
        )[0]
        repo = target_sat.api.Repository(organization=default_org.id).search(
            query={'search': f'name={pre_test_name}_repo'}
        )[0]
        product = target_sat.api.Product(organization=default_org.id).search(
            query={'search': f'name={pre_test_name}_prod'}
        )[0]
        env_name = ak.environment.read()
        org_name = env_name.organization.read_json()['label']

        content_view = target_sat.api.ContentView(organization=f'{default_org.id}').search(
            query={'search': f'name={pre_test_name}_cv'}
        )[0]
        capsule = target_sat.api.SmartProxy().search(query={'search': f'name={cap_host}'})[0]
        call_entity_method_with_timeout(
            target_sat.api.Capsule(id=capsule.id).content_sync, timeout=3600
        )
        result = execute(
            lambda: run(
                f'[ -f /var/lib/pulp/published/yum/http/repos/'
                f'{org_name}/{env_name.name}/{content_view.name}/custom/{pre_test_name}_prod/'
                f'{pre_test_name}_repo/Packages/b/{rpm_name} ]; echo $?'
            ),
            host=cap_host,
        )[cap_host]
        assert result == '0'
示例#2
0
 def setUpClass(cls):
     cls.sat_host = settings.server.hostname
     cls.cls_name = 'Scenario_capsule_sync'
     cls.cap_host = settings.upgrade.rhev_cap_host or settings.upgrade.capsule_hostname
     cls.repo_name = 'capsulesync_TestRepo_' + cls.cls_name
     cls.repo_path = '/var/www/html/pub/preupgradeCapSync_repo/'
     cls.rpm_name = rpm1.split('/')[-1]
     cls.prod_name = 'Scenario_preUpgradeCapSync_' + cls.cls_name
     cls.activation_key = settings.upgrade.rhev_capsule_ak or settings.upgrade.capsule_ak
     cls.cv_name = 'Scenario_precapSync_' + cls.cls_name
     cls.org_id = '1'
     cls.repo_url = 'http://{0}{1}'.format(cls.sat_host,
                                           '/pub/preupgradeCapSync_repo/')
示例#3
0
 def setUpClass(cls):
     cls.sat_host = settings.server.hostname
     cls.cls_name = 'Scenario_capsule_sync'
     cls.cap_host = os.environ.get('RHEV_CAP_HOST',
                                   os.environ.get('CAPSULE_HOSTNAME'))
     cls.repo_name = 'capsulesync_TestRepo_' + cls.cls_name
     cls.repo_path = '/var/www/html/pub/preupgradeCapSync_repo/'
     cls.rpm_name = rpm1.split('/')[-1]
     cls.prod_name = 'Scenario_preUpgradeCapSync_' + cls.cls_name
     cls.activation_key = os.environ.get('CAPSULE_AK',
                                         os.environ.get('RHEV_CAPSULE_AK'))
     cls.cv_name = 'Scenario_precapSync_' + cls.cls_name
     cls.org_id = '1'
     cls.repo_url = 'http://{0}{1}'.format(cls.sat_host,
                                           '/pub/preupgradeCapSync_repo/')
示例#4
0
 def setUpClass(cls):
     cls.sat_host = settings.server.hostname
     cls.cls_name = 'Scenario_capsule_sync'
     cls.cap_host = os.environ.get(
         'RHEV_CAP_HOST', os.environ.get('CAPSULE_HOSTNAME'))
     cls.repo_name = 'capsulesync_TestRepo_' + cls.cls_name
     cls.repo_path = '/var/www/html/pub/preupgradeCapSync_repo/'
     cls.rpm_name = rpm1.split('/')[-1]
     cls.prod_name = 'Scenario_preUpgradeCapSync_' + cls.cls_name
     cls.activation_key = os.environ.get(
         'CAPSULE_AK', os.environ.get('RHEV_CAPSULE_AK'))
     cls.cv_name = 'Scenario_precapSync_' + cls.cls_name
     cls.org_id = '1'
     cls.repo_url = 'http://{0}{1}'.format(
         cls.sat_host, '/pub/preupgradeCapSync_repo/')
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
    cap_host = os.environ.get('RHEV_CAP_HOST',
                              os.environ.get('CAPSULE_HOSTNAME'))
    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_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)