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, 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 從裝置取得錯誤報告,避免發生任何 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 void logDirectory(File remoteDirectory, String baseName, ITestLogger logger, LogDataType type)
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, 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)

司機

參數
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。

公用方法

雲端關機

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:是否在具有預先設定 IP 的遠端裝置上建立 AVD

傳回
boolean 若成功,則為 True

清理

public void cleanUp ()

getBugreportzWithSsh

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

使用 SSH 從裝置取得錯誤報告,避免發生任何 ADB 連線潛在問題。

參數
gceAvd GceAvdInfo:描述裝置的 GceAvdInfo

options TestDeviceOptionsTestDeviceOptions,說明要用於 GCE 裝置的裝置選項。

runUtil IRunUtil:用於執行指令的 IRunUtil

傳回
File 指向 ZIP 錯誤報告的檔案;如果發生問題,則為空值。

擲回
IOException

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 序列記錄輸出;如果發生問題,則為空值。

getNestedDeviceSshBugreportz

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

透過 SSH 取得巢狀執行個體的錯誤報告。這需要在巢狀虛擬執行個體中要求 ADB。

參數
gceAvd GceAvdInfo:描述裝置的 GceAvdInfo

options TestDeviceOptionsTestDeviceOptions,說明要用於 GCE 裝置的裝置選項。

runUtil IRunUtil:用於執行指令的 IRunUtil

傳回
File 指向 ZIP 錯誤報告的檔案;如果發生問題,則為空值。

擲回
IOException

記錄目錄

public static void logDirectory (File remoteDirectory, 
                String baseName, 
                ITestLogger logger, 
                LogDataType type)

參數
remoteDirectory File

baseName String

logger ITestLogger

type LogDataType

logNestedRemoteFile

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

從巢狀執行個體擷取遠端檔案並加以記錄。

參數
logger ITestLogger:用於記錄檔案的 ITestLogger

gceAvd GceAvdInfo:描述裝置的 GceAvdInfo

options TestDeviceOptionsTestDeviceOptions,說明要用於 GCE 裝置的裝置選項。

runUtil IRunUtil:用於執行指令的 IRunUtil

remoteFilePath String:尋找檔案的遠端路徑。

type LogDataType:已記錄檔案的 LogDataType

傳回
boolean 檢查是否成功記錄檔案

logNestedRemoteFile

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 TestDeviceOptionsTestDeviceOptions,說明要用於 GCE 裝置的裝置選項。

runUtil IRunUtil:用於執行指令的 IRunUtil

remoteFilePath String:尋找檔案的遠端路徑。

type LogDataType:已記錄檔案的 LogDataType

baseName String:用來記錄檔案的基礎名稱。如果為空值,系統會使用實際的檔案名稱。

傳回
boolean 檢查是否成功記錄檔案

logSerialOutput

public void logSerialOutput (GceAvdInfo infos, 
                ITestLogger logger)

記錄 GceAvdInfo 描述的裝置序列輸出內容。

參數
infos GceAvdInfo:說明執行個體的 GceAvdInfo

logger ITestLogger:用於記錄序列記錄的 ITestLogger

RemoteSshCommandExecution

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

透過執行個體的 SSH 執行遠端指令。

參數
gceAvd GceAvdInfo:描述裝置的 GceAvdInfo

options TestDeviceOptionsTestDeviceOptions,說明要用於 GCE 裝置的裝置選項。

runUtil IRunUtil:用於執行指令的 IRunUtil

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

command String:要執行的遠端指令。

傳回
CommandResult CommandResult,包含執行結果。

關機

public boolean shutdownGce ()

關閉與 startGce() 相關聯的 Gce 執行個體。

傳回
boolean 如果 gce 因非阻塞而要求關閉,則會傳回 true。

startGce

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:與目前叫用相關聯的屬性,用來將適用資訊向下傳遞至要新增為 VM 中繼資料的 GCE 執行個體

logger ITestLogger:用來記錄裝置啟動記錄的 ITestLogger

傳回
GceAvdInfo 說明 GCE 執行個體的 GceAvdInfo。可以是 BOOT_FAIL 執行個體。

擲回
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

startGce

public GceAvdInfo startGce ()

傳回
GceAvdInfo

擲回
TargetSetupError

startGce

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

嘗試啟動 gce 執行個體。

參數
ipDevice String:用於執行 AVD 的 GCE 執行個體的初始 IP,null (如適用)

attributes MultiMap:與目前叫用相關聯的屬性,用來將適用資訊向下傳遞至要新增為 VM 中繼資料的 GCE 執行個體

傳回
GceAvdInfo 說明 GCE 執行個體的 GceAvdInfo。可以是 BOOT_FAIL 執行個體。

擲回
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

startGce

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:與目前叫用相關聯的屬性,用來將適用資訊向下傳遞至要新增為 VM 中繼資料的 GCE 執行個體

傳回
GceAvdInfo 說明 GCE 執行個體的 GceAvdInfo。可以是 BOOT_FAIL 執行個體。

擲回
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

啟動 MultiDeviceGce

public  startMultiDevicesGce ( buildInfos)

此方法已淘汰。
請在主要分支版本更新後移除此項目。

參數
buildInfos

傳回

擲回
TargetSetupError

啟動 MultiDeviceGce

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

嘗試使用 Oxygen 啟動多裝置 gce 執行個體。

參數
buildInfos ERROR(/List)

attributes MultiMap:與目前叫用相關聯的屬性

傳回
說明 GCE 廣告主資訊的 ERROR(/List)

擲回
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

傳回

BuildShutdownCommand

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 開機記錄檔中擷取執行個體名稱。搜尋「name」:「gce-」模式以擷取名稱。我們會從記錄 (而非結果檔案) 擷取內容,因為 gce 啟動失敗時,嘗試執行的執行個體名稱不會顯示在 JSON 中。

參數
bootupLogs String

傳回
String