Add some tests for directory-based inventory

This commit is contained in:
Daniel Hokka Zakrisson 2013-03-01 23:34:14 +01:00
parent f1eb195ff5
commit 1f8805d9e0
4 changed files with 30 additions and 0 deletions

View file

@ -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'}

View file

@ -0,0 +1,3 @@
zeus var_a=2
morpheus
thor

View file

@ -0,0 +1,6 @@
[greek]
zeus
morpheus
[norse]
thor

View file

@ -0,0 +1,6 @@
[major-god]
zeus var_a=1
thor
[minor-god]
morpheus