def test_write_output_to_stdout_writes_directly_to_stdout_if_can_not_write_to_buffer(self):
        # In Python 2 stdout.buffer does not exists, so we need to write
        # the output (which is not a bytestring in python 2) directly
        # to sys.stdout
        self.stdout.buffer.write.side_effect = AttributeError

        write_output_to_stdout(self.output)

        self.stdout.write.assert_called_once_with(self.output)
def run_command_in_vagrant(command_to_run, vagrant_info,
                           ssh_user=HYPERNODE_VAGRANT_DEFAULT_USER):
    """
    Run a command in the remote vagrant
    :param str command_to_run: The command to run
    :param dict vagrant_info: The vagrant ssh-config connection details
    :param str ssh_user: The SSH user to run the command as
    :return None:
    """
    log.info("Running command in the vagrant environment")
    ssh_wrapper_command = wrap_ssh_call(
        vagrant_info, ssh_user=ssh_user, command_to_run=command_to_run
    )
    try:
        run_local_command(ssh_wrapper_command, shell=True)
    except CalledProcessError as e:
        log.info("Running command in Vagrant exited nonzero")
        write_output_to_stdout(e.output)
示例#3
0
def run_command_in_vagrant(command_to_run,
                           vagrant_info,
                           ssh_user=HYPERNODE_VAGRANT_DEFAULT_USER):
    """
    Run a command in the remote vagrant
    :param str command_to_run: The command to run
    :param dict vagrant_info: The vagrant ssh-config connection details
    :param str ssh_user: The SSH user to run the command as
    :return None:
    """
    log.info("Running command in the vagrant environment")
    ssh_wrapper_command = wrap_ssh_call(vagrant_info,
                                        ssh_user=ssh_user,
                                        command_to_run=command_to_run)
    try:
        run_local_command(ssh_wrapper_command, shell=True)
    except CalledProcessError as e:
        log.info("Running command in Vagrant exited nonzero")
        write_output_to_stdout(e.output)
    def test_write_output_to_stdout_does_not_write_directly_to_stdout(self):
        write_output_to_stdout(self.output)

        self.assertFalse(self.stdout.write.called)
    def test_write_output_to_stdout_attempts_to_write_to_buffer(self):
        write_output_to_stdout(self.output)

        self.stdout.buffer.write.assert_called_once_with(self.output)