Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions e2etests/orchestration/restart_test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2026 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_go//go:def.bzl", "go_test")

go_test(
name = "restart_test_test",
srcs = ["main_test.go"],
data = [
"//orchestration/artifacts:cvd_host_package",
"//orchestration/artifacts:images_zip",
],
deps = [
"//orchestration/common",
"@com_github_google_android_cuttlefish_frontend_src_libhoclient//:libhoclient",
],
)
83 changes: 83 additions & 0 deletions e2etests/orchestration/restart_test/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (C) 2026 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"log"
"testing"

"github.com/google/android-cuttlefish/e2etests/orchestration/common"

hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient"
)

const baseURL = "http://0.0.0.0:2080"

func TestRestart(t *testing.T) {
adbH := common.NewAdbHelper()
if err := adbH.StartServer(); err != nil {
t.Fatal(err)
}
srv := hoclient.NewHostOrchestratorClient(baseURL)
t.Cleanup(func() {
if err := common.CollectHOLogs(baseURL); err != nil {
log.Printf("failed to collect HO logs: %s", err)
}
})
imageDir, err := common.PrepareArtifact(srv, "../artifacts/images.zip")
if err != nil {
t.Fatal(err)
}
hostPkgDir, err := common.PrepareArtifact(srv, "../artifacts/cvd-host_package.tar.gz")
if err != nil {
t.Fatal(err)
}
cvd, err := common.CreateCVDFromImageDirs(srv, hostPkgDir, imageDir)
if err != nil {
t.Fatal(err)
}
if err := adbH.Connect(cvd.ADBSerial); err != nil {
t.Fatal(err)
}
if err := adbH.WaitForDevice(cvd.ADBSerial); err != nil {
t.Fatal(err)
}

// Get boot time before restart
bootTimeBefore, err := adbH.ExecShellCommand(cvd.ADBSerial, []string{"uptime", "-s"})
if err != nil {
t.Fatal(err)
}

// Restart the device
if err := srv.Restart(cvd.Group, cvd.Name); err != nil {
t.Fatal(err)
}

// Verify the device comes back online
if err := adbH.WaitForDevice(cvd.ADBSerial); err != nil {
t.Fatal(err)
}

// Get boot time after restart
bootTimeAfter, err := adbH.ExecShellCommand(cvd.ADBSerial, []string{"uptime", "-s"})
if err != nil {
t.Fatal(err)
}

if bootTimeBefore == bootTimeAfter {
t.Fatalf("Device does not seem to have restarted. Boot time remained: %s", bootTimeBefore)
}
}
2 changes: 2 additions & 0 deletions frontend/src/host_orchestrator/orchestrator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (c *Controller) AddRoutes(router *mux.Router) {
httpHandler(newExecCVDInstanceCommandHandler(c.Config, c.OperationManager, &powerwashCvdCommand{}))).Methods("POST")
router.Handle("/cvds/{group}/{name}/:powerbtn",
httpHandler(newExecCVDInstanceCommandHandler(c.Config, c.OperationManager, &powerbtnCvdCommand{}))).Methods("POST")
router.Handle("/cvds/{group}/{name}/:restart",
httpHandler(newExecCVDInstanceCommandHandler(c.Config, c.OperationManager, &restartCvdCommand{}))).Methods("POST")
router.Handle("/cvds/{group}/{name}/:start_screen_recording",
httpHandler(newExecCVDInstanceCommandHandler(c.Config, c.OperationManager, &startScreenRecordingCvdCommand{}))).Methods("POST")
router.Handle("/cvds/{group}/{name}/:stop_screen_recording",
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/host_orchestrator/orchestrator/cvd/cvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ func (i *Instance) PowerWash() error {
return err
}

func (i *Instance) Restart() error {
args := i.selectorArgs()
args = append(args, "restart")
_, err := i.cli.exec(CVDBin, args...)
return err
}

func (i *Instance) Resume() error {
args := i.selectorArgs()
args = append(args, "resume")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func (a *powerbtnCvdCommand) exec(cvd *cvd.CLI, sel cvd.InstanceSelector) error
return cvd.LazySelectInstance(sel).PowerBtn()
}

type restartCvdCommand struct{}

func (a *restartCvdCommand) exec(cvd *cvd.CLI, sel cvd.InstanceSelector) error {
return cvd.LazySelectInstance(sel).Restart()
}

type startScreenRecordingCvdCommand struct{}

func (a *startScreenRecordingCvdCommand) exec(cvd *cvd.CLI, sel cvd.InstanceSelector) error {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/libhoclient/fake_host_orchestrator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func (c *FakeHostOrchestratorClient) Powerwash(groupName, instanceName string) e

func (c *FakeHostOrchestratorClient) Stop(groupName, instanceName string) error { return nil }

func (c *FakeHostOrchestratorClient) Restart(groupName, instanceName string) error { return nil }

func (c *FakeHostOrchestratorClient) Start(groupName, instanceName string, req *hoapi.StartCVDRequest) error {
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/libhoclient/host_orchestrator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type InstanceOperationsClient interface {
Powerwash(groupName, instanceName string) error
// Stop the device.
Stop(groupName, instanceName string) error
// Restart the device.
Restart(groupName, instanceName string) error
// Press power button.
Powerbtn(groupName, instanceName string) error
// Start the device.
Expand Down Expand Up @@ -489,6 +491,12 @@ func (c *HostOrchestratorClientImpl) Stop(groupName, instanceName string) error
return c.doEmptyResponseRequest(rb)
}

func (c *HostOrchestratorClientImpl) Restart(groupName, instanceName string) error {
path := fmt.Sprintf("/cvds/%s/%s/:restart", groupName, instanceName)
rb := c.HTTPHelper.NewPostRequest(path, nil)
return c.doEmptyResponseRequest(rb)
}

func (c *HostOrchestratorClientImpl) Start(groupName, instanceName string, req *hoapi.StartCVDRequest) error {
path := fmt.Sprintf("/cvds/%s/%s/:start", groupName, instanceName)
rb := c.HTTPHelper.NewPostRequest(path, req)
Expand Down
Loading