def test_verify_commit_not_in_branch(self): target = "7035bd33614972ac66559ac1fdd019ff6027ad21" scm = module_build_service.common.scm.SCM(repo_url + "?#" + target, "master") scm.checkout(self.tempdir) with pytest.raises(ValidationError): scm.verify()
def test_verify_commit_in_branch(self): target = "7035bd33614972ac66559ac1fdd019ff6027ad21" scm = module_build_service.common.scm.SCM(repo_url + "?#" + target, "dev") scm.checkout(self.tempdir) scm.verify()
def test_get_module_yaml(self): scm = module_build_service.common.scm.SCM(repo_url) scm.checkout(self.tempdir) scm.verify() with pytest.raises(UnprocessableEntity): scm.get_module_yaml()
def test_verify(self): scm = module_build_service.common.scm.SCM(repo_url) scm.checkout(self.tempdir) scm.verify()
def fetch_mmd(url, branch=None, allow_local_url=False, whitelist_url=False, mandatory_checks=True): td = None scm = None try: log.debug("Verifying modulemd") td = tempfile.mkdtemp() if whitelist_url: scm = module_build_service.common.scm.SCM(url, branch, [url], allow_local_url) else: scm = module_build_service.common.scm.SCM(url, branch, conf.scmurls, allow_local_url) scm.checkout(td) if not whitelist_url and mandatory_checks: scm.verify() cofn = scm.get_module_yaml() mmd = load_mmd_file(cofn) finally: try: if td is not None: shutil.rmtree(td) except Exception as e: log.warning("Failed to remove temporary directory {!r}: {}".format( td, str(e))) if conf.check_for_eol: if _is_eol_in_pdc(scm.name, scm.branch): raise ValidationError( "Module {}:{} is marked as EOL in PDC.".format( scm.name, scm.branch)) if not mandatory_checks: return mmd, scm # If the name was set in the modulemd, make sure it matches what the scmurl # says it should be if mmd.get_module_name() and mmd.get_module_name() != scm.name: if not conf.allow_name_override_from_scm: raise ValidationError( 'The name "{0}" that is stored in the modulemd is not valid'. format(mmd.get_module_name())) else: # Set the module name mmd = mmd.copy(scm.name) # If the stream was set in the modulemd, make sure it matches what the repo # branch is if mmd.get_stream_name() and mmd.get_stream_name() != scm.branch: if not conf.allow_stream_override_from_scm: raise ValidationError( 'The stream "{0}" that is stored in the modulemd does not match the branch "{1}"' .format(mmd.get_stream_name(), scm.branch)) else: # Set the module stream mmd = mmd.copy(mmd.get_module_name(), scm.branch) # If the version is in the modulemd, throw an exception since the version # since the version is generated by MBS if mmd.get_version(): raise ValidationError( 'The version "{0}" is already defined in the modulemd but it shouldn\'t be since the ' "version is generated based on the commit time".format( mmd.get_version())) else: mmd.set_version(int(scm.version)) return mmd, scm