Merge "Start removing some of the GCS test resource logic"
diff --git a/device_build_interfaces/com/android/tradefed/device/TestDeviceOptions.java b/device_build_interfaces/com/android/tradefed/device/TestDeviceOptions.java
index 0d10607..e3d7de1 100644
--- a/device_build_interfaces/com/android/tradefed/device/TestDeviceOptions.java
+++ b/device_build_interfaces/com/android/tradefed/device/TestDeviceOptions.java
@@ -176,11 +176,6 @@
private File mAvdConfigFile = null;
@Option(
- name = "gce-driver-config-test-resource-name",
- description = "Test resource name of the config to use to launch GCE devices.")
- private String mAvdConfigTestResourceName;
-
- @Option(
name = "gce-driver-service-account-json-key-path",
description = "path to the service account json key location.")
private File mJsonKeyFile = null;
@@ -549,11 +544,6 @@
mAvdConfigFile = avdConfigFile;
}
- /** Return the Gce Avd config test resource name to start the instance. */
- public String getAvdConfigTestResourceName() {
- return mAvdConfigTestResourceName;
- }
-
/** @return the service account json key file. */
public File getServiceAccountJsonKeyFile() {
return mJsonKeyFile;
diff --git a/src/com/android/tradefed/build/GCSTestResourceProvider.java b/src/com/android/tradefed/build/GCSTestResourceProvider.java
deleted file mode 100644
index aabbeb2..0000000
--- a/src/com/android/tradefed/build/GCSTestResourceProvider.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tradefed.build;
-
-import com.android.tradefed.build.gcs.GCSDownloaderHelper;
-import com.android.tradefed.config.Option;
-
-import com.google.common.annotations.VisibleForTesting;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
-/** Download test resource from GCS. */
-public class GCSTestResourceProvider implements IBuildProvider {
-
- @Option(
- name = "test-resource",
- description =
- "GCS files as test resources that are required for the test."
- + "Key is the identity of the test resource."
- + "Value is a gs://bucket/path/to/file format GCS path.")
- private Map<String, String> mTestResources = new HashMap<>();
-
- private IBuildInfo mBuildInfo;
- private GCSDownloaderHelper mDownloaderHelper = null;
-
- @Override
- public IBuildInfo getBuild() throws BuildRetrievalError {
- mBuildInfo = new BuildInfo();
- mBuildInfo.setTestResourceBuild(true);
- fetchTestResources();
- return mBuildInfo;
- }
-
- private void fetchTestResources() throws BuildRetrievalError {
- for (Map.Entry<String, String> entry : mTestResources.entrySet()) {
- fetchTestResource(entry.getKey(), entry.getValue());
- }
- }
-
- private void fetchTestResource(String key, String value) throws BuildRetrievalError {
- File localFile = getHelper().fetchTestResource(value);
- mBuildInfo.setFile(key, localFile, "");
- }
-
- @Override
- public void cleanUp(IBuildInfo info) {
- info.cleanUp();
- }
-
- /** Returns the {@link GCSDownloaderHelper} that downloads from GCS buckets. */
- @VisibleForTesting
- GCSDownloaderHelper getHelper() {
- if (mDownloaderHelper == null) {
- mDownloaderHelper = new GCSDownloaderHelper();
- }
- return mDownloaderHelper;
- }
-}
diff --git a/src/com/android/tradefed/device/cloud/GceManager.java b/src/com/android/tradefed/device/cloud/GceManager.java
index 3e6a77d..4ef0434 100644
--- a/src/com/android/tradefed/device/cloud/GceManager.java
+++ b/src/com/android/tradefed/device/cloud/GceManager.java
@@ -15,7 +15,6 @@
*/
package com.android.tradefed.device.cloud;
-import com.android.tradefed.build.BuildInfo;
import com.android.tradefed.build.IBuildInfo;
import com.android.tradefed.command.remote.DeviceDescriptor;
import com.android.tradefed.device.TestDeviceOptions;
@@ -71,7 +70,6 @@
private DeviceDescriptor mDeviceDescriptor;
private TestDeviceOptions mDeviceOptions;
private IBuildInfo mBuildInfo;
- private List<IBuildInfo> mTestResourceBuildInfos;
private String mGceInstanceName = null;
private String mGceHost = null;
@@ -83,17 +81,12 @@
* @param deviceDesc The {@link DeviceDescriptor} that will be associated with the GCE device.
* @param deviceOptions A {@link TestDeviceOptions} associated with the device.
* @param buildInfo A {@link IBuildInfo} describing the gce build to start.
- * @param testResourceBuildInfos A list {@link IBuildInfo} describing test resources
*/
public GceManager(
- DeviceDescriptor deviceDesc,
- TestDeviceOptions deviceOptions,
- IBuildInfo buildInfo,
- List<IBuildInfo> testResourceBuildInfos) {
+ DeviceDescriptor deviceDesc, TestDeviceOptions deviceOptions, IBuildInfo buildInfo) {
mDeviceDescriptor = deviceDesc;
mDeviceOptions = deviceOptions;
mBuildInfo = buildInfo;
- mTestResourceBuildInfos = testResourceBuildInfos;
if (!deviceOptions.allowGceCmdTimeoutOverride()) {
return;
@@ -117,13 +110,22 @@
}
}
+ /** @deprecated Use other constructors, we keep this temporarily for backward compatibility. */
+ @Deprecated
+ public GceManager(
+ DeviceDescriptor deviceDesc,
+ TestDeviceOptions deviceOptions,
+ IBuildInfo buildInfo,
+ List<IBuildInfo> testResourceBuildInfos) {
+ this(deviceDesc, deviceOptions, buildInfo);
+ }
+
/**
* Ctor, variation that can be used to provide the GCE instance name to use directly.
*
* @param deviceDesc The {@link DeviceDescriptor} that will be associated with the GCE device.
* @param deviceOptions A {@link TestDeviceOptions} associated with the device
* @param buildInfo A {@link IBuildInfo} describing the gce build to start.
- * @param testResourceBuildInfos A list {@link IBuildInfo} describing test resources
* @param gceInstanceName The instance name to use.
* @param gceHost The host name or ip of the instance to use.
*/
@@ -131,10 +133,9 @@
DeviceDescriptor deviceDesc,
TestDeviceOptions deviceOptions,
IBuildInfo buildInfo,
- List<IBuildInfo> testResourceBuildInfos,
String gceInstanceName,
String gceHost) {
- this(deviceDesc, deviceOptions, buildInfo, testResourceBuildInfos);
+ this(deviceDesc, deviceOptions, buildInfo);
mGceInstanceName = gceInstanceName;
mGceHost = gceHost;
}
@@ -729,10 +730,6 @@
@VisibleForTesting
File getAvdConfigFile() {
- if (getTestDeviceOptions().getAvdConfigTestResourceName() != null) {
- return BuildInfo.getTestResource(
- mTestResourceBuildInfos, getTestDeviceOptions().getAvdConfigTestResourceName());
- }
return getTestDeviceOptions().getAvdConfigFile();
}
diff --git a/src/com/android/tradefed/device/cloud/ManagedRemoteDevice.java b/src/com/android/tradefed/device/cloud/ManagedRemoteDevice.java
index f196cfe..282c9bd 100644
--- a/src/com/android/tradefed/device/cloud/ManagedRemoteDevice.java
+++ b/src/com/android/tradefed/device/cloud/ManagedRemoteDevice.java
@@ -79,7 +79,7 @@
// First get the options
TestDeviceOptions options = getOptions();
// We create a brand new GceManager each time to ensure clean state.
- mGceHandler = new GceManager(getDeviceDescriptor(), options, info, testResourceBuildInfos);
+ mGceHandler = new GceManager(getDeviceDescriptor(), options, info);
getGceHandler().logStableHostImageInfos(info);
setFastbootEnabled(false);
diff --git a/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java b/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java
index d0c2875..641fe31 100644
--- a/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java
+++ b/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java
@@ -91,9 +91,7 @@
mGceAvd = null;
mGceSshMonitor = null;
// We create a brand new GceManager each time to ensure clean state.
- mGceHandler =
- new GceManager(
- getDeviceDescriptor(), getOptions(), info, testResourceBuildInfos);
+ mGceHandler = new GceManager(getDeviceDescriptor(), getOptions(), info);
getGceHandler().logStableHostImageInfos(info);
setFastbootEnabled(false);
diff --git a/tests/src/com/android/tradefed/UnitTests.java b/tests/src/com/android/tradefed/UnitTests.java
index 3dabdfc..45594a4 100644
--- a/tests/src/com/android/tradefed/UnitTests.java
+++ b/tests/src/com/android/tradefed/UnitTests.java
@@ -23,7 +23,6 @@
import com.android.tradefed.build.DeviceBuildInfoTest;
import com.android.tradefed.build.DeviceFolderBuildInfoTest;
import com.android.tradefed.build.FileDownloadCacheTest;
-import com.android.tradefed.build.GCSTestResourceProviderTest;
import com.android.tradefed.build.LocalDeviceBuildProviderTest;
import com.android.tradefed.build.OtaZipfileBuildProviderTest;
import com.android.tradefed.clearcut.ClearcutClientTest;
@@ -415,7 +414,6 @@
DeviceBuildDescriptorTest.class,
DeviceFolderBuildInfoTest.class,
FileDownloadCacheTest.class,
- GCSTestResourceProviderTest.class,
LocalDeviceBuildProviderTest.class,
OtaZipfileBuildProviderTest.class,
diff --git a/tests/src/com/android/tradefed/build/GCSTestResourceProviderTest.java b/tests/src/com/android/tradefed/build/GCSTestResourceProviderTest.java
deleted file mode 100644
index ad93333..0000000
--- a/tests/src/com/android/tradefed/build/GCSTestResourceProviderTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tradefed.build;
-
-import com.android.tradefed.build.gcs.GCSDownloaderHelper;
-import com.android.tradefed.config.OptionSetter;
-import com.android.tradefed.util.FileUtil;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.io.File;
-import java.io.IOException;
-
-/** Unit test for {@link GCSTestResourceProvider}. */
-@RunWith(JUnit4.class)
-public class GCSTestResourceProviderTest {
-
- private static final String TEST_RESOURCE1 = "gs://b/this/is/a/file1.txt";
- private static final String TEST_RESOURCE2 = "gs://b/this/is/a/file2.txt";
-
- private File mRoot;
- private GCSTestResourceProvider mTestResourceProvider;
-
- @Before
- public void setUp() throws Exception {
- mRoot = FileUtil.createTempDir(GCSTestResourceProviderTest.class.getSimpleName());
- mTestResourceProvider =
- new GCSTestResourceProvider() {
- @Override
- GCSDownloaderHelper getHelper() {
- return new GCSDownloaderHelper() {
- @Override
- public File fetchTestResource(String gsPath)
- throws BuildRetrievalError {
- try {
- File f = FileUtil.createTempFile("test-gcs-file", "txt");
- FileUtil.writeToFile(gsPath, f);
- return f;
- } catch (IOException e) {
- throw new BuildRetrievalError(e.getMessage(), e);
- }
- }
- };
- }
- };
- OptionSetter setter = new OptionSetter(mTestResourceProvider);
- setter.setOptionValue("test-resource", "key1", TEST_RESOURCE1);
- setter.setOptionValue("test-resource", "key2", TEST_RESOURCE2);
- }
-
- @After
- public void tearDown() {
- FileUtil.recursiveDelete(mRoot);
- }
-
- @Test
- public void testGetBuild() throws Exception {
- IBuildInfo buildInfo = mTestResourceProvider.getBuild();
- File file1 = buildInfo.getFile("key1");
- File file2 = buildInfo.getFile("key2");
- Assert.assertEquals(TEST_RESOURCE1, FileUtil.readStringFromFile(file1));
- Assert.assertEquals(TEST_RESOURCE2, FileUtil.readStringFromFile(file2));
- mTestResourceProvider.cleanUp(buildInfo);
- Assert.assertFalse(file1.exists());
- Assert.assertFalse(file2.exists());
- }
-}
diff --git a/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java b/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java
index f3bdced..cae19ce 100644
--- a/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java
+++ b/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java
@@ -40,7 +40,6 @@
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -79,7 +78,7 @@
mOptions.setAvdDriverBinary(mAvdBinary);
mOptions.setAvdConfigFile(mAvdBinary);
mGceManager =
- new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null) {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo) {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -249,7 +248,7 @@
setter.setOptionValue("gce-driver-param", "--emulator-build-id");
setter.setOptionValue("gce-driver-param", "EMULATOR_BUILD_ID");
mGceManager =
- new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null) {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo) {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -331,7 +330,7 @@
// Boot-time on Acloud params will be overridden by TF option.
setter.setOptionValue("allow-gce-boot-timeout-override", "false");
mGceManager =
- new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null) {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo) {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -418,7 +417,7 @@
OptionSetter setter = new OptionSetter(mOptions);
setter.setOptionValue("allow-gce-boot-timeout-override", "true");
mGceManager =
- new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null) {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo) {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -475,7 +474,7 @@
OptionSetter setter = new OptionSetter(mOptions);
setter.setOptionValue("allow-gce-boot-timeout-override", "true");
mGceManager =
- new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null) {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo) {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -517,7 +516,7 @@
OptionSetter setter = new OptionSetter(mOptions);
setter.setOptionValue("allow-gce-boot-timeout-override", "true");
mGceManager =
- new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null) {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo) {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -572,8 +571,7 @@
@Test
public void testShutdownGce() throws Exception {
mGceManager =
- new GceManager(
- mMockDeviceDesc, mOptions, mMockBuildInfo, null, "instance1", "host1") {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, "instance1", "host1") {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -611,8 +609,7 @@
OptionSetter setter = new OptionSetter(mOptions);
setter.setOptionValue("wait-gce-teardown", "false");
mGceManager =
- new GceManager(
- mMockDeviceDesc, mOptions, mMockBuildInfo, null, "instance1", "host1") {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, "instance1", "host1") {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -645,8 +642,7 @@
@Test
public void testShutdownGce_withJsonKeyFile() throws Exception {
mGceManager =
- new GceManager(
- mMockDeviceDesc, mOptions, mMockBuildInfo, null, "instance1", "host1") {
+ new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, "instance1", "host1") {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -854,7 +850,7 @@
setter.setOptionValue("allow-gce-boot-timeout-override", "true");
DeviceDescriptor desc = null;
mGceManager =
- new GceManager(desc, mOptions, mMockBuildInfo, null) {
+ new GceManager(desc, mOptions, mMockBuildInfo) {
@Override
IRunUtil getRunUtil() {
return mMockRunUtil;
@@ -916,28 +912,6 @@
EasyMock.verify(mMockRunUtil);
}
- /**
- * Test {@link GceManager#getAvdConfigFile()} while using test resource.
- *
- * @throws Exception
- */
- @Test
- public void testGetAvdConfigFile_testResource() throws Exception {
- OptionSetter setter = new OptionSetter(mOptions);
- setter.setOptionValue("gce-driver-config-test-resource-name", "device.config");
-
- BuildInfo testResourceBuild = new BuildInfo();
- testResourceBuild.setTestResourceBuild(true);
- File configFile = new File("device.config");
- testResourceBuild.setFile("device.config", configFile, "");
- List<IBuildInfo> testResourceBuildInfos = new ArrayList<>();
- testResourceBuildInfos.add(testResourceBuild);
-
- mGceManager =
- new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, testResourceBuildInfos);
- Assert.assertEquals(configFile, mGceManager.getAvdConfigFile());
- }
-
@Test
public void testUpdateTimeout() throws Exception {
OptionSetter setter = new OptionSetter(mOptions);
@@ -945,7 +919,7 @@
mOptions.getGceDriverParams().add("--boot-timeout");
mOptions.getGceDriverParams().add("900");
assertEquals(1800000L, mOptions.getGceCmdTimeout());
- mGceManager = new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null);
+ mGceManager = new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo);
assertEquals(1080000L, mOptions.getGceCmdTimeout());
}
@@ -958,7 +932,7 @@
mOptions.getGceDriverParams().add("--boot-timeout");
mOptions.getGceDriverParams().add("450");
assertEquals(1800000L, mOptions.getGceCmdTimeout());
- mGceManager = new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null);
+ mGceManager = new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo);
// The last specified boot-timeout is used.
assertEquals(630000L, mOptions.getGceCmdTimeout());
}
@@ -970,7 +944,7 @@
mOptions.getGceDriverParams().add("--someargs");
mOptions.getGceDriverParams().add("900");
assertEquals(1800000L, mOptions.getGceCmdTimeout());
- mGceManager = new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo, null);
+ mGceManager = new GceManager(mMockDeviceDesc, mOptions, mMockBuildInfo);
assertEquals(1800000L, mOptions.getGceCmdTimeout());
}
}
diff --git a/tests/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDeviceTest.java b/tests/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDeviceTest.java
index 6fa4e2b..e8d0219 100644
--- a/tests/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDeviceTest.java
+++ b/tests/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDeviceTest.java
@@ -174,10 +174,7 @@
@Override
GceManager getGceHandler() {
return new GceManager(
- getDeviceDescriptor(),
- new TestDeviceOptions(),
- mMockBuildInfo,
- null) {
+ getDeviceDescriptor(), new TestDeviceOptions(), mMockBuildInfo) {
@Override
protected List<String> buildGceCmd(
File reportFile, IBuildInfo b, String ipDevice) {