def test_rpe_from_stackdriver_data(filename, expected_resource_type, expected_operation_type, expected_resource_name): log_message = get_test_data(filename) assets = StackdriverParser._extract_asset_info(log_message) asset_info = assets[0] GoogleAPIResource.from_resource_data(client_kwargs=test_google_args, **asset_info)
def test_single_asset_log_messages(filename, expected_resource_type, expected_operation_type, expected_resource_name): log_message = get_test_data(filename) assets = StackdriverParser._extract_asset_info(log_message) assert len(assets) == 1 asset_info = assets[0] assert asset_info['resource_type'] == expected_resource_type #assert asset_info['operation_type'] == expected_operation_type assert asset_info['name'] == expected_resource_name
def test_compute_instance_logs_get_disk_names(filename, expected_disk_names): ''' Instance creation audit logs contain details about the disks, but extracting the disk name is complicated. This tests multiple known log formats for instance creation against expected disk names. ''' log = get_test_data(filename) assets = StackdriverParser._extract_asset_info(log) disk_names = [asset['name'] for asset in assets if asset['resource_type'] == GcpComputeDisk.resource_type] assert sorted(disk_names) == sorted(expected_disk_names)
def test_log_resource_count(filename, expected_resource_count): log_message = get_test_data(filename) assets = StackdriverParser._extract_asset_info(log_message) assert len(assets) == expected_resource_count asset_info = assets[0]