mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-13 22:15:48 +00:00
Remote call trigger support (#105)
* add support of remote task tracking * add remote call trigger implementation * docs update * add cross-service upload * add notes about user * add more ability to control upload * multipart upload with signatures as well as safe file save * configuration reference update * rename watcher methods * erase logs based on current package version Old implementation has used process id instead, but it leads to log removal in case of remote process trigger * add --server flag for setup command * restore behavior of the httploghandler
This commit is contained in:
@ -1,9 +1,17 @@
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.core.spawn import Spawn
|
||||
|
||||
|
||||
def test_boolean_action_argument() -> None:
|
||||
"""
|
||||
must correctly convert argument to boolean flag
|
||||
"""
|
||||
assert Spawn.boolean_action_argument("option", True) == "option"
|
||||
assert Spawn.boolean_action_argument("option", False) == "no-option"
|
||||
|
||||
|
||||
def test_process(spawner: Spawn) -> None:
|
||||
"""
|
||||
must process external process run correctly
|
||||
@ -15,9 +23,10 @@ def test_process(spawner: Spawn) -> None:
|
||||
spawner.process(callback, args, spawner.architecture, "id", spawner.queue)
|
||||
|
||||
callback.assert_called_once_with(args, spawner.architecture)
|
||||
(uuid, status) = spawner.queue.get()
|
||||
(uuid, status, time) = spawner.queue.get()
|
||||
assert uuid == "id"
|
||||
assert status
|
||||
assert time >= 0
|
||||
assert spawner.queue.empty()
|
||||
|
||||
|
||||
@ -30,9 +39,10 @@ def test_process_error(spawner: Spawn) -> None:
|
||||
|
||||
spawner.process(callback, MagicMock(), spawner.architecture, "id", spawner.queue)
|
||||
|
||||
(uuid, status) = spawner.queue.get()
|
||||
(uuid, status, time) = spawner.queue.get()
|
||||
assert uuid == "id"
|
||||
assert not status
|
||||
assert time >= 0
|
||||
assert spawner.queue.empty()
|
||||
|
||||
|
||||
@ -42,7 +52,7 @@ def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
start_mock = mocker.patch("multiprocessing.Process.start")
|
||||
|
||||
spawner._spawn_process("add", "ahriman", now="", maybe="?", none=None)
|
||||
assert spawner._spawn_process("add", "ahriman", now="", maybe="?", none=None)
|
||||
start_mock.assert_called_once_with()
|
||||
spawner.args_parser.parse_args.assert_called_once_with(
|
||||
spawner.command_arguments + [
|
||||
@ -51,12 +61,22 @@ def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_has_process(spawner: Spawn) -> None:
|
||||
"""
|
||||
must correctly determine if there is a process
|
||||
"""
|
||||
assert not spawner.has_process("id")
|
||||
|
||||
spawner.active["id"] = MagicMock()
|
||||
assert spawner.has_process("id")
|
||||
|
||||
|
||||
def test_key_import(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call key import
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.key_import("0xdeadbeaf", None)
|
||||
assert spawner.key_import("0xdeadbeaf", None)
|
||||
spawn_mock.assert_called_once_with("service-key-import", "0xdeadbeaf")
|
||||
|
||||
|
||||
@ -65,7 +85,7 @@ def test_key_import_with_server(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call key import with server specified
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.key_import("0xdeadbeaf", "keyserver.ubuntu.com")
|
||||
assert spawner.key_import("0xdeadbeaf", "keyserver.ubuntu.com")
|
||||
spawn_mock.assert_called_once_with("service-key-import", "0xdeadbeaf", **{"key-server": "keyserver.ubuntu.com"})
|
||||
|
||||
|
||||
@ -74,7 +94,7 @@ def test_packages_add(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call package addition
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], None, now=False)
|
||||
assert spawner.packages_add(["ahriman", "linux"], None, now=False)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", username=None)
|
||||
|
||||
|
||||
@ -83,7 +103,7 @@ def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call package addition with update
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], None, now=True)
|
||||
assert spawner.packages_add(["ahriman", "linux"], None, now=True)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", username=None, now="")
|
||||
|
||||
|
||||
@ -92,7 +112,7 @@ def test_packages_add_with_username(spawner: Spawn, mocker: MockerFixture) -> No
|
||||
must call package addition with username
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], "username", now=False)
|
||||
assert spawner.packages_add(["ahriman", "linux"], "username", now=False)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", username="username")
|
||||
|
||||
|
||||
@ -101,7 +121,7 @@ def test_packages_rebuild(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call package rebuild
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_rebuild("python", "packager")
|
||||
assert spawner.packages_rebuild("python", "packager")
|
||||
spawn_mock.assert_called_once_with("repo-rebuild", **{"depends-on": "python", "username": "packager"})
|
||||
|
||||
|
||||
@ -110,7 +130,7 @@ def test_packages_remove(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call package removal
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_remove(["ahriman", "linux"])
|
||||
assert spawner.packages_remove(["ahriman", "linux"])
|
||||
spawn_mock.assert_called_once_with("package-remove", "ahriman", "linux")
|
||||
|
||||
|
||||
@ -119,8 +139,26 @@ def test_packages_update(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call repo update
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_update("packager")
|
||||
spawn_mock.assert_called_once_with("repo-update", username="packager")
|
||||
|
||||
assert spawner.packages_update("packager", aur=True, local=True, manual=True)
|
||||
args = {"username": "packager", "aur": "", "local": "", "manual": ""}
|
||||
spawn_mock.assert_called_once_with("repo-update", **args)
|
||||
spawn_mock.reset_mock()
|
||||
|
||||
assert spawner.packages_update("packager", aur=False, local=True, manual=True)
|
||||
args = {"username": "packager", "no-aur": "", "local": "", "manual": ""}
|
||||
spawn_mock.assert_called_once_with("repo-update", **args)
|
||||
spawn_mock.reset_mock()
|
||||
|
||||
assert spawner.packages_update("packager", aur=True, local=False, manual=True)
|
||||
args = {"username": "packager", "aur": "", "no-local": "", "manual": ""}
|
||||
spawn_mock.assert_called_once_with("repo-update", **args)
|
||||
spawn_mock.reset_mock()
|
||||
|
||||
assert spawner.packages_update("packager", aur=True, local=True, manual=False)
|
||||
args = {"username": "packager", "aur": "", "local": "", "no-manual": ""}
|
||||
spawn_mock.assert_called_once_with("repo-update", **args)
|
||||
spawn_mock.reset_mock()
|
||||
|
||||
|
||||
def test_run(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
@ -129,8 +167,8 @@ def test_run(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
logging_mock = mocker.patch("logging.Logger.info")
|
||||
|
||||
spawner.queue.put(("1", False))
|
||||
spawner.queue.put(("2", True))
|
||||
spawner.queue.put(("1", False, 1))
|
||||
spawner.queue.put(("2", True, 1))
|
||||
spawner.queue.put(None) # terminate
|
||||
|
||||
spawner.run()
|
||||
@ -144,8 +182,8 @@ def test_run_pop(spawner: Spawn) -> None:
|
||||
first = spawner.active["1"] = MagicMock()
|
||||
second = spawner.active["2"] = MagicMock()
|
||||
|
||||
spawner.queue.put(("1", False))
|
||||
spawner.queue.put(("2", True))
|
||||
spawner.queue.put(("1", False, 1))
|
||||
spawner.queue.put(("2", True, 1))
|
||||
spawner.queue.put(None) # terminate
|
||||
|
||||
spawner.run()
|
||||
|
Reference in New Issue
Block a user