From 9ed7717634decad9dd66db6c04483c7ae7842542 Mon Sep 17 00:00:00 2001 From: Taylor Barstow Date: Thu, 10 Apr 2014 21:07:59 -0400 Subject: [PATCH 1/2] Adding unit tests for host groups with inventory dir --- test/units/TestInventory.py | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/units/TestInventory.py b/test/units/TestInventory.py index 7f20af6bb6..e9fd8f7534 100644 --- a/test/units/TestInventory.py +++ b/test/units/TestInventory.py @@ -439,3 +439,55 @@ class TestInventory(unittest.TestCase): actual_host_names = [host.name for host in group_greek] print "greek : %s " % actual_host_names assert actual_host_names == ['zeus', 'morpheus'] + + def test_dir_inventory_group_hosts(self): + inventory = self.dir_inventory() + expected_groups = {'all': ['morpheus', 'thor', 'zeus'], + 'major-god': ['thor', 'zeus'], + 'minor-god': ['morpheus'], + 'norse': ['thor'], + 'greek': ['morpheus', 'zeus'], + 'ungrouped': []} + + actual_groups = {} + for group in inventory.get_groups(): + actual_groups[group.name] = sorted([h.name for h in group.get_hosts()]) + print "INVENTORY groups[%s].hosts=%s" % (group.name, actual_groups[group.name]) + print "EXPECTED groups[%s].hosts=%s" % (group.name, expected_groups[group.name]) + + assert actual_groups == expected_groups + + def test_dir_inventory_groups_for_host(self): + inventory = self.dir_inventory() + expected_groups_for_host = {'morpheus': ['all', 'greek', 'minor-god'], + 'thor': ['all', 'norse', 'major-god'], + 'zeus': ['all', 'greek', 'major-god']} + + actual_groups_for_host = {} + for (host, expected) in expected_groups_for_host.iteritems(): + groups = inventory.groups_for_host(host) + names = sorted([g.name for g in groups]) + actual_groups_for_host[host] = names + print "INVENTORY groups_for_host(%s)=%s" % (host, names) + print "EXPECTED groups_for_host(%s)=%s" % (host, expected) + + assert actual_groups_for_host == expected_groups_for_host + + def test_dir_inventory_groups_list(self): + inventory = self.dir_inventory() + inventory_groups = inventory.groups_list() + + expected_groups = {'all': ['morpheus', 'thor', 'zeus'], + 'major-god': ['thor', 'zeus'], + 'minor-god': ['morpheus'], + 'norse': ['thor'], + 'greek': ['morpheus', 'zeus'], + 'ungrouped': []} + + for (name, expected_hosts) in expected_groups.iteritems(): + inventory_groups[name] = sorted(inventory_groups.get(name, [])) + print "INVENTORY groups_list['%s']=%s" % (name, inventory_groups[name]) + print "EXPECTED groups_list['%s']=%s" % (name, expected_hosts) + + assert inventory_groups == expected_groups + From 154055e9ffb0953c3345ef7e500381230c3a2a66 Mon Sep 17 00:00:00 2001 From: Taylor Barstow Date: Thu, 17 Apr 2014 16:41:49 -0400 Subject: [PATCH 2/2] Fixing expectations in test_dir_inventory_groups_for_host --- test/units/TestInventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/TestInventory.py b/test/units/TestInventory.py index e9fd8f7534..51d929c5a4 100644 --- a/test/units/TestInventory.py +++ b/test/units/TestInventory.py @@ -460,7 +460,7 @@ class TestInventory(unittest.TestCase): def test_dir_inventory_groups_for_host(self): inventory = self.dir_inventory() expected_groups_for_host = {'morpheus': ['all', 'greek', 'minor-god'], - 'thor': ['all', 'norse', 'major-god'], + 'thor': ['all', 'major-god', 'norse'], 'zeus': ['all', 'greek', 'major-god']} actual_groups_for_host = {}