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_rh_repos_to_satellite(): """Task to sync Redhat Repositories to latest required during upgrade :returns tuple: RHSCL and Redhat 7 Server repo name, label name and product name """ # RHSCL rhscl_repo = 'Red Hat Software Collections RPMs for Red Hat ' \ 'Enterprise Linux 7 Server' rhscl_prd = 'Red Hat Software Collections for RHEL Server' rhscl_label = 'rhel-server-rhscl-7-rpms' rhscl_repo_name = 'Red Hat Software Collections RPMs for Red ' \ 'Hat Enterprise Linux 7 Server x86_64 7Server' # Red Hat Enterprise Linux 7 Server rh7server_repo = 'Red Hat Enterprise Linux 7 Server (RPMs)' rh7server_prd = 'Red Hat Enterprise Linux Server' rh7server_label = 'rhel-7-server-rpms' rh7server_repo_name = 'Red Hat Enterprise Linux 7 Server RPMs x86_64 ' \ '7Server' # Enable rhscl repository hammer('repository-set enable --name "{0}" ' '--product "{1}" ' '--organization-id 1 ' '--basearch "x86_64" ' '--releasever 7Server'.format(rhscl_repo, rhscl_prd) ) time.sleep(20) # Sync enabled Repo from cdn hammer_repository_synchronize(rhscl_repo_name, '1', rhscl_prd ) # Enable RHEL 7 Server repository hammer('repository-set enable --name "{0}" ' '--product "{1}" ' '--organization-id 1 ' '--basearch "x86_64" ' '--releasever 7Server'.format(rh7server_repo, rh7server_prd) ) time.sleep(20) # Sync enabled Repo from cdn hammer_repository_synchronize(rh7server_repo_name, '1', rh7server_prd ) # FixMe: If number of repository to be synced from CDN increases use dict return { rhscl_prd, rhscl_repo_name, rhscl_label, rh7server_prd, rh7server_repo_name, rh7server_label }
def delete_manifest(org_name): """ Delete manifest from satellite :param org_name: Organization name in satellite Usage: delete_manifest(self.org_name) """ # Sets hammer default configuration hammer.set_hammer_config() print hammer.hammer('subscription delete-manifest ' '--organization "{0}"'.format(org_name))
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 check_capsule(capsule_name): """Running capsule sync on external capsule""" set_hammer_config() if os.environ.get('TO_VERSION') in ['6.2', '6.3']: check = hammer( 'capsule refresh-features --name "{0}"'.format(capsule_name)) print check[u'message'] if check.return_code == 0: logger.info('Running Capsule sync') hammer('capsule content synchronize --name "{0}"'.format( capsule_name)) else: logger.info('Running Capsule sync') hammer('capsule content synchronize --name "{0}"'.format(capsule_name))
def upload_manifest(manifest_url, org_name): """ Upload manifest to satellite :param manifest_url: URL of manifest hosted over http :param org_name: Organization name in satellite Usage: upload_manifest(self.manifest_url, self.org_name) """ # Sets hammer default configuration hammer.set_hammer_config() run('wget {0} -O {1}'.format(manifest_url, '/manifest.zip')) print hammer.hammer('subscription upload --file {0} ' '--organization {1}'.format('/manifest.zip', org_name))
def capsule_sync(cap_host): """Run Capsule Sync as a part of job :param list cap_host: List of capsules to perform sync """ set_hammer_config() if os.environ.get('TO_VERSION') in ['6.2', '6.3', '6.4']: logger.info('Refreshing features for capsule host {0}'. format(cap_host)) print hammer('capsule refresh-features --name "{0}"'. format(cap_host)) logger.info('Running Capsule sync for capsule host {0}'. format(cap_host)) print hammer('capsule content synchronize --name {0}'.format(cap_host))
def test_pre_manifest_scenario_refresh(self): """Pre-upgrade scenario that upload and refresh manifest in satellite which will be refreshed in post upgrade scenario. :id: preupgrade-29b246aa-2c7f-49f4-870a-7a0075e184b1 :steps: 1. Before Satellite upgrade, upload and refresh manifest. :expectedresults: Manifest should upload and refresh successfully. """ org = entities.Organization(name=self.org_name).create() upload_manifest(self.manifest_url, org.name) history = hammer.hammer('subscription manifest-history' ' --organization {0}'.format(org.name)) self.assertIn("{0} file imported successfully.".format(org.name), history[0]['status message']) sub = entities.Subscription(organization=org) sub.refresh_manifest(data={'organization_id': org.id}) self.assertGreater(len(sub.search()), 0)
def test_post_manifest_scenario_refresh(self): """Post-upgrade scenario that verifies manifest refreshed successfully and deleted successfully. :id: postupgrade-29b246aa-2c7f-49f4-870a-7a0075e184b1 :steps: 1. Refresh manifest 2. Delete manifest :expectedresults: 1. The manifest should refresh and delete successfully. """ org = entities.Organization().search( query={'search': 'name={0}'.format(self.org_name)})[0] sub = entities.Subscription(organization=org) sub.refresh_manifest(data={'organization_id': org.id}) self.assertGreater(len(sub.search()), 0) delete_manifest(self.org_name) history = hammer.hammer('subscription manifest-history' ' --organization {0}'.format(self.org_name)) self.assertIn( "Subscriptions deleted by foreman_admin".format(self.org_name), history[0]['status message'])
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)
def satellite6_zstream_upgrade(): """Upgrades Satellite Server to its latest zStream version Note: For zstream upgrade both 'To' and 'From' version should be same FROM_VERSION Current satellite version which will be upgraded to latest version TO_VERSION Next satellite version to which satellite will be upgraded """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') from_version = os.environ.get('FROM_VERSION') to_version = os.environ.get('TO_VERSION') if not from_version == to_version: logger.warning('zStream Upgrade on Satellite cannot be performed as ' 'FROM and TO versions are not same!') sys.exit(1) base_url = os.environ.get('BASE_URL') # Setting yum stdout log level to be less verbose set_yum_debug_level() setup_satellite_firewall() major_ver = distro_info()[1] # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo disable_repos('*', silent=True) enable_repos('rhel-{0}-server-rpms'.format(major_ver)) enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver)) # If CDN upgrade then enable satellite latest version repo if base_url is None: enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version)) # Remove old custom sat repo for fname in os.listdir('/etc/yum.repos.d/'): if 'sat' in fname.lower(): os.remove('/etc/yum.repos.d/{}'.format(fname)) # Else, consider this as Downstream upgrade else: # Add Sat6 repo from latest compose satellite_repo = StringIO() satellite_repo.write('[sat6]\n') satellite_repo.write('name=satellite 6\n') satellite_repo.write('baseurl={0}\n'.format(base_url)) satellite_repo.write('enabled=1\n') satellite_repo.write('gpgcheck=0\n') put(local_path=satellite_repo, remote_path='/etc/yum.repos.d/sat6.repo') satellite_repo.close() # Check what repos are set run('yum repolist') # Stop katello services, except mongod run('katello-service stop') if to_version == '6.1': run('service-wait mongod start') run('yum clean all', warn_only=True) # Updating the packages again after setting sat6 repo logger.info('Updating system and satellite packages... ') preyum_time = datetime.now().replace(microsecond=0) update_packages(quiet=False) postyum_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for system and satellite packages update - ' '{}'.format(str(postyum_time-preyum_time))) # Rebooting the system to check the possible issues if kernal is updated if os.environ.get('RHEV_SAT_HOST'): reboot(120) if to_version == '6.1': # Stop the service again which started in restart # This step is not required with 6.2 upgrade as installer itself # stop all the services before upgrade run('katello-service stop') run('service-wait mongod start') # Running Upgrade preup_time = datetime.now().replace(microsecond=0) if to_version == '6.1': run('katello-installer --upgrade') else: run('satellite-installer --scenario satellite --upgrade') postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time-preup_time))) # Test the Upgrade is successful set_hammer_config() hammer('ping') run('katello-service status', warn_only=True) if os.environ.get('RUN_EXISTANCE_TESTS', 'false').lower() == 'true': logger.info('Setting up postupgrade datastore for existance tests') set_datastore('postupgrade')
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 satellite6_upgrade(): """Upgrades satellite from old version to latest version. The following environment variables affect this command: BASE_URL Optional, defaults to available satellite version in CDN. URL for the compose repository TO_VERSION Satellite version to upgrade to and enable repos while upgrading. e.g '6.1','6.2', '6.3' """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') to_version = os.environ.get('TO_VERSION') rhev_sat_host = os.environ.get('RHEV_SAT_HOST') base_url = os.environ.get('BASE_URL') if to_version not in ['6.1', '6.2', '6.3']: logger.warning('Wrong Satellite Version Provided to upgrade to. ' 'Provide one of 6.1, 6.2, 6.3') sys.exit(1) setup_satellite_firewall() run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo') logger.info('Updating system packages ... ') update_packages(quiet=True) # Rebooting the system to see possible errors if rhev_sat_host: reboot(160) # Setting Satellite to_version Repos major_ver = distro_info()[1] # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo disable_repos('*', silent=True) enable_repos('rhel-{0}-server-rpms'.format(major_ver)) enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver)) # If CDN upgrade then enable satellite latest version repo if base_url is None: enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version)) # Remove old custom sat repo for fname in os.listdir('/etc/yum.repos.d/'): if 'sat' in fname.lower(): os.remove('/etc/yum.repos.d/{}'.format(fname)) # Else, consider this as Downstream upgrade else: # Add Sat6 repo from latest compose satellite_repo = StringIO() satellite_repo.write('[sat6]\n') satellite_repo.write('name=satellite 6\n') satellite_repo.write('baseurl={0}\n'.format(base_url)) satellite_repo.write('enabled=1\n') satellite_repo.write('gpgcheck=0\n') put(local_path=satellite_repo, remote_path='/etc/yum.repos.d/sat6.repo') satellite_repo.close() # Check what repos are set run('yum repolist') # Stop katello services, except mongod run('katello-service stop') if to_version == '6.1': run('service-wait mongod start') run('yum clean all', warn_only=True) # Updating the packages again after setting sat6 repo logger.info('Updating satellite packages ... ') preyum_time = datetime.now().replace(microsecond=0) update_packages(quiet=False) postyum_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for satellite packages update - {}'.format( str(postyum_time - preyum_time))) # Rebooting the system again for possible errors # Only for RHEV based satellite and not for personal one if rhev_sat_host: reboot(160) if to_version == '6.1': # Stop the service again which started in restart # This step is not required with 6.2 upgrade as installer itself # stop all the services before upgrade run('katello-service stop') run('service-wait mongod start') # Running Upgrade preup_time = datetime.now().replace(microsecond=0) if to_version == '6.1': run('katello-installer --upgrade') else: run('satellite-installer --scenario satellite --upgrade') postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time - preup_time))) # Test the Upgrade is successful set_hammer_config() hammer('ping') run('katello-service status', warn_only=True) # Enable ostree feature only for rhel7 and sat6.2 if to_version == '6.2' and major_ver == 7: enable_ostree(sat_version='6.2') if os.environ.get('RUN_EXISTANCE_TESTS', 'false').lower() == 'true': logger.info('Setting up postupgrade datastore for existance tests..') set_datastore('postupgrade')
def satellite6_upgrade(): """Upgrades satellite from old version to latest version. The following environment variables affect this command: BASE_URL Optional, defaults to available satellite version in CDN. URL for the compose repository TO_VERSION Satellite version to upgrade to and enable repos while upgrading. e.g '6.1','6.2' """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') to_version = os.environ.get('TO_VERSION') rhev_sat_host = os.environ.get('RHEV_SAT_HOST') base_url = os.environ.get('BASE_URL') if to_version not in ['6.1', '6.2']: logger.warning('Wrong Satellite Version Provided to upgrade to. ' 'Provide one of 6.1, 6.2') sys.exit(1) # Setting yum stdout log level to be less verbose set_yum_debug_level() setup_satellite_firewall() run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo') logger.info('Updating system packages ... ') update_packages(quiet=True) # Rebooting the system to see possible errors if rhev_sat_host: reboot(160) # Setting Satellite to_version Repos major_ver = distro_info()[1] # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo disable_repos('*', silent=True) enable_repos('rhel-{0}-server-rpms'.format(major_ver)) enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver)) # If CDN upgrade then enable satellite latest version repo if base_url is None: enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version)) # Remove old custom sat repo for fname in os.listdir('/etc/yum.repos.d/'): if 'sat' in fname.lower(): os.remove('/etc/yum.repos.d/{}'.format(fname)) # Else, consider this as Downstream upgrade else: # Add Sat6 repo from latest compose satellite_repo = StringIO() satellite_repo.write('[sat6]\n') satellite_repo.write('name=satellite 6\n') satellite_repo.write('baseurl={0}\n'.format(base_url)) satellite_repo.write('enabled=1\n') satellite_repo.write('gpgcheck=0\n') put(local_path=satellite_repo, remote_path='/etc/yum.repos.d/sat6.repo') satellite_repo.close() # Check what repos are set run('yum repolist') # Stop katello services, except mongod run('katello-service stop') if to_version == '6.1': run('service-wait mongod start') run('yum clean all', warn_only=True) # Updating the packages again after setting sat6 repo logger.info('Updating satellite packages ... ') preyum_time = datetime.now().replace(microsecond=0) update_packages(quiet=False) postyum_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for satellite packages update - {}'.format( str(postyum_time-preyum_time))) # Rebooting the system again for possible errors # Only for RHEV based satellite and not for personal one if rhev_sat_host: reboot(160) if to_version == '6.1': # Stop the service again which started in restart # This step is not required with 6.2 upgrade as installer itself # stop all the services before upgrade run('katello-service stop') run('service-wait mongod start') # Running Upgrade preup_time = datetime.now().replace(microsecond=0) if to_version == '6.1': run('katello-installer --upgrade') else: run('satellite-installer --scenario satellite --upgrade') postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time-preup_time))) # Test the Upgrade is successful set_hammer_config() hammer('ping') run('katello-service status', warn_only=True) # Enable ostree feature only for rhel7 and sat6.2 if to_version == '6.2' and major_ver == '7': enable_ostree(sat_version='6.2') if os.environ.get('RUN_EXISTANCE_TESTS', 'false').lower() == 'true': logger.info('Setting up postupgrade datastore for existance tests..') set_datastore('postupgrade')
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)
def satellite6_zstream_upgrade(): """Upgrades Satellite Server to its latest zStream version Note: For zstream upgrade both 'To' and 'From' version should be same FROM_VERSION Current satellite version which will be upgraded to latest version TO_VERSION Next satellite version to which satellite will be upgraded """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') from_version = os.environ.get('FROM_VERSION') to_version = os.environ.get('TO_VERSION') if not from_version == to_version: logger.warning('zStream Upgrade on Satellite cannot be performed as ' 'FROM and TO versions are not same!') sys.exit(1) base_url = os.environ.get('BASE_URL') setup_satellite_firewall() major_ver = distro_info()[1] # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo disable_repos('*', silent=True) enable_repos('rhel-{0}-server-rpms'.format(major_ver)) enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver)) # If CDN upgrade then enable satellite latest version repo if base_url is None: enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version)) # Remove old custom sat repo for fname in os.listdir('/etc/yum.repos.d/'): if 'sat' in fname.lower(): os.remove('/etc/yum.repos.d/{}'.format(fname)) # Else, consider this as Downstream upgrade else: # Add Sat6 repo from latest compose satellite_repo = StringIO() satellite_repo.write('[sat6]\n') satellite_repo.write('name=satellite 6\n') satellite_repo.write('baseurl={0}\n'.format(base_url)) satellite_repo.write('enabled=1\n') satellite_repo.write('gpgcheck=0\n') put(local_path=satellite_repo, remote_path='/etc/yum.repos.d/sat6.repo') satellite_repo.close() # Check what repos are set run('yum repolist') # Stop katello services, except mongod run('katello-service stop') if to_version == '6.1': run('service-wait mongod start') run('yum clean all', warn_only=True) # Updating the packages again after setting sat6 repo logger.info('Updating system and satellite packages... ') preyum_time = datetime.now().replace(microsecond=0) update_packages(quiet=False) postyum_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for system and satellite packages update - ' '{}'.format(str(postyum_time - preyum_time))) # Rebooting the system to check the possible issues if kernal is updated if os.environ.get('RHEV_SAT_HOST'): reboot(120) if to_version == '6.1': # Stop the service again which started in restart # This step is not required with 6.2 upgrade as installer itself # stop all the services before upgrade run('katello-service stop') run('service-wait mongod start') # Running Upgrade preup_time = datetime.now().replace(microsecond=0) if to_version == '6.1': run('katello-installer --upgrade') else: run('satellite-installer --scenario satellite --upgrade') postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time - preup_time))) # Test the Upgrade is successful set_hammer_config() hammer('ping') run('katello-service status', warn_only=True) if os.environ.get('RUN_EXISTANCE_TESTS', 'false').lower() == 'true': logger.info('Setting up postupgrade datastore for existance tests') set_datastore('postupgrade')
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])
def satellite6_upgrade(): """Upgrades satellite from old version to latest version. The following environment variables affect this command: BASE_URL Optional, defaults to available satellite version in CDN. URL for the compose repository TO_VERSION Satellite version to upgrade to and enable repos while upgrading. e.g '6.1','6.2' """ to_version = os.environ.get('TO_VERSION') rhev_sat_host = os.environ.get('RHEV_SAT_HOST') base_url = os.environ.get('BASE_URL') if to_version not in ['6.1', '6.2']: print('Wrong Satellite Version Provided to upgrade to. ' 'Provide one of 6.1, 6.2') sys.exit(1) # Setting yum stdout log level to be less verbose set_yum_debug_level() setup_satellite_firewall() run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo') print('Wait till Packages update ... ') update_packages(quiet=True) # Rebooting the system to see possible errors if rhev_sat_host: reboot(120) # Setting Satellite to_version Repos major_ver = distro_info()[1] # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo disable_repos('*', silent=True) enable_repos('rhel-{0}-server-rpms'.format(major_ver)) enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver)) # If CDN upgrade then enable satellite latest version repo if base_url is None: enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version)) # Else, consider this as Downstream upgrade else: # Add Sat6 repo from latest compose satellite_repo = StringIO() satellite_repo.write('[sat6]\n') satellite_repo.write('name=satellite 6\n') satellite_repo.write('baseurl={0}\n'.format(base_url)) satellite_repo.write('enabled=1\n') satellite_repo.write('gpgcheck=0\n') put(local_path=satellite_repo, remote_path='/etc/yum.repos.d/sat6.repo') satellite_repo.close() # Stop katello services, except mongod run('katello-service stop') if to_version == '6.1': run('service-wait mongod start') run('yum clean all', warn_only=True) # Updating the packages again after setting sat6 repo print('Wait till packages update ... ') print('YUM UPDATE started at: {0}'.format(time.ctime())) update_packages(quiet=False) print('YUM UPDATE finished at: {0}'.format(time.ctime())) # Rebooting the system again for possible errors # Only for RHEV based satellite and not for personal one if rhev_sat_host: reboot(120) if to_version == '6.1': # Stop the service again which started in restart # This step is not required with 6.2 upgrade as installer itself # stop all the services before upgrade run('katello-service stop') run('service-wait mongod start') # Verifying impact of BZ #1357655 on upgrade if rhev_sat_host: run('katello-installer --help', quiet=True) # Running Upgrade print('SATELLITE UPGRADE started at: {0}'.format(time.ctime())) if to_version == '6.1': run('katello-installer --upgrade') else: run('satellite-installer --scenario satellite --upgrade') print('SATELLITE UPGRADE finished at: {0}'.format(time.ctime())) # Test the Upgrade is successful set_hammer_config() hammer('ping') run('katello-service status', warn_only=True)
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])
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 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)
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'))
def satellite6_zstream_upgrade(): """Upgrades Satellite Server to its latest zStream version Note: For zstream upgrade both 'To' and 'From' version should be same FROM_VERSION Current satellite version which will be upgraded to latest version TO_VERSION Next satellite version to which satellite will be upgraded PERFORM_FOREMAN_MAINTAIN_UPGRADE use foreman-maintain for satellite upgrade """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') from_version = os.environ.get('FROM_VERSION') to_version = os.environ.get('TO_VERSION') if not from_version == to_version: logger.warning('zStream Upgrade on Satellite cannot be performed as ' 'FROM and TO versions are not same!') sys.exit(1) base_url = os.environ.get('BASE_URL') major_ver = distro_info()[1] if os.environ.get('PERFORM_FOREMAN_MAINTAIN_UPGRADE') == "true" \ and os.environ.get('OS') == 'rhel7': if base_url is None: os.environ['DISTRIBUTION'] = "CDN" else: os.environ['DISTRIBUTION'] = "DOWNSTREAM" # setup foreman-maintain setup_foreman_maintain() preup_time = datetime.now().replace(microsecond=0) # perform upgrade using foreman-maintain upgrade_using_foreman_maintain() postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time - preup_time))) else: setup_satellite_firewall() # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo disable_repos('*', silent=True) enable_repos('rhel-{0}-server-rpms'.format(major_ver)) enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver)) enable_repos('rhel-{0}-server-extras-rpms'.format(major_ver)) # If CDN upgrade then enable satellite latest version repo if base_url is None: enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version)) # Remove old custom sat repo for fname in os.listdir('/etc/yum.repos.d/'): if 'sat' in fname.lower(): os.remove('/etc/yum.repos.d/{}'.format(fname)) # Else, consider this as Downstream upgrade else: # Add Sat6 repo from latest compose satellite_repo = StringIO() satellite_repo.write('[sat6]\n') satellite_repo.write('name=satellite 6\n') satellite_repo.write('baseurl={0}\n'.format(base_url)) satellite_repo.write('enabled=1\n') satellite_repo.write('gpgcheck=0\n') put(local_path=satellite_repo, remote_path='/etc/yum.repos.d/sat6.repo') satellite_repo.close() # Check what repos are set run('yum repolist') # Stop katello services, except mongod run('katello-service stop') if to_version == '6.1': run('service-wait mongod start') run('yum clean all', warn_only=True) # Updating the packages again after setting sat6 repo logger.info('Updating system and satellite packages... ') preyum_time = datetime.now().replace(microsecond=0) update_packages(quiet=False) postyum_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for system and satellite packages update' ' - {}'.format(str(postyum_time - preyum_time))) # Running Upgrade preup_time = datetime.now().replace(microsecond=0) if to_version == '6.1': run('katello-installer --upgrade') else: run('satellite-installer --scenario satellite --upgrade') postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time - preup_time))) # Rebooting the satellite for kernel update if any reboot(180) host_ssh_availability_check(env.get('satellite_host')) # Test the Upgrade is successful set_hammer_config() hammer('ping') run('katello-service status', warn_only=True)
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)
def satellite6_upgrade(): """Upgrades satellite from old version to latest version. The following environment variables affect this command: BASE_URL Optional, defaults to available satellite version in CDN. URL for the compose repository TO_VERSION Satellite version to upgrade to and enable repos while upgrading. e.g '6.1','6.2', '6.3' PERFORM_FOREMAN_MAINTAIN_UPGRADE use foreman-maintain for satellite upgrade """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') to_version = os.environ.get('TO_VERSION') base_url = os.environ.get('BASE_URL') if to_version not in ['6.1', '6.2', '6.3', '6.4']: logger.warning('Wrong Satellite Version Provided to upgrade to. ' 'Provide one of 6.1, 6.2, 6.3, 6.4') sys.exit(1) major_ver = distro_info()[1] if os.environ.get('PERFORM_FOREMAN_MAINTAIN_UPGRADE') == 'true' \ and os.environ.get('OS') == 'rhel7' and to_version != '6.4': if base_url is None: os.environ['DISTRIBUTION'] = "CDN" else: os.environ['DISTRIBUTION'] = "DOWNSTREAM" # setup foreman-maintain setup_foreman_maintain() preup_time = datetime.now().replace(microsecond=0) # perform upgrade using foreman-maintain upgrade_using_foreman_maintain() postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time - preup_time))) else: setup_satellite_firewall() run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo') logger.info('Updating system packages ... ') # setup foreman-maintain setup_foreman_maintain() update_packages(quiet=True) # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo disable_repos('*', silent=True) enable_repos('rhel-{0}-server-rpms'.format(major_ver)) enable_repos('rhel-server-rhscl-{0}-rpms'.format(major_ver)) enable_repos('rhel-{0}-server-extras-rpms'.format(major_ver)) # If CDN upgrade then enable satellite latest version repo if base_url is None: enable_repos('rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version)) # Remove old custom sat repo for fname in os.listdir('/etc/yum.repos.d/'): if 'sat' in fname.lower(): os.remove('/etc/yum.repos.d/{}'.format(fname)) # Else, consider this as Downstream upgrade else: # Add Sat6 repo from latest compose satellite_repo = StringIO() satellite_repo.write('[sat6]\n') satellite_repo.write('name=satellite 6\n') satellite_repo.write('baseurl={0}\n'.format(base_url)) satellite_repo.write('enabled=1\n') satellite_repo.write('gpgcheck=0\n') put(local_path=satellite_repo, remote_path='/etc/yum.repos.d/sat6.repo') satellite_repo.close() # Check what repos are set run('yum repolist') # Stop katello services, except mongod run('katello-service stop') if to_version == '6.1': run('service-wait mongod start') run('yum clean all', warn_only=True) # Updating the packages again after setting sat6 repo logger.info('Updating satellite packages ... ') preyum_time = datetime.now().replace(microsecond=0) update_packages(quiet=False) postyum_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for satellite packages update- {}'.format( str(postyum_time - preyum_time))) # Running Upgrade preup_time = datetime.now().replace(microsecond=0) if to_version == '6.1': run('katello-installer --upgrade') else: run('satellite-installer --scenario satellite --upgrade') postup_time = datetime.now().replace(microsecond=0) logger.highlight('Time taken for Satellite Upgrade - {}'.format( str(postup_time - preup_time))) set_hammer_config() # Rebooting the satellite for kernel update if any reboot(180) host_ssh_availability_check(env.get('satellite_host')) # Test the Upgrade is successful hammer('ping') run('katello-service status', warn_only=True) # Enable ostree feature only for rhel7 and sat6.2 if to_version == '6.2' and major_ver == 7: enable_ostree(sat_version='6.2')
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_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)
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)