Skip to content

Commit

Permalink
Merge pull request #179 from Incubaid/iah-rc
Browse files Browse the repository at this point in the history
PyLabs: Don't ignore 'inject-as-head' exit code
  • Loading branch information
NicolasT committed Sep 2, 2013
2 parents 287adac + 6de8e72 commit 5a8ca00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions extension/server/ArakoonManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,9 @@ def injectAsHead(self, nodeName, newHead):
rs = ' '.join(r)
p = subprocess.Popen(rs, shell= True, stdout = subprocess.PIPE)
output = p.communicate()[0]
logging.debug("injectAsHead returned %s", output)
return
rc = p.returncode
logging.debug("injectAsHead returned [%d] %s", rc, output)
return rc


def defragDb(self, nodeName):
Expand Down
31 changes: 30 additions & 1 deletion extension/test/server/shaky/test_inject_as_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def test_inject_as_head():
print "1"
cluster.backupDb(s0, new_head)
logging.info("backup-ed %s from %s", new_head, s0)
cluster.injectAsHead(s1, new_head)
ret = cluster.injectAsHead(s1, new_head)

if ret != 0:
raise RuntimeError('injectAsHead returned %d' % ret)

print "2"
logging.info("injected as head")
Common.iterate_n_times(n,Common.simple_set)
Expand All @@ -61,3 +65,28 @@ def test_inject_as_head():
print "4"
ntlogs = Common.get_tlog_count(s1)
logging.info("get_tlog_dir => %i", ntlogs)

@Common.with_custom_setup(Common.setup_3_nodes_mini, Common.basic_teardown)
def test_inject_as_head_failure():
'''Test inject_as_head with a fake database file (should fail)'''

logging.info('Filling cluster')
cluster = Common._getCluster()
Common.iterate_n_times(10, Common.simple_set)

logging.info('Looking up master')
client = Common.get_client()
m = client.whoMaster()
slaves = filter(lambda x: x != m, Common.node_names)
s = slaves[0]

logging.info('Creating broken database')
new_head = '/tmp/broken.db'
with open(new_head, 'w') as fd:
fd.write('this is not a TC database')

logging.info('Injecting broken database')
ret = cluster.injectAsHead(s, new_head)

if ret in [0, None]:
raise RuntimeError('Unexpected injectAsHead result: %r', ret)

0 comments on commit 5a8ca00

Please sign in to comment.