Exemplo n.º 1
0
    def test_dryrun_should_not_perform_actual_delete(self, mock_db_client,
                                                     mock_es_client):
        metric_name = 'metric.test'
        args = em.parse_arguments(
            ['delete', '-m', metric_name, '-t', '836986', '--dryrun'])

        # set up the mock for db client
        mock_db_client.connect.return_value = ''
        mock_db_client.get_excess_enums_relevant_data.return_value = {
            'metrics_excess_enums': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_full': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_5m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_20m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_60m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_240m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_1440m': ('836986.enumtest.enum.one', 0),
        }

        # set up the mock for es client
        mock_es_client.get_metric_metadata.return_value = {'found': 'true'}
        mock_es_client.get_enums_data.return_value = {'found': 'true'}

        em.clear_excess_enums(args, mock_db_client, mock_es_client)

        self.assertFalse(
            mock_db_client.delete_metrics_excess_enums.called,
            'delete_metrics_excess_enums method should not have been called')
        self.assertFalse(
            mock_db_client.delete_metrics_preaggregated_full.called,
            'delete_metrics_preaggregated_full method should not have been called'
        )
        self.assertFalse(
            mock_db_client.delete_metrics_preaggregated_5m.called,
            'delete_metrics_preaggregated_5m method should not have been called'
        )
        self.assertFalse(
            mock_db_client.delete_metrics_preaggregated_20m.called,
            'delete_metrics_preaggregated_20m method should not have been called'
        )
        self.assertFalse(
            mock_db_client.delete_metrics_preaggregated_60m.called,
            'delete_metrics_preaggregated_60m method should not have been called'
        )
        self.assertFalse(
            mock_db_client.delete_metrics_preaggregated_240m.called,
            'delete_metrics_preaggregated_240m method should not have been called'
        )
        self.assertFalse(
            mock_db_client.delete_metrics_preaggregated_1440m.called,
            'delete_metrics_preaggregated_1440m method should not have been called'
        )

        self.assertFalse(
            mock_es_client.delete_metric_metadata.called,
            'delete_metric_metadata method should not have been called')
        self.assertFalse(
            mock_es_client.delete_enums_data.called,
            'delete_enums_data method should not have been called')
Exemplo n.º 2
0
    def test_delete_from_es_only_if_it_is_an_excess_enum(self, mock_db_client, mock_es_client):
        metric_name = 'metric.test'
        args = em.parse_arguments(['delete', '-m', metric_name, '-t', '836986'])

        # set up the mock for db client
        mock_db_client.connect.return_value = ''
        mock_db_client.get_excess_enums_relevant_data.return_value = {}  # metric is not an excess enum

        # set up the mock for es client
        mock_es_client.get_metric_metadata.return_value = {'found': 'true'}
        mock_es_client.get_enums_data.return_value = {'found': 'true'}

        em.clear_excess_enums(args, mock_db_client, mock_es_client)

        self.assertFalse(mock_es_client.delete_metric_metadata.called,
                         'delete_metric_metadata method should not have been called')
        self.assertFalse(mock_es_client.delete_enums_data.called,
                         'delete_enums_data method should not have been called')
Exemplo n.º 3
0
    def test_dryrun_should_not_perform_actual_delete(self, mock_db_client, mock_es_client):
        metric_name = 'metric.test'
        args = em.parse_arguments(['delete', '-m', metric_name, '-t', '836986', '--dryrun'])

        # set up the mock for db client
        mock_db_client.connect.return_value = ''
        mock_db_client.get_excess_enums_relevant_data.return_value = {
            'metrics_excess_enums': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_full': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_5m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_20m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_60m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_240m': ('836986.enumtest.enum.one', 0),
            'metrics_preaggregated_1440m': ('836986.enumtest.enum.one', 0),
        }

        # set up the mock for es client
        mock_es_client.get_metric_metadata.return_value = {'found': 'true'}
        mock_es_client.get_enums_data.return_value = {'found': 'true'}

        em.clear_excess_enums(args, mock_db_client, mock_es_client)

        self.assertFalse(mock_db_client.delete_metrics_excess_enums.called,
                         'delete_metrics_excess_enums method should not have been called')
        self.assertFalse(mock_db_client.delete_metrics_preaggregated_full.called,
                         'delete_metrics_preaggregated_full method should not have been called')
        self.assertFalse(mock_db_client.delete_metrics_preaggregated_5m.called,
                         'delete_metrics_preaggregated_5m method should not have been called')
        self.assertFalse(mock_db_client.delete_metrics_preaggregated_20m.called,
                         'delete_metrics_preaggregated_20m method should not have been called')
        self.assertFalse(mock_db_client.delete_metrics_preaggregated_60m.called,
                         'delete_metrics_preaggregated_60m method should not have been called')
        self.assertFalse(mock_db_client.delete_metrics_preaggregated_240m.called,
                         'delete_metrics_preaggregated_240m method should not have been called')
        self.assertFalse(mock_db_client.delete_metrics_preaggregated_1440m.called,
                         'delete_metrics_preaggregated_1440m method should not have been called')

        self.assertFalse(mock_es_client.delete_metric_metadata.called,
                         'delete_metric_metadata method should not have been called')
        self.assertFalse(mock_es_client.delete_enums_data.called,
                         'delete_enums_data method should not have been called')
Exemplo n.º 4
0
    def test_delete_from_es_only_if_it_is_an_excess_enum(
            self, mock_db_client, mock_es_client):
        metric_name = 'metric.test'
        args = em.parse_arguments(
            ['delete', '-m', metric_name, '-t', '836986'])

        # set up the mock for db client
        mock_db_client.connect.return_value = ''
        mock_db_client.get_excess_enums_relevant_data.return_value = {
        }  # metric is not an excess enum

        # set up the mock for es client
        mock_es_client.get_metric_metadata.return_value = {'found': 'true'}
        mock_es_client.get_enums_data.return_value = {'found': 'true'}

        em.clear_excess_enums(args, mock_db_client, mock_es_client)

        self.assertFalse(
            mock_es_client.delete_metric_metadata.called,
            'delete_metric_metadata method should not have been called')
        self.assertFalse(
            mock_es_client.delete_enums_data.called,
            'delete_enums_data method should not have been called')