def create_osbs_build_object(mocker, builder_type, params): mocker.patch.object(subprocess, 'check_output') mocker.patch('cekit.tools.decision') builder = Builder(builder_type, 'tmp', params) builder.dist_git_dir = '/tmp' builder.dist_git = DistGitMock() builder.artifacts = [] return builder
def test_osbs_builder_user(mocker): mocker.patch.object(subprocess, 'check_output') params = {'user': '******'} builder = Builder('osbs', 'tmp', params) assert builder._user == 'UserFoo'
def test_osbs_builder_nowait(mocker): mocker.patch.object(subprocess, 'check_output') params = {'nowait': True} builder = Builder('osbs', 'tmp', params) assert builder._nowait is True
def test_osbs_builder_custom_commit_msg(mocker): mocker.patch.object(subprocess, 'check_output') params = {'stage': True, 'commit_msg': 'foo'} builder = Builder('osbs', 'tmp', params) assert builder._commit_msg == 'foo'
def test_osbs_builder_use_rhpkg_staget(mocker): mocker.patch.object(subprocess, 'check_output') params = {'stage': True, 'redhat': True} builder = Builder('osbs', 'tmp', params) assert builder._rhpkg == 'rhpkg-stage'
def test_osbs_builder_defaults(mocker): mocker.patch.object(subprocess, 'check_output') builder = Builder('osbs', 'tmp', {}) assert builder._release is False assert builder._rhpkg == 'fedpkg' assert builder._nowait is False
def test_merge_container_yaml_limit_arch(mocker, tmpdir): mocker.patch.object(glob, 'glob', return_value=True) mocker.patch.object(subprocess, 'check_output') builder = Builder('osbs', 'tmp', {}) builder.dist_git_dir = str(tmpdir.mkdir('target')) container_yaml_f = 'container.yaml' source = 'souce_cont.yaml' with open(source, 'w') as file_: yaml.dump({'tags': ['foo']}, file_) builder._merge_container_yaml(source, container_yaml_f) with open(container_yaml_f, 'r') as file_: container_yaml = yaml.safe_load(file_) os.remove(container_yaml_f) assert 'x86_64' in container_yaml['platforms']['only'] assert len(container_yaml['platforms']['only']) == 1
def test_docker_builder_defaults(): params = {'tags': ['foo', 'bar']} builder = Builder('docker', 'tmp', params) assert builder._tags == ['foo', 'bar']
def test_osbs_builder_redhat(mocker): mocker.patch.object(subprocess, 'check_output') builder = Builder('osbs', 'tmp', {'redhat': True}) assert builder._rhpkg == 'rhpkg'
def run(self): try: self.configure() generator = self.generator # Now we can fetch repositories of modules (we have all overrides) get_dependencies(generator.image, os.path.join(self.args.target, 'repo')) # We have all overrided repo fetch so we can discover modules # and process its dependency trees discover_modules(os.path.join(self.args.target, 'repo')) generator.prepare_modules() if self.args.build_tech_preview: generator.generate_tech_preview() # if tags are not specified on command line we take them from image descriptor if not self.args.tags: self.args.tags = generator.get_tags() # we run generate for build command too if set(['generate', 'build']).intersection(set(self.args.commands)): generator.prepare_repositories() generator.image.remove_none_keys() generator.prepare_artifacts() generator.image.write( os.path.join(self.args.target, 'image.yaml')) generator.render_dockerfile() if 'build' in self.args.commands: params = { 'user': self.args.build_osbs_user, 'nowait': self.args.build_osbs_nowait, 'stage': self.args.build_osbs_stage, 'release': self.args.build_osbs_release, 'tags': self.args.tags, 'pull': self.args.build_pull, 'redhat': config.get('common', 'redhat'), 'target': self.args.build_osbs_target, 'commit_msg': self.args.build_osbs_commit_msg } builder = Builder(self.args.build_engine, self.args.target, params) builder.prepare(generator.image) builder.build() if 'test' in self.args.commands: test_tags = [generator.get_tags()[0]] # if wip is specifed set tags to @wip if self.args.test_wip: test_tags = ['@wip'] # at first we collect tests tc = TestCollector(os.path.dirname(self.args.descriptor), self.args.target) # we run the test only if we collect any if tc.collect(generator.image.get('schema_version'), self.args.test_steps_url): runner = TestRunner(self.args.target) runner.run(self.args.tags[0], test_tags, test_names=self.args.test_names) else: logger.warning("No test collected, test can't be run.") logger.info("Finished!") sys.exit(0) except KeyboardInterrupt as e: pass except CekitError as e: if self.args.verbose: logger.exception(e) else: logger.error(e.message) sys.exit(1)
def run(self): if self.args.verbose: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) logger.debug("Running version %s", version) if 'dev' in version: logger.warning("You are running unreleased development version of Cekit, " "use it only at your own risk!") try: tools.cfg = tools.get_cfg(self.args.config) tools.cleanup(self.args.target) if self.args.redhat: tools.cfg['common']['redhat'] = True if self.args.work_dir: tools.cfg['common']['work_dir'] = self.args.work_dir # We need to construct Generator first, because we need overrides # merged in params = {'redhat': tools.cfg['common']['redhat']} generator = Generator(self.args.descriptor, self.args.target, self.args.build_engine, self.args.overrides, params) # Now we can fetch repositories of modules (we have all overrides) get_dependencies(generator.image, os.path.join(self.args.target, 'repo')) # We have all overrided repo fetch so we can discover modules # and process its dependency trees discover_modules(os.path.join(self.args.target, 'repo')) # we run generate for every possible command if self.args.commands: generator.prepare_modules() generator.prepare_repositories() generator.prepare_artifacts() if self.args.build_tech_preview: generator.generate_tech_preview() generator.image.write(os.path.join(self.args.target, 'image.yaml')) generator.render_dockerfile() # if tags are not specified on command line we take them from image descriptor if not self.args.tags: self.args.tags = generator.get_tags() if 'build' in self.args.commands: params = {'user': self.args.build_osbs_user, 'nowait': self.args.build_osbs_nowait, 'stage': self.args.build_osbs_stage, 'release': self.args.build_osbs_release, 'tags': self.args.tags, 'pull': self.args.build_pull, 'redhat': tools.cfg['common']['redhat'], 'target': self.args.build_osbs_target } builder = Builder(self.args.build_engine, self.args.target, params) builder.prepare(generator.image) builder.build() if 'test' in self.args.commands: test_tags = [generator.get_tags()[0]] # if wip is specifed set tags to @wip if self.args.test_wip: test_tags = ['@wip'] # at first we collect tests tc = TestCollector(os.path.dirname(self.args.descriptor), self.args.target) # we run the test only if we collect any if tc.collect(generator.image.get('schema_version'), self.args.test_steps_url): runner = TestRunner(self.args.target) runner.run(self.args.tags[0], test_tags) else: logger.warning("No test collected, test can't be run.") logger.info("Finished!") sys.exit(0) except KeyboardInterrupt as e: pass except CekitError as e: if self.args.verbose: logger.exception(e) else: logger.error(str(e)) sys.exit(1)