Commit d4dec5f5 by Jasper Capel

Allow creating empty inventory

Instantiating the Inventory class with host_list=None now results in an
empty inventory instead of an error.
parent 776fc044
...@@ -70,7 +70,9 @@ class Inventory(object): ...@@ -70,7 +70,9 @@ class Inventory(object):
host_list = host_list.split(",") host_list = host_list.split(",")
host_list = [ h for h in host_list if h and h.strip() ] host_list = [ h for h in host_list if h and h.strip() ]
if isinstance(host_list, list): if host_list is None:
self.parser = None
elif isinstance(host_list, list):
self.parser = None self.parser = None
all = Group('all') all = Group('all')
self.groups = [ all ] self.groups = [ all ]
......
...@@ -30,6 +30,9 @@ class TestInventory(unittest.TestCase): ...@@ -30,6 +30,9 @@ class TestInventory(unittest.TestCase):
print right print right
assert left == right assert left == right
def empty_inventory(self):
return Inventory(None)
def simple_inventory(self): def simple_inventory(self):
return Inventory(self.inventory_file) return Inventory(self.inventory_file)
...@@ -55,6 +58,14 @@ class TestInventory(unittest.TestCase): ...@@ -55,6 +58,14 @@ class TestInventory(unittest.TestCase):
'BastC', 'BastD', ] 'BastC', 'BastD', ]
##################################### #####################################
### Empty inventory format tests
def test_empty(self):
inventory = self.empty_inventory()
hosts = inventory.list_hosts()
self.assertEqual(hosts, [])
#####################################
### Simple inventory format tests ### Simple inventory format tests
def test_simple(self): def test_simple(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment