aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2018-04-09 14:07:47 -0400
committerMarcoFalke <falke.marco@gmail.com>2018-04-20 18:38:41 -0400
commit7460945e0b663585a7af3cde6c8675cbe21b4111 (patch)
tree3a4f094714d9ed74ad9cc0793ea841a9d3f25391
parent0a76ed232a6c448a8666234a2c190db37e3498e7 (diff)
downloadbitcoin-7460945e0b663585a7af3cde6c8675cbe21b4111.tar.xz
[qa] Delete cookie file before starting node
If a cookie file exists in a datadir prior to node startup, it must have been leftover from a prior unclean shutdown. As bitcoind will overwrite it anyway, delete it before starting up to prevent the test framework from inadvertently trying to connect using stale credentials. Github-Pull: #12902 Rebased-From: 75d0e4c5444249f0cf81ed0494e2c2717170b695
-rwxr-xr-xtest/functional/test_framework/test_node.py5
-rw-r--r--test/functional/test_framework/util.py6
2 files changed, 11 insertions, 0 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 19db11d8a3..f6e4871299 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -17,6 +17,7 @@ import time
from .authproxy import JSONRPCException
from .util import (
assert_equal,
+ delete_cookie_file,
get_rpc_proxy,
rpc_url,
wait_until,
@@ -98,6 +99,10 @@ class TestNode():
extra_args = self.extra_args
if stderr is None:
stderr = self.stderr
+ # Delete any existing cookie file -- if such a file exists (eg due to
+ # unclean shutdown), it will get overwritten anyway by bitcoind, and
+ # potentially interfere with our attempt to authenticate
+ delete_cookie_file(self.datadir)
self.process = subprocess.Popen(self.args + extra_args, stderr=stderr, *args, **kwargs)
self.running = True
self.log.debug("bitcoind started, waiting for RPC to come up")
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 538ae7691b..ead1f844f7 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -319,6 +319,12 @@ def get_auth_cookie(datadir):
raise ValueError("No RPC credentials")
return user, password
+# If a cookie file exists in the given datadir, delete it.
+def delete_cookie_file(datadir):
+ if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
+ logger.debug("Deleting leftover cookie file")
+ os.remove(os.path.join(datadir, "regtest", ".cookie"))
+
def get_bip9_status(node, key):
info = node.getblockchaininfo()
return info['bip9_softforks'][key]