api: router: Precreate chroot's /tmp directory

We naturally create some chroot paths within Create API endpoints, or
related flows (e.g., when bind-mounting paths). But that natural
creation point doesn't fit for some build API, where we want to stash
files (e.g., proto messages) before we've made any calls into the SDK.

Previous efforts at mitigating related issues were in
scripts/cros_sdk.py:
https://chromium.googlesource.com/chromiumos/chromite/+/c2a448336069a4c42ff29fa3cd76e4b23ec84cdd%5E%21#F5

But that still doesn't cover cases where:

1. recipe calls SdkService/Create on an older manifest (where chroot's /tmp
   is at .../chroot/tmp)
2. sync to a new manifest (where /tmp is at .../out/tmp)
3. recipe calls an SDK endpoint, such as SdkService/Update

Because /tmp was only created at chroot/tmp and not out/tmp, we fail in
tempdir methods ("No such file or directory:
'/b/s/w/ir/cache/cros_chroot/out/tmp/tmp8vvl050y") when we try to create
temporary paths here in _reexecute_inside().

This was only noticed on (experimental) incremental builders, which are
using older (since-reverted; soon-to-reland) chromite, including:
https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4507725

Let's just accept the redundancy, and create this particular path
on-demand as needed.

BUG=b:265885353
TEST=./run_tests

Change-Id: I3a78e788d2e058feeab0b3262407984babe612ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4572769
Tested-by: Brian Norris <briannorris@chromium.org>
Commit-Queue: Brian Norris <briannorris@chromium.org>
Reviewed-by: Sergey Frolov <sfrolov@google.com>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
diff --git a/api/router.py b/api/router.py
index b0feaaa..587746c 100644
--- a/api/router.py
+++ b/api/router.py
@@ -472,6 +472,12 @@
         if not chroot.exists():
             raise InvalidSdkError("Chroot does not exist.")
 
+        # This may be redundant with other SDK setup flows, but we need this
+        # tmp directory to exist (including across chromite updates, where the
+        # path may move) before we can write our proto messages (e.g., for
+        # SdkService/Update) to it below.
+        osutils.SafeMakedirsNonRoot(chroot.tmp, mode=0o777)
+
         # Use a ExitStack to avoid the deep nesting this many context managers
         # introduces.
         with contextlib.ExitStack() as stack: