From 7fec9c3ebafd7efc1a81afc56ef62cdf4dc9f992 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 23 Aug 2013 12:00:39 +0200 Subject: [PATCH 1/6] add a test to cover bound stepping in inventory --- test/TestInventory.py | 4 ++-- test/complex_hosts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/TestInventory.py b/test/TestInventory.py index e46027a5e6..d269544c9a 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -219,9 +219,9 @@ class TestInventory(unittest.TestCase): def test_complex_group_names(self): inventory = self.complex_inventory() tests = { - 'host1': [ 'role1' ], + 'host1': [ 'role1', 'role3' ], 'host2': [ 'role1', 'role2' ], - 'host3': [ 'role2' ] + 'host3': [ 'role2', 'role3' ] } for host, roles in tests.iteritems(): group_names = inventory.get_variables(host)['group_names'] diff --git a/test/complex_hosts b/test/complex_hosts index 5153bf095d..0b5ce8c19c 100644 --- a/test/complex_hosts +++ b/test/complex_hosts @@ -85,3 +85,5 @@ host[1:2] [role2] host[2:3] +[role3] +host[1:3:2] From 2aea8a63688f4421875ae8f1d2a2839c52fe1659 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 23 Aug 2013 12:29:38 +0200 Subject: [PATCH 2/6] add a test to verify ansible detect invalid range --- test/TestInventory.py | 3 +++ test/inventory/test_incorrect_range | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 test/inventory/test_incorrect_range diff --git a/test/TestInventory.py b/test/TestInventory.py index d269544c9a..7e442716dd 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -270,6 +270,9 @@ class TestInventory(unittest.TestCase): hosts = inventory.list_hosts("nc:&triangle:!tri_c") self.compare(hosts, ['tri_a', 'tri_b']) + @raises(errors.AnsibleError) + def test_invalid_range(self): + Inventory(os.path.join(self.test_dir, 'inventory','test_incorrect_range')) ################################################### ### Inventory API tests diff --git a/test/inventory/test_incorrect_range b/test/inventory/test_incorrect_range new file mode 100644 index 0000000000..272ca7be71 --- /dev/null +++ b/test/inventory/test_incorrect_range @@ -0,0 +1,2 @@ +[test] +host[1:2:3:4] From 835fdd1ec26a62efffebe19fea3baa490bfd8341 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 23 Aug 2013 12:42:26 +0200 Subject: [PATCH 3/6] add test for missing end in host range --- test/TestInventory.py | 5 +++++ test/inventory/test_missing_end | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 test/inventory/test_missing_end diff --git a/test/TestInventory.py b/test/TestInventory.py index 7e442716dd..1fddfc73cd 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -274,6 +274,11 @@ class TestInventory(unittest.TestCase): def test_invalid_range(self): Inventory(os.path.join(self.test_dir, 'inventory','test_incorrect_range')) + @raises(errors.AnsibleError) + def test_missing_end(self): + Inventory(os.path.join(self.test_dir, 'inventory','test_missing_end')) + + ################################################### ### Inventory API tests diff --git a/test/inventory/test_missing_end b/test/inventory/test_missing_end new file mode 100644 index 0000000000..ff32042402 --- /dev/null +++ b/test/inventory/test_missing_end @@ -0,0 +1,2 @@ +[test] +host[1:] From 4f69b63fec02b2a1a4abedc49eafa0d14d4807dc Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 23 Aug 2013 12:51:17 +0200 Subject: [PATCH 4/6] add test for incorrect format in range host --- test/TestInventory.py | 4 ++++ test/inventory/test_incorrect_format | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 test/inventory/test_incorrect_format diff --git a/test/TestInventory.py b/test/TestInventory.py index 1fddfc73cd..53c8107467 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -278,6 +278,10 @@ class TestInventory(unittest.TestCase): def test_missing_end(self): Inventory(os.path.join(self.test_dir, 'inventory','test_missing_end')) + @raises(errors.AnsibleError) + def test_incorrect_format(self): + Inventory(os.path.join(self.test_dir, 'inventory','test_incorrect_format')) + ################################################### ### Inventory API tests diff --git a/test/inventory/test_incorrect_format b/test/inventory/test_incorrect_format new file mode 100644 index 0000000000..339bd59edf --- /dev/null +++ b/test/inventory/test_incorrect_format @@ -0,0 +1,2 @@ +[test] +host[001:10] From 64d35cb3b62224b9651287ab1179900d91a1939c Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 23 Aug 2013 12:58:10 +0200 Subject: [PATCH 5/6] test that using non ordered range of char send a exception --- test/TestInventory.py | 4 ++++ test/inventory/test_alpha_end_before_beg | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 test/inventory/test_alpha_end_before_beg diff --git a/test/TestInventory.py b/test/TestInventory.py index 53c8107467..f2035231d4 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -282,6 +282,10 @@ class TestInventory(unittest.TestCase): def test_incorrect_format(self): Inventory(os.path.join(self.test_dir, 'inventory','test_incorrect_format')) + @raises(errors.AnsibleError) + def test_alpha_end_before_beg(self): + Inventory(os.path.join(self.test_dir, 'inventory','test_alpha_end_before_beg')) + ################################################### ### Inventory API tests diff --git a/test/inventory/test_alpha_end_before_beg b/test/inventory/test_alpha_end_before_beg new file mode 100644 index 0000000000..1b7a478d87 --- /dev/null +++ b/test/inventory/test_alpha_end_before_beg @@ -0,0 +1,2 @@ +[test] +host[Z:T] From a0b73b18c39b408de3dd6374bea47dcf2b819f62 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 23 Aug 2013 13:06:31 +0200 Subject: [PATCH 6/6] add one last test, for combined range, which make ansible.inventory.expand_hosts covered to 100% --- test/TestInventory.py | 5 +++++ test/inventory/test_combined_range | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 test/inventory/test_combined_range diff --git a/test/TestInventory.py b/test/TestInventory.py index f2035231d4..3a1cae1e4f 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -286,6 +286,11 @@ class TestInventory(unittest.TestCase): def test_alpha_end_before_beg(self): Inventory(os.path.join(self.test_dir, 'inventory','test_alpha_end_before_beg')) + def test_combined_range(self): + i = Inventory(os.path.join(self.test_dir, 'inventory','test_combined_range')) + hosts = i.list_hosts('test') + expected_hosts=['host1A','host2A','host1B','host2B'] + assert sorted(hosts) == sorted(expected_hosts) ################################################### ### Inventory API tests diff --git a/test/inventory/test_combined_range b/test/inventory/test_combined_range new file mode 100644 index 0000000000..cbcb41753e --- /dev/null +++ b/test/inventory/test_combined_range @@ -0,0 +1,2 @@ +[test] +host[1:2][A:B]