Exemple #1
0
    def test_synchronize_action_basic(self):

        """ verify the synchronize action plugin sets 
            the delegate to 127.0.0.1 and remote path to user@host:/path """

        runner = FakeRunner()
        runner.remote_user = "******"
        runner.transport = "ssh"
        conn = FakeConn()
        inject = {
                    'inventory_hostname': "el6.lab.net",
                    'inventory_hostname_short': "el6",
                    'ansible_connection': None,
                    'ansible_ssh_user': '******',
                    'delegate_to': None,
                    'playbook_dir': '.',
                 }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject)

        assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert runner.executed_complex_args == {"dest":"[email protected]:/tmp/bar", "src":"/tmp/foo"}, "wrong args used"
        assert runner.sudo == None, "sudo was not reset to None" 
Exemple #2
0
    def test_synchronize_action_sudo(self):

        """ verify the synchronize action plugin unsets and then sets sudo """ 

        runner = FakeRunner()
        runner.become = True
        runner.remote_user = "******"
        runner.transport = "ssh"
        conn = FakeConn()
        inject = {
                    'inventory_hostname': "el6.lab.net",
                    'inventory_hostname_short': "el6",
                    'ansible_connection': None,
                    'ansible_ssh_user': '******',
                    'delegate_to': None,
                    'playbook_dir': '.',
                 }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject)

        assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert runner.executed_complex_args == {'dest':'[email protected]:/tmp/bar',
                                                'src':'/tmp/foo',
                                                'rsync_path':'"sudo rsync"'}, "wrong args used"
        assert runner.become == True, "sudo was not reset to True"
Exemple #3
0
    def test_synchronize_action_local(self):

        """ verify the synchronize action plugin sets 
            the delegate to 127.0.0.1 and does not alter the dest """

        runner = FakeRunner()
        runner.remote_user = "******"
        runner.transport = "paramiko"
        conn = FakeConn()
        conn.host = "127.0.0.1"
        conn.delegate = "thishost"
        inject = {
                    'inventory_hostname': "thishost",
                    'ansible_ssh_host': '127.0.0.1',
                    'ansible_connection': 'local',
                    'delegate_to': None,
                    'playbook_dir': '.',
                 }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject)

        assert runner.transport == "paramiko", "runner transport was changed"
        assert runner.remote_user == "jtanner", "runner remote_user was changed"
        assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert "dest_port" not in runner.executed_complex_args, "dest_port should not have been set"
        assert runner.executed_complex_args.get("src") == "/tmp/foo", "source was set incorrectly"
        assert runner.executed_complex_args.get("dest") == "/tmp/bar", "dest was set incorrectly"
Exemple #4
0
    def test_synchronize_action_sudo(self):
        """ verify the synchronize action plugin unsets and then sets sudo """

        runner = FakeRunner()
        runner.become = True
        runner.remote_user = "******"
        runner.transport = "ssh"
        conn = FakeConn()
        inject = {
            'inventory_hostname': "el6.lab.net",
            'inventory_hostname_short': "el6",
            'ansible_connection': None,
            'ansible_ssh_user': '******',
            'delegate_to': None,
            'playbook_dir': '.',
        }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar",
              inject)

        assert runner.executed_inject[
            'delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert runner.executed_complex_args == {
            'dest': '[email protected]:/tmp/bar',
            'src': '/tmp/foo',
            'rsync_path': '"sudo rsync"'
        }, "wrong args used"
        assert runner.become == True, "sudo was not reset to True"
Exemple #5
0
    def test_synchronize_action_basic(self):
        """ verify the synchronize action plugin sets 
            the delegate to 127.0.0.1 and remote path to user@host:/path """

        runner = FakeRunner()
        runner.remote_user = "******"
        runner.transport = "ssh"
        conn = FakeConn()
        inject = {
            'inventory_hostname': "el6.lab.net",
            'inventory_hostname_short': "el6",
            'ansible_connection': None,
            'ansible_ssh_user': '******',
            'delegate_to': None,
            'playbook_dir': '.',
        }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar",
              inject)

        assert runner.executed_inject[
            'delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert runner.executed_complex_args == {
            "dest": "[email protected]:/tmp/bar",
            "src": "/tmp/foo"
        }, "wrong args used"
        assert runner.sudo == None, "sudo was not reset to None"
Exemple #6
0
    def test_synchronize_action_local(self):
        """ verify the synchronize action plugin sets 
            the delegate to 127.0.0.1 and does not alter the dest """

        runner = FakeRunner()
        runner.remote_user = "******"
        runner.transport = "paramiko"
        conn = FakeConn()
        conn.host = "127.0.0.1"
        conn.delegate = "thishost"
        inject = {
            'inventory_hostname': "thishost",
            'ansible_ssh_host': '127.0.0.1',
            'ansible_connection': 'local',
            'delegate_to': None,
            'playbook_dir': '.',
        }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar",
              inject)

        assert runner.transport == "paramiko", "runner transport was changed"
        assert runner.remote_user == "jtanner", "runner remote_user was changed"
        assert runner.executed_inject[
            'delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert "dest_port" not in runner.executed_complex_args, "dest_port should not have been set"
        assert runner.executed_complex_args.get(
            "src") == "/tmp/foo", "source was set incorrectly"
        assert runner.executed_complex_args.get(
            "dest") == "/tmp/bar", "dest was set incorrectly"
Exemple #7
0
    def test_synchronize_action_vagrant(self):
        """ Verify the action plugin accommodates the common
            scenarios for vagrant boxes. """

        runner = FakeRunner()
        runner.remote_user = "******"
        runner.transport = "ssh"
        conn = FakeConn()
        conn.host = "127.0.0.1"
        conn.delegate = "thishost"
        inject = {
            'inventory_hostname': "thishost",
            'ansible_ssh_user': '******',
            'ansible_ssh_host': '127.0.0.1',
            'ansible_ssh_port': '2222',
            'delegate_to': None,
            'playbook_dir': '.',
            'hostvars': {
                'thishost': {
                    'inventory_hostname': 'thishost',
                    'ansible_ssh_port': '2222',
                    'ansible_ssh_host': '127.0.0.1',
                    'ansible_ssh_user': '******'
                }
            }
        }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar",
              inject)

        assert runner.transport == "ssh", "runner transport was changed"
        assert runner.remote_user == "jtanner", "runner remote_user was changed"
        assert runner.executed_inject[
            'delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert runner.executed_inject[
            'ansible_ssh_user'] == "vagrant", "runner user was changed"
        assert runner.executed_complex_args.get(
            "dest_port") == "2222", "remote port was not set to 2222"
        assert runner.executed_complex_args.get(
            "src") == "/tmp/foo", "source was set incorrectly"
        assert runner.executed_complex_args.get(
            "dest") == "[email protected]:/tmp/bar", "dest was set incorrectly"
Exemple #8
0
    def test_synchronize_action_vagrant(self):

        """ Verify the action plugin accommodates the common
            scenarios for vagrant boxes. """

        runner = FakeRunner()
        runner.remote_user = "******"
        runner.transport = "ssh"
        conn = FakeConn()
        conn.host = "127.0.0.1"
        conn.delegate = "thishost"
        inject = {
                    'inventory_hostname': "thishost",
                    'ansible_ssh_user': '******',
                    'ansible_ssh_host': '127.0.0.1',
                    'ansible_ssh_port': '2222',
                    'delegate_to': None,
                    'playbook_dir': '.',
                    'hostvars': {
                        'thishost': {
                            'inventory_hostname': 'thishost',
                            'ansible_ssh_port': '2222',
                            'ansible_ssh_host': '127.0.0.1',
                            'ansible_ssh_user': '******'
                        }
                    }
                 }

        x = Synchronize(runner)
        x.setup("synchronize", inject)
        x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject)

        assert runner.transport == "ssh", "runner transport was changed"
        assert runner.remote_user == "jtanner", "runner remote_user was changed"
        assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
        assert runner.executed_inject['ansible_ssh_user'] == "vagrant", "runner user was changed"
        assert runner.executed_complex_args.get("dest_port") == "2222", "remote port was not set to 2222"
        assert runner.executed_complex_args.get("src") == "/tmp/foo", "source was set incorrectly"
        assert runner.executed_complex_args.get("dest") == "[email protected]:/tmp/bar", "dest was set incorrectly"
############################################
#   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
############################################