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


Python GPDBConfig.get_hosts方法代码示例

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


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

示例1: copy_files_to_segments

# 需要导入模块: from mpp.lib.config import GPDBConfig [as 别名]
# 或者: from mpp.lib.config.GPDBConfig import get_hosts [as 别名]
def copy_files_to_segments(filename, location):
    config = GPDBConfig()
    hosts = config.get_hosts(segments=True)
    for host in hosts:
        cmd = 'gpssh -h %s -e "scp %s %s:%s/" ' % (host, filename, host, location)
        tinctest.logger.debug(cmd)
        res = {"rc": 0, "stderr": "", "stdout": ""}
        run_shell_command(cmd, "run scp", res)
        if res["rc"] > 0:
            raise Exception("Copying to host %s failed" % host)
开发者ID:kaknikhil,项目名称:gpdb,代码行数:12,代码来源:common_utils.py

示例2: setUpClass

# 需要导入模块: from mpp.lib.config import GPDBConfig [as 别名]
# 或者: from mpp.lib.config.GPDBConfig import get_hosts [as 别名]
 def setUpClass(cls):
     super(PreExpansionWorkloadTests, cls).setUpClass()
     # gpscp the script required for external table in create_base_workload
     scp_file = os.path.join(cls.get_sql_dir(), 'datagen.py')
     gpconfig = GPDBConfig()
     hosts = gpconfig.get_hosts()
     hosts_file = os.path.join(cls.get_out_dir(), 'hostfile')
     with open(hosts_file, 'w') as f:
         f.write('\n'.join(hosts))
     
     res = {'rc':0, 'stderr':'', 'stdout':''}
     run_shell_command("gpscp -f %s %s =:$GPHOME/bin" %(hosts_file, scp_file), 'gpscp script', res)
     if res['rc'] > 0:
         tinctest.logger.warning("Failed to gpscp the required script to all the segments for external table queries. The script might already exist !")
开发者ID:50wu,项目名称:gpdb,代码行数:16,代码来源:test_run_workload.py

示例3: GPDBConfigRegressionTests

# 需要导入模块: from mpp.lib.config import GPDBConfig [as 别名]
# 或者: from mpp.lib.config.GPDBConfig import get_hosts [as 别名]
class GPDBConfigRegressionTests(unittest.TestCase):

    def __init__(self, methodName):
        self.gpconfig = GPDBConfig()
        super(GPDBConfigRegressionTests,self).__init__(methodName)

    def test_get_countprimarysegments(self):
        nprimary = self.gpconfig.get_countprimarysegments()
        self.assertTrue(nprimary > 0)

    def test_get_hostandport_of_segment(self):
        (host,port) = self.gpconfig.get_hostandport_of_segment(psegmentNumber = -1, pRole = 'p')
        myhost = socket.gethostname()
        self.assertEquals(host, myhost)

    def test_get_count_segments(self):
        seg_count = self.gpconfig.get_count_segments()
        self.assertTrue(seg_count.strip() >0)

    def test_seghostnames(self):
        hostlist = self.gpconfig.get_hosts()
        self.assertTrue(len(hostlist) >0)
 
    def test_hostnames(self):
        hostlist = self.gpconfig.get_hosts(segments=False)
        self.assertTrue(len(hostlist) >0)

    def tes_get_masterhost(self):
        master_host = self.gpconfig.get_masterhost()
        myhost = socket.gethostname()
        self.assertEquals(master_host, myhost)

    def test_get_masterdata_directory(self):
        master_dd = self.gpconfig.get_masterdata_directory()
        my_mdd = os.getenv("MASTER_DATA_DIRECTORY")
        self.assertEquals(master_dd, my_mdd)
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:38,代码来源:regress_config.py

示例4: GPAddmirrorsTestCase

# 需要导入模块: from mpp.lib.config import GPDBConfig [as 别名]
# 或者: from mpp.lib.config.GPDBConfig import get_hosts [as 别名]
class GPAddmirrorsTestCase(MPPTestCase):

    def __init__(self, methodName):
        self.config = GPDBConfig()
        self.mdd = os.environ.get('MASTER_DATA_DIRECTORY')
        self.seg_prefix = os.path.basename(self.mdd).split('-')[0]
        self.master_host = self.config.get_masterhost()
        self.gpinitconfig_template = local_path('configs/gpinitconfig_template')
        self.datadir_config_file = local_path('configs/datadir_config_file') 
        self.mirror_config_file = local_path('configs/mirror_config_file')
        self.gpinitconfig_file = local_path('configs/gpinitconfig')
        self.host_file = local_path('configs/hosts')
        self.hosts = self.config.get_hosts(segments = True)

        self.port_base = '40000'
        self.master_port = os.environ.get('PGPORT', '5432')
        self.primary_data_dir = self.config.get_host_and_datadir_of_segment(dbid = 2)[1]
        # initially set the mirror data dir same to primary's
        self.mirror_data_dir = os.path.join(os.path.dirname(os.path.dirname(self.primary_data_dir)), 'mirror')
        self.gpinitsystem = True
        self.number_of_segments = self.config.get_countprimarysegments()
        self.number_of_segments_per_host = self.number_of_segments / len(self.hosts)
        self.standby_enabled = False
        self.number_of_parallelism = 4
        self.fs_location = []

        super(GPAddmirrorsTestCase, self).__init__(methodName)

    def setUp(self):
        super(GPAddmirrorsTestCase, self).setUp()

    def _setup_gpaddmirrors(self, port_offset=1000):
        """
        Takes care of creating all the directories required for gpaddmirrors
        and generating input files for gpaddmirrors
        """
        # Generate gpaddmirrors config files
        try:
            self._generate_gpaddmirrors_input_files(port_offset)
        except Exception, e:
            tinctest.logger.exception("Encountered exception during generation of input files: %s" % e)
            raise
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:44,代码来源:test_gpaddmirrors.py

示例5: _generate_gpexpand_input_files

# 需要导入模块: from mpp.lib.config import GPDBConfig [as 别名]
# 或者: from mpp.lib.config.GPDBConfig import get_hosts [as 别名]
    def _generate_gpexpand_input_files(self):
        config = GPDBConfig()

        # use the last segment as a template
        # TODO: This logic needs fixing when we enable mirror tests
        seg = (sorted(config.record, lambda a, b: b.content - a.content)).pop(0)
        # Find max db id for generating gpexpand input file
        max_db_id = max([r.dbid for r in config.record])
        self.assertNotEqual(seg.content, -1)


        def next_datadir(datadir, i=1):
            # /path/to/foo/seg12 -> /path/to/foo/seg13
            lefthand = datadir.rstrip('0123456789')
            segnum = int(datadir[len(lefthand):])
            return lefthand + str(segnum + i)

        with open(self.testcase_gpexpand_file, 'w') as f:
            # For existing hosts, add self.number_of_expansion_segments
            # For new hosts add existing number of segments + number_of_expansion_segments

            # Existing hosts
            existing_hosts = config.get_hosts(segments=True)
            existing_number_of_segments = 0

            cnt = 1

            for host in existing_hosts:
                # Find the existing number of segments in the existing hosts
                existing_number_of_segments = config.get_segments_count_per_host()[host]

                for i in range(self.number_of_expansion_segments):
                    f.write(
                    "{host}:{addr}:{port}:{datadir}:{dbid}:{content}:{role}\n".format(
                        host=host,
                        addr=host,
                        port= int(seg.port) + cnt,
                        datadir=next_datadir(seg.datadir, cnt),
                        dbid=int(max_db_id) + cnt,
                        content= int(seg.content) + cnt,
                        role='p'
                        ))
                    cnt += 1

            # New hosts
            if self.number_of_expansion_hosts > 0:
                new_expansion_hosts = list(set(self.hosts) - existing_hosts)
                if not new_expansion_hosts:
                    raise GPExpandTestCaseException("No new hosts available for expansion based on the environment variable GPEXPAND_HOSTS: %s" %os.environ.get("GPEXPAND_HOSTS"))

                for host in new_expansion_hosts[0:self.number_of_expansion_hosts]:
                    for i in range(existing_number_of_segments + self.number_of_expansion_segments):
                        f.write(
                            "{host}:{addr}:{port}:{datadir}:{dbid}:{content}:{role}\n".format(
                            host=host,
                            addr=host,
                            port= int(seg.port) + cnt,
                            datadir=next_datadir(seg.datadir, cnt),
                            dbid=int(seg.dbid) + cnt,
                            content= int(seg.content) + cnt,
                            role='p'
                            ))
                        cnt += 1
开发者ID:phan-pivotal,项目名称:gpdb,代码行数:65,代码来源:test_gpexpand.py

示例6: GpinitStandby

# 需要导入模块: from mpp.lib.config import GPDBConfig [as 别名]
# 或者: from mpp.lib.config.GPDBConfig import get_hosts [as 别名]
class GpinitStandby(object):
    '''Class for gpinitstandby operations 
       Disclaimer: Some of these may repeat with the mpp/lib version'''
    def __init__(self):
        self.stdby = StandbyVerify()
        self.runmixin = StandbyRunMixin()
        self.runmixin.createdb(dbname='walrepl')        
        self.mdd = os.environ.get('MASTER_DATA_DIRECTORY')
        self.config = GPDBConfig()
        self.pgutil = GpUtility()
        self.host = socket.gethostname()
 
    def run(self, option = ''):
        '''Runs gpinitstandby and returns True if successfull '''
        gpinitstandby_cmd = 'gpinitstandby -a %s' % option
        cmd = Command(name='Running Gpinitstandby', cmdStr="%s" % gpinitstandby_cmd)
        tinctest.logger.info(" %s" % cmd)
        cmd.run(validateAfter=False)
        result = cmd.get_results()
        if result.rc != 0:
            return False
        return True

    def verify_gpinitstandby(self, primary_pid):  
        '''Verify the presence of standby in recovery mode '''
        if (self.stdby.check_gp_segment_config()) and (self.stdby.check_pg_stat_replication()) and (self.stdby.check_standby_processes())and self.compare_primary_pid(primary_pid) :
            return True
        return False

    def get_masterhost(self):
        std_sql = "select hostname from gp_segment_configuration where content=-1 and role='p';"
        master_host = PSQL.run_sql_command(std_sql, flags = '-q -t', dbname= 'postgres')
        return master_host.strip()

    def get_standbyhost(self):
        std_sql = "select hostname from gp_segment_configuration where content='-1' and role='m';"
        standby_host = PSQL.run_sql_command(std_sql, flags = '-q -t', dbname= 'postgres')
        return standby_host.strip()

    def get_filespace_location(self):
        fs_sql = "select fselocation from pg_filespace_entry where fselocation like '%fs_walrepl_a%' and fsedbid=1;"
        filespace_loc = PSQL.run_sql_command(fs_sql, flags = '-q -t', dbname= 'postgres')
        return filespace_loc.strip()

    def get_standbyhostnode(self):
        '''
        Function used to obtain the hostname of one of the segment node inorder to use it as the standby master node" 
        @return : returns the hostname of the segment node which can be used as the standby master node
        '''
        hostlist = self.config.get_hosts()
        standby = ''
        for host in hostlist:
            if host.strip() != self.host:
                standby = host.strip()
        if len(standby) > 0 :
            return standby
        else:
            tinctest.logger.error('No segment host other than master available to have remote standby')

    def get_primary_pid(self):
        pid = self.pgutil.get_pid_by_keyword(pgport=os.environ.get('PGPORT'), keyword=self.mdd)
        if int(pid) == -1:
            raise WalReplException('Unable to get pid of primary master process')
        else:
            return int(pid)

    def compare_primary_pid(self, initial_pid):
        final_pid = self.get_primary_pid()
        if initial_pid == final_pid :
            return True
        return False

    def create_dir_on_standby(self, standby, location):
        fs_cmd = "gpssh -h %s -e 'rm -rf %s; mkdir -p %s' " % (standby, location, location)
        cmd = Command(name='Make dierctory on standby before running the command', cmdStr = fs_cmd)
        tinctest.logger.info('%s' % cmd)
        cmd.run(validateAfter=True)
        result = cmd.get_results()
        if result.rc != 0:
            raise WalReplException('Unable to create directory on standby')
        else:
            return True
      
    def initstand_by_with_default(self):
        master_host = self.get_masterhost()
        gp_cmd =  "/bin/bash -c 'gpinitstandby -s %s'" % (master_host)
        logfile = open(local_path('install.log'),'w')

        child = pexpect.spawn(gp_cmd, timeout=400)
        child.logfile = logfile
        sleep(2)
        check = child.expect(['.* Enter standby filespace location for filespace pg_system .*', ' '])
        if check != 0:
            child.close()

        l_file = open(local_path('install.log'),'r')
        lines = l_file.readlines()
        for line in lines:
            if 'default: NA' in line:
                return True
#.........这里部分代码省略.........
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:103,代码来源:__init__.py


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