def disable(self, silent=False, force=False): """Disable specific entitlement @return: True on success, False otherwise. """ if not self.can_disable(silent, force): return False series = util.get_platform_info('series') repo_filename = self.repo_list_file_tmpl.format(name=self.name, series=series) keyring_file = os.path.join(apt.APT_KEYS_DIR, self.repo_key_file) entitlement_cfg = self.cfg.read_cache('machine-access-%s' % self.name)['entitlement'] access_directives = entitlement_cfg.get('directives', {}) repo_url = access_directives.get('aptURL', self.repo_url) if not repo_url: repo_url = self.repo_url apt.remove_auth_apt_repo(repo_filename, repo_url, keyring_file) apt.remove_apt_list_files(repo_url, series) print('Removing packages: %s' % ', '.join(self.packages)) try: util.subp(['apt-get', 'remove', '--assume-yes'] + self.packages) except util.ProcessExecutionError: pass return True
def disable(self, silent=False, force=False): if not self.can_disable(silent, force): return False if force: # Force config cleanup as broke during setup attempt. series = util.get_platform_info('series') repo_filename = self.repo_list_file_tmpl.format(name=self.name, series=series) keyring_file = os.path.join(apt.APT_KEYS_DIR, self.repo_key_file) entitlement = self.cfg.read_cache( 'machine-access-%s' % self.name).get('entitlement', {}) access_directives = entitlement.get('directives', {}) repo_url = access_directives.get('aptURL', self.repo_url) if not repo_url: repo_url = self.repo_url apt.remove_auth_apt_repo(repo_filename, repo_url, keyring_file) if self.repo_pin_priority: repo_pref_file = self.repo_pref_file_tmpl.format( name=self.name, series=series) if os.path.exists(repo_pref_file): os.unlink(repo_pref_file) apt.remove_apt_list_files(repo_url, series) try: util.subp(['apt-get', 'remove', '--assume-yes'] + self.packages) except util.ProcessExecutionError: pass if not silent: print('Warning: no option to disable {title}'.format( title=self.title)) return False
def remove_apt_config(self): """Remove any repository apt configuration files.""" series = util.get_platform_info()['series'] repo_filename = self.repo_list_file_tmpl.format( name=self.name, series=series) keyring_file = os.path.join(apt.APT_KEYS_DIR, self.repo_key_file) entitlement = self.cfg.read_cache( 'machine-access-%s' % self.name).get('entitlement', {}) access_directives = entitlement.get('directives', {}) repo_url = access_directives.get('aptURL', self.repo_url) if not repo_url: repo_url = self.repo_url if self.disable_apt_auth_only: # We only remove the repo from the apt auth file, because ESM # is a special-case: we want to be able to report on the # available ESM updates even when it's disabled apt.remove_repo_from_apt_auth_file(repo_url) apt.restore_commented_apt_list_file(repo_filename) else: apt.remove_auth_apt_repo(repo_filename, repo_url, keyring_file) apt.remove_apt_list_files(repo_url, series) if self.repo_pin_priority: repo_pref_file = self.repo_pref_file_tmpl.format( name=self.name, series=series) if self.repo_pin_priority == 'never': # Disable the repo with a pinning file apt.add_ppa_pinning( repo_pref_file, repo_url, self.origin, self.repo_pin_priority) elif os.path.exists(repo_pref_file): os.unlink(repo_pref_file)
def remove_apt_config(self, run_apt_update: bool = True, silent: bool = False): """Remove any repository apt configuration files. :param run_apt_update: If after removing the apt update command after removing the apt files. """ series = util.get_platform_info()["series"] repo_filename = self.repo_list_file_tmpl.format(name=self.name) entitlement = self.cfg.entitlements[self.name].get("entitlement", {}) access_directives = entitlement.get("directives", {}) repo_url = access_directives.get("aptURL") if not repo_url: raise exceptions.MissingAptURLDirective(self.name) if self.disable_apt_auth_only: # We only remove the repo from the apt auth file, because # UA Infra: ESM is a special-case: we want to be able to report on # the available UA Infra: ESM updates even when it's disabled apt.remove_repo_from_apt_auth_file(repo_url) apt.restore_commented_apt_list_file(repo_filename) else: apt.remove_auth_apt_repo(repo_filename, repo_url, self.repo_key_file) apt.remove_apt_list_files(repo_url, series) if self.repo_pin_priority: repo_pref_file = self.repo_pref_file_tmpl.format(name=self.name) if self.repo_pin_priority == "never": # Disable the repo with a pinning file apt.add_ppa_pinning( repo_pref_file, repo_url, self.origin, self.repo_pin_priority, ) elif os.path.exists(repo_pref_file): os.unlink(repo_pref_file) if run_apt_update: if not silent: event.info(messages.APT_UPDATING_LISTS) apt.run_apt_update_command()
def remove_apt_config(self): """Remove any repository apt configuration files.""" series = util.get_platform_info()["series"] repo_filename = self.repo_list_file_tmpl.format( name=self.name, series=series ) entitlement = self.cfg.entitlements[self.name].get("entitlement", {}) access_directives = entitlement.get("directives", {}) repo_url = access_directives.get("aptURL") if not repo_url: raise exceptions.MissingAptURLDirective(self.name) if self.disable_apt_auth_only: # We only remove the repo from the apt auth file, because ESM Infra # is a special-case: we want to be able to report on the # available ESM Infra updates even when it's disabled apt.remove_repo_from_apt_auth_file(repo_url) apt.restore_commented_apt_list_file(repo_filename) else: apt.remove_auth_apt_repo( repo_filename, repo_url, self.repo_key_file ) apt.remove_apt_list_files(repo_url, series) if self.repo_pin_priority: repo_pref_file = self.repo_pref_file_tmpl.format( name=self.name, series=series ) if self.repo_pin_priority == "never": # Disable the repo with a pinning file apt.add_ppa_pinning( repo_pref_file, repo_url, self.origin, self.repo_pin_priority, ) elif os.path.exists(repo_pref_file): os.unlink(repo_pref_file) print(status.MESSAGE_APT_UPDATING_LISTS) apt.run_apt_command( ["apt-get", "update"], status.MESSAGE_APT_UPDATE_FAILED )
def test_remove_all_apt_list_files_from_apt_config_key( self, m_subp, tmpdir): """Remove all matching apt list files from apt-config dir.""" m_subp.return_value = ("key='%s'" % tmpdir.strpath, '') repo_url = 'http://c.com/fips-updates/' _protocol, repo_path = repo_url.split('://') prefix = repo_path.rstrip('/').replace('/', '_') nomatch_file = tmpdir.join(prefix + '_dists_nomatch').strpath paths = [ nomatch_file, tmpdir.join(prefix + '_dists_xenial_InRelease').strpath, tmpdir.join( prefix + '_dists_xenial_main_binary-amd64_Packages').strpath] for path in paths: util.write_file(path, '') assert None is remove_apt_list_files(repo_url, 'xenial') assert [nomatch_file] == glob.glob('%s/*' % tmpdir.strpath)
def test_remove_all_apt_list_files_from_apt_config_key( self, m_subp, tmpdir): """Remove all matching apt list files from apt-config dir.""" m_subp.return_value = ("key='{}'".format(tmpdir.strpath), "") repo_url = "http://c.com/fips-updates/" _protocol, repo_path = repo_url.split("://") prefix = repo_path.rstrip("/").replace("/", "_") nomatch_file = tmpdir.join(prefix + "_dists_nomatch").strpath paths = [ nomatch_file, tmpdir.join(prefix + "_dists_xenial_InRelease").strpath, tmpdir.join(prefix + "_dists_xenial_main_binary-amd64_Packages").strpath, ] for path in paths: util.write_file(path, "") assert None is remove_apt_list_files(repo_url, "xenial") assert [nomatch_file] == glob.glob("{}/*".format(tmpdir.strpath))