Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
125 changes: 118 additions & 7 deletions dnf-behave-tests/dnf/plugins-core/actions-json_mode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ check_reply(

And file "/var/log/dnf5.log" contains lines
"""
TRACE Actions plugin: Hook in file .* Test log message 1
DEBUG Actions plugin: Hook in file .* Test log message 2
INFO Actions plugin: Hook in file .* Test log message 3
NOTICE Actions plugin: Hook in file .* Test log message 4
WARNING Actions plugin: Hook in file .* Test log message 5
ERROR Actions plugin: Hook in file .* Test log message 6
CRITICAL Actions plugin: Hook in file .* Test log message 7
TRACE Actions plugin: .* Test log message 1
DEBUG Actions plugin: .* Test log message 2
INFO Actions plugin: .* Test log message 3
NOTICE Actions plugin: .* Test log message 4
WARNING Actions plugin: .* Test log message 5
ERROR Actions plugin: .* Test log message 6
CRITICAL Actions plugin: .* Test log message 7
"""


Expand Down Expand Up @@ -727,3 +727,114 @@ check_reply("Incomplete input", {})
Syntax error in json request .* expected
Syntax error in json request .* Incomplete input
"""


Scenario: Testing the "error" action message (JSON mode)
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
repos_configured:::mode=json:/bin/python3 {context.dnf.installroot}/etc/dnf/libdnf5-plugins/actions.d/json_hook_error1.py {context.dnf.installroot}/actions.log
repos_configured:::mode=json raise_error=0:/bin/python3 {context.dnf.installroot}/etc/dnf/libdnf5-plugins/actions.d/json_hook_error2.py {context.dnf.installroot}/actions.log
repos_configured:::mode=json raise_error=1:/bin/python3 {context.dnf.installroot}/etc/dnf/libdnf5-plugins/actions.d/json_hook_error3.py {context.dnf.installroot}/actions.log
"""

And I create file "/etc/dnf/libdnf5-plugins/actions.d/json_hook_error1.py" with
"""
from json_test_utils import *

send_request({"op": "error", "args": {"message": "Error in action process 1"}})
check_reply(
'Sent "error" message, no "raise_error" defined',
{"op": "reply", "requested_op": "error", "domain": "error", "status": "OK"})
"""

And I create file "/etc/dnf/libdnf5-plugins/actions.d/json_hook_error2.py" with
"""
from json_test_utils import *

send_request({"op": "error", "args": {"message": "Error in action process 2"}})
check_reply(
'Sent "error" message, "raise_error=0"',
{"op": "reply", "requested_op": "error", "domain": "error", "status": "OK"})
"""

And I create file "/etc/dnf/libdnf5-plugins/actions.d/json_hook_error3.py" with
"""
from json_test_utils import *

send_request({"op": "error", "args": {"message": "Error in action process 3"}})
check_reply(
'Sent "error" message, "raise_error=1"',
{"op": "reply", "requested_op": "error", "domain": "error", "status": "OK"})
"""

When I execute dnf with args "repo list"
Then the exit code is 1

And file "/actions.log" contents is
"""
Sent "error" message, no "raise_error" defined: OK
Sent "error" message, "raise_error=0": OK
Sent "error" message, "raise_error=1": Error: No reply
"""

And stderr contains "Action sent error message: Error in action process 3"

And file "/var/log/dnf5.log" contains lines
"""
ERROR Actions plugin: .* Action sent error message: Error in action process 1
ERROR Actions plugin: .* Action sent error message: Error in action process 2
"""


Scenario: Testing the "stop" action request (JSON mode)
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
repos_configured:::mode=json raise_error=1:/bin/python3 {context.dnf.installroot}/etc/dnf/libdnf5-plugins/actions.d/json_hook_stop.py {context.dnf.installroot}/actions.log
"""

And I create file "/etc/dnf/libdnf5-plugins/actions.d/json_hook_stop.py" with
"""
from json_test_utils import *

send_request({"op": "stop", "args": {"message": "I want to stop the task"}})
check_reply(
'Sent "stop" request',
{"op": "reply", "requested_op": "stop", "domain": "stop", "status": "OK"})
"""

When I execute dnf with args "repo list"
Then the exit code is 1

And file "/actions.log" contents is
"""
Sent "stop" request: Error: No reply
"""

And stderr contains "Action calls for stop: I want to stop the task"


Scenario: Testing the "stop" action request (JSON mode), must thrown exception even with "raise_error=0"
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
repos_configured:::mode=json raise_error=0:/bin/python3 {context.dnf.installroot}/etc/dnf/libdnf5-plugins/actions.d/json_hook_stop.py {context.dnf.installroot}/actions.log
"""

And I create file "/etc/dnf/libdnf5-plugins/actions.d/json_hook_stop.py" with
"""
from json_test_utils import *

send_request({"op": "stop", "args": {"message": "I want to stop the task"}})
check_reply(
'Sent "stop" request',
{"op": "reply", "requested_op": "stop", "domain": "stop", "status": "OK"})
"""

When I execute dnf with args "repo list"
Then the exit code is 1

And file "/actions.log" contents is
"""
Sent "stop" request: Error: No reply
"""

And stderr contains "Action calls for stop: I want to stop the task"
143 changes: 143 additions & 0 deletions dnf-behave-tests/dnf/plugins-core/actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,146 @@ Scenario: Reason change is in transaction
\? installonlyA-0:2.0-1.x86_64 repo @System
I installonlyA-0:2.2-1.x86_64 repo installonly
"""


Scenario: Testing the "raise_error" and a non-existent action process file
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
# Error logged.
repos_configured::::/bin/non-existed ab c
repos_configured:::raise_error=0:/bin/non-existed d ef

# Exception thrown.
repos_configured:::raise_error=1:/bin/non-existed xy z
"""
When I execute dnf with args "install setup"
Then the exit code is 1
And stderr contains "Cannot execute action, command \"/bin/non-existed\" arguments \"xy z\""
And file "/var/log/dnf5.log" contains lines
"""
ERROR Actions plugin: .* Cannot execute action, command "/bin/non-existed" arguments "ab c"
ERROR Actions plugin: .* Cannot execute action, command "/bin/non-existed" arguments "d ef"
"""


Scenario: Testing the "raise_error" option and exit codes
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
# Zero exit code. Success. No error was logged and no exception was thrown.
repos_configured::::/bin/sh -c exit\ 0
repos_configured:::raise_error=0:/bin/sh -c exit\ 0
repos_configured:::raise_error=1:/bin/sh -c exit\ 0

# Non-zero exit code. Error logged.
repos_configured::::/bin/sh -c exit\ 1
repos_configured:::raise_error=0:/bin/sh -c exit\ 2

# Non-zero exit code. Exception thrown.
repos_configured:::raise_error=1:/bin/sh -c exit\ 3
"""
When I execute dnf with args "install setup"
Then the exit code is 1
And stderr contains "Exit code: 3"
And file "/var/log/dnf5.log" does not contain lines
"""
ERROR Actions plugin: .* Exit code: 0
"""
And file "/var/log/dnf5.log" contains lines
"""
ERROR Actions plugin: .* Exit code: 1
ERROR Actions plugin: .* Exit code: 2
"""


Scenario: Testing the "raise_error" option and failed to process the output line in plain communication mode
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
# Error logged.
repos_configured::::/bin/sh -c echo\ "conf.nonexist_option=1"
repos_configured:::raise_error=0:/bin/sh -c echo\ "conf.nonexist_option=2"

# Exception thrown.
repos_configured:::raise_error=1:/bin/sh -c echo\ "conf.nonexist_option=3"
"""
When I execute dnf with args "install setup"
Then the exit code is 1
And stderr contains "Cannot set option: Action output line: conf.nonexist_option=3"
And file "/var/log/dnf5.log" contains lines
"""
ERROR Actions plugin: .* Cannot set option: Action output line: conf.nonexist_option=1
ERROR Actions plugin: .* Cannot set option: Action output line: conf.nonexist_option=2
"""


Scenario: Testing the "error" action message
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
# Error logged.
repos_configured::::/bin/sh -c echo\ "error=Error\ in\ action\ process\ 1"
repos_configured:::raise_error=0:/bin/sh -c echo\ "error=Error\ in\ action\ process\ 2"

# Exception thrown.
repos_configured:::raise_error=1:/bin/sh -c echo\ "error=Error\ in\ action\ process\ 3"
"""
When I execute dnf with args "install setup"
Then the exit code is 1
And stderr contains "Action sent error message: Error in action process 3"
And file "/var/log/dnf5.log" contains lines
"""
ERROR Actions plugin: .* Action sent error message: Error in action process 1
ERROR Actions plugin: .* Action sent error message: Error in action process 2
"""


Scenario: Testing the "stop" action request
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
# Exception thrown.
repos_configured:::raise_error=1:/bin/sh -c echo\ "stop=I\ want\ to\ stop\ the\ task"
"""
When I execute dnf with args "install setup"
Then the exit code is 1
And stderr contains "Action calls for stop: I want to stop the task"


Scenario: Testing the "stop" action request, must thrown exception even with "raise_error=0"
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
# Exception thrown.
repos_configured:::raise_error=0:/bin/sh -c echo\ "stop=I\ want\ to\ stop\ the\ task"
"""
When I execute dnf with args "install setup"
Then the exit code is 1
And stderr contains "Action calls for stop: I want to stop the task"


Scenario: Testing the "log" action request
Given I create and substitute file "/etc/dnf/libdnf5-plugins/actions.d/test.actions" with
"""
# Error logged.
repos_configured::::/bin/sh -c echo\ "log.TRACE=Test\ log\ message\ 1"
repos_configured::::/bin/sh -c echo\ "log.DEBUG=Test\ log\ message\ 2"
repos_configured::::/bin/sh -c echo\ "log.INFO=Test\ log\ message\ 3"
repos_configured::::/bin/sh -c echo\ "log.NOTICE=Test\ log\ message\ 4"
repos_configured::::/bin/sh -c echo\ "log.WARNING=Test\ log\ message\ 5"
repos_configured::::/bin/sh -c echo\ "log.ERROR=Test\ log\ message\ 6"
repos_configured::::/bin/sh -c echo\ "log.CRITICAL=Test\ log\ message\ 7"
repos_configured:::raise_error=0:/bin/sh -c echo\ "log.BAD_LEVEL=Test\ log\ message\ 8"

# Exception thrown.
repos_configured:::raise_error=1:/bin/sh -c echo\ "log.BAD_LEVEL=Test\ log\ message\ 9"
"""
When I execute dnf with args "install setup"
Then the exit code is 1
And stderr contains "Action sent the wrong log level: log.BAD_LEVEL=Test log message 9"
And file "/var/log/dnf5.log" contains lines
"""
TRACE Actions plugin: .* Test log message 1
DEBUG Actions plugin: .* Test log message 2
INFO Actions plugin: .* Test log message 3
NOTICE Actions plugin: .* Test log message 4
WARNING Actions plugin: .* Test log message 5
ERROR Actions plugin: .* Test log message 6
CRITICAL Actions plugin: .* Test log message 7
ERROR Actions plugin: .* Action sent the wrong log level: log.BAD_LEVEL=Test log message 8
"""
Loading