diff options
author | Abhijit Menon-Sen <abhijit@menon-sen.com> | 2015-09-17 22:48:12 +0530 |
---|---|---|
committer | Abhijit Menon-Sen <abhijit@menon-sen.com> | 2015-09-17 22:48:12 +0530 |
commit | 713f5ab79d2c8fe9e0e882817e08f6faff504a57 (patch) | |
tree | 54a4024a1275c0250e9ea7d780eaa7da6ba4b948 | |
parent | 349eec7855549ca2c458c222ae10406193a25cae (diff) | |
parent | 14fefebaad0d5a6fc70cb913b138da78345818f9 (diff) | |
download | ansible-713f5ab79d2c8fe9e0e882817e08f6faff504a57.tar.gz |
Merge pull request #1 from mcsalgado/hostpatterns
More tests, better handling of list arguments to _split_pattern
-rw-r--r-- | lib/ansible/inventory/__init__.py | 5 | ||||
-rw-r--r-- | test/units/inventory/test_inventory.py | 11 |
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 079243b0cd..643f12d8fd 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -24,6 +24,7 @@ import os import sys import re import stat +import itertools from ansible import constants as C from ansible.errors import AnsibleError @@ -185,9 +186,7 @@ class Inventory(object): """ if isinstance(pattern, list): - pattern = ','.join(pattern) - - patterns = [] + return list(itertools.chain(*map(self._split_pattern, pattern))) if ';' in pattern: display.deprecated("Use ',' instead of ':' or ';' to separate host patterns", version=2.0, removed=True) diff --git a/test/units/inventory/test_inventory.py b/test/units/inventory/test_inventory.py index 3869e15b58..e397143390 100644 --- a/test/units/inventory/test_inventory.py +++ b/test/units/inventory/test_inventory.py @@ -44,6 +44,14 @@ class TestInventory(unittest.TestCase): ' a : b ': ['a', 'b'], '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): v = VariableManager() @@ -56,3 +64,6 @@ class TestInventory(unittest.TestCase): for p in self.patterns: r = self.patterns[p] self.assertEqual(r, self.i._split_pattern(p)) + + for p, r in self.pattern_lists: + self.assertEqual(r, self.i._split_pattern(p)) |