1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Playbook test upgrades, made some notes about callbacks we need to add. Still need to compare events

recieved vs expected so we can be notified if this test breaks, and also to add some more detailed
playbooks that use includes & async, etc.
This commit is contained in:
Michael DeHaan 2012-03-18 18:50:25 -04:00
parent 45abe3c16b
commit b15c8e9cb1
2 changed files with 22 additions and 36 deletions

View file

@ -6,6 +6,7 @@
import unittest
import getpass
import ansible.playbook
import ansible.utils as utils
import os
import shutil
import time
@ -17,55 +18,40 @@ except:
class TestCallbacks(object):
def __init__(self):
self.tasks_started = []
self.plays_started = []
self.unreachable = {}
self.failed = {}
self.ok_counts = {}
self.poll_events = []
self.dark = []
def results(self):
return dict(
tasks_started = self.tasks_started,
plays_started = self.plays_started,
unreachable = self.unreachable,
failed = self.failed,
ok_counts = self.ok_counts,
poll_events = self.poll_events,
dark = self.dark
)
self.events = []
def set_playbook(self, playbook):
self.playbook = playbook
def on_start(self):
pass
self.events.append('start')
def on_task_start(self, name, is_conditional):
self.tasks_started.append(name)
self.events.append([ 'task start', [ name, is_conditional ]])
def on_unreachable(self, host, msg):
self.unreachable[host] = msg
self.events.append([ 'unreachable', [ host, msg ]])
def on_failed(self, host, results):
self.failed[host] = results
self.events.append([ 'failed', [ host, results ]])
# FIXME: this callback should get results too!
def on_ok(self, host):
ok = self.ok_counts.get(host, 0)
self.ok_counts[host] = ok + 1
self.events.append([ 'ok', [ host ]])
def on_play_start(self, pattern):
self.plays_started.append(pattern)
self.events.append([ 'play start', [ pattern ]])
def on_async_confused(self, msg):
raise Exception("confused: %s" % msg)
self.events.append([ 'async confused', [ msg ]])
def on_async_poll(self, jid, host, clock, host_result):
self.poll_events.append([jid,host,clock.host_result])
self.events.append([ 'async poll', [ host, jid ]])
def on_dark_host(self, host, msg):
self.dark.append([host,msg])
self.events.append([ 'failed/dark', [ host, msg ]])
# FIXME: callbacks need to be fired on notifiers as well
class TestRunner(unittest.TestCase):
@ -112,11 +98,11 @@ class TestRunner(unittest.TestCase):
)
results = self.playbook.run()
return dict(
results = results,
callbacks = self.test_callbacks.results(),
results = results,
events = self.test_callbacks.events,
)
def test_one(self):
pb = os.path.join(self.test_dir, 'playbook1.yml')
print self._run(pb)
print utils.bigjson(self._run(pb))
assert False, "this test works, but we need to check the results values to complete it"

View file

@ -2,7 +2,7 @@
---
- hosts: all
vars:
answer: "I think so, Brain, but if they called them sad meals, kids wouldn't buy them."
answer: "???"
port: 5150
tasks:
@ -14,13 +14,13 @@
action: command /bin/true
- name: test basic shell
action: echo $HOME
action: shell echo $HOME
- name: test copy
action: copy src=sample.j2 dest=test_data/copy.out
action: copy src=sample.j2 dest=/tmp/ansible_test_data_copy.out
- name: test template
action: template src=sample.j2 dest=test_data/template.out
action: template src=sample.j2 dest=/tmp/ansible_test_data_template.out
handlers: