forked from oamg/leapp-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for actor udevamdinfo
* Move actor's process to its library * Add check for run in process * Create file with short output of 'udevamd info -e' for testing purposes * Add unit tests for actor Jira: OAMG-1277
- Loading branch information
1 parent
050620e
commit b65ef94
Showing
4 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from leapp.exceptions import StopActorExecutionError | ||
from leapp.libraries.stdlib import api, CalledProcessError, run | ||
from leapp.models import UdevAdmInfoData | ||
|
||
|
||
def process(): | ||
try: | ||
out = run(['udevadm', 'info', '-e'])['stdout'] | ||
except (CalledProcessError, OSError) as err: | ||
raise StopActorExecutionError( | ||
message=( | ||
"Unable to gather information about the system devices" | ||
), | ||
details={ | ||
'details': 'Failed to execute `udevadm info -e` command.', | ||
'error': str(err) | ||
} | ||
) | ||
api.produce(UdevAdmInfoData(db=out)) |
134 changes: 134 additions & 0 deletions
134
repos/system_upgrade/common/actors/udev/udevadminfo/tests/files/udevadm_database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:LNXCPU: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1698543 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:01 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:01 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:LNXCPU: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1698839 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0103:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0103:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:PNP0103: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1697906 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:PNP0A03: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1698109 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/PNP0A06:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/PNP0A06:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:PNP0A06: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1702939 | ||
P: /devices/LNXSYSTM:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:LNXSYSTM: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1694509 | ||
|
||
P: /devices/LNXSYSTM:00/LNXPWRBN:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXPWRBN:00 | ||
E: DRIVER=button | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:LNXPWRBN: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1695034 | ||
|
||
P: /devices/LNXSYSTM:00/LNXPWRBN:00/input/input0 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input0 | ||
E: EV=3 | ||
E: ID_FOR_SEAT=input-acpi-LNXPWRBN_00 | ||
E: ID_INPUT=1 | ||
E: ID_INPUT_KEY=1 | ||
E: ID_PATH=acpi-LNXPWRBN:00 | ||
E: ID_PATH_TAG=acpi-LNXPWRBN_00 | ||
E: KEY=10000000000000 0 | ||
E: MODALIAS=input:b0019v0000p0001e0000-e0,1,k74,ramlsfw | ||
E: NAME="Power Button" | ||
E: PHYS="LNXPWRBN/button/input0" | ||
E: PRODUCT=19/0/1/0 | ||
E: PROP=0 | ||
E: SUBSYSTEM=input | ||
E: TAGS=:seat: | ||
E: USEC_INITIALIZED=1697068 | ||
|
||
P: /devices/LNXSYSTM:00/LNXPWRBN:00/input/input0/event0 | ||
N: input/event0 | ||
E: DEVNAME=/dev/input/event0 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input0/event0 | ||
E: ID_INPUT=1 | ||
E: ID_INPUT_KEY=1 | ||
E: ID_PATH=acpi-LNXPWRBN:00 | ||
E: ID_PATH_TAG=acpi-LNXPWRBN_00 | ||
E: MAJOR=13 | ||
E: MINOR=64 | ||
E: SUBSYSTEM=input | ||
E: TAGS=:power-switch: | ||
E: USEC_INITIALIZED=1744996 | ||
|
||
P: /devices/LNXSYSTM:00/LNXPWRBN:00/wakeup/wakeup10 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXPWRBN:00/wakeup/wakeup10 | ||
E: SUBSYSTEM=wakeup | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:LNXSYBUS: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1695925 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:ACPI0010:PNP0A05: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1698058 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:LNXCPU: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1698543 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:01 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/LNXCPU:01 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:LNXCPU: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1698839 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0103:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0103:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:PNP0103: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1697906 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:PNP0A03: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1698109 | ||
|
||
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/PNP0A06:00 | ||
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/PNP0A06:00 | ||
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation | ||
E: MODALIAS=acpi:PNP0A06: | ||
E: SUBSYSTEM=acpi | ||
E: USEC_INITIALIZED=1702939 | ||
|
40 changes: 40 additions & 0 deletions
40
repos/system_upgrade/common/actors/udev/udevadminfo/tests/test_udevadminfo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from leapp.exceptions import StopActorExecutionError | ||
from leapp.libraries.actor import udevadminfo | ||
from leapp.libraries.common import testutils | ||
from leapp.libraries.stdlib import api, CalledProcessError | ||
from leapp.models import UdevAdmInfoData | ||
|
||
CUR_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
def _raise_call_error(*args): | ||
raise CalledProcessError( | ||
message='A Leapp Command Error occurred.', | ||
command=args, | ||
result={'signal': None, 'exit_code': 1, 'pid': 0, 'stdout': 'fake', 'stderr': 'fake'} | ||
) | ||
|
||
|
||
def test_failed_run(monkeypatch): | ||
monkeypatch.setattr(api, 'produce', testutils.produce_mocked()) | ||
monkeypatch.setattr(udevadminfo, 'run', _raise_call_error) | ||
|
||
with pytest.raises(StopActorExecutionError): | ||
udevadminfo.process() | ||
|
||
|
||
def test_udevadminfo(monkeypatch): | ||
|
||
with open(os.path.join(CUR_DIR, 'files', 'udevadm_database'), 'r') as fp: | ||
mocked_data = fp.read() | ||
monkeypatch.setattr(api, 'produce', testutils.produce_mocked()) | ||
monkeypatch.setattr(udevadminfo, 'run', lambda *args: {'stdout': mocked_data}) | ||
udevadminfo.process() | ||
|
||
assert api.produce.called == 1 | ||
assert isinstance(api.produce.model_instances[0], UdevAdmInfoData) | ||
assert api.produce.model_instances[0].db == mocked_data |