From e51e5c7e2f873f13687f7d9758998971d330ca61 Mon Sep 17 00:00:00 2001 From: "Peter V. Saveliev" Date: Wed, 31 May 2017 20:55:36 +0200 Subject: [PATCH 1/4] 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 --- tests/unit/modules/test_pyroute2.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/unit/modules/test_pyroute2.py diff --git a/tests/unit/modules/test_pyroute2.py b/tests/unit/modules/test_pyroute2.py new file mode 100644 index 0000000000..5878bcd6fc --- /dev/null +++ b/tests/unit/modules/test_pyroute2.py @@ -0,0 +1,12 @@ + +from pyroute2 import IPDB +from tests.support.unit import TestCase +from salt.beacons.network_settings import ATTRS + + +class Pyroute2TestCase(TestCase): + + def test_interface_dict_fields(self): + with IPDB() as ipdb: + for attr in ATTRS: + self.assertIn(attr, ipdb.interfaces[1]) From c744cbefd74e3ad5748232e4fa9d645735acecac Mon Sep 17 00:00:00 2001 From: "Peter V. Saveliev" Date: Wed, 31 May 2017 22:34:00 +0200 Subject: [PATCH 2/4] unit tests: fix absolute imports in test_pyroute2 Bug-Url: https://github.com/saltstack/salt/pull/41533 --- tests/unit/modules/test_pyroute2.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/modules/test_pyroute2.py b/tests/unit/modules/test_pyroute2.py index 5878bcd6fc..bb277509f7 100644 --- a/tests/unit/modules/test_pyroute2.py +++ b/tests/unit/modules/test_pyroute2.py @@ -1,4 +1,6 @@ +from __future__ import absolute_import + from pyroute2 import IPDB from tests.support.unit import TestCase from salt.beacons.network_settings import ATTRS From d4939e1ac9319cefdaa5faefbc5adec10f0a3a15 Mon Sep 17 00:00:00 2001 From: "Peter V. Saveliev" Date: Thu, 1 Jun 2017 07:44:47 +0200 Subject: [PATCH 3/4] unit tests: add encoding clause into test_pyroute2 Bug-Url: https://github.com/saltstack/salt/pull/41533 --- tests/unit/modules/test_pyroute2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/modules/test_pyroute2.py b/tests/unit/modules/test_pyroute2.py index bb277509f7..ea43314ffa 100644 --- a/tests/unit/modules/test_pyroute2.py +++ b/tests/unit/modules/test_pyroute2.py @@ -1,3 +1,4 @@ +# -*- coding: UTF-8 -*- from __future__ import absolute_import From 602a7af748306a2f574a37a305c097a643084249 Mon Sep 17 00:00:00 2001 From: "Peter V. Saveliev" Date: Thu, 1 Jun 2017 10:47:26 +0200 Subject: [PATCH 4/4] unit tests: test_pyroute2 -- add skipIf ... and comments Bug-Url: https://github.com/saltstack/salt/pull/41533 --- tests/unit/modules/test_pyroute2.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/unit/modules/test_pyroute2.py b/tests/unit/modules/test_pyroute2.py index ea43314ffa..a4ccce74e8 100644 --- a/tests/unit/modules/test_pyroute2.py +++ b/tests/unit/modules/test_pyroute2.py @@ -2,14 +2,26 @@ from __future__ import absolute_import -from pyroute2 import IPDB 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])