def test_zero_ownership_should_not_fail(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = ZERO_OWNERSHIP_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) (cassandra.CassandraStatusValidation(ssh_ctx, hosts=["127.0.0.1"]).perform({}))
def test_cassandra_success_without_percent_signs(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = HEALTHY_OUTPUT_WITHOUT_PERCENT_SIGNS monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) (cassandra.CassandraStatusValidation(ssh_ctx, hosts=["127.0.0.1"]).perform({}))
def test_repr(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = ZERO_OWNERSHIP_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) (cassandra.CassandraStatusValidation(ssh_ctx, hosts=["127.0.0.1"]).__repr__())
def test_ignore_joining_nodes(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = JOINING_NODE_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) (cassandra.CassandraStatusValidation(ssh_ctx, number_nodes=4, hosts=["127.0.0.1"]).perform({}))
def test_cassandra_down(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = SERVER_DOWN_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) with pytest.raises(ValidationFailure): (cassandra.CassandraStatusValidation(ssh_ctx, hosts=["127.0.0.1"]).perform({}))
def test_cassandra_threshold(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = UNBALANCED_RING_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) with pytest.raises(ValidationFailure): (cassandra.CassandraStatusValidation(ssh_ctx, owns_threshold=40, hosts=["127.0.0.1"]).perform({}))
def test_cassandra_success_with_percent_signs(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = UNHEALTHY_OUTPUT_WITH_PERCENT_SIGNS monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) with pytest.raises(ValidationFailure): (cassandra.CassandraStatusValidation(ssh_ctx, owns_threshold=40, hosts=["127.0.0.1"]).perform({}))
def test_no_cassandra(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = "Error connecting to remote JMX agent!" monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) with pytest.raises(ValidationFailure): (cassandra.CassandraStatusValidation(ssh_ctx, number_nodes=5, hosts=["127.0.0.1"]).perform({}))
def test_cassandra_node_count(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = MISSING_NODE_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) with pytest.raises(ValidationFailure): (cassandra.CassandraStatusValidation(ssh_ctx, number_nodes=5, hosts=["127.0.0.1"]).perform({}))
def test_extra_nodes(monkeypatch, tmpdir): """Don't complain if there are extra nodes; the cluster might be scaling up. """ ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = HEALTHY_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) (cassandra.CassandraStatusValidation(ssh_ctx, number_nodes=4, hosts=["127.0.0.1"]).perform({}))
def test_str(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = ZERO_OWNERSHIP_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) str(cassandra.CassandraStatusValidation(ssh_ctx, hosts=["127.0.0.1"], cluster_name=_CLUSTER_NAME))
def test_cassandra_success_with_question_marks_in_owns(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = QUESTION_MARK_OUTPUT monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) (cassandra.CassandraStatusValidation(ssh_ctx, hosts=["127.0.0.1"], cluster_name=_CLUSTER_NAME) .perform({}))
def test_stack_trace(monkeypatch, tmpdir): ssh_ctx = ssh.SshContext("ubuntu", get_mock_key_file(tmpdir)) text = """[10.198.10.174] out: Exception java.lang.RuntimeException. [10.198.10.174] out: at org.apache.cassandra.dht.Murmur3Partitioner.describeOwnership(Murmur3Partitioner.java:120) [10.198.10.174] out: at org.apache.cassandra.service.StorageService.getOwnership(StorageService.java:3512) [10.198.10.174] out: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) """ monkeypatch.setattr(ssh, "run", lambda x: get_mock_ssh_text(text, 0)) monkeypatch.setattr(cassandra, "run", lambda x: get_mock_ssh_text(text, 0)) with pytest.raises(ValidationFailure): (cassandra.CassandraStatusValidation(ssh_ctx, number_nodes=4, hosts=["127.0.0.1"]).perform({}))
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({}))
def test_ssh_expected_rejects_0_when_changed(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(ValidationFailure): (ssh.SshCommandValidation(ssh_ctx, "name", "cmd", hosts=hosts).expect_exit_code(1).perform({}))
def test_str(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)) str(ssh.SshCommandValidation(ssh_ctx, "name", "cmd", hosts=hosts))
def test_exit_code_not_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)) with pytest.raises(ValidationFailure): (ssh.SshCommandValidation(ssh_ctx, "citations", "command", hosts=hosts).expect_exit_code(1).perform({}))
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({}))
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__())
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({}))
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( {}))
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({}))
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({})
def test_max_load_correctly_fails_5_minute(monkeypatch, tmpdir): t = "18:01:46 up 62 days, 18:27, 1 user, load average: 0.09, 30.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)) with pytest.raises(ValidationFailure): (ssh.LoadAverageValidation(ssh_ctx, hosts=hosts) .expect_max_5_minute_load(20) .perform({}))
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({}))
def test_output_does_not_contain(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_output_does_not_contain("what") .perform({}))
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({})
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({}))
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({}))
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({}))
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({}))
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({}))
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"]) .perform({}))
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({}))
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({}))
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"]) .perform({}))
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({})
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({})
def test_max_load_correctly_formats_failure(monkeypatch, tmpdir): t = "18:01:46 up 62 days, 18:27, 1 user, load average: 40.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)) try: (ssh.LoadAverageValidation(ssh_ctx, hosts=hosts) .expect_max_1_minute_load(40) .perform({})) #we should have raised an error assert False except ValidationFailure, e: #this is a weak check assert "{0}" not in str(e)
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__()
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"]) v.__repr__()