lib: revert cidb deprecation attempt

CIDB is too deeply integrated to turn of trivially. This is true
even though it appears possible based on the configuration options
presented. In trying to do so we ran into ever expanding issues.

BUG=b:247170885

Revert "lib: fix buildstore client initialization"

This reverts commit 0c3cb09623972b86c528cd6b1002759325b5b7a6.

Revert "cbuildbot: fix format"

This reverts commit e52e6829e497eafa64deb8a66df3821057134b0e.

Revert "cbuildbot: deprecate cidb"

This reverts commit 78320f7b32e8a91538cc7e207d1dc83e91e12d15.

Change-Id: Ibe010a06fb94596a596fc4309d16bb44b920d10e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3906604
Reviewed-by: Madeleine Hardt <hardtmad@google.com>
Tested-by: George Engelbrecht <engeg@google.com>
Commit-Queue: George Engelbrecht <engeg@google.com>
Reviewed-by: Benjamin Shai <bshai@google.com>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index a3efafd..573953c 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -1049,16 +1049,32 @@
 
 
 def _SetupConnections(options, build_config):
-    """Set up mock CIDB connections using the appropriate Setup call.
-
-    CIDB is deprecated and we will only use the mock client.
+    """Set up CIDB connections using the appropriate Setup call.
 
     Args:
       options: Command line options structure.
       build_config: Config object for this build.
     """
-    cidb.CIDBConnectionFactory.SetupNoCidb()
-    context = ts_mon_config.TrivialContextManager()
+    # Outline:
+    # 1) Based on options and build_config, decide whether we are a production
+    # run, debug run, or standalone run.
+    # 2) Set up cidb instance accordingly.
+    # 3) Update topology info from cidb, so that any other service set up can use
+    # topology.
+    # 4) Set up any other services.
+    run_type = _GetRunEnvironment(options, build_config)
+
+    if run_type == _ENVIRONMENT_PROD:
+        cidb.CIDBConnectionFactory.SetupProdCidb()
+        context = ts_mon_config.SetupTsMonGlobalState(
+            "cbuildbot", indirect=True
+        )
+    elif run_type == _ENVIRONMENT_DEBUG:
+        cidb.CIDBConnectionFactory.SetupDebugCidb()
+        context = ts_mon_config.TrivialContextManager()
+    else:
+        cidb.CIDBConnectionFactory.SetupNoCidb()
+        context = ts_mon_config.TrivialContextManager()
 
     topology.FetchTopology()
     return context