Inject parent builder to build+test test drone

Post submit tasks are using Target name to update task status in datastore. The parent builder is the one stored in datastore and we should inject that property to the test drone builder.

Change-Id: Icf2e4998ee18d2cc69798255f10fb9533d2c6404
Bug: https://github.com/flutter/flutter/issues/103542
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/33440
Commit-Queue: Keyong Han <keyonghan@google.com>
Reviewed-by: Yusuf Mohsinally <mohsinally@google.com>
diff --git a/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json b/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json
index 25352e4..824b89a 100644
--- a/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json
+++ b/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json
@@ -809,7 +809,7 @@
       }
     },
     "name": "buildbucket.schedule",
-    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/main\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
+    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/main\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"parent_builder\": \"Linux abc\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"responses\": [@@@",
@@ -854,6 +854,7 @@
       "@@@STEP_LOG_LINE@request@          \"artifact\": \"def\", @@@",
       "@@@STEP_LOG_LINE@request@          \"dependencies\": [], @@@",
       "@@@STEP_LOG_LINE@request@          \"git_branch\": \"master\", @@@",
+      "@@@STEP_LOG_LINE@request@          \"parent_builder\": \"Linux abc\", @@@",
       "@@@STEP_LOG_LINE@request@          \"task_name\": \"abc\"@@@",
       "@@@STEP_LOG_LINE@request@        }, @@@",
       "@@@STEP_LOG_LINE@request@        \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", @@@",
diff --git a/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json b/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json
index f86c982..ff5728d 100644
--- a/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json
+++ b/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json
@@ -34,7 +34,7 @@
     ],
     "infra_step": true,
     "name": "buildbucket.schedule",
-    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"builder\": \"Linux Devicelab Test Drone\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"git_ref\": \"refs/pull/1/head\", \"git_url\": \"test/repo\", \"task_name\": \"abc\"}, \"requestId\": \"0-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"0\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
+    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"builder\": \"Linux Devicelab Test Drone\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"git_ref\": \"refs/pull/1/head\", \"git_url\": \"test/repo\", \"parent_builder\": \"Linux abc\", \"task_name\": \"abc\"}, \"requestId\": \"0-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"0\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"responses\": [@@@",
@@ -71,6 +71,7 @@
       "@@@STEP_LOG_LINE@request@          \"git_branch\": \"master\", @@@",
       "@@@STEP_LOG_LINE@request@          \"git_ref\": \"refs/pull/1/head\", @@@",
       "@@@STEP_LOG_LINE@request@          \"git_url\": \"test/repo\", @@@",
+      "@@@STEP_LOG_LINE@request@          \"parent_builder\": \"Linux abc\", @@@",
       "@@@STEP_LOG_LINE@request@          \"task_name\": \"abc\"@@@",
       "@@@STEP_LOG_LINE@request@        }, @@@",
       "@@@STEP_LOG_LINE@request@        \"requestId\": \"0-00000000-0000-0000-0000-000000001337\", @@@",
diff --git a/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json b/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json
index 3245aed..de9336d 100644
--- a/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json
+++ b/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json
@@ -980,7 +980,7 @@
       }
     },
     "name": "buildbucket.schedule",
-    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/master\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
+    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/master\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"parent_builder\": \"Linux abc\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"responses\": [@@@",
@@ -1025,6 +1025,7 @@
       "@@@STEP_LOG_LINE@request@          \"artifact\": \"def\", @@@",
       "@@@STEP_LOG_LINE@request@          \"dependencies\": [], @@@",
       "@@@STEP_LOG_LINE@request@          \"git_branch\": \"master\", @@@",
+      "@@@STEP_LOG_LINE@request@          \"parent_builder\": \"Linux abc\", @@@",
       "@@@STEP_LOG_LINE@request@          \"task_name\": \"abc\"@@@",
       "@@@STEP_LOG_LINE@request@        }, @@@",
       "@@@STEP_LOG_LINE@request@        \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", @@@",
diff --git a/recipes/devicelab/devicelab_drone_build_test.py b/recipes/devicelab/devicelab_drone_build_test.py
index f626c2f..5129058 100644
--- a/recipes/devicelab/devicelab_drone_build_test.py
+++ b/recipes/devicelab/devicelab_drone_build_test.py
@@ -98,6 +98,7 @@
   test_props = {
       'dependencies': [api.shard_util_v2.unfreeze_dict(dep) for dep in deps],
       'task_name': task_name,
+      'parent_builder': api.properties.get('buildername'),
       'artifact': artifact,
       'git_branch': api.properties.get('git_branch'),
   }
diff --git a/recipes/devicelab/devicelab_test_drone.expected/artifact-exists.json b/recipes/devicelab/devicelab_test_drone.expected/artifact-exists.json
index 14d5e20..5ba7332 100644
--- a/recipes/devicelab/devicelab_test_drone.expected/artifact-exists.json
+++ b/recipes/devicelab/devicelab_test_drone.expected/artifact-exists.json
@@ -302,7 +302,7 @@
       "--results-file",
       "[CLEANUP]/results_tmp_1/results",
       "--luci-builder",
-      "Linux abc",
+      "ghi",
       "--task-args",
       "test",
       "--task-args",
@@ -838,7 +838,7 @@
       "--git-branch",
       "master",
       "--luci-builder",
-      "Linux abc",
+      "ghi",
       "--test-status",
       "Succeeded",
       "--service-account-token-file",
diff --git a/recipes/devicelab/devicelab_test_drone.expected/basic.json b/recipes/devicelab/devicelab_test_drone.expected/basic.json
index 0b3e48e..4c614f5 100644
--- a/recipes/devicelab/devicelab_test_drone.expected/basic.json
+++ b/recipes/devicelab/devicelab_test_drone.expected/basic.json
@@ -493,7 +493,7 @@
       "--results-file",
       "[CLEANUP]/results_tmp_1/results",
       "--luci-builder",
-      "Linux abc",
+      "ghi",
       "--task-args",
       "test",
       "--task-args",
diff --git a/recipes/devicelab/devicelab_test_drone.expected/experimental.json b/recipes/devicelab/devicelab_test_drone.expected/experimental.json
index ced4451..1aa15f0 100644
--- a/recipes/devicelab/devicelab_test_drone.expected/experimental.json
+++ b/recipes/devicelab/devicelab_test_drone.expected/experimental.json
@@ -493,7 +493,7 @@
       "--results-file",
       "[CLEANUP]/results_tmp_1/results",
       "--luci-builder",
-      "Linux abc",
+      "ghi",
       "--task-args",
       "test",
       "--task-args",
diff --git a/recipes/devicelab/devicelab_test_drone.expected/local-engine.json b/recipes/devicelab/devicelab_test_drone.expected/local-engine.json
index f252c25..b5b3e05 100644
--- a/recipes/devicelab/devicelab_test_drone.expected/local-engine.json
+++ b/recipes/devicelab/devicelab_test_drone.expected/local-engine.json
@@ -639,7 +639,7 @@
       "--results-file",
       "[CLEANUP]/results_tmp_1/results",
       "--luci-builder",
-      "Linux abc",
+      "ghi",
       "--task-args",
       "test",
       "--task-args",
@@ -1383,7 +1383,7 @@
       "--git-branch",
       "master",
       "--luci-builder",
-      "Linux abc",
+      "ghi",
       "--test-status",
       "Succeeded",
       "--service-account-token-file",
diff --git a/recipes/devicelab/devicelab_test_drone.expected/no-upload-metrics-linux-staging.json b/recipes/devicelab/devicelab_test_drone.expected/no-upload-metrics-linux-staging.json
index fa8b135..93738b0 100644
--- a/recipes/devicelab/devicelab_test_drone.expected/no-upload-metrics-linux-staging.json
+++ b/recipes/devicelab/devicelab_test_drone.expected/no-upload-metrics-linux-staging.json
@@ -493,7 +493,7 @@
       "--results-file",
       "[CLEANUP]/results_tmp_1/results",
       "--luci-builder",
-      "Linux abc",
+      "ghi",
       "--task-args",
       "test",
       "--task-args",
diff --git a/recipes/devicelab/devicelab_test_drone.py b/recipes/devicelab/devicelab_test_drone.py
index 93607f1..0ade68a 100644
--- a/recipes/devicelab/devicelab_test_drone.py
+++ b/recipes/devicelab/devicelab_test_drone.py
@@ -86,9 +86,10 @@
   # Create tmp file to store results in
   results_path = api.path.mkdtemp(prefix='results').join('results')
   # Run test
+  parent_builder = api.properties.get('parent_builder')
   runner_params = [
       '-t', task_name, '--results-file', results_path, '--luci-builder',
-      api.properties.get('buildername')
+      parent_builder
   ]
   # Downloads artifact
   artifact_destination_dir = api.path.mkdtemp()
@@ -129,7 +130,7 @@
   with api.context(env=env, env_prefixes=env_prefixes, cwd=devicelab_path):
     uploadResults(
         api, env, env_prefixes, results_path, test_status == 'flaky',
-        git_branch, api.properties.get('buildername'), commit_time, task_name,
+        git_branch, parent_builder, commit_time, task_name,
         benchmark_tags
     )
     uploadMetricsToCas(api, results_path)
@@ -279,7 +280,8 @@
           task_name='abc',
           git_branch='master',
           artifact='def',
-          git_ref='refs/pull/1/head'
+          git_ref='refs/pull/1/head',
+          parent_builder='ghi',
       ),
       api.repo_util.flutter_environment_data(checkout_dir=checkout_path),
   )
@@ -291,7 +293,8 @@
           git_branch='master',
           artifact='def',
           upload_metrics=True,
-          upload_metrics_to_cas=True
+          upload_metrics_to_cas=True,
+          parent_builder='ghi',
       ),
       api.repo_util.flutter_environment_data(checkout_dir=checkout_path),
       api.step_data(
@@ -310,7 +313,8 @@
           buildername='Linux abc',
           task_name='abc',
           git_branch='master',
-          artifact='def'
+          artifact='def',
+          parent_builder='ghi',
       ),
       api.repo_util.flutter_environment_data(checkout_dir=checkout_path),
       api.step_data(
@@ -332,6 +336,7 @@
           artifact='def',
           upload_metrics_to_cas=True,
           git_branch='master',
+          parent_builder='ghi',
       ), api.repo_util.flutter_environment_data(checkout_dir=checkout_path),
       api.buildbucket.ci_build(
           git_ref='refs/heads/master',
@@ -347,6 +352,7 @@
           local_engine='host-release',
           git_branch='master',
           artifact='def',
+          parent_builder='ghi',
       ), api.repo_util.flutter_environment_data(checkout_dir=checkout_path),
       api.buildbucket.ci_build(
           project='test',