From 1f8805d9e09be08122af272483cd340b38ba5324 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Fri, 1 Mar 2013 23:34:14 +0100 Subject: [PATCH] Add some tests for directory-based inventory --- test/TestInventory.py | 15 +++++++++++++++ test/inventory_dir/0hosts | 3 +++ test/inventory_dir/1mythology | 6 ++++++ test/inventory_dir/2levels | 6 ++++++ 4 files changed, 30 insertions(+) create mode 100644 test/inventory_dir/0hosts create mode 100644 test/inventory_dir/1mythology create mode 100644 test/inventory_dir/2levels diff --git a/test/TestInventory.py b/test/TestInventory.py index 1f2cd02c21..55706bba6b 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -13,6 +13,7 @@ class TestInventory(unittest.TestCase): self.large_range_inventory_file = os.path.join(self.test_dir, 'large_range') self.complex_inventory_file = os.path.join(self.test_dir, 'complex_hosts') self.inventory_script = os.path.join(self.test_dir, 'inventory_api.py') + self.inventory_dir = os.path.join(self.test_dir, 'inventory_dir') os.chmod(self.inventory_script, 0755) @@ -39,6 +40,9 @@ class TestInventory(unittest.TestCase): def complex_inventory(self): return Inventory(self.complex_inventory_file) + def dir_inventory(self): + return Inventory(self.inventory_dir) + all_simple_hosts=['jupiter', 'saturn', 'zeus', 'hera', 'cerberus001','cerberus002','cerberus003', 'cottus99', 'cottus100', @@ -288,3 +292,14 @@ class TestInventory(unittest.TestCase): assert vars == {'inventory_hostname': 'zeus', 'inventory_hostname_short': 'zeus', 'group_names': ['greek', 'major-god']} + + def test_dir_inventory(self): + inventory = self.dir_inventory() + vars = inventory.get_variables('zeus') + + print "VARS=%s" % vars + + assert vars == {'inventory_hostname': 'zeus', + 'inventory_hostname_short': 'zeus', + 'group_names': ['greek', 'major-god', 'ungrouped'], + 'var_a': '1'} diff --git a/test/inventory_dir/0hosts b/test/inventory_dir/0hosts new file mode 100644 index 0000000000..27fc46e853 --- /dev/null +++ b/test/inventory_dir/0hosts @@ -0,0 +1,3 @@ +zeus var_a=2 +morpheus +thor diff --git a/test/inventory_dir/1mythology b/test/inventory_dir/1mythology new file mode 100644 index 0000000000..43fa181bd5 --- /dev/null +++ b/test/inventory_dir/1mythology @@ -0,0 +1,6 @@ +[greek] +zeus +morpheus + +[norse] +thor diff --git a/test/inventory_dir/2levels b/test/inventory_dir/2levels new file mode 100644 index 0000000000..22f06bcd43 --- /dev/null +++ b/test/inventory_dir/2levels @@ -0,0 +1,6 @@ +[major-god] +zeus var_a=1 +thor + +[minor-god] +morpheus