mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add a functional vm_test for root_test.
This change renames the tools/images directory to tools/vm for clarity, and adds a functional vm_test. Sharding is also added to the same test, and some documentation added around key flags & variables to describe how they work. Subsequent changes will add vm_tests for other cases, such as the runtime tests. PiperOrigin-RevId: 307492245
This commit is contained in:
committed by
gVisor bot
parent
07b1b4cc98
commit
1a597e01be
+2
-2
@@ -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",
|
||||
|
||||
@@ -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",),
|
||||
|
||||
@@ -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.
|
||||
|
||||
+13
-1
@@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"],
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
# Images
|
||||
# VM Images & Tests
|
||||
|
||||
All commands in this directory require the `gcloud` project to be set.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -2,6 +2,6 @@ package(licenses = ["notice"])
|
||||
|
||||
alias(
|
||||
name = "ubuntu1804",
|
||||
actual = "//tools/images/ubuntu1604",
|
||||
actual = "//tools/vm/ubuntu1604",
|
||||
visibility = ["//:sandbox"],
|
||||
)
|
||||
Reference in New Issue
Block a user