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

Feat: Add teamdctl_state_dump spec to insights_archive #3455

Merged
merged 8 commits into from
Jul 14, 2022
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
30 changes: 30 additions & 0 deletions insights/specs/datasources/ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from insights.core.dr import SkipComponent
from insights.core.plugins import datasource
from insights.core.spec_factory import simple_command
from insights.parsers.nmcli import NmcliConnShow
from insights.specs import Specs


Expand Down Expand Up @@ -55,3 +56,32 @@ def interfaces(broker):
return sorted(ifaces)

raise SkipComponent


@datasource(NmcliConnShow, HostContext)
def team_interfaces(broker):
"""
This datasource provides a list of the team device.

Sample data returned::

['team0', 'team1']

Returns:
list: List of the team device.

Raises:
SkipComponent: When there is not any team interfaces.
"""

content = broker[NmcliConnShow].data
if content:
team_ifaces = []
for x in content:
if 'team' in x['TYPE'] and x['DEVICE'] != '--':
team_ifaces.append(x['DEVICE'])

if team_ifaces:
return sorted(team_ifaces)

raise SkipComponent
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ class DefaultSpecs(Specs):
])
sys_vmbus_device_id = glob_file('/sys/bus/vmbus/devices/*/device_id')
sys_vmbus_class_id = glob_file('/sys/bus/vmbus/devices/*/class_id')
teamdctl_state_dump = foreach_execute(ethernet.team_interfaces, "/usr/bin/teamdctl %s state dump")
testparm_s = simple_command("/usr/bin/testparm -s")
testparm_v_s = simple_command("/usr/bin/testparm -v -s")
tags = simple_file("/tags.json", kind=RawFileProvider)
Expand Down
69 changes: 68 additions & 1 deletion insights/tests/datasources/test_ethernet.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest

from insights.core.dr import SkipComponent
from insights.specs.datasources.ethernet import interfaces, LocalSpecs
from insights.specs.datasources.ethernet import interfaces, LocalSpecs, team_interfaces
from insights.parsers.nmcli import NmcliConnShow
from mock.mock import Mock
from insights.tests import context_wrap

RELATIVE_PATH = "insights_commands/ethernet_interfaces"

Expand All @@ -16,6 +18,29 @@

IP_LINK_BAD = ""

NMCLI_C_SHOW_OUTPUT_1 = """
NAME UUID TYPE DEVICE
enp0s3 320d4923-c410-4b22-b7e9-afc5f794eecc ethernet enp0s3
virbr0 7c7dec66-4a8c-4b49-834a-889194b3b83c bridge virbr0
test-net f858b1cc-d149-4de0-93bc-b1826256847a ethernet --
team0 bf000427-d9f1-432f-819d-257edb86c6fb team team0
ens3 1b1f5c95-1026-4699-95e5-2cd5baa033c3 ethernet ens3
ens8 a2c39643-b356-435a-955c-50cef6b36052 ethernet ens8
team1 ca07b1cf-b293-4871-b255-17f1abfa991d team team1
"""

NMCLI_C_SHOW_OUTPUT_2 = """
NAME UUID TYPE DEVICE
enp0s3 320d4923-c410-4b22-b7e9-afc5f794eecc ethernet enp0s3
"""

NMCLI_C_SHOW_OUTPUT_3 = """
NAME UUID TYPE DEVICE
team0 bf000427-d9f1-432f-819d-257edb86c6fb team --
"""

NMCLI_C_SHOW_EMPTY = ""

EXPECTED = ['enp1s0', 'enp8s0', 'enp1s0.2']


Expand All @@ -35,3 +60,45 @@ def test_ethernet_interfaces_bad():
broker = {LocalSpecs.ip_link: ip_link_command}
with pytest.raises(SkipComponent):
interfaces(broker)


def test_team_device_1():
mmcli_c_show = NmcliConnShow(context_wrap(NMCLI_C_SHOW_OUTPUT_1))

broker = {
NmcliConnShow: mmcli_c_show
}
result = team_interfaces(broker)
assert result is not None
assert isinstance(result, list)
assert result == sorted(['team0', 'team1'])


def test_team_device_2():
mmcli_c_show = NmcliConnShow(context_wrap(NMCLI_C_SHOW_OUTPUT_2))

broker = {
NmcliConnShow: mmcli_c_show
}
with pytest.raises(SkipComponent):
team_interfaces(broker)


def test_team_device_3():
mmcli_c_show = NmcliConnShow(context_wrap(NMCLI_C_SHOW_OUTPUT_3))

broker = {
NmcliConnShow: mmcli_c_show
}
with pytest.raises(SkipComponent):
team_interfaces(broker)


def test_team_device_bad():
mmcli_c_show = NmcliConnShow(context_wrap(NMCLI_C_SHOW_EMPTY))

broker = {
NmcliConnShow: mmcli_c_show
}
with pytest.raises(SkipComponent):
team_interfaces(broker)