Skip to content

Commit

Permalink
[Draft] Snapshot e2e test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ser-io committed Oct 2, 2024
1 parent 4046044 commit 7155fe0
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 22 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ jobs:
e2e-tests-orchestration:
runs-on: ubuntu-22.04
steps:
- name: Free space
run: |
echo "disk space before cleanup:"
df -h
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /usr/local/lib/android/sdk/ndk
sudo rm -rf /usr/local/share/boost
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/hostedtoolcache
sudo rm -rf /opt/ghc
sudo apt-get clean
echo "disk space after cleanup:"
df -h
- name: Check kvm
run: |
ls /dev/kvm
Expand Down
60 changes: 38 additions & 22 deletions e2etests/orchestration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ go_library(
],
)

create_single_instance_test(
name="create_fixed_build_id_and_target",
build_id="11510808",
build_target="aosp_cf_x86_64_phone-trunk_staging-userdebug",
)
# create_single_instance_test(
# name="create_fixed_build_id_and_target",
# build_id="11510808",
# build_target="aosp_cf_x86_64_phone-trunk_staging-userdebug",
# )

aosp_artifact(
name = "cvd_host_package",
Expand All @@ -56,25 +56,41 @@ aosp_artifact(
out_name = "images.zip",
)

go_test(
name = "create_local_image",
srcs = ["createlocalimage_test.go"],
data = [
":images_zip",
":cvd_host_package",
"@images//docker:orchestration_image_tar",
],
deps = [
":e2etesting",
"@com_github_google_android_cuttlefish_frontend_src_liboperator//api/v1:api",
"@com_github_google_cloud_android_orchestration//pkg/client",
"@com_github_google_go_cmp//cmp",
],
)
# go_test(
# name = "create_local_image",
# srcs = ["createlocalimage_test.go"],
# data = [
# ":images_zip",
# ":cvd_host_package",
# "@images//docker:orchestration_image_tar",
# ],
# deps = [
# ":e2etesting",
# "@com_github_google_android_cuttlefish_frontend_src_liboperator//api/v1:api",
# "@com_github_google_cloud_android_orchestration//pkg/client",
# "@com_github_google_go_cmp//cmp",
# ],
# )
#
# go_test(
# name = "create_from_images_zip",
# srcs = ["createfromimageszip_test.go"],
# data = [
# ":images_zip",
# ":cvd_host_package",
# "@images//docker:orchestration_image_tar",
# ],
# deps = [
# ":e2etesting",
# "@com_github_google_android_cuttlefish_frontend_src_liboperator//api/v1:api",
# "@com_github_google_cloud_android_orchestration//pkg/client",
# "@com_github_google_go_cmp//cmp",
# ],
# )

go_test(
name = "create_from_images_zip",
srcs = ["createfromimageszip_test.go"],
name = "snapshot",
srcs = ["snapshot_test.go"],
data = [
":images_zip",
":cvd_host_package",
Expand Down
63 changes: 63 additions & 0 deletions e2etests/orchestration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,69 @@ func (h *DockerHelper) RemoveContainer(id string) error {
return nil
}

func (h *DockerHelper) StartADBServer(id, adbBin string) error {
return h.exec(id, []string{adbBin, "start-server"})
}

func (h *DockerHelper) ConnectADB(id, adbBin, serial string) error {
return h.exec(id, []string{adbBin, "connect", serial})
}

func (h *DockerHelper) ExecADBShellCommand(id, adbBin, serial string, cmd []string) error {
return h.exec(id, append([]string{adbBin, "-s", serial, "shell"}, cmd...))
}

type DockerExecExitCodeError struct {
ExitCode int
}

func (e DockerExecExitCodeError) Error() string {
return fmt.Sprintf("exit code: %d", e.ExitCode)
}

func (h *DockerHelper) exec(id string, cmd []string) error {
if err := h.runExec(id, cmd); err != nil {
return fmt.Errorf("docker exec %v failed: %w", cmd, err)
}
return nil
}

func (h *DockerHelper) runExec(id string, cmd []string) error {
ctx := context.TODO()
config := types.ExecConfig{
User: "root",
Privileged: true,
Cmd: cmd,
}
cExec, err := h.client.ContainerExecCreate(ctx, id, config)
if err != nil {
return err
}
if err = h.client.ContainerExecStart(ctx, cExec.ID, types.ExecStartCheck{}); err != nil {
return err
}
// ContainerExecStart does not block, short poll process status for 60 seconds to
// check when it has been completed. return a time out error otherwise.
cExecStatus := types.ContainerExecInspect{}
for i := 0; i < 30; i++ {
time.Sleep(500 * time.Millisecond)
cExecStatus, err = h.client.ContainerExecInspect(ctx, cExec.ID)
if err != nil {
return err
}
if !cExecStatus.Running {
break
}
}
if cExecStatus.Running {
return fmt.Errorf("command %v timed out", cmd)
}
if cExecStatus.ExitCode != 0 {
return &DockerExecExitCodeError{ExitCode: cExecStatus.ExitCode}
}
return nil
}

func Cleanup(ctx *TestContext) {
dockerHelper, err := NewDockerHelper()
if err != nil {
Expand Down
Loading

0 comments on commit 7155fe0

Please sign in to comment.