From 6d128c03da81f2915b8e7aa1110640459cad0769 Mon Sep 17 00:00:00 2001 From: Sergio Andres Rodriguez Orama Date: Tue, 15 Oct 2024 12:08:21 -0400 Subject: [PATCH] Make e2e orchestration tests depend on libhoclient. --- e2etests/BUILD.bazel | 1 + e2etests/WORKSPACE | 5 +++++ e2etests/orchestration/common/BUILD.bazel | 2 +- e2etests/orchestration/common/common.go | 6 +++--- .../create_from_images_zip_test/BUILD.bazel | 2 +- .../create_from_images_zip_test/main_test.go | 6 +++--- .../create_local_image_test/BUILD.bazel | 1 + .../create_local_image_test/main_test.go | 8 ++++---- .../create_single_instance_test/def.bzl | 1 + .../create_single_instance_test/main_test.go | 6 +++--- .../orchestration/snapshot_test/BUILD.bazel | 1 + .../orchestration/snapshot_test/main_test.go | 20 +++++++++---------- 12 files changed, 34 insertions(+), 25 deletions(-) diff --git a/e2etests/BUILD.bazel b/e2etests/BUILD.bazel index a7e6b11dec..6f4433bf4e 100644 --- a/e2etests/BUILD.bazel +++ b/e2etests/BUILD.bazel @@ -17,6 +17,7 @@ load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") GO_PREFIX = "github.com/google/android-cuttlefish/e2etests" +# gazelle:resolve_regexp go github.com/google/android-cuttlefish/frontend/src/libhoclient/* @libhoclient gazelle( name = "gazelle", external = "external", diff --git a/e2etests/WORKSPACE b/e2etests/WORKSPACE index 4485cbcb1c..b9305a5253 100644 --- a/e2etests/WORKSPACE +++ b/e2etests/WORKSPACE @@ -59,3 +59,8 @@ local_repository( name = "images", path = "..", ) + +local_repository( + name = "libhoclient", + path = "../frontend/src/libhoclient", +) diff --git a/e2etests/orchestration/common/BUILD.bazel b/e2etests/orchestration/common/BUILD.bazel index 98119c8d99..cc3ed9629f 100644 --- a/e2etests/orchestration/common/BUILD.bazel +++ b/e2etests/orchestration/common/BUILD.bazel @@ -24,6 +24,6 @@ go_library( "@com_github_docker_docker//api/types/container", "@com_github_docker_docker//client", "@com_github_docker_go_connections//nat", - "@com_github_google_cloud_android_orchestration//pkg/client", + "@libhoclient", ], ) diff --git a/e2etests/orchestration/common/common.go b/e2etests/orchestration/common/common.go index fa69da0a27..ce9e2fd543 100644 --- a/e2etests/orchestration/common/common.go +++ b/e2etests/orchestration/common/common.go @@ -19,7 +19,7 @@ import ( "github.com/docker/docker/api/types/container" clientpkg "github.com/docker/docker/client" "github.com/docker/go-connections/nat" - orchclient "github.com/google/cloud-android-orchestration/pkg/client" + hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient" ) type TestContext struct { @@ -247,7 +247,7 @@ func Cleanup(ctx *TestContext) { } } -func DownloadHostBugReport(srv orchclient.HostOrchestratorService, group string) error { +func DownloadHostBugReport(srv hoclient.HostOrchestratorService, group string) error { // `TEST_UNDECLARED_OUTPUTS_DIR` env var is defined by bazel // https://bazel.build/reference/test-encyclopedia#initial-conditions val, ok := os.LookupEnv("TEST_UNDECLARED_OUTPUTS_DIR") @@ -271,7 +271,7 @@ func DownloadHostBugReport(srv orchclient.HostOrchestratorService, group string) return nil } -func UploadAndExtract(srv orchclient.HostOrchestratorService, remoteDir, src string) error { +func UploadAndExtract(srv hoclient.HostOrchestratorService, remoteDir, src string) error { if err := srv.UploadFile(remoteDir, src); err != nil { return err } diff --git a/e2etests/orchestration/create_from_images_zip_test/BUILD.bazel b/e2etests/orchestration/create_from_images_zip_test/BUILD.bazel index 4f55ea40c0..137ec95c39 100644 --- a/e2etests/orchestration/create_from_images_zip_test/BUILD.bazel +++ b/e2etests/orchestration/create_from_images_zip_test/BUILD.bazel @@ -25,7 +25,7 @@ go_test( deps = [ "//orchestration/common", "@com_github_google_android_cuttlefish_frontend_src_host_orchestrator//api/v1:api", - "@com_github_google_cloud_android_orchestration//pkg/client", "@com_github_google_go_cmp//cmp", + "@libhoclient", ], ) diff --git a/e2etests/orchestration/create_from_images_zip_test/main_test.go b/e2etests/orchestration/create_from_images_zip_test/main_test.go index 1c174c6247..f172b6a15a 100644 --- a/e2etests/orchestration/create_from_images_zip_test/main_test.go +++ b/e2etests/orchestration/create_from_images_zip_test/main_test.go @@ -21,7 +21,7 @@ import ( "github.com/google/android-cuttlefish/e2etests/orchestration/common" hoapi "github.com/google/android-cuttlefish/frontend/src/host_orchestrator/api/v1" - "github.com/google/cloud-android-orchestration/pkg/client" + hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient" "github.com/google/go-cmp/cmp" ) @@ -33,7 +33,7 @@ func TestInstance(t *testing.T) { t.Cleanup(func() { common.Cleanup(ctx) }) - srv := client.NewHostOrchestratorService(ctx.ServiceURL) + srv := hoclient.NewHostOrchestratorService(ctx.ServiceURL) uploadDir, err := srv.CreateUploadDir() if err != nil { t.Fatal(err) @@ -77,7 +77,7 @@ func TestInstance(t *testing.T) { EnvConfig: envConfig, } - got, createErr := srv.CreateCVD(createReq, client.BuildAPICredential{}) + got, createErr := srv.CreateCVD(createReq, hoclient.BuildAPICredential{}) if err := common.DownloadHostBugReport(srv, group_name); err != nil { t.Errorf("failed creating bugreport: %s\n", err) diff --git a/e2etests/orchestration/create_local_image_test/BUILD.bazel b/e2etests/orchestration/create_local_image_test/BUILD.bazel index 58bcf5d071..a8616b7a87 100644 --- a/e2etests/orchestration/create_local_image_test/BUILD.bazel +++ b/e2etests/orchestration/create_local_image_test/BUILD.bazel @@ -27,5 +27,6 @@ go_test( "@com_github_google_android_cuttlefish_frontend_src_host_orchestrator//api/v1:api", "@com_github_google_cloud_android_orchestration//pkg/client", "@com_github_google_go_cmp//cmp", + "@libhoclient", ], ) diff --git a/e2etests/orchestration/create_local_image_test/main_test.go b/e2etests/orchestration/create_local_image_test/main_test.go index 6e1d263c7a..078dc50141 100644 --- a/e2etests/orchestration/create_local_image_test/main_test.go +++ b/e2etests/orchestration/create_local_image_test/main_test.go @@ -27,7 +27,7 @@ import ( "github.com/google/android-cuttlefish/e2etests/orchestration/common" hoapi "github.com/google/android-cuttlefish/frontend/src/host_orchestrator/api/v1" - "github.com/google/cloud-android-orchestration/pkg/client" + hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient" "github.com/google/go-cmp/cmp" ) @@ -39,7 +39,7 @@ func TestInstance(t *testing.T) { t.Cleanup(func() { common.Cleanup(ctx) }) - srv := client.NewHostOrchestratorService(ctx.ServiceURL) + srv := hoclient.NewHostOrchestratorService(ctx.ServiceURL) uploadDir, err := srv.CreateUploadDir() if err != nil { t.Fatal(err) @@ -82,7 +82,7 @@ func TestInstance(t *testing.T) { EnvConfig: envConfig, } - got, createErr := srv.CreateCVD(createReq, client.BuildAPICredential{}) + got, createErr := srv.CreateCVD(createReq, hoclient.BuildAPICredential{}) if err := common.DownloadHostBugReport(srv, group_name); err != nil { t.Errorf("failed creating bugreport: %s\n", err) @@ -111,7 +111,7 @@ func TestInstance(t *testing.T) { } } -func uploadImages(srv client.HostOrchestratorService, remoteDir, imgsZipSrc string) error { +func uploadImages(srv hoclient.HostOrchestratorService, remoteDir, imgsZipSrc string) error { outDir := "/tmp/aosp_cf_x86_64_phone-img-12198634" if err := runCmd("unzip", "-d", outDir, imgsZipSrc); err != nil { return err diff --git a/e2etests/orchestration/create_single_instance_test/def.bzl b/e2etests/orchestration/create_single_instance_test/def.bzl index 58d059a118..c9671ddd37 100644 --- a/e2etests/orchestration/create_single_instance_test/def.bzl +++ b/e2etests/orchestration/create_single_instance_test/def.bzl @@ -30,5 +30,6 @@ def create_single_instance_test(name, build_id, build_target): "@com_github_google_cloud_android_orchestration//pkg/client", "@com_github_google_android_cuttlefish_frontend_src_host_orchestrator//api/v1:api", "@com_github_google_go_cmp//cmp", + "@libhoclient", ], ) diff --git a/e2etests/orchestration/create_single_instance_test/main_test.go b/e2etests/orchestration/create_single_instance_test/main_test.go index bad5718d62..12706a6381 100644 --- a/e2etests/orchestration/create_single_instance_test/main_test.go +++ b/e2etests/orchestration/create_single_instance_test/main_test.go @@ -21,7 +21,7 @@ import ( "github.com/google/android-cuttlefish/e2etests/orchestration/common" hoapi "github.com/google/android-cuttlefish/frontend/src/host_orchestrator/api/v1" - client "github.com/google/cloud-android-orchestration/pkg/client" + hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient" "github.com/google/go-cmp/cmp" ) @@ -35,7 +35,7 @@ func TestCreateSingleInstance(t *testing.T) { }) buildID := os.Getenv("BUILD_ID") buildTarget := os.Getenv("BUILD_TARGET") - srv := client.NewHostOrchestratorService(ctx.ServiceURL) + srv := hoclient.NewHostOrchestratorService(ctx.ServiceURL) createReq := &hoapi.CreateCVDRequest{ CVD: &hoapi.CVD{ BuildSource: &hoapi.BuildSource{ @@ -49,7 +49,7 @@ func TestCreateSingleInstance(t *testing.T) { }, } - got, createErr := srv.CreateCVD(createReq, client.BuildAPICredential{}) + got, createErr := srv.CreateCVD(createReq, hoclient.BuildAPICredential{}) if err := common.DownloadHostBugReport(srv, "cvd"); err != nil { t.Errorf("failed creating bugreport: %s\n", err) diff --git a/e2etests/orchestration/snapshot_test/BUILD.bazel b/e2etests/orchestration/snapshot_test/BUILD.bazel index 78f7d6658c..c633769751 100644 --- a/e2etests/orchestration/snapshot_test/BUILD.bazel +++ b/e2etests/orchestration/snapshot_test/BUILD.bazel @@ -27,5 +27,6 @@ go_test( "@com_github_google_android_cuttlefish_frontend_src_host_orchestrator//api/v1:api", "@com_github_google_cloud_android_orchestration//pkg/client", "@com_github_google_go_cmp//cmp", + "@libhoclient", ], ) diff --git a/e2etests/orchestration/snapshot_test/main_test.go b/e2etests/orchestration/snapshot_test/main_test.go index 2b3e088de1..eb6a52dbc3 100644 --- a/e2etests/orchestration/snapshot_test/main_test.go +++ b/e2etests/orchestration/snapshot_test/main_test.go @@ -25,7 +25,7 @@ import ( "github.com/google/android-cuttlefish/e2etests/orchestration/common" hoapi "github.com/google/android-cuttlefish/frontend/src/host_orchestrator/api/v1" - "github.com/google/cloud-android-orchestration/pkg/client" + hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient" "github.com/google/go-cmp/cmp" ) @@ -41,7 +41,7 @@ func TestSnapshot(t *testing.T) { if err != nil { t.Fatal(err) } - srv := client.NewHostOrchestratorService(ctx.ServiceURL) + srv := hoclient.NewHostOrchestratorService(ctx.ServiceURL) uploadDir, err := uploadArtifacts(srv) if err != nil { t.Fatal(err) @@ -109,7 +109,7 @@ func TestSnapshot(t *testing.T) { } } -func uploadArtifacts(srv client.HostOrchestratorService) (string, error) { +func uploadArtifacts(srv hoclient.HostOrchestratorService) (string, error) { uploadDir, err := srv.CreateUploadDir() if err != nil { return "", err @@ -123,7 +123,7 @@ func uploadArtifacts(srv client.HostOrchestratorService) (string, error) { return uploadDir, nil } -func createDevice(srv client.HostOrchestratorService, group_name, artifactsDir string) (*hoapi.CVD, error) { +func createDevice(srv hoclient.HostOrchestratorService, group_name, artifactsDir string) (*hoapi.CVD, error) { config := ` { "common": { @@ -152,7 +152,7 @@ func createDevice(srv client.HostOrchestratorService, group_name, artifactsDir s return nil, err } createReq := &hoapi.CreateCVDRequest{EnvConfig: envConfig} - res, createErr := srv.CreateCVD(createReq, client.BuildAPICredential{}) + res, createErr := srv.CreateCVD(createReq, hoclient.BuildAPICredential{}) if createErr != nil { if err := common.DownloadHostBugReport(srv, group_name); err != nil { log.Printf("error downloading cvd bugreport: %v", err) @@ -175,7 +175,7 @@ type StartCVDRequest struct { // TODO(b/370550070) Remove once this method is added to the client implementation. func createSnapshot(srvURL, group, name string) (*CreateSnapshotResponse, error) { - helper := client.HTTPHelper{ + helper := hoclient.HTTPHelper{ Client: http.DefaultClient, RootEndpoint: srvURL, } @@ -185,7 +185,7 @@ func createSnapshot(srvURL, group, name string) (*CreateSnapshotResponse, error) if err := rb.JSONResDo(op); err != nil { return nil, err } - srv := client.NewHostOrchestratorService(srvURL) + srv := hoclient.NewHostOrchestratorService(srvURL) res := &CreateSnapshotResponse{} if err := srv.WaitForOperation(op.Name, res); err != nil { return nil, err @@ -207,7 +207,7 @@ func startDevice(srvURL, group, name, snapshotID string) error { } func doRequest(srvURL, group, name, oper string, body any) error { - helper := client.HTTPHelper{ + helper := hoclient.HTTPHelper{ Client: http.DefaultClient, RootEndpoint: srvURL, } @@ -217,7 +217,7 @@ func doRequest(srvURL, group, name, oper string, body any) error { if err := rb.JSONResDo(op); err != nil { return err } - srv := client.NewHostOrchestratorService(srvURL) + srv := hoclient.NewHostOrchestratorService(srvURL) res := &hoapi.EmptyResponse{} if err := srv.WaitForOperation(op.Name, &res); err != nil { return err @@ -225,7 +225,7 @@ func doRequest(srvURL, group, name, oper string, body any) error { return nil } -func getCVD(srv client.HostOrchestratorService) (*hoapi.CVD, error) { +func getCVD(srv hoclient.HostOrchestratorService) (*hoapi.CVD, error) { cvds, err := srv.ListCVDs() if err != nil { return nil, err