Beispiel #1
0
    def test_get_file_error(self, fake_get_file):
        fake_ssh_docker_shell.custom_command = [
            "docker cp containerid:not-a-file remote_tempfile",
            False,
            [],
            ["docker error"],
        ]

        inventory = make_inventory(hosts=("@dockerssh/somehost:not-an-image",))
        state = State(inventory, Config())
        state.get_temp_filename = lambda _: "remote_tempfile"

        host = inventory.get_host("@dockerssh/somehost:not-an-image")
        host.connect()

        fake_get_file.return_value = True
        with self.assertRaises(IOError) as ex:
            host.get_file("not-a-file", "not-another-file", print_output=True)

        assert str(ex.exception) == "docker error"

        # SSH error
        fake_ssh_docker_shell.custom_command = [
            "docker cp containerid:not-a-file remote_tempfile",
            True,
            [],
            [],
        ]
        fake_get_file.return_value = False
        with self.assertRaises(IOError) as ex:
            host.get_file("not-a-file", "not-another-file", print_output=True)

        assert str(ex.exception) == "failed to copy file over ssh"
    def test_get_file(self, fake_get_file):
        fake_ssh_docker_shell.custom_command = [
            'docker cp containerid:not-a-file remote_tempfile', True, [], []
        ]

        inventory = make_inventory(
            hosts=('@dockerssh/somehost:not-an-image', ))
        state = State(inventory, Config())
        state.get_temp_filename = lambda _: 'remote_tempfile'

        host = inventory.get_host('@dockerssh/somehost:not-an-image')
        host.connect()

        host.get_file('not-a-file', 'not-another-file', print_output=True)

        # ensure copy from local to remote host
        fake_get_file.assert_called_with(state, host, 'remote_tempfile',
                                         'not-another-file')

        # ensure copy from remote host to remote docker container
        assert fake_ssh_docker_shell.ran_custom_command
Beispiel #3
0
    def test_put_file(self, fake_put_file):
        fake_ssh_docker_shell.custom_command = [
            "docker cp remote_tempfile containerid:not-another-file",
            True,
            [],
            [],
        ]

        inventory = make_inventory(hosts=("@dockerssh/somehost:not-an-image",))
        state = State(inventory, Config())
        state.get_temp_filename = lambda _: "remote_tempfile"

        host = inventory.get_host("@dockerssh/somehost:not-an-image")
        host.connect()

        host.put_file("not-a-file", "not-another-file", print_output=True)

        # ensure copy from local to remote host
        fake_put_file.assert_called_with(state, host, "local_tempfile", "remote_tempfile")

        # ensure copy from remote host to remote docker container
        assert fake_ssh_docker_shell.ran_custom_command
    def test_put_file_error(self, fake_put_file):
        inventory = make_inventory(
            hosts=('@dockerssh/somehost:not-an-image', ))
        state = State(inventory, Config())
        state.get_temp_filename = lambda _: 'remote_tempfile'

        host = inventory.get_host('@dockerssh/somehost:not-an-image')
        host.connect()

        # SSH error
        fake_put_file.return_value = False
        with self.assertRaises(IOError):
            host.put_file('not-a-file', 'not-another-file', print_output=True)

        # docker copy error
        fake_ssh_docker_shell.custom_command = [
            'docker cp remote_tempfile containerid:not-another-file', False,
            [], ['docker error']
        ]
        fake_put_file.return_value = True

        with self.assertRaises(IOError) as exn:
            host.put_file('not-a-file', 'not-another-file', print_output=True)
        assert str(exn.exception) == 'docker error'