def generate_capsule_certs(capsule_hostname, force=False): """Generate certificates for a capsule. Run ``capsule-certs-generate --capsule-fqdn <capsule_hostname> --certs-tar "<capsule_hostname>-certs.tar"`` in order to generate them. The resulting tarbal will be store on the working directory of the remote host. :param str capsule_hostname: The fully qualified domain name for the capsule. :param bool force: Force creation of the capsule cert even if it is already created. """ if bz_bug_is_open(1466688): # Absolute path bug cert_path = '~/{0}-certs.tar'.format(capsule_hostname) else: cert_path = '{0}-certs.tar'.format(capsule_hostname) result = run('[ -f {0} ]'.format(cert_path), quiet=True) if result.failed or force: run('capsule-certs-generate -v --foreman-proxy-fqdn {0} ' '--certs-tar {1} --certs-update-all'.format( capsule_hostname, cert_path)) return cert_path
def generate_capsule_certs(capsule_hostname, force=False): """Generate certificates for a capsule. Run ``capsule-certs-generate --capsule-fqdn <capsule_hostname> --certs-tar "<capsule_hostname>-certs.tar"`` in order to generate them. The resulting tarbal will be store on the working directory of the remote host. :param str capsule_hostname: The fully qualified domain name for the capsule. :param bool force: Force creation of the capsule cert even if it is already created. """ if bz_bug_is_open(1466688): # Absolute path bug cert_path = '~/{0}-certs.tar'.format(capsule_hostname) else: cert_path = '{0}-certs.tar'.format(capsule_hostname) result = run('[ -f {0} ]'.format(cert_path), quiet=True) if result.failed or force: if os.environ.get('SATELLITE_VERSION') == '6.3': run('capsule-certs-generate -v --foreman-proxy-fqdn {0} ' '--certs-tar {1} --certs-update-all'.format(capsule_hostname, cert_path )) else: run('capsule-certs-generate -v --capsule-fqdn {0} ' '--certs-tar {1}'.format(capsule_hostname, cert_path )) return cert_path
def __call__(self, func): """Return unchanged function or function decorated with `pytest.mark.run_in_one_thread` marker decorator if bug is open. :param func: The function being decorated. :return: The return value of test method ``func``. :raises BugTypeError: If ``bug_type`` is not recognized. """ self.register_bug_id(func) if self.bug_type not in ('bugzilla', 'redmine'): raise BugTypeError( '"{0}" is not a recognized bug type. Did you mean ' '"bugzilla" or "redmine"?'.format(self.bug_type) ) if self.bug_type == 'bugzilla': _add_bugzilla_id(func, self.bug_id) if (self.bug_type == 'bugzilla' and bz_bug_is_open( self.bug_id, sat_version_picker=self.sat_version_picker, config_picker=self.config_picker )) or (self.bug_type == 'redmine' and rm_bug_is_open(self.bug_id)): func = self._wrapper(func) return func
def test_all_closed(): closed_bugs = [ int(key) for key, val in cache_data.items() if val.get('status_resolution', val['status']) in robozilla.constants.BZ_CLOSED_STATUSES ] for bug_id in closed_bugs: assert bz_bug_is_open(bug_id) is False
def test_all_open(): open_bugs = [ int(key) for key, val in cache_data.items() if val.get('status_resolution', val['status']) in robozilla.constants.BZ_OPEN_STATUSES ] for bug_id in open_bugs: assert bz_bug_is_open(bug_id) is True
def post_upgrade_test_tasks(sat_host, cap_host=None): """Run set of tasks for post upgrade tests :param string sat_host: Hostname to run the tasks on :param list cap_host: Capsule hosts to run sync on """ # Execute tasks as post upgrade tests are dependent certificate_url = os.environ.get('FAKE_MANIFEST_CERT_URL') if certificate_url is not None: execute(setup_fake_manifest_certificate, certificate_url, host=sat_host) sat_version = os.environ.get('TO_VERSION') execute(setup_alternate_capsule_ports, host=sat_host) if float(sat_version) > 6.1: # Update the Default Organization name, which was updated in 6.2 logger.info("Update the Default Organization name, which was updated " "in 6.2") org = entities.Organization().search( query={'search': 'label=Default_Organization'})[0] org.name = "Default Organization" org.update(['name']) # Update the Default Location name, which was updated in 6.2 logger.info("Update the Default Location name, which was updated in " "6.2") loc = entities.Location().search( query={'search': 'name="Default Location"'})[0] loc.name = "Default Location" loc.update(['name']) if bz_bug_is_open(1502505): logger.info( "Update the default_location_puppet_content value with " "updated location name.Refer BZ:1502505") puppet_location = entities.Setting().search( query={'search': 'name=default_location_puppet_content'})[0] puppet_location.value = 'Default Location' puppet_location.update(['value']) # Increase log level to DEBUG, to get better logs in foreman_debug execute(lambda: run('sed -i -e \'/:level: / s/: .*/: ' 'debug/\' /etc/foreman/settings.yaml'), host=sat_host) execute(lambda: run('katello-service restart'), host=sat_host) # Execute task for template changes required for discovery feature execute(setup_foreman_discovery, sat_version=sat_version, host=sat_host) # Execute task for creating latest discovery iso required for unattended # test env.disable_known_hosts = True execute(get_discovery_image, host=os.environ.get('LIBVIRT_HOSTNAME')) # Commenting out until GH issue:#135 # Removing the original manifest from Default Organization (Org-id 1), # to allow test-cases to utilize the same manifest. # logger.info("Removing the Original Manifest from Default Organization") # execute(hammer, 'subscription delete-manifest --organization-id 1', # host=sat_host) # Run Avahi Task on upgrade boxes for REX tests to run execute(lambda: run('yum remove -y epel*'), host=sat_host) execute(setup_avahi_discovery, host=sat_host)
def satellite_capsule_setup(satellite_host, capsule_hosts, os_version, upgradable_capsule=True): """ Setup all pre-requisites for user provided capsule :param satellite_host: Satellite hostname to which the capsule registered :param capsule_hosts: List of capsule which mapped with satellite host :param os_version: The OS version onto which the capsule installed e.g: rhel6, rhel7 :param upgradable_capsule:Whether to setup capsule to be able to upgrade in future :return: capsule_hosts """ if os_version == 'rhel6': baseurl = settings.repos.rhel6_os elif os_version == 'rhel7': baseurl = settings.repos.rhel7_os else: logger.highlight('No OS Specified. Aborting...') sys.exit(1) non_responsive_host = [] for cap_host in capsule_hosts: if not host_pings(cap_host): non_responsive_host.append(cap_host) else: execute(host_ssh_availability_check, cap_host) # Update the template once 1829115 gets fixed. execute(workaround_1829115, host=cap_host) if not bz_bug_is_open(1829115): logger.warn( "Please update the capsule template for fixed capsule version") execute(foreman_service_restart, host=cap_host) if non_responsive_host: logger.highlight( str(non_responsive_host) + ' these are non-responsive hosts. ' 'Aborting...') sys.exit(1) copy_ssh_key(satellite_host, capsule_hosts) if upgradable_capsule: if settings.upgrade.distribution == "cdn": settings.repos.capsule_repo = None settings.repos.sattools_repo[settings.upgrade.os] = None settings.repos.satmaintenance_repo = None execute(update_capsules_to_satellite, capsule_hosts, host=satellite_host) if settings.upgrade.upgrade_with_http_proxy: http_proxy_config(capsule_hosts) execute(sync_capsule_repos_to_satellite, capsule_hosts, host=satellite_host) for cap_host in capsule_hosts: settings.upgrade.capsule_hostname = cap_host execute(add_baseOS_repo, baseurl, host=cap_host) execute(yum_repos_cleanup, host=cap_host) logger.info(f'Capsule {cap_host} is ready for Upgrade') return capsule_hosts
def setUpClass(cls): """Steps to Configure foreman discovery 1. Build PXE default template 2. Create Organization/Location 3. Update Global parameters to set default org and location for discovered hosts. 4. Enable auto_provision flag to perform discovery via discovery rules. """ super(DiscoveredTestCase, cls).setUpClass() # Build PXE default template to get default PXE file Template.build_pxe_default() # let's just modify the timeouts to speed things up ssh.command("sed -ie 's/TIMEOUT [[:digit:]]\\+/TIMEOUT 1/g' " "/var/lib/tftpboot/pxelinux.cfg/default") ssh.command("sed -ie '/APPEND initrd/s/$/ fdi.countdown=1/' " "/var/lib/tftpboot/pxelinux.cfg/default") # Create Org and location cls.org = make_org() cls.loc = make_location() # Get default settings values cls.default_discovery_loc = Settings.list( {'search': 'name=%s' % 'discovery_location'})[0] cls.default_discovery_org = Settings.list( {'search': 'name=%s' % 'discovery_organization'})[0] cls.default_discovery_auto = Settings.list( {'search': 'name=%s' % 'discovery_auto'})[0] # Update default org and location params to place discovered host Settings.set({'name': 'discovery_location', 'value': cls.loc['name']}) Settings.set({ 'name': 'discovery_organization', 'value': cls.org['name'] }) # Enable flag to auto provision discovered hosts via discovery rules Settings.set({'name': 'discovery_auto', 'value': 'true'}) # Flag which shows whether environment is fully configured for # discovered host provisioning. cls.configured_env = False if bz_bug_is_open(1578290): ssh.command('mkdir /var/lib/tftpboot/boot/fdi-image') ssh.command('ln -s /var/lib/tftpboot/boot/' 'foreman-discovery-image-3.4.4-1.iso-vmlinuz' ' /var/lib/tftpboot/boot/fdi-image/vmlinuz0') ssh.command('ln -s /var/lib/tftpboot/boot/' 'foreman-discovery-image-3.4.4-1.iso-img' ' /var/lib/tftpboot/boot/fdi-image/initrd0.img') ssh.command('chown -R foreman-proxy /var/lib/tftpboot/boot/')
def setUpClass(cls): """Steps to Configure foreman discovery 1. Build PXE default template 2. Create Organization/Location 3. Update Global parameters to set default org and location for discovered hosts. 4. Enable auto_provision flag to perform discovery via discovery rules. """ super(DiscoveredTestCase, cls).setUpClass() # Build PXE default template to get default PXE file Template.build_pxe_default() # let's just modify the timeouts to speed things up ssh.command("sed -ie 's/TIMEOUT [[:digit:]]\\+/TIMEOUT 1/g' " "/var/lib/tftpboot/pxelinux.cfg/default") ssh.command("sed -ie '/APPEND initrd/s/$/ fdi.countdown=1/' " "/var/lib/tftpboot/pxelinux.cfg/default") # Create Org and location cls.org = make_org() cls.loc = make_location() # Get default settings values cls.default_discovery_loc = Settings.list( {'search': 'name=%s' % 'discovery_location'})[0] cls.default_discovery_org = Settings.list( {'search': 'name=%s' % 'discovery_organization'})[0] cls.default_discovery_auto = Settings.list( {'search': 'name=%s' % 'discovery_auto'})[0] # Update default org and location params to place discovered host Settings.set({'name': 'discovery_location', 'value': cls.loc['name']}) Settings.set( {'name': 'discovery_organization', 'value': cls.org['name']}) # Enable flag to auto provision discovered hosts via discovery rules Settings.set({'name': 'discovery_auto', 'value': 'true'}) # Flag which shows whether environment is fully configured for # discovered host provisioning. cls.configured_env = False if bz_bug_is_open(1578290): ssh.command('mkdir /var/lib/tftpboot/boot/fdi-image') ssh.command('ln -s /var/lib/tftpboot/boot/' 'foreman-discovery-image-3.4.4-1.iso-vmlinuz' ' /var/lib/tftpboot/boot/fdi-image/vmlinuz0') ssh.command('ln -s /var/lib/tftpboot/boot/' 'foreman-discovery-image-3.4.4-1.iso-img' ' /var/lib/tftpboot/boot/fdi-image/initrd0.img') ssh.command('chown -R foreman-proxy /var/lib/tftpboot/boot/')
def post_upgrade_test_tasks(sat_host, cap_host=None): """Run set of tasks for post upgrade tests :param string sat_host: Hostname to run the tasks on :param list cap_host: Capsule hosts to run sync on """ # Execute tasks as post upgrade tests are dependent certificate_url = os.environ.get('FAKE_MANIFEST_CERT_URL') if certificate_url is not None: execute( setup_fake_manifest_certificate, certificate_url, host=sat_host ) sat_version = os.environ.get('TO_VERSION') execute(setup_alternate_capsule_ports, host=sat_host) if sat_version not in ['6.0', '6.1']: # Update the Default Organization name, which was updated in 6.2 logger.info("Update the Default Organization name, which was updated " "in 6.2") execute(hammer, 'organization update --name "Default_Organization" ' '--new-name "Default Organization" ', host=sat_host) # Update the Default Location name, which was updated in 6.2 logger.info("Update the Default Location name, which was updated in " "6.2") execute(hammer, 'location update --name "Default_Location" ' '--new-name "Default Location" ', host=sat_host) if bz_bug_is_open(1502505): logger.info( "Update the default_location_puppet_content value with " "updated location name.Refer BZ:1502505") execute(hammer, 'settings set --name ' '"default_location_puppet_content" --value ' '"Default Location"', host=sat_host) # Increase log level to DEBUG, to get better logs in foreman_debug execute(lambda: run('sed -i -e \'/:level: / s/: .*/: ' 'debug/\' /etc/foreman/settings.yaml'), host=sat_host) execute(lambda: run('katello-service restart'), host=sat_host) # Execute capsule sync task , after the upgrade is completed if cap_host: execute(capsule_sync, cap_host, host=sat_host) # Execute task for template changes required for discovery feature execute( setup_foreman_discovery, sat_version=sat_version, host=sat_host )
def satellite6_upgrade(zstream=False): """This function is used to perform the satellite upgrade of two type based on their passed parameter. :param zstream: if upgrade_type==None: - Upgrades Satellite Server from old version to latest The following environment variables affect this command: BASE_URL Optional, defaults to available satellite version in CDN. URL for the compose repository FROM_VERSION Current satellite version which will be upgraded to latest version TO_VERSION Satellite version to upgrade to and enable repos while upgrading. e.g '6.1','6.2', '6.3' FOREMAN_MAINTAIN_SATELLITE_UPGRADE use foreman-maintain for satellite upgrade else: - 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 FOREMAN_MAINTAIN_SATELLITE_UPGRADE use foreman-maintain for satellite upgrade """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') to_version = os.environ.get('TO_VERSION') from_version = os.environ.get('FROM_VERSION') if zstream: 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 = None if not os.environ.get('BASE_URL') else os.environ.get( 'BASE_URL') major_ver = distro_info()[1] disable_repo_name = ["*"] enable_repos_name = [ 'rhel-{0}-server-rpms'.format(major_ver), 'rhel-server-rhscl-{0}-rpms'.format(major_ver) ] if bz_bug_is_open(1850934): run('echo "apache::mod::proxy::proxy_timeout: 120" >> ' '/etc/foreman-installer/custom-hiera.yaml') # This statement will execute only until downstream release not become beta. if os.environ.get('DOWNSTREAM_FM_UPGRADE') == 'true' or \ os.environ.get('FOREMAN_MAINTAIN_SATELLITE_UPGRADE') == 'false': # Following disables the old satellite repo and extra repos enabled # during subscribe e.g Load balancer Repo enable_disable_repo(disable_repo_name, enable_repos_name) os.environ[ "whitelisted_param"] = ", repositories-validate, repositories-setup" else: os.environ["whitelisted_param"] = '' if os.environ.get('FOREMAN_MAINTAIN_SATELLITE_UPGRADE') == 'true' \ and os.environ.get('OS') == 'rhel7': foreman_maintain_upgrade(base_url) else: # To install the package using foreman-maintain and it is applicable # above 6.7 version. setup_satellite_firewall() if not zstream: run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo') logger.info('Updating system packages ... ') foreman_packages_installation_check(state="unlock") setup_foreman_maintain() update_packages(quiet=True) if base_url is None: enable_disable_repo([], [ 'rhel-{0}-server-satellite-{1}-rpms'.format( major_ver, to_version) ]) # Remove old custom sat repo repository_cleanup('sat') else: repository_setup("sat6", "satellite 6", base_url, 1, 0) nonfm_upgrade() foreman_packages_installation_check(state="lock") # Rebooting the satellite for kernel update if any reboot(180) host_ssh_availability_check(env.get('satellite_host')) # Test the Upgrade is successful upgrade_validation(True)
def satellite_upgrade(zstream=False): """This function is used to perform the satellite upgrade of two type based on their passed parameter. :param zstream: if upgrade_type==None: - Upgrades Satellite Server from old version to latest The following environment variables affect this command: SAT_UPGRADE_BASE_URL Optional, defaults to available satellite version in CDN. URL for the compose repository FROM_VERSION Current satellite version which will be upgraded to latest version TO_VERSION Satellite version to upgrade to and enable repos while upgrading. e.g '6.1','6.2', '6.3' FOREMAN_MAINTAIN_SATELLITE_UPGRADE use foreman-maintain for satellite upgrade else: - 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 FOREMAN_MAINTAIN_SATELLITE_UPGRADE use foreman-maintain for satellite upgrade """ logger.highlight('\n========== SATELLITE UPGRADE =================\n') if zstream: if not settings.upgrade.from_version == settings.upgrade.to_version: logger.highlight( 'zStream Upgrade on Satellite cannot be performed as FROM and TO' ' versions are not same. Aborting...') sys.exit(1) major_ver = settings.upgrade.os[-1] common_sat_cap_repos = [ RHEL_CONTENTS["rhscl"]["label"], RHEL_CONTENTS["server"]["label"] ] if settings.upgrade.downstream_fm_upgrade: settings.upgrade.whitelist_param = ", repositories-validate, repositories-setup" # disable all the repos enable_disable_repo(disable_repos_name=["*"]) # It is required to enable the tools and server for non-fm upgrade because in # fm both the repos enabled by the fm tool. if not settings.upgrade.foreman_maintain_satellite_upgrade: enable_disable_repo(enable_repos_name=common_sat_cap_repos) if settings.upgrade.distribution == 'cdn': enable_disable_repo( enable_repos_name=['rhel-7-server-satellite-maintenance-6-rpms']) else: for repo in CUSTOM_SAT_REPO: repository_setup(CUSTOM_SAT_REPO[repo]["repository"], CUSTOM_SAT_REPO[repo]["repository_name"], CUSTOM_SAT_REPO[repo]["base_url"], CUSTOM_SAT_REPO[repo]["enable"], CUSTOM_SAT_REPO[repo]["gpg"]) foreman_maintain_package_update() if settings.upgrade.to_version == "6.10": if bz_bug_is_open(1967131): workaround_1967131(task_type="apply") pulp_migration_status = pulp2_pulp3_migration() if bz_bug_is_open(1967131): workaround_1967131() if not pulp_migration_status: logger.highlight("Pulp migration failed. Aborting") sys.exit(1) if settings.upgrade.foreman_maintain_satellite_upgrade: upgrade_using_foreman_maintain() else: # To install the package using foreman-maintain and it is applicable # above 6.7 version. setup_satellite_firewall() if not zstream: run('rm -rf /etc/yum.repos.d/rhel-{optional,released}.repo') logger.info('Updating system packages ... ') foreman_packages_installation_check(state="unlock") setup_satellite_repo() foreman_maintain_package_update() update_packages(quiet=True) if settings.upgrade.distribution == "cdn": enable_disable_repo(enable_repos_name=[ f'rhel-{major_ver}-server-satellite' f'-{settings.upgrade.to_version}-rpms' ]) nonfm_upgrade() foreman_packages_installation_check(state="lock") # Rebooting the satellite for kernel update if any if settings.upgrade.satellite_capsule_setup_reboot: reboot(180) host_ssh_availability_check(env.get('satellite_host')) # Test the Upgrade is successful upgrade_validation(True) if settings.upgrade.mongodb_upgrade: mongo_db_engine_upgrade() if settings.upgrade.satellite_backup: satellite_backup()