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

Public constructors

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

Ctor

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

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

Public methods

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.

void shutdownGce()

Shutdown the Gce instance associated with the startGce().

GceAvdInfo startGce()

Attempt to start a gce instance

Protected methods

buildGceCmd(File reportFile, IBuildInfo b)

Build and return the command to launch GCE.

String extractInstanceName(String bootupLogs)

Retrieve the instance name from the gce boot logs.

Public constructors

GceManager

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

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.

testResourceBuildInfos : A list IBuildInfo describing test resources

GceManager

public GceManager (DeviceDescriptor deviceDesc, 
                TestDeviceOptions deviceOptions, 
                IBuildInfo buildInfo, 
                 testResourceBuildInfos, 
                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.

testResourceBuildInfos : A list IBuildInfo describing test resources

gceInstanceName String: The instance name to use.

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

Public methods

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 void shutdownGce ()

Shutdown the Gce instance associated with the startGce().

startGce

public GceAvdInfo startGce ()

Attempt to start a gce instance

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)

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

Parameters
reportFile File

b IBuildInfo

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