Google is committed to advancing racial equity for Black communities. See how.

GceManager

public class GceManager
extends Object

java.lang.Object
   ↳ com.android.tradefed.device.cloud.GceManager


Helper that manages the GCE calls to start/stop and collect logs from GCE.

Summary

Fields

public static final String GCE_INSTANCE_CLEANED_KEY

public static final String GCE_INSTANCE_NAME_KEY

Public constructors

GceManager(DeviceDescriptor deviceDesc, TestDeviceOptions deviceOptions, IBuildInfo buildInfo)

Ctor

GceManager(DeviceDescriptor deviceDesc, TestDeviceOptions deviceOptions, IBuildInfo buildInfo, testResourceBuildInfos)

This constructor is deprecated. Use other constructors, we keep this temporarily for backward compatibility.

GceManager(DeviceDescriptor deviceDesc, TestDeviceOptions deviceOptions, IBuildInfo buildInfo, String gceInstanceName, String gceHost)

Ctor, variation that can be used to provide the GCE instance name to use directly.

Public methods

static boolean AcloudShutdown(TestDeviceOptions options, IRunUtil runUtil, String instanceName)

Actual Acloud run to shutdown the virtual device.

void cleanUp()
static File getBugreportzWithSsh(GceAvdInfo gceAvd, TestDeviceOptions options, IRunUtil runUtil)

Get a bugreportz from the device using ssh to avoid any adb connection potential issue.

static String getInstanceSerialLog(GceAvdInfo infos, File avdConfigFile, File jsonKeyFile, IRunUtil runUtil)

Reads the current content of the Gce Avd instance serial log.

static File getNestedDeviceSshBugreportz(GceAvdInfo gceAvd, TestDeviceOptions options, IRunUtil runUtil)

Get a bugreport via ssh for a nested instance.

static void logNestedRemoteFile(ITestLogger logger, GceAvdInfo gceAvd, TestDeviceOptions options, IRunUtil runUtil, String remoteFilePath, LogDataType type)

Fetch a remote file from a nested instance and log it.

static void logNestedRemoteFile(ITestLogger logger, GceAvdInfo gceAvd, TestDeviceOptions options, IRunUtil runUtil, String remoteFilePath, LogDataType type, String baseName)

Fetch a remote file from a nested instance and log it.

void logSerialOutput(GceAvdInfo infos, ITestLogger logger)

Log the serial output of a device described by GceAvdInfo.

void logStableHostImageInfos(IBuildInfo build)

Log the information related to the stable host image used.

static CommandResult remoteSshCommandExecution(GceAvdInfo gceAvd, TestDeviceOptions options, IRunUtil runUtil, long timeoutMs, String... command)

Execute the remote command via ssh on an instance.

boolean shutdownGce()

Shutdown the Gce instance associated with the startGce().

GceAvdInfo startGce()
GceAvdInfo startGce(String ipDevice)

Attempt to start a gce instance

Protected methods

buildGceCmd(File reportFile, IBuildInfo b, String ipDevice)

Build and return the command to launch GCE.

String extractInstanceName(String bootupLogs)

Retrieve the instance name from the gce boot logs.

Fields

GCE_INSTANCE_CLEANED_KEY

public static final String GCE_INSTANCE_CLEANED_KEY

GCE_INSTANCE_NAME_KEY

public static final String GCE_INSTANCE_NAME_KEY

Public constructors

GceManager

public GceManager (DeviceDescriptor deviceDesc, 
                TestDeviceOptions deviceOptions, 
                IBuildInfo buildInfo)

Ctor

Parameters
deviceDesc DeviceDescriptor: The DeviceDescriptor that will be associated with the GCE device.

deviceOptions TestDeviceOptions: A TestDeviceOptions associated with the device.

buildInfo IBuildInfo: A IBuildInfo describing the gce build to start.

GceManager

public GceManager (DeviceDescriptor deviceDesc, 
                TestDeviceOptions deviceOptions, 
                IBuildInfo buildInfo, 
                 testResourceBuildInfos)

This constructor is deprecated.
Use other constructors, we keep this temporarily for backward compatibility.

Parameters
deviceDesc DeviceDescriptor

deviceOptions TestDeviceOptions

buildInfo IBuildInfo

testResourceBuildInfos

GceManager

public GceManager (DeviceDescriptor deviceDesc, 
                TestDeviceOptions deviceOptions, 
                IBuildInfo buildInfo, 
                String gceInstanceName, 
                String gceHost)

Ctor, variation that can be used to provide the GCE instance name to use directly.

Parameters
deviceDesc DeviceDescriptor: The DeviceDescriptor that will be associated with the GCE device.

deviceOptions TestDeviceOptions: A TestDeviceOptions associated with the device

buildInfo IBuildInfo: A IBuildInfo describing the gce build to start.

gceInstanceName String: The instance name to use.

gceHost String: The host name or ip of the instance to use.

Public methods

AcloudShutdown

public static boolean AcloudShutdown (TestDeviceOptions options, 
                IRunUtil runUtil, 
                String instanceName)

Actual Acloud run to shutdown the virtual device.

Parameters
options TestDeviceOptions: The TestDeviceOptions for the Acloud options

runUtil IRunUtil: The IRunUtil to run Acloud

instanceName String: The instance to shutdown.

Returns
boolean True if successful

cleanUp

public void cleanUp ()

getBugreportzWithSsh

public static File getBugreportzWithSsh (GceAvdInfo gceAvd, 
                TestDeviceOptions options, 
                IRunUtil runUtil)

Get a bugreportz from the device using ssh to avoid any adb connection potential issue.

Parameters
gceAvd GceAvdInfo: The GceAvdInfo that describe the device.

options TestDeviceOptions: a TestDeviceOptions describing the device options to be used for the GCE device.

runUtil IRunUtil: a IRunUtil to execute commands.

Returns
File A file pointing to the zip bugreport, or null if an issue occurred.

getInstanceSerialLog

public static String getInstanceSerialLog (GceAvdInfo infos, 
                File avdConfigFile, 
                File jsonKeyFile, 
                IRunUtil runUtil)

Reads the current content of the Gce Avd instance serial log.

Parameters
infos GceAvdInfo: The GceAvdInfo describing the instance.

avdConfigFile File: the avd config file

jsonKeyFile File: the service account json key file.

runUtil IRunUtil: a IRunUtil to execute commands.

Returns
String The serial log output or null if something goes wrong.

getNestedDeviceSshBugreportz

public static File getNestedDeviceSshBugreportz (GceAvdInfo gceAvd, 
                TestDeviceOptions options, 
                IRunUtil runUtil)

Get a bugreport via ssh for a nested instance. This requires requesting the adb in the nested virtual instance.

Parameters
gceAvd GceAvdInfo: The GceAvdInfo that describe the device.

options TestDeviceOptions: a TestDeviceOptions describing the device options to be used for the GCE device.

runUtil IRunUtil: a IRunUtil to execute commands.

Returns
File A file pointing to the zip bugreport, or null if an issue occurred.

logNestedRemoteFile

public static void logNestedRemoteFile (ITestLogger logger, 
                GceAvdInfo gceAvd, 
                TestDeviceOptions options, 
                IRunUtil runUtil, 
                String remoteFilePath, 
                LogDataType type)

Fetch a remote file from a nested instance and log it.

Parameters
logger ITestLogger: The ITestLogger where to log the file.

gceAvd GceAvdInfo: The GceAvdInfo that describe the device.

options TestDeviceOptions: a TestDeviceOptions describing the device options to be used for the GCE device.

runUtil IRunUtil: a IRunUtil to execute commands.

remoteFilePath String: The remote path where to find the file.

type LogDataType: the LogDataType of the logged file.

logNestedRemoteFile

public static void logNestedRemoteFile (ITestLogger logger, 
                GceAvdInfo gceAvd, 
                TestDeviceOptions options, 
                IRunUtil runUtil, 
                String remoteFilePath, 
                LogDataType type, 
                String baseName)

Fetch a remote file from a nested instance and log it.

Parameters
logger ITestLogger: The ITestLogger where to log the file.

gceAvd GceAvdInfo: The GceAvdInfo that describe the device.

options TestDeviceOptions: a TestDeviceOptions describing the device options to be used for the GCE device.

runUtil IRunUtil: a IRunUtil to execute commands.

remoteFilePath String: The remote path where to find the file.

type LogDataType: the LogDataType of the logged file.

baseName String: The base name to use to log the file. If null the actual file name will be used.

logSerialOutput

public void logSerialOutput (GceAvdInfo infos, 
                ITestLogger logger)

Log the serial output of a device described by GceAvdInfo.

Parameters
infos GceAvdInfo: The GceAvdInfo describing the instance.

logger ITestLogger: The ITestLogger where to log the serial log.

logStableHostImageInfos

public void logStableHostImageInfos (IBuildInfo build)

Log the information related to the stable host image used.

Parameters
build IBuildInfo

remoteSshCommandExecution

public static CommandResult remoteSshCommandExecution (GceAvdInfo gceAvd, 
                TestDeviceOptions options, 
                IRunUtil runUtil, 
                long timeoutMs, 
                String... command)

Execute the remote command via ssh on an instance.

Parameters
gceAvd GceAvdInfo: The GceAvdInfo that describe the device.

options TestDeviceOptions: a TestDeviceOptions describing the device options to be used for the GCE device.

runUtil IRunUtil: a IRunUtil to execute commands.

timeoutMs long: The timeout in millisecond for the command. 0 means no timeout.

command String: The remote command to execute.

Returns
CommandResult CommandResult containing the result of the execution.

shutdownGce

public boolean shutdownGce ()

Shutdown the Gce instance associated with the startGce().

Returns
boolean returns true if gce shutdown was requested as non-blocking.

startGce

public GceAvdInfo startGce ()

Returns
GceAvdInfo

Throws
TargetSetupError

startGce

public GceAvdInfo startGce (String ipDevice)

Attempt to start a gce instance

Parameters
ipDevice String

Returns
GceAvdInfo a GceAvdInfo describing the GCE instance. Could be a BOOT_FAIL instance.

Throws
TargetSetupError

Protected methods

buildGceCmd

protected  buildGceCmd (File reportFile, 
                IBuildInfo b, 
                String ipDevice)

Build and return the command to launch GCE. Exposed for testing.

Parameters
reportFile File

b IBuildInfo

ipDevice String

Returns

extractInstanceName

protected String extractInstanceName (String bootupLogs)

Retrieve the instance name from the gce boot logs. Search for the 'name': 'gce-' pattern to extract the name of it. We extract from the logs instead of result file because on gce boot failure, the attempted instance name won't show in json.

Parameters
bootupLogs String

Returns
String