本文整理汇总了Python中util.check_cluster函数的典型用法代码示例。如果您正苦于以下问题:Python check_cluster函数的具体用法?Python check_cluster怎么用?Python check_cluster使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_cluster函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: unblock_network
def unblock_network(cluster, mgmt_ip, mgmt_port, final_state):
# Unblock
if util.iptables_drop('D', '127.0.0.100') == False:
util.log('delete a bloking role to iptables fail.')
return False
# Check cluster state
for i in range(3):
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, final_state)
time.sleep(1)
return True
开发者ID:LichKing-lee,项目名称:nbase-arc,代码行数:12,代码来源:test_network_isolation.py
示例2: unblock_network
def unblock_network(cluster, mgmt_ip, mgmt_port, final_state):
# Unblock
out = util.sudo('iptables -D OUTPUT -d 127.0.0.100 -j DROP')
if out.succeeded == False:
util.log('delete a bloking role to iptables fail. output:%s' % out)
return False
# Check cluster state
for i in range(3):
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, final_state)
time.sleep(1)
return True
开发者ID:cl9200,项目名称:nbase-arc,代码行数:13,代码来源:test_network_isolation.py
示例3: block_network
def block_network(cluster, mgmt_ip, mgmt_port):
# Block
if util.iptables_drop('A', '127.0.0.100') == False:
util.log('add a bloking role to iptables fail.')
return False
for i in range(4):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
for i in range(2):
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port)
time.sleep(1)
return True
开发者ID:LichKing-lee,项目名称:nbase-arc,代码行数:16,代码来源:test_network_isolation.py
示例4: block_network
def block_network(cluster, mgmt_ip, mgmt_port):
# Block
out = util.sudo('iptables -A OUTPUT -d 127.0.0.100 -j DROP')
if out.succeeded == False:
util.log('add a bloking role to iptables fail. output:%s' % out)
return False
for i in range(4):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
for i in range(2):
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port)
time.sleep(1)
return True
开发者ID:cl9200,项目名称:nbase-arc,代码行数:17,代码来源:test_network_isolation.py
示例5: __check_cluster_state
def __check_cluster_state(self):
leader_cm = classify_cm(self.__servers)['leader'][0]
for cluster in self.__cmi['cluster']:
ret = util.await(30)(
lambda x: x,
lambda : util.check_cluster(cluster['clusterName'].encode('ascii'), leader_cm['ip'], leader_cm['port'], None, True))
if ret == False:
return False
return True
开发者ID:LichKing-lee,项目名称:nbase-arc,代码行数:9,代码来源:config_checker.py
示例6: test_4_mgmt_is_isolated_with_red_failover
def test_4_mgmt_is_isolated_with_red_failover(self):
util.print_frame()
util.iptables_print_list()
cluster = filter(lambda x: x['cluster_name'] == 'network_isolation_cluster_1', config.clusters)[0]
util.log(util.json_to_str(cluster))
self.leader_cm = cluster['servers'][0]
# MGMT
mgmt_ip = cluster['servers'][0]['real_ip']
mgmt_port = cluster['servers'][0]['cm_port']
# Create cluster
conf_checker = default_cluster.initialize_starting_up_smr_before_redis( cluster )
self.assertIsNotNone(conf_checker, 'failed to initialize cluster')
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port)
# Master must be the first pgs, cluster['servers'][0].
to_be_master = cluster['servers'][0]
m = util.get_server_by_role_and_pg(cluster['servers'], 'master', to_be_master['pg_id'])
master_id = -1
if m['id'] != to_be_master['id']:
try_cnt = 0
while master_id != to_be_master['id'] and try_cnt < 20:
master_id = util.role_change(cluster['servers'][0], cluster['cluster_name'], to_be_master['id'])
try_cnt += 1
time.sleep(1)
self.assertEquals(master_id, to_be_master['id'], 'change %d to a master fail' % to_be_master['id'])
# Print initial state of cluster
util.log('\n\n\n ### INITIAL STATE OF CLUSTER ### ')
initial_state = []
self.assertTrue(util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, initial_state, check_quorum=True), 'failed to check cluster state')
# Set SMR option (slave_idle_timeout)
util.log('\n\n\n ### Set SMR option ###')
for s in cluster['servers']:
t = telnet.Telnet('SMR%d' % s['id'])
self.assertEqual(t.connect(s['ip'], s['smr_mgmt_port']), 0,
'Failed to connect to smr. ADDR=%s:%d' % (s['ip'], s['smr_mgmt_port']))
cmd = 'confset slave_idle_timeout_msec 18000'
util.log('[%s:%d] >> %s' % (s['ip'], s['smr_mgmt_port'], cmd))
t.write('confset slave_idle_timeout_msec 18000\r\n')
reply = t.read_until('\r\n').strip()
util.log('[%s:%d] << %s' % (s['ip'], s['smr_mgmt_port'], reply))
self.assertEqual(reply, '+OK', 'Failed to set slave_idle_timeout, REPLY=%s' % reply)
# Network isolation test
for loop_cnt in range(3):
# Block network
util.log('\n\n\n ### BLOCK NETWORK, %d ### ' % loop_cnt)
for s in cluster['servers']:
self.assertTrue(util.iptables_drop('A', '127.0.0.100', s['smr_mgmt_port']), 'add a bloking role to iptables fail.')
for i in range(4):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
ok = False
for i in range(7):
isolated_states = []
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, isolated_states, check_quorum=True)
time.sleep(1)
state_transition_done = True
for s in isolated_states:
if s['ip'] != '127.0.0.100':
continue
if s['active_role'] != '?' or s['mgmt_role'] != 'N':
state_transition_done = False
if state_transition_done :
ok = True
break
time.sleep(1)
self.assertTrue(ok, 'Fail, state transition')
pgs_list = util.get_pgs_info_list(mgmt_ip, mgmt_port, cluster)
reds = filter(lambda x: x['color'] == 'RED', pgs_list)
# Shutdown
server = cluster['servers'][random.choice(reds)['pgs_id']]
util.log( 'shutdown pgs%d while hanging.' % server['id'] )
ret = testbase.request_to_shutdown_smr( server )
self.assertEqual( ret, 0, 'failed to shutdown smr. id:%d' % server['id'] )
ret = testbase.request_to_shutdown_redis( server )
self.assertEqual( ret, 0, 'failed to shutdown redis. id:%d' % server['id'] )
# Check state F
max_try = 20
expected = 'F'
for i in range( 0, max_try):
util.log('MGMT_IP:%s, MGMT_PORT:%d' % (mgmt_ip, mgmt_port))
state = util._get_smr_state( server['id'], cluster['cluster_name'], mgmt_ip, mgmt_port )
if expected == state:
#.........这里部分代码省略.........
开发者ID:LichKing-lee,项目名称:nbase-arc,代码行数:101,代码来源:test_network_isolation.py
示例7: test_4_role_change_with_failover
#.........这里部分代码省略.........
r = ''
expected = 'N'
for fc_cnt in xrange(20):
r = util.get_smr_role_of_cm(target, self.leader_cm)
if r == expected:
break
time.sleep(0.5)
self.assertEquals(r, expected, 'failure detection error.')
running_servers = []
for s in self.cluster['servers']:
if s != target:
running_servers.append(s)
# Get old timestamp
old_timestamps = {}
for s in running_servers:
ts = util.get_timestamp_of_pgs(s)
old_timestamps[s['id']] = ts
# Start load generator
self.load_gen_list = {}
util.log('start load generator')
for i in range(self.max_load_generator):
ip, port = util.get_rand_gateway(self.cluster)
load_gen = load_generator.LoadGenerator(i, ip, port)
load_gen.start()
self.load_gen_list[i] = load_gen
m, s1, s2 = util.get_mss(self.cluster)
self.assertNotEqual(m, None, 'master is None.')
self.assertNotEqual(s1, None, 'slave1 is None.')
# Role change
master_id = util.role_change(self.leader_cm, self.cluster['cluster_name'], s1['id'])
self.assertNotEqual(master_id, -1, 'role_change failed')
util.log("States (after role change)")
util.log_server_state(self.cluster)
# Check - get new timestamp
new_timestamps= {}
for s in running_servers:
ts = util.get_timestamp_of_pgs( s )
new_timestamps[s['id']] = ts
# Check - compare old timestamps and new timestamps
for s in running_servers:
old_ts = old_timestamps[s['id']]
new_ts = new_timestamps[s['id']]
self.assertNotEqual(old_ts, new_ts, 'Timestamp of a running server has not changed. %d->%d' % (old_ts, new_ts))
# Check quorum
m = self.cluster['servers'][master_id]
expected = 1
ok = self.__check_quorum(m, expected)
self.assertTrue(ok, 'unexpected quorum(after role change). expected:%s' % (expected))
# recovery
util.log('recovery pgs%d(%s:%d)' % (target['id'], target['ip'], target['smr_base_port']))
ret = testbase.request_to_start_smr( target )
self.assertEqual( ret, 0, 'failed to start smr' )
util.log('start smr-replicator done')
ret = testbase.request_to_start_redis( target, 60 )
self.assertEqual( ret, 0, 'failed to start redis' )
util.log('start redis-arc done')
ret = testbase.wait_until_finished_to_set_up_role( target, max_try=300)
self.assertEquals( ret, 0, 'failed to role change. smr_id:%d' % (target['id']) )
util.log("States (after recovery)")
util.log_server_state(self.cluster)
# Check cluster state
normal_state = False
for i in xrange(20):
normal_state = util.check_cluster(self.cluster['cluster_name'], self.leader_cm['ip'], self.leader_cm['cm_port'], check_quorum=True)
if normal_state:
break
time.sleep(0.5)
self.assertTrue(normal_state, "Unstable cluster state")
# Check quorum
expected = 2
ok = self.__check_quorum(m, expected)
self.assertTrue(ok, 'unexpected quorum(after recovery). expected:%s' % (expected))
# Cheeck Consistency
util.log('stop load generator')
for i in range(self.max_load_generator):
self.load_gen_list[i].quit()
for i in range(self.max_load_generator):
self.load_gen_list[i].join()
self.assertTrue(self.load_gen_list[i].isConsistent(), 'Inconsistent after migration')
self.load_gen_list.pop(i, None)
loop_cnt += 1
return 0
开发者ID:cl9200,项目名称:nbase-arc,代码行数:101,代码来源:test_maintenance.py
示例8: test_2_some_pgs_is_isolated
def test_2_some_pgs_is_isolated(self):
util.print_frame()
out = util.sudo('iptables -L')
util.log('====================================================================')
util.log('out : %s' % out)
util.log('out.return_code : %d' % out.return_code)
util.log('out.stderr : %s' % out.stderr)
util.log('out.succeeded : %s' % out.succeeded)
# Add forwarding role (127.0.0.100 -> 127.0.0.1)
out = util.sudo('iptables -t nat -A OUTPUT -d 127.0.0.100 -p tcp -j DNAT --to-destination 127.0.0.1')
self.assertTrue(out.succeeded, 'add a forwarding role to iptables fail. output:%s' % out)
out = util.sudo('iptables -t nat -A PREROUTING -d 127.0.0.100 -p tcp -j DNAT --to-destination 127.0.0.1')
self.assertTrue(out.succeeded, 'add a forwarding role to iptables fail. output:%s' % out)
cluster = filter(lambda x: x['cluster_name'] == 'network_isolation_cluster_2', config.clusters)[0]
util.log(util.json_to_str(cluster))
# MGMT
mgmt_ip = cluster['servers'][0]['real_ip']
mgmt_port = cluster['servers'][0]['cm_port']
# Create cluster
ret = default_cluster.initialize_starting_up_smr_before_redis( cluster )
self.assertEqual(0, ret, 'failed to TestMaintenance.initialize')
# Place master on virtual ip address in order to cause master election.
pg_id = 0
m = util.get_server_by_role_and_pg(cluster['servers'], 'master', pg_id)
s = util.get_server_by_role_and_pg(cluster['servers'], 'slave', pg_id)
if m.has_key('ip') == True and m.has_key('real_ip') == False:
ret = util.role_change(cluster['servers'][0], cluster['cluster_name'], s['id'])
self.assertNotEquals(ret, -1, 'change %d to a master fail' % s['id'])
# Print initial state of cluster
util.log('\n\n\n ### INITIAL STATE OF CLUSTER ### ')
initial_state = []
self.assertTrue(util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, initial_state, check_quorum=True), 'failed to check cluster state')
# Network isolation test
for cnt in range(3):
# Block network
util.log('\n\n\n ### BLOCK NETWORK, %d ### ' % cnt)
out = util.sudo('iptables -A OUTPUT -d 127.0.0.100 -j DROP')
self.assertTrue(out.succeeded, 'add a bloking role to iptables fail. output:%s' % out)
for i in range(4):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
ok = False
for i in range(7):
isolated_states = []
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, isolated_states, check_quorum=True)
time.sleep(1)
state_transition_done = True
for s in isolated_states:
if s['pgs_id'] == 1:
continue
if s['active_role'] != '?' or s['mgmt_role'] != 'N':
state_transition_done = False
if state_transition_done :
ok = True
break
time.sleep(1)
self.assertTrue(ok, 'Fail, state transition')
# Unblock network
util.log('\n\n\n ### UNBLOCK NETWORK, %d ### ' % cnt)
out = util.sudo('iptables -D OUTPUT -d 127.0.0.100 -j DROP')
self.assertTrue(out.succeeded, 'delete a bloking role to iptables fail. output:%s' % out)
# Check cluster state
ok = False
for i in range(7):
final_state = []
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, final_state, check_quorum=True)
state_consistency = True
for s in final_state:
if s['pgs_id'] == 1:
continue
if s['active_role'] != s['mgmt_role']:
state_consistency = False
if state_consistency:
ok = True
break
time.sleep(1)
self.assertTrue(ok, 'Fail, state consistency')
# Check state
self.assertNotEqual(initial_state, None, 'initial_state is None')
#.........这里部分代码省略.........
开发者ID:ducky-hong,项目名称:nbase-arc,代码行数:101,代码来源:test_network_isolation.py
示例9: test_5_mgmt_is_isolated_with_master_failover
def test_5_mgmt_is_isolated_with_master_failover(self):
util.print_frame()
out = util.sudo('iptables -L')
util.log('====================================================================')
util.log('out : %s' % out)
util.log('out.return_code : %d' % out.return_code)
util.log('out.stderr : %s' % out.stderr)
util.log('out.succeeded : %s' % out.succeeded)
# Add forwarding role (127.0.0.100 -> 127.0.0.1)
out = util.sudo('iptables -t nat -A OUTPUT -d 127.0.0.100 -p tcp -j DNAT --to-destination 127.0.0.1')
self.assertTrue(out.succeeded, 'add a forwarding role to iptables fail. output:%s' % out)
out = util.sudo('iptables -t nat -A PREROUTING -d 127.0.0.100 -p tcp -j DNAT --to-destination 127.0.0.1')
self.assertTrue(out.succeeded, 'add a forwarding role to iptables fail. output:%s' % out)
cluster = filter(lambda x: x['cluster_name'] == 'network_isolation_cluster_1', config.clusters)[0]
util.log(util.json_to_str(cluster))
self.leader_cm = cluster['servers'][0]
# MGMT
mgmt_ip = cluster['servers'][0]['real_ip']
mgmt_port = cluster['servers'][0]['cm_port']
# Create cluster
ret = default_cluster.initialize_starting_up_smr_before_redis( cluster )
self.assertEqual(0, ret, 'failed to TestMaintenance.initialize')
# Print initial state of cluster
util.log('\n\n\n ### INITIAL STATE OF CLUSTER ### ')
initial_state = []
self.assertTrue(util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, initial_state, check_quorum=True), 'failed to check cluster state')
# Network isolation test
for loop_cnt in range(3):
master, slave1, slave2 = util.get_mss(cluster)
self.assertNotEquals(master, None, 'there is no master')
self.assertNotEquals(slave1, None, 'there is no slave1')
self.assertNotEquals(slave2, None, 'there is no slave2')
# Block network
util.log('\n\n\n ### BLOCK NETWORK, %d ### ' % loop_cnt)
out = util.sudo('iptables -A OUTPUT -d 127.0.0.100 -j DROP')
self.assertTrue(out.succeeded, 'add a bloking role to iptables fail. output:%s' % out)
for i in range(4):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
ok = False
for i in range(10):
isolated_states = []
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, isolated_states, check_quorum=True)
time.sleep(1)
state_transition_done = True
for s in isolated_states:
if s['ip'] != '127.0.0.100':
continue
if s['active_role'] != '?' or s['mgmt_role'] != 'N':
state_transition_done = False
if state_transition_done :
ok = True
break
time.sleep(1)
self.assertTrue(ok, 'Fail, state transition')
# Shutdown master
util.log( 'shutdown pgs%d while hanging.' % master['id'] )
ret = testbase.request_to_shutdown_smr( master )
self.assertEqual( ret, 0, 'failed to shutdown smr. id:%d' % master['id'] )
ret = testbase.request_to_shutdown_redis( master )
self.assertEqual( ret, 0, 'failed to shutdown redis. id:%d' % master['id'] )
# Check state F
max_try = 20
expected = 'F'
for i in range( 0, max_try):
util.log('MGMT_IP:%s, MGMT_PORT:%d' % (mgmt_ip, mgmt_port))
state = util._get_smr_state( master['id'], cluster['cluster_name'], mgmt_ip, mgmt_port )
if expected == state:
break;
time.sleep( 1 )
self.assertEqual( expected , state,
'master%d - state:%s, expected:%s' % (master['id'], state, expected) )
util.log( 'succeeded : pgs%d state changed to F.' % master['id'] )
# Unblock network
util.log('\n\n\n ### UNBLOCK NETWORK, %d ### ' % loop_cnt)
out = util.sudo('iptables -D OUTPUT -d 127.0.0.100 -j DROP')
self.assertTrue(out.succeeded, 'delete a bloking role to iptables fail. output:%s' % out)
# Check cluster state
ok = False
for i in range(7):
#.........这里部分代码省略.........
开发者ID:ducky-hong,项目名称:nbase-arc,代码行数:101,代码来源:test_network_isolation.py
示例10: test_all_pgs_hang
def test_all_pgs_hang( self ):
util.print_frame()
self.setup_test_cluster( self.cluster_3copy )
# get gateway info
ip, port = util.get_rand_gateway( self.cluster )
gw = gateway_mgmt.Gateway( self.cluster['servers'][0]['id'] )
ret = gw.connect( ip, port )
self.assertEqual( ret, 0, 'failed to connect to gateway, %s:%d' % (ip, port) )
# set values
for i in range( 0, 10000 ):
cmd = 'set %s%d %d\r\n' % (self.key_base, i, i)
gw.write( cmd )
res = gw.read_until( '\r\n' )
self.assertEqual( res, '+OK\r\n', 'failed to set values. cmd:%s, res:%s' % (cmd, res) )
# get master, slave1, slave2
m, s1, s2 = util.get_mss( self.cluster )
self.assertNotEqual( m, None, 'master is None.' )
self.assertNotEqual( s1, None, 'slave1 is None.' )
self.assertNotEqual( s2, None, 'slave2 is None.' )
util.log( 'server state before hang' )
util.log_server_state( self.cluster )
# hang
smr_master = smr_mgmt.SMR( m['id'] )
ret = smr_master.connect( m['ip'], m['smr_mgmt_port'] )
self.assertEqual( ret, 0, 'failed to connect to master. %s:%d' % (m['ip'], m['smr_mgmt_port']) )
smr_slave1 = smr_mgmt.SMR( s1['id'] )
ret = smr_slave1.connect( s1['ip'], s1['smr_mgmt_port'] )
self.assertEqual( ret, 0, 'failed to connect to master. %s:%d' % (s1['ip'], s1['smr_mgmt_port']) )
smr_slave2 = smr_mgmt.SMR( s2['id'] )
ret = smr_slave2.connect( s2['ip'], s2['smr_mgmt_port'] )
self.assertEqual( ret, 0, 'failed to connect to master. %s:%d' % (s2['ip'], s2['smr_mgmt_port']) )
m_ts = util.get_timestamp_of_pgs( m )
s1_ts = util.get_timestamp_of_pgs( s1 )
s2_ts = util.get_timestamp_of_pgs( s2 )
smr_master.write( 'fi delay sleep 1 8000\r\n' )
reply = smr_master.read_until( '\r\n', 1 )
if reply != None and reply.find('-ERR not supported') != -1:
self.assertEqual( 0, 1, 'make sure that smr has compiled with gcov option.' )
smr_slave1.write( 'fi delay sleep 1 8000\r\n' )
smr_slave2.write( 'fi delay sleep 1 8000\r\n' )
time.sleep( 10 )
# check consistency
ok = False
for try_cnt in xrange(20):
ok = util.check_cluster(self.cluster['cluster_name'], self.mgmt_ip, self.mgmt_port)
if ok:
break
time.sleep(0.5)
self.assertTrue(ok, 'Unstable cluster state')
util.log( 'server state transition after hang' )
util.log_server_state( self.cluster )
redis0 = redis_mgmt.Redis( m['id'] )
ret = redis0.connect( m['ip'], m['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis(%s:%d).' % (m['ip'], m['redis_port']) )
# set values
for i in range( 10000, 20000 ):
cmd = 'set %s%d %d\r\n' % (self.key_base, i, i)
redis0 .write( cmd )
res = redis0.read_until( '\r\n' )
self.assertEqual( res, '+OK\r\n', 'failed to set values. cmd:%s, res:%s' % (cmd, res) )
redis1 = redis_mgmt.Redis( s1['id'] )
ret = redis1.connect( s1['ip'], s1['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis(%s:%d).' % (s1['ip'], s1['redis_port']) )
redis2 = redis_mgmt.Redis( s2['id'] )
ret = redis2.connect( s2['ip'], s2['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis(%s:%d).' % (s2['ip'], s2['redis_port']) )
# check new values (m)
for i in range( 10000, 20000 ):
cmd = 'get %s%d\r\n' % (self.key_base, i)
redis0.write( cmd )
redis0.read_until( '\r\n' )
res = redis0.read_until( '\r\n' )
self.assertEqual( res, '%d\r\n' % i, 'failed to get values from redis(id:%d). %s != %d' % (m['id'], res, i) )
# check new values (s1)
for i in range( 10000, 20000 ):
cmd = 'get %s%d\r\n' % (self.key_base, i)
redis1.write( cmd )
redis1.read_until( '\r\n' )
res = redis1.read_until( '\r\n' )
self.assertEqual( res, '%d\r\n' % i, 'failed to get values from redis(id:%d). %s != %d' % (s1['id'], res[:-2], i) )
# check new values (s2)
#.........这里部分代码省略.........
开发者ID:iloview,项目名称:nbase-arc,代码行数:101,代码来源:test_pgs_hanging.py
示例11: slave_failover_while_hang
def slave_failover_while_hang( self ):
util.print_frame()
# get gateway info
ip, port = util.get_rand_gateway( self.cluster )
gw = gateway_mgmt.Gateway( self.cluster['servers'][0]['id'] )
ret = gw.connect( ip, port )
self.assertEqual( ret, 0, 'failed to connect to gateway, %s:%d' % (ip, port) )
# set values
for i in range( 0, 10000 ):
cmd = 'set %s%d %d\r\n' % (self.key_base, i, i)
gw.write( cmd )
res = gw.read_until( '\r\n' )
self.assertEqual( res, '+OK\r\n', 'failed to set values. cmd:%s, res:%s' % (cmd, res) )
# get master, slave1, slave2
if len(self.cluster['servers']) == 3:
m, s1, s2 = util.get_mss( self.cluster )
self.assertNotEqual( m, None, 'master is None.' )
self.assertNotEqual( s1, None, 'slave1 is None.' )
self.assertNotEqual( s2, None, 'slave2 is None.' )
else:
m, s1 = util.get_mss( self.cluster )
self.assertNotEqual( m, None, 'master is None.' )
self.assertNotEqual( s1, None, 'slave1 is None.' )
util.log( 'server state before hang' )
util.log_server_state( self.cluster )
self.failover_while_hang( s1 )
util.log( 'server state transition after hang' )
util.log_server_state( self.cluster )
redis1 = redis_mgmt.Redis( s1['id'] )
ret = redis1.connect( s1['ip'], s1['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis(%s:%d).' % (s1['ip'], s1['redis_port']) )
# set new values
for i in range( 10000, 20000 ):
cmd = 'set %s%d %d\r\n' % (self.key_base, i, i)
redis1.write( cmd )
res = redis1.read_until( '\r\n' )
self.assertEqual( res, '+OK\r\n', 'failed to set values to redis1. cmd:%s, res:%s' % (cmd[:-2], res) )
if len(self.cluster['servers']) == 3:
redis2 = redis_mgmt.Redis( s2['id'] )
ret = redis2.connect( s2['ip'], s2['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis(%s:%d).' % (s2['ip'], s2['redis_port']) )
# check new values
for i in range( 10000, 20000 ):
cmd = 'get %s%d\r\n' % (self.key_base, i)
redis2.write( cmd )
redis2.read_until( '\r\n' )
res = redis2.read_until( '\r\n' )
self.assertEqual( res, '%d\r\n' % i, 'failed to get values from redis2. %s != %d' % (res, i) )
util.log( 'succeeded : check values with set/get operations with pgs%d and pgs%d.' % (s1['id'], s2['id']) )
redis0 = redis_mgmt.Redis( m['id'] )
ret = redis0.connect( m['ip'], m['redis_port'] )
self.assertEquals( ret, 0, 'failed to connect to redis(%s:%d).' % (m['ip'], m['redis_port']) )
# check new values
for i in range( 10000, 20000 ):
cmd = 'get %s%d\r\n' % (self.key_base, i)
redis0.write( cmd )
redis0.read_until( '\r\n' )
res = redis0.read_until( '\r\n' )
self.assertEqual( res, '%d\r\n' % i, 'failed to get values from redis2. %s != %d' % (res[:-2], i) )
# check consistency
self.assertEqual(util.check_cluster(self.cluster['cluster_name'], self.mgmt_ip, self.mgmt_port), True, 'role consistency fail')
return 0
开发者ID:iloview,项目名称:nbase-arc,代码行数:75,代码来源:test_pgs_hanging.py
示例12: test_7_dirty_network_fi
def test_7_dirty_network_fi(self):
util.print_frame()
clnts = []
try:
util.iptables_print_list()
# Add forwarding role
self.assertTrue(util.iptables_redirect('A', '127.0.0.100', '127.0.0.1'), 'add a forwarding role to iptables fail.')
cluster_name = 'network_isolation_cluster_1'
cluster = filter(lambda x: x['cluster_name'] == cluster_name, config.clusters)[0]
util.log(util.json_to_str(cluster))
self.leader_cm = cluster['servers'][0]
# MGMT
mgmt_ip = cluster['servers'][0]['real_ip']
mgmt_port = cluster['servers'][0]['cm_port']
# Create cluster
conf_checker = default_cluster.initialize_starting_up_smr_before_redis( cluster,
conf={'cm_context':'applicationContext-fi.xml'})
self.assertIsNotNone(conf_checker, 'failed to initialize cluster')
# Print initial state of cluster
util.log('\n\n\n ### INITIAL STATE OF CLUSTER ### ')
initial_state = []
self.assertTrue(util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, initial_state, check_quorum=True), 'failed to check cluster state')
# Start crc16 client
for s in cluster['servers']:
c = load_generator_crc16.Crc16Client(s['id'], s['ip'], s['redis_port'], 600, verbose=False)
c.start()
clnts.append(c)
# Network isolation test
cmfi = fi_confmaster.ConfmasterWfFi(['ra', 'me', 'yj', 'bj', 'mg'],
['lconn', 'slave', 'master', 'setquorum'], [True, False], 1)
for fi in cmfi:
# Block network
util.log('\n\n\n ### BLOCK NETWORK, %s ### ' % str(fi))
ret = block_network(cluster, mgmt_ip, mgmt_port)
self.assertTrue(ret, '[%s] failed to block network.' % str(fi))
for i in xrange(4):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
ok = False
for i in xrange(10):
isolated_states = []
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, isolated_states, check_quorum=True)
state_transition_done = True
for s in isolated_states:
if s['ip'] != '127.0.0.100':
continue
if s['active_role'] != '?' or s['mgmt_role'] != 'N':
state_transition_done = False
if state_transition_done:
ok = True
break
time.sleep(1)
self.assertTrue(ok, 'Fail, state transition')
# Fault injection
try:
self.assertTrue(fi_confmaster.fi_add(fi, 1, mgmt_ip, mgmt_port),
"Confmaster command fail. fi: %s" % str(fi))
except ValueError as e:
self.fail("Confmaster command error. cmd: \"%s\", reply: \"%s\"" % (cmd, reply))
# Unblock network
util.log('\n\n\n ### UNBLOCK NETWORK, %s ### ' % str(fi))
ret = unblock_network(cluster, mgmt_ip, mgmt_port, None)
self.assertTrue(ret, '[%s] failed to unblock network.' % str(fi))
for i in xrange(4):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
ok = False
for i in xrange(10):
isolated_states = []
ok = util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, isolated_states, check_quorum=True)
if ok:
break
time.sleep(1)
self.assertTrue(ok, '[%s] Fail. unstable cluster.' % str(fi))
check_cluster = False
# 'bj', 'slave'
if fi[0] == 'bj' and fi[1] == 'slave':
#.........这里部分代码省略.........
开发者ID:LichKing-lee,项目名称:nbase-arc,代码行数:101,代码来源:test_network_isolation.py
示例13: master_and_slave_hang
def master_and_slave_hang( self ):
# get gateway info
ip, port = util.get_rand_gateway( self.cluster )
gw = gateway_mgmt.Gateway( self.cluster['servers'][0]['id'] )
ret = gw.connect( ip, port )
self.assertEqual( ret, 0, 'failed to connect to gateway, %s:%d' % (ip, port) )
# set values
for i in range( 0, 10000 ):
cmd = 'set %s%d %d\r\n' % (self.key_base, i, i)
gw.write( cmd )
res = gw.read_until( '\r\n' )
self.assertEqual( res, '+OK\r\n', 'failed to set values. cmd:%s, res:%s' % (cmd, res) )
# get master, slave1, slave2
if len(self.cluster['servers']) == 3:
m, s1, s2 = util.get_mss( self.cluster )
self.assertNotEqual( m, None, 'master is None.' )
self.assertNotEqual( s1, None, 'slave1 is None.' )
self.assertNotEqual( s2, None, 'slave2 is None.' )
else:
m, s1 = util.get_mss( self.cluster )
self.assertNotEqual( m, None, 'master is None.' )
self.assertNotEqual( s1, None, 'slave1 is None.' )
util.log( 'server state before hang' )
util.log_server_state( self.cluster )
# hang
smr_master = smr_mgmt.SMR( m['id'] )
ret = smr_master.connect( m['ip'], m['smr_mgmt_port'] )
self.assertEqual( ret, 0, 'failed to connect to master. %s:%d' % (m['ip'], m['smr_mgmt_port']) )
smr_slave = smr_mgmt.SMR( s1['id'] )
ret = smr_slave.connect( s1['ip'], s1['smr_mgmt_port'] )
self.assertEqual( ret, 0, 'failed to connect to master. %s:%d' % (s1['ip'], s1['smr_mgmt_port']) )
smr_master.write( 'fi delay sleep 1 10000\r\n' )
reply = smr_master.read_until( '\r\n', 1 )
if reply != None and reply.find('-ERR not supported') != -1:
self.assertEqual( 0, 1, 'make sure that smr has compiled with gcov option.' )
smr_slave.write( 'fi delay sleep 1 10000\r\n' )
util.log( 'server state transition after hang' )
util.log_server_state( self.cluster )
time.sleep( 5 )
if len(self.cluster['servers']) == 3:
# wait for forced master election
success = True
for i in range( 15 ):
state = []
util.check_cluster(self.cluster['cluster_name'], self.leader_cm['ip'], self.leader_cm['cm_port'], state)
s2_state = filter(lambda s: s['pgs_id'] == s2['id'], state)[0]
role = s2_state['active_role']
if role != 'M':
success = False
break
time.sleep( 1 )
util.log( '' )
util.log( 'It expects that pgs2 is a master. PG.COPY: 3, PG.Q: 2' )
util.log( '' )
util.log_server_state( self.cluster )
self.assertEqual( success, True, 'failed to check copy-quorum' )
ok = False
for i in xrange(10):
ok = util.check_cluster(self.cluster['cluster_name'], self.leader_cm['ip'], self.leader_cm['cm_port'])
if ok:
break
self.assertTrue( ok, 'Cluster state is not normal!' )
redis2 = redis_mgmt.Redis( s2['id'] )
ret = redis2.connect( s2['ip'], s2['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis(%s:%d).' % (s2['ip'], s2['redis_port']) )
# set new values
for i in range( 10000, 20000 ):
cmd = 'set %s%d %d\r\n' % (self.key_base, i, i)
redis2.write( cmd )
res = redis2.read_until( '\r\n' )
self.assertEqual( res, '+OK\r\n', 'failed to set values to redis1. cmd:%s, res:%s' % (cmd[:-2], res) )
util.log( 'server state transition after hang' )
util.log_server_state( self.cluster )
redis0 = redis_mgmt.Redis( m['id'] )
ret = redis0.connect( m['ip'], m['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis0(%s:%d).' % (m['ip'], m['redis_port']) )
redis1 = redis_mgmt.Redis( s1['id'] )
ret = redis1.connect( s1['ip'], s1['redis_port'] )
self.assertEqual( ret, 0, 'failed to connect to redis1(%s:%d).' % (s1['ip'], s1['redis_port']) )
if len(self.cluster['servers']) != 3:
# set new values
for i in range( 10000, 20000 ):
#.........这里部分代码省略.........
开发者ID:iloview,项目名称:nbase-arc,代码行数:101,代码来源:test_pgs_hanging.py
示例14: test_5_mgmt_is_isolated_with_lconn
def test_5_mgmt_is_isolated_with_lconn(self):
util.print_frame()
util.iptables_print_list()
cluster = filter(lambda x: x['cluster_name'] == 'network_isolation_cluster_1', config.clusters)[0]
util.log(util.json_to_str(cluster))
self.leader_cm = cluster['servers'][0]
# MGMT
mgmt_ip = cluster['servers'][0]['real_ip']
mgmt_port = cluster['servers'][0]['cm_port']
# Create cluster
conf_checker = default_cluster.initialize_starting_up_smr_before_redis( cluster )
self.assertIsNotNone(conf_checker, 'failed to initialize cluster')
# Print initial state of cluster
util.log('\n\n\n ### INITIAL STATE OF CLUSTER ### ')
initial_state = []
self.assertTrue(util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, initial_state, check_quorum=True), 'failed to check cluster state')
# Set SMR option (slave_idle_timeout)
util.log('\n\n\n ### Set SMR option ###')
for s in cluster['servers']:
t = telnet.Telnet('SMR%d' % s['id'])
self.assertEqual(t.connect(s['ip'], s['smr_mgmt_port']), 0,
'Failed to connect to smr. ADDR=%s:%d' % (s['ip'], s['smr_mgmt_port']))
cmd = 'confset slave_idle_timeout_msec 18000'
util.log('[%s:%d] >> %s' % (s['ip'], s['smr_mgmt_port'], cmd))
t.write('confset slave_idle_timeout_msec 18000\r\n')
reply = t.read_until('\r\n').strip()
util.log('[%s:%d] << %s' % (s['ip'], s['smr_mgmt_port'], reply))
self.assertEqual(reply, '+OK', 'Failed to set slave_idle_timeout, REPLY=%s' % reply)
# Network isolation test
for loop_cnt in range(3):
# Get master
master = util.get_server_by_role_and_pg( cluster['servers'], 'master', 0 )
first_slave = None
for s in cluster['servers']:
if s == master:
continue
# Skip non-virtual host
if s.has_key('real_ip') == False:
continue
if first_slave == None:
first_slave = s
# 'role lconn'
util.log( 'role lconn pgs%d while hanging.' % s['id'] )
ret = util.role_lconn_addr( s['real_ip'], s['smr_mgmt_port'] )
self.assertEqual( ret, '+OK\r\n', 'role lconn failed. reply="%s"' % (ret[:-2]) )
util.log( 'succeeded : cmd="role lconn", reply="%s"' % (ret[:-2]) )
time.sleep(0.5)
# Block network
util.log('\n\n\n ### BLOCK NETWORK, %d ### ' % loop_cnt)
self.assertTrue(util.iptables_drop('A', '127.0.0.100', first_slave['smr_mgmt_port']), 'add a bloking role to iptables fail.')
for i in range(6):
util.log('waiting... %d' % (i + 1))
time.sleep(1)
# Check cluster state
ok = False
for i in range(10):
isolated_states = []
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, isolated_states, check_quorum=True)
time.sleep(1)
state_transition_done = True
for s in isolated_states:
if s['pgs_id'] != first_slave['id']:
continue
if s['active_role'] != '?' or s['mgmt_role'] != 'N':
state_transition_done = False
if state_transition_done :
ok = True
break
time.sleep(1)
self.assertTrue(ok, 'Fail, state transition')
# Unblock network
self.assertTrue(util.iptables_drop('D', '127.0.0.100', first_slave['smr_mgmt_port']), 'delete a bloking role to iptables fail.')
# Check cluster state
ok = False
for i in range(7):
final_state = []
util.check_cluster(cluster['cluster_name'], mgmt_ip, mgmt_port, final_state, check_quorum=True)
state_consistency = True
#.........这里部分代码省略.........
开发者ID:LichKing-lee,项目名称:nbase-arc,代码行数:101,代码来源:test_network_isolation.py
示例15: role_change_with_hanging_pgs
def role_change_with_hanging_pgs(self, hanging_servers, running_servers, target_id, master):
util.log('hanging_servers:%s' % hanging_servers)
util.log('running_servers:%s' % running_servers)
util.log('target_id:%s' % target_id)
# Initial data
util.put_some_data(self.cluster, 3, 10)
util.log("States (before role change)")
util.log_server_state(self.cluster)
# Get old timestamp
old_timestamps = {}
for s in self.cluster['servers']:
ts = util.get_timestamp_of_pgs(s)
old_timestamps[s['id']] = ts
# hang
for s in hanging_servers:
smr = smr_mgmt.SMR(s['id'])
ret = smr.connect(s['ip'], s['smr_mgmt_port'])
self.assertEqual(ret, 0, 'failed to connect to master. %s:%d' % (s['ip'], s['smr_mgmt_port']))
util.log("PGS '%d' hang" % s['id'])
smr.write('fi delay sleep 1 13000\r\n')
reply = smr.read_until('\r\n', 1)
if reply != None and reply.find('-ERR not supported') != -1:
self.assertEqual(0, 1, 'make sure that smr has compiled with gcov option.')
smr.disconnect()
# Role change
master_id = util.role_change(self.leader_cm, self.cluster['cluster_name'], target_id)
self.assertEqual(master_id, -1, 'We expected that role_change failed, but success')
# Check rollback - check quorum
if master not in hanging_servers:
expected = 2
ok = self.__check_quorum(master, expected)
self.assertTrue(ok, 'rollback quorum fail. expected:%s' % (expected))
# Check rollback - get new timestamp
new_timestamps_in_hang = {}
for s in running_servers:
ts = util.get_timestamp_of_pgs( s )
new_timestamps_in_hang[s['id']] = ts
# Check rollback - compare old timestamps and new timestamps
for s in running_servers:
old_ts = old_timestamps[s['id']]
new_ts = new_timestamps_in_hang[s['id']]
self.assertEqual(old_ts, new_ts, 'Timestamp of a running server has changed. %d->%d' % (old_ts, new_ts))
t
|
请发表评论