| OLD | NEW |
| 1 # Copyright 2008 Google Inc, Martin J. Bligh <mbligh@google.com>, | 1 # Copyright 2008 Google Inc, Martin J. Bligh <mbligh@google.com>, |
| 2 # Benjamin Poirier, Ryan Stutsman | 2 # Benjamin Poirier, Ryan Stutsman |
| 3 # Released under the GPL v2 | 3 # Released under the GPL v2 |
| 4 """ | 4 """ |
| 5 Miscellaneous small functions. | 5 Miscellaneous small functions. |
| 6 | 6 |
| 7 DO NOT import this file directly - it is mixed in by server/utils.py, | 7 DO NOT import this file directly - it is mixed in by server/utils.py, |
| 8 import that instead | 8 import that instead |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 while len(key_machines) >= n: | 237 while len(key_machines) >= n: |
| 238 ntuples.append(key_machines[0:n]) | 238 ntuples.append(key_machines[0:n]) |
| 239 key_machines = key_machines[n:] | 239 key_machines = key_machines[n:] |
| 240 | 240 |
| 241 for mach in key_machines: | 241 for mach in key_machines: |
| 242 failures.append((mach, "machine can not be tupled")) | 242 failures.append((mach, "machine can not be tupled")) |
| 243 | 243 |
| 244 return (ntuples, failures) | 244 return (ntuples, failures) |
| 245 | 245 |
| 246 | 246 |
| 247 def parse_machine(machine, user='root', password='', port=22): | 247 def parse_machine(machine, user = 'root', port = 22, password = ''): |
| 248 """ | 248 """ |
| 249 Parse the machine string user:pass@host:port and return it separately, | 249 Parse the machine string user:pass@host:port and return it separately, |
| 250 if the machine string is not complete, use the default parameters | 250 if the machine string is not complete, use the default parameters |
| 251 when appropriate. | 251 when appropriate. |
| 252 """ | 252 """ |
| 253 | 253 |
| 254 if '@' in machine: | 254 user = user |
| 255 user, machine = machine.split('@', 1) | 255 port = port |
| 256 password = password |
| 256 | 257 |
| 257 if ':' in user: | 258 if re.search('@', machine): |
| 258 user, password = user.split(':', 1) | 259 machine = machine.split('@') |
| 259 | 260 |
| 260 if ':' in machine: | 261 if re.search(':', machine[0]): |
| 261 machine, port = machine.split(':', 1) | 262 machine[0] = machine[0].split(':') |
| 262 port = int(port) | 263 user = machine[0][0] |
| 264 password = machine[0][1] |
| 263 | 265 |
| 264 if not machine or not user: | 266 else: |
| 265 raise ValueError | 267 user = machine[0] |
| 266 | 268 |
| 267 return machine, user, password, port | 269 if re.search(':', machine[1]): |
| 270 machine[1] = machine[1].split(':') |
| 271 hostname = machine[1][0] |
| 272 port = int(machine[1][1]) |
| 273 |
| 274 else: |
| 275 hostname = machine[1] |
| 276 |
| 277 elif re.search(':', machine): |
| 278 machine = machine.split(':') |
| 279 hostname = machine[0] |
| 280 port = int(machine[1]) |
| 281 |
| 282 else: |
| 283 hostname = machine |
| 284 |
| 285 return hostname, user, password, port |
| 268 | 286 |
| 269 | 287 |
| 270 def get_public_key(): | 288 def get_public_key(): |
| 271 """ | 289 """ |
| 272 Return a valid string ssh public key for the user executing autoserv or | 290 Return a valid string ssh public key for the user executing autoserv or |
| 273 autotest. If there's no DSA or RSA public key, create a DSA keypair with | 291 autotest. If there's no DSA or RSA public key, create a DSA keypair with |
| 274 ssh-keygen and return it. | 292 ssh-keygen and return it. |
| 275 """ | 293 """ |
| 276 | 294 |
| 277 ssh_conf_path = os.path.expanduser('~/.ssh') | 295 ssh_conf_path = os.path.expanduser('~/.ssh') |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 419 |
| 402 # Client side barrier for all the tests to start at the same time | 420 # Client side barrier for all the tests to start at the same time |
| 403 control_new.append('b1 = job.barrier("%s", "c_bar", %d, port=%d)' | 421 control_new.append('b1 = job.barrier("%s", "c_bar", %d, port=%d)' |
| 404 % (jobid, c_bar_timeout, c_bar_port)) | 422 % (jobid, c_bar_timeout, c_bar_port)) |
| 405 control_new.append("b1.rendezvous(%s)" % rendvstr) | 423 control_new.append("b1.rendezvous(%s)" % rendvstr) |
| 406 | 424 |
| 407 # Stick in the rest of the control file | 425 # Stick in the rest of the control file |
| 408 control_new.append(control) | 426 control_new.append(control) |
| 409 | 427 |
| 410 return "\n".join(control_new) | 428 return "\n".join(control_new) |
| OLD | NEW |