Volans has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/349731 )
Change subject: IRC logging, make messages more human-friendly
......................................................................
IRC logging, make messages more human-friendly
Bug: T163367
Change-Id: I4e5d37007165346c0874a7a29ad59fd446705268
---
M doc/examples/t01_example.py
M switchdc/lib/remote.py
M switchdc/log.py
M switchdc/menu.py
M switchdc/stages/t00_disable_puppet.py
M switchdc/stages/t00_reduce_ttl.py
M switchdc/stages/t01_stop_maintenance.py
M switchdc/stages/t02_start_mediawiki_readonly.py
M switchdc/stages/t03_coredb_masters_readonly.py
M switchdc/stages/t04_cache_wipe.py
M switchdc/stages/t05_switch_datacenter.py
M switchdc/stages/t05_switch_traffic.py
M switchdc/stages/t06_redis.py
M switchdc/stages/t07_coredb_masters_readwrite.py
M switchdc/stages/t08_stop_mediawiki_readonly.py
M switchdc/stages/t09_restart_parsoid.py
M switchdc/stages/t09_restore_ttl.py
M switchdc/stages/t09_start_maintenance.py
M switchdc/stages/t09_tendril.py
M switchdc/switch.py
20 files changed, 59 insertions(+), 39 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/switchdc
refs/changes/31/349731/1
diff --git a/doc/examples/t01_example.py b/doc/examples/t01_example.py
index 2f94059..b6fb0c3 100644
--- a/doc/examples/t01_example.py
+++ b/doc/examples/t01_example.py
@@ -2,7 +2,7 @@
from switchdc.log import logger
from switchdc.stages import get_module_config
-__title__ = "Example task description"
+__title__ = 'Example task description, migrates service from {dc_from} to
{dc_to}'
# Standard location for config files specific to this module:
# ${CONFIG_DIR}/stages.d/t01_example
diff --git a/switchdc/lib/remote.py b/switchdc/lib/remote.py
index 05bddcf..6f5d7ec 100644
--- a/switchdc/lib/remote.py
+++ b/switchdc/lib/remote.py
@@ -13,7 +13,7 @@
# Load cumin's configuration
-with open('/etc/cumin/config.yaml', 'r') as f:
+with open('config.yaml', 'r') as f:
cumin_config = yaml.safe_load(f)
diff --git a/switchdc/log.py b/switchdc/log.py
index 9f57782..6adcfef 100644
--- a/switchdc/log.py
+++ b/switchdc/log.py
@@ -38,8 +38,8 @@
See https://docs.python.org/2/library/logging.html#handler-objects
"""
- message = '!log switchdc ({user}@{host}) {msg}'.format(
- user=self.user, host=socket.gethostname(), msg=record.getMessage())
+ message = '!log {msg} (switchdc/{user}@{host})'.format(
+ msg=record.getMessage(), user=self.user, host=socket.gethostname())
sock = None
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -102,18 +102,33 @@
logger.setLevel(logging.DEBUG)
-def log_task_start(prefix, message):
- """Log the start of a task."""
- _log_task('START', prefix, message)
+def log_task_start(message):
+ """Log the start of a task both on the logs and IRC.
+
+ Arguments:
+ message -- the message to be logged.
+ """
+ _log_task('START', message)
-def log_task_end(prefix, message):
- """Log the end of a task."""
- _log_task('END', prefix, message)
+def log_task_end(status, message):
+ """Log the start of a task both on the logs and IRC.
+
+ Arguments:
+ status -- the final status of the task.
+ message -- the message to be logged.
+ """
+ _log_task('END ({status})'.format(status=status), message)
-def _log_task(action, prefix, message):
- message = '{action} TASK - {prefix} {message}'.format(action=action,
prefix=prefix, message=message)
+def _log_task(prefix, message):
+ """Log a task message both on the logs and IRC.
+
+ Arguments:
+ prefix -- the prefix of the message.
+ message -- the message to be logged.
+ """
+ message = '{prefix} - {message}'.format(prefix=prefix, message=message)
logger.info(message)
if not is_dry_run():
diff --git a/switchdc/menu.py b/switchdc/menu.py
index 0b29a04..a95743a 100644
--- a/switchdc/menu.py
+++ b/switchdc/menu.py
@@ -97,23 +97,29 @@
kwargs -- the dictionary of keyword arguments to pass to the
function. [optional, default: None]
"""
self.name = name
- self.title = title
self.status = self.todo
self.function = function
+
if args is not None:
self.args = args
else:
- self.args = []
+ self.args = ()
+
if kwargs is not None:
self.kwargs = kwargs
else:
self.kwargs = {}
+ try:
+ title = title.format(*self.args, **self.kwargs)
+ except (KeyError, IndexError):
+ pass # Leave the title untouched if unable to format it
+
+ self.title = '{title} - {name}'.format(title=title, name=self.name)
+
def run(self):
- """Run the item calling the configured function."""
- params = ', '.join(self.args + ['='.join([str(k), str(v)]) for k, v in
self.kwargs.iteritems()])
- task_desc = '{name}({params})'.format(name=self.name, params=params)
- log_task_start(task_desc, self.title)
+ """Run the item, calling the configured function."""
+ log_task_start(self.title)
try:
self.function(*self.args, **self.kwargs)
@@ -126,11 +132,9 @@
if retval == 0:
self.status = self.success
- message = 'Successfully completed'
else:
self.status = self.failed
- message = 'Failed to execute'
- log_task_end(task_desc, message)
+ log_task_end(self.status, self.title)
return retval
diff --git a/switchdc/stages/t00_disable_puppet.py
b/switchdc/stages/t00_disable_puppet.py
index 1fff823..2b936cb 100644
--- a/switchdc/stages/t00_disable_puppet.py
+++ b/switchdc/stages/t00_disable_puppet.py
@@ -2,7 +2,7 @@
from switchdc.lib.remote import Remote
from switchdc.log import logger
-__title__ = 'Disabling puppet on selected hosts'
+__title__ = 'Disabling puppet on selected hosts in {dc_from} and {dc_to}'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t00_reduce_ttl.py
b/switchdc/stages/t00_reduce_ttl.py
index 4a8d9df..ece5409 100644
--- a/switchdc/stages/t00_reduce_ttl.py
+++ b/switchdc/stages/t00_reduce_ttl.py
@@ -2,7 +2,7 @@
from switchdc.lib.dnsdisc import DiscoveryTTL
-__title__ = 'Reduce the TTL of all the MediaWiki discovery records'
+__title__ = 'Reduce the TTL of all the MediaWiki read-write discovery records'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t01_stop_maintenance.py
b/switchdc/stages/t01_stop_maintenance.py
index 32b2aeb..4ec39da 100644
--- a/switchdc/stages/t01_stop_maintenance.py
+++ b/switchdc/stages/t01_stop_maintenance.py
@@ -1,7 +1,7 @@
from switchdc.lib.remote import Remote, RemoteExecutionError
from switchdc.log import logger
-__title__ = "Stop MediaWiki maintenance in the old master DC"
+__title__ = 'Stop MediaWiki jobrunners, videoscalers and maintenance in
{dc_from}'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t02_start_mediawiki_readonly.py
b/switchdc/stages/t02_start_mediawiki_readonly.py
index c2bd306..900bddb 100644
--- a/switchdc/stages/t02_start_mediawiki_readonly.py
+++ b/switchdc/stages/t02_start_mediawiki_readonly.py
@@ -5,7 +5,7 @@
from switchdc.lib import mediawiki
from switchdc.log import irc_logger, logger
-__title__ = "Set MediaWiki in read-only mode (db_from config already merged
and git pulled)"
+__title__ = 'Set MediaWiki in read-only mode in {dc_from} (db-{dc_from} config
already merged and git pulled)'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t03_coredb_masters_readonly.py
b/switchdc/stages/t03_coredb_masters_readonly.py
index 1057563..2a759c4 100644
--- a/switchdc/stages/t03_coredb_masters_readonly.py
+++ b/switchdc/stages/t03_coredb_masters_readonly.py
@@ -2,7 +2,7 @@
from switchdc.lib import mysql
from switchdc.log import logger
-__title__ = "set core DB masters in read-only mode"
+__title__ = 'Set core DB masters in read-only mode in {dc_from}, ensure all
masters are read-only'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t04_cache_wipe.py
b/switchdc/stages/t04_cache_wipe.py
index 8914121..fccd59f 100644
--- a/switchdc/stages/t04_cache_wipe.py
+++ b/switchdc/stages/t04_cache_wipe.py
@@ -3,7 +3,7 @@
from switchdc.log import logger
from switchdc.stages import get_module_config
-__title__ = "wipe and warmup caches"
+__title__ = 'Wipe and warmup caches in {dc_from}'
config = get_module_config('t03_cache_wipe')
diff --git a/switchdc/stages/t05_switch_datacenter.py
b/switchdc/stages/t05_switch_datacenter.py
index 98ddd25..03a338e 100644
--- a/switchdc/stages/t05_switch_datacenter.py
+++ b/switchdc/stages/t05_switch_datacenter.py
@@ -4,7 +4,7 @@
from switchdc.lib.confctl import Confctl
from switchdc.log import logger
-__title__ = "Switch MediaWiki configuration to the new datacenter"
+__title__ = 'Switch MediaWiki master datacenter and read-write discovery
records from {dc_from} to {dc_to}'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t05_switch_traffic.py
b/switchdc/stages/t05_switch_traffic.py
index 823f298..82ca092 100644
--- a/switchdc/stages/t05_switch_traffic.py
+++ b/switchdc/stages/t05_switch_traffic.py
@@ -2,7 +2,7 @@
from switchdc.lib.remote import Remote
from switchdc.log import logger
-__title__ = "Switch traffic flow to the appservers in the new datacenter"
+__title__ = 'Switch traffic flow to the appservers from {dc_from} to {dc_to}'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t06_redis.py b/switchdc/stages/t06_redis.py
index a7ce7dc..36d7e5f 100644
--- a/switchdc/stages/t06_redis.py
+++ b/switchdc/stages/t06_redis.py
@@ -8,7 +8,7 @@
from switchdc.log import logger
from switchdc.stages import get_module_config, get_module_config_dir
-__title__ = 'Switch the Redis replication'
+__title__ = 'Switch the Redis masters from {dc_from} to {dc_to} and invert the
replication'
dirname = __name__.split('.')[-1]
config = get_module_config(dirname)
diff --git a/switchdc/stages/t07_coredb_masters_readwrite.py
b/switchdc/stages/t07_coredb_masters_readwrite.py
index 5778585..e6ccd1c 100644
--- a/switchdc/stages/t07_coredb_masters_readwrite.py
+++ b/switchdc/stages/t07_coredb_masters_readwrite.py
@@ -2,7 +2,7 @@
from switchdc.lib import mysql
from switchdc.log import logger
-__title__ = "set core DB masters in read-write mode"
+__title__ = 'Set core DB masters in read-write mode in {dc_to}, ensure masters
in {dc_from} are read-only'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t08_stop_mediawiki_readonly.py
b/switchdc/stages/t08_stop_mediawiki_readonly.py
index 1dc94ee..f4575a5 100644
--- a/switchdc/stages/t08_stop_mediawiki_readonly.py
+++ b/switchdc/stages/t08_stop_mediawiki_readonly.py
@@ -5,7 +5,7 @@
from switchdc.lib import mediawiki
from switchdc.log import irc_logger, logger
-__title__ = "Set MediaWiki in read-write mode (db_to config already merged and
git pulled)"
+__title__ = 'Set MediaWiki in read-write mode in {dc_to} (db-{dc_to} config
already merged and git pulled)'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t09_restart_parsoid.py
b/switchdc/stages/t09_restart_parsoid.py
index 555811c..b25ac2a 100644
--- a/switchdc/stages/t09_restart_parsoid.py
+++ b/switchdc/stages/t09_restart_parsoid.py
@@ -1,6 +1,6 @@
from switchdc.lib.remote import Remote
-__title__ = "Rolling restart parsoid in eqiad and codfw"
+__title__ = 'Rolling restart of parsoid in {dc_from} and {dc_to}'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t09_restore_ttl.py
b/switchdc/stages/t09_restore_ttl.py
index e61f317..bd238c4 100644
--- a/switchdc/stages/t09_restore_ttl.py
+++ b/switchdc/stages/t09_restore_ttl.py
@@ -2,7 +2,7 @@
from switchdc.lib.dnsdisc import DiscoveryTTL
-__title__ = "Restore the TTL of all the MediaWiki discovery records"
+__title__ = 'Restore the TTL of all the MediaWiki read-write discovery records'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t09_start_maintenance.py
b/switchdc/stages/t09_start_maintenance.py
index 25b8cc8..045ccd8 100644
--- a/switchdc/stages/t09_start_maintenance.py
+++ b/switchdc/stages/t09_start_maintenance.py
@@ -1,7 +1,7 @@
from switchdc import get_reason
from switchdc.lib.remote import Remote
-__title__ = "Start MediaWiki maintenance in the new master DC"
+__title__ = 'Start MediaWiki jobrunners, videoscalers and maintenance in
{dc_to}'
def execute(dc_from, dc_to):
diff --git a/switchdc/stages/t09_tendril.py b/switchdc/stages/t09_tendril.py
index 886cfbe..6ebc616 100644
--- a/switchdc/stages/t09_tendril.py
+++ b/switchdc/stages/t09_tendril.py
@@ -3,7 +3,7 @@
from switchdc.lib.remote import Remote
from switchdc.log import logger
-__title__ = "Update Tendril configuration for the new masters"
+__title__ = 'Update Tendril tree to start from the core DB masters in {dc_to}'
def execute(dc_from, dc_to):
diff --git a/switchdc/switch.py b/switchdc/switch.py
index cc3433a..174370c 100644
--- a/switchdc/switch.py
+++ b/switchdc/switch.py
@@ -90,7 +90,8 @@
submenu = Menu('Stage {stage}'.format(stage=module_stage))
menu.append(submenu, stage)
- submenu.append(Item(module.__name__, module.__title__, module.execute,
args=[dc_from, dc_to]))
+ submenu.append(Item(module.__name__.split('.')[-1], module.__title__,
module.execute,
+ kwargs={'dc_from': dc_from, 'dc_to': dc_to}))
return menu
@@ -119,7 +120,7 @@
try:
submenu = menu.items[stage]
for item in submenu.items.values():
- if item.name.split('.')[-1] == args.task:
+ if item.name == args.task:
rc = item.run()
break
else:
@@ -135,7 +136,7 @@
for item in menu.items[stage].items.values():
rc = item.run()
if rc != 0:
- print "Task {name}: {title} failed, aborting
execution".format(name=item.name, title=item.title)
+ print "Task {name} failed, aborting
execution".format(name=item.name)
break
else:
rc = run(menu, args.dc_from, args.dc_to) # Run the interactive menu
--
To view, visit https://gerrit.wikimedia.org/r/349731
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e5d37007165346c0874a7a29ad59fd446705268
Gerrit-PatchSet: 1
Gerrit-Project: operations/switchdc
Gerrit-Branch: master
Gerrit-Owner: Volans <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits