From 66414705d3e80531bab091d8761cb9996e22005e Mon Sep 17 00:00:00 2001 From: Jacob McGill Date: Sat, 16 Jun 2018 21:17:19 -0400 Subject: [PATCH 1/5] Boolean Magic Method: Python 3 replaced __nonzero__ with __bool__, so add __nonzero__ and point to __bool__ --- hier_config/hc_child.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hier_config/hc_child.py b/hier_config/hc_child.py index 34dda07..bf422d0 100644 --- a/hier_config/hc_child.py +++ b/hier_config/hc_child.py @@ -54,6 +54,9 @@ def __len__(self): def __bool__(self): return True + def __nonzero__(self): + return self.__bool__() + def __contains__(self, item): return str(item) in self.children_dict From da4d6cea3aead6dd56fb6abdd99c906ebf777333 Mon Sep 17 00:00:00 2001 From: Jacob McGill Date: Sat, 16 Jun 2018 21:52:55 -0400 Subject: [PATCH 2/5] Change truth test to only test for None --- hier_config/hc_child.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hier_config/hc_child.py b/hier_config/hc_child.py index bf422d0..6e11036 100644 --- a/hier_config/hc_child.py +++ b/hier_config/hc_child.py @@ -593,7 +593,7 @@ def _config_to_get_to_right(self, target, delta): for target_child in target.children: # if the child exist, recurse into its children self_child = self.get_child('equals', target_child.text) - if self_child: + if self_child is not None: # This creates a new HConfigChild object just in case there are some delta children # Not very efficient, think of a way to not do this subtree = delta.add_child(target_child.text) From 5385079b72c3e67dfb921a7004be0637ec0bbea6 Mon Sep 17 00:00:00 2001 From: Jacob McGill Date: Sat, 16 Jun 2018 22:14:29 -0400 Subject: [PATCH 3/5] Add test for checking that HConfig object evaluates to True --- tests/test_hier_config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_hier_config.py b/tests/test_hier_config.py index d422a84..48498c0 100644 --- a/tests/test_hier_config.py +++ b/tests/test_hier_config.py @@ -43,6 +43,9 @@ def setUpClass(cls): cls.host_a = Host('example1.rtr', cls.os, cls.options) cls.host_b = Host('example2.rtr', cls.os, cls.options) + def test_bool(self): + self.assertTrue(HConfig(host=self.host_a)) + def test_merge(self): hier1 = HConfig(host=self.host_a) hier1.add_child('interface Vlan2') From 3b58c0f22e5ccbeef7cb144fd7e39bdd4aa697a7 Mon Sep 17 00:00:00 2001 From: Jacob McGill Date: Sat, 16 Jun 2018 22:58:06 -0400 Subject: [PATCH 4/5] Add tests for _config_to_get_to_right --- tests/test_hier_config.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_hier_config.py b/tests/test_hier_config.py index 48498c0..97718d6 100644 --- a/tests/test_hier_config.py +++ b/tests/test_hier_config.py @@ -335,6 +335,17 @@ def test_config_to_get_to(self): remediation_config_hier = running_config_hier.config_to_get_to(compiled_config_hier) self.assertEqual(2, len(list(remediation_config_hier.all_children()))) + def test_config_to_get_to_right(self): + running_config_hier = HConfig(host=self.host_a) + running_config_hier.add_child('do not add me') + compiled_config_hier = HConfig(host=self.host_a) + compiled_config_hier.add_child('do not add me') + compiled_config_hier.add_child('add me') + delta = HConfig(host=self.host_a) + running_config_hier._config_to_get_to_right(compiled_config_hier, delta) + self.assertNotIn('do not add me', delta) + self.assertIn('add me', delta) + def test_is_idempotent_command(self): pass From 8dce88e91296e1f439e70d7c206fa12513caf425 Mon Sep 17 00:00:00 2001 From: jtdub Date: Sun, 17 Jun 2018 15:14:47 -0500 Subject: [PATCH 5/5] version increment --- hier_config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hier_config/__init__.py b/hier_config/__init__.py index 93690de..9bb7559 100644 --- a/hier_config/__init__.py +++ b/hier_config/__init__.py @@ -2,7 +2,7 @@ import re -__version__ = '1.4.1' +__version__ = '1.4.2' class HConfig(HConfigChild):