11# -*- coding: utf-8 -*-
22import boto3
3+ import tempfile
34import time
45import pytest
56import logging
@@ -84,6 +85,15 @@ def setup_s3():
8485
8586 return s3_endpoint , s3_access_key , s3_secret_key , s3_bucket
8687
88+ def _execute_command_and_get_result (self , command ):
89+ with tempfile .NamedTemporaryFile (mode = 'w+' , delete = True ) as temp_file :
90+ yatest .common .execute (command , wait = True , stdout = temp_file , stderr = temp_file )
91+ temp_file .flush ()
92+ temp_file .seek (0 )
93+ result = json .load (temp_file )
94+ self .output_f .write (str (result ) + "\n " )
95+ return result
96+
8797 def change_cluster_version (self , new_binary_paths ):
8898 binary_path_before = self .config .get_binary_paths ()
8999 versions_on_before = self .get_nodes_version ()
@@ -341,28 +351,26 @@ def test_tpch1(self, store_type):
341351 def test_export (self ):
342352 s3_endpoint , s3_access_key , s3_secret_key , s3_bucket = self .s3_config
343353
344- session = ydb .retry_operation_sync (lambda : self .driver .table_client .session ().create ())
345-
346- for table_num in range (1 , 6 ):
347- table_name = f"sample_table_{ table_num } "
348-
349- session .execute_scheme (
350- f"create table `{ table_name } ` (id Uint64, payload Utf8, PRIMARY KEY(id));"
351- )
354+ with ydb .SessionPool (self .driver , size = 1 ) as pool :
355+ with pool .checkout () as session :
356+ for table_num in range (1 , 6 ):
357+ table_name = f"sample_table_{ table_num } "
358+ session .execute_scheme (
359+ f"create table `{ table_name } ` (id Uint64, payload Utf8, PRIMARY KEY(id));"
360+ )
352361
353- query = f"""INSERT INTO `{ table_name } ` (id, payload) VALUES
354- (1, 'Payload 1 for table { table_num } '),
355- (2, 'Payload 2 for table { table_num } '),
356- (3, 'Payload 3 for table { table_num } '),
357- (4, 'Payload 4 for table { table_num } '),
358- (5, 'Payload 5 for table { table_num } ');"""
359- session .transaction ().execute (
360- query , commit_tx = True
361- )
362+ query = f"""INSERT INTO `{ table_name } ` (id, payload) VALUES
363+ (1, 'Payload 1 for table { table_num } '),
364+ (2, 'Payload 2 for table { table_num } '),
365+ (3, 'Payload 3 for table { table_num } '),
366+ (4, 'Payload 4 for table { table_num } '),
367+ (5, 'Payload 5 for table { table_num } ');"""
368+ session .transaction ().execute (
369+ query , commit_tx = True
370+ )
362371
363372 export_command = [
364373 yatest .common .binary_path (os .getenv ("YDB_CLI_BINARY" )),
365- "--verbose" ,
366374 "--endpoint" ,
367375 "grpc://localhost:%d" % self .cluster .nodes [1 ].grpc_port ,
368376 "--database=/Root" ,
@@ -377,7 +385,48 @@ def test_export(self):
377385 "--secret-key" ,
378386 s3_secret_key ,
379387 "--item" ,
380- "src=/Root,dst=Root"
388+ "src=/Root,dst=." ,
389+ "--format" ,
390+ "proto-json-base64"
391+ ]
392+
393+ result_export = self ._execute_command_and_get_result (export_command )
394+
395+ export_id = result_export ["id" ]
396+ status_export = result_export ["status" ]
397+ progress_export = result_export ["metadata" ]["progress" ]
398+
399+ assert status_export == "SUCCESS"
400+ assert progress_export in ["PROGRESS_PREPARING" , "PROGRESS_DONE" ]
401+
402+ operation_get_command = [
403+ yatest .common .binary_path (os .getenv ("YDB_CLI_BINARY" )),
404+ "--endpoint" ,
405+ "grpc://localhost:%d" % self .cluster .nodes [1 ].grpc_port ,
406+ "--database=/Root" ,
407+ "operation" ,
408+ "get" ,
409+ "%s" % export_id ,
410+ "--format" ,
411+ "proto-json-base64"
381412 ]
382413
383- yatest .common .execute (export_command , wait = True , stdout = self .output_f , stderr = self .output_f )
414+ while progress_export != "PROGRESS_DONE" :
415+ result_get = self ._execute_command_and_get_result (operation_get_command )
416+ progress_export = result_get ["metadata" ]["progress" ]
417+
418+ s3_resource = boto3 .resource ("s3" , endpoint_url = s3_endpoint , aws_access_key_id = s3_access_key , aws_secret_access_key = s3_secret_key )
419+
420+ keys_expected = set ()
421+ for table_num in range (1 , 6 ):
422+ table_name = f"sample_table_{ table_num } "
423+ keys_expected .add (table_name + "/data_00.csv" )
424+ keys_expected .add (table_name + "/metadata.json" )
425+ keys_expected .add (table_name + "/scheme.pb" )
426+
427+ bucket = s3_resource .Bucket (s3_bucket )
428+ keys = set ()
429+ for x in list (bucket .objects .all ()):
430+ keys .add (x .key )
431+
432+ assert keys_expected <= keys
0 commit comments