8000 Add deb822 for aptpkg by vzhestkov · Pull Request #67956 · saltstack/salt · GitHub
[go: up one dir, main page]

Skip to content

Add deb822 for aptpkg #67956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes for test_aptpkg
Co-authored-by: Marek Czernek <marek.czernek@suse.com>
  • Loading branch information
2 people authored and dwoz committed Jun 23, 2025
commit cf8d80cf20ea356beb76318f7360a20679d0585d
103 changes: 103 additions & 0 deletions tests/pytests/unit/modules/test_aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ def __init__(self, uri, source_type, line, invalid, dist="", file=None):
self.file = file
self.disabled = False
self.dist = dist
self.suites = [dist]
self.comps = []
self.architectures = []
self.signedby = ""
self.types = []

def mysplit(self, line):
return line.split()
Expand All @@ -213,6 +215,107 @@ def configure_loader_modules():
return {aptpkg: {"__grains__": {}}}


@pytest.fixture
def deb822_repo_content():
return """
Types: deb
URIs: http://cz.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
"""


@pytest.fixture
def deb822_repo_file(tmp_path: pathlib.Path, deb822_repo_content: str):
"""
Create a Debian-style repository in the deb822 format and return
the path of the repository file.
"""
repo = tmp_path / "sources.list.d" / "test.sources"
repo.parent.mkdir(parents=True, exist_ok=True)
repo.write_text(deb822_repo_content.strip(), encoding="UTF-8")
return repo


@pytest.fixture
def mock_apt_config(deb822_repo_file: pathlib.Path):
"""
Mocking common to deb822 testing so that apt_pkg uses the
tmp_path/sources.list.d as the sourceparts location
"""
with patch.dict(
aptpkg.__salt__,
{"config.option": MagicMock()},
) as mock_config, patch(
"salt.utils.pkg.deb._APT_SOURCES_PARTSDIR",
os.path.dirname(str(deb822_repo_file)),
):
yield mock_config


def test_mod_repo_deb822_modify(deb822_repo_file: pathlib.Path, mock_apt_config):
"""
Test that aptpkg can modify an existing repository in the deb822 format.
In this test, we match the repository by name and disable it.
"""
uri = "http://cz.archive.ubuntu.com/ubuntu/"
repo = f"deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] {uri} noble main"

aptpkg.mod_repo(repo, enabled=False, file=str(deb822_repo_file), refresh_db=False)

repo_file = deb822_repo_file.read_text(encoding="UTF-8")
assert "Enabled: no" in repo_file
assert f"URIs: {uri}" in repo_file


def test_mod_repo_deb822_add(deb822_repo_file: pathlib.Path, mock_apt_config):
"""
Test that aptpkg can add a repository in the deb822 format.
"""
uri = "http://security.ubuntu.com/ubuntu/"
repo = f"deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] {uri} noble-security main"

aptpkg.mod_repo(repo, file=str(deb822_repo_file), refresh_db=False)

repo_file = deb822_repo_file.read_text(encoding="UTF-8")
assert f"URIs: {uri}" in repo_file
assert "URIs: http://cz.archive.ubuntu.com/ubuntu/" in repo_file


def test_del_repo_deb822(deb822_repo_file: pathlib.Path, mock_apt_config):
"""
Test that aptpkg can delete a repository in the deb822 format.
"""
uri = "http://cz.archive.ubuntu.com/ubuntu/"

with patch.object(aptpkg, "refresh_db"):
repo = f"deb {uri} noble main"
aptpkg.del_repo(repo, file=str(deb822_repo_file))
assert os.path.isfile(str(deb822_repo_file))

repo = f"deb {uri} noble-updates main"
aptpkg.del_repo(repo, file=str(deb822_repo_file))
assert os.path.isfile(str(deb822_repo_file))

repo = f"deb {uri} noble-backports main"
aptpkg.del_repo(repo, file=str(deb822_repo_file))
assert not os.path.isfile(str(deb822_repo_file))


def test_get_repo_deb822(deb822_repo_file: pathlib.Path, mock_apt_config):
"""
Test that aptpkg can match a repository in the deb822 format.
"""
uri = "http://cz.archive.ubuntu.com/ubuntu/"
repo = f"deb {uri} noble main"

result = aptpkg.get_repo(repo)

assert bool(result)
assert result["uri"] == uri


def test_version(lowpkg_info_var):
"""
Test - Returns a string representing the package version or an empty string if
Expand Down
0