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)
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])
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)
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
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)
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 """ _, 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) 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), 'label') 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, 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)
class Scenario_capsule_sync_2(TestCase): """ The test class contains pre-upgrade and post-upgrade scenarios to test if package added postupgrade in satellite is snyced to capsule post upgrade. Test Steps: 1. Upgrade Satellite and Capsule. 2. Sync a repo/rpm in satellite. 3. Run capsule sync. 4. Check if the repo/rpm is been synced to capsule. """ cls_name = 'Scenario_capsule_sync_2' 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/postupgradeCapSync_repo/' rpm_name = rpm2.split('/')[-1] prod_name = 'Scenario_postUpgradeCapSync_' + cls_name activation_key = os.environ.get('CAPSULE_AK', os.environ.get('RHEV_CAPSULE_AK')) cv_name = 'Scenario_postcapSync_' + cls_name _, env_name = hammer.hammer_determine_cv_and_env_from_ak( activation_key, '1') org_id = '1' repo_url = 'http://' + sat_host + '/pub/postupgradeCapSync_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(rpm2, self.repo_path)) # Renaming custom rpm to preRepoSync.rpm run('createrepo --database {0}'.format(self.repo_path)) @post_upgrade 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_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)
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)
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
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])