swarming: always mock bot and task IDs in test mode.
Recipes are now always executed on top of swarming, but not every test
fakes swarming environment nor should it.
This will indicate realistic impact of CLs relying on swarming task id
being present like
https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/1846932
R=vadimsh
Change-Id: I6cd7f1052617899f4926a7066601d46b1a15a962
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/1846717
Commit-Queue: Andrii Shyshkalov <tandrii@google.com>
Auto-Submit: Andrii Shyshkalov <tandrii@google.com>
Reviewed-by: Vadim Shtayura <vadimsh@chromium.org>
diff --git a/README.recipes.md b/README.recipes.md
index fd14fb5..a845c17 100644
--- a/README.recipes.md
+++ b/README.recipes.md
@@ -2509,7 +2509,7 @@
Swarming bot ID executing this task.
-— **def [collect](/recipe_modules/swarming/api.py#1051)(self, name, tasks, output_dir=None, timeout=None):**
+— **def [collect](/recipe_modules/swarming/api.py#1059)(self, name, tasks, output_dir=None, timeout=None):**
Waits on a set of Swarming tasks.
@@ -2529,7 +2529,7 @@
— **def [initialize](/recipe_modules/swarming/api.py#928)(self):**
-  **@contextlib.contextmanager**<br>— **def [on\_path](/recipe_modules/swarming/api.py#959)(self):**
+  **@contextlib.contextmanager**<br>— **def [on\_path](/recipe_modules/swarming/api.py#967)(self):**
This context manager ensures the go swarming client is available on
$PATH.
@@ -2543,7 +2543,7 @@
This task's Swarming ID.
-— **def [task\_request](/recipe_modules/swarming/api.py#991)(self):**
+— **def [task\_request](/recipe_modules/swarming/api.py#999)(self):**
Creates a new TaskRequest object.
@@ -2553,7 +2553,7 @@
Once your TaskRequest is complete, you can pass it to `trigger` in order to
have it start running on the swarming server.
-— **def [trigger](/recipe_modules/swarming/api.py#1002)(self, step_name, requests, cancel_extra_tasks=False):**
+— **def [trigger](/recipe_modules/swarming/api.py#1010)(self, step_name, requests, cancel_extra_tasks=False):**
Triggers a set of Swarming tasks.
@@ -2568,7 +2568,7 @@
Returns:
A list of TaskRequestMetadata objects.
-  **@contextlib.contextmanager**<br>— **def [with\_server](/recipe_modules/swarming/api.py#973)(self, server):**
+  **@contextlib.contextmanager**<br>— **def [with\_server](/recipe_modules/swarming/api.py#981)(self, server):**
This context sets the server for Swarming calls.
diff --git a/recipe_modules/swarming/api.py b/recipe_modules/swarming/api.py
index 06264ed..3be505c 100644
--- a/recipe_modules/swarming/api.py
+++ b/recipe_modules/swarming/api.py
@@ -928,6 +928,14 @@
def initialize(self):
if self._test_data.enabled:
self._server = 'https://example.swarmingserver.appspot.com'
+ # Recipes always run on top of swarming task now.
+ self._env_properties.SWARMING_TASK_ID = (
+ self._env_properties.SWARMING_TASK_ID or
+ 'fake-task-id')
+ self._env_properties.SWARMING_BOT_ID = (
+ self._env_properties.SWARMING_BOT_ID or
+ 'fake-bot-id')
+
if self.m.runtime.is_experimental:
self._version = 'latest'
self._client_dir = self.m.path['cache'].join('swarming_client')