def do_save_raw_crash(boto_connection, raw_crash, dumps, crash_id): if dumps is None: dumps = MemoryDumpsMapping() raw_crash_as_string = boto_connection._convert_mapping_to_string( raw_crash ) boto_connection.submit( crash_id, "raw_crash", raw_crash_as_string ) dump_names_as_string = boto_connection._convert_list_to_string( dumps.keys() ) boto_connection.submit( crash_id, "dump_names", dump_names_as_string ) # we don't know what type of dumps mapping we have. We do know, # however, that by calling the memory_dump_mapping method, we will # get a MemoryDumpMapping which is exactly what we need. dumps = dumps.as_memory_dumps_mapping() for dump_name, dump in dumps.iteritems(): if dump_name in (None, '', 'upload_file_minidump'): dump_name = 'dump' boto_connection.submit(crash_id, dump_name, dump)
def save_raw_crash(self, raw_crash, dumps, crash_id): """Save raw crash data to S3 bucket. A raw crash consists of the raw crash annotations and all the dumps that came in the crash report. We need to save the raw crash file, a dump names file listing the dumps that came in the crash report, and then each of the dumps. """ if dumps is None: dumps = MemoryDumpsMapping() path = build_keys("raw_crash", crash_id)[0] raw_crash_data = dict_to_str(raw_crash).encode("utf-8") self.conn.save_file(path, raw_crash_data) path = build_keys("dump_names", crash_id)[0] dump_names_data = list_to_str(dumps.keys()).encode("utf-8") self.conn.save_file(path, dump_names_data) # We don't know what type of dumps mapping we have. We do know, # however, that by calling the memory_dump_mapping method, we will get # a MemoryDumpMapping which is exactly what we need. dumps = dumps.as_memory_dumps_mapping() for dump_name, dump in dumps.items(): if dump_name in (None, "", "upload_file_minidump"): dump_name = "dump" path = build_keys(dump_name, crash_id)[0] self.conn.save_file(path, dump)
def test_simple(self): mdm = MemoryDumpsMapping( {"upload_file_minidump": b"binary_data", "moar_dump": b"more binary data"} ) assert mdm.as_memory_dumps_mapping() is mdm fdm = mdm.as_file_dumps_mapping("a", "/tmp", "dump") assert fdm.as_file_dumps_mapping() is fdm assert fdm.as_memory_dumps_mapping() == mdm
def test_simple(self): mdm = MemoryDumpsMapping({ 'upload_file_minidump': 'binary_data', 'moar_dump': "more binary data", }) ok_(mdm.as_memory_dumps_mapping() is mdm) fdm = mdm.as_file_dumps_mapping('a', '/tmp', 'dump') ok_(fdm.as_file_dumps_mapping() is fdm) eq_(fdm.as_memory_dumps_mapping(), mdm)
def test_simple(self): mdm = MemoryDumpsMapping({ 'upload_file_minidump': b'binary_data', 'moar_dump': b'more binary data', }) assert mdm.as_memory_dumps_mapping() is mdm fdm = mdm.as_file_dumps_mapping('a', '/tmp', 'dump') assert fdm.as_file_dumps_mapping() is fdm assert fdm.as_memory_dumps_mapping() == mdm
def save_raw_crash(self, raw_crash, dumps, crash_id): if dumps is None: dumps = MemoryDumpsMapping() files = { crash_id + self.config.json_file_suffix: json.dumps(raw_crash) } in_memory_dumps = dumps.as_memory_dumps_mapping() files.update(dict((self._get_dump_file_name(crash_id, fn), dump) for fn, dump in in_memory_dumps.iteritems())) self._save_files(crash_id, files)
def save_raw_crash(self, raw_crash, dumps, crash_id): if dumps is None: dumps = MemoryDumpsMapping() files = { crash_id + self.config.json_file_suffix: json.dumps(raw_crash) } in_memory_dumps = dumps.as_memory_dumps_mapping() files.update( dict((self._get_dump_file_name(crash_id, fn), dump) for fn, dump in in_memory_dumps.iteritems())) self._save_files(crash_id, files)
def save_raw_crash(self, raw_crash, dumps, crash_id): if dumps is None: dumps = MemoryDumpsMapping() files = { crash_id + self.config.json_file_suffix: json.dumps(raw_crash).encode('utf-8') } in_memory_dumps = dumps.as_memory_dumps_mapping() files.update({ self._get_dump_file_name(crash_id, fn): dump for fn, dump in in_memory_dumps.items() }) self._save_files(crash_id, files)
def test_simple(self): mdm = MemoryDumpsMapping({ 'upload_file_minidump': 'binary_data', 'moar_dump': "more binary data", }) ok_(mdm.as_memory_dumps_mapping() is mdm) fdm = mdm.as_file_dumps_mapping( 'a', '/tmp', 'dump' ) ok_(fdm.as_file_dumps_mapping() is fdm) eq_(fdm.as_memory_dumps_mapping(), mdm)
def test_simple(self): mdm = MemoryDumpsMapping({ 'upload_file_minidump': 'binary_data', 'moar_dump': "more binary data", }) assert mdm.as_memory_dumps_mapping() is mdm fdm = mdm.as_file_dumps_mapping( 'a', '/tmp', 'dump' ) assert fdm.as_file_dumps_mapping() is fdm assert fdm.as_memory_dumps_mapping() == mdm
def test_save_raw_crash_no_dumps(self, boto_helper): boto_s3_store = self.get_s3_store() bucket = boto_s3_store.conn.bucket boto_helper.create_bucket(bucket) # Run save_raw_crash boto_s3_store.save_raw_crash( {"submitted_timestamp": "2013-01-09T22:21:18.646733+00:00"}, # This is an empty set of dumps--no dumps! MemoryDumpsMapping(), "0bba929f-8721-460c-dead-a43c20071027", ) # Verify the raw_crash made it to the right place and has the right # contents raw_crash = boto_helper.download_fileobj( bucket_name=bucket, key= "v2/raw_crash/0bb/20071027/0bba929f-8721-460c-dead-a43c20071027", ) assert json.loads(raw_crash) == { "submitted_timestamp": "2013-01-09T22:21:18.646733+00:00" } # Verify dump_names made it to the right place and has the right # contents dump_names = boto_helper.download_fileobj( bucket_name=bucket, key="v1/dump_names/0bba929f-8721-460c-dead-a43c20071027", ) assert json.loads(dump_names) == []
def test_save_raw_crash_hang(self): self.storage.save_raw_crash({ "submitted_timestamp": "2013-01-09T22:21:18.646733+00:00", "HangID": "?" }, MemoryDumpsMapping(), "0bba929f-8721-460c-dead-a43c20071027") with self.storage.hbase() as conn: eq_(conn.client.mutateRow.call_count, 7)
def test_save_raw_crash_no_dumps_existing_bucket(self, boto_helper): boto_s3_store = setup_mocked_s3_storage() # Create the bucket boto_helper.get_or_create_bucket('crash_storage') # Run save_raw_crash boto_s3_store.save_raw_crash( {"submitted_timestamp": "2013-01-09T22:21:18.646733+00:00"}, # This is an empty set of dumps--no dumps! MemoryDumpsMapping(), "0bba929f-8721-460c-dead-a43c20071027") # Verify the raw_crash made it to the right place and has the right # contents raw_crash = boto_helper.get_contents_as_string( bucket_name='crash_storage', key='dev/v1/raw_crash/0bba929f-8721-460c-dead-a43c20071027') assert (json.loads(raw_crash) == { "submitted_timestamp": "2013-01-09T22:21:18.646733+00:00" }) # Verify dump_names made it to the right place and has the right # contents dump_names = boto_helper.get_contents_as_string( bucket_name='crash_storage', key='dev/v1/dump_names/0bba929f-8721-460c-dead-a43c20071027') assert json.loads(dump_names) == []
def test_save_raw_crash(self): self.storage.save_raw_crash({ "submitted_timestamp": "2013-01-09T22:21:18.646733+00:00" }, MemoryDumpsMapping(), "0bba929f-8721-460c-dead-a43c20071027") with self.storage.hbase() as conn: self.assertEqual(conn.table.call_count, 1) self.assertEqual(conn.table.return_value.put.call_count, 1)
def test_save_raw_crash(self): raw_crash = { "submitted_timestamp": "2013-01-09T22:21:18.646733+00:00", "HangID": "?", "Product": "FireSquid", "Version": "-33", } dumps = MemoryDumpsMapping({ 'upload_file_minidump': 'dump #1', 'browser': 'dump #2' }) crash_id = "0bba929f-8721-460c-dead-a43c20071027" with patch("socorro.external.http.crashstorage.poster") as m_poster: with patch( "socorro.external.http.crashstorage.urllib2") as m_urllib: m_poster.encode.multipart_encode.return_value = (1, 2) m_urllib.Request.return_value = 23 self.storage.save_raw_crash(raw_crash, dumps, crash_id) eq_(m_poster.encode.MultipartParam.call_count, 2) m_poster.encode.multipart_encode.assert_called_once_with( raw_crash) m_urllib.Request.assert_called_once_with( self.storage.config.url, 1, 2) m_urllib.urlopen.assert_called_once_with(23)
def test_save_raw_crash_with_timeouts_to_falure(self): self.setUpForTimeout() raw_crash = { "submitted_timestamp": "2013-01-09T22:21:18.646733+00:00", "HangID": "?", "Product": "FireSquid", "Version": "-33", } dumps = MemoryDumpsMapping({ 'upload_file_minidump': 'dump #1', 'browser': 'dump #2' }) crash_id = "0bba929f-8721-460c-dead-a43c20071027" with patch("socorro.external.http.crashstorage.poster") as m_poster: with patch( "socorro.external.http.crashstorage.urllib2") as m_urllib: m_poster.encode.multipart_encode.return_value = (1, 2) m_urllib.Request.return_value = 23 m_urllib.urlopen.side_effect = socket.timeout assert_raises( socket.timeout, self.storage.save_raw_crash, raw_crash, dumps, crash_id, ) eq_(m_poster.encode.MultipartParam.call_count, 4) eq_(m_urllib.Request.call_count, 2) eq_(m_urllib.urlopen.call_count, 2)
def test_save_raw_crash(self): config = self.get_standard_config() db_sampling = DBCrashStorageWrapperNewCrashSource(config) crash_id = '86b58ff2-9708-487d-bfc4-9dac32121214' fake_raw_crash = SocorroDotDict({ "name": "Gabi", "submitted_timestamp": "2012-12-14T00:00:00" }) fake_dumps = MemoryDumpsMapping({ 'upload_file_minidump': '86b58ff2-9708-487d-bfc4-9dac32121214' '.upload_file_minidump.TEMPORARY.dump' }) # the call to be tested db_sampling.save_raw_crash( fake_raw_crash, fake_dumps, crash_id ) # this is what should have happened db_sampling._implementation.save_raw_crash.assert_called_once_with( fake_raw_crash, fake_dumps, crash_id )
def _make_test_crash(self, crash_id=CRASH_ID_1): self.fsrts.save_raw_crash({ "test": "TEST" }, MemoryDumpsMapping({ 'foo': 'bar', self.fsrts.config.dump_field: 'baz' }), crash_id)
def test_save_raw_crash_2(self): boto_s3_store = self.setup_mocked_s3_storage() # the tested call boto_s3_store.save_raw_crash( {"submitted_timestamp": "2013-01-09T22:21:18.646733+00:00"}, MemoryDumpsMapping( {'dump': 'fake dump', 'flash_dump': 'fake flash dump'} ), "0bba929f-8721-460c-dead-a43c20071027" ) # what should have happened internally assert boto_s3_store.connection_source._calling_format.call_count == 1 boto_s3_store.connection_source._calling_format.assert_called_with() assert boto_s3_store.connection_source._connect_to_endpoint.call_count == 1 self.assert_s3_connection_parameters(boto_s3_store) get_bucket = ( boto_s3_store.connection_source._mocked_connection.get_bucket ) assert get_bucket.call_count == 1 get_bucket.assert_called_with('crash_storage') bucket_mock = get_bucket.return_value assert bucket_mock.new_key.call_count == 4 bucket_mock.new_key.assert_has_calls( [ mock.call( 'dev/v1/raw_crash/0bba929f-8721-460c-dead-a43c20071027' ), mock.call( 'dev/v1/dump_names/0bba929f-8721-460c-dead-a43c20071027' ), mock.call( 'dev/v1/dump/0bba929f-8721-460c-dead-a43c20071027' ), mock.call( 'dev/v1/flash_dump/0bba929f-8721-460c-dead-a43c20071027' ), ], any_order=True, ) storage_key_mock = bucket_mock.new_key.return_value assert storage_key_mock.set_contents_from_string.call_count == 4 storage_key_mock.set_contents_from_string.assert_has_calls( [ mock.call( '{"submitted_timestamp": ' '"2013-01-09T22:21:18.646733+00:00"}' ), mock.call('["flash_dump", "dump"]'), mock.call('fake dump'), mock.call('fake flash dump'), ], any_order=True, )
def _make_test_crash(self, crash_id=CRASH_ID_1): self.fsrts.save_raw_crash( raw_crash={"test": "TEST"}, dumps=MemoryDumpsMapping( {"foo": b"bar", self.fsrts.config.dump_field: b"baz"} ), crash_id=crash_id, )
def _make_test_crash(self, crash_id=CRASH_ID_1): self.fsrts.save_raw_crash(raw_crash={'test': 'TEST'}, dumps=MemoryDumpsMapping({ 'foo': b'bar', self.fsrts.config.dump_field: b'baz' }), crash_id=crash_id)
def test_get_raw_dumps(self): self._make_test_crash() expected = MemoryDumpsMapping({ 'foo': 'bar', self.fsrts.config.dump_field: 'baz' }) assert self.fsrts.get_raw_dumps(self.CRASH_ID_1) == expected with pytest.raises(CrashIDNotFound): self.fsrts.get_raw_dumps(self.CRASH_ID_2)
def do_save_raw_crash(boto_connection, raw_crash, dumps, crash_id): if dumps is None: dumps = MemoryDumpsMapping() raw_crash_data = boto_connection._convert_mapping_to_string(raw_crash).encode('utf-8') boto_connection.submit(crash_id, 'raw_crash', raw_crash_data) dump_names_data = boto_connection._convert_list_to_string(dumps.keys()).encode('utf-8') boto_connection.submit(crash_id, 'dump_names', dump_names_data) # We don't know what type of dumps mapping we have. We do know, # however, that by calling the memory_dump_mapping method, we will get # a MemoryDumpMapping which is exactly what we need. dumps = dumps.as_memory_dumps_mapping() for dump_name, dump in iteritems(dumps): if dump_name in (None, '', 'upload_file_minidump'): dump_name = 'dump' boto_connection.submit(crash_id, dump_name, dump)
def do_get(connection, row_id): try: crash_report_table = connection.table('crash_reports') dumps = crash_report_table.row(row_id, columns=['raw_data']) # ensure that we return a proper mapping of names to # binary blobs. return MemoryDumpsMapping( (self._make_dump_name(k), v) for k, v in dumps.iteritems()) except KeyError: raise CrashIDNotFound(crash_id)
def test_get_raw_dumps(self): self._make_test_crash() eq_( self.fsrts.get_raw_dumps(self.CRASH_ID_1), MemoryDumpsMapping({ 'foo': 'bar', self.fsrts.config.dump_field: 'baz' })) assert_raises(CrashIDNotFound, self.fsrts.get_raw_dumps, self.CRASH_ID_2)
def _make_test_crash(self): self.fsrts.save_raw_crash( { # raw crash "test": "TEST" }, MemoryDumpsMapping({ # dumps 'foo': 'bar', self.fsrts.config.dump_field: 'baz' }), self.CRASH_ID_1)
def do_save_raw_crash(boto_connection, raw_crash, dumps, crash_id): if dumps is None: dumps = MemoryDumpsMapping() raw_crash_data = boto_connection._convert_mapping_to_string( raw_crash).encode('utf-8') boto_connection.submit(crash_id, 'raw_crash', raw_crash_data) dump_names_data = boto_connection._convert_list_to_string( dumps.keys()).encode('utf-8') boto_connection.submit(crash_id, 'dump_names', dump_names_data) # We don't know what type of dumps mapping we have. We do know, # however, that by calling the memory_dump_mapping method, we will get # a MemoryDumpMapping which is exactly what we need. dumps = dumps.as_memory_dumps_mapping() for dump_name, dump in iteritems(dumps): if dump_name in (None, '', 'upload_file_minidump'): dump_name = 'dump' boto_connection.submit(crash_id, dump_name, dump)
def do_save_raw_crash(conn, raw_crash, dumps, crash_id): if dumps is None: dumps = MemoryDumpsMapping() raw_crash_data = conn._convert_mapping_to_string(raw_crash).encode( "utf-8") conn.submit(crash_id, "raw_crash", raw_crash_data) dump_names_data = conn._convert_list_to_string( dumps.keys()).encode("utf-8") conn.submit(crash_id, "dump_names", dump_names_data) # We don't know what type of dumps mapping we have. We do know, # however, that by calling the memory_dump_mapping method, we will get # a MemoryDumpMapping which is exactly what we need. dumps = dumps.as_memory_dumps_mapping() for dump_name, dump in iteritems(dumps): if dump_name in (None, "", "upload_file_minidump"): dump_name = "dump" conn.submit(crash_id, dump_name, dump)
def test_make_sure_old_style_date_directories_are_traversed(self): with self._secondary_config_setup().context() as config: self.fsrts_old = FSLegacyDatedRadixTreeStorage(config) self.fsrts_old._current_slot = lambda: ['00', '00_00'] # save crash 1 in old system self.fsrts_old.save_raw_crash({"test": "TEST"}, MemoryDumpsMapping({ 'foo': 'bar', self.fsrts.config.dump_field: 'baz' }), self.CRASH_ID_1) ok_( os.path.exists( FS_ROOT + '/20071025/date/00/00_00/0bba929f-8721-460c-dead-a43c20071025') ) self.fsrts._current_slot = lambda: ['00', '00_00'] #save crash 3 in new system self._make_test_crash_3() ok_( os.path.exists( FS_ROOT + '/25/date/00/00_00/0bba929f-8721-460c-dddd-a43c20071025')) # consume crashes for x in self.fsrts.new_crashes(): pass # should be consumed because it isn't in our working tree or slot ok_(not os.path.exists( FS_ROOT + '/20071025/date/00/00_00/0bba929f-8721-460c-dead-a43c20071025')) # should not be consumed, while in working tree, it is in active slot ok_( os.path.exists( FS_ROOT + '/25/date/00/00_00/0bba929f-8721-460c-dddd-a43c20071025')) # switch to next active slot self.fsrts._current_slot = lambda: ['00', '00_01'] # consume crashes for x in self.fsrts.new_crashes(): pass # should be consumed because it is in working tree and inactive slot ok_(not os.path.exists( FS_ROOT + '/25/date/00/00_00/0bba929f-8721-460c-dddd-a43c20071025'))
def do_get_raw_dumps(conn, crash_id): try: dump_names_as_string = conn.fetch(crash_id, "dump_names") dump_names = conn._convert_string_to_list(dump_names_as_string) dumps = MemoryDumpsMapping() for dump_name in dump_names: if dump_name in (None, "", "upload_file_minidump"): dump_name = "dump" dumps[dump_name] = conn.fetch(crash_id, dump_name) return dumps except conn.ResponseError as x: raise CrashIDNotFound("%s not found: %s" % (crash_id, x))
def do_get_raw_dumps(boto_connection, crash_id): try: dump_names_as_string = boto_connection.fetch( crash_id, 'dump_names') dump_names = boto_connection._convert_string_to_list( dump_names_as_string) dumps = MemoryDumpsMapping() for dump_name in dump_names: if dump_name in (None, '', 'upload_file_minidump'): dump_name = 'dump' dumps[dump_name] = boto_connection.fetch(crash_id, dump_name) return dumps except boto_connection.ResponseError as x: raise CrashIDNotFound('%s not found: %s' % (crash_id, x))
def do_get_raw_dumps(boto_connection, crash_id): try: dump_names_as_string = boto_connection.fetch( crash_id, "dump_names") dump_names = boto_connection._convert_string_to_list( dump_names_as_string) # when we fetch the dumps, they are by default in memory, so we'll # put them into a MemoryDumpMapping. dumps = MemoryDumpsMapping() for dump_name in dump_names: if dump_name in (None, '', 'upload_file_minidump'): dump_name = 'dump' dumps[dump_name] = boto_connection.fetch(crash_id, dump_name) return dumps except boto_connection.ResponseError, x: raise CrashIDNotFound('%s not found: %s' % (crash_id, x))
def test_save_raw_crash_1(self): boto_s3_store = self.setup_mocked_s3_storage() # the tested call boto_s3_store.save_raw_crash( {"submitted_timestamp": "2013-01-09T22:21:18.646733+00:00"}, MemoryDumpsMapping(), "0bba929f-8721-460c-dead-a43c20071027") # what should have happened internally self.assertEqual( boto_s3_store.connection_source._calling_format.call_count, 1) boto_s3_store.connection_source._calling_format.assert_called_with() self.assertEqual( boto_s3_store.connection_source._connect_to_endpoint.call_count, 1) self.assert_s3_connection_parameters(boto_s3_store) self.assertEqual( boto_s3_store.connection_source._mocked_connection.get_bucket. call_count, 1) boto_s3_store.connection_source._mocked_connection.get_bucket.assert_called_with( 'crash_storage') bucket_mock = boto_s3_store.connection_source._mocked_connection.get_bucket \ .return_value self.assertEqual(bucket_mock.new_key.call_count, 2) bucket_mock.new_key.assert_has_calls( [ mock.call( 'dev/v1/raw_crash/0bba929f-8721-460c-dead-a43c20071027'), mock.call( 'dev/v1/dump_names/0bba929f-8721-460c-dead-a43c20071027'), ], any_order=True, ) storage_key_mock = bucket_mock.new_key.return_value self.assertEqual(storage_key_mock.set_contents_from_string.call_count, 2) storage_key_mock.set_contents_from_string.assert_has_calls( [ mock.call('{"submitted_timestamp": ' '"2013-01-09T22:21:18.646733+00:00"}'), mock.call('[]'), ], any_order=True, )
def test_save_raw_crash_with_dumps(self, boto_helper): boto_s3_store = self.get_s3_store() bucket = boto_s3_store.conn.bucket boto_helper.create_bucket(bucket) # Run save_raw_crash boto_s3_store.save_raw_crash( {"submitted_timestamp": "2013-01-09T22:21:18.646733+00:00"}, MemoryDumpsMapping({ "dump": b"fake dump", "flash_dump": b"fake flash dump" }), "0bba929f-8721-460c-dead-a43c20071027", ) # Verify the raw_crash made it to the right place and has the right contents raw_crash = boto_helper.download_fileobj( bucket_name=bucket, key= "v2/raw_crash/0bb/20071027/0bba929f-8721-460c-dead-a43c20071027", ) assert json.loads(raw_crash) == { "submitted_timestamp": "2013-01-09T22:21:18.646733+00:00" } # Verify dump_names made it to the right place and has the right # contents dump_names = boto_helper.download_fileobj( bucket_name=bucket, key="v1/dump_names/0bba929f-8721-460c-dead-a43c20071027", ) assert sorted(json.loads(dump_names)) == ["dump", "flash_dump"] # Verify dumps dump = boto_helper.download_fileobj( bucket_name=bucket, key="v1/dump/0bba929f-8721-460c-dead-a43c20071027", ) assert dump == b"fake dump" flash_dump = boto_helper.download_fileobj( bucket_name=bucket, key="v1/flash_dump/0bba929f-8721-460c-dead-a43c20071027", ) assert flash_dump == b"fake flash dump"