Include index in preconfigured virtual device serial
The format of preconfigured virtual device serials is changed to
gce-device-<IP address>-<index>-<user>
where -<user> is optional. This format allows multiple devices sharing
an account on a host.
For example, the preconfigured-virtual-device-pool:
192.168.1.2
192.168.1.2:vsoc-01
192.168.1.3:vsoc-01
They are converted to the serials:
gce-device-192.168.1.2-0
gce-device-192.168.1.2-1-vsoc-01
gce-device-192.168.1.3-0-vsoc-01
Test: TF_GLOBAL_CONFIG=test.xml tradefed.sh list devices all
Bug: 229812494
Change-Id: I89fcf632ecae28f578b5623a7d716d1d6e5f3771
diff --git a/global_configuration/com/android/tradefed/host/HostOptions.java b/global_configuration/com/android/tradefed/host/HostOptions.java
index 1cee254..a5262f1 100644
--- a/global_configuration/com/android/tradefed/host/HostOptions.java
+++ b/global_configuration/com/android/tradefed/host/HostOptions.java
@@ -213,8 +213,8 @@
/** {@inheritDoc} */
@Override
- public Set<String> getKnownPreconfigureVirtualDevicePool() {
- return new HashSet<>(mPreconfiguredVirtualDevicePool);
+ public List<String> getKnownPreconfigureVirtualDevicePool() {
+ return new ArrayList<>(mPreconfiguredVirtualDevicePool);
}
/** {@inheritDoc} */
diff --git a/global_configuration/com/android/tradefed/host/IHostOptions.java b/global_configuration/com/android/tradefed/host/IHostOptions.java
index d9634f5..1f27475 100644
--- a/global_configuration/com/android/tradefed/host/IHostOptions.java
+++ b/global_configuration/com/android/tradefed/host/IHostOptions.java
@@ -83,7 +83,7 @@
Set<String> getKnownRemoteDeviceIpPool();
/** Known preconfigured virtual device pool. */
- Set<String> getKnownPreconfigureVirtualDevicePool();
+ List<String> getKnownPreconfigureVirtualDevicePool();
/** Check if it should use the zip64 format in partial download or not. */
boolean getUseZip64InPartialDownload();
diff --git a/src/com/android/tradefed/device/DeviceManager.java b/src/com/android/tradefed/device/DeviceManager.java
index 9fc5c78..dbd0f6f 100644
--- a/src/com/android/tradefed/device/DeviceManager.java
+++ b/src/com/android/tradefed/device/DeviceManager.java
@@ -548,20 +548,17 @@
// hostname.google.com:vsoc-1
String[] parts = preconfigureDevice.split(":", 2);
preconfigureHostUsers.putIfAbsent(parts[0], new ArrayList<>());
- preconfigureHostUsers.get(parts[0]).add(parts[1]);
+ preconfigureHostUsers.get(parts[0]).add(parts.length > 1 ? parts[1] : null);
}
for (Map.Entry<String, List<String>> hostUsers : preconfigureHostUsers.entrySet()) {
for (int i = 0; i < hostUsers.getValue().size(); i++) {
- addAvailableDevice(
- new RemoteAvdIDevice(
- String.format(
- "%s-%s-%s",
- GCE_DEVICE_SERIAL_PREFIX,
- hostUsers.getKey(),
- hostUsers.getValue().get(i)),
- hostUsers.getKey(),
- hostUsers.getValue().get(i),
- i));
+ String user = hostUsers.getValue().get(i);
+ String serial =
+ String.format("%s-%s-%d", GCE_DEVICE_SERIAL_PREFIX, hostUsers.getKey(), i);
+ if (user != null) {
+ serial += "-" + user;
+ }
+ addAvailableDevice(new RemoteAvdIDevice(serial, hostUsers.getKey(), user, i));
}
}