Exemple #1
0
    def testClientGetTaskStatistics(self, _, __, ___):
        """Tests get_task_statistics() basic functionality."""
        client = TurbiniaClient()
        client.get_task_data = mock.MagicMock()
        client.get_task_data.return_value = self.task_data
        task_stats = client.get_task_statistics('inst', 'proj', 'reg')

        # Make sure we have the right number of tasks for all sections
        self.assertEqual(task_stats['all_tasks'].count, 3)
        self.assertEqual(task_stats['successful_tasks'].count, 2)
        self.assertEqual(task_stats['failed_tasks'].count, 1)
        self.assertEqual(task_stats['requests'].count, 2)
        self.assertEqual(len(task_stats['tasks_per_user']), 2)
        self.assertEqual(len(task_stats['tasks_per_worker']), 2)
        self.assertEqual(len(task_stats['tasks_per_type']), 3)

        # Checking min/mean/max
        self.assertEqual(task_stats['all_tasks'].min, timedelta(minutes=1))
        self.assertEqual(task_stats['all_tasks'].mean, timedelta(minutes=3))
        self.assertEqual(task_stats['all_tasks'].max, timedelta(minutes=5))
        # Delta for this is 21 minutes because the last_update for 0xfakeTaskId2 is
        # 20 minutes later than the first task, and the first task ran for 1 minute.
        self.assertEqual(task_stats['requests'].max, timedelta(minutes=21))
        self.assertEqual(task_stats['tasks_per_user']['myuser'].max,
                         timedelta(minutes=5))
        self.assertEqual(task_stats['tasks_per_worker']['fake_worker'].max,
                         timedelta(minutes=3))
        self.assertEqual(task_stats['tasks_per_type']['TaskName2'].mean,
                         timedelta(minutes=5))
Exemple #2
0
 def testClientFormatTaskStatusShortReport(self, _, __, ___):
     """Tests format_task_status() has valid output with short report."""
     client = TurbiniaClient()
     client.get_task_data = mock.MagicMock()
     client.get_task_data.return_value = self.task_data
     result = client.format_task_status('inst', 'proj', 'reg')
     self.assertEqual(result.strip(), SHORT_REPORT.strip())
Exemple #3
0
 def testClientFormatTaskStatistics(self, _, __, ___):
     """Tests format_task_statistics() report output."""
     client = TurbiniaClient()
     client.get_task_data = mock.MagicMock()
     client.get_task_data.return_value = self.task_data
     stats_report = client.format_task_statistics('inst', 'proj', 'reg')
     self.maxDiff = None
     self.assertEqual(stats_report, STATISTICS_REPORT)
Exemple #4
0
 def testTurbiniaClientGetTaskData(self, _, mock_cloud_function):
   """Basic test for client.get_task_data"""
   # ExecuteFunction returns a dict with a 'result' key that has a json-encoded
   # list.
   function_return = {'result': '["bar", "baz"]'}
   mock_cloud_function.return_value = function_return
   client = TurbiniaClient()
   self.assertEqual(client.get_task_data("inst", "proj", "reg"), "bar")
Exemple #5
0
 def testClientFormatTaskStatusFiles(self, _, __, ___):
   """Tests format_task_status() has valid output with report and files."""
   client = TurbiniaClient()
   client.get_task_data = mock.MagicMock()
   client.get_task_data.return_value = self.task_data
   result = client.format_task_status(
       'inst', 'proj', 'reg', all_fields=True, full_report=True)
   self.assertEqual(result.strip(), LONG_REPORT_FILES.strip())
Exemple #6
0
 def testClientFormatTaskStatus(self, _, __, ___):
     """Tests format_task_status() with empty report_priority."""
     client = TurbiniaClient()
     client.get_task_data = mock.MagicMock()
     self.task_data[0]['report_priority'] = None
     self.task_data[1]['report_priority'] = ''
     self.task_data[2].pop('report_priority')
     client.get_task_data.return_value = self.task_data
     result = client.format_task_status('inst', 'proj', 'reg')
     self.assertIn('Processed 3 Tasks', result.strip())
Exemple #7
0
 def testTurbiniaClientGetTaskData(self, _, __, mock_cloud_function):
     """Basic test for client.get_task_data"""
     # ExecuteFunction returns a dict with a 'result' key that has a json-encoded
     # list.  This contains our task data, which is a list of dicts.
     run_time = timedelta(seconds=3)
     test_task_data = [{
         'bar': 'bar2',
         'run_time': run_time.total_seconds()
     }]
     gcf_result = [test_task_data, 'Unused GCF data']
     gcf_result = json.dumps(gcf_result)
     function_return = {'result': gcf_result}
     mock_cloud_function.return_value = function_return
     client = TurbiniaClient()
     task_data = client.get_task_data('inst', 'proj', 'reg')
     # get_task_data() converts this back into a timedelta(). We returned it
     # seconds from the GCF function call because that is what it is stored in
     # Datastore as.
     test_task_data[0]['run_time'] = run_time
     self.assertEqual(task_data, test_task_data)