Ejemplo n.º 1
0
def initialize_starting_up_smr_before_redis( cluster, verbose=2, conf=None ):
    if conf == None:
        conf = {'smr_log_delete_delay':86400,
                'cm_context':''}
    if conf.has_key('smr_log_delete_delay') == False:
        conf['smr_log_delete_delay'] = 86400
    if conf.has_key('cm_context') == False:
        conf['cm_context'] = ''

    if testbase.cleanup_zookeeper_root() is not 0:
        util.log('failed to cleanup_zookeeper_root')
        return -1

    if testbase.cleanup_processes() is not 0:
        util.log('failed to cleanup_test_environment')
        return -1

    for server in cluster['servers']:
        if testbase.cleanup_pgs_log_and_ckpt( cluster['cluster_name'], server ) is not 0:
            util.log( 'failed to cleanup_pgs_data' )
            return -1

    for server in cluster['servers']:
        if testbase.request_to_start_cm( server['id'], server['cm_port'], conf['cm_context'] ) is not 0:
            util.log('failed to request_to_start_cm')
            return -1

    if testbase.initialize_cluster( cluster ) is not 0:
        util.log('failed to setup_znodes')
        return -1

    for server in cluster['servers']:
        if testbase.request_to_start_smr( server, verbose=verbose, log_delete_delay=conf['smr_log_delete_delay'] ) is not 0:
            return -1

    for server in cluster['servers']:
        if testbase.request_to_start_redis( server, check=False ) is not 0:
            return -1

    for server in cluster['servers']:
        if testbase.wait_until_finished_to_set_up_role( server ) is not 0:
            return -1

    for server in cluster['servers']:
        if testbase.request_to_start_gateway( cluster['cluster_name'], server, cluster['servers'][0] ) is not 0:
            util.log('failed to request_to_start_gateway')
            return -1

    return 0
Ejemplo n.º 2
0
    def test_large_scale_master_election( self ):
        util.print_frame()

        # initialize cluster information
        pgs_id = 10
        cluster = {
                    'cluster_name' : 'large_scale',
                    'keyspace_size' : 8192,
                    'quorum_policy' : '0:1',
                    'slots' : [],
                    'pg_id_list' : [],
                    'servers' : []
                  }
        pg_max = 32
        pgs_per_pg = 3
        for pg_id in range(pg_max):
            cluster['pg_id_list'].append(pg_id)
            cluster['slots'].append(8192 / pg_max * pg_id)
            if pg_id == pg_max - 1:
                cluster['slots'].append(8191)
            else:
                cluster['slots'].append(8192 / pg_max * (pg_id + 1) - 1)

            for pgs in range(pgs_per_pg):
                smr_base_port = 15000 + pgs_id * 20
                smr_mgmt_port = smr_base_port + 3
                gateway_port = smr_base_port + 10
                redis_port = smr_base_port + 9

                server = {}
                server['id'] = pgs_id
                pgs_id = pgs_id + 1
                server['cluster_name'] = cluster['cluster_name']
                server['ip'] = self.cluster['servers'][0]['ip']
                server['pm_name'] = self.cluster['servers'][0]['pm_name']
                server['cm_port'] = None
                server['pg_id'] = pg_id
                server['smr_base_port'] = smr_base_port
                server['smr_mgmt_port'] = smr_mgmt_port
                server['gateway_port'] = gateway_port
                server['redis_port'] = redis_port
                server['zk_port'] = 2181

                cluster['servers'].append(server)

        # send initialize commands to confmaster
        testbase.initialize_cluster(cluster, self.leader_cm)

        # set up pgs binaries
        try:
            for server in cluster['servers']:
                id = server['id']

                util.log('copy binaries, server_id=%d' % id)
                util.copy_smrreplicator( id )
                util.copy_gw( id )
                util.copy_redis_server( id )
                util.copy_cluster_util( id )

        except IOError as e:
            util.log(e)
            util.log('Error: can not find file or read data')
            self.assertEqual(0, 1, 'Error: can not find file or read data')

        except:
            util.log('Error: file open error.')

        # cleanup servers`s directories
        for server in cluster['servers']:
            ret = testbase.cleanup_pgs_log_and_ckpt( cluster['cluster_name'], server )
            self.assertEqual(ret, 0, 'failed to cleanup_test_environment, id=%d' % server['id'])

        # start pgs
        for server in cluster['servers']:
            ret = testbase.request_to_start_smr( server )
            self.assertEqual(ret, 0, 'failed to request_to_start_smr, id=%d' % server['id'])

        for server in cluster['servers']:
            ret = testbase.request_to_start_redis( server, check=False )
            self.assertEqual(ret, 0, 'failed to request_to_start_smr, id=%d' % server['id'])

        for server in cluster['servers']:
            ret = testbase.wait_until_finished_to_set_up_role(server)
            self.assertEqual(ret, 0, 'failed to role set up, id=%d' % server['id'])

        for i in range(4):
            server = cluster['servers'][i]
            ret = testbase.request_to_start_gateway( cluster['cluster_name'], server, self.leader_cm )
            self.assertEqual(ret, 0, 'failed to request_to_start_gateway, id=%d' % server['id'])

        clusters = cluster_ls()
        self.assertNotEqual(len(clusters), 0, 'There is no clsuter.')

        ok = True
        for c in clusters:
            if not util.check_cluster(str(c), self.leader_cm['ip'], self.leader_cm['cm_port'], check_quorum=True):
                ok = False

        self.assertEqual(ok, True, 'failed to initlize roles of pgs')
Ejemplo n.º 3
0
    def test_large_scale_master_election(self):
        util.print_frame()

        # initialize cluster information
        pgs_id = 10
        cluster = {
            'cluster_name': 'large_scale',
            'keyspace_size': 8192,
            'quorum_policy': '0:1',
            'slots': [],
            'pg_id_list': [],
            'servers': []
        }
        pg_max = 32
        pgs_per_pg = 3
        for pg_id in range(pg_max):
            cluster['pg_id_list'].append(pg_id)
            cluster['slots'].append(8192 / pg_max * pg_id)
            if pg_id == pg_max - 1:
                cluster['slots'].append(8191)
            else:
                cluster['slots'].append(8192 / pg_max * (pg_id + 1) - 1)

            for pgs in range(pgs_per_pg):
                smr_base_port = 15000 + pgs_id * 20
                smr_mgmt_port = smr_base_port + 3
                gateway_port = smr_base_port + 10
                redis_port = smr_base_port + 9

                server = {}
                server['id'] = pgs_id
                pgs_id = pgs_id + 1
                server['cluster_name'] = cluster['cluster_name']
                server['ip'] = self.cluster['servers'][0]['ip']
                server['pm_name'] = self.cluster['servers'][0]['pm_name']
                server['cm_port'] = None
                server['pg_id'] = pg_id
                server['smr_base_port'] = smr_base_port
                server['smr_mgmt_port'] = smr_mgmt_port
                server['gateway_port'] = gateway_port
                server['redis_port'] = redis_port
                server['zk_port'] = 2181

                cluster['servers'].append(server)

        # send initialize commands to confmaster
        testbase.initialize_cluster(cluster, self.leader_cm)

        # set up pgs binaries
        try:
            for server in cluster['servers']:
                id = server['id']

                util.log('copy binaries, server_id=%d' % id)
                util.copy_smrreplicator(id)
                util.copy_gw(id)
                util.copy_redis_server(id)
                util.copy_cluster_util(id)

        except IOError as e:
            util.log(e)
            util.log('Error: can not find file or read data')
            self.assertEqual(0, 1, 'Error: can not find file or read data')

        except:
            util.log('Error: file open error.')

        # cleanup servers`s directories
        for server in cluster['servers']:
            ret = testbase.cleanup_pgs_log_and_ckpt(cluster['cluster_name'],
                                                    server)
            self.assertEqual(
                ret, 0,
                'failed to cleanup_test_environment, id=%d' % server['id'])

        # start pgs
        for server in cluster['servers']:
            ret = testbase.request_to_start_smr(server)
            self.assertEqual(
                ret, 0, 'failed to request_to_start_smr, id=%d' % server['id'])

        for server in cluster['servers']:
            ret = testbase.request_to_start_redis(server, check=False)
            self.assertEqual(
                ret, 0, 'failed to request_to_start_smr, id=%d' % server['id'])

        for server in cluster['servers']:
            ret = testbase.wait_until_finished_to_set_up_role(server)
            self.assertEqual(ret, 0,
                             'failed to role set up, id=%d' % server['id'])

        for i in range(4):
            server = cluster['servers'][i]
            ret = testbase.request_to_start_gateway(cluster['cluster_name'],
                                                    server, self.leader_cm)
            self.assertEqual(
                ret, 0,
                'failed to request_to_start_gateway, id=%d' % server['id'])

        clusters = cluster_ls()
        self.assertNotEqual(len(clusters), 0, 'There is no clsuter.')

        ok = True
        for c in clusters:
            if not util.check_cluster(str(c),
                                      self.leader_cm['ip'],
                                      self.leader_cm['cm_port'],
                                      check_quorum=True):
                ok = False

        self.assertEqual(ok, True, 'failed to initlize roles of pgs')