commit cdd9119df445161162617d36b03cc6c20bcd8f53 Author: teor teor2345@gmail.com Date: Mon Feb 27 21:08:49 2017 +1100
Make chutney accept relative paths, as well as the scripts
Closes 21467 (finally!) --- lib/chutney/TorNet.py | 28 ++++++++++++++++++++++++---- tools/bootstrap-network.sh | 3 --- tools/test-network.sh | 27 +++++++++++---------------- 3 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py index c9668f8..33b7cde 100644 --- a/lib/chutney/TorNet.py +++ b/lib/chutney/TorNet.py @@ -47,6 +47,26 @@ def mkdir_p(d, mode=448): return raise
+def get_absolute_chutney_path(): + # use the current directory as the default + # (./chutney already sets CHUTNEY_PATH using the path to the script) + # use tools/test-network.sh if you want chutney to try really hard to find + # itself + relative_chutney_path = os.environ.get('CHUTNEY_PATH', os.getcwd()) + return os.path.abspath(relative_chutney_path) + +def get_absolute_net_path(): + # use the chutney path as the default + absolute_chutney_path = get_absolute_chutney_path() + relative_net_path = os.environ.get('CHUTNEY_DATA_DIR', 'net') + # but what is it relative to? + # let's check if it's in CHUTNEY_PATH first, to preserve + # backwards-compatible behaviour + chutney_net_path = os.path.join(absolute_chutney_path, relative_net_path) + if os.path.isdir(chutney_net_path): + return chutney_net_path + # ok, it's relative to the current directory, whatever that is + return os.path.abspath(relative_net_path)
class Node(object):
@@ -672,7 +692,7 @@ DEFAULTS = { 'hs_directory': 'hidden_service', 'hs-hostname': None, 'connlimit': 60, - 'net_base_dir': os.environ.get('CHUTNEY_DATA_DIR', 'net'), + 'net_base_dir': get_absolute_net_path(), 'tor': os.environ.get('CHUTNEY_TOR', 'tor'), 'tor-gencert': os.environ.get('CHUTNEY_TOR_GENCERT', None), 'auth_cert_lifetime': 12, @@ -681,7 +701,7 @@ DEFAULTS = { # so we default to ipv6_addr None 'ipv6_addr': os.environ.get('CHUTNEY_LISTEN_ADDRESS_V6', None), 'dirserver_flags': 'no-v2', - 'chutney_dir': '.', + 'chutney_dir': get_absolute_chutney_path(), 'torrc_fname': '${dir}/torrc', 'orport_base': 5000, 'dirport_base': 7000, @@ -819,7 +839,7 @@ class Network(object): self._nodes.append(n)
def move_aside_nodes(self): - net_base_dir = os.environ.get('CHUTNEY_DATA_DIR', 'net') + net_base_dir = get_absolute_net_path() nodesdir = os.path.join(net_base_dir, 'nodes')
if not os.path.exists(nodesdir): @@ -927,7 +947,7 @@ def ConfigureNodes(nodelist):
def getTests(): tests = [] - chutney_path = os.environ.get('CHUTNEY_PATH', '') + chutney_path = get_absolute_chutney_path() if len(chutney_path) > 0 and chutney_path[-1] != '/': chutney_path += "/" for x in os.listdir(chutney_path + "scripts/chutney_tests/"): diff --git a/tools/bootstrap-network.sh b/tools/bootstrap-network.sh index bbc77f7..496bc95 100755 --- a/tools/bootstrap-network.sh +++ b/tools/bootstrap-network.sh @@ -38,9 +38,6 @@ export CHUTNEY_NETWORK="$CHUTNEY_PATH/networks/$NETWORK_FLAVOUR" [ -e "$CHUTNEY_NETWORK" ] || \ { echo "$myname: missing network file: $CHUTNEY_NETWORK"; exit 1; }
-# Chutney must be launched at $CHUTNEY_PATH, at least until #21521 is fixed -cd "$CHUTNEY_PATH" - "$CHUTNEY" stop "$CHUTNEY_NETWORK"
echo "$myname: bootstrapping network: $flavour" diff --git a/tools/test-network.sh b/tools/test-network.sh index 008e410..1308c08 100755 --- a/tools/test-network.sh +++ b/tools/test-network.sh @@ -193,26 +193,24 @@ if [ -d "$PWD/$CHUTNEY_PATH" -a -x "$PWD/$CHUTNEY_PATH/chutney" ]; then export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH" fi
-# For picking up the right tor binaries. +# For picking up the right tor binaries +# Choose coverage binaries, if selected +tor_name=tor +tor_gencert_name=tor-gencert +if [ "$USE_COVERAGE_BINARY" = true ]; then + tor_name=tor-cov +fi # If $TOR_DIR isn't set, chutney looks for tor binaries by name or path # using $CHUTNEY_TOR and $CHUTNEY_TOR_GENCERT, and then falls back to # looking for tor and tor-gencert in $PATH if [ -d "$TOR_DIR" ]; then - tor_name=tor - tor_gencert_name=tor-gencert - if [ "$USE_COVERAGE_BINARY" = true ]; then - tor_name=tor-cov - fi + # TOR_DIR is absolute, so these are absolute paths export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}" export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}" else - # make binary paths absolute - if [ -x "$PWD/$CHUTNEY_TOR" ]; then - export CHUTNEY_TOR="$PWD/$CHUTNEY_TOR" - fi - if [ -x "$PWD/$CHUTNEY_TOR_GENCERT" ]; then - export CHUTNEY_TOR_GENCERT="$PWD/$CHUTNEY_TOR_GENCERT" - fi + # these are binary names, they will be searched for in $PATH + export CHUTNEY_TOR="${tor_name}" + export CHUTNEY_TOR_GENCERT="${tor_gencert_name}" fi
# Set the variables for the chutney network flavour @@ -226,9 +224,6 @@ if [ "$NETWORK_DRY_RUN" = true ]; then return 2>/dev/null || exit fi
-# Chutney must be launched at $CHUTNEY_PATH, at least until #21521 is fixed -cd "$CHUTNEY_PATH" - "$CHUTNEY_PATH/tools/bootstrap-network.sh" "$NETWORK_FLAVOUR" || exit 2
# chutney starts verifying after 20 seconds, keeps on trying for 60 seconds,
tor-commits@lists.torproject.org