def test_check_with_errored_handled_metadata_section(): # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.ERROR, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=NodeMetadataFactory.batch(1), ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=False, duplicate_container_collector=False, unknown_collector=False, ), ) # Act check_result = list( kube_collector_info.check( collector_metadata, None, collector_daemons, )) # Assert assert len(check_result) == 3 assert isinstance(check_result[0], Result) and check_result[0].state == State.CRIT
def test_check_with_no_collector_components_section(): # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.OK, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=NodeMetadataFactory.batch(1), ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=False, duplicate_container_collector=False, unknown_collector=False, )) # Act check_result = list( kube_collector_info.check( collector_metadata, None, collector_daemons, )) # Assert assert all(isinstance(result, Result) for result in check_result) assert isinstance(check_result[0], Result) and check_result[0].summary.startswith( "Cluster collector version:") assert len(check_result) == 4
def test_check_with_no_collector_components_section(collectors_metadata): check_result = list(kube_collector_info.check(collectors_metadata, None)) assert all(isinstance(result, Result) for result in check_result) assert isinstance(check_result[0], Result) and check_result[0].summary.startswith( "Cluster collector version:") assert len(check_result) == 2
def test_check_with_errored_handled_metadata_section(collectors_metadata, collector_handling_logs): check_result = list( kube_collector_info.check(collectors_metadata, collector_handling_logs)) assert len(check_result) == 1 assert isinstance(check_result[0], Result) and check_result[0].state == State.CRIT
def test_check_all_ok_sections(collectors_metadata, collector_handling_logs): check_result = list( kube_collector_info.check( collectors_metadata, collector_handling_logs, )) assert len(check_result) == 4 assert all(isinstance(result, Result) for result in check_result) assert all(result.state == State.OK for result in check_result if isinstance(result, Result))
def test_check_api_daemonsets_multiple_with_same_label() -> None: # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.OK, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=None, ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=True, duplicate_container_collector=True, unknown_collector=False, ), ) collector_processing_logs = None # Act check_result = list( kube_collector_info.check( collector_metadata, collector_processing_logs, collector_daemons, )) # Assert assert len(check_result) == 4 container_result = check_result[1] machine_result = check_result[2] additional_info_result = check_result[3] assert isinstance(container_result, Result) and container_result.state == State.OK assert (container_result.summary == "Multiple DaemonSets with label node-collector=container-metrics") assert isinstance(machine_result, Result) and machine_result.state == State.OK assert (machine_result.summary == "Multiple DaemonSets with label node-collector=machine-sections") assert isinstance(additional_info_result, Result) and additional_info_result.state == State.OK assert ( additional_info_result.details == "Cannot identify node collector, if label is found on multiple DaemonSets" )
def test_check_all_ok_sections(): # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.OK, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=NodeMetadataFactory.batch(1), ) collector_processing_logs = CollectorProcessingLogs( container=CollectorHandlerLog(status=CollectorState.OK, title="title", detail="OK"), machine=CollectorHandlerLog(status=CollectorState.OK, title="title", detail="OK"), ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=False, duplicate_container_collector=False, unknown_collector=False, )) # Act check_result = list( kube_collector_info.check( collector_metadata, collector_processing_logs, collector_daemons, )) # Assert assert len(check_result) == 6 assert all(isinstance(result, Result) for result in check_result) assert all(result.state == State.OK for result in check_result if isinstance(result, Result))