Skip to content

Commit

Permalink
Finish unit testing of HW transformations in mrack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
happz authored and psss committed Mar 19, 2024
1 parent fb6ceb6 commit 630e95a
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 125 deletions.
233 changes: 212 additions & 21 deletions tests/unit/provision/mrack/test_hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import pytest

import tmt.utils
from tmt.hardware import Hardware, Operator, _parse_hostname, _parse_memory
from tmt.hardware import (
Hardware,
Operator,
_parse_cpu,
_parse_disk,
_parse_hostname,
_parse_memory,
_parse_virtualization,
)
from tmt.log import Logger
from tmt.steps.provision.mrack import (
_CONSTRAINT_TRANSFORMERS,
Expand Down Expand Up @@ -57,7 +65,9 @@ def test_maximal_constraint(root_logger: Logger) -> None:
- "!= smep"
disk:
- size: 40 GiB
model-name: "PERC H310"
- size: 120 GiB
driver: mpt3sas
gpu:
device-name: G86 [Quadro NVS 290]
hostname: "~ .*.foo.redhat.com"
Expand Down Expand Up @@ -111,15 +121,6 @@ def test_maximal_constraint(root_logger: Logger) -> None:
}
},
{'or': []},
{
'cpu': {
'model': {
'_op': '==',
'_value': '62'
}
}
},
{'or': []},
{'or': []},
{'or': []},
{
Expand Down Expand Up @@ -163,21 +164,44 @@ def test_maximal_constraint(root_logger: Logger) -> None:
{
'and': [
{
'disk': {
'size': {
'_op': '==',
'_value': '42949672960'
'and': [
{
'disk': {
'size': {
'_op': '==',
'_value': '42949672960'
}
}
},
{
'disk': {
'model': {
'_op': '==',
'_value': 'PERC H310'
}
}
}
}
]
},
{
'disk': {
'size': {
'_op': '==',
'_value': '128849018880'
'and': [
{
'disk': {
'size': {
'_op': '==',
'_value': '128849018880'
}
}
},
{
'key_value': {
'_key': 'BOOTDISK',
'_op': '==',
'_value': 'mpt3sas'
}
}
}
}
]
},
]
},
{
Expand Down Expand Up @@ -211,6 +235,147 @@ def test_maximal_constraint(root_logger: Logger) -> None:
}


def test_cpu_model(root_logger: Logger) -> None:
result = _CONSTRAINT_TRANSFORMERS['cpu.model'](_parse_cpu({'model': '79'}), root_logger)

assert result.to_mrack() == {
'cpu': {
'model': {
'_op': '==',
'_value': '79'
}
}
}


def test_cpu_processors(root_logger: Logger) -> None:
result = _CONSTRAINT_TRANSFORMERS['cpu.processors'](
_parse_cpu({'processors': '79'}), root_logger)

assert result.to_mrack() == {
'cpu': {
'cpu_count': {
'_op': '==',
'_value': '79'
}
}
}


def test_disk_driver(root_logger: Logger) -> None:
result = _CONSTRAINT_TRANSFORMERS['disk.driver'](
_parse_disk({'driver': 'mpt3sas'}, 1), root_logger)

assert result.to_mrack() == {
'key_value': {
'_key': 'BOOTDISK',
'_op': '==',
'_value': 'mpt3sas'
}
}

result = _CONSTRAINT_TRANSFORMERS['disk.driver'](
_parse_disk({'driver': '!= mpt3sas'}, 1), root_logger)

assert result.to_mrack() == {
'key_value': {
'_key': 'BOOTDISK',
'_op': '!=',
'_value': 'mpt3sas'
}
}

result = _CONSTRAINT_TRANSFORMERS['disk.driver'](
_parse_disk({'driver': '~ mpt3.*'}, 1), root_logger)

assert result.to_mrack() == {
'key_value': {
'_key': 'BOOTDISK',
'_op': 'like',
'_value': 'mpt3%'
}
}

result = _CONSTRAINT_TRANSFORMERS['disk.driver'](
_parse_disk({'driver': '!~ mpt3.*'}, 1), root_logger)

assert result.to_mrack() == {
'not': {
'key_value': {
'_key': 'BOOTDISK',
'_op': 'like',
'_value': 'mpt3%'
}
}
}


def test_disk_size(root_logger: Logger) -> None:
result = _CONSTRAINT_TRANSFORMERS['disk.size'](
_parse_disk({'size': '>= 40 GiB'}, 1), root_logger)

assert result.to_mrack() == {
'disk': {
'size': {
'_op': '>=',
'_value': '42949672960'
}
}
}


def test_disk_model_name(root_logger: Logger) -> None:
result = _CONSTRAINT_TRANSFORMERS['disk.model_name'](
_parse_disk({'model-name': 'PERC H310'}, 1), root_logger)

assert result.to_mrack() == {
'disk': {
'model': {
'_op': '==',
'_value': 'PERC H310'
}
}
}

result = _CONSTRAINT_TRANSFORMERS['disk.model_name'](
_parse_disk({'model-name': '!= PERC H310'}, 1), root_logger)

assert result.to_mrack() == {
'disk': {
'model': {
'_op': '!=',
'_value': 'PERC H310'
}
}
}

result = _CONSTRAINT_TRANSFORMERS['disk.model_name'](
_parse_disk({'model-name': '~ PERC.*'}, 1), root_logger)

assert result.to_mrack() == {
'disk': {
'model': {
'_op': 'like',
'_value': 'PERC%'
}
}
}

result = _CONSTRAINT_TRANSFORMERS['disk.model_name'](
_parse_disk({'model-name': '!~ PERC.*'}, 1), root_logger)

assert result.to_mrack() == {
'not': {
'disk': {
'model': {
'_op': 'like',
'_value': 'PERC%'
}
}
}
}


def test_memory(root_logger: Logger) -> None:
result = _CONSTRAINT_TRANSFORMERS['memory'](_parse_memory({'memory': '>= 4 GiB'}), root_logger)

Expand Down Expand Up @@ -256,3 +421,29 @@ def test_hostname(root_logger: Logger) -> None:
}
}
}


def test_virtualization_is_virtualized(root_logger: Logger) -> None:
result = _CONSTRAINT_TRANSFORMERS['virtualization.is_virtualized'](
_parse_virtualization({'is-virtualized': True}), root_logger)

assert result.to_mrack() == {
'system': {
'hypervisor': {
'_op': '!=',
'_value': ''
}
}
}

result = _CONSTRAINT_TRANSFORMERS['virtualization.is_virtualized'](
_parse_virtualization({'is-virtualized': False}), root_logger)

assert result.to_mrack() == {
'system': {
'hypervisor': {
'_op': '==',
'_value': ''
}
}
}
13 changes: 0 additions & 13 deletions tmt/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,19 +1010,6 @@ def _parse_cpu(spec: Spec) -> BaseConstraint:
if constraint_name in spec
]

group.constraints += [
TextConstraint.from_specification(
f'cpu.{constraint_name.replace("-", "_")}',
str(spec[constraint_name]),
allowed_operators=[
Operator.EQ, Operator.NEQ, Operator.LT, Operator.LTE, Operator.GT, Operator.GTE])
for constraint_name in (
'model',
'family'
)
if constraint_name in spec
]

group.constraints += [
TextConstraint.from_specification(
f'cpu.{constraint_name.replace("-", "_")}',
Expand Down
Loading

0 comments on commit 630e95a

Please sign in to comment.