Skip to content

Commit

Permalink
Use str() method instead of repo_line for SourceEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
Megan Wilhite committed Aug 29, 2022
1 parent ad9caa9 commit f1725a6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/62546.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use str() method instead of repo_line for when python3-apt is installed or not in aptpkg.py.
5 changes: 4 additions & 1 deletion salt/modules/aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def __init__(self, line, file=None):
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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/pytests/functional/states/pkgrepo/test_debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit f1725a6

Please sign in to comment.