From: Harshal Gohel Date: Mon, 11 Apr 2022 12:45:05 +0000 (+0530) Subject: tests: Add inventory configuration tests X-Git-Tag: 1.0.14~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df35cd76a99eba2d1f93b594dc4c3608cbd1c18a;p=thirdparty%2Flldpd.git tests: Add inventory configuration tests --- diff --git a/tests/integration/test_configinventory.py b/tests/integration/test_configinventory.py new file mode 100644 index 00000000..a3945410 --- /dev/null +++ b/tests/integration/test_configinventory.py @@ -0,0 +1,88 @@ +import os +import pytest +import platform +import time +import shlex + +@pytest.mark.skipif("'LLDP-MED' not in config.lldpd.features", + reason="LLDP-MED not supported") +class TestConfigInventory(object): + + def test_configinventory(self, lldpd1, lldpd, lldpcli, namespaces, + replace_file): + with namespaces(2): + if os.path.isdir("/sys/class/dmi/id"): + # /sys/class/dmi/id/* + for what, value in dict(product_version="1.14", + bios_version="1.10", + product_serial="45872512", + sys_vendor="Spectacular", + product_name="Workstation", + chassis_asset_tag="487122").items(): + replace_file("/sys/class/dmi/id/{}".format(what), + value) + lldpd("-M", "1") + + def test_default_inventory(namespaces, lldpcli): + with namespaces(1): + if os.path.isdir("/sys/class/dmi/id"): + out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") + assert out['lldp.eth0.chassis.name'] == 'ns-2.example.com' + assert out['lldp.eth0.lldp-med.inventory.hardware'] == '1.14' + assert out['lldp.eth0.lldp-med.inventory.firmware'] == '1.10' + assert out['lldp.eth0.lldp-med.inventory.serial'] == '45872512' + assert out['lldp.eth0.lldp-med.inventory.manufacturer'] == \ + 'Spectacular' + assert out['lldp.eth0.lldp-med.inventory.model'] == 'Workstation' + assert out['lldp.eth0.lldp-med.inventory.asset'] == '487122' + assert out['lldp.eth0.lldp-med.inventory.software'] == \ + platform.release() + else: + assert 'lldp.eth0.lldp-med.inventory.hardware' not in out.items() + assert 'lldp.eth0.lldp-med.inventory.firmware' not in out.items() + assert 'lldp.eth0.lldp-med.inventory.serial' not in out.items() + assert 'lldp.eth0.lldp-med.inventory.manufacturer' not in out.items() + assert 'lldp.eth0.lldp-med.inventory.model' not in out.items() + assert 'lldp.eth0.lldp-med.inventory.asset' not in out.items() + assert 'lldp.eth0.lldp-med.inventory.software' not in out.items() + + test_default_inventory(namespaces, lldpcli) + + custom_values = [ + ('hardware-revision', 'hardware', 'SQRT2_1.41421356237309504880'), + ('software-revision', 'software', 'E_2.7182818284590452354'), + ('firmware-revision', 'firmware', 'PI_3.14159265358979323846'), + ('serial', 'serial', 'FIBO_112358'), + ('manufacturer', 'manufacturer', 'Cybertron'), + ('model', 'model', 'OptimusPrime'), + ('asset', 'asset', 'SQRT3_1.732050807568877') + ] + with namespaces(2): + for what, pfx, value in custom_values: + result = lldpcli( + *shlex.split("configure inventory {} {}".format(what, value))) + assert result.returncode == 0 + result = lldpcli("resume") + assert result.returncode == 0 + result = lldpcli("update") + assert result.returncode == 0 + time.sleep(3) + + with namespaces(1): + out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") + for what, pfx, value in custom_values: + key_to_find = "lldp.eth0.lldp-med.inventory.{}".format(pfx) + assert out[key_to_find] == value + + with namespaces(2): + for what, pfx, value in custom_values: + result = lldpcli( + *shlex.split("unconfigure inventory {}".format(what))) + assert result.returncode == 0 + result = lldpcli("resume") + assert result.returncode == 0 + result = lldpcli("update") + assert result.returncode == 0 + + test_default_inventory(namespaces, lldpcli) + diff --git a/tests/lldpcli.conf b/tests/lldpcli.conf index 600235eb..d085f63c 100644 --- a/tests/lldpcli.conf +++ b/tests/lldpcli.conf @@ -56,5 +56,21 @@ configure dot3 power pse supported enabled paircontrol powerpairs spare class cl configure ports eth0 dot3 power pse supported enabled paircontrol powerpairs spare class class-3 configure dot3 power pd supported enabled powerpairs spare class class-3 type 1 source pse priority low requested 10000 allocated 15000 +configure inventory hardware-revision "SQRT2-1.41421356237309504880" +configure inventory software-revision "E-2.7182818284590452354" +configure inventory firmware-revision "PI-3.14159265358979323846" +configure inventory serial "FIBO112358" +configure inventory manufacturer "Cybertron" +configure inventory model "OptimusPrime" +configure inventory asset "SQRT3-1.732050807568877" + +unconfigure inventory hardware-revision +unconfigure inventory software-revision +unconfigure inventory firmware-revision +unconfigure inventory serial +unconfigure inventory manufacturer +unconfigure inventory model +unconfigure inventory asset + # A convenient way to "test" lldpcli and liblldpctl is to load those commands in lldpcli with valgrind: # libtool execute valgrind --suppressions=../src/client/lldpcli.supp --leak-check=full src/client/lldpcli -c ../tests/lldpcli.conf