Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(835)

Side by Side Diff: infra/libs/buildbot/master.py

Issue 1114303002: Abort master management if the current hostname doesn't match the master's. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix typo. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « infra/libs/buildbot/__init__.py ('k') | infra/tools/master_manager/__main__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Get information about a buildbot master and manipulate it.""" 5 """Get information about a buildbot master and manipulate it."""
6 6
7 7
8 import errno 8 import errno
9 import os 9 import os
10 import json 10 import json
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 """ 86 """
87 last_boot = get_last_boot(directory) 87 last_boot = get_last_boot(directory)
88 last_no_new_builds = _get_last_action(directory, 'make no-new-builds') 88 last_no_new_builds = _get_last_action(directory, 'make no-new-builds')
89 if not last_no_new_builds: 89 if not last_no_new_builds:
90 return None 90 return None
91 if last_boot > last_no_new_builds: 91 if last_boot > last_no_new_builds:
92 return None 92 return None
93 return last_no_new_builds 93 return last_no_new_builds
94 94
95 95
96 def _get_mastermap_data(directory): 96 def get_mastermap_data(directory):
97 """Get mastermap JSON from a master directory.""" 97 """Get mastermap JSON from a master directory."""
98 98
99 build_dir = os.path.join(directory, os.pardir, os.pardir, os.pardir, 'build') 99 build_dir = os.path.join(directory, os.pardir, os.pardir, os.pardir, 'build')
100 runit = os.path.join(build_dir, 'scripts', 'tools', 'runit.py') 100 runit = os.path.join(build_dir, 'scripts', 'tools', 'runit.py')
101 build_internal_dir = os.path.join(build_dir, os.pardir, 'build_internal') 101 build_internal_dir = os.path.join(build_dir, os.pardir, 'build_internal')
102 102
103 script_path = os.path.join(build_dir, 'scripts', 'tools', 'mastermap.py') 103 script_path = os.path.join(build_dir, 'scripts', 'tools', 'mastermap.py')
104 if os.path.exists(build_internal_dir): 104 if os.path.exists(build_internal_dir):
105 script_path = os.path.join( 105 script_path = os.path.join(
106 build_internal_dir, 'scripts', 'tools', 'mastermap_internal.py') 106 build_internal_dir, 'scripts', 'tools', 'mastermap_internal.py')
107 107
108 script_data = json.loads(subprocess.check_output( 108 script_data = json.loads(subprocess.check_output(
109 [runit, script_path, '-f', 'json'])) 109 [runit, script_path, '-f', 'json']))
110 110
111 short_dirname = os.path.basename(directory) 111 short_dirname = os.path.basename(directory)
112 matches = [x for x in script_data if x.get('dirname') == short_dirname] 112 matches = [x for x in script_data if x.get('dirname') == short_dirname]
113 assert len(matches) < 2, ( 113 assert len(matches) < 2, (
114 'Multiple masters were found with the same master directory.') 114 'Multiple masters were found with the same master directory.')
115 if matches: 115 if matches:
116 return matches[0] 116 return matches[0]
117 return None 117 return None
118 118
119 119
120 def _get_master_web_port(directory): 120 def _get_master_web_port(directory):
121 """Determine the web port of the master running in the given directory.""" 121 """Determine the web port of the master running in the given directory."""
122 mastermap_data = _get_mastermap_data(directory) 122 mastermap_data = get_mastermap_data(directory)
123 if mastermap_data: 123 if mastermap_data:
124 return mastermap_data['port'] 124 return mastermap_data['port']
125 return None 125 return None
126 126
127 127
128 def get_accepting_builds(directory, timeout=30): 128 def get_accepting_builds(directory, timeout=30):
129 """Determine whether the master is accepting new builds or not. 129 """Determine whether the master is accepting new builds or not.
130 130
131 *** This only works for masters running on localhost.*** 131 *** This only works for masters running on localhost.***
132 """ 132 """
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 elif action_item == MakeStop: 177 elif action_item == MakeStop:
178 yield cmd_dict(['make', 'stop'], 'make') 178 yield cmd_dict(['make', 'stop'], 'make')
179 elif action_item == MakeWait: 179 elif action_item == MakeWait:
180 yield cmd_dict(['make', 'wait'], 'make') 180 yield cmd_dict(['make', 'wait'], 'make')
181 elif action_item == MakeStart: 181 elif action_item == MakeStart:
182 yield cmd_dict(['make', 'start'], 'make') 182 yield cmd_dict(['make', 'start'], 'make')
183 elif action_item == MakeNoNewBuilds: 183 elif action_item == MakeNoNewBuilds:
184 yield cmd_dict(['make', 'no-new-builds'], 'make') 184 yield cmd_dict(['make', 'no-new-builds'], 'make')
185 else: 185 else:
186 raise ValueError('Invalid action item %s' % action_item) 186 raise ValueError('Invalid action item %s' % action_item)
OLDNEW
« no previous file with comments | « infra/libs/buildbot/__init__.py ('k') | infra/tools/master_manager/__main__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698