Exemplo n.º 1
0
    def test_permutations(self, tmpdir, before, expected):
        list_file = tmpdir.join("list_file")
        list_file.write(before)

        apt.restore_commented_apt_list_file(list_file.strpath)

        assert expected == list_file.read()
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
 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
     )