Skip to content

Commit

Permalink
Fix(or skip) remaining broken tests for Ubuntu 24.04
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed May 13, 2024
1 parent 85ea23d commit 86245dc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
5 changes: 3 additions & 2 deletions tests/pytests/functional/modules/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_mod_del_repo(grains, modules):

try:
# ppa:otto-kesselgulasch/gimp-edge has no Ubuntu 22.04 repo
if grains["os"] == "Ubuntu" and grains["osmajorrelease"] != 22:
if grains["os"] == "Ubuntu" and grains["osmajorrelease"] < 22:
repo = "ppa:otto-kesselgulasch/gimp-edge"
uri = "http://ppa.launchpad.net/otto-kesselgulasch/gimp-edge/ubuntu"
ret = modules.pkg.mod_repo(repo, "comps=main")
Expand Down Expand Up @@ -217,7 +217,8 @@ def test_owner(modules):
"""
test finding the package owning a file
"""
ret = modules.pkg.owner("/bin/ls")
binary = shutil.which("ls")
ret = modules.pkg.owner(binary)
assert len(ret) != 0


Expand Down
4 changes: 4 additions & 0 deletions tests/pytests/functional/modules/test_system.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import logging
import os
import shutil
import signal
import subprocess
import textwrap
Expand Down Expand Up @@ -106,6 +107,9 @@ def hwclock_has_compare(cmdmod):
systems where it's not present so that we can skip the
comparison portion of the test.
"""
hwclock = shutil.which("hwclock")
if hwclock is None:
pytest.skip("The 'hwclock' binary could not be found")
res = cmdmod.run_all(cmd="hwclock -h")
_hwclock_has_compare_ = res["retcode"] == 0 and res["stdout"].find("--compare") > 0
return _hwclock_has_compare_
Expand Down
43 changes: 27 additions & 16 deletions tests/pytests/functional/states/pkgrepo/test_debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import pathlib
import shutil
import sys
from sysconfig import get_path
import sysconfig

import attr
import pytest
import requests

import salt.modules.aptpkg
import salt.utils.files
Expand Down Expand Up @@ -123,7 +124,7 @@ def system_aptsources(request, grains):
"{}".format(*sys.version_info),
"{}.{}".format(*sys.version_info),
]
session_site_packages_dir = get_path(
session_site_packages_dir = sysconfig.get_path(
"purelib"
) # note: platlib and purelib could differ
session_site_packages_dir = os.path.relpath(
Expand Down Expand Up @@ -649,6 +650,7 @@ class Repo:
key_file = attr.ib()
sources_list_file = attr.ib()
repo_file = attr.ib()
repo_url = attr.ib()
repo_content = attr.ib()
key_url = attr.ib()

Expand Down Expand Up @@ -686,6 +688,10 @@ def _default_key_file(self):
def _default_repo_file(self):
return self.sources_list_file

@repo_url.default
def _default_repo_url(self):
return f"https://repo.saltproject.io/py3/{self.fullname}/{self.grains['osrelease']}/{self.grains['osarch']}/latest"

@repo_content.default
def _default_repo_content(self):
if self.alt_repo:
Expand All @@ -703,36 +709,41 @@ def _default_repo_content(self):
opts = "[arch={arch} signed-by=/usr/share/keyrings/salt-archive-keyring.gpg]".format(
arch=self.grains["osarch"]
)
repo_content = "deb {opts} https://repo.saltproject.io/py3/{}/{}/{arch}/latest {} main".format(
self.fullname,
self.grains["osrelease"],
self.grains["oscodename"],
arch=self.grains["osarch"],
opts=opts,
repo_content = (
f"deb {opts} {self.repo_url} {self.grains['oscodename']} main"
)
return repo_content

@key_url.default
def _default_key_url(self):
key_url = "https://repo.saltproject.io/py3/{}/{}/{}/latest/salt-archive-keyring.gpg".format(
self.fullname, self.grains["osrelease"], self.grains["osarch"]
)

key_url = f"{self.repo_url}/salt-archive-keyring.gpg"
if self.alt_repo:
key_url = "https://artifacts.elastic.co/GPG-KEY-elasticsearch"
return key_url

@property
def exists(self):
"""
Return True if the repository path exists.
"""
response = requests.head(self.key_url, timeout=30)
return response.status_code == 200


@pytest.fixture
def repo(request, grains, sources_list_file):
signedby = False
if "signedby" in request.node.name:
signedby = True
repo = Repo(grains=grains, sources_list_file=sources_list_file, signedby=signedby)
yield repo
for key in [repo.key_file, repo.key_file.parent / "salt-alt-key.gpg"]:
if key.is_file():
key.unlink()
if not repo.exists:
pytest.skip(f"The repo url '{repo.repo_url}' does not exist")
try:
yield repo
finally:
for key in [repo.key_file, repo.key_file.parent / "salt-alt-key.gpg"]:
if key.is_file():
key.unlink()


def test_adding_repo_file_signedby(pkgrepo, states, repo, subtests):
Expand Down
29 changes: 13 additions & 16 deletions tests/pytests/unit/modules/test_kmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import salt.modules.kmod as kmod
from salt.exceptions import CommandExecutionError
from tests.support.mock import MagicMock, patch
from tests.support.mock import MagicMock, mock_open, patch


@pytest.fixture
Expand All @@ -17,7 +17,7 @@ def test_available():
Tests return a list of all available kernel modules
"""
with patch("salt.modules.kmod.available", MagicMock(return_value=["kvm"])):
assert ["kvm"] == kmod.available()
assert kmod.available() == ["kvm"]


def test_check_available():
Expand All @@ -42,7 +42,7 @@ def test_lsmod():
), patch.dict(kmod.__salt__, {"cmd.run": mock_cmd}):
with pytest.raises(CommandExecutionError):
kmod.lsmod()
assert expected == kmod.lsmod()
assert kmod.lsmod() == expected


@pytest.mark.skipif(
Expand All @@ -55,15 +55,12 @@ def test_mod_list():
with patch(
"salt.modules.kmod._get_modules_conf",
MagicMock(return_value="/etc/modules"),
):
with patch(
"salt.modules.kmod._strip_module_name", MagicMock(return_value="lp")
):
assert ["lp"] == kmod.mod_list(True)
), patch("salt.utils.files.fopen", mock_open(read_data="lp")):
assert kmod.mod_list(True) == ["lp"]

mock_ret = [{"size": 100, "module": None, "depcount": 10, "deps": None}]
with patch("salt.modules.kmod.lsmod", MagicMock(return_value=mock_ret)):
assert [None] == kmod.mod_list(False)
assert kmod.mod_list(False) == [None]


def test_load():
Expand All @@ -90,10 +87,10 @@ def test_load():
kmod.load(mod, True)

with patch.dict(kmod.__salt__, {"cmd.run_all": mock_run_all_0}):
assert [mod] == kmod.load(mod, True)
assert kmod.load(mod, True) == [mod]

with patch.dict(kmod.__salt__, {"cmd.run_all": mock_run_all_1}):
assert f"Error loading module {mod}: {err_msg}" == kmod.load(mod)
assert kmod.load(mod) == f"Error loading module {mod}: {err_msg}"


def test_is_loaded():
Expand Down Expand Up @@ -126,11 +123,11 @@ def test_remove():
with pytest.raises(CommandExecutionError):
kmod.remove(mod)

assert [mod] == kmod.remove(mod, True)
assert kmod.remove(mod, True) == [mod]

assert [] == kmod.remove(mod)
assert kmod.remove(mod) == []

with patch.dict(kmod.__salt__, {"cmd.run_all": mock_run_all_1}):
assert "Error removing module {}: {}".format(
mod, err_msg
) == kmod.remove(mod, True)
assert (
kmod.remove(mod, True) == f"Error removing module {mod}: {err_msg}"
)

0 comments on commit 86245dc

Please sign in to comment.