Skip to content

Commit

Permalink
Migrate project from gcloud to Flank
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Mar 13, 2019
1 parent 88def96 commit d50e77e
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 51 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ gcloud:
## Invoke a test asynchronously without waiting for test results.
# async: false

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723

## The history name for your test results (an arbitrary string label; default: the application's label from the APK manifest).
## All tests which use the same history name will have their results grouped together in the Firebase console in a time-ordered test history list.
# results-history-name: android-history
Expand Down Expand Up @@ -151,6 +148,9 @@ flank:
## test targets - a list of tests to run. omit to run all tests.
# test-targets:
# - className/testName

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723
```

### Android example
Expand Down Expand Up @@ -186,9 +186,6 @@ gcloud:
## Invoke a test asynchronously without waiting for test results.
# async: false

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723

## The history name for your test results (an arbitrary string label; default: the application's label from the APK manifest).
## All tests which use the same history name will have their results grouped together in the Firebase console in a time-ordered test history list.
# results-history-name: android-history
Expand Down Expand Up @@ -285,6 +282,9 @@ flank:
## regex is matched against bucket paths, for example: 2019-01-09_00:13:06.106000_YCKl/shard_0/NexusLowRes-28-en-portrait/bugreport.txt
# files-to-download:
# - .*\.mp4$

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723
```

### Android code coverage
Expand Down
2 changes: 1 addition & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- [#507](https://github.com/TestArmada/flank/pull/507) Improve error message when credentials fail to load, folder doesn't exist, and on bucket creation failure. Properly pass through user credential when checking the storage bucket. ([bootstraponline](https://github.com/bootstraponline))
- [#514](https://github.com/TestArmada/flank/pull/514) Rename `testShards` to `maxTestShards` ([miguelslemos](https://github.com/miguelslemos))
- [#518](https://github.com/TestArmada/flank/pull/518) Add deprecation warnings when old key names are used. `flank android doctor --fix` will auto fix the YAML file. ([bootstraponline](https://github.com/bootstraponline))
- [#519](https://github.com/TestArmada/flank/pull/519) Rename `maxTestShards` to `max-test-shards`, `shardTime` to `shard-time`, `repeatTests` to `repeat-tests`, `smartFlankGcsPath` to `smart-flank-gcs-path`, `disableSharding` to `disable-sharding`. ([bootstraponline](https://github.com/bootstraponline))
- [#519](https://github.com/TestArmada/flank/pull/519) Rename `maxTestShards` to `max-test-shards`, `shardTime` to `shard-time`, `repeatTests` to `repeat-tests`, `smartFlankGcsPath` to `smart-flank-gcs-path`, `disableSharding` to `disable-sharding`. Moved `project` from `gcloud` to `flank` ([bootstraponline](https://github.com/bootstraponline))

## v4.4.0

Expand Down
6 changes: 3 additions & 3 deletions test_runner/flank.ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ gcloud:
## Invoke a test asynchronously without waiting for test results.
# async: false

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723

## The history name for your test results (an arbitrary string label; default: the application's label from the APK manifest).
## All tests which use the same history name will have their results grouped together in the Firebase console in a time-ordered test history list.
# results-history-name: android-history
Expand Down Expand Up @@ -102,3 +99,6 @@ flank:
## test targets - a list of tests to run. omit to run all tests.
# test-targets:
# - className/testName

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723
6 changes: 3 additions & 3 deletions test_runner/flank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ gcloud:
## Invoke a test asynchronously without waiting for test results.
# async: false

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723

## The history name for your test results (an arbitrary string label; default: the application's label from the APK manifest).
## All tests which use the same history name will have their results grouped together in the Firebase console in a time-ordered test history list.
# results-history-name: android-history
Expand Down Expand Up @@ -121,3 +118,6 @@ flank:
## regex is matched against bucket paths, for example: 2019-01-09_00:13:06.106000_YCKl/shard_0/NexusLowRes-28-en-portrait/bugreport.txt
# files-to-download:
# - .*\.mp4$

## The billing enabled Google Cloud Platform project name to use
# project: delta-essence-114723
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class AndroidArgs(
override val recordVideo = cli?.recordVideo ?: cli?.noRecordVideo?.not() ?: gcloud.recordVideo
override val testTimeout = cli?.timeout ?: gcloud.timeout
override val async = cli?.async ?: gcloud.async
override val project = cli?.project ?: gcloud.project
override val resultsHistoryName = cli?.resultsHistoryName ?: gcloud.resultsHistoryName
override val flakyTestAttempts = cli?.flakyTestAttempts ?: gcloud.flakyTestAttempts

Expand All @@ -72,6 +71,7 @@ class AndroidArgs(
override val testTargetsAlwaysRun = cli?.testTargetsAlwaysRun ?: flank.testTargetsAlwaysRun
override val filesToDownload = cli?.filesToDownload ?: flank.filesToDownload
override val disableSharding = cli?.disableSharding ?: flank.disableSharding
override val project = cli?.project ?: flank.project

// computed properties not specified in yaml
override val testShardChunks: List<List<String>> by lazy {
Expand Down Expand Up @@ -145,7 +145,6 @@ AndroidArgs
record-video: $recordVideo
timeout: $testTimeout
async: $async
project: $project
results-history-name: $resultsHistoryName
# Android gcloud
app: $appApk
Expand Down Expand Up @@ -173,6 +172,7 @@ ${listToString(filesToDownload)}
test-targets-always-run:
${listToString(testTargetsAlwaysRun)}
disable-sharding: $disableSharding
project: $project
""".trimIndent()
}

Expand Down
8 changes: 5 additions & 3 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import ftl.config.FtlConstants
import ftl.config.FtlConstants.GCS_PREFIX
import ftl.config.FtlConstants.JSON_FACTORY
import ftl.config.FtlConstants.defaultCredentialPath
import ftl.config.FtlConstants.useMock
import ftl.gc.GcStorage
import ftl.gc.GcToolResults
import ftl.reports.xml.model.JUnitTestResult
import ftl.shard.Shard
import ftl.shard.StringShards
Expand Down Expand Up @@ -105,9 +107,9 @@ object ArgsHelper {
}

fun createGcsBucket(projectId: String, bucket: String): String {
// com.google.cloud.storage.contrib.nio.testing.FakeStorageRpc doesn't support list
// when testing, use a hard coded results bucket instead.
if (FtlConstants.useMock) return bucket
if (bucket.isEmpty()) return GcToolResults.getDefaultBucket(projectId) ?: throw RuntimeException("Failed to make bucket for $projectId")
if (useMock) return bucket

// test lab supports using a special free storage bucket
// because we don't have access to the root account, it won't show up in the storage list.
if (bucket.startsWith("test-lab-")) return bucket
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class IosArgs(
override val recordVideo = cli?.recordVideo ?: cli?.noRecordVideo?.not() ?: gcloud.recordVideo
override val testTimeout = cli?.timeout ?: gcloud.timeout
override val async = cli?.async ?: gcloud.async
override val project = cli?.project ?: gcloud.project
override val resultsHistoryName = cli?.resultsHistoryName ?: gcloud.resultsHistoryName
override val flakyTestAttempts = cli?.flakyTestAttempts ?: gcloud.flakyTestAttempts

Expand All @@ -56,6 +55,7 @@ class IosArgs(
override val testTargetsAlwaysRun = cli?.testTargetsAlwaysRun ?: flank.testTargetsAlwaysRun
override val filesToDownload = cli?.filesToDownload ?: flank.filesToDownload
override val disableSharding = cli?.disableSharding ?: flank.disableSharding
override val project = cli?.project ?: flank.project

private val iosFlank = iosFlankYml.flank
val testTargets = cli?.testTargets ?: iosFlank.testTargets
Expand Down Expand Up @@ -109,7 +109,6 @@ IosArgs
record-video: $recordVideo
timeout: $testTimeout
async: $async
project: $project
results-history-name: $resultsHistoryName
# iOS gcloud
test: $xctestrunZip
Expand All @@ -132,6 +131,7 @@ ${listToString(filesToDownload)}
test-targets:
${listToString(testTargets)}
disable-sharding: $disableSharding
project: $project
""".trimIndent()
}

Expand Down
15 changes: 13 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package ftl.args.yml

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import ftl.args.ArgsHelper
import ftl.config.FtlConstants
import ftl.config.FtlConstants.GCS_PREFIX
import ftl.util.Utils
import ftl.util.Utils.fatalError

/** Flank specific parameters for both iOS and Android */
Expand All @@ -27,16 +30,24 @@ class FlankYmlParams(
val testTargetsAlwaysRun: List<String> = emptyList(),

@field:JsonProperty("files-to-download")
val filesToDownload: List<String> = emptyList()
val filesToDownload: List<String> = emptyList(),

val project: String = ArgsHelper.getDefaultProjectId() ?: ""
) {
companion object : IYmlKeys {
override val keys = listOf(
"max-test-shards", "shard-time", "repeat-tests", "smart-flank-gcs-path", "disable-sharding",
"test-targets-always-run", "files-to-download"
"test-targets-always-run", "files-to-download", "project"
)
}

init {
Utils.assertNotEmpty(
project, "The project is not set. Define GOOGLE_CLOUD_PROJECT, set project in flank.yml\n" +
"or save service account credential to ${FtlConstants.defaultCredentialPath}\n" +
" See https://github.com/GoogleCloudPlatform/google-cloud-java#specifying-a-project-id"
)

if (maxTestShards <= 0 && maxTestShards != -1) fatalError("max-test-shards must be >= 1 or -1")
if (shardTime <= 0 && shardTime != -1) fatalError("shard-time must be >= 1 or -1")
if (repeatTests < 1) fatalError("repeat-tests must be >= 1")
Expand Down
19 changes: 1 addition & 18 deletions test_runner/src/main/kotlin/ftl/args/yml/GcloudYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package ftl.args.yml

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import ftl.args.ArgsHelper.getDefaultProjectId
import ftl.config.FtlConstants.defaultCredentialPath
import ftl.gc.GcToolResults
import ftl.util.Utils.assertNotEmpty

/**
* Common Gcloud parameters shared between iOS and Android
Expand All @@ -28,8 +24,6 @@ class GcloudYmlParams(

val async: Boolean = false,

val project: String = getDefaultProjectId() ?: "",

@field:JsonProperty("results-history-name")
val resultsHistoryName: String? = null,

Expand All @@ -38,20 +32,9 @@ class GcloudYmlParams(
) {
companion object : IYmlKeys {
override val keys =
listOf("results-bucket", "results-dir", "record-video", "timeout", "async", "project",
listOf("results-bucket", "results-dir", "record-video", "timeout", "async",
"results-history-name", "flaky-test-attempts")
}

init {
assertNotEmpty(
project, "The project is not set. Define GOOGLE_CLOUD_PROJECT, set project in flank.yml\n" +
"or save service account credential to $defaultCredentialPath\n" +
" See https://github.com/GoogleCloudPlatform/google-cloud-java#specifying-a-project-id"
)

if (resultsBucket.isEmpty()) resultsBucket = GcToolResults.getDefaultBucket(project) ?: ""
assertNotEmpty(resultsBucket, "results-bucket is not set")
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
11 changes: 10 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.args.yml

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import com.fasterxml.jackson.databind.node.ObjectNode
import ftl.args.ArgsHelper.yamlMapper
import ftl.util.Utils
Expand Down Expand Up @@ -52,6 +53,11 @@ object YamlDeprecated {
Key(Parent.flank, "disableSharding"),
Key(Parent.flank, "disable-sharding"),
Level.Warning
),
ModifiedKey(
Key(Parent.gcloud, "project"),
Key(Parent.flank, "project"),
Level.Warning
)
)

Expand All @@ -65,7 +71,10 @@ object YamlDeprecated {
}

private fun JsonNode.replace(parent: Parent, child: String, value: JsonNode) {
(this[parent.toString()] as ObjectNode).replace(child, value)
val parentKey = parent.toString()
// if the parent node ('flank:') doesn't exist then add it ('flank: {}') to the YAML
if (this[parentKey] == null) (this as ObjectNode).set(parentKey, JsonNodeFactory.instance.objectNode())
(this[parentKey] as ObjectNode).replace(child, value)
}

private fun mutate(parsed: JsonNode, changes: List<Transform>) {
Expand Down
9 changes: 6 additions & 3 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ class AndroidArgsFileTest {
val config = AndroidArgs(
GcloudYml(
GcloudYmlParams(
resultsBucket = oldConfig.resultsBucket,
project = "delta-essence-114723"
resultsBucket = oldConfig.resultsBucket
)
),
AndroidGcloudYml(
Expand All @@ -172,7 +171,11 @@ class AndroidArgsFileTest {
test = oldConfig.testApk
)
),
FlankYml(),
FlankYml(
FlankYmlParams(
project = "delta-essence-114723"
)
),
""
)

Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ AndroidArgs
record-video: false
timeout: 70m
async: true
project: projectFoo
results-history-name: android-history
# Android gcloud
app: $appApkAbsolutePath
Expand Down Expand Up @@ -226,6 +225,7 @@ AndroidArgs
- class example.Test#grantPermission
- class example.Test#grantPermission2
disable-sharding: true
project: projectFoo
""".trimIndent()
)
}
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/test/kotlin/ftl/args/ArgsHelperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ArgsHelperTest {
fun mergeYmlMaps_succeeds() {
val merged = mergeYmlMaps(GcloudYml, IosGcloudYml)
assertThat(merged.keys.size).isEqualTo(1)
assertThat(merged["gcloud"]?.size).isEqualTo(12)
assertThat(merged["gcloud"]?.size).isEqualTo(11)
}

@Test
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/test/kotlin/ftl/args/GcloudYmlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GcloudYmlTest {
@Test
fun gcloudYml() {
val gcloud = GcloudYml().gcloud
gcloud.resultsBucket = "mockBucket"
assertThat(gcloud.resultsBucket)
.isEqualTo("mockBucket")

Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ IosArgs
record-video: false
timeout: 70m
async: true
project: projectFoo
results-history-name: ios-history
# iOS gcloud
test: $testAbsolutePath
Expand Down Expand Up @@ -178,6 +177,7 @@ IosArgs
- b/testBasicSelection
- b/testBasicSelection2
disable-sharding: true
project: projectFoo
""".trimIndent()
)
}
Expand Down
Loading

0 comments on commit d50e77e

Please sign in to comment.