def test_send_build_event_smoke(self): args = send_event.get_arguments([ '--event-mon-service-name', 'thing', '--build-event-type', 'SCHEDULER', '--build-event-hostname', 'foo.bar.dns', '--build-event-build-name', 'whatever' ]) send_event.send_build_event(args)
def test_send_build_event_with_goma_error_crashed(self): with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--build-event-type', 'BUILD', '--build-event-hostname', 'foo.bar.dns', '--build-event-build-name', 'whatever', '--build-event-goma-error', 'GOMA_ERROR_CRASHED', '--build-event-goma-crash-report-id-path', os.path.join(DATA_DIR, 'goma_error_report.txt')]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) self.assertTrue(send_event.send_build_event(args)) # Now open the resulting file and check what was written with open(outfile, 'rb') as f: request = LogRequestLite.FromString(f.read()) self.assertEqual(len(request.log_event), 1) event = ChromeInfraEvent.FromString(request.log_event[0].source_extension) self.assertEqual(event.build_event.goma_error, BuildEvent.GOMA_ERROR_CRASHED) self.assertEqual(event.build_event.goma_crash_report_id, '0123456789abcdef0') self.assertEqual(event.build_event.host_name, 'foo.bar.dns')
def test_send_build_event_with_goma_stats(self): # Write a file to avoid mocks with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--build-event-type', 'BUILD', '--build-event-hostname', 'foo.bar.dns', '--build-event-build-name', 'whatever', '--build-event-goma-stats-path', os.path.join(DATA_DIR, 'goma_stats.bin')]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) self.assertTrue(send_event.send_build_event(args)) # Now open the resulting file and check what was written with open(outfile, 'rb') as f: request = LogRequestLite.FromString(f.read()) self.assertEqual(len(request.log_event), 1) event = ChromeInfraEvent.FromString(request.log_event[0].source_extension) self.assertEqual(event.build_event.goma_stats.request_stats.total, 10) self.assertEqual(event.build_event.goma_stats.request_stats.success, 9) self.assertEqual(event.build_event.goma_stats.request_stats.failure, 1) self.assertEqual(event.build_event.host_name, 'foo.bar.dns')
def test_logrequest_path_service_type_override(self): with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--event-logrequest-path', os.path.join(DATA_DIR, 'service-bar-service.bin'), '--service-event-type', 'STOP', ]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) send_event._process_logrequest_path(args) self.assertTrue(send_event.send_service_event(args)) # Now open the resulting file and check what was written with open(outfile, 'rb') as f: request = LogRequestLite.FromString(f.read()) self.assertEqual(len(request.log_event), 1) event = ChromeInfraEvent.FromString(request.log_event[0].source_extension) self.assertEqual(event.event_source.host_name, 'myhostname') self.assertEqual(event.service_event.type, ServiceEvent.STOP) self.assertEqual(event.timestamp_kind, ChromeInfraEvent.END)
def test_send_build_event_smoke(self): args = send_event.get_arguments( ['--event-mon-service-name', 'thing', '--build-event-type', 'SCHEDULER', '--build-event-hostname', 'foo.bar.dns', '--build-event-build-name', 'whatever']) self.assertTrue(send_event.send_build_event(args))
def test_send_service_event_revinfo_smoke(self): args = send_event.get_arguments([ '--event-mon-service-name', 'thing', '--service-event-type', 'START', '--service-event-revinfo', os.path.join(DATA_DIR, 'revinfo.txt') ]) send_event.send_service_event(args)
def test_logrequest_path_build_type_override(self): # logrequest contains build event, overrid the type with an arg. with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--event-logrequest-path', os.path.join(DATA_DIR, 'build-foo-builder.bin'), '--build-event-build-number', '3', '--build-event-type', 'STEP', ]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) send_event._process_logrequest_path(args) self.assertTrue(send_event.send_build_event(args)) # Now open the resulting file and check what was written with open(outfile, 'rb') as f: request = LogRequestLite.FromString(f.read()) self.assertEqual(len(request.log_event), 1) event = ChromeInfraEvent.FromString(request.log_event[0].source_extension) self.assertEqual(event.build_event.host_name, 'myhostname') self.assertEqual(event.build_event.type, BuildEvent.STEP) self.assertEqual(event.build_event.build_number, 3) self.assertEqual(event.timestamp_kind, ChromeInfraEvent.BEGIN)
def test_send_build_event_smoke_missing_goma_file(self): args = send_event.get_arguments( ['--event-mon-service-name', 'thing', '--build-event-type', 'BUILD', '--build-event-hostname', 'foo.bar.dns', '--build-event-build-name', 'whatever', '--build-event-goma-stats-path', os.path.join(DATA_DIR, 'this-file-does-not-exist')]) with self.assertRaises(IOError): send_event.send_build_event(args)
def test_logrequest_path_service_build_conflict(self): with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--event-logrequest-path', os.path.join(DATA_DIR, 'service-bar-service.bin'), '--build-event-type', 'BUILD', ]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) with self.assertRaises(ValueError): send_event._process_logrequest_path(args)
def test_logrequest_path_service_build_and_service(self): # The logrequest provided contains both a service and a build type, # which is invalid. with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--event-logrequest-path', os.path.join(DATA_DIR, 'build-and-service-event.bin'), ]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) with self.assertRaises(ValueError): send_event._process_logrequest_path(args)
def test_send_build_event_with_invalid_goma_stats(self): # Write a file to avoid mocks with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--build-event-type', 'BUILD', '--build-event-hostname', 'foo.bar.dns', '--build-event-build-name', 'whatever', '--build-event-goma-stats-path', os.path.join(DATA_DIR, 'garbage')]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) with self.assertRaises(google.protobuf.message.DecodeError): send_event.send_build_event(args)
def test_logrequest_path_build_service_conflicts(self): # logrequest contains build event, provides service event as arg with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--event-logrequest-path', os.path.join(DATA_DIR, 'build-foo-builder.bin'), '--build-event-build-number', '3', '--service-event-type', 'START', ]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) with self.assertRaises(ValueError): send_event._process_logrequest_path(args)
def test_send_build_event_with_non_existing_goma_error_report(self): # Write a file to avoid mocks with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir: outfile = os.path.join(tmpdir, 'out.bin') args = send_event.get_arguments( ['--event-mon-run-type', 'file', '--event-mon-output-file', outfile, '--event-mon-service-name', 'thing', '--build-event-type', 'BUILD', '--build-event-hostname', 'foo.bar.dns', '--build-event-build-name', 'whatever', '--build-event-goma-error', 'GOMA_ERROR_CRASHED', '--build-event-goma-crash-report-id-path', os.path.join(DATA_DIR, 'this-file-does-not-exist')]) self.assertEquals(args.event_mon_run_type, 'file') event_mon.process_argparse_options(args) with self.assertRaises(IOError): send_event.send_build_event(args)
def test_send_events_from_file_delete_file_smoke(self): # Create a temporary file because we don't want to risk deleting a # checked-in file. with infra_libs.temporary_directory(prefix='send-events-test-') as tempdir: event_file = os.path.join(tempdir, 'events.log') with open(event_file, 'w') as f: f.write('{"build-event-type": "STEP", ' '"build-event-build-name": "infra-continuous-precise-64", ' '"event-mon-service-name": "buildbot/master/chromium.infra", ' '"build-event-step-number": 9, ' '"build-event-build-number": 5, ' '"event-mon-timestamp-kind": "END", ' '"build-event-step-name": "cipd - test packages integrity", ' '"build-event-build-scheduling-time": 1434665160000, ' '"build-event-hostname": "vm25-m1"}\n') self.assertTrue(os.path.isfile(event_file)) args = send_event.get_arguments(['--events-from-file', event_file, '--delete-file-when-sent']) send_event.send_events_from_file(args) self.assertFalse(os.path.isfile(event_file))
def main(argv): # pragma: no cover # Does nothing when no arguments are passed, to make it safe to import this # module (main() is executed on import, because this file is called __main__). status = 0 if len(argv) == 0: return status success_metric = ts_mon.BooleanMetric('send_monitoring_event/success') try: args = send_event.get_arguments(argv) send_event.process_argparse_options(args) if args.build_event_type: success_metric.set(send_event.send_build_event(args)) elif args.service_event_type: success_metric.set(send_event.send_service_event(args)) elif args.events_from_file: success_metric.set(send_event.send_events_from_file(args)) else: print >> sys.stderr, ( 'At least one of the --*-event-type options or ' '--events-from-file should be provided. Nothing ' 'was sent.') status = 2 success_metric.set(False) except Exception: success_metric.set(False) finally: event_mon.close() try: ts_mon.flush() except ts_mon.MonitoringNoConfiguredMonitorError: pass return status
def test_send_events_from_file_smoke(self): # Create a temporary file because we don't want to risk deleting a # checked-in file. with infra_libs.temporary_directory( prefix='send-events-test') as tempdir: event_file = os.path.join(tempdir, 'events.log') with open(event_file, 'w') as f: f.write( '{"build-event-type": "STEP", ' '"build-event-build-name": "infra-continuous-precise-64", ' '"event-mon-service-name": "buildbot/master/chromium.infra", ' '"build-event-step-number": 9, ' '"build-event-build-number": 5, ' '"event-mon-timestamp-kind": "END", ' '"build-event-step-name": "cipd - test packages integrity", ' '"build-event-build-scheduling-time": 1434665160000, ' '"build-event-hostname": "vm25-m1"}\n') self.assertTrue(os.path.isfile(event_file)) args = send_event.get_arguments(['--events-from-file', event_file]) send_event.send_events_from_file(args) self.assertTrue(os.path.isfile(event_file))
def main(argv): # pragma: no cover # Does nothing when no arguments are passed, to make it safe to import this # module (main() is executed on import, because this file is called __main__). status = 0 if len(argv) == 0: return status success_metric = ts_mon.BooleanMetric('send_monitoring_event/success') try: args = send_event.get_arguments(argv) send_event.process_argparse_options(args) if args.build_event_type: success_metric.set(send_event.send_build_event(args)) elif args.service_event_type: success_metric.set(send_event.send_service_event(args)) elif args.events_from_file: success_metric.set(send_event.send_events_from_file(args)) else: print >> sys.stderr, ('At least one of the --*-event-type options or ' '--events-from-file should be provided. Nothing ' 'was sent.') status = 2 success_metric.set(False) except Exception: success_metric.set(False) finally: event_mon.close() try: ts_mon.flush() except ts_mon.MonitoringNoConfiguredMonitorError: pass return status
def main(argv): # pragma: no cover # Does nothing when no arguments are passed, to make it safe to import this # module (main() is executed on import, because this file is called __main__). status = 0 if len(argv) == 0: return status try: args = send_event.get_arguments(argv) send_event.process_argparse_options(args) if args.build_event_type: success_metric.set(send_event.send_build_event(args)) elif args.service_event_type: success_metric.set(send_event.send_service_event(args)) elif args.events_from_file: success_metric.set(send_event.send_events_from_file(args)) else: print >> sys.stderr, ('At least one of the --*-event-type options or ' '--events-from-file should be provided. Nothing ' 'was sent.') status = 2 success_metric.set(False) except Exception: success_metric.set(False) traceback.print_exc() # helps with debugging locally. finally: event_mon.close() try: ts_mon.flush() except ts_mon.MonitoringNoConfiguredMonitorError: logging.error("Unable to flush ts_mon because it's not configured.") except Exception: logging.exception("Flushing ts_mon metrics failed.") return status
def test_smoke(self): args = send_event.get_arguments(['--event-mon-service-name', 'thing']) self.assertIsInstance(args, argparse.Namespace) self.assertEquals(args.event_mon_service_name, 'thing')
def test_both_from_file_and_build(self): with self.assertRaises(SystemExit): send_event.get_arguments([ '--build-event-type', 'BUILD', '--events-from-file', 'filename' ])
def test_both_build_and_service_flags(self): with self.assertRaises(SystemExit): send_event.get_arguments([ '--build-event-type', 'BUILD', '--service-event-type', 'START' ])
def test_send_service_event_stack_trace_smoke(self): args = send_event.get_arguments( ['--event-mon-service-name', 'thing', '--service-event-stack-trace', 'stack trace']) send_event.send_service_event(args)
def test_send_service_event_revinfo_smoke(self): args = send_event.get_arguments( ['--event-mon-service-name', 'thing', '--service-event-type', 'START', '--service-event-revinfo', os.path.join(DATA_DIR, 'revinfo.txt')]) send_event.send_service_event(args)
def test_extra_result_code_strings_list(self): args = send_event.get_arguments( ['--service-event-type', 'START', '--build-event-extra-result-code', 'code1,code2,code3']) self.assertEquals(args.build_event_extra_result_code, ['code1', 'code2', 'code3'])
def test_extra_result_code_json(self): args = send_event.get_arguments( ['--service-event-type', 'START', '--build-event-extra-result-code', '["code4", "code5","code6"]']) self.assertEquals(args.build_event_extra_result_code, ['code4', 'code5', 'code6'])
def test_both_from_file_and_service(self): with self.assertRaises(SystemExit): send_event.get_arguments( ['--service-event-type', 'START', '--events-from-file', 'filename'])
def test_extra_result_code_string(self): args = send_event.get_arguments( ['--service-event-type', 'START', '--build-event-extra-result-code', 'test-string']) self.assertEquals(args.build_event_extra_result_code, 'test-string')
def test_both_from_file_and_service(self): with self.assertRaises(SystemExit): send_event.get_arguments([ '--service-event-type', 'START', '--events-from-file', 'filename' ])
def test_both_from_file_and_build(self): with self.assertRaises(SystemExit): send_event.get_arguments( ['--build-event-type', 'BUILD', '--events-from-file', 'filename'])
def test_send_service_event_stack_trace_smoke(self): args = send_event.get_arguments([ '--event-mon-service-name', 'thing', '--service-event-stack-trace', 'stack trace' ]) send_event.send_service_event(args)
def test_smoke(self): args = send_event.get_arguments(['--event-mon-service-name', 'thing']) self.assertIsInstance(args, argparse.Namespace) self.assertEquals(args.event_mon_service_name, 'thing')
def test_both_build_and_service_flags(self): with self.assertRaises(SystemExit): send_event.get_arguments( ['--build-event-type', 'BUILD', '--service-event-type', 'START'])