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_HOSTNAME_KEY

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, String hostname)

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.

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, MultiMap<String, String> attributes)

Attempt to start a gce instance

Protected methods

buildGceCmd(File reportFile, IBuildInfo b, String ipDevice, MultiMap<String, String> attributes)

Build and return the command to launch GCE.

String extractInstanceName(String bootupLogs)

Retrieve the instance name from the gce boot logs.

Fields

GCE_HOSTNAME_KEY

public static final String GCE_HOSTNAME_KEY

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, 
                String hostname)

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.

hostname String: hostname of the instance, only used for Oxygen cuttlefish.

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.

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, 
                MultiMap<String, String> attributes)

Attempt to start a gce instance

Parameters
ipDevice String: the initial IP of the GCE instance to run AVD in, null if not applicable

attributes MultiMap: attributes associated with current invocation, used for passing applicable information down to the GCE instance to be added as VM metadata

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, 
                MultiMap<String, String> attributes)

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

Parameters
reportFile File

b IBuildInfo

ipDevice String

attributes MultiMap

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