def test_check_flink_service_health_too_few_taskmanagers(instance_config): def check_under_replication_side_effect(*args, **kwargs): if kwargs["sub_component"] == "supervisor": return False, "OK" if kwargs["sub_component"] == "jobmanager": return False, "OK" if kwargs["sub_component"] == "taskmanager": return True, "NOPE" all_pods = [] with mock.patch( "paasta_tools.check_flink_services_health.healthy_flink_containers_cnt", autospec=True, return_value=1, ), mock.patch( "paasta_tools.check_flink_services_health.check_under_registered_taskmanagers", autospec=True, return_value=(True, "NOPE"), ) as mock_check_under_registered_taskmanagers, mock.patch( "paasta_tools.check_flink_services_health.check_under_replication", autospec=True, side_effect=check_under_replication_side_effect, ) as mock_check_under_replication, mock.patch( "paasta_tools.check_flink_services_health.send_replication_event", autospec=True ) as mock_send_replication_event: instance_config.config_dict["taskmanager"] = {"instances": 3} check_flink_services_health.check_flink_service_health( instance_config=instance_config, all_tasks_or_pods=all_pods, smartstack_replication_checker=None, ) expected = [ mock.call( instance_config=instance_config, expected_count=1, num_available=1, sub_component="supervisor", ), mock.call( instance_config=instance_config, expected_count=1, num_available=1, sub_component="jobmanager", ), mock.call( instance_config=instance_config, expected_count=3, num_available=1, sub_component="taskmanager", ), ] mock_check_under_replication.assert_has_calls(expected) mock_check_under_registered_taskmanagers.assert_called_once_with( instance_config=instance_config, expected_count=3, ) mock_send_replication_event.assert_called_once_with( instance_config=instance_config, status=pysensu_yelp.Status.CRITICAL, output="OK\n########\nOK\n########\nNOPE\n########\nNOPE", )
def test_check_flink_service_health_under_registered_taskamanagers(instance_config): all_pods = [] with mock.patch( "paasta_tools.check_flink_services_health.healthy_flink_containers_cnt", autospec=True, return_value=1, ), mock.patch( "paasta_tools.check_flink_services_health.check_under_replication", autospec=True, return_value=(False, "OK", "check_rep"), ) as mock_check_under_replication, mock.patch( "paasta_tools.check_flink_services_health.check_under_registered_taskmanagers", autospec=True, return_value=(True, "NOPE", "check_task"), ) as mock_check_under_registered_taskmanagers, mock.patch( "paasta_tools.check_flink_services_health.send_replication_event", autospec=True ) as mock_send_replication_event: instance_config.config_dict["taskmanager"] = {"instances": 3} check_flink_services_health.check_flink_service_health( instance_config=instance_config, all_tasks_or_pods=all_pods, replication_checker=None, dry_run=True, ) expected = [ mock.call( instance_config=instance_config, expected_count=1, num_available=1, sub_component="supervisor", ), mock.call( instance_config=instance_config, expected_count=1, num_available=1, sub_component="jobmanager", ), mock.call( instance_config=instance_config, expected_count=3, num_available=1, sub_component="taskmanager", ), ] mock_check_under_replication.assert_has_calls(expected) mock_check_under_registered_taskmanagers.assert_called_once_with( instance_config=instance_config, expected_count=3, cr_name="" ) mock_send_replication_event.assert_called_once_with( instance_config=instance_config, status=pysensu_yelp.Status.CRITICAL, output="OK, OK, OK, NOPE", description="check_rep\n########\ncheck_rep\n########\ncheck_rep\n########\ncheck_task", dry_run=True, )
def test_check_flink_service_health_healthy(instance_config): all_pods = [] with mock.patch( "paasta_tools.check_flink_services_health.healthy_flink_containers_cnt", autospec=True, return_value=1, ), mock.patch( "paasta_tools.check_flink_services_health.check_under_replication", autospec=True, return_value=(False, "OK"), ) as mock_check_under_replication, mock.patch( "paasta_tools.check_flink_services_health.check_under_registered_taskmanagers", autospec=True, return_value=(False, "OK"), ) as mock_check_under_registered_taskmanagers, mock.patch( "paasta_tools.check_flink_services_health.send_replication_event", autospec=True) as mock_send_replication_event: instance_config.config_dict["taskmanager"] = {"instances": 3} check_flink_services_health.check_flink_service_health( instance_config=instance_config, all_pods=all_pods, smartstack_replication_checker=None, ) expected = [ mock.call( instance_config=instance_config, expected_count=1, num_available=1, sub_component="supervisor", ), mock.call( instance_config=instance_config, expected_count=1, num_available=1, sub_component="jobmanager", ), mock.call( instance_config=instance_config, expected_count=3, num_available=1, sub_component="taskmanager", ), ] mock_check_under_replication.assert_has_calls(expected) mock_check_under_registered_taskmanagers.assert_called_once_with( instance_config=instance_config, expected_count=3, ) mock_send_replication_event.assert_called_once_with( instance_config=instance_config, status=pysensu_yelp.Status.OK, output="OK\n########\nOK\n########\nOK\n########\nOK", )