api: router: switch to contextlib.ExitStack

The python 3 stdlib provides a complete replacement for this util func.

BUG=b:224592438
TEST=CQ passes

Change-Id: I05221903df1a53552d19a009c79eaeabacf3eec1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4307017
Tested-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Sergey Frolov <sfrolov@google.com>
Reviewed-by: Sergey Frolov <sfrolov@google.com>
diff --git a/api/router.py b/api/router.py
index a47544a..68a71e8 100644
--- a/api/router.py
+++ b/api/router.py
@@ -9,6 +9,7 @@
 """
 
 import collections
+import contextlib
 import importlib
 import logging
 import os
@@ -360,25 +361,27 @@
         if not chroot.exists():
             raise InvalidSdkError("Chroot does not exist.")
 
-        # Use a ContextManagerStack to avoid the deep nesting this many
-        # context managers introduces.
-        with cros_build_lib.ContextManagerStack() as stack:
+        # Use a ExitStack to avoid the deep nesting this many context managers
+        # introduces.
+        with contextlib.ExitStack() as stack:
             # TempDirs setup.
-            tempdir = stack.Add(chroot.tempdir).tempdir
-            sync_tempdir = stack.Add(chroot.tempdir).tempdir
+            tempdir = stack.enter_context(chroot.tempdir())
+            sync_tempdir = stack.enter_context(chroot.tempdir())
             # The copy-paths-in context manager to handle Path messages.
-            stack.Add(
-                field_handler.copy_paths_in,
-                input_msg,
-                chroot.tmp,
-                prefix=chroot.path,
+            stack.enter_context(
+                field_handler.copy_paths_in(
+                    input_msg,
+                    chroot.tmp,
+                    prefix=chroot.path,
+                )
             )
             # The sync-directories context manager to handle SyncedDir messages.
-            stack.Add(
-                field_handler.sync_dirs,
-                input_msg,
-                sync_tempdir,
-                prefix=chroot.path,
+            stack.enter_context(
+                field_handler.sync_dirs(
+                    input_msg,
+                    sync_tempdir,
+                    prefix=chroot.path,
+                )
             )
 
             # Parse goma.