diff --git a/changelog/62546.fixed b/changelog/62546.fixed new file mode 100644 index 00000000000..68ada1d2bc5 --- /dev/null +++ b/changelog/62546.fixed @@ -0,0 +1 @@ +Use str() method instead of repo_line for when python3-apt is installed or not in aptpkg.py. diff --git a/salt/modules/aptpkg.py b/salt/modules/aptpkg.py index 0b94cd03708..19b5ef5772d 100644 --- a/salt/modules/aptpkg.py +++ b/salt/modules/aptpkg.py @@ -182,6 +182,9 @@ if not HAS_APT: self.file = str(pathlib.Path(os.sep, "etc", "apt", "sources.list")) self._parse_sources(line) + def str(self): + return self.repo_line() + def repo_line(self): """ Return the repo line for the sources file @@ -2946,7 +2949,7 @@ def mod_repo(repo, saltenv="base", aptkey=True, **kwargs): if mod_source.uri != repo_uri: mod_source.uri = repo_uri - mod_source.line = mod_source.repo_line() + mod_source.line = mod_source.str() sources.save() # on changes, explicitly refresh diff --git a/tests/pytests/functional/states/pkgrepo/test_debian.py b/tests/pytests/functional/states/pkgrepo/test_debian.py index 12ab69ab6b2..585a2f96865 100644 --- a/tests/pytests/functional/states/pkgrepo/test_debian.py +++ b/tests/pytests/functional/states/pkgrepo/test_debian.py @@ -537,6 +537,37 @@ def test_repo_present_absent_no_trailing_slash_uri(pkgrepo, trailing_slash_repo_ assert ret.result +@pytest.mark.requires_salt_states("pkgrepo.managed", "pkgrepo.absent") +def test_repo_present_absent_no_trailing_slash_uri_add_slash( + pkgrepo, trailing_slash_repo_file +): + """ + test adding a repo without a trailing slash, and then running it + again with a trailing slash. + """ + # without the trailing slash + repo_content = "deb http://www.deb-multimedia.org stable main" + # initial creation + ret = pkgrepo.managed( + name=repo_content, file=trailing_slash_repo_file, refresh=False, clean_file=True + ) + with salt.utils.files.fopen(trailing_slash_repo_file, "r") as fp: + file_content = fp.read() + assert file_content.strip() == "deb http://www.deb-multimedia.org stable main" + assert ret.changes + # now add a trailing slash in the name + repo_content = "deb http://www.deb-multimedia.org/ stable main" + ret = pkgrepo.managed( + name=repo_content, file=trailing_slash_repo_file, refresh=False + ) + with salt.utils.files.fopen(trailing_slash_repo_file, "r") as fp: + file_content = fp.read() + assert file_content.strip() == "deb http://www.deb-multimedia.org/ stable main" + # absent + ret = pkgrepo.absent(name=repo_content) + assert ret.result + + @attr.s(kw_only=True) class Repo: key_root = attr.ib(default=pathlib.Path("/usr", "share", "keyrings"))