Combine both yaml unit tests into one example file

This commit is contained in:
Dag Wieërs 2012-07-12 19:31:51 +02:00
parent 7db49a8048
commit 264ebaa77c
3 changed files with 2 additions and 155 deletions

View file

@ -15,7 +15,6 @@ class TestInventory(unittest.TestCase):
self.complex_inventory_file = os.path.join(self.test_dir, 'complex_hosts')
self.inventory_script = os.path.join(self.test_dir, 'inventory_api.py')
self.inventory_yaml = os.path.join(self.test_dir, 'yaml_hosts')
self.inventory_yaml2 = os.path.join(self.test_dir, 'yaml2_hosts')
os.chmod(self.inventory_script, 0755)
@ -326,111 +325,3 @@ class TestInventory(unittest.TestCase):
assert 'group_names' in vars
assert sorted(vars['group_names']) == [ 'norse', 'ruler' ]
### Tests for yaml2 inventory file
def test_yaml2(self):
inventory = self.yaml2_inventory()
hosts = inventory.list_hosts()
print hosts
expected_hosts=['jupiter', 'saturn', 'mars', 'zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki']
self.compare(hosts, expected_hosts)
def test_yaml2_all(self):
inventory = self.yaml2_inventory()
hosts = inventory.list_hosts('all')
expected_hosts=['jupiter', 'saturn', 'mars', 'zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki']
self.compare(hosts, expected_hosts)
def test_yaml2_norse(self):
inventory = self.yaml2_inventory()
hosts = inventory.list_hosts("norse")
expected_hosts=['thor', 'odin', 'loki']
self.compare(hosts, expected_hosts)
def test_yaml2_ungrouped(self):
inventory = self.yaml2_inventory()
hosts = inventory.list_hosts("ungrouped")
expected_hosts=['jupiter', 'mars']
self.compare(hosts, expected_hosts)
def test_yaml2_combined(self):
inventory = self.yaml2_inventory()
hosts = inventory.list_hosts("norse:greek")
expected_hosts=['zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki']
self.compare(hosts, expected_hosts)
def test_yaml2_restrict(self):
inventory = self.yaml2_inventory()
restricted_hosts = ['hera', 'poseidon', 'thor']
expected_hosts=['zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki']
inventory.restrict_to(restricted_hosts)
hosts = inventory.list_hosts("norse:greek")
self.compare(hosts, restricted_hosts)
inventory.lift_restriction()
hosts = inventory.list_hosts("norse:greek")
self.compare(hosts, expected_hosts)
def test_yaml2_vars(self):
inventory = self.yaml2_inventory()
vars = inventory.get_variables('thor')
assert vars == {'group_names': ['norse'],
'hammer':True,
'inventory_hostname': 'thor'}
def test_yaml2_list_vars(self):
inventory = self.yaml2_inventory()
vars = inventory.get_variables('zeus')
assert vars == {'ansible_ssh_port': 3001,
'group_names': ['greek', 'ruler'],
'inventory_hostname': 'zeus',
'ntp_server': 'olympus.example.com'}
def test_yaml2_change_vars(self):
inventory = self.yaml2_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_yaml2_host_vars(self):
inventory = self.yaml2_inventory()
vars = inventory.get_variables('saturn')
print vars
assert vars == {'inventory_hostname': 'saturn',
'moon': 'titan',
'moon2': 'enceladus',
'group_names': ['multiple']}
def test_yaml2_port(self):
inventory = self.yaml2_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_yaml2_multiple_groups(self):
inventory = self.yaml2_inventory()
vars = inventory.get_variables('odin')
assert 'group_names' in vars
assert sorted(vars['group_names']) == [ 'norse', 'ruler' ]

View file

@ -1,40 +0,0 @@
---
- jupiter
- host: saturn
groups: [ multiple ]
vars:
moon: titan
moon2: enceladus
- host: hera
groups: [ greek ]
- host: poseidon
groups: greek
- host: mars
- host: zeus
groups: [ greek, ruler ]
vars:
- ansible_ssh_port: 3001
- host: odin
groups:
- norse
- ruler
- host: loki
groups: [ norse ]
- host: thor
groups: [ norse ]
vars:
- hammer: True
- group: greek
vars:
- ansible_ssh_port: 3000
- ntp_server: olympus.example.com

View file

@ -2,6 +2,7 @@
- jupiter
- host: saturn
groups: [ multiple ]
vars:
moon: titan
moon2: enceladus
@ -9,12 +10,12 @@
- host: mars
- host: zeus
groups: [ greek, ruler ]
vars:
- ansible_ssh_port: 3001
- group: greek
hosts:
- zeus
- hera
- poseidon
vars:
@ -31,9 +32,4 @@
- group: ruler
hosts:
- zeus
- odin
- group: multiple
hosts:
- saturn