Handle output placeholder missing backing file

In preparation for this CL:
https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/1777143

Currently, if no test step data is provided for a step that uses an
output placeholder, the placeholder evaluates to an empty string. After
that CL lands, the placeholder will instead evaluate to None, breaking
any non-mocked code that assumes a non-null placeholder result.

There were dozens of places where these env var fetches would've needed
mocking, so I figured it was easier to just silently handle the case
where the placeholder backing file doesn't exist. Especially for trivial
cases like these environment variable fetches where the backing file is
a temporary file created just for that step (no `leak_to` argument
specified), it should be impossible for the backing file to not exist
unless you're doing some really weird stuff.

Change-Id: Ibb646142ee8471b2444f54fe78c640a94d18a607
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/240663
Commit-Queue: Eric Boren <borenet@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
diff --git a/infra/bots/recipe_modules/vars/api.py b/infra/bots/recipe_modules/vars/api.py
index b736a20..cc001a6 100644
--- a/infra/bots/recipe_modules/vars/api.py
+++ b/infra/bots/recipe_modules/vars/api.py
@@ -84,21 +84,23 @@
   @property
   def swarming_bot_id(self):
     if not self._swarming_bot_id:
-      self._swarming_bot_id = self.m.python.inline(
+      step_stdout = self.m.python.inline(
           name='get swarming bot id',
           program='''import os
 print os.environ.get('SWARMING_BOT_ID', '')
 ''',
-          stdout=self.m.raw_io.output()).stdout.rstrip()
+          stdout=self.m.raw_io.output()).stdout
+      self._swarming_bot_id = step_stdout.rstrip() if step_stdout else ''
     return self._swarming_bot_id
 
   @property
   def swarming_task_id(self):
     if not self._swarming_task_id:
-      self._swarming_task_id = self.m.python.inline(
+      step_stdout = self.m.python.inline(
           name='get swarming task id',
           program='''import os
 print os.environ.get('SWARMING_TASK_ID', '')
 ''',
-          stdout=self.m.raw_io.output()).stdout.rstrip()
+          stdout=self.m.raw_io.output()).stdout
+      self._swarming_task_id = step_stdout.rstrip() if step_stdout else ''
     return self._swarming_task_id