GceManager

public class GceManager
extends Object

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


管理 GCE 調用以啟動/停止並從 GCE 收集日誌的助手。

概括

字段

public static final String GCE_HOSTNAME_KEY

public static final String GCE_INSTANCE_CLEANED_KEY

public static final String GCE_INSTANCE_NAME_KEY

public static final String GCE_IP_PRECONFIGURED_KEY

公共構造函數

GceManager ( DeviceDescriptor deviceDesc, TestDeviceOptions deviceOptions, IBuildInfo buildInfo)

Ctor

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

此構造函數已棄用。使用其他構造函數,我們暫時保留它是為了向後兼容。

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

Ctor,可用於提供要直接使用的 GCE 實例名稱的變體。

公共方法

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

實際 Acloud 運行以關閉虛擬設備。

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

使用 ssh 從設備獲取 bugreportz 以避免任何 adb 連接潛在問題。

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

讀取 Gce Avd 實例串行日誌的當前內容。

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

通過 ssh 獲取嵌套實例的錯誤報告。

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

從嵌套實例中獲取遠程文件並記錄它。

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

從嵌套實例中獲取遠程文件並記錄它。

void logSerialOutput ( GceAvdInfo infos, ITestLogger logger)

記錄GceAvdInfo描述的設備的串行輸出。

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

在實例上通過 ssh 執行遠程命令。

boolean shutdownGce ()

關閉與startGce()關聯的 Gce 實例。

GceAvdInfo startGce (String ipDevice, String user, Integer offset, MultiMap <String, String> attributes, ITestLogger logger)

嘗試使用 Acloud 或 Oxygen 啟動 gce 實例。

GceAvdInfo startGce ()
GceAvdInfo startGce (String ipDevice, MultiMap <String, String> attributes)

嘗試啟動 gce 實例。

GceAvdInfo startGce (String ipDevice, String user, Integer offset, MultiMap <String, String> attributes)

嘗試使用 Acloud 或 Oxygen 啟動 gce 實例。

startMultiDevicesGce ( buildInfos) startMultiDevicesGce ( buildInfos)

此方法已棄用。更新 master 分支後刪除它。

startMultiDevicesGce ( buildInfos, MultiMap <String, String> attributes) startMultiDevicesGce ( buildInfos, MultiMap <String, String> attributes)

嘗試使用 Oxygen 啟動多設備 gce 實例。

受保護的方法

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

構建並返回啟動 GCE 的命令。

static buildShutdownCommand (File config, TestDeviceOptions options, String instanceName, String hostname, boolean isIpPreconfigured)
String extractInstanceName (String bootupLogs)

從 gce 引導日誌中檢索實例名稱。

字段

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

GCE_IP_PRECONFIGURED_KEY

public static final String GCE_IP_PRECONFIGURED_KEY

公共構造函數

GceManager

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

Ctor

參數
deviceDesc DeviceDescriptor :將與 GCE 設備關聯的DeviceDescriptor

deviceOptions TestDeviceOptions :與設備關聯的TestDeviceOptions

buildInfo IBuildInfo :描述要啟動的 gce 構建的IBuildInfo

GceManager

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

此構造函數已棄用。
使用其他構造函數,我們暫時保留它是為了向後兼容。

參數
deviceDesc DeviceDescriptor

deviceOptions TestDeviceOptions

buildInfo IBuildInfo

testResourceBuildInfos

GceManager

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

Ctor,可用於提供要直接使用的 GCE 實例名稱的變體。

參數
deviceDesc DeviceDescriptor :將與 GCE 設備關聯的DeviceDescriptor

deviceOptions TestDeviceOptions :與設備關聯的TestDeviceOptions

buildInfo IBuildInfo :描述要啟動的 gce 構建的IBuildInfo

gceInstanceName String :要使用的實例名稱。

gceHost String :要使用的實例的主機名或 ip。

公共方法

Acloud關機

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

實際 Acloud 運行以關閉虛擬設備。

參數
options TestDeviceOptions :Acloud 選項的TestDeviceOptions

runUtil IRunUtil :運行 Acloud 的IRunUtil

instanceName String :要關閉的實例。

hostname String : 實例的主機名,僅用於 Oxygen cuttlefish。

isIpPreconfigured boolean :AVD 是否是在具有預配置 IP 的遠程設備上創建的

退貨
boolean如果成功則為真

清理

public void cleanUp ()

getBugreportzWithSsh

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

使用 ssh 從設備獲取 bugreportz 以避免任何 adb 連接潛在問題。

參數
gceAvd GceAvdInfo :描述設備的GceAvdInfo

options TestDeviceOptions :一個TestDeviceOptions描述用於 GCE 設備的設備選項。

runUtil IRunUtil :用於執行命令的IRunUtil

退貨
File指向 zip 錯誤報告的文件,如果出現問題則為 null。

投擲
異常

getInstanceSerialLog

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

讀取 Gce Avd 實例串行日誌的當前內容。

參數
infos GceAvdInfo :描述實例的GceAvdInfo

avdConfigFile File :avd 配置文件

jsonKeyFile File :服務帳戶 json 密鑰文件。

runUtil IRunUtil :用於執行命令的IRunUtil

退貨
String串行日誌輸出,如果出現問題則為 null。

getNestedDeviceSshBugreportz

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

通過 ssh 獲取嵌套實例的錯誤報告。這需要在嵌套的虛擬實例中請求 adb。

參數
gceAvd GceAvdInfo :描述設備的GceAvdInfo

options TestDeviceOptions :一個TestDeviceOptions描述用於 GCE 設備的設備選項。

runUtil IRunUtil :用於執行命令的IRunUtil

退貨
File指向 zip 錯誤報告的文件,如果出現問題則為 null。

投擲
異常

日誌嵌套遠程文件

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

從嵌套實例中獲取遠程文件並記錄它。

參數
logger ITestLogger :記錄文件的ITestLogger

gceAvd GceAvdInfo :描述設備的GceAvdInfo

options TestDeviceOptions :一個TestDeviceOptions描述用於 GCE 設備的設備選項。

runUtil IRunUtil :用於執行命令的IRunUtil

remoteFilePath String :查找文件的遠程路徑。

type LogDataType :記錄文件的LogDataType

退貨
boolean文件是否記錄成功。

日誌嵌套遠程文件

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

從嵌套實例中獲取遠程文件並記錄它。

參數
logger ITestLogger :記錄文件的ITestLogger

gceAvd GceAvdInfo :描述設備的GceAvdInfo

options TestDeviceOptions :一個TestDeviceOptions描述用於 GCE 設備的設備選項。

runUtil IRunUtil :用於執行命令的IRunUtil

remoteFilePath String :查找文件的遠程路徑。

type LogDataType :記錄文件的LogDataType

baseName String :用於記錄文件的基本名稱。如果為空,將使用實際文件名。

退貨
boolean文件是否記錄成功。

日誌串行輸出

public void logSerialOutput (GceAvdInfo infos, 
                ITestLogger logger)

記錄GceAvdInfo描述的設備的串行輸出。

參數
infos GceAvdInfo :描述實例的GceAvdInfo

logger ITestLogger :記錄串行日誌的ITestLogger

遠程 Ssh 命令執行

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

在實例上通過 ssh 執行遠程命令。

參數
gceAvd GceAvdInfo :描述設備的GceAvdInfo

options TestDeviceOptions :一個TestDeviceOptions描述用於 GCE 設備的設備選項。

runUtil IRunUtil :用於執行命令的IRunUtil

timeoutMs long :命令的超時時間(以毫秒為單位)。 0 表示沒有超時。

command String :要執行的遠程命令。

退貨
CommandResult包含執行結果的CommandResult

關閉Gce

public boolean shutdownGce ()

關閉與startGce()關聯的 Gce 實例。

退貨
boolean如果 gce shutdown 被請求為非阻塞,則返回 true。

開始

public GceAvdInfo startGce (String ipDevice, 
                String user, 
                Integer offset, 
                MultiMap<String, String> attributes, 
                ITestLogger logger)

嘗試使用 Acloud 或 Oxygen 啟動 gce 實例。

參數
ipDevice String : 運行 AVD 的 GCE 實例的初始 IP,如果不適用則為null

user String : AVD的主機運行用戶,不適用則為null

offset Integer : 主機中 AVD 的設備編號偏移量,如果不適用則為null

attributes MultiMap :與當前調用關聯的屬性,用於將適用信息向下傳遞到 GCE 實例以作為 VM 元數據添加

logger ITestLogger :用於記錄設備啟動日誌的ITestLogger

退貨
GceAvdInfo描述 GCE 實例的GceAvdInfo 。可能是 BOOT_FAIL 實例。

投擲
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

開始

public GceAvdInfo startGce ()

退貨
GceAvdInfo

投擲
TargetSetupError

開始

public GceAvdInfo startGce (String ipDevice, 
                MultiMap<String, String> attributes)

嘗試啟動 gce 實例。

參數
ipDevice String : 運行 AVD 的 GCE 實例的初始 IP,如果不適用則為null

attributes MultiMap :與當前調用關聯的屬性,用於將適用信息向下傳遞到 GCE 實例以作為 VM 元數據添加

退貨
GceAvdInfo描述 GCE 實例的GceAvdInfo 。可能是 BOOT_FAIL 實例。

投擲
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

開始

public GceAvdInfo startGce (String ipDevice, 
                String user, 
                Integer offset, 
                MultiMap<String, String> attributes)

嘗試使用 Acloud 或 Oxygen 啟動 gce 實例。

參數
ipDevice String : 運行 AVD 的 GCE 實例的初始 IP,如果不適用則為null

user String : AVD的主機運行用戶,不適用則為null

offset Integer : 主機中 AVD 的設備編號偏移量,如果不適用則為null

attributes MultiMap :與當前調用關聯的屬性,用於將適用信息向下傳遞到 GCE 實例以作為 VM 元數據添加

退貨
GceAvdInfo描述 GCE 實例的GceAvdInfo 。可能是 BOOT_FAIL 實例。

投擲
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

啟動MultiDevicesGce

public  startMultiDevicesGce ( buildInfos)

此方法已棄用。
更新 master 分支後刪除它。

參數
buildInfos

退貨

投擲
TargetSetupError

啟動MultiDevicesGce

public  startMultiDevicesGce ( buildInfos, 
                MultiMap<String, String> attributes)

嘗試使用 Oxygen 啟動多設備 gce 實例。

參數
buildInfos : ERROR(/List ) ERROR(/List )

attributes MultiMap :與當前調用關聯的屬性

退貨
一個ERROR(/List ) ERROR(/List )描述 GCE Avd 信息。

投擲
TargetSetupError

受保護的方法

構建GceCmd

protected  buildGceCmd (File reportFile, 
                IBuildInfo b, 
                String ipDevice, 
                String user, 
                Integer offset, 
                MultiMap<String, String> attributes)

構建並返回啟動 GCE 的命令。暴露測試。

參數
reportFile File

b IBuildInfo

ipDevice String

user String

offset Integer

attributes MultiMap

退貨

建立關機命令

protected static  buildShutdownCommand (File config, 
                TestDeviceOptions options, 
                String instanceName, 
                String hostname, 
                boolean isIpPreconfigured)

參數
config File

options TestDeviceOptions

instanceName String

hostname String

isIpPreconfigured boolean

退貨

提取實例名稱

protected String extractInstanceName (String bootupLogs)

從 gce 引導日誌中檢索實例名稱。搜索“名稱”:“gce- ' 模式來提取它的名稱。我們從日誌而不是結果文件中提取,因為在 gce 啟動失敗時,嘗試的實例名稱不會顯示在 json 中。

參數
bootupLogs String

退貨
String