Allow leading ranges in the inventory host entries.

pull/4351/head
Martynas Mickevicius 11 years ago
parent 6480945184
commit 44279ce34f

@ -41,8 +41,7 @@ def detect_range(line = None):
Returnes True if the given line contains a pattern, else False. Returnes True if the given line contains a pattern, else False.
''' '''
if (not line.startswith("[") and if (line.find("[") != -1 and
line.find("[") != -1 and
line.find(":") != -1 and line.find(":") != -1 and
line.find("]") != -1 and line.find("]") != -1 and
line.index("[") < line.index(":") < line.index("]")): line.index("[") < line.index(":") < line.index("]")):

@ -65,7 +65,7 @@ class InventoryParser(object):
active_group_name = 'ungrouped' active_group_name = 'ungrouped'
for line in self.lines: for line in self.lines:
if line.startswith("["): if line.startswith("[") and line.strip().endswith("]"):
active_group_name = line.split(" #")[0].replace("[","").replace("]","").strip() active_group_name = line.split(" #")[0].replace("[","").replace("]","").strip()
if line.find(":vars") != -1 or line.find(":children") != -1: if line.find(":vars") != -1 or line.find(":children") != -1:
active_group_name = active_group_name.rsplit(":", 1)[0] active_group_name = active_group_name.rsplit(":", 1)[0]

@ -294,6 +294,12 @@ class TestInventory(unittest.TestCase):
expected_hosts=['host1A','host2A','host1B','host2B'] expected_hosts=['host1A','host2A','host1B','host2B']
assert sorted(hosts) == sorted(expected_hosts) 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 ### Inventory API tests

@ -0,0 +1,3 @@
[test]
[1:2].host
[A:B].host
Loading…
Cancel
Save