def test_raises_when_no_global_cluster_health(self): """Test that parses cluster global status when unhealthy.""" mock_run_sync = _get_mock_run_sync( return_value=b""" member 5208bbf5c00e7cdf is unhealthy: got unhealthy result from https://toolsbeta-test-k8s-etcd-6.toolsbeta.eqiad1.wikimedia.cloud:2379 """, # noqa: E501 ) controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): with self.assertRaises(UnableToParseOutput): controller.get_cluster_health() mock_run_sync.assert_called_once()
def test_passes_correct_ca_file(self): """Test that passes correct ca file by default.""" expected_ca_file = "/etc/etcd/ssl/ca.pem" mock_run_sync = _get_mock_run_sync( return_value=b""" member 415090d15def9053 is healthy: got healthy result from https://toolsbeta-test-k8s-etcd-6.toolsbeta.eqiad1.wikimedia.cloud:2379 cluster is healthy """, # noqa: E501 ) controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): controller.get_cluster_health() _assert_called_with_single_param( param=f"--ca-file {expected_ca_file}", mock_obj=mock_run_sync, )
def test_gets_cluster_unhealthy(self): """Test that parses cluster global status when unhealthy.""" expected_global_status = HealthStatus.unhealthy mock_run_sync = _get_mock_run_sync( return_value=b""" member 5208bbf5c00e7cdf is unhealthy: got unhealthy result from https://toolsbeta-test-k8s-etcd-6.toolsbeta.eqiad1.wikimedia.cloud:2379 cluster is unhealthy """, # noqa: E501 ) controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): gotten_result = controller.get_cluster_health() mock_run_sync.assert_called_once() assert expected_global_status == gotten_result.global_status
def test_parses_result_with_one_member(self): """Test that parses result with one member.""" expected_members = {"415090d15def9053": HealthStatus.healthy} mock_run_sync = _get_mock_run_sync( return_value=b""" member 415090d15def9053 is healthy: got healthy result from https://toolsbeta-test-k8s-etcd-6.toolsbeta.eqiad1.wikimedia.cloud:2379 cluster is healthy """, # noqa: E501 ) controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): gotten_result = controller.get_cluster_health() mock_run_sync.assert_called_once() assert gotten_result.members_status == expected_members