Skip to content

Commit

Permalink
Cover create snapshot operation in host orchestrator client.
Browse files Browse the repository at this point in the history
  • Loading branch information
ser-io committed Oct 30, 2024
1 parent 799ab6e commit 5afa28d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
23 changes: 1 addition & 22 deletions e2etests/orchestration/snapshot_test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"log"
"net/http"
"testing"

"github.com/google/android-cuttlefish/e2etests/orchestration/common"
Expand Down Expand Up @@ -66,7 +65,7 @@ func TestSnapshot(t *testing.T) {
t.Fatal(err)
}
// Create a snapshot containing the temporary file.
createSnapshotRes, err := createSnapshot(ctx.ServiceURL, groupName, cvd.Name)
createSnapshotRes, err := srv.CreateSnapshot(groupName, cvd.Name)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -163,26 +162,6 @@ func createDevice(srv hoclient.HostOrchestratorService, group_name, artifactsDir
return res.CVDs[0], nil
}

// TODO(b/370550070) Remove once this method is added to the client implementation.
func createSnapshot(srvURL, group, name string) (*hoapi.CreateSnapshotResponse, error) {
helper := hoclient.HTTPHelper{
Client: http.DefaultClient,
RootEndpoint: srvURL,
}
op := &hoapi.Operation{}
path := fmt.Sprintf("/cvds/%s/%s/snapshots", group, name)
rb := helper.NewPostRequest(path, nil)
if err := rb.JSONResDo(op); err != nil {
return nil, err
}
srv := hoclient.NewHostOrchestratorService(srvURL)
res := &hoapi.CreateSnapshotResponse{}
if err := srv.WaitForOperation(op.Name, res); err != nil {
return nil, err
}
return res, nil
}

func getCVD(srv hoclient.HostOrchestratorService) (*hoapi.CVD, error) {
cvds, err := srv.ListCVDs()
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/libhoclient/host_orchestrator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ type HostOrchestratorService interface {

// Start the device.
Start(group, name string, req *hoapi.StartCVDRequest) error

// Create device snapshot.
CreateSnapshot(group, name string) (*hoapi.CreateSnapshotResponse, error)
}

const (
Expand Down Expand Up @@ -413,6 +416,25 @@ func (c *HostOrchestratorServiceImpl) Start(group, name string, req *hoapi.Start
return c.doEmptyResponseRequest(rb)
}

func (c *HostOrchestratorServiceImpl) CreateSnapshot(group, name string) (*hoapi.CreateSnapshotResponse, error) {
path := fmt.Sprintf("/cvds/%s/%s/snapshots", group, name)
rb := c.HTTPHelper.NewPostRequest(path, nil)
op := &hoapi.Operation{}
if err := rb.JSONResDo(op); err != nil {
return nil, err
}
res := &hoapi.CreateSnapshotResponse{}
retryOpts := RetryOptions{
StatusCodes: []int{http.StatusServiceUnavailable, http.StatusGatewayTimeout},
RetryDelay: 30 * time.Second,
MaxWait: 10 * time.Minute,
}
if err := c.waitForOperation(op.Name, &res, retryOpts); err != nil {
return nil, err
}
return res, nil
}

func (c *HostOrchestratorServiceImpl) doEmptyResponseRequest(rb *HTTPRequestBuilder) error {
op := &hoapi.Operation{}
if err := rb.JSONResDo(op); err != nil {
Expand Down

0 comments on commit 5afa28d

Please sign in to comment.