From 838e71edb7ea37212b40b6cae7ad2350a244239c Mon Sep 17 00:00:00 2001 From: Abhijit Menon-Sen Date: Wed, 30 Sep 2015 16:15:39 +0530 Subject: [PATCH 1/2] Add more exhaustive tests for various IPv6 address notations --- test/units/parsing/test_addresses.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/units/parsing/test_addresses.py b/test/units/parsing/test_addresses.py index bb6e51b22a4..870cbb0a14a 100644 --- a/test/units/parsing/test_addresses.py +++ b/test/units/parsing/test_addresses.py @@ -17,6 +17,20 @@ class TestParseAddress(unittest.TestCase): '[::1]:442': ['::1', 442], 'abcd:ef98:7654:3210:abcd:ef98:7654:3210': ['abcd:ef98:7654:3210:abcd:ef98:7654:3210', None], '[abcd:ef98:7654:3210:abcd:ef98:7654:3210]:42': ['abcd:ef98:7654:3210:abcd:ef98:7654:3210', 42], + '1234:5678:9abc:def0:1234:5678:9abc:def0': ['1234:5678:9abc:def0:1234:5678:9abc:def0', None], + '1234::9abc:def0:1234:5678:9abc:def0': ['1234::9abc:def0:1234:5678:9abc:def0', None], + '1234:5678::def0:1234:5678:9abc:def0': ['1234:5678::def0:1234:5678:9abc:def0', None], + '1234:5678:9abc::1234:5678:9abc:def0': ['1234:5678:9abc::1234:5678:9abc:def0', None], + '1234:5678:9abc:def0::5678:9abc:def0': ['1234:5678:9abc:def0::5678:9abc:def0', None], + '1234:5678:9abc:def0:1234::9abc:def0': ['1234:5678:9abc:def0:1234::9abc:def0', None], + '1234:5678:9abc:def0:1234:5678::def0': ['1234:5678:9abc:def0:1234:5678::def0', None], + '1234:5678:9abc:def0:1234:5678::': ['1234:5678:9abc:def0:1234:5678::', None], + '::9abc:def0:1234:5678:9abc:def0': ['::9abc:def0:1234:5678:9abc:def0', None], + '0:0:0:0:0:ffff:1.2.3.4': ['0:0:0:0:0:ffff:1.2.3.4', None], + '0:0:0:0:0:0:1.2.3.4': ['0:0:0:0:0:0:1.2.3.4', None], + '::ffff:1.2.3.4': ['::ffff:1.2.3.4', None], + '::1.2.3.4': ['::1.2.3.4', None], + '1234::': ['1234::', None], # Hostnames 'some-host': ['some-host', None], From d100db837b68938afdc889a7650c63d12a933de2 Mon Sep 17 00:00:00 2001 From: Abhijit Menon-Sen Date: Wed, 30 Sep 2015 16:28:45 +0530 Subject: [PATCH 2/2] Add basic tests for expand_hostname_range --- test/units/inventory/test_inventory.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/units/inventory/test_inventory.py b/test/units/inventory/test_inventory.py index e7bcceb85da..b6a5938862c 100644 --- a/test/units/inventory/test_inventory.py +++ b/test/units/inventory/test_inventory.py @@ -26,6 +26,7 @@ from ansible.compat.tests.mock import patch, MagicMock from ansible.errors import AnsibleError, AnsibleParserError from ansible.inventory import Inventory +from ansible.inventory.expand_hosts import expand_hostname_range from ansible.vars import VariableManager from units.mock.loader import DictDataLoader @@ -71,6 +72,16 @@ class TestInventory(unittest.TestCase): 'a[1:]': [('a', (1, -1)), list(string.ascii_letters[1:])], } + ranges_to_expand = { + 'a[1:2]': ['a1', 'a2'], + 'a[1:10:2]': ['a1', 'a3', 'a5', 'a7', 'a9'], + 'a[a:b]': ['aa', 'ab'], + 'a[a:i:3]': ['aa', 'ad', 'ag'], + 'a[a:b][c:d]': ['aac', 'aad', 'abc', 'abd'], + 'a[0:1][2:3]': ['a02', 'a03', 'a12', 'a13'], + 'a[a:b][2:3]': ['aa2', 'aa3', 'ab2', 'ab3'], + } + def setUp(self): v = VariableManager() fake_loader = DictDataLoader({}) @@ -98,3 +109,9 @@ class TestInventory(unittest.TestCase): r[0][1] ) ) + + def test_expand_hostname_range(self): + + for e in self.ranges_to_expand: + r = self.ranges_to_expand[e] + self.assertEqual(r, expand_hostname_range(e))