当前位置: 首页>>代码示例>>Python>>正文


Python GpUtility.run方法代码示例

本文整理汇总了Python中mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility.run方法的典型用法代码示例。如果您正苦于以下问题:Python GpUtility.run方法的具体用法?Python GpUtility.run怎么用?Python GpUtility.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility的用法示例。


在下文中一共展示了GpUtility.run方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OOMGpstartTestCase

# 需要导入模块: from mpp.gpdb.tests.storage.walrepl.lib.pg_util import GpUtility [as 别名]
# 或者: from mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility import run [as 别名]
class OOMGpstartTestCase(MPPTestCase):
    ''' Simulating oom on standby master , gpstart fails to start standby'''
    
    # Setup OOM env
    oom.setup_oom()

    def __init__(self, methodName):
        self.gpinitstandby= GpinitStandby()
        self.gputil = GpUtility()
        super(OOMGpstartTestCase,self).__init__(methodName)

    def setUp(self):
        self.gpinitstandby.run(option='-r')

    def tearDown(self):
        self.gpinitstandby.run(option='-r')

    def test_oom_with_gpstart(self):
        # Create standby
        oom.create_standby()
        # Stop cluster
        self.gputil.run('gpstop -a')
        # Run gpstart after creaitng the flag file- Presence of this flag file will return NULL for malloc simulating a no  memory scenario
        oom.touch_malloc()
        self.assertFalse(oom.startdb(), 'Standby start is expected to fail with no memory error')
        # Restart after removing the flag file
        self.assertTrue(oom.restartdb(), 'Expected a successful start of standby')

    @unittest.skipIf(not config.is_multinode(), "Test applies only to a multinode cluster")
    def test_oom_with_psql_con(self):
        # Create standby
        oom.create_standby()
        # Stop cluster
        self.gputil.run('gpstop -a')
        # Run gpstart with wrapper
        oom.startdb()
        # OOM with psql- after adding the flag file to the standby directory to simulate OOM
        self.assertTrue(oom.psql_and_oom())
        # Start standby after free up memory
        self.assertTrue(oom.start_standby())
开发者ID:50wu,项目名称:gpdb,代码行数:42,代码来源:test_oom.py

示例2: GpstopTestCase

# 需要导入模块: from mpp.gpdb.tests.storage.walrepl.lib.pg_util import GpUtility [as 别名]
# 或者: from mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility import run [as 别名]
class GpstopTestCase(MPPTestCase):
   '''testcase for gpstart''' 
    
   origin_mdd = os.environ.get('MASTER_DATA_DIRECTORY') 
   
   def __init__(self,methodName):
       self.gputil = GpUtility()
       super(GpstopTestCase,self).__init__(methodName)
    
    
   def setUp(self):
       self.gputil.check_and_start_gpdb()     
       stdby_presence = self.gputil.check_standby_presence()
       if  stdby_presence:
           self.gputil.remove_standby()
       self.gputil.install_standby()

   def tearDown(self):
       self.gputil.remove_standby()
       self.gputil.run('gpstart -a')
       self.gputil.run('gprecoverseg -a')

   def test_gpstop_from_master(self):
       self.assertTrue(self.gputil.gpstop_and_verify())
       self.gputil.run('gpstart -a')

   def test_gpstop_master_only(self):
       self.assertTrue(self.gputil.gpstop_and_verify(option = '-m'))
       self.gputil.run('gpstart -a')

   def test_gpstop_fast(self):
       #run transactions, and stop fast, check if transaction aborted, and the cluster was stopped
       self.assertTrue(self.gputil.gpstop_and_verify(option = '-M fast'))
       self.gputil.run('gpstart -a')

   def test_gpstop_immediate(self):
       self.assertTrue(self.gputil.gpstop_and_verify(option = '-M immediate'))
       self.gputil.run('gpstart -a')

   def test_gpstop_smart(self):
       self.assertTrue(self.gputil.gpstop_and_verify(option = '-M smart'))
       self.gputil.run('gpstart -a')
  
   def test_gpdb_restart(self):
       self.assertTrue(self.gputil.gpstop_and_verify('-r'))

   def test_gpdb_reload(self):
       self.assertTrue(self.gputil.gpstop_and_verify('-u'))

   def test_gpstop_except_stdby(self):
       self.assertTrue(self.gputil.gpstop_and_verify('-y'))
       self.gputil.run('gpstart -y')

   def test_gpstop_after_failover(self):
       tinctest.logger.info("test gpstop from new master after failover")
       activatestdby = GpactivateStandby()
       standby_host = activatestdby.get_current_standby()
       standby_port =  activatestdby.get_standby_port()
       standby_mdd = activatestdby.get_standby_dd()
       activatestdby.activate()    
       (rc,stdout)=activatestdby.run_remote(standby_host, rmt_cmd='gpstop -a -M fast',
                                                 pgport=standby_port,standbydd=standby_mdd) 
       self.assertEqual(0,rc)
       activatestdby.run_remote(standby_host, rmt_cmd='gpstart -a',
                                                 pgport=standby_port,
                                                 standbydd=standby_mdd)
       self.gputil.failback_to_original_master(self.origin_mdd, standby_host, standby_mdd, standby_port) 
开发者ID:50wu,项目名称:gpdb,代码行数:69,代码来源:test_gpstop.py

示例3: WalReplKillProcessTestCase

# 需要导入模块: from mpp.gpdb.tests.storage.walrepl.lib.pg_util import GpUtility [as 别名]
# 或者: from mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility import run [as 别名]
class WalReplKillProcessTestCase(TINCTestCase):
  
   # this is not hard code, will be updated  
   stdby_host = 'localhost'
   stdby_port = '5432'
 
   def __init__(self,methodName):
       self.gphome = os.environ.get('GPHOME')
       self.pgport = os.environ.get('PGPORT')
       self.pgdatabase = os.environ.get('PGDATABASE')
       self.stdby_host = 'localhost'
       self.master_dd = os.environ.get('MASTER_DATA_DIRECTORY')
       self.pgutil = GpUtility()
       self.stdby = StandbyVerify()
       super(WalReplKillProcessTestCase,self).__init__(methodName)


   def killProcess_byPid(self, signal=9, pid_toKill=[], host="localhost"):
       pid_list = ""
       for pid in pid_toKill:
           pid_list = pid_list + " " + str(pid)

       kill_cmd = "%s/bin/gpssh -h %s -e 'kill -%s  %s'" % (os.environ.get('GPHOME'), host, signal, pid_list)
       (rc, result) = self.pgutil.run(kill_cmd)
       if rc == 0:
           tinctest.logger.info("Process killed, %s" % result)
           return True
       else:
           tinctest.logger.error("Killing process error, Status Code non zero, cmd: %s\n"%kill_cmd)
           return False

   def kill_walstartup(self):
       gpstdby = GpinitStandby()
       stdby_host = gpstdby.get_standbyhost()
       activate_stdby = GpactivateStandby()
       stdby_port = activate_stdby.get_standby_port()
       pid_list = []
       startup_pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword="startup process")
       if int(startup_pid) == -1:
           tinctest.logger.error("error:startup process does not exist!")
           return False
       else:
           pid_list.append(startup_pid)
           self.killProcess_byPid(pid_toKill=pid_list, host=stdby_host)

   def kill_walreceiver(self):
       gpstdby = GpinitStandby()
       stdby_host = gpstdby.get_standbyhost()
       activate_stdby = GpactivateStandby()
       stdby_port = activate_stdby.get_standby_port()
       pid_list = []
       walreceiver_pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword="wal receiver process")
       if int(walreceiver_pid) == -1:
           tinctest.logger.error("error: wal receiver process does not exist!")
           return False
       else:  
           pid_list.append(walreceiver_pid)
           self.killProcess_byPid(pid_toKill=pid_list, host=stdby_host)


   def kill_walsender_check_postmaster_reset(self):
       pid_list = []
       walsender_old_pid=self.pgutil.get_pid_by_keyword(pgport=self.pgport,keyword="wal sender process")
       if int(walsender_old_pid) == -1:
           tinctest.logger.error("error: process wal sender does not exist on host")
           return False
       else:
           pid_list.append(walsender_old_pid)
           self.killProcess_byPid(pid_toKill=pid_list)
       sleep(2)
       walsender_new_pid=self.pgutil.get_pid_by_keyword(pgport=self.pgport,keyword="wal sender process")
       if walsender_old_pid == walsender_new_pid:
          raise Exception("Killing walsender failed to force postmaster reset")
       else:
          return True         

   def kill_transc_backend_check_reset(self):
       dict_process = { 'stats collector process': -1, 'writer process': -1,
                       'checkpointer process': -1,'seqserver process': -1,
                       'ftsprobe process': -1,'sweeper process': -1,'wal sender process': -1}
       for process in dict_process:
           pid = self.pgutil.get_pid_by_keyword(pgport=self.pgport,keyword=process)
           dict_process[process] = pid 
       self.kill_transc_backend()
       for process in dict_process:
           pid = self.pgutil.get_pid_by_keyword(pgport=self.pgport,keyword=process)
           delay = 1
           while dict_process.get(process) == pid and delay < 5:
                pid = self.pgutil.get_pid_by_keyword(pgport=self.pgport,keyword=process)
                sleep(1)
                delay = delay +1
           if delay == 5:
                tinctest.logger.error("Killing transaction backend process failed to force postmaster reset: %s"%process)
                raise Exception("Killing transaction backend process failed to force postmaster reset child process") 
 
   def kill_transc_backend(self):
       pid_list = []
       sql = "SELECT procpid FROM pg_stat_activity WHERE datname='{0}' AND current_query like 'INSERT INTO%'".format(self.pgdatabase)    
       tinctest.logger.info("running sql command to get transaction backend process: ---  %s"%sql)
       procid = PSQL.run_sql_command(sql, flags = '-q -t', dbname= self.pgdatabase)
#.........这里部分代码省略.........
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:103,代码来源:__init__.py

示例4: OOMClass

# 需要导入模块: from mpp.gpdb.tests.storage.walrepl.lib.pg_util import GpUtility [as 别名]
# 或者: from mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility import run [as 别名]
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
开发者ID:50wu,项目名称:gpdb,代码行数:74,代码来源:__init__.py

示例5: GpstartTestCase

# 需要导入模块: from mpp.gpdb.tests.storage.walrepl.lib.pg_util import GpUtility [as 别名]
# 或者: from mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility import run [as 别名]
class GpstartTestCase(MPPTestCase):
    '''
    testcase for gpstart

    gpstart may return status code 1 as well as 0 in the success case.  The
    difference is whether it produces WARNING or not, but here we don't care.
    '''
    origin_mdd = os.environ.get('MASTER_DATA_DIRECTORY')

    def __init__(self,methodName):
        self.gputil = GpUtility()
        self.stdby = StandbyVerify()
        super(GpstartTestCase,self).__init__(methodName)

    def setUp(self):
        self.gputil.check_and_start_gpdb()
        stdby_presence = self.gputil.check_standby_presence()
        # We should forcibly recreate standby, as it might has been promoted.
        if stdby_presence:
            self.gputil.remove_standby()
        self.gputil.install_standby()

    def tearDown(self):
        self.gputil.remove_standby()
        
    """
    Gpstart test cases in recovery mode
    """

    def test_gpstart_from_master(self):
        """
        tag
        """
        self.gputil.check_and_stop_gpdb()
        (rc, stdout) = self.gputil.run('gpstart -a ')
        self.assertIn(rc, (0, 1))
        self.assertTrue(self.gputil.gpstart_and_verify())
        sleep(2)
        self.assertTrue(self.stdby.check_gp_segment_config(),'standby master not cofigured')
        self.assertTrue(self.stdby.check_pg_stat_replication(),'standby not in replication status')
        self.assertTrue(self.stdby.check_standby_processes(), 'standby processes not running')
        (rc, output) = self.gputil.run(command = 'ps -ef|grep "wal sender "|grep -v grep')
        self.assertIsNotNone(output)

    def test_gpstart_master_only(self):
        """
        tag
        """
        self.gputil.check_and_stop_gpdb()
        (rc, stdout) = self.gputil.run('export GPSTART_INTERNAL_MASTER_ONLY=1; '
                                   'gpstart -a -m ')
        self.assertIn(rc, (0, 1))
        self.assertTrue(self.gputil.gpstart_and_verify())
        (rc,output) = self.gputil.run('PGDATABASE=template1 '
                                  "PGOPTIONS='-c gp_session_role=utility' "
                                  'psql')
        self.assertEqual(rc, 0)
        (rc, output) = self.gputil.run('psql template1')
        # should fail due to master only mode
        self.assertEqual(rc, 2)
        self.gputil.run('gpstop -a -m')
        self.gputil.run('gpstart -a')


    def test_gpstart_restricted_mode_master(self):
        """Test -R option with standby."""

        self.gputil.check_and_stop_gpdb()
        (rc, stdout) = self.gputil.run('gpstart -a -R')
        self.assertIn(rc, (0, 1))
        self.assertTrue(self.gputil.gpstart_and_verify())
        (rc,output) = self.gputil.run(command = 'psql template1')
        self.assertIn(rc, (0, 1))
        self.gputil.run('gpstop -ar')


    def test_gpstart_master_w_timeout(self):
        """Test -t option with standby."""

        self.gputil.check_and_stop_gpdb()
        (rc, output) = self.gputil.run('gpstart -a -t 30')
        self.assertIn(rc, (0, 1))
        self.assertTrue(self.gputil.gpstart_and_verify())
        self.gputil.run('gpstop -ar')

    def test_gpstart_no_standby(self):
        """Test -y with standby configured."""

        self.gputil.check_and_stop_gpdb()
        (rc, stdout) = self.gputil.run('gpstart -a -y')
        self.assertIn(rc, (0, 1))
        self.assertTrue(self.gputil.gpstart_and_verify())
        self.assertFalse(self.stdby.check_standby_processes(),
                         'gpstart without standby failed, standby was running')
        self.gputil.run('gpstop -ar')

    def test_gpstart_wo_standby(self):
        """Test -y without standby configured."""

        self.gputil.remove_standby()
#.........这里部分代码省略.........
开发者ID:50wu,项目名称:gpdb,代码行数:103,代码来源:test_gpstart.py


注:本文中的mpp.gpdb.tests.storage.walrepl.lib.pg_util.GpUtility.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。