Skip to content
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

Add test for udevadminfo actor #1186

Merged
merged 1 commit into from
Mar 28, 2024
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
5 changes: 2 additions & 3 deletions repos/system_upgrade/common/actors/udev/udevadminfo/actor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from leapp.actors import Actor
from leapp.libraries.stdlib import run
from leapp.libraries.actor import udevadminfo
from leapp.models import UdevAdmInfoData
from leapp.tags import FactsPhaseTag, IPUWorkflowTag

Expand All @@ -15,5 +15,4 @@ class UdevAdmInfo(Actor):
tags = (IPUWorkflowTag, FactsPhaseTag,)

def process(self):
out = run(['udevadm', 'info', '-e'])['stdout']
self.produce(UdevAdmInfoData(db=out))
udevadminfo.process()
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))
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

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:
tomasfratrik marked this conversation as resolved.
Show resolved Hide resolved
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
Loading