Ejemplo n.º 1
0
def test_sendtorsync_rsyncformat1(mock_sendtoshell):
    """
    Testing the format of the rsync call sent to the shell. This test
    will check that calls without masks get formed correctly.
    """

    job = {
        "port": "22",
        "user": "******",
        "host": "massive-machine"
    }

    # Set the return values of sendtoshell.
    mock_sendtoshell.return_value = "Output message", "Error message", 0

    sendtorsync(job, "src", "dst", "", "")

    callargs = mock_sendtoshell.call_args[0][0]
    testargs = "rsync -azP -e ssh -p 22 src dst"

    assert " ".join(callargs) == testargs
Ejemplo n.º 2
0
def test_sendtorsync_retries(mock_sendtoshell, mock_time):
    """
    Test that the rsync method will try three times if rsync fails before
    finally raising the RsyncError exception.
    """

    job = {
        "port": "22",
        "user": "******",
        "host": "massive-machine"
    }

    # Set the return values of sendtoshell.
    mock_sendtoshell.return_value = "Output message", "Error message", 1

    # Set the timout for retries to 0 seconds to speed up test.
    mock_time.return_value = None

    with pytest.raises(exceptions.RsyncError):

        sendtorsync(job, "src", "dst", "", "")

    assert mock_sendtoshell.call_count == 3, "This method should retry 3 times"
Ejemplo n.º 3
0
def test_sendtorsync_rsyncformat4(mock_sendtoshell):
    """
    Testing the format of the rsync call sent to the shell. This test will
    check that calls with file masks get formed correctly for multiple excluded
    files.
    """

    job = {
        "port": "22",
        "user": "******",
        "host": "massive-machine"
    }

    # Set the return values of sendtoshell.
    mock_sendtoshell.return_value = "Output message", "Error message", 0

    sendtorsync(job, "src", "dst", "incfile", "exfile1, exfile2")

    callargs = mock_sendtoshell.call_args[0][0]
    testargs = ("rsync -azP --include incfile --exclude exfile1 --exclude "
                "exfile2 -e ssh -p 22 src dst")

    assert " ".join(callargs) == testargs