aboutsummaryrefslogtreecommitdiff
path: root/public/actions/create_goldfish_action_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'public/actions/create_goldfish_action_test.py')
-rw-r--r--public/actions/create_goldfish_action_test.py121
1 files changed, 112 insertions, 9 deletions
diff --git a/public/actions/create_goldfish_action_test.py b/public/actions/create_goldfish_action_test.py
index 3d841b1f..12320f2b 100644
--- a/public/actions/create_goldfish_action_test.py
+++ b/public/actions/create_goldfish_action_test.py
@@ -15,9 +15,10 @@
# limitations under the License.
"""Tests for acloud.public.actions.create_goldfish_actions."""
import uuid
-
import unittest
import mock
+
+from acloud.internal import constants
from acloud.internal.lib import android_build_client
from acloud.internal.lib import android_compute_client
from acloud.internal.lib import auth
@@ -43,6 +44,7 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
GOLDFISH_HOST_IMAGE_NAME = "fake-stable-host-image-name"
GOLDFISH_HOST_IMAGE_PROJECT = "fake-stable-host-image-project"
EXTRA_DATA_DISK_GB = 4
+ EXTRA_SCOPES = None
def setUp(self):
"""Sets up the test."""
@@ -62,6 +64,16 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
"AndroidComputeClient",
return_value=self.compute_client)
self.Patch(auth, "CreateCredentials", return_value=mock.MagicMock())
+ #Initialize new avd_spec
+ self.avd_spec = mock.MagicMock()
+ self.avd_spec.cfg = self._CreateCfg()
+ self.avd_spec.remote_image = {constants.BUILD_ID: self.BUILD_ID,
+ constants.BUILD_BRANCH: self.BRANCH,
+ constants.BUILD_TARGET: self.BUILD_TARGET}
+ self.avd_spec.emulator_build_id = self.EMULATOR_BUILD_ID
+ self.avd_spec.gpu = self.GPU
+ self.avd_spec.serial_log_file = None
+ self.avd_spec.autoconnect = False
def _CreateCfg(self):
"""A helper method that creates a mock configuration object."""
@@ -75,6 +87,7 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
cfg.stable_goldfish_host_image_project = self.GOLDFISH_HOST_IMAGE_PROJECT
cfg.emulator_build_target = self.EMULATOR_TARGET
cfg.extra_data_disk_size_gb = self.EXTRA_DATA_DISK_GB
+ cfg.extra_scopes = self.EXTRA_SCOPES
return cfg
def testCreateDevices(self):
@@ -95,10 +108,12 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
self.BRANCH, self.EMULATOR_BRANCH
]
- # Call CreateDevices
+ none_avd_spec = None
+
+ # Call CreateDevices with avd_spec is None
report = create_goldfish_action.CreateDevices(
- cfg, self.BUILD_TARGET, self.BUILD_ID, self.EMULATOR_BUILD_ID,
- self.GPU)
+ none_avd_spec, cfg, self.BUILD_TARGET, self.BUILD_ID,
+ self.EMULATOR_BUILD_ID, self.GPU)
# Verify
self.compute_client.CreateInstance.assert_called_with(
@@ -111,19 +126,47 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
build_id=self.BUILD_ID,
emulator_branch=self.EMULATOR_BRANCH,
emulator_build_id=self.EMULATOR_BUILD_ID,
- gpu=self.GPU)
+ gpu=self.GPU,
+ avd_spec=none_avd_spec,
+ extra_scopes=self.EXTRA_SCOPES)
self.assertEquals(report.data, {
"devices": [
{
"instance_name": self.INSTANCE,
"ip": self.IP.external,
+ "branch": self.BRANCH,
+ "build_id": self.BUILD_ID,
+ "build_target": self.BUILD_TARGET,
+ "emulator_branch": self.EMULATOR_BRANCH,
+ "emulator_build_id": self.EMULATOR_BUILD_ID,
+ "emulator_build_target": self.EMULATOR_TARGET,
},
],
})
self.assertEquals(report.command, "create_gf")
self.assertEquals(report.status, "SUCCESS")
+ # Call CreateDevices with avd_spec
+ self.build_client.GetBranch.side_effect = [
+ self.BRANCH, self.EMULATOR_BRANCH
+ ]
+ report = create_goldfish_action.CreateDevices(avd_spec=self.avd_spec)
+ # Verify
+ self.compute_client.CreateInstance.assert_called_with(
+ instance=self.INSTANCE,
+ blank_data_disk_size_gb=self.EXTRA_DATA_DISK_GB,
+ image_name=self.GOLDFISH_HOST_IMAGE_NAME,
+ image_project=self.GOLDFISH_HOST_IMAGE_PROJECT,
+ build_target=self.BUILD_TARGET,
+ branch=self.BRANCH,
+ build_id=self.BUILD_ID,
+ emulator_branch=self.EMULATOR_BRANCH,
+ emulator_build_id=self.EMULATOR_BUILD_ID,
+ gpu=self.GPU,
+ avd_spec=self.avd_spec,
+ extra_scopes=self.EXTRA_SCOPES)
+
def testCreateDevicesWithoutBuildId(self):
"""Test CreateDevices when emulator sys image build id is not provided."""
cfg = self._CreateCfg()
@@ -148,8 +191,10 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
"_FetchBuildIdFromFile",
return_value=self.BUILD_ID)
- # Call CreateDevices
+ none_avd_spec = None
+ # Call CreateDevices with no avd_spec
report = create_goldfish_action.CreateDevices(
+ none_avd_spec,
cfg,
self.BUILD_TARGET,
None,
@@ -168,17 +213,45 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
build_id=self.BUILD_ID,
emulator_branch=self.EMULATOR_BRANCH,
emulator_build_id=self.EMULATOR_BUILD_ID,
- gpu=self.GPU)
+ gpu=self.GPU,
+ avd_spec=none_avd_spec,
+ extra_scopes=self.EXTRA_SCOPES)
self.assertEquals(report.data, {
"devices": [{
"instance_name": self.INSTANCE,
"ip": self.IP.external,
+ "branch": self.BRANCH,
+ "build_id": self.BUILD_ID,
+ "build_target": self.BUILD_TARGET,
+ "emulator_branch": self.EMULATOR_BRANCH,
+ "emulator_build_id": self.EMULATOR_BUILD_ID,
+ "emulator_build_target": self.EMULATOR_TARGET,
},],
})
self.assertEquals(report.command, "create_gf")
self.assertEquals(report.status, "SUCCESS")
+ # Call CreateDevices with avd_spec
+ self.build_client.GetBranch.side_effect = [
+ self.BRANCH, self.EMULATOR_BRANCH
+ ]
+ report = create_goldfish_action.CreateDevices(avd_spec=self.avd_spec)
+ # Verify
+ self.compute_client.CreateInstance.assert_called_with(
+ instance=self.INSTANCE,
+ blank_data_disk_size_gb=self.EXTRA_DATA_DISK_GB,
+ image_name=self.GOLDFISH_HOST_IMAGE_NAME,
+ image_project=self.GOLDFISH_HOST_IMAGE_PROJECT,
+ build_target=self.BUILD_TARGET,
+ branch=self.BRANCH,
+ build_id=self.BUILD_ID,
+ emulator_branch=self.EMULATOR_BRANCH,
+ emulator_build_id=self.EMULATOR_BUILD_ID,
+ gpu=self.GPU,
+ avd_spec=self.avd_spec,
+ extra_scopes=self.EXTRA_SCOPES)
+
#pylint: disable=invalid-name
def testCreateDevicesWithoutEmulatorBuildId(self):
"""Test CreateDevices when emulator build id is not provided."""
@@ -204,9 +277,11 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
"_FetchBuildIdFromFile",
return_value=self.EMULATOR_BUILD_ID)
+ none_avd_spec = None
# Call CreateDevices
report = create_goldfish_action.CreateDevices(
- cfg, self.BUILD_TARGET, self.BUILD_ID, None, self.GPU)
+ none_avd_spec, cfg, self.BUILD_TARGET, self.BUILD_ID, None,
+ self.GPU)
# Verify
self.compute_client.CreateInstance.assert_called_with(
@@ -219,17 +294,45 @@ class CreateGoldfishActionTest(driver_test_lib.BaseDriverTest):
build_id=self.BUILD_ID,
emulator_branch=self.EMULATOR_BRANCH,
emulator_build_id=self.EMULATOR_BUILD_ID,
- gpu=self.GPU)
+ gpu=self.GPU,
+ avd_spec=none_avd_spec,
+ extra_scopes=self.EXTRA_SCOPES)
self.assertEquals(report.data, {
"devices": [{
"instance_name": self.INSTANCE,
"ip": self.IP.external,
+ "branch": self.BRANCH,
+ "build_id": self.BUILD_ID,
+ "build_target": self.BUILD_TARGET,
+ "emulator_branch": self.EMULATOR_BRANCH,
+ "emulator_build_id": self.EMULATOR_BUILD_ID,
+ "emulator_build_target": self.EMULATOR_TARGET,
},],
})
self.assertEquals(report.command, "create_gf")
self.assertEquals(report.status, "SUCCESS")
+ # Call CreateDevices with avd_spec
+ self.build_client.GetBranch.side_effect = [
+ self.BRANCH, self.EMULATOR_BRANCH
+ ]
+ report = create_goldfish_action.CreateDevices(avd_spec=self.avd_spec)
+ # Verify
+ self.compute_client.CreateInstance.assert_called_with(
+ instance=self.INSTANCE,
+ blank_data_disk_size_gb=self.EXTRA_DATA_DISK_GB,
+ image_name=self.GOLDFISH_HOST_IMAGE_NAME,
+ image_project=self.GOLDFISH_HOST_IMAGE_PROJECT,
+ build_target=self.BUILD_TARGET,
+ branch=self.BRANCH,
+ build_id=self.BUILD_ID,
+ emulator_branch=self.EMULATOR_BRANCH,
+ emulator_build_id=self.EMULATOR_BUILD_ID,
+ gpu=self.GPU,
+ avd_spec=self.avd_spec,
+ extra_scopes=self.EXTRA_SCOPES)
+
if __name__ == "__main__":
unittest.main()