From 58468a451d7d87450fbc36beb99dd39b10f06d61 Mon Sep 17 00:00:00 2001 From: "Peter V. Saveliev" Date: Mon, 29 May 2017 16:30:49 +0200 Subject: [PATCH] clean up `change` attribute from interface dict The attribute is hidden in IPDB from the high-level logics since pyroute2 version 0.4.2. Bug-Url: https://github.com/saltstack/salt/issues/41461 unit tests: add pyroute2 interface dict test Bug-Url: https://github.com/saltstack/salt/pull/41487 Bug-Url: https://github.com/saltstack/salt/issues/41461 unit tests: fix absolute imports in test_pyroute2 Bug-Url: https://github.com/saltstack/salt/pull/41533 unit tests: add encoding clause into test_pyroute2 Bug-Url: https://github.com/saltstack/salt/pull/41533 unit tests: test_pyroute2 -- add skipIf ... and comments Bug-Url: https://github.com/saltstack/salt/pull/41533 --- salt/beacons/network_settings.py | 2 +- tests/unit/modules/test_pyroute2.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/unit/modules/test_pyroute2.py diff --git a/salt/beacons/network_settings.py b/salt/beacons/network_settings.py index 5af71a0804..78c387b2f2 100644 --- a/salt/beacons/network_settings.py +++ b/salt/beacons/network_settings.py @@ -25,7 +25,7 @@ __virtual_name__ = 'network_settings' ATTRS = ['family', 'txqlen', 'ipdb_scope', 'index', 'operstate', 'group', 'carrier_changes', 'ipaddr', 'neighbours', 'ifname', 'promiscuity', 'linkmode', 'broadcast', 'address', 'num_tx_queues', 'ipdb_priority', - 'change', 'kind', 'qdisc', 'mtu', 'num_rx_queues', 'carrier', 'flags', + 'kind', 'qdisc', 'mtu', 'num_rx_queues', 'carrier', 'flags', 'ifi_type', 'ports'] LAST_STATS = {} diff --git a/tests/unit/modules/test_pyroute2.py b/tests/unit/modules/test_pyroute2.py new file mode 100644 index 0000000000..a4ccce74e8 --- /dev/null +++ b/tests/unit/modules/test_pyroute2.py @@ -0,0 +1,27 @@ +# -*- coding: UTF-8 -*- + +from __future__ import absolute_import + +from tests.support.unit import TestCase +from tests.support.unit import skipIf +from salt.beacons.network_settings import ATTRS +try: + from pyroute2 import IPDB + HAS_PYROUTE2 = True +except ImportError: + HAS_PYROUTE2 = False + + +@skipIf(not HAS_PYROUTE2, 'no pyroute2 installed, skipping') +class Pyroute2TestCase(TestCase): + + def test_interface_dict_fields(self): + with IPDB() as ipdb: + for attr in ATTRS: + # ipdb.interfaces is a dict-like object, that + # contains interface definitions. Interfaces can + # be referenced both with indices and names. + # + # ipdb.interfaces[1] is an interface with index 1, + # that is the loopback interface. + self.assertIn(attr, ipdb.interfaces[1]) -- 2.13.0