From c76c5dcf15e0419e6f48855245fbbc12a7401f71 Mon Sep 17 00:00:00 2001 From: Martin Curlej Date: Nov 10 2017 17:33:42 +0000 Subject: mbs-build now builds modules only from yaml files --- diff --git a/module_build_service/config.py b/module_build_service/config.py index 23735a1..70da0db 100644 --- a/module_build_service/config.py +++ b/module_build_service/config.py @@ -60,9 +60,7 @@ def init_config(app): # Load LocalBuildConfiguration section in case we are building modules # locally. - local_build_cmds = ["build_module_locally", "build_module_locally_from_file"] - local = [cmd for cmd in sys.argv if cmd in local_build_cmds] - if local: + if "build_module_locally" in sys.argv: config_section = "LocalBuildConfiguration" # try getting config_file from os.environ diff --git a/module_build_service/scm.py b/module_build_service/scm.py index 896f303..4098197 100644 --- a/module_build_service/scm.py +++ b/module_build_service/scm.py @@ -86,18 +86,8 @@ class SCM(object): self.name = self.name[:-4] self.commit = match.group("commit") self.branch = branch if branch else "master" - self.latest = False - # if not stated otherwise the default behaviour is that we work with - # non-local bare repositories - self.local = False - self.bare_repo = True - if self.repository.startswith("file://") and allow_local: - self.local = True - abs_repo_path = self.repository[7:] - self.bare_repo = self._is_bare_repo(abs_repo_path) if not self.commit: self.commit = self.get_latest(self.branch) - self.latest = True self.version = None else: raise ValidationError("Unhandled SCM scheme: %s" % self.scheme) @@ -180,11 +170,7 @@ class SCM(object): "within the repository. Perhaps you forgot to push. " "The original message was: %s" % e.message) raise - # will patch the temp git repo with uncommited changes only if there - # is no commit repo present in repo definition and its a local dir - # and not a bare repo. - if self.latest and self.local and not self.bare_repo: - self.patch_with_uncommited_changes(self.sourcedir) + timestamp = SCM._run(["git", "show", "-s", "--format=%ct"], chdir=self.sourcedir)[1] dt = datetime.datetime.utcfromtimestamp(int(timestamp)) self.version = dt.strftime("%Y%m%d%H%M%S") @@ -211,12 +197,6 @@ class SCM(object): else: raise RuntimeError("get_latest: Unhandled SCM scheme.") - def _is_bare_repo(self, repo_path): - """ Checks if the repository is a bare repo """ - is_bare_repo_cmd = ["git", "config", "core.bare"] - _, is_bare, _ = SCM._run(is_bare_repo_cmd, chdir=repo_path) - return is_bare.rstrip() == "true" - def get_full_commit_hash(self, commit_hash=None): """ Takes a shortened commit hash and returns the full hash @@ -273,30 +253,6 @@ class SCM(object): "Couldn't access: %s" % path_to_yaml) raise UnprocessableEntity("The SCM repository doesn't contain a modulemd file") - def patch_with_uncommited_changes(self, source_dir): - """ - This method patches the given tmp git repository with uncommented changes from its - origin git dir. Creates a patch file which holds the result for `git diff` command - executed in the origin repo. - - source_dir (str): path to the temp git repo - """ - module_diff = ['git', 'diff'] - # stripping the 'file:// from self.repository' - _, diff, _ = SCM._run(module_diff, chdir=self.repository[7:]) - if diff: - try: - log.debug("Working with local, non-bare repository. Applying uncommited changes.") - patch_file = os.path.join(source_dir, "patch") - with open(patch_file, "w") as fd: - fd.write(diff) - module_patch = ['git', 'apply', 'patch'] - SCM._run(module_patch, chdir=source_dir) - except Exception: - log.exception("Failed to update repo %s with uncommited changes." - % source_dir) - raise - @staticmethod def is_full_commit_hash(scheme, commit): """ diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 31769a7..6387423 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -907,7 +907,7 @@ def record_component_builds(mmd, module, initial_batch=1, return batch -def submit_module_build_from_yaml(username, handle, stream=None, **kwargs): +def submit_module_build_from_yaml(username, handle, stream=None, optional_params=None): yaml = handle.read() mmd = load_mmd(yaml) @@ -923,14 +923,14 @@ def submit_module_build_from_yaml(username, handle, stream=None, **kwargs): mmd.stream = mmd.stream or stream or "master" mmd.version = mmd.version or def_version - return submit_module_build(username, None, mmd, None, yaml, **kwargs) + return submit_module_build(username, None, mmd, None, yaml, optional_params) _url_check_re = re.compile(r"^[^:/]+:.*$") def submit_module_build_from_scm(username, url, branch, allow_local_url=False, - skiptests=False, **kwargs): + skiptests=False, optional_params=None): # Translate local paths into file:// URL if allow_local_url and not _url_check_re.match(url): log.info( @@ -940,14 +940,12 @@ def submit_module_build_from_scm(username, url, branch, allow_local_url=False, mmd, scm = _fetch_mmd(url, branch, allow_local_url) if skiptests: mmd.buildopts.rpms.macros += "\n\n%__spec_check_pre exit 0\n" - return submit_module_build(username, url, mmd, scm, yaml, **kwargs) + return submit_module_build(username, url, mmd, scm, yaml, optional_params) -def submit_module_build(username, url, mmd, scm, optional_params=None): +def submit_module_build(username, url, mmd, scm, yaml, optional_params=None): import koji # Placed here to avoid py2/py3 conflicts... - -def submit_module_build(username, url, mmd, scm, yaml, **kwargs): # Import it here, because SCM uses utils methods # and fails to import them because of dep-chain. validate_mmd(mmd) @@ -992,7 +990,7 @@ def submit_module_build(username, url, mmd, scm, yaml, **kwargs): modulemd=mmd.dumps(), scmurl=url, username=username, - **(kwargs or {}) + **(optional_params or {}) ) db.session.add(module) diff --git a/module_build_service/views.py b/module_build_service/views.py index 48a124e..3c0f2fb 100644 --- a/module_build_service/views.py +++ b/module_build_service/views.py @@ -317,7 +317,8 @@ class SCMHandler(BaseHandler): branch = branch.encode('utf-8') return submit_module_build_from_scm(self.username, url, branch, - allow_local_url=False, **self.optional_params) + allow_local_url=False, + optional_params=self.optional_params) class YAMLFileHandler(BaseHandler): @@ -335,7 +336,8 @@ class YAMLFileHandler(BaseHandler): def post(self): handle = request.files["yaml"] - return submit_module_build_from_yaml(self.username, handle, **self.optional_params) + return submit_module_build_from_yaml(self.username, handle, + optional_params=self.optional_params) def register_api_v1(): diff --git a/tests/test_scm.py b/tests/test_scm.py index a88cb75..2f500a2 100644 --- a/tests/test_scm.py +++ b/tests/test_scm.py @@ -115,8 +115,3 @@ class TestSCMModule(unittest.TestCase): scm.checkout(self.tempdir) scm.verify() scm.get_module_yaml() - - @raises(UnprocessableEntity) - def test_get_latest_incorect_component_branch(self): - scm = module_build_service.scm.SCM(repo_path) - scm.get_latest(branch='foobar')