Rush has submitted this change and it was merged.

Change subject: labsdb: maintain-views allow specification of a single table
......................................................................


labsdb: maintain-views allow specification of a single table

There are a few test case scenarios where this is consistently
needed but also to minimize side effects to production where
the state may be currently unpredicable for a measured
transition to fully managed views.

Change-Id: I57f86dca5b730fd809379d5f2d34302f96e554ab
---
M modules/role/files/labsdb/maintain-views.py
1 file changed, 32 insertions(+), 11 deletions(-)

Approvals:
  Rush: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/role/files/labsdb/maintain-views.py 
b/modules/role/files/labsdb/maintain-views.py
index 467620c..5fdf3a1 100644
--- a/modules/role/files/labsdb/maintain-views.py
+++ b/modules/role/files/labsdb/maintain-views.py
@@ -301,6 +301,11 @@
         default="/etc/maintain-views.yaml"
     )
     argparser.add_argument(
+        "--table",
+        help="Specify a single table to act on (currently only fullviews are 
supported)",
+        default=''
+    )
+    argparser.add_argument(
         "--dry-run",
         help=("Give this parameter if you don't want the script to actually"
               " make changes."),
@@ -332,6 +337,11 @@
 
     args = argparser.parse_args()
 
+    # argparse mutually exclusive is weird http://bugs.python.org/issue10984
+    if args.table and args.clean:
+        logging.critical("cannot specify a single table and cleanup")
+        sys.exit(1)
+
     with open(args.config_location, 'r') as stream:
         try:
             config = yaml.load(stream)
@@ -343,6 +353,14 @@
     all_tables = all_tables + config['fullviews']
     all_tables = all_tables + config['logging_whitelist']
     all_tables = all_tables + list(config['customviews'].keys())
+
+    if args.table:
+        fullviews = [t for t in config["fullviews"] if t == args.table]
+        # TODO: stop ignoring customviews on table specification
+        customviews = {}
+    else:
+        fullviews = config['fullviews']
+        customviews = config['customviews']
 
     dbs_metadata = config['metadata']
     sensitive_db_lists = config['sensitive_db_lists']
@@ -360,16 +378,17 @@
         charset="utf8"
     )
 
-    # Hacks
-    safelog = ("log_type IN ('" +
-               "', '".join(config["logging_whitelist"]) +
-               "')")
-    customviews = config["customviews"]
-    customviews["logging"]["where"] = safelog
-    customviews["logging_logindex"]["where"] = ("(log_deleted&1)=0 and " +
-                                                safelog)
-    customviews["logging_userindex"]["where"] = ("(log_deleted&4)=0 and " +
-                                                 safelog)
+    # This is weirdly arranged and should be cleaned up
+    # to be more explicit at the config file layer
+    if customviews:
+        safelog = ("log_type IN ('" +
+                   "', '".join(config["logging_whitelist"]) +
+                   "')")
+        customviews["logging"]["where"] = safelog
+        customviews["logging_logindex"]["where"] = ("(log_deleted&1)=0 and " +
+                                                    safelog)
+        customviews["logging_userindex"]["where"] = ("(log_deleted&4)=0 and " +
+                                                     safelog)
 
     # This will include private and deleted dbs at this stage
     all_dbs_file = "{}/dblists/all.dblist".format(args.mediawiki_config)
@@ -418,11 +437,13 @@
                 logging.critical("Definer has not been created")
                 sys.exit(1)
 
-            ops.execute(config["fullviews"], customviews)
+            ops.execute(fullviews, customviews)
 
             if args.clean:
+                logging.info('cleanup is enabled')
                 live_tables = ops.tables(ops.db_p)
                 dead_tables = [t for t in live_tables if t not in all_tables]
+                logging.info('cleaning {} tables'.format(len(dead_tables)))
                 for dt in dead_tables:
                     logging.info("Dropping view {}".format(dt))
                     ops.drop_view(dt)

-- 
To view, visit https://gerrit.wikimedia.org/r/316584
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I57f86dca5b730fd809379d5f2d34302f96e554ab
Gerrit-PatchSet: 5
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Rush <r...@wikimedia.org>
Gerrit-Reviewer: Rush <r...@wikimedia.org>
Gerrit-Reviewer: Volans <rcocci...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to