Beispiel #1
0
def test_repr(monkeypatch, tmpdir):
    t = "18:01:46 up 62 days, 18:27,  1 user,  load average: 0.09, 0.04, 0.05"
    monkeypatch.setattr(
        ssh, "run", lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    (ssh.SshCommandValidation(ssh_ctx, "name", "cmd", hosts=hosts).__repr__())
Beispiel #2
0
def test_generate_id_consistency_ssh(tmpdir):

    pub = PagerDutyPublisher("url", "token")
    ssh_ctx = ssh.SshContext("ubuntu", ssh_key_file(tmpdir))
    ssh_ctx2 = ssh.SshContext("ubuntu", ssh_key_file(tmpdir))

    v = ssh.SshCommandValidation(ssh_ctx, "name", "cmd", hosts=["a fake host"])
    v2 = ssh.SshCommandValidation(ssh_ctx2,
                                  "name",
                                  "cmd",
                                  hosts=["a fake host"])

    failure = Failure("bar", v, "unable to transmogrify")
    another = Failure("foo", v2, "to transmogrify")

    assert pub._generate_id(failure) == pub._generate_id(another)
Beispiel #3
0
def test_ssh_expected_return_code(monkeypatch, tmpdir):
    t = "18:01:46 up 62 days, 18:27,  1 user,  load average: 0.09, 0.04, 0.05"
    monkeypatch.setattr(
        ssh, "run", lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 1))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    (ssh.SshCommandValidation(ssh_ctx, "name", "cmd",
                              hosts=hosts).expect_exit_code(1).perform({}))
Beispiel #4
0
def test_exit_code_equals(monkeypatch, tmpdir):
    t = "stopped/waiting"
    monkeypatch.setattr(
        ssh, "run", lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    (ssh.SshCommandValidation(ssh_ctx, "citations", "command",
                              hosts=hosts).expect_exit_code(0).perform({}))
Beispiel #5
0
def test_ssh_expected_0_by_default(monkeypatch, tmpdir):
    t = "18:01:46 up 62 days, 18:27,  1 user,  load average: 0.09, 0.04, 0.05"
    monkeypatch.setattr(
        ssh, "run", lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 1))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    with pytest.raises(ValidationFailure):
        (ssh.SshCommandValidation(ssh_ctx, "name", "cmd",
                                  hosts=hosts).perform({}))
Beispiel #6
0
def test_output_does_not_contain_correctly_fails(monkeypatch, tmpdir):
    t = "stopped/waiting"
    monkeypatch.setattr(
        ssh, "run", lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    with pytest.raises(ValidationFailure):
        (ssh.SshCommandValidation(
            ssh_ctx, "citations", "command",
            hosts=hosts).expect_output_does_not_contain("stopped").perform({}))
Beispiel #7
0
def test_output_correct_on_ssh_failure(monkeypatch, tmpdir):
    monkeypatch.setattr(ssh, "run",
                        lambda x, combine_stderr, timeout: broken_ssh())
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    with pytest.raises(ValidationFailure):
        validation = ssh.SshCommandValidation(ssh_ctx,
                                              "citations",
                                              "command",
                                              hosts=hosts)
        validation.add_expectation(ssh.OutputLessThan(validation, 90))
        validation.perform({})
Beispiel #8
0
def test_output_less_than(monkeypatch, tmpdir):
    t = "100"
    monkeypatch.setattr(
        ssh, "run", lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    validation = ssh.SshCommandValidation(ssh_ctx,
                                          "citations",
                                          "command",
                                          hosts=hosts)
    validation.add_expectation(ssh.OutputLessThan(validation, 110))
    validation.perform({})
Beispiel #9
0
def test_output_greater_than_correctly_fails(monkeypatch, tmpdir):
    t = "100"
    monkeypatch.setattr(
        ssh, "run", lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    with pytest.raises(ValidationFailure):
        validation = ssh.SshCommandValidation(ssh_ctx,
                                              "citations",
                                              "command",
                                              hosts=hosts)
        validation.add_expectation(ssh.OutputGreaterThan(validation, 110))
        validation.perform({})