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 """ 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(rpm1, 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) global_dict = {self.__class__.__name__: {'env_name': ak_env.name}} create_dict(global_dict)
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
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)
def test_post_scenario_custom_repo_check(self, default_sat): """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: postupgrade-5c793577-e573-46a7-abbf-b6fd1f20b06e :steps: 1. Remove old and add new package into custom repo. 2. Sync repo , publish the new version of cv. 3. Try to install new package on client. :expectedresults: Content host should able to pull the new rpm. """ entity_data = get_entity_data(self.__class__.__name__) client = entity_data.get('rhel_client') client_container_id = list(client.values())[0] content_view_name = entity_data.get('content_view_name') lce_id = entity_data.get('lce_id') lce_name = entity_data.get('lce_name') org_label = entity_data.get('org_label') prod_label = entity_data.get('prod_label') repo_name = entity_data.get('repo_name') create_repo(rpm2, FILE_PATH, post_upgrade=True, other_rpm=rpm1) repo = default_sat.api.Repository(name=repo_name).search()[0] repo.sync() content_view = default_sat.api.ContentView( name=content_view_name).search()[0] content_view.publish() content_view = default_sat.api.ContentView( name=content_view_name).search()[0] promote(content_view.version[-1], lce_id) result = default_sat.execute( 'ls /var/lib/pulp/published/yum/https/repos/{}/{}/{}/custom/{}/{}/' 'Packages/c/| grep {}'.format(org_label, lce_name, content_view.label, prod_label, repo.label, RPM2_NAME)) assert result.status == 0 assert len(result.stdout) install_or_update_package(client_hostname=client_container_id, package=RPM2_NAME)
def test_pre_user_scenario_capsule_sync(self, request): """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: 1. The repo/rpm should be synced to satellite 2. Activation key's environment id should be available in the content views environment id's list """ pre_test_name = request.node.name repo_name = f"{pre_test_name}_repo" repo_path = f'/var/www/html/pub/{repo_name}/' activation_key = ( settings.upgrade.capsule_ak[settings.upgrade.os] or settings.upgrade.custom_capsule_ak[settings.upgrade.os]) prod_name = f"{pre_test_name}_prod" cv_name = f"{pre_test_name}_cv" repo_url = f'http://{settings.server.hostname}/pub/{repo_name}' org = entities.Organization().search( query={'search': f'name="{DEFAULT_ORG}"'})[0] ak = entities.ActivationKey(organization=org.id).search( query={'search': f'name={activation_key}'})[0] ak_env = ak.environment.read() product = entities.Product(name=prod_name, organization=org.id).create() create_repo(rpm1, repo_path) repo = entities.Repository(product=product.id, name=repo_name, url=repo_url).create() repo.sync() content_view = entities.ContentView(name=cv_name, organization=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_id = [ env.id for env in content_view.read().environment ] assert ak_env.id in content_view_env_id
def test_pre_scenario_custom_repo_check(self): """This is pre-upgrade scenario test to verify if we can create a custom repository and consume it via content host. :id: preupgrade-eb6831b1-c5b6-4941-a325-994a09467478 :steps: 1. Before Satellite upgrade. 2. Create new Organization, Location. 3. Create Product, custom repo, cv. 4. Create activation key and add subscription. 5. Create a content host, register and install package on it. :expectedresults: 1. Custom repo is created. 2. Package is installed on Content host. """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() lce = entities.LifecycleEnvironment(organization=org).create() product = entities.Product(organization=org).create() create_repo(rpm1, FILE_PATH) repo = entities.Repository(product=product.id, url=CUSTOM_REPO).create() repo.sync() content_view = publish_content_view(org=org, repolist=repo) promote(content_view.version[0], lce.id) result = ssh.command( 'ls /var/lib/pulp/published/yum/https/repos/{}/{}/{}/custom/{}/{}/' 'Packages/b/|grep {}'.format(org.label, lce.name, content_view.label, product.label, repo.label, RPM1_NAME)) assert result.return_code == 0 assert len(result.stdout) >= 1 subscription = entities.Subscription(organization=org).search( query={'search': f'name={product.name}'})[0] ak = entities.ActivationKey(content_view=content_view, organization=org.id, environment=lce).create() ak.add_subscriptions(data={'subscription_id': subscription.id}) rhel7_client = dockerize(ak_name=ak.name, distro='rhel7', org_label=org.label) client_container_id = [value for value in rhel7_client.values()][0] client_container_name = [key for key in rhel7_client.keys()][0] host_location_update(client_container_name=client_container_name, logger_obj=logger, loc=loc) status = execute( docker_execute_command, client_container_id, 'subscription-manager identity', host=DOCKER_VM, )[DOCKER_VM] assert org.name in status install_or_update_package(client_hostname=client_container_id, package=RPM1_NAME) scenario_dict = { self.__class__.__name__: { 'content_view_name': content_view.name, 'lce_id': lce.id, 'lce_name': lce.name, 'org_label': org.label, 'prod_label': product.label, 'rhel_client': rhel7_client, 'repo_name': repo.name, } } create_dict(scenario_dict)