コード例 #1
0
ファイル: __init__.py プロジェクト: 50wu/gpdb
 def do_gpcheckcat(self):
     dbstate = GpdbVerify()
     i = 0 
     errorCode = 1 
     while(errorCode>0 and i<5):
         (errorCode, hasError, gpcheckcat_output, repairScriptDir) = dbstate.gpcheckcat(alldb = False)
         tinctest.logger.info(" %s Gpcheckcat iteration . ErrorCode: %s " % (i,errorCode))
         if (errorCode>0):
             dbstate.run_repair_script(repairScriptDir)
             i = i+1 
         if errorCode!=0 and i>=5 :
             raise Exception('gpcheckcat finished with error(s)')
コード例 #2
0
 def do_gpcheckcat(self):
     dbstate = GpdbVerify()
     i = 0
     errorCode = 1
     while (errorCode > 0 and i < 5):
         (errorCode, hasError, gpcheckcat_output,
          repairScriptDir) = dbstate.gpcheckcat(alldb=False)
         tinctest.logger.info(" %s Gpcheckcat iteration . ErrorCode: %s " %
                              (i, errorCode))
         if (errorCode > 0):
             dbstate.run_repair_script(repairScriptDir)
             i = i + 1
         if errorCode != 0 and i >= 5:
             raise Exception('gpcheckcat finished with error(s)')
コード例 #3
0
class GpdbVerifyRegressionTests(unittest.TestCase):
    def __init__(self, methodName):
        self.gpv = GpdbVerify()
        super(GpdbVerifyRegressionTests, self).__init__(methodName)

    def setUp(self):
        PSQL.run_sql_command('create database gptest;', dbname='postgres')

    def tearDown(self):
        PSQL.run_sql_command('drop database gptest', dbname='postgres')

    def test_gpcheckcat(self):
        (a, b, c, d) = self.gpv.gpcheckcat()
        self.assertIn(a, (0, 1, 2))

    def test_gpcheckmirrorseg(self):
        (res, fix_file) = self.gpv.gpcheckmirrorseg()
        self.assertIn(res, (True, False))

    def test_check_db_is_running(self):
        self.assertTrue(self.gpv.check_db_is_running())

    def test_run_repairscript(self):
        repair_script = local_path('gpcheckcat_repair')
        res = self.gpv.run_repair_script(repair_script)
        self.assertIn(res, (True, False))

    def test_ignore_extra_m(self):
        fix_file = local_path('fix_file')
        res = self.gpv.ignore_extra_m(fix_file)
        self.assertIn(res, (True, False))
コード例 #4
0
class GpdbVerifyRegressionTests(unittest.TestCase):
    def __init__(self, methodName):
        self.gpv = GpdbVerify()
        super(GpdbVerifyRegressionTests, self).__init__(methodName)

    def setUp(self):
        PSQL.run_sql_command('create database gptest;', dbname='postgres')

    def tearDown(self):
        PSQL.run_sql_command('drop database gptest', dbname='postgres')

    def test_gpcheckcat(self):
        (a, b, c, d) = self.gpv.gpcheckcat()
        self.assertIn(a, (0, 1, 2))

    def test_gpcheckmirrorseg(self):
        (res, fix_file) = self.gpv.gpcheckmirrorseg()
        self.assertIn(res, (True, False))

    def test_check_db_is_running(self):
        self.assertTrue(self.gpv.check_db_is_running())

    def test_run_repairscript(self):
        repair_script = local_path('gpcheckcat_repair')
        res = self.gpv.run_repair_script(repair_script)
        self.assertIn(res, (True, False))

    def test_ignore_extra_m(self):
        fix_file = local_path('fix_file')
        res = self.gpv.ignore_extra_m(fix_file)
        self.assertIn(res, (True, False))

    def test_cleanup_old_file(self):
        old_time = int(time.strftime("%Y%m%d%H%M%S")) - 1005000
        old_file = local_path('checkmirrorsegoutput_%s' % old_time)
        open(old_file, 'w')
        self.gpv.cleanup_day_old_out_files(local_path(''))
        self.assertFalse(os.path.isfile(old_file))

    def test_not_cleanup_todays_file(self):
        new_file = local_path('checkmirrorsegoutput_%s' %
                              time.strftime("%Y%m%d%H%M%S"))
        open(new_file, 'w')
        self.gpv.cleanup_day_old_out_files(local_path(''))
        self.assertTrue(os.path.isfile(new_file))
コード例 #5
0
class GpdbVerifyRegressionTests(unittest.TestCase):

    def __init__(self, methodName):
        self.gpv = GpdbVerify()
        super(GpdbVerifyRegressionTests, self).__init__(methodName)
    
    def setUp(self):
        PSQL.run_sql_command('create database gptest;', dbname='postgres')

    def tearDown(self):
        PSQL.run_sql_command('drop database gptest', dbname='postgres')
     
    def test_gpcheckcat(self):
        (a,b,c,d) = self.gpv.gpcheckcat()
        self.assertIn(a,(0,1,2))

    def test_gpcheckmirrorseg(self):
        (res,fix_file) = self.gpv.gpcheckmirrorseg()
        self.assertIn(res, (True,False))

    def test_check_db_is_running(self):
        self.assertTrue(self.gpv.check_db_is_running())

    def test_run_repairscript(self):
        repair_script = local_path('gpcheckcat_repair')
        res = self.gpv.run_repair_script(repair_script)
        self.assertIn(res, (True,False))

    def test_ignore_extra_m(self):
        fix_file = local_path('fix_file')
        res = self.gpv.ignore_extra_m(fix_file)
        self.assertIn(res, (True,False))
     
    def test_cleanup_old_file(self):
        old_time = int(time.strftime("%Y%m%d%H%M%S")) - 1005000 
        old_file = local_path('checkmirrorsegoutput_%s' % old_time)
        open(old_file,'w')
        self.gpv.cleanup_day_old_out_files(local_path(''))
        self.assertFalse(os.path.isfile(old_file))
        
    def test_not_cleanup_todays_file(self):
        new_file = local_path('checkmirrorsegoutput_%s' % time.strftime("%Y%m%d%H%M%S"))
        open(new_file,'w')
        self.gpv.cleanup_day_old_out_files(local_path(''))
        self.assertTrue(os.path.isfile(new_file))
コード例 #6
0
ファイル: dbstate.py プロジェクト: stefanieqiang/gpdb-1
class DbStateClass(MPPTestCase):
    def __init__(self, methodName, config=None):
        if config is not None:
            self.config = config
        else:
            self.config = GPDBConfig()
        self.gpverify = GpdbVerify(config=self.config)
        super(DbStateClass, self).__init__(methodName)

    def check_system(self):
        ''' 
        @summary: Check whether the system is up and sync. Exit out if not 
        '''
        cmd = "select count(*) from gp_segment_configuration where content<> -1 ;"
        count_all = PSQL.run_sql_command(cmd, flags='-q -t', dbname='postgres')
        cmd = "select count(*) from gp_segment_configuration where content<> -1 and mode = 's' and status = 'u';"
        count_up_and_sync = PSQL.run_sql_command(cmd,
                                                 flags='-q -t',
                                                 dbname='postgres')
        if count_all.strip() != count_up_and_sync.strip():
            tinctest.logger.info(
                'Exiting the test. The cluster is not in up/sync ............')
            os._exit(1)
        else:
            tinctest.logger.info(
                "\n Starting New Test: System is up and in sync .........")

    def check_catalog(self,
                      dbname=None,
                      alldb=True,
                      online=False,
                      testname=None,
                      outputFile=None,
                      run_repair=True,
                      host=None,
                      port=None,
                      expected_rc=0):
        '''1. Run gpcheckcat 2. Run repairscript if present 3. Run gpcheckcat again. Repeat this 5 times'''
        errorCode = 1
        if run_repair:
            i = 0
            while i < 5:
                (errorCode, hasError, gpcheckcat_output,
                 repairScriptDir) = self.gpverify.gpcheckcat(
                     dbname=dbname,
                     alldb=alldb,
                     online=online,
                     testname=testname,
                     outputFile=outputFile,
                     host=host,
                     port=port)
                tinctest.logger.info(
                    " %s Gpcheckcat iteration . ErrorCode: %s " %
                    (i, errorCode))
                if errorCode == 0:
                    break
                else:
                    self.gpverify.run_repair_script(repairScriptDir,
                                                    dbname=dbname,
                                                    alldb=alldb,
                                                    online=online,
                                                    testname=testname,
                                                    outputFile=outputFile,
                                                    host=host,
                                                    port=port)
                    i = i + 1
        else:
            (errorCode, hasError, gpcheckcat_output,
             repairScriptDir) = self.gpverify.gpcheckcat(dbname=dbname,
                                                         alldb=alldb,
                                                         online=online,
                                                         testname=testname,
                                                         outputFile=outputFile,
                                                         host=host,
                                                         port=port)
        if errorCode != expected_rc:
            raise Exception('GpCheckcat failed, %s != %s ' %
                            (errorCode, expected_rc))

    def check_mirrorintegrity(self, master=False):
        '''Runs checkmirrorintegrity(default), check_mastermirrorintegrity(when master=True) '''
        (checkmirror,
         fix_outfile) = self.gpverify.gpcheckmirrorseg(master=master)
        if not checkmirror:
            self.fail('Checkmirrorseg failed. Fix file location : %s' %
                      fix_outfile)
        tinctest.logger.info('Successfully completed integrity check')

    def run_validation(self):
        '''
        1. gpcheckcat
        2. checkmirrorintegrity
        3. check_mastermirrorintegrity 
        '''
        self.check_catalog()
        self.check_mirrorintegrity()
        if self.config.has_master_mirror():
            self.check_mirrorintegrity(master=True)