示例#1
0
def test_max_load_correctly_fails_15_minute(monkeypatch, tmpdir):
    t = "18:01:46 up 62 days, 18:27,  1 user,  load average: 0.09, 0.04, 12.05"
    monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))
    with pytest.raises(ValidationFailure):
        (ssh.LoadAverageValidation(
            ssh_ctx, hosts=hosts).expect_max_15_minute_load(10).perform({}))
示例#2
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__())
示例#3
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)
示例#4
0
def test_max_load_average(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: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    (ssh.LoadAverageValidation(ssh_ctx, hosts=hosts).expect_max_1_minute_load(
        40).expect_max_5_minute_load(20).expect_max_15_minute_load(10).perform(
            {}))
示例#5
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({}))
示例#6
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({}))
示例#7
0
def test_load_average_disallows_generic_expections(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))

    with pytest.raises(NotImplementedError):
        (ssh.LoadAverageValidation(
            ssh_ctx, hosts=hosts).expect_exit_code(1).perform({}))
示例#8
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({}))
示例#9
0
def test_service_state(monkeypatch, tmpdir):
    t = "running"
    monkeypatch.setattr(
        ssh, "sudo",
        lambda x, combine_stderr, timeout: get_mock_ssh_text(t, 0))
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))

    (ssh.UpstartServiceValidation(ssh_ctx, "citations",
                                  hosts=hosts).perform({}))
示例#10
0
def test_kafka_command_not_found(monkeypatch, tmpdir):
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))
    text = "-bash: /opt/kafka2/bin/kdkd: No such file or directory"
    monkeypatch.setattr(kafka, "run", lambda x: get_mock_ssh_text(text, 0))
    with pytest.raises(ValidationFailure):
        (kafka.KafkaStatusValidation(ssh_ctx,
                                     zookeeper_nodes="1.2.3.4:2181",
                                     hosts=["127.0.0.1"],
                                     cluster_name=_CLUSTER_NAME).perform({}))
示例#11
0
def test_kafka_multiple_duplicate_partition(monkeypatch, tmpdir):
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))
    text = "topic: topic1\tpartition: 0\tleader: 140\treplicas: 140,187,96,99,132\tisr: 140,187,96,99,132\r\ntopic: topic1\tpartition: 1\tleader: 187\treplicas: 187,96,99,132,140\tisr: 132,96,187,140,99\r\ntopic: topic1\tpartition: 2\tleader: 96\treplicas: 96,99,132,140,187\tisr: 96,99,132,140,187\r\ntopic: topic1\tpartition: 3\tleader: 99\treplicas: 99,132,140,187,96\tisr: 99,132,140,187,96\r\ntopic: topic1\tpartition: 4\tleader: 99\treplicas: 132,140,187,96,99\tisr: 132,140,187,96,99\r\ntopic: topic2\tpartition: 0\tleader: 187\treplicas: 187,96,99,132,140\tisr: 132,96,187,140,99\r\ntopic: topic2\tpartition: 1\tleader: 96\treplicas: 96,99,132,140,187\tisr: 132,96,187,140,99\r\ntopic: topic2\tpartition: 2\tleader: 99\treplicas: 99,132,140,187,96\tisr: 132,96,187,140,99\r\ntopic: topic2\tpartition: 3\tleader: 132\treplicas: 132,140,187,96,99\tisr: 132,96,187,140,99\r\ntopic: topic2\tpartition: 4\tleader: 132\treplicas: 140,187,96,99,132\tisr: 132,96,187,140,99"
    monkeypatch.setattr(kafka, "run", lambda x: get_mock_ssh_text(text, 0))
    with pytest.raises(ValidationFailure):
        (kafka.KafkaStatusValidation(ssh_ctx,
                                     zookeeper_nodes="1.2.3.4:2181",
                                     hosts=["127.0.0.1"],
                                     cluster_name=_CLUSTER_NAME).perform({}))
示例#12
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({}))
示例#13
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({})
示例#14
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({})
示例#15
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({})
示例#16
0
def test_repr(monkeypatch, tmpdir):
    ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir))
    text = """
  Exception in thread "main" joptsimple.OptionMissingRequiredArgumentException: Option ['zookeeper'] requires an argument
    at joptsimple.RequiredArgumentOptionSpec.detectOptionArgument(RequiredArgumentOptionSpec.java:49)
    at joptsimple.ArgumentAcceptingOptionSpec.handleOption(ArgumentAcceptingOptionSpec.java:209)
    at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:405)
    at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:55)
    at joptsimple.OptionParser.parse(OptionParser.java:392)
    at kafka.admin.ListTopicCommand$.main(ListTopicCommand.scala:43)
    at kafka.admin.ListTopicCommand.main(ListTopicCommand.scala)
    """
    monkeypatch.setattr(kafka, "run", lambda x: get_mock_ssh_text(text, 0))
    v = kafka.KafkaStatusValidation(ssh_ctx,
                                    zookeeper_nodes="1.2.3.4:2181",
                                    hosts=["127.0.0.1"],
                                    cluster_name=_CLUSTER_NAME)
    v.__repr__()