OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Swarming Authors. All rights reserved. | 2 # Copyright 2014 The Swarming Authors. All rights reserved. |
3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 # Use of this source code is governed by the Apache v2.0 license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Integration test for the Swarming server, Swarming bot and Swarming client. | 6 """Integration test for the Swarming server, Swarming bot and Swarming client. |
7 | 7 |
8 It starts both a Swarming server and a Swarming bot and triggers tasks with the | 8 It starts both a Swarming server and a Swarming bot and triggers tasks with the |
9 Swarming client to ensure the system works end to end. | 9 Swarming client to ensure the system works end to end. |
10 """ | 10 """ |
11 | 11 |
12 import json | 12 import json |
13 import glob | 13 import glob |
14 import logging | 14 import logging |
15 import os | 15 import os |
16 import shutil | |
17 import signal | 16 import signal |
18 import socket | 17 import socket |
19 import sys | 18 import sys |
20 import tempfile | 19 import tempfile |
21 import time | 20 import time |
22 import unittest | 21 import unittest |
23 import urllib | 22 import urllib |
24 | 23 |
25 APP_DIR = os.path.dirname(os.path.abspath(__file__)) | 24 APP_DIR = os.path.dirname(os.path.abspath(__file__)) |
26 BOT_DIR = os.path.join(APP_DIR, 'swarming_bot') | 25 BOT_DIR = os.path.join(APP_DIR, 'swarming_bot') |
27 CLIENT_DIR = os.path.join(APP_DIR, '..', '..', 'client') | 26 CLIENT_DIR = os.path.join(APP_DIR, '..', '..', 'client') |
28 | 27 |
29 from tools import start_bot | 28 from tools import start_bot |
30 from tools import start_servers | 29 from tools import start_servers |
31 | 30 |
32 sys.path.insert(0, CLIENT_DIR) | 31 sys.path.insert(0, CLIENT_DIR) |
| 32 from third_party.depot_tools import fix_encoding |
| 33 from utils import file_path |
33 from utils import subprocess42 | 34 from utils import subprocess42 |
34 sys.path.pop(0) | 35 sys.path.pop(0) |
35 | 36 |
36 sys.path.insert(0, BOT_DIR) | 37 sys.path.insert(0, BOT_DIR) |
37 | 38 |
38 # This is only needed on Windows. | 39 # This is only needed on Windows. |
39 import test_env_bot | 40 import test_env_bot |
40 test_env_bot.init_symlinks(BOT_DIR) | 41 test_env_bot.init_symlinks(BOT_DIR) |
41 | 42 |
42 from api import os_utilities | 43 from api import os_utilities |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 raise | 161 raise |
161 outputs = {} | 162 outputs = {} |
162 for root, _, files in os.walk(tmpdir): | 163 for root, _, files in os.walk(tmpdir): |
163 for i in files: | 164 for i in files: |
164 p = os.path.join(root, i) | 165 p = os.path.join(root, i) |
165 name = p[len(tmpdir)+1:] | 166 name = p[len(tmpdir)+1:] |
166 with open(p, 'rb') as f: | 167 with open(p, 'rb') as f: |
167 outputs[name] = f.read() | 168 outputs[name] = f.read() |
168 return summary, outputs | 169 return summary, outputs |
169 finally: | 170 finally: |
170 shutil.rmtree(tmpdir) | 171 file_path.rmtree(tmpdir) |
171 finally: | 172 finally: |
172 os.remove(tmp) | 173 os.remove(tmp) |
173 | 174 |
174 def terminate(self, bot_id): | 175 def terminate(self, bot_id): |
175 return self._run('terminate', ['--wait', bot_id]) | 176 return self._run('terminate', ['--wait', bot_id]) |
176 | 177 |
177 def cleanup(self): | 178 def cleanup(self): |
178 if self._tmpdir: | 179 if self._tmpdir: |
179 shutil.rmtree(self._tmpdir) | 180 file_path.rmtree(self._tmpdir) |
180 self._tmpdir = None | 181 self._tmpdir = None |
181 | 182 |
182 def dump_log(self): | 183 def dump_log(self): |
183 print >> sys.stderr, '-' * 60 | 184 print >> sys.stderr, '-' * 60 |
184 print >> sys.stderr, 'Client calls' | 185 print >> sys.stderr, 'Client calls' |
185 print >> sys.stderr, '-' * 60 | 186 print >> sys.stderr, '-' * 60 |
186 for i in xrange(self._index): | 187 for i in xrange(self._index): |
187 with open(os.path.join(self._tmpdir, 'client_%d.log' % i), 'rb') as f: | 188 with open(os.path.join(self._tmpdir, 'client_%d.log' % i), 'rb') as f: |
188 log = f.read().strip('\n') | 189 log = f.read().strip('\n') |
189 for l in log.splitlines(): | 190 for l in log.splitlines(): |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 with open(os.path.join(tmpdir, 'hello_world.py'), 'wb') as f: | 464 with open(os.path.join(tmpdir, 'hello_world.py'), 'wb') as f: |
464 f.write(hello_world) | 465 f.write(hello_world) |
465 isolated_hash = self.client.isolate(isolate_path, isolated_path) | 466 isolated_hash = self.client.isolate(isolate_path, isolated_path) |
466 task_id = self.client.task_trigger_isolated( | 467 task_id = self.client.task_trigger_isolated( |
467 name, isolated_hash, extra=args) | 468 name, isolated_hash, extra=args) |
468 actual_summary, actual_files = self.client.task_collect(task_id) | 469 actual_summary, actual_files = self.client.task_collect(task_id) |
469 self.assertResults(expected_summary, actual_summary) | 470 self.assertResults(expected_summary, actual_summary) |
470 actual_files.pop('summary.json') | 471 actual_files.pop('summary.json') |
471 self.assertEqual(expected_files, actual_files) | 472 self.assertEqual(expected_files, actual_files) |
472 finally: | 473 finally: |
473 shutil.rmtree(tmpdir) | 474 file_path.rmtree(tmpdir) |
474 | 475 |
475 def assertResults(self, expected, result): | 476 def assertResults(self, expected, result): |
476 self.assertEqual(['shards'], result.keys()) | 477 self.assertEqual(['shards'], result.keys()) |
477 self.assertEqual(1, len(result['shards'])) | 478 self.assertEqual(1, len(result['shards'])) |
478 self.assertTrue(result['shards'][0]) | 479 self.assertTrue(result['shards'][0]) |
479 result = result['shards'][0].copy() | 480 result = result['shards'][0].copy() |
480 # These are not deterministic (or I'm too lazy to calculate the value). | 481 # These are not deterministic (or I'm too lazy to calculate the value). |
481 bot_version = result.pop('bot_version') | 482 bot_version = result.pop('bot_version') |
482 self.assertTrue(bot_version) | 483 self.assertTrue(bot_version) |
483 self.assertTrue(result.pop('costs_usd')) | 484 self.assertTrue(result.pop('costs_usd')) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 if servers: | 518 if servers: |
518 servers.dump_log() | 519 servers.dump_log() |
519 if client: | 520 if client: |
520 client.dump_log() | 521 client.dump_log() |
521 finally: | 522 finally: |
522 if client and not leak: | 523 if client and not leak: |
523 client.cleanup() | 524 client.cleanup() |
524 | 525 |
525 | 526 |
526 def main(): | 527 def main(): |
| 528 fix_encoding.fix_encoding() |
527 verbose = '-v' in sys.argv | 529 verbose = '-v' in sys.argv |
528 leak = bool('--leak' in sys.argv) | 530 leak = bool('--leak' in sys.argv) |
529 if leak: | 531 if leak: |
530 sys.argv.remove('--leak') | 532 sys.argv.remove('--leak') |
531 if verbose: | 533 if verbose: |
532 logging.basicConfig(level=logging.INFO) | 534 logging.basicConfig(level=logging.INFO) |
533 unittest.TestCase.maxDiff = None | 535 unittest.TestCase.maxDiff = None |
534 else: | 536 else: |
535 logging.basicConfig(level=logging.ERROR) | 537 logging.basicConfig(level=logging.ERROR) |
536 | 538 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 if bot: | 576 if bot: |
575 bot.kill() | 577 bot.kill() |
576 bot.wait() | 578 bot.wait() |
577 finally: | 579 finally: |
578 cleanup(bot, client, servers, failed or verbose, leak) | 580 cleanup(bot, client, servers, failed or verbose, leak) |
579 return int(failed) | 581 return int(failed) |
580 | 582 |
581 | 583 |
582 if __name__ == '__main__': | 584 if __name__ == '__main__': |
583 sys.exit(main()) | 585 sys.exit(main()) |
OLD | NEW |