Merge pull request #1 from mcsalgado/hostpatterns

More tests, better handling of list arguments to _split_pattern
This commit is contained in:
Abhijit Menon-Sen 2015-09-17 22:48:12 +05:30
commit 713f5ab79d
2 changed files with 13 additions and 3 deletions

View file

@ -24,6 +24,7 @@ import os
import sys import sys
import re import re
import stat import stat
import itertools
from ansible import constants as C from ansible import constants as C
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
@ -185,9 +186,7 @@ class Inventory(object):
""" """
if isinstance(pattern, list): if isinstance(pattern, list):
pattern = ','.join(pattern) return list(itertools.chain(*map(self._split_pattern, pattern)))
patterns = []
if ';' in pattern: if ';' in pattern:
display.deprecated("Use ',' instead of ':' or ';' to separate host patterns", version=2.0, removed=True) display.deprecated("Use ',' instead of ':' or ';' to separate host patterns", version=2.0, removed=True)

View file

@ -44,6 +44,14 @@ class TestInventory(unittest.TestCase):
' a : b ': ['a', 'b'], ' a : b ': ['a', 'b'],
'foo:bar:baz[1:2]': ['foo', 'bar', 'baz[1:2]'], 'foo:bar:baz[1:2]': ['foo', 'bar', 'baz[1:2]'],
} }
pattern_lists = [
[['a'], ['a']],
[['a', 'b'], ['a', 'b']],
[['a, b'], ['a', 'b']],
[['9a01:7f8:191:7701::9', '9a01:7f8:191:7701::9,foo'],
['9a01:7f8:191:7701::9', '9a01:7f8:191:7701::9','foo']]
]
def setUp(self): def setUp(self):
v = VariableManager() v = VariableManager()
@ -56,3 +64,6 @@ class TestInventory(unittest.TestCase):
for p in self.patterns: for p in self.patterns:
r = self.patterns[p] r = self.patterns[p]
self.assertEqual(r, self.i._split_pattern(p)) self.assertEqual(r, self.i._split_pattern(p))
for p, r in self.pattern_lists:
self.assertEqual(r, self.i._split_pattern(p))