[MediaWiki-commits] [Gerrit] labs/toollabs[master]: sql: Update to allow connecting to new cluster
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/380684 ) Change subject: sql: Update to allow connecting to new cluster .. sql: Update to allow connecting to new cluster Update the python port of /usr/bin/sql to add: * --cluster argument for selecting analytics, web, or labsdb hosts * Simplify legacy alias support * Add additional aliases for connecting to tools.db.svc.eqiad.wmflabs * Arbitrary style changes that I couldn't help myself from making Bug: T176688 Change-Id: I5d432bb3e0565cc2a7b729b6ba7306cbcc4cec9b --- M debian/changelog M misctools/sql 2 files changed, 78 insertions(+), 46 deletions(-) Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified diff --git a/debian/changelog b/debian/changelog index 6c073c3..99b8010 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +toollabs (1.22) trusty; urgency=medium + + * misctools: update sql command + + -- Bryan Davis Mon, 26 Sep 2017 04:47:19 + + toollabs (1.21) trusty; urgency=medium * jsub: remove support for release=precise diff --git a/misctools/sql b/misctools/sql index 9621886..b3dd580 100755 --- a/misctools/sql +++ b/misctools/sql @@ -1,6 +1,7 @@ -#!/usr/bin/python3 +#!/usr/bin/python3 -Es # # Copyright (C) 2017 Tim Landscheidt +# Copyright (C) 2017 Wikimedia Foundation and contributors # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,72 +23,97 @@ import socket import sys -parser = argparse.ArgumentParser(description='Connect to or run SQL query ' + - 'on replica or Tools database server', - epilog='Report bugs to Phabricator: ' + - 'https://phabricator.wikimedia.org') -parser.add_argument('-v', '--verbose', action='store_true', default=False, -help='show debugging information') -parser.add_argument('dbname', metavar='DATABASE NAME|WIKI NAME', -help='for example commonswiki_p or enwiki') -parser.add_argument('sqlquery', metavar='SQL QUERY', nargs=argparse.REMAINDER, -help='SQL query; multiple words will be joined by spaces') +logger = logging.getLogger(__name__) + +ALIASES = { +'commons': 'commonswiki_p', +'cs': 'cswiki_p', +'de': 'dewiki_p', +'en': 'enwiki_p', +'fr': 'frwiki_p', +'wikidata': 'wikidatawiki_p', +'meta': 'meta_p', +} + +parser = argparse.ArgumentParser( +description=( +'Connect to or run SQL query ' +'on replica or Tools database server'), +epilog=( +'Report bugs to Phabricator: ' +'https://phabricator.wikimedia.org') +) +parser.add_argument( +'-v', '--verbose', action='count', default=0, dest='loglevel', +help='increase logging verbosity') +parser.add_argument( +'--cluster', default='labsdb', +choices=['analytics', 'web', 'labsdb'], +help='cluster to connect to') +parser.add_argument( +'dbname', metavar='DATABASE', +help='for example commonswiki_p or enwiki') +parser.add_argument( +'sqlquery', metavar='...', nargs=argparse.REMAINDER, +help='SQL query; multiple arguments will be joined by spaces') args = parser.parse_args() -# Set up logging. -logging.basicConfig(stream=sys.stderr, -format='%(message)s', -level=logging.DEBUG if args.verbose else logging.WARN) +logging.basicConfig( +stream=sys.stderr, +format='%(message)s', +level=max(logging.DEBUG, logging.WARNING - (10 * args.loglevel))) + +if args.cluster == 'labsdb': +domain = 'labsdb' +else: +domain = '{}.db.svc.eqiad.wmflabs'.format(args.cluster) exec_args = ['mysql'] -if os.path.isfile(os.path.expanduser('~/replica.my.cnf')): -exec_args += ['--defaults-file=' + os.path.expanduser('~/replica.my.cnf')] -elif not(os.path.isfile(os.path.expanduser('~/.my.cnf'))): -exec_args += ['-p'] -logging.warn('There is no configuration file for mysql to use, ' + - 'you will probably be unable to access the database') +replica_cnf = os.path.expanduser('~/replica.my.cnf') +if os.path.isfile(replica_cnf): +exec_args.append('--defaults-file={}'.format(replica_cnf)) +elif not os.path.isfile(os.path.expanduser('~/.my.cnf')): +exec_args.append('-p') +logger.warn( +'There is no configuration file for mysql to use, ' + +'you will probably be unable to access the database') -# These aliases have historically been supported; no new ones should -# be added here. -if args.dbname in ['commons', 'cs', 'de', 'en', 'fr', 'wikidata']: -server = args.dbname + 'wiki.labsdb' -db = args.dbname + 'wiki_p' -elif args.dbname in ['meta', 'meta_p']: -# https://wikitech.wikimedia.org/wiki/Help:Tool_Labs/Database#Metadata_database; +db = ALIASE
[MediaWiki-commits] [Gerrit] labs/toollabs[master]: sql: Update to allow connecting to new cluster
BryanDavis has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380684 ) Change subject: sql: Update to allow connecting to new cluster .. sql: Update to allow connecting to new cluster Update the python port of /usr/bin/sql to add: * --cluster argument for selecting analytics, web, or labsdb hosts * Simplify legacy alias support * Add additional aliases for connecting to tools.db.svc.eqiad.wmflabs * Arbitrary style changes that I couldn't help myself from making Bug: T176688 Change-Id: I5d432bb3e0565cc2a7b729b6ba7306cbcc4cec9b --- M debian/changelog M misctools/sql 2 files changed, 78 insertions(+), 46 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs refs/changes/84/380684/1 diff --git a/debian/changelog b/debian/changelog index 6c073c3..99b8010 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +toollabs (1.22) trusty; urgency=medium + + * misctools: update sql command + + -- Bryan Davis Mon, 26 Sep 2017 04:47:19 + + toollabs (1.21) trusty; urgency=medium * jsub: remove support for release=precise diff --git a/misctools/sql b/misctools/sql index 9621886..b3dd580 100755 --- a/misctools/sql +++ b/misctools/sql @@ -1,6 +1,7 @@ -#!/usr/bin/python3 +#!/usr/bin/python3 -Es # # Copyright (C) 2017 Tim Landscheidt +# Copyright (C) 2017 Wikimedia Foundation and contributors # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,72 +23,97 @@ import socket import sys -parser = argparse.ArgumentParser(description='Connect to or run SQL query ' + - 'on replica or Tools database server', - epilog='Report bugs to Phabricator: ' + - 'https://phabricator.wikimedia.org') -parser.add_argument('-v', '--verbose', action='store_true', default=False, -help='show debugging information') -parser.add_argument('dbname', metavar='DATABASE NAME|WIKI NAME', -help='for example commonswiki_p or enwiki') -parser.add_argument('sqlquery', metavar='SQL QUERY', nargs=argparse.REMAINDER, -help='SQL query; multiple words will be joined by spaces') +logger = logging.getLogger(__name__) + +ALIASES = { +'commons': 'commonswiki_p', +'cs': 'cswiki_p', +'de': 'dewiki_p', +'en': 'enwiki_p', +'fr': 'frwiki_p', +'wikidata': 'wikidatawiki_p', +'meta': 'meta_p', +} + +parser = argparse.ArgumentParser( +description=( +'Connect to or run SQL query ' +'on replica or Tools database server'), +epilog=( +'Report bugs to Phabricator: ' +'https://phabricator.wikimedia.org') +) +parser.add_argument( +'-v', '--verbose', action='count', default=0, dest='loglevel', +help='increase logging verbosity') +parser.add_argument( +'--cluster', default='labsdb', +choices=['analytics', 'web', 'labsdb'], +help='cluster to connect to') +parser.add_argument( +'dbname', metavar='DATABASE', +help='for example commonswiki_p or enwiki') +parser.add_argument( +'sqlquery', metavar='...', nargs=argparse.REMAINDER, +help='SQL query; multiple arguments will be joined by spaces') args = parser.parse_args() -# Set up logging. -logging.basicConfig(stream=sys.stderr, -format='%(message)s', -level=logging.DEBUG if args.verbose else logging.WARN) +logging.basicConfig( +stream=sys.stderr, +format='%(message)s', +level=max(logging.DEBUG, logging.WARNING - (10 * args.loglevel))) + +if args.cluster == 'labsdb': +domain = 'labsdb' +else: +domain = '{}.db.svc.eqiad.wmflabs'.format(args.cluster) exec_args = ['mysql'] -if os.path.isfile(os.path.expanduser('~/replica.my.cnf')): -exec_args += ['--defaults-file=' + os.path.expanduser('~/replica.my.cnf')] -elif not(os.path.isfile(os.path.expanduser('~/.my.cnf'))): -exec_args += ['-p'] -logging.warn('There is no configuration file for mysql to use, ' + - 'you will probably be unable to access the database') +replica_cnf = os.path.expanduser('~/replica.my.cnf') +if os.path.isfile(replica_cnf): +exec_args.append('--defaults-file={}'.format(replica_cnf)) +elif not os.path.isfile(os.path.expanduser('~/.my.cnf')): +exec_args.append('-p') +logger.warn( +'There is no configuration file for mysql to use, ' + +'you will probably be unable to access the database') -# These aliases have historically been supported; no new ones should -# be added here. -if args.dbname in ['commons', 'cs', 'de', 'en', 'fr', 'wikidata']: -server = args.dbname + 'wiki.labsdb' -db = args.dbname + 'wiki_p' -elif args.dbname in ['meta', 'meta_p']: -# https://wikitech.wikimedia.org/wiki/Help:Tool_Labs/Database#Metadata_database; +db = ALIASES.get(ar