Skip to content

Commit

Permalink
build: use rules_oci, fixup tests, cleanup image names
Browse files Browse the repository at this point in the history
  • Loading branch information
matzf committed Mar 14, 2024
1 parent 95f6fed commit e36ba06
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 105 deletions.
22 changes: 13 additions & 9 deletions acceptance/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,19 @@ def _setup_artifacts(self):
print("artifacts dir: %s" % self.artifacts)

def _setup_container_loaders(self):
for tag, script in self.container_loaders:
o = local[script]()
idx = o.index("as ")
if idx < 0:
logger.error("extracting tag from loader script %s" % tag)
continue
bazel_tag = o[idx+len("as "):].strip()
logger.info("docker tag %s %s" % (bazel_tag, tag))
cmd.docker("tag", bazel_tag, tag)

for _, tar in self.container_loaders:
o = cmd.docker("load", "--input", tar)
print(o)

# needle = "Loaded image: "
# idx = o.index(needle)
# if idx < 0:
# logger.error("extracting tag from load output %s" % tag)
# continue
# loaded_tag = o[idx+len(needle):].strip()
#logger.info("docker tag %s %s" % (loaded_tag, tag))
#cmd.docker("tag", loaded_tag, tag)

def get_executable(self, name: str):
"""Resolve the executable by name.
Expand Down
14 changes: 7 additions & 7 deletions acceptance/common/topogen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def topogen_test(
deps = [],
data = [],
homedir = "",
tester = "//docker:tester"):
tester = "//docker:tester.tar"):
"""Creates a test based on a topology file.
It creates a target specified by the 'name' argument that runs the entire
Expand Down Expand Up @@ -117,12 +117,12 @@ def topogen_test(

def container_loaders(tester, gateway):
images = {
"control:latest": "//docker:control",
"daemon:latest": "//docker:daemon",
"dispatcher:latest": "//docker:dispatcher",
"tester:latest": tester,
"router:latest": "//docker:router",
"scion/control:latest": "//docker:control.tar",
"scion/daemon:latest": "//docker:daemon.tar",
"scion/dispatcher:latest": "//docker:dispatcher.tar",
"scion/tester:latest": tester,
"scion/router:latest": "//docker:router.tar",
}
if gateway:
images["gateway:latest"] = "//docker:gateway"
images["scion/gateway:latest"] = "//docker:gateway.tar"
return images
6 changes: 3 additions & 3 deletions acceptance/router_benchmark/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ exports_files([
args = [
"--executable",
"brload:$(location //acceptance/router_benchmark/brload:brload)",
"--container-loader=router:latest#$(location //docker:router)",
"--container-loader=$(location //docker:router.tar)",
]

data = [
":conf",
"//docker:router",
"//docker:router.tar",
"//acceptance/router_benchmark/brload:brload",
]

Expand All @@ -22,7 +22,7 @@ raw_test(
src = "test.py",
args = args,
data = data,
homedir = "$(rootpath //docker:router)",
homedir = "$(rootpath //docker:router.tar)",
# This test uses sudo and accesses /var/run/netns.
local = True,
)
2 changes: 1 addition & 1 deletion acceptance/router_benchmark/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def setup_prepare(self):
"--network", "container:prometheus",
"--name", "router",
"--cpuset-cpus", ",".join(map(str, self.router_cpus)),
"posix-router:latest")
"scion/router:latest")

time.sleep(2)

Expand Down
8 changes: 4 additions & 4 deletions acceptance/router_multi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ args = [
"--executable",
"braccept:$(location //tools/braccept)",
"--container-loader",
"router:latest#$(location //docker:router)",
"scion/router:latest#$(location //docker:router.tar)",
"--pause_tar",
"$(location //acceptance/router_multi:pause.tar)",
]

data = [
"pause.tar",
":conf",
":router",
"//docker:router.tar",
"//tools/braccept",
]

Expand All @@ -29,7 +29,7 @@ raw_test(
"--bfd",
],
data = data,
homedir = "$(rootpath :router)",
homedir = "$(rootpath :conf)",
# This test uses sudo and accesses /var/run/netns.
local = True,
)
Expand All @@ -39,7 +39,7 @@ raw_test(
src = "test.py",
args = args,
data = data,
homedir = "$(rootpath :router)",
homedir = "$(rootpath :conf)",
# This test uses sudo and accesses /var/run/netns.
local = True,
)
2 changes: 1 addition & 1 deletion acceptance/router_multi/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def setup_start(self):

exec_docker("run -v %s/conf:/etc/scion -d %s --network container:%s \
--name router %s" % (self.artifacts, " ".join(envs),
"pause", "bazel/acceptance/router_multi:router"))
"pause", "scion/router:latest"))

time.sleep(1)

Expand Down
91 changes: 61 additions & 30 deletions acceptance/topo_cs_reload/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//tools/lint:go.bzl", "go_test")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")

go_test(
name = "go_default_test",
Expand Down Expand Up @@ -36,36 +37,66 @@ go_test(
],
)

# oci_image(
# name = "dispatcher",
# base = "//docker:dispatcher",
# cmd = [
# "--config",
# "/disp.toml",
# ],
# entrypoint = ["/app/dispatcher"],
# files = ["testdata/disp.toml"],
# )
# dispatcher container
oci_tarball(
name = "dispatcher.tar",
format = "docker",
image = ":dispatcher_image",
repo_tags = ["bazel/" + package_name() + ":dispatcher"],
)

oci_image(
name = "dispatcher_image",
base = "//docker:dispatcher",
entrypoint = ["/app/dispatcher"],
cmd = [
"--config",
"/disp.toml",
],
tars = [
":dispatcher_data",
],
)

pkg_tar(
name = "dispatcher_data",
srcs = ["testdata/disp.toml"],
)

# oci_image(
# name = "control",
# base = "//docker:control",
# cmd = [
# "--config",
# "/cs.toml",
# ],
# entrypoint = ["/app/control"],
# files = [
# "testdata/cs.toml",
# "testdata/tls.key",
# "testdata/tls.pem",
# "testdata/topology_reload.json",
# ":invalid_changed_ip",
# ":invalid_changed_port",
# "//acceptance/topo_common:invalid_reloads",
# "//acceptance/topo_common:topology",
# ],
# )
# control container
oci_tarball(
name = "control.tar",
format = "docker",
image = ":control_image",
repo_tags = ["bazel/" + package_name() + ":control"],
)

oci_image(
name = "control_image",
base = "//docker:control",
entrypoint = ["/app/control"],
cmd = [
"--config",
"/cs.toml",
],
tars = [
":control_data",
]
)

pkg_tar(
name = "control_data",
srcs = [
"testdata/cs.toml",
"testdata/tls.key",
"testdata/tls.pem",
"testdata/topology_reload.json",
":invalid_changed_ip",
":invalid_changed_port",
"//acceptance/topo_common:invalid_reloads",
"//acceptance/topo_common:topology",
],
)

genrule(
name = "invalid_changed_ip",
Expand Down
23 changes: 21 additions & 2 deletions acceptance/topo_cs_reload/reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestPSTopoReload(t *testing.T) {
assert.NoError(t, err, "Loading reloadTopo failed")

// check initial topo matches expected.
check(t)
checkTopology(t, origTopo)

// try invalid topos first.
Expand Down Expand Up @@ -104,8 +105,8 @@ func setupTest(t *testing.T) testState {
s.mustExec(t, "tar", "-xf", "crypto.tar", "-C", tmpDir)
// first load the docker images from bazel into the docker deamon, the
// tars are in the same folder as this test runs in bazel.
s.mustExec(t, "docker", "image", "load", "-i", "dispatcher.tar")
s.mustExec(t, "docker", "image", "load", "-i", "control.tar")
s.mustExec(t, "docker", "image", "load", "-i", "dispatcher.tar/tarball.tar")
s.mustExec(t, "docker", "image", "load", "-i", "control.tar/tarball.tar")
// now start the docker containers
s.mustExec(t, "docker", "compose", "-f", "docker-compose.yml", "up", "-d")
// wait a bit to make sure the containers are ready.
Expand Down Expand Up @@ -178,13 +179,31 @@ func checkTopology(t *testing.T, expectedTopo *topology.RWTopology) {
assert.Equal(t, eJSON, aJSON)
}

func check(t *testing.T) {
url := "http://242.253.100.2:30453/info"
resp, err := http.Get(url)
require.NoError(t, err)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
fmt.Println("--- req url", url)
fmt.Println("--- resp body")
fmt.Println(string(body))

}

func fetchTopologyFromEndpoint(t *testing.T, url string) *topology.RWTopology {
t.Helper()

resp, err := http.Get(url)
require.NoError(t, err)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)

fmt.Println("--- req url", url)
fmt.Println("--- resp body")
fmt.Println(string(body))

require.NoError(t, err)
var topo *topology.RWTopology
require.NoError(t, json.Unmarshal(body, &topo))
Expand Down
83 changes: 57 additions & 26 deletions acceptance/topo_daemon_reload/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//tools/lint:go.bzl", "go_test")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")

go_test(
name = "go_default_test",
Expand All @@ -23,29 +24,59 @@ go_test(
],
)

# oci_image(
# name = "dispatcher",
# base = "//docker:dispatcher",
# cmd = [
# "--config",
# "/disp.toml",
# ],
# entrypoint = ["/app/dispatcher"],
# files = ["testdata/disp.toml"],
# )
# dispatcher container
oci_tarball(
name = "dispatcher.tar",
format = "docker",
image = ":dispatcher_image",
repo_tags = ["bazel/" + package_name() + ":dispatcher"],
)

oci_image(
name = "dispatcher_image",
base = "//docker:dispatcher",
entrypoint = ["/app/dispatcher"],
cmd = [
"--config",
"/disp.toml",
],
tars = [
":dispatcher_data",
],
)

pkg_tar(
name = "dispatcher_data",
srcs = ["testdata/disp.toml"],
)

# daemon container
oci_tarball(
name = "daemon.tar",
format = "docker",
image = ":daemon_image",
repo_tags = ["bazel/" + package_name() + ":daemon"],
)

# oci_image(
# name = "daemon",
# base = "//docker:daemon",
# cmd = [
# "--config",
# "/sd.toml",
# ],
# entrypoint = ["/app/daemon"],
# files = [
# "testdata/sd.toml",
# "testdata/topology_reload.json",
# "//acceptance/topo_common:invalid_reloads",
# "//acceptance/topo_common:topology",
# ],
# )
oci_image(
name = "daemon_image",
base = "//docker:daemon",
entrypoint = ["/app/daemon"],
cmd = [
"--config",
"/sd.toml",
],
tars = [
":daemon_data",
]
)

pkg_tar(
name = "daemon_data",
srcs = [
"testdata/sd.toml",
"testdata/topology_reload.json",
"//acceptance/topo_common:invalid_reloads",
"//acceptance/topo_common:topology",
],
)
4 changes: 2 additions & 2 deletions acceptance/topo_daemon_reload/reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func TestSDTopoReload(t *testing.T) {
func setupTest(t *testing.T) {
// first load the docker images from bazel into the docker deamon, the
// tars are in the same folder as this test runs in bazel.
mustExec(t, "docker", "image", "load", "-i", "dispatcher.tar")
mustExec(t, "docker", "image", "load", "-i", "daemon.tar")
mustExec(t, "docker", "image", "load", "-i", "dispatcher.tar/tarball.tar")
mustExec(t, "docker", "image", "load", "-i", "daemon.tar/tarball.tar")
// now start the docker containers
mustExec(t, "docker", "compose", "-f", "docker-compose.yml",
"up", "-d", "topo_daemon_reload_dispatcher", "topo_daemon_reload_daemon")
Expand Down
Loading

0 comments on commit e36ba06

Please sign in to comment.