summaryrefslogtreecommitdiff
path: root/funcs.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-08-14 10:17:23 +0300
committerLars Wirzenius <liw@liw.fi>2020-08-14 10:50:27 +0300
commite0c099011fe902c52933992bc5e70c9a3e363c52 (patch)
treeb829645290de3915379be891dd77c81a487b930c /funcs.py
parent8fb1eba3225eacc9a56bd0422c2a3d323458b502 (diff)
downloadick-contractor-e0c099011fe902c52933992bc5e70c9a3e363c52.tar.gz
fix: use files in srcdir for passing in manager address, env vars
Subplot now clears the environment before running scenarios so we can't use $CONTRACTOR_ADDRESS to pass in the manager's address. We also need the SSH agent's address so we can authenticate into the manager. set up test.env get env from test.env
Diffstat (limited to 'funcs.py')
-rw-r--r--funcs.py44
1 files changed, 36 insertions, 8 deletions
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