Commit 44279ce3 by Martynas Mickevicius

Allow leading ranges in the inventory host entries.

parent 64809451
......@@ -41,8 +41,7 @@ def detect_range(line = None):
Returnes True if the given line contains a pattern, else False.
'''
if (not line.startswith("[") and
line.find("[") != -1 and
if (line.find("[") != -1 and
line.find(":") != -1 and
line.find("]") != -1 and
line.index("[") < line.index(":") < line.index("]")):
......
......@@ -65,7 +65,7 @@ class InventoryParser(object):
active_group_name = 'ungrouped'
for line in self.lines:
if line.startswith("["):
if line.startswith("[") and line.strip().endswith("]"):
active_group_name = line.split(" #")[0].replace("[","").replace("]","").strip()
if line.find(":vars") != -1 or line.find(":children") != -1:
active_group_name = active_group_name.rsplit(":", 1)[0]
......
......@@ -294,6 +294,12 @@ class TestInventory(unittest.TestCase):
expected_hosts=['host1A','host2A','host1B','host2B']
assert sorted(hosts) == sorted(expected_hosts)
def test_leading_range(self):
i = Inventory(os.path.join(self.test_dir, 'inventory','test_leading_range'))
hosts = i.list_hosts('test')
expected_hosts=['1.host','2.host','A.host','B.host']
assert sorted(hosts) == sorted(expected_hosts)
###################################################
### Inventory API tests
......
[test]
[1:2].host
[A:B].host
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