Index: infra/tools/restart/restart.py |
diff --git a/infra/tools/restart/restart.py b/infra/tools/restart/restart.py |
index d48ad6e9a04f45e54ead8463b2abf728a5bc3afd..dde8639ef3dcb97b4674570992ecb729c7c1a5a4 100644 |
--- a/infra/tools/restart/restart.py |
+++ b/infra/tools/restart/restart.py |
@@ -4,6 +4,7 @@ |
import contextlib |
import datetime |
+import distutils.util |
import json |
import logging |
import os |
@@ -19,6 +20,8 @@ from infra.libs.time_functions import zulu |
LOGGER = logging.getLogger(__name__) |
+MM_REPO = 'https://chrome-internal.googlesource.com/infradata/master-manager' |
+ |
class MasterNotFoundException(Exception): |
pass |
@@ -30,6 +33,9 @@ def add_argparse_options(parser): |
'-m', '--minutes-in-future', default=15, type=int, |
help='how many minutes in the future to schedule the restart. ' |
'use 0 for "now." default %(default)d') |
+ parser.add_argument( |
+ '--force', action='store_true', |
Ryan Tseng
2015/09/08 22:10:39
+ short arg "-f"
ghost stip (do not use)
2015/09/09 00:08:53
Done.
|
+ help='don\'t ask for confirmation, just commit') |
def get_restart_time(delta): |
@@ -41,28 +47,44 @@ def get_restart_time(delta): |
@contextlib.contextmanager |
def get_master_state_checkout(): |
target_dir = tempfile.mkdtemp() |
- mm_repo = 'https://chrome-internal.googlesource.com/infradata/master-manager' |
try: |
- LOGGER.info('Cloning %s into %s' % (mm_repo, target_dir)) |
- subprocess.call(['git', 'clone', mm_repo, target_dir]) |
+ LOGGER.info('Cloning %s into %s' % (MM_REPO, target_dir)) |
+ subprocess.call(['git', 'clone', MM_REPO, target_dir]) |
LOGGER.info('done') |
yield target_dir |
finally: |
shutil.rmtree(target_dir) |
-def commit(target, masters): |
+def commit(target, masters, timestring, force): |
"""Commits the local CL via the CQ.""" |
desc = 'Restarting masters %s' % ', '.join(masters) |
subprocess.check_call( |
['git', 'commit', '--all', '--message', desc], cwd=target) |
+ |
+ print 'Restarting the following masters at %s' % timestring |
Ryan Tseng
2015/09/08 22:10:39
Suggestion:
Restarting the following masters in 5
ghost stip (do not use)
2015/09/09 00:08:54
Done.
|
+ for master in sorted(masters): |
+ print ' %s' % master |
Ryan Tseng
2015/09/08 22:10:39
+print "This will upload a CL for master_manager.g
ghost stip (do not use)
2015/09/09 00:08:54
Done.
|
+ |
+ if not force: |
+ print 'Commit? [Y/n]:', |
+ input_string = raw_input() |
+ if input_string != '' and not distutils.util.strtobool(input_string): |
Ryan Tseng
2015/09/08 22:10:39
https://big.corp.google.com/~jmcmaster/testing/201
ghost stip (do not use)
2015/09/09 00:08:54
problem is, this has to return to stop control flo
|
+ print 'Aborting.' |
+ return |
+ |
+ print 'To cancel, edit desired_master_state.json in %s.' % MM_REPO |
+ |
LOGGER.info('Uploading to Rietveld and CQ.') |
subprocess.check_call( |
['git', 'cl', 'upload', '-m', desc, '-t', desc, |
'--tbr-owners', '-c', '-f'], cwd=target) |
-def run(masters, delta): |
+def run(masters, delta, force): |
"""Restart all the masters in the list of masters. |
Schedules the restart for now + delta. |
@@ -98,4 +120,4 @@ def run(masters, delta): |
# Step 3: Send the patch to Rietveld and commit it via the CQ. |
LOGGER.info('Committing back into repository') |
- commit(master_state_dir, masters) |
+ commit(master_state_dir, masters, restart_time, force) |