Further work on making the YAML inventory parser use the new inventory objects.

This commit is contained in:
Michael DeHaan
2012-05-06 17:03:17 -04:00
parent a8f0b5fd06
commit 1a00e2635e
3 changed files with 132 additions and 27 deletions

View File

@@ -3,7 +3,7 @@ import unittest
from ansible.inventory import Inventory
from ansible.runner import Runner
from nose.plugins.skip import SkipTest
# from nose.plugins.skip import SkipTest
class TestInventory(unittest.TestCase):
@@ -20,6 +20,14 @@ class TestInventory(unittest.TestCase):
def tearDown(self):
os.chmod(self.inventory_script, 0644)
def compare(self, left, right):
left = sorted(left)
right = sorted(right)
print left
print right
assert left == right
### Simple inventory format tests
def simple_inventory(self):
@@ -167,47 +175,41 @@ class TestInventory(unittest.TestCase):
### Tests for yaml inventory file
def test_yaml(self):
raise SkipTest
inventory = self.yaml_inventory()
hosts = inventory.list_hosts()
print hosts
expected_hosts=['jupiter', 'saturn', 'zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki']
assert hosts == expected_hosts
self.compare(hosts, expected_hosts)
def test_yaml_all(self):
raise SkipTest
inventory = self.yaml_inventory()
hosts = inventory.list_hosts('all')
expected_hosts=['jupiter', 'saturn', 'zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki']
assert hosts == expected_hosts
self.compare(hosts, expected_hosts)
def test_yaml_norse(self):
raise SkipTest
inventory = self.yaml_inventory()
hosts = inventory.list_hosts("norse")
expected_hosts=['thor', 'odin', 'loki']
assert hosts == expected_hosts
self.compare(hosts, expected_hosts)
def test_simple_ungrouped(self):
raise SkipTest
inventory = self.yaml_inventory()
hosts = inventory.list_hosts("ungrouped")
expected_hosts=['jupiter']
assert hosts == expected_hosts
expected_hosts=['jupiter','zeus']
self.compare(hosts, expected_hosts)
def test_yaml_combined(self):
raise SkipTest
inventory = self.yaml_inventory()
hosts = inventory.list_hosts("norse:greek")
expected_hosts=['zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki']
assert hosts == expected_hosts
self.compare(hosts, expected_hosts)
def test_yaml_restrict(self):
raise SkipTest
inventory = self.yaml_inventory()
restricted_hosts = ['hera', 'poseidon', 'thor']
@@ -216,56 +218,53 @@ class TestInventory(unittest.TestCase):
inventory.restrict_to(restricted_hosts)
hosts = inventory.list_hosts("norse:greek")
assert hosts == restricted_hosts
self.compare(hosts, restricted_hosts)
inventory.lift_restriction()
hosts = inventory.list_hosts("norse:greek")
assert hosts == expected_hosts
self.compare(hosts, expected_hosts)
def test_yaml_vars(self):
raise SkipTest
inventory = self.yaml_inventory()
vars = inventory.get_variables('thor')
print vars
assert vars == {'group_names': ['norse'],
'hammer':True,
'inventory_hostname': 'thor'}
def test_yaml_change_vars(self):
raise SkipTest
inventory = self.yaml_inventory()
vars = inventory.get_variables('thor')
vars["hammer"] = False
vars = inventory.get_variables('thor')
print vars
assert vars == {'hammer':True,
'inventory_hostname': 'thor',
'group_names': ['norse']}
def test_yaml_host_vars(self):
raise SkipTest
inventory = self.yaml_inventory()
vars = inventory.get_variables('saturn')
print vars
assert vars == {'inventory_hostname': 'saturn',
'moon': 'titan',
'moon2': 'enceladus',
'group_names': ['multiple']}
def test_yaml_port(self):
raise SkipTest
inventory = self.yaml_inventory()
vars = inventory.get_variables('hera')
print vars
assert vars == {'ansible_ssh_port': 3000,
'inventory_hostname': 'hera',
'ntp_server': 'olympus.example.com',
'group_names': ['greek']}
def test_yaml_multiple_groups(self):
raise SkipTest
inventory = self.yaml_inventory()
vars = inventory.get_variables('odin')