Skip to content

Commit

Permalink
QA: make sure we can run on Linux without Docker (#836)
Browse files Browse the repository at this point in the history
* QA: make sure we can run from Linux

Previous changes made it much more difficult to run on Linux. Yet, to
do QA of Web Connectivity it's more practical to perform it on Linux using
also OONI Probe v2.x and Measurement Kit.

For this reason, this diff implements changes that should allow us to run
both on Linux and when using Docker.

While it's possible to create a Docker container where we deploy compiled
versions of MK and OONI Probe v2.x, it's more practical to use a Linux system
where they are already installed, like my Linux desktop.

Part of #810

* QA: fix running on Linux

1. we cannot write on QA/HOME when running on Linux so just
use `/tmp` as the HOME directory (slower but works)

2. the `/tmp` directory may be on another device than `/home`, so
we cannot move, then just perform a copy

Part of #810
  • Loading branch information
bassosimone authored Aug 12, 2020
1 parent 8bc9684 commit f35b002
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions QA/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
1 change: 0 additions & 1 deletion cmd/jafar/Dockerfile → QA/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
FROM alpine:edge
RUN apk add go git musl-dev iptables tmux bind-tools curl sudo python3
RUN adduser -D ooniprobe
5 changes: 2 additions & 3 deletions QA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ where `$nettest` is the nettest name (e.g. `telegram`) and `$ooni_exe`
is the OONI Probe v2.x compatible binary to test.

The Python script needs to run as root. Note however that sudo will also
be used to run `$ooni_exe` with the privileges of the `$SUDO_USER` that
called `sudo ./QA/$nettest.py $ooni_exe`.
be used to run `$ooni_exe` with the privileges of the `nobody` user.

## Run QA using a docker container

Run test in a suitable Docker container using:

```
```bash
./QA/rundocker.sh $nettest
```

Expand Down
9 changes: 5 additions & 4 deletions QA/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ def execute(args):

def execute_jafar_and_miniooni(ooni_exe, outfile, experiment, tag, args):
""" Executes jafar and miniooni. Returns the test keys. """
tmpoutfile = "/tmp/{}".format(outfile)
with contextlib.suppress(FileNotFoundError):
os.remove(outfile) # just in case
os.remove(tmpoutfile) # just in case
execute(
[
"./jafar",
"-main-command",
"%s -no '/home/ooniprobe/%s' %s" % (ooni_exe, outfile, experiment),
"{} -no '{}' --home /tmp {}".format(ooni_exe, tmpoutfile, experiment),
"-main-user",
"ooniprobe", # created in cmd/jafar/Dockerfile
"nobody", # should be present on Unix
"-tag",
tag,
]
+ args
)
shutil.move("/home/ooniprobe/{}".format(outfile), outfile)
shutil.copy(tmpoutfile, outfile)
result = read_result(outfile)
assert isinstance(result, dict)
assert isinstance(result["test_keys"], dict)
Expand Down
2 changes: 1 addition & 1 deletion QA/rundocker.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -ex
DOCKER=${DOCKER:-docker}
$DOCKER build -t jafar-qa ./cmd/jafar/
$DOCKER build -t jafar-qa ./QA/
$DOCKER run --privileged -v`pwd`:/jafar -w/jafar jafar-qa ./QA/pyrun.sh "$@"
22 changes: 15 additions & 7 deletions libminiooni/libminiooni.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
// Options contains the options you can set from the CLI.
type Options struct {
Annotations []string
Inputs []string
ExtraOptions []string
HomeDir string
Inputs []string
NoBouncer bool
NoGeoIP bool
NoJSON bool
Expand Down Expand Up @@ -68,14 +69,18 @@ func init() {
&collectorURLUnused, "collector", 'c',
"Unsupported option that used to set the collector base URL", "URL",
)
getopt.FlagLong(
&globalOptions.Inputs, "input", 'i',
"Add test-dependent input to the test input", "INPUT",
)
getopt.FlagLong(
&globalOptions.ExtraOptions, "option", 'O',
"Pass an option to the experiment", "KEY=VALUE",
)
getopt.FlagLong(
&globalOptions.HomeDir, "home", 0,
"Force specific home directory", "PATH",
)
getopt.FlagLong(
&globalOptions.Inputs, "input", 'i',
"Add test-dependent input to the test input", "INPUT",
)
getopt.FlagLong(
&globalOptions.NoBouncer, "no-bouncer", 0, "Don't use the OONI bouncer",
)
Expand Down Expand Up @@ -196,7 +201,10 @@ func (h *logHandler) HandleLog(e *log.Entry) (err error) {
}

// See https://gist.github.com/miguelmota/f30a04a6d64bd52d7ab59ea8d95e54da
func gethomedir() string {
func gethomedir(optionsHome string) string {
if optionsHome != "" {
return optionsHome
}
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
Expand Down Expand Up @@ -244,7 +252,7 @@ func MainWithConfiguration(experimentName string, currentOptions Options) {
}
log.Log = logger

homeDir := gethomedir()
homeDir := gethomedir(currentOptions.HomeDir)
fatalIfFalse(homeDir != "", "home directory is empty")
miniooniDir := path.Join(homeDir, ".miniooni")
assetsDir := path.Join(miniooniDir, "assets")
Expand Down

0 comments on commit f35b002

Please sign in to comment.