]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- rework oracle de-provisioning to write URLs to the file as well,
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 Aug 2017 22:21:34 +0000 (18:21 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 Aug 2017 22:21:34 +0000 (18:21 -0400)
supporting custom dburi etc.

Change-Id: Ic0ab0b3b4223e40fd335ee3313fda4dfce942100

lib/sqlalchemy/testing/plugin/plugin_base.py
lib/sqlalchemy/testing/plugin/pytestplugin.py
lib/sqlalchemy/testing/provision.py
reap_oracle_dbs.py

index 506a1c922150e9008a4cd2202c69974669521071..cab93a0e7a771503678bbe3d181557b91d1acfc6 100644 (file)
@@ -277,6 +277,11 @@ def _engine_uri(options, file_config):
 
     config._current = None
     for db_url in db_urls:
+
+        if options.write_idents and provision.FOLLOWER_IDENT: # != 'master':
+            with open(options.write_idents, "a") as file_:
+                file_.write(provision.FOLLOWER_IDENT + " " + db_url + "\n")
+
         cfg = provision.setup_config(
             db_url, options, file_config, provision.FOLLOWER_IDENT)
 
index d7da73828a5b3e19a99d9fb6a51e6b7e71315f5f..377b4643c8e2585eb0608db966eae2031472d605 100644 (file)
@@ -42,10 +42,6 @@ def pytest_configure(config):
         plugin_base.configure_follower(
             config.slaveinput["follower_ident"]
         )
-
-        if config.option.write_idents:
-            with open(config.option.write_idents, "a") as file_:
-                file_.write(config.slaveinput["follower_ident"] + "\n")
     else:
         if config.option.write_idents and \
                 os.path.exists(config.option.write_idents):
index 97b981f2ac3d14bead805748bcb4beb3c4e980a7..14aa762e2cedb9cf402bd5ae70a3b4608bbc9985 100644 (file)
@@ -1,8 +1,10 @@
 from sqlalchemy.engine import url as sa_url
+from sqlalchemy import create_engine
 from sqlalchemy import text
 from sqlalchemy import exc
 from sqlalchemy.util import compat
 from . import config, engines
+import collections
 import os
 import time
 import logging
@@ -279,36 +281,47 @@ def _oracle_update_db_opts(db_url, db_opts):
     db_opts['_retry_on_12516'] = True
 
 
-def reap_oracle_dbs(eng, idents_file):
+def reap_oracle_dbs(idents_file):
     log.info("Reaping Oracle dbs...")
-    with eng.connect() as conn:
-        with open(idents_file) as file_:
-            idents = set(line.strip() for line in file_)
-
-        log.info("identifiers in file: %s", ", ".join(idents))
-
-        to_reap = conn.execute(
-            "select u.username from all_users u where username "
-            "like 'TEST_%' and not exists (select username "
-            "from v$session where username=u.username)")
-        all_names = {username.lower() for (username, ) in to_reap}
-        to_drop = set()
-        for name in all_names:
-            if name.endswith("_ts1") or name.endswith("_ts2"):
-                continue
-            elif name in idents:
-                to_drop.add(name)
-                if "%s_ts1" % name in all_names:
-                    to_drop.add("%s_ts1" % name)
-                if "%s_ts2" % name in all_names:
-                    to_drop.add("%s_ts2" % name)
-
-        dropped = total = 0
-        for total, username in enumerate(to_drop, 1):
-            if _ora_drop_ignore(conn, username):
-                dropped += 1
-        log.info(
-            "Dropped %d out of %d stale databases detected", dropped, total)
+
+    urls = collections.defaultdict(list)
+    with open(idents_file) as file_:
+        for line in file_:
+            line = line.strip()
+            db_name, db_url = line.split(" ")
+            urls[db_url].append(db_name)
+
+    for url in urls:
+        idents = urls[url]
+        log.info("db reaper connecting to %r", url)
+        eng = create_engine(url)
+        with eng.connect() as conn:
+
+            log.info("identifiers in file: %s", ", ".join(idents))
+
+            to_reap = conn.execute(
+                "select u.username from all_users u where username "
+                "like 'TEST_%' and not exists (select username "
+                "from v$session where username=u.username)")
+            all_names = {username.lower() for (username, ) in to_reap}
+            to_drop = set()
+            for name in all_names:
+                if name.endswith("_ts1") or name.endswith("_ts2"):
+                    continue
+                elif name in idents:
+                    to_drop.add(name)
+                    if "%s_ts1" % name in all_names:
+                        to_drop.add("%s_ts1" % name)
+                    if "%s_ts2" % name in all_names:
+                        to_drop.add("%s_ts2" % name)
+
+            dropped = total = 0
+            for total, username in enumerate(to_drop, 1):
+                if _ora_drop_ignore(conn, username):
+                    dropped += 1
+            log.info(
+                "Dropped %d out of %d stale databases detected",
+                dropped, total)
 
 
 @_follower_url_from_main.for_db("oracle")
index 4762faac55afd41f118659ea4b0f9a90ce8dab16..29d227464360f785b395a44e8f0dedeb0daba74b 100644 (file)
@@ -6,8 +6,6 @@ TCP connection even if close() is called, which prevents the provisioning
 system from dropping a database in-process.
 
 """
-from sqlalchemy.testing.plugin import plugin_base
-from sqlalchemy.testing import engines
 from sqlalchemy.testing import provision
 import logging
 import sys
@@ -15,11 +13,6 @@ import sys
 logging.basicConfig()
 logging.getLogger(provision.__name__).setLevel(logging.INFO)
 
-plugin_base.read_config()
-oracle = plugin_base.file_config.get('db', 'oracle')
-from sqlalchemy.testing import provision
-
-engine = engines.testing_engine(oracle, {})
-provision.reap_oracle_dbs(engine, sys.argv[1])
+provision.reap_oracle_dbs(sys.argv[1])