Created
February 10, 2014 17:16
-
-
Save jctanner/8920201 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from ansible.runner.action_plugins.synchronize import ActionModule as Synchronize | |
class FakeRunner(object): | |
def __init__(self): | |
self.connection = None | |
self.transport = None | |
self.basedir = None | |
self.sudo = None | |
self.remote_user = None | |
self.private_key_file = None | |
def _execute_module(self, conn, tmp, module_name, args, inject=None): | |
self.executed_conn = conn | |
self.executed_tmp = tmp | |
self.executed_module_name = module_name | |
self.executed_args = args | |
self.executed_inject = inject | |
class FakeConn(object): | |
def __init__(self): | |
self.x = None | |
""" | |
class FakeInject(object): | |
def __init__(self): | |
self.x = None | |
""" | |
############################################ | |
# Basic Test | |
############################################ | |
runner = FakeRunner() | |
conn = FakeConn() | |
inject = { | |
'inventory_hostname': "localhost", | |
'delegate_to': None, | |
} | |
# def setup(self, module_name, inject) | |
# def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs): | |
# return self.runner._execute_module(conn, tmp, 'synchronize', module_items, inject=inject) | |
x = Synchronize(runner) | |
x.setup("synchronize", inject) | |
x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject) | |
print "#======================================#" | |
print "conn:",runner.executed_conn | |
print "tmp:",runner.executed_tmp | |
print "module_name:",runner.executed_module_name | |
print "args:",runner.executed_args | |
print "inject:",runner.executed_inject | |
############################################ | |
# Simple Remote Host | |
############################################ | |
""" | |
#BEFORE | |
runner.remote_user: jtanner | |
runner.transport: ssh | |
inject['ansible_connection']: None | |
inject['ansible_ssh_user']: root | |
inject['delegate_to']: None | |
# AFTER | |
options['dest_port']: None | |
inject['ansible_connection']: local | |
inject['ansible_ssh_port']: None | |
inject['ansible_ssh_user']: jtanner | |
inject['delegate_to']: 127.0.0.1 | |
module_items: [email protected]:/tmp/foobar src=/tmp/foobaz | |
""" | |
runner = FakeRunner() | |
runner.remote_user = "root" | |
runner.transport = "ssh" | |
conn = FakeConn() | |
inject = { | |
'inventory_hostname': "el6.lab.net", | |
'inventory_hostname_short': "el6", | |
'ansible_connection': None, | |
'ansible_ssh_user': 'root', | |
'delegate_to': None, | |
'playbook_dir': '.', | |
'dest': '/tmp/foobaz', | |
'src': '/tmp/foobar', | |
'vars': { | |
'dest': '/tmp/foobaz', | |
'src': '/tmp/foobaz', | |
} | |
} | |
x = Synchronize(runner) | |
x.setup("synchronize", inject) | |
x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject) | |
print "#======================================#" | |
print "conn:",runner.executed_conn | |
print "tmp:",runner.executed_tmp | |
print "module_name:",runner.executed_module_name | |
print "args:",runner.executed_args | |
print "inject:",runner.executed_inject | |
assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1" | |
assert runner.executed_args == "[email protected]:/tmp/bar src=/tmp/foo", "wrong args used" | |
assert runner.sudo == False, "sudo not set to false" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment