def test_write_invalid_unicode(self): bs = BSClient() log = BuildLog(bs, "un", "queue", "worker_id", 123, filename=self.filepath) with log: log.write(b'this can not be unicode \xe2') self.assertEqual(b'this can not be unicode \xe2', bs.last_log)
def test_write(self): log = BuildLog(BSClient(), "un", "queue", "worker_id", 123, filename=self.filepath) with log: self.assertTrue(log.writable()) res = log.write(b'test') self.assertEqual(4, res) with self.assertRaises(TypeError): log.write('this is unicode')
def mk_log(**kwargs): return BuildLog( BinstarBuildAPI(), "user_name", "queue_name", "worker_id", 123, **kwargs)
def test_read(self): with BuildLog(BSClient(), "un", "queue", "worker_id", 123, filename=self.filepath) as log: self.assertFalse(log.readable())
def mk_log(self, **kwargs): return BuildLog( BinstarBuildAPI(), "user_name", "queue_name", "worker_id", 123, filename=self.filepath, **kwargs)
def test_context(self): log = BuildLog(BSClient(), "un", "queue", "worker_id", 123, filename=self.filepath) self.assertFalse(log.fd.closed) with log: self.assertFalse(log.fd.closed) self.assertTrue(log.fd.closed)
def build(self, job_data): """ Run a single build """ job_id = job_data['job']['_id'] if 'envvars' in job_data['build_item_info']: job_data['build_item_info']['env'] = job_data[ 'build_item_info'].pop('envvars') working_dir = self.working_dir(job_data) staging_dir = self.staging_dir(job_data) # -- Clean -- log.info("Removing previous build dir: {0}".format(staging_dir)) rm_rf(staging_dir) log.info("Creating working dir: {0}".format(staging_dir)) os.makedirs(staging_dir) quiet = job_data['build_item_info'].get('instructions', {}).get('quiet', False) build_log = BuildLog( self.bs, self.config.username, self.config.queue, self.worker_id, job_id, filename=self.build_logfile(job_data), quiet=quiet, ) build_log.update_metadata({'section': 'dequeue_build'}) with build_log: instructions = job_data['build_item_info'].get('instructions') msg = "Building on worker {0} (platform {1})\n".format( self.config.hostname, self.config.platform) build_log.writeline(msg.encode('utf-8', errors='replace')) msg = "Starting build {0} at {1}\n".format( job_data['job_name'], job_data['BUILD_UTC_DATETIME']) build_log.writeline(msg.encode('utf-8', errors='replace')) # build_log.flush() script_filename = script_generator.gen_build_script( staging_dir, working_dir, job_data, conda_build_dir=self.args.conda_build_dir) iotimeout = instructions.get('iotimeout', DEFAULT_IO_TIMEOUT) timeout = self.args.timeout api_token = job_data['upload_token'] git_oauth_token = job_data.get('git_oauth_token') if not job_data.get('build_info', {}).get('github_info'): build_filename = self.download_build_source( staging_dir, job_id) else: build_filename = None exit_code = self.run( job_data, script_filename, build_log, timeout, iotimeout, api_token, git_oauth_token, build_filename, instructions=instructions, build_was_stopped_by_user=build_log.terminated) log.info("Build script exited with code {0}".format(exit_code)) if exit_code == script_generator.EXIT_CODE_OK: failed = False status = 'success' log.info('Build {0} Succeeded'.format(job_data['job_name'])) elif exit_code == script_generator.EXIT_CODE_ERROR: failed = True status = 'error' log.error("Build {0} errored".format(job_data['job_name'])) elif exit_code == script_generator.EXIT_CODE_FAILED: failed = True status = 'failure' log.error("Build {0} failed".format(job_data['job_name'])) else: # Unknown error failed = True status = 'error' log.error("Unknown build exit status {0} for build {1}".format( exit_code, job_data['job_name'])) return failed, status
def build(self, job_data): """ Run a single build """ job_id = job_data['job']['_id'] if 'envvars' in job_data['build_item_info']: job_data['build_item_info']['env'] = job_data['build_item_info'].pop('envvars') working_dir = self.working_dir(job_data) staging_dir = self.staging_dir(job_data) # -- Clean -- log.info("Removing previous build dir: {0}".format(staging_dir)) rm_rf(staging_dir) log.info("Creating working dir: {0}".format(staging_dir)) os.makedirs(staging_dir) quiet = job_data['build_item_info'].get('instructions',{}).get('quiet', False) build_log = BuildLog( self.bs, self.config.username, self.config.queue, self.worker_id, job_id, filename=self.build_logfile(job_data), quiet=quiet, ) build_log.update_metadata({'section': 'dequeue_build'}) with build_log: instructions = job_data['build_item_info'].get('instructions') msg = "Building on worker {0} (platform {1})\n".format( self.config.hostname, self.config.platform) build_log.writeline(msg.encode('utf-8', errors='replace')) msg = "Starting build {0} at {1}\n".format(job_data['job_name'], job_data['BUILD_UTC_DATETIME']) build_log.writeline(msg.encode('utf-8', errors='replace')) # build_log.flush() script_filename = script_generator.gen_build_script( staging_dir, working_dir, job_data, conda_build_dir=self.args.conda_build_dir) iotimeout = instructions.get('iotimeout', DEFAULT_IO_TIMEOUT) timeout = self.args.timeout api_token = job_data['upload_token'] git_oauth_token = job_data.get('git_oauth_token') if not job_data.get('build_info', {}).get('github_info'): build_filename = self.download_build_source(staging_dir, job_id) else: build_filename = None exit_code = self.run( job_data, script_filename, build_log, timeout, iotimeout, api_token, git_oauth_token, build_filename, instructions=instructions, build_was_stopped_by_user=build_log.terminated) log.info("Build script exited with code {0}".format(exit_code)) if exit_code == script_generator.EXIT_CODE_OK: failed = False status = 'success' log.info('Build {0} Succeeded'.format(job_data['job_name'])) elif exit_code == script_generator.EXIT_CODE_ERROR: failed = True status = 'error' log.error("Build {0} errored".format(job_data['job_name'])) elif exit_code == script_generator.EXIT_CODE_FAILED: failed = True status = 'failure' log.error("Build {0} failed".format(job_data['job_name'])) else: # Unknown error failed = True status = 'error' log.error("Unknown build exit status {0} for build {1}".format( exit_code, job_data['job_name'])) return failed, status