Fix NullPointerException thrown by AcloudShutdown
A virtual device with preconfigured IP address does not require
a configuration file.
Test: ./run_tradefed_tests.sh
Bug: 216591507
Change-Id: I033d6cdf3c886f80b4428455df3ca2a4cfd814b1
diff --git a/src/com/android/tradefed/device/cloud/GceManager.java b/src/com/android/tradefed/device/cloud/GceManager.java
index 2d465a2..3123cf8 100644
--- a/src/com/android/tradefed/device/cloud/GceManager.java
+++ b/src/com/android/tradefed/device/cloud/GceManager.java
@@ -744,7 +744,7 @@
gceArgs.add(options.getInstanceUser());
gceArgs.add("--host-ssh-private-key-path");
gceArgs.add(options.getSshPrivateKeyPath().getAbsolutePath());
- } else {
+ } else if (config != null) {
gceArgs.add("--config_file");
gceArgs.add(config.getAbsolutePath());
}
@@ -772,10 +772,13 @@
// Add extra args.
File config = null;
try {
- config = FileUtil.createTempFile(options.getAvdConfigFile().getName(), "config");
- // Copy the config in case it comes from a dynamic file. In order to ensure Acloud has
- // the file until it's done with it.
- FileUtil.copyFile(options.getAvdConfigFile(), config);
+ File originalConfig = options.getAvdConfigFile();
+ if (originalConfig != null) {
+ config = FileUtil.createTempFile(originalConfig.getName(), "config");
+ // Copy the config in case it comes from a dynamic file. In order to ensure Acloud
+ // has the file until it's done with it.
+ FileUtil.copyFile(originalConfig, config);
+ }
List<String> gceArgs =
buildShutdownCommand(
config, options, instanceName, hostname, isIpPreconfigured);
@@ -803,8 +806,9 @@
// Discard the output so the process is not linked to the parent and doesn't die
// if the JVM exit.
Process p = runUtil.runCmdInBackground(Redirect.DISCARD, gceArgs);
- AcloudDeleteCleaner cleaner = new AcloudDeleteCleaner(p, config);
- cleaner.start();
+ if (config != null) {
+ new AcloudDeleteCleaner(p, config).start();
+ }
}
} catch (IOException ioe) {
CLog.e("failed to create log file for GCE Teardown");