@@ -37,13 +37,15 @@ def parseargs():
37
37
' verify that all the tables in a specific database can be accessed.' ,
38
38
epilog = 'Source code available at github.com/ielizaga/gpcheckintegrity' )
39
39
parser .add_option ('-v' , '--verbose' , action = 'store_true' , help = 'Enables debug logging' )
40
+ parser .add_option ('-y' , '--yes' , action = 'store_true' , help = 'Assumes yes and do not prompt to confirm' )
40
41
parser .add_option ('-A' , '--all' , action = 'store_true' , help = 'Check all databases' )
41
42
parser .add_option ('-d' , '--database' , help = 'Database to connect to' )
42
43
parser .add_option ('-s' , '--schema' , help = 'Checks all the tables in this schema' )
43
44
parser .add_option ('-S' , '--schema-list' , dest = 'schema_list' ,
44
45
help = 'Comma-separated list of schemas to check tables from. Example: s1,s2,s3' )
45
46
parser .add_option ('-t' , '--table' , help = 'Check just this table' )
46
- parser .add_option ('-B' , '--parallel' , type = int , default = DEFAULT_NUM_THREADS , help = 'Number of parallel workers (Default: 32)' )
47
+ parser .add_option ('-B' , '--parallel' , type = int , default = DEFAULT_NUM_THREADS ,
48
+ help = 'Number of parallel workers (Default: 32)' )
47
49
(options_object , args_object ) = parser .parse_args ()
48
50
49
51
USER = os .getenv ('USER' )
@@ -84,8 +86,8 @@ def connect(user=None, password=None, host=None, port=None, database=None, utili
84
86
database = os .environ .get ('PGDATABASE' , 'template1' )
85
87
try :
86
88
logger .debug ('connecting to %s:%s %s' % (host , port , database ))
87
- db_conn = pg .connect (host = host , port = port , user = user ,
88
- passwd = password , dbname = database , opt = conf )
89
+ db_conn = pg .connect (host = host , port = port , user = user ,
90
+ passwd = password , dbname = database , opt = conf )
89
91
except pg .InternalError , ex :
90
92
logger .error ('could not connect to %s: "%s"' %
91
93
(database , str (ex ).strip ()))
@@ -290,6 +292,11 @@ def _spawn_threads(database):
290
292
if options .table is None and options .schema is None and options .schema_list is None :
291
293
tables .extend (get_tables (database ))
292
294
295
+ if options .yes is not True \
296
+ and prompt_user (database , tables ) is False :
297
+ logger .info ('User cancelled the program, aborting...' )
298
+ sys .exit (0 )
299
+
293
300
dbids = get_gp_segment_configuration () # get Greenplum segment information
294
301
threads = []
295
302
for dbid in dbids :
@@ -306,6 +313,24 @@ def _spawn_threads(database):
306
313
return
307
314
308
315
316
+ def prompt_user (database , tables ):
317
+ logger .info ('We are going to check the following. Make sure you intended to run on those tables '
318
+ 'and nothing is missing' )
319
+
320
+ for table_obj in tables :
321
+ logger .info ('DB: %(database)s - %(schema)s.%(table)s' % {'database' : database , 'schema' : table_obj ['schema' ],
322
+ 'table' : table_obj ['table' ]})
323
+ while True :
324
+ logger .info ('\n Do you want to proceed? [Y/N]' )
325
+ line = sys .stdin .readline ()
326
+
327
+ if line [:- 1 ] in ('Y' , 'y' , 'yes' , 'Yes' ):
328
+ return True
329
+
330
+ if line [:- 1 ] in ('N' , 'n' , 'no' , 'No' ):
331
+ return False
332
+
333
+
309
334
class CheckIntegrity (Thread ):
310
335
def __init__ (self , tables , hostname , database , content , port ):
311
336
Thread .__init__ (self )
@@ -398,7 +423,7 @@ if __name__ == '__main__':
398
423
logger .info ("Checking database %s" % db ['datname' ])
399
424
_spawn_threads (db ['datname' ])
400
425
else :
401
- _spawn_threads (options .database )
426
+ _spawn_threads (options .database )
402
427
403
428
logger .info ("ERROR REPORT SUMMARY %s" % datetime .now ())
404
429
logger .info ("============================================" )
0 commit comments