diff options
-rw-r--r-- | benchmarks/BUILD | 4 | ||||
-rw-r--r-- | benchmarks/runner/commands.py | 5 | ||||
-rw-r--r-- | runsc/dockerutil/dockerutil.go | 12 | ||||
-rw-r--r-- | test/root/BUILD | 14 | ||||
-rwxr-xr-x | tools/installers/head.sh | 2 | ||||
-rw-r--r-- | tools/vm/BUILD (renamed from tools/images/BUILD) | 16 | ||||
-rw-r--r-- | tools/vm/README.md (renamed from tools/images/README.md) | 2 | ||||
-rwxr-xr-x | tools/vm/build.sh (renamed from tools/images/build.sh) | 8 | ||||
-rw-r--r-- | tools/vm/defs.bzl (renamed from tools/images/defs.bzl) | 33 | ||||
-rwxr-xr-x | tools/vm/execute.sh (renamed from tools/images/execute.sh) | 10 | ||||
-rw-r--r-- | tools/vm/test.cc (renamed from tools/images/test.cc) | 8 | ||||
-rwxr-xr-x | tools/vm/ubuntu1604/10_core.sh (renamed from tools/images/ubuntu1604/10_core.sh) | 0 | ||||
-rwxr-xr-x | tools/vm/ubuntu1604/20_bazel.sh (renamed from tools/images/ubuntu1604/20_bazel.sh) | 0 | ||||
-rwxr-xr-x | tools/vm/ubuntu1604/25_docker.sh (renamed from tools/images/ubuntu1604/25_docker.sh) | 0 | ||||
-rwxr-xr-x | tools/vm/ubuntu1604/30_containerd.sh (renamed from tools/images/ubuntu1604/30_containerd.sh) | 0 | ||||
-rwxr-xr-x | tools/vm/ubuntu1604/40_kokoro.sh (renamed from tools/images/ubuntu1604/40_kokoro.sh) | 0 | ||||
-rw-r--r-- | tools/vm/ubuntu1604/BUILD (renamed from tools/images/ubuntu1604/BUILD) | 0 | ||||
-rw-r--r-- | tools/vm/ubuntu1804/BUILD (renamed from tools/images/ubuntu1804/BUILD) | 2 | ||||
-rwxr-xr-x | tools/vm/zone.sh (renamed from tools/images/zone.sh) | 0 |
19 files changed, 77 insertions, 39 deletions
diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 2a2d15d7e..ac44f479d 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -13,8 +13,8 @@ py_binary( data = select({ ":gcloud_rule": [], "//conditions:default": [ - "//tools/images:ubuntu1604", - "//tools/images:zone", + "//tools/vm:ubuntu1604", + "//tools/vm:zone", ], }), main = "run.py", diff --git a/benchmarks/runner/commands.py b/benchmarks/runner/commands.py index e8289f6c5..9a391eb01 100644 --- a/benchmarks/runner/commands.py +++ b/benchmarks/runner/commands.py @@ -103,13 +103,12 @@ class GCPCommand(RunCommand): ("--image_file",), help="The binary that emits the GCP image.", default=os.path.join( - os.path.dirname(__file__), "../../tools/images/ubuntu1604"), + os.path.dirname(__file__), "../../tools/vm/ubuntu1604"), ) zone_file = click.core.Option( ("--zone_file",), help="The binary that emits the GCP zone.", - default=os.path.join( - os.path.dirname(__file__), "../../tools/images/zone"), + default=os.path.join(os.path.dirname(__file__), "../../tools/vm/zone"), ) internal = click.core.Option( ("--internal/--no-internal",), diff --git a/runsc/dockerutil/dockerutil.go b/runsc/dockerutil/dockerutil.go index 1ff5e8cc3..f009486bc 100644 --- a/runsc/dockerutil/dockerutil.go +++ b/runsc/dockerutil/dockerutil.go @@ -36,8 +36,18 @@ import ( ) var ( + // runtime is the runtime to use for tests. This will be applied to all + // containers. Note that the default here ("runsc") corresponds to the + // default used by the installations. This is important, because the + // default installer for vm_tests (in tools/installers:head, invoked + // via tools/vm:defs.bzl) will install with this name. So without + // changing anything, tests should have a runsc runtime available to + // them. Otherwise installers should update the existing runtime + // instead of installing a new one. runtime = flag.String("runtime", "runsc", "specify which runtime to use") - config = flag.String("config_path", "/etc/docker/daemon.json", "configuration file for reading paths") + + // config is the default Docker daemon configuration path. + config = flag.String("config_path", "/etc/docker/daemon.json", "configuration file for reading paths") ) // EnsureSupportedDockerVersion checks if correct docker is installed. diff --git a/test/root/BUILD b/test/root/BUILD index ddc9b4955..05166673a 100644 --- a/test/root/BUILD +++ b/test/root/BUILD @@ -1,4 +1,5 @@ load("//tools:defs.bzl", "go_library", "go_test") +load("//tools/vm:defs.bzl", "vm_test") package(licenses = ["notice"]) @@ -24,7 +25,9 @@ go_test( library = ":root", tags = [ # Requires docker and runsc to be configured before the test runs. - # Also test only runs as root. + # Also, the test needs to be run as root. Note that below, the + # root_vm_test relies on the default runtime 'runsc' being installed by + # the default installer. "manual", "local", ], @@ -44,3 +47,12 @@ go_test( "@org_golang_x_sys//unix:go_default_library", ], ) + +vm_test( + name = "root_vm_test", + shard_count = 1, + targets = [ + "//tools/installers:shim", + ":root_test", + ], +) diff --git a/tools/installers/head.sh b/tools/installers/head.sh index 9de8f138c..7fc566ebd 100755 --- a/tools/installers/head.sh +++ b/tools/installers/head.sh @@ -15,7 +15,7 @@ # limitations under the License. # Install our runtime. -$(dirname $0)/runsc install +$(find . -executable -type f -name runsc) install # Restart docker. service docker restart || true diff --git a/tools/images/BUILD b/tools/vm/BUILD index 8d319e3e4..f7160c627 100644 --- a/tools/images/BUILD +++ b/tools/vm/BUILD @@ -1,5 +1,5 @@ load("//tools:defs.bzl", "cc_binary", "gtest") -load("//tools/images:defs.bzl", "vm_image", "vm_test") +load("//tools/vm:defs.bzl", "vm_image", "vm_test") package( default_visibility = ["//:sandbox"], @@ -37,27 +37,21 @@ vm_image( family = "ubuntu-1604-lts", project = "ubuntu-os-cloud", scripts = [ - "//tools/images/ubuntu1604", + "//tools/vm/ubuntu1604", ], ) -vm_test( - name = "ubuntu1604_test", - image = ":ubuntu1604", - targets = [":test"], -) - vm_image( name = "ubuntu1804", family = "ubuntu-1804-lts", project = "ubuntu-os-cloud", scripts = [ - "//tools/images/ubuntu1804", + "//tools/vm/ubuntu1804", ], ) vm_test( - name = "ubuntu1804_test", - image = ":ubuntu1804", + name = "vm_test", + shard_count = 2, targets = [":test"], ) diff --git a/tools/images/README.md b/tools/vm/README.md index 26c0f84f2..898c95fca 100644 --- a/tools/images/README.md +++ b/tools/vm/README.md @@ -1,4 +1,4 @@ -# Images +# VM Images & Tests All commands in this directory require the `gcloud` project to be set. diff --git a/tools/images/build.sh b/tools/vm/build.sh index f39f723b8..5d3dc0bbf 100755 --- a/tools/images/build.sh +++ b/tools/vm/build.sh @@ -43,6 +43,9 @@ if ! [[ -z "${existing}" ]]; then exit 0 fi +# Standard arguments (applies only on script execution). +declare -ar SSH_ARGS=("-o" "ConnectTimeout=60" "--") + # gcloud has path errors; is this a result of being a genrule? export PATH=${PATH:-/bin:/usr/bin:/usr/local/bin} @@ -69,9 +72,9 @@ declare -r start=$(date +%s) declare -r end=$((${start}+${timeout})) while [[ "$(date +%s)" -lt "${end}" ]] && [[ "${success}" -lt 3 ]]; do echo -n "." - if gcloud compute ssh --zone "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- env - true 2>/dev/null; then + if gcloud compute ssh --zone "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- true 2>/dev/null; then success=$((${success}+1)) - elif gcloud compute ssh --internal-ip --zone "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- env - true 2>/dev/null; then + elif gcloud compute ssh --internal-ip --zone "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- true 2>/dev/null; then success=$((${success}+1)) internal="--internal-ip" fi @@ -89,6 +92,7 @@ for arg; do (set -x; gcloud compute ssh ${internal} \ --zone "${ZONE}" \ "${USERNAME}"@"${INSTANCE_NAME}" -- \ + "${SSH_ARGS[@]}" \ sudo bash - <"${arg}" >/dev/null) done diff --git a/tools/images/defs.bzl b/tools/vm/defs.bzl index 2847e1847..24bf0aabc 100644 --- a/tools/images/defs.bzl +++ b/tools/vm/defs.bzl @@ -38,13 +38,13 @@ vm_image_builder = rule( attrs = { "_builder": attr.label( executable = True, - default = "//tools/images:builder", + default = "//tools/vm:builder", cfg = "host", ), "username": attr.string(default = "$(whoami)"), "zone": attr.label( executable = True, - default = "//tools/images:zone", + default = "//tools/vm:zone", cfg = "host", ), "family": attr.string(mandatory = True), @@ -80,14 +80,14 @@ def _vm_image_impl(ctx): # resolved and consumed in the generation of the trivial echo script. return [DefaultInfo(executable = echo)] -_vm_image = rule( +_vm_image_test = rule( attrs = { "builder": attr.label( executable = True, cfg = "host", ), }, - executable = True, + test = True, implementation = _vm_image_impl, ) @@ -96,9 +96,13 @@ def vm_image(name, **kwargs): name = name + "_builder", **kwargs ) - _vm_image( + _vm_image_test( name = name, builder = ":" + name + "_builder", + tags = [ + "local", + "manual", + ], ) def _vm_test_impl(ctx): @@ -109,9 +113,9 @@ def _vm_test_impl(ctx): # they can be copied over for remote execution. runner_content = "\n".join([ "#!/bin/bash", - "export ZONE=$(cat %s)" % ctx.files.zone[0].short_path, + "export ZONE=$(%s)" % ctx.files.zone[0].short_path, "export USERNAME=%s" % ctx.attr.username, - "export IMAGE=$(cat %s)" % ctx.files.image[0].short_path, + "export IMAGE=$(%s)" % ctx.files.image[0].short_path, "export SUDO=%s" % "true" if ctx.attr.sudo else "false", "%s %s" % ( ctx.executable.executer.short_path, @@ -141,17 +145,19 @@ def _vm_test_impl(ctx): _vm_test = rule( attrs = { "image": attr.label( - mandatory = True, + executable = True, + default = "//tools/vm:ubuntu1804", cfg = "host", ), "executer": attr.label( executable = True, - default = "//tools/images:executer", + default = "//tools/vm:executer", cfg = "host", ), "username": attr.string(default = "$(whoami)"), "zone": attr.label( - default = "//tools/images:zone", + executable = True, + default = "//tools/vm:zone", cfg = "host", ), "sudo": attr.bool(default = True), @@ -167,7 +173,7 @@ _vm_test = rule( ) def vm_test( - installer = "//tools/installers:head", + installers = None, **kwargs): """Runs the given targets as a remote test. @@ -176,8 +182,9 @@ def vm_test( **kwargs: All test arguments. Should include targets and image. """ targets = kwargs.pop("targets", []) - if installer: - targets = [installer] + targets + if installers == None: + installers = ["//tools/installers:head"] + targets = installers + targets if default_installer(): targets = [default_installer()] + targets _vm_test( diff --git a/tools/images/execute.sh b/tools/vm/execute.sh index ba4b1ac0e..1f1f3ce01 100755 --- a/tools/images/execute.sh +++ b/tools/vm/execute.sh @@ -31,6 +31,9 @@ declare -r MACHINE=${MACHINE:-n1-standard-1} declare -r ZONE=${ZONE:-us-central1-f} declare -r SUDO=${SUDO:-false} +# Standard arguments (applies only on script execution). +declare -ar SSH_ARGS=("-o" "ConnectTimeout=60" "--") + # This script is executed as a test rule, which will reset the value of HOME. # Unfortunately, it is needed to load the gconfig credentials. We will reset # HOME when we actually execute in the remote environment, defined below. @@ -81,7 +84,9 @@ tar czf - --dereference --exclude=.git . | gcloud compute ssh \ --ssh-key-file="${KEYNAME}" \ --zone "${ZONE}" \ - "${USERNAME}"@"${INSTANCE_NAME}" -- tar xzf - + "${USERNAME}"@"${INSTANCE_NAME}" -- \ + "${SSH_ARGS[@]}" \ + tar xzf - # Execute the command remotely. for cmd; do @@ -108,6 +113,7 @@ for cmd; do --ssh-key-file="${KEYNAME}" \ --zone "${ZONE}" \ "${USERNAME}"@"${INSTANCE_NAME}" -- \ + "${SSH_ARGS[@]}" \ mkdir -p "/tmp/${REMOTE_TMPDIR}" fi if [[ -v XML_OUTPUT_FILE ]]; then @@ -123,6 +129,7 @@ for cmd; do --ssh-key-file="${KEYNAME}" \ --zone "${ZONE}" \ "${USERNAME}"@"${INSTANCE_NAME}" -- \ + "${SSH_ARGS[@]}" \ "${PREFIX[@]}" "${cmd}" # Collect relevant results. @@ -147,6 +154,7 @@ for cmd; do --ssh-key-file="${KEYNAME}" \ --zone "${ZONE}" \ "${USERNAME}"@"${INSTANCE_NAME}" -- \ + "${SSH_ARGS[@]}" \ rm -rf "/tmp/${REMOTE_TMPDIR}" fi done diff --git a/tools/images/test.cc b/tools/vm/test.cc index 4f31d93c5..c0ceacda1 100644 --- a/tools/images/test.cc +++ b/tools/vm/test.cc @@ -16,8 +16,12 @@ namespace { -TEST(Image, Sanity) { - // Do nothing. +TEST(Image, Sanity0) { + // Do nothing (in shard 0). +} + +TEST(Image, Sanity1) { + // Do nothing (in shard 1). } } // namespace diff --git a/tools/images/ubuntu1604/10_core.sh b/tools/vm/ubuntu1604/10_core.sh index cd518d6ac..cd518d6ac 100755 --- a/tools/images/ubuntu1604/10_core.sh +++ b/tools/vm/ubuntu1604/10_core.sh diff --git a/tools/images/ubuntu1604/20_bazel.sh b/tools/vm/ubuntu1604/20_bazel.sh index bb7afa676..bb7afa676 100755 --- a/tools/images/ubuntu1604/20_bazel.sh +++ b/tools/vm/ubuntu1604/20_bazel.sh diff --git a/tools/images/ubuntu1604/25_docker.sh b/tools/vm/ubuntu1604/25_docker.sh index 11eea2d72..11eea2d72 100755 --- a/tools/images/ubuntu1604/25_docker.sh +++ b/tools/vm/ubuntu1604/25_docker.sh diff --git a/tools/images/ubuntu1604/30_containerd.sh b/tools/vm/ubuntu1604/30_containerd.sh index fb3699c12..fb3699c12 100755 --- a/tools/images/ubuntu1604/30_containerd.sh +++ b/tools/vm/ubuntu1604/30_containerd.sh diff --git a/tools/images/ubuntu1604/40_kokoro.sh b/tools/vm/ubuntu1604/40_kokoro.sh index 06a1e6c48..06a1e6c48 100755 --- a/tools/images/ubuntu1604/40_kokoro.sh +++ b/tools/vm/ubuntu1604/40_kokoro.sh diff --git a/tools/images/ubuntu1604/BUILD b/tools/vm/ubuntu1604/BUILD index ab1df0c4c..ab1df0c4c 100644 --- a/tools/images/ubuntu1604/BUILD +++ b/tools/vm/ubuntu1604/BUILD diff --git a/tools/images/ubuntu1804/BUILD b/tools/vm/ubuntu1804/BUILD index 7aa1ecdf7..0c8856dde 100644 --- a/tools/images/ubuntu1804/BUILD +++ b/tools/vm/ubuntu1804/BUILD @@ -2,6 +2,6 @@ package(licenses = ["notice"]) alias( name = "ubuntu1804", - actual = "//tools/images/ubuntu1604", + actual = "//tools/vm/ubuntu1604", visibility = ["//:sandbox"], ) diff --git a/tools/images/zone.sh b/tools/vm/zone.sh index 79569fb19..79569fb19 100755 --- a/tools/images/zone.sh +++ b/tools/vm/zone.sh |