diff --git a/insights/specs/datasources/ethernet.py b/insights/specs/datasources/ethernet.py index 2224f47410..351b1905af 100644 --- a/insights/specs/datasources/ethernet.py +++ b/insights/specs/datasources/ethernet.py @@ -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 @@ -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 diff --git a/insights/specs/default.py b/insights/specs/default.py index b600c1bdd4..7b7d91c7b1 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -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) diff --git a/insights/tests/datasources/test_ethernet.py b/insights/tests/datasources/test_ethernet.py index 1d4a35ca97..eeccf210f1 100644 --- a/insights/tests/datasources/test_ethernet.py +++ b/insights/tests/datasources/test_ethernet.py @@ -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" @@ -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'] @@ -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)