def get(self): auth.warmup() bot_code.get_swarming_bot_zip(self.request.host_url) bot_groups_config.warmup() utils.get_module_version_list(None, None) self.response.headers['Content-Type'] = 'text/plain; charset=utf-8' self.response.write('ok')
def test_get_swarming_bot_zip_is_reproducible(self): self.mock(time, 'time', lambda: 1500000000.0) local_mc = self.mock_memcache() zipped_code_1 = bot_code.get_swarming_bot_zip('http://localhost') # Time passes, memcache clears. self.mock(time, 'time', lambda: 1500001000.0) local_mc['store'].clear() # Some time later, the exact same zip is fetched, byte-to-byte. zipped_code_2 = bot_code.get_swarming_bot_zip('http://localhost') self.assertTrue(zipped_code_1 == zipped_code_2)
def test_get_swarming_bot_zip(self): get_self_config_orig = config.get_self_config def get_self_config_mock(path, revision=None, store_last_good=False): if path == 'settings.cfg': return get_self_config_orig(path, revision, store_last_good) self.assertEqual('scripts/bot_config.py', path) self.assertEqual(None, revision) self.assertEqual(True, store_last_good) return 'rev1', 'foo bar' self.mock(config, 'get_self_config', get_self_config_mock) local_mc = self.mock_memcache() self.assertEqual(0, local_mc['writes']) zipped_code = bot_code.get_swarming_bot_zip('http://localhost') self.assertEqual(0, local_mc['reads']) self.assertNotEqual(0, local_mc['writes']) # Make sure that we read from memcached if we get it again zipped_code_copy = bot_code.get_swarming_bot_zip('http://localhost') self.assertEqual(local_mc['writes'], local_mc['reads']) # Why not assertEqual? Don't want to dump ~1MB of data if this fails. self.assertTrue(zipped_code == zipped_code_copy) # Ensure the zip is valid and all the expected files are present. with zipfile.ZipFile(StringIO.StringIO(zipped_code), 'r') as zip_file: for i in bot_archive.FILES: with zip_file.open(i) as f: content = f.read() if os.path.basename(i) != '__init__.py': self.assertTrue(content, i) temp_dir = tempfile.mkdtemp(prefix='swarming') try: # Try running the bot and ensure it can import the required files. (It # would crash if it failed to import them). bot_path = os.path.join(temp_dir, 'swarming_bot.zip') with open(bot_path, 'wb') as f: f.write(zipped_code) proc = subprocess.Popen( [sys.executable, bot_path, 'start_bot', '-h'], cwd=temp_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out = proc.communicate()[0] self.assertEqual(0, proc.returncode, out) finally: file_path.rmtree(temp_dir)
def test_get_swarming_bot_zip(self): zipped_code = bot_code.get_swarming_bot_zip('http://localhost') # Ensure the zip is valid and all the expected files are present. with zipfile.ZipFile(StringIO.StringIO(zipped_code), 'r') as zip_file: for i in bot_archive.FILES: with zip_file.open(i) as f: content = f.read() if os.path.basename(i) != '__init__.py': self.assertTrue(content, i) temp_dir = tempfile.mkdtemp(prefix='swarming') try: # Try running the bot and ensure it can import the required files. (It # would crash if it failed to import them). bot_path = os.path.join(temp_dir, 'swarming_bot.zip') with open(bot_path, 'wb') as f: f.write(zipped_code) proc = subprocess.Popen( [sys.executable, bot_path, 'start_bot', '-h'], cwd=temp_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out = proc.communicate()[0] self.assertEqual(0, proc.returncode, out) finally: file_path.rmtree(temp_dir)
def get(self, version=None): if version: expected = bot_code.get_bot_version(self.request.host_url) if version != expected: # This can happen when the server is rapidly updated. logging.error("Requested Swarming bot %s, have %s", version, expected) self.abort(404) self.response.headers["Cache-Control"] = "public, max-age=3600" else: self.response.headers["Cache-Control"] = "no-cache, no-store" self.response.headers["Content-Type"] = "application/octet-stream" self.response.headers["Content-Disposition"] = 'attachment; filename="swarming_bot.zip"' self.response.out.write(bot_code.get_swarming_bot_zip(self.request.host_url))
def get(self, version=None): if version: expected = bot_code.get_bot_version(self.request.host_url) if version != expected: # This can happen when the server is rapidly updated. logging.error('Requested Swarming bot %s, have %s', version, expected) self.abort(404) self.response.headers['Cache-Control'] = 'public, max-age=3600' else: self.response.headers['Cache-Control'] = 'no-cache, no-store' self.response.headers['Content-Type'] = 'application/octet-stream' self.response.headers['Content-Disposition'] = ( 'attachment; filename="swarming_bot.zip"') self.response.out.write( bot_code.get_swarming_bot_zip(self.request.host_url))
def get(self): auth.warmup() bot_code.get_swarming_bot_zip(self.request.host_url) utils.get_module_version_list(None, None) self.response.headers['Content-Type'] = 'text/plain; charset=utf-8' self.response.write('ok')