summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-08-14 07:51:51 +0000
committerLars Wirzenius <liw@liw.fi>2020-08-14 07:51:51 +0000
commita6e9c1c04c5b85ddd43724243e300c9b3a8ee50b (patch)
treeb829645290de3915379be891dd77c81a487b930c
parent8fb1eba3225eacc9a56bd0422c2a3d323458b502 (diff)
parente0c099011fe902c52933992bc5e70c9a3e363c52 (diff)
downloadick-contractor-a6e9c1c04c5b85ddd43724243e300c9b3a8ee50b.tar.gz
Merge branch 'fix' into 'master'
fix: use files in srcdir for passing in manager address, env vars See merge request larswirzenius/contractor!19
-rwxr-xr-xcheck4
-rw-r--r--funcs.py44
2 files changed, 39 insertions, 9 deletions
diff --git a/check b/check
index cde86a6..bc57b7a 100755
--- a/check
+++ b/check
@@ -4,4 +4,6 @@ set -eu
rm -f test.py
black --check contractor *.py
-CONTRACTOR_ADDRESS="$1" sp-codegen contractor.md -o test.py --run
+echo "$1" > test.address
+echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" > test.env
+sp-codegen contractor.md -o test.py --run
diff --git a/funcs.py b/funcs.py
index f028730..fb772d0 100644
--- a/funcs.py
+++ b/funcs.py
@@ -2,6 +2,7 @@
# Some helpers to make step functions simpler.
import json
+import logging
import os
import re
import subprocess
@@ -11,10 +12,11 @@ import yaml
# Run a subprocess, capture its output and exit code in context.
-def _run(ctx, argv):
- p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+def _run(ctx, argv, env):
+ p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
stdout, stderr = p.communicate("")
ctx["argv"] = argv
+ ctx["env"] = env
ctx["stdout"] = stdout.decode("utf-8")
ctx["stderr"] = stderr.decode("utf-8")
ctx["exit"] = p.returncode
@@ -30,7 +32,31 @@ def _contractor():
# Return manager address.
def _manager_address():
- return os.environ["CONTRACTOR_ADDRESS"]
+ filename = os.path.join(srcdir, "test.address")
+ addr = open(filename).read().strip()
+ logging.debug("Manager address from %s is %r", filename, addr)
+ return addr
+
+
+# Create a config file for Contractor. Return its filename.
+def _create_config(ctx):
+ filename = "config.yaml"
+ if ctx.get("config") is None:
+ ctx["config"] = {"manager_address": _manager_address(), "verbose": True}
+ with open(filename, "w") as f:
+ yaml.safe_dump(ctx["config"], stream=f)
+ logging.debug("config file: %r", open(filename).read())
+ return filename
+
+
+# Create dict with environment variables for running Contractor, merging
+# os.environ and srcdir/test.env.
+def _create_env():
+ env = dict(os.environ)
+ for line in open(os.path.join(srcdir, "test.env")):
+ name, value = line.split("=", 1)
+ env[name] = value.strip()
+ return env
#############################################################################
@@ -45,8 +71,9 @@ def nop(ctx, **kwargs):
# Check that we can access the contractor VM.
# FIXME: this hardcodes some things.
def contractor_is_working(ctx):
- argv = _contractor() + ["status", "-m", _manager_address()]
- _run(ctx, argv)
+ config = _create_config(ctx)
+ argv = _contractor() + ["-c", config, "status"]
+ _run(ctx, argv, _create_env())
assert_eq(ctx["exit"], 0)
@@ -75,13 +102,14 @@ def exit_code_is(ctx, exit_code=None):
# Run contractor dump
def run_contractor_dump(ctx, filename=None):
argv = _contractor() + ["dump", filename]
- _run(ctx, argv)
+ _run(ctx, argv, _create_env())
# Run the contractor to do a build.
def run_contractor_build(ctx, filename=None):
- argv = _contractor() + ["build", filename, "-m", _manager_address()]
- _run(ctx, argv)
+ config = _create_config(ctx)
+ argv = _contractor() + ["-c", config, "build", filename]
+ _run(ctx, argv, _create_env())
# Parse stdout from latest subprocess as JSON into a dict. Read the