Exemplo n.º 1
0
class PromoteTestCase(MPPTestCase):
   '''testcase for gpstart''' 
 
   def __init__(self,methodName):
       self.pgutil = GpUtility()
       super(PromoteTestCase,self).__init__(methodName)
  
   def setUp(self):
       self.pgutil.check_and_start_gpdb()
       # We should forcibly recreate standby, as it might has been promoted.
       self.pgutil.remove_standby()
       self.pgutil.install_standby()


   def tearDown(self):
       self.pgutil.remove_standby()

   def test_promote_incomplete_stdby(self):
       ''' 
       remove the standby base dir, try promote and check if fail       
       '''
       gpactivate_stdby = GpactivateStandby()
       gpinit_stdby = GpinitStandby()
       stdby_mdd = gpactivate_stdby.get_standby_dd()
       stdby_host = gpinit_stdby.get_standbyhost()
       stdby_port = gpactivate_stdby.get_standby_port()
       destDir = os.path.join(stdby_mdd, 'base')
       self.pgutil.clean_dir(stdby_host,destDir)
       promote_cmd = "pg_ctl promote -D %s"%stdby_mdd       
       (rc, output) = gpactivate_stdby.run_remote(stdby_host,promote_cmd ,stdby_port,stdby_mdd)
       self.assertEqual(rc, 0)
       pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword='master', option='bin')
       self.assertTrue(int(pid) == -1, 'incomplete standby data directory promote succeeds.')
Exemplo n.º 2
0
class PromoteTestCase(MPPTestCase):
    '''testcase for gpstart'''
    def __init__(self, methodName):
        self.pgutil = GpUtility()
        super(PromoteTestCase, self).__init__(methodName)

    def setUp(self):
        self.pgutil.check_and_start_gpdb()
        # We should forcibly recreate standby, as it might has been promoted.
        self.pgutil.remove_standby()
        self.pgutil.install_standby()

    def tearDown(self):
        self.pgutil.remove_standby()

    def test_promote_incomplete_stdby(self):
        ''' 
       remove the standby base dir, try promote and check if fail       
       '''
        gpactivate_stdby = GpactivateStandby()
        gpinit_stdby = GpinitStandby()
        stdby_mdd = gpactivate_stdby.get_standby_dd()
        stdby_host = gpinit_stdby.get_standbyhost()
        stdby_port = gpactivate_stdby.get_standby_port()
        destDir = os.path.join(stdby_mdd, 'base')
        self.pgutil.clean_dir(stdby_host, destDir)
        promote_cmd = "pg_ctl promote -D %s" % stdby_mdd
        (rc, output) = gpactivate_stdby.run_remote(stdby_host, promote_cmd,
                                                   stdby_port, stdby_mdd)
        self.assertEqual(rc, 0)
        pid = self.pgutil.get_pid_by_keyword(host=stdby_host,
                                             pgport=stdby_port,
                                             keyword='master',
                                             option='bin')
        self.assertTrue(
            int(pid) == -1,
            'incomplete standby data directory promote succeeds.')
Exemplo n.º 3
0
class OOMClass(object):
    '''Class for methods required for OOM testcase'''

    standby_port = '5433'
    standby_dirname = 'newstandby'

    def __init__(self):
        self.gpinit = GpinitStandby()
        self.mdd = os.environ.get('MASTER_DATA_DIRECTORY')
        self.config = GPDBConfig()
        self.pgutil = GpUtility()
        self.verify = StandbyVerify()
        self.host = socket.gethostname()
        self.standby_loc = os.path.join(os.path.split(self.mdd)[0],
                                        self.standby_dirname)
        self.standby = Standby(self.standby_loc, self.standby_port)

    def create_standby(self):
        self.pgutil.clean_dir(self.host,self.standby_loc)
        self.gpinit.run(option = '-P %s -s %s -F pg_system:%s' % (self.standby_port, self.host, self.standby_loc))

    def setup_oom(self):
        # Build it before testing.
        thisdir = os.path.dirname(__file__)
        builddir = os.path.join(thisdir, 'lib')
        subprocess.check_call(['make', '-C', builddir, 'install'])

        #Copy oom_malloc.so and wrapper.sh to all the segment nodes
        for host in config.get_hosts() :
            if host.strip() == self.host :
                continue
            cmd = "gpssh -h %s -e 'mkdir -p %s'; scp %s/oom_malloc.so %s:%s/; scp %s/wrapper.sh %s:%s/" % (host.strip(), builddir, builddir, host.strip(), builddir, builddir, host.strip(), builddir)
            self.pgutil.run(cmd)

    def touch_malloc(self):
        # Touch file oom_malloc in standby directory
        cmd = 'touch %s/oom_malloc' % self.standby_loc
        self.pgutil.run(cmd)

    def startdb(self):
        (rc, result) = self.pgutil.run('gpstart -a --wrapper %s' % (local_path('lib/wrapper.sh')))
        if rc != 0 and 'Could not start standby master' in result :
            return False
        return True

    def restartdb(self):
        # Remove file oom_malloc from standby
        cmd = 'rm %s/oom_malloc' % self.standby_loc
        self.pgutil.run(cmd)
        (rc, result) = self.pgutil.run('gpstop -ar')
        if rc == 0 and (self.verify.check_pg_stat_replication()):
            return True
        return False

    def psql_and_oom(self):
        #Touch oom_malloc in standby_dir and issue PSQL : Check if processes are gone
        self.touch_malloc()
        PSQL.run_sql_command('Drop table if exists wal_oomt1;Create table wal_oomt1(a1 int, a2 text) with(appendonly=true);')
        sleep(2)
        if not (self.verify.check_standby_processes()):
            return True
        return False 

    def start_standby(self):
        # Remove oom_malloc and start standby : Check if all processes are back
        cmd = 'rm %s/oom_malloc' % self.standby_loc
        self.pgutil.run(cmd)
        res = self.standby.start()
        sleep(2)
        if (self.verify.check_standby_processes()) :
            return True
        return False
Exemplo n.º 4
0
class OOMClass(object):
    '''Class for methods required for OOM testcase'''

    standby_port = '5433'
    standby_dirname = 'newstandby'

    def __init__(self):
        self.gpinit = GpinitStandby()
        self.mdd = os.environ.get('MASTER_DATA_DIRECTORY')
        self.config = GPDBConfig()
        self.pgutil = GpUtility()
        self.verify = StandbyVerify()
        self.host = socket.gethostname()
        self.standby_loc = os.path.join(
            os.path.split(self.mdd)[0], self.standby_dirname)
        self.standby = Standby(self.standby_loc, self.standby_port)

    def create_standby(self):
        self.pgutil.clean_dir(self.host, self.standby_loc)
        self.gpinit.run(option='-P %s -s %s -F pg_system:%s' %
                        (self.standby_port, self.host, self.standby_loc))

    def setup_oom(self):
        # Build it before testing.
        thisdir = os.path.dirname(__file__)
        builddir = os.path.join(thisdir, 'lib')
        subprocess.check_call(['make', '-C', builddir, 'install'])

        #Copy oom_malloc.so and wrapper.sh to all the segment nodes
        for host in config.get_hosts():
            if host.strip() == self.host:
                continue
            cmd = "gpssh -h %s -e 'mkdir -p %s; scp %s/oom_malloc.so %s:%s/;scp %s/wrapper.sh %s:%s/'" % (
                host.strip(), builddir, builddir, host.strip(), builddir,
                builddir, host.strip(), builddir)
            self.pgutil.run(cmd)

    def touch_malloc(self):
        # Touch file oom_malloc in standby directory
        cmd = 'touch %s/oom_malloc' % self.standby_loc
        self.pgutil.run(cmd)

    def startdb(self):
        (rc, result) = self.pgutil.run('gpstart -a --wrapper %s' %
                                       (local_path('lib/wrapper.sh')))
        if rc != 0 and 'Could not start standby master' in result:
            return False
        return True

    def restartdb(self):
        # Remove file oom_malloc from standby
        cmd = 'rm %s/oom_malloc' % self.standby_loc
        self.pgutil.run(cmd)
        (rc, result) = self.pgutil.run('gpstop -ar')
        if rc == 0 and (self.verify.check_pg_stat_replication()):
            return True
        return False

    def psql_and_oom(self):
        #Touch oom_malloc in standby_dir and issue PSQL : Check if processes are gone
        self.touch_malloc()
        PSQL.run_sql_command(
            'Drop table if exists wal_oomt1;Create table wal_oomt1(a1 int, a2 text) with(appendonly=true);'
        )
        sleep(2)
        if not (self.verify.check_standby_processes()):
            return True
        return False

    def start_standby(self):
        # Remove oom_malloc and start standby : Check if all processes are back
        cmd = 'rm %s/oom_malloc' % self.standby_loc
        self.pgutil.run(cmd)
        res = self.standby.start()
        sleep(2)
        if (self.verify.check_standby_processes()):
            return True
        return False