|
|
@ -329,15 +329,17 @@ class Node(object):
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
return ''
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
|
|
def wait_for_leader(self, timeout=TIMEOUT):
|
|
|
|
def wait_for_leader(self, timeout=TIMEOUT, log=True):
|
|
|
|
lr = None
|
|
|
|
lr = None
|
|
|
|
t = 0
|
|
|
|
t = 0
|
|
|
|
while lr == None or lr['addr'] == '':
|
|
|
|
while lr == None or lr['addr'] == '':
|
|
|
|
if t > timeout:
|
|
|
|
if t > timeout:
|
|
|
|
|
|
|
|
if log:
|
|
|
|
|
|
|
|
self.dump_log("dumping log due to timeout waiting for leader")
|
|
|
|
raise Exception('rqlite node failed to detect leader within %d seconds' % timeout)
|
|
|
|
raise Exception('rqlite node failed to detect leader within %d seconds' % timeout)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
lr = self.status()['store']['leader']
|
|
|
|
lr = self.status()['store']['leader']
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
except (KeyError, requests.exceptions.ConnectionError):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
time.sleep(1)
|
|
|
|
time.sleep(1)
|
|
|
|
t+=1
|
|
|
|
t+=1
|
|
|
@ -347,6 +349,13 @@ class Node(object):
|
|
|
|
raise Exception('leader is available but node reports not ready')
|
|
|
|
raise Exception('leader is available but node reports not ready')
|
|
|
|
return lr
|
|
|
|
return lr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def expect_leader_fail(self, timeout=TIMEOUT):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
self.wait_for_leader(self, timeout, log=False)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
def db_applied_index(self):
|
|
|
|
def db_applied_index(self):
|
|
|
|
return int(self.status()['store']['db_applied_index'])
|
|
|
|
return int(self.status()['store']['db_applied_index'])
|
|
|
|
|
|
|
|
|
|
|
@ -1102,7 +1111,7 @@ class TestAuthJoin(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
n1 = Node(RQLITED_PATH, '1', auth=self.auth_file.name)
|
|
|
|
n1 = Node(RQLITED_PATH, '1', auth=self.auth_file.name)
|
|
|
|
n1.start(join=n0.APIAddr())
|
|
|
|
n1.start(join=n0.APIAddr())
|
|
|
|
self.assertRaises(Exception, n1.wait_for_leader) # Join should fail due to lack of auth.
|
|
|
|
self.assertTrue(n1.expect_leader_fail()) # Join should fail due to lack of auth.
|
|
|
|
|
|
|
|
|
|
|
|
n2 = Node(RQLITED_PATH, '2', auth=self.auth_file.name)
|
|
|
|
n2 = Node(RQLITED_PATH, '2', auth=self.auth_file.name)
|
|
|
|
n2.start(join=n0.APIAddr(), join_as="foo")
|
|
|
|
n2.start(join=n0.APIAddr(), join_as="foo")
|
|
|
|