Simplify format_mmd since scm.commit is always set or returns an exception

This commit is contained in:
mprahl
2019-04-30 09:49:02 -04:00
parent f4dd91e9ec
commit 37e4c718d9
4 changed files with 32 additions and 11 deletions

View File

@@ -145,18 +145,13 @@ def format_mmd(mmd, scmurl, module=None, session=None):
# If module build was submitted via yaml file, there is no scmurl
if scmurl:
scm = SCM(scmurl)
# If a commit hash is provided, add that information to the modulemd
if scm.commit:
# We want to make sure we have the full commit hash for consistency
if SCM.is_full_commit_hash(scm.scheme, scm.commit):
full_scm_hash = scm.commit
else:
full_scm_hash = scm.get_full_commit_hash()
xmd["mbs"]["commit"] = full_scm_hash
# If a commit hash wasn't provided then just get the latest from master
# We want to make sure we have the full commit hash for consistency
if SCM.is_full_commit_hash(scm.scheme, scm.commit):
full_scm_hash = scm.commit
else:
xmd["mbs"]["commit"] = scm.get_latest()
full_scm_hash = scm.get_full_commit_hash()
xmd["mbs"]["commit"] = full_scm_hash
if mmd.get_rpm_components() or mmd.get_module_components():
if "rpms" not in xmd["mbs"]:

View File

@@ -28,6 +28,7 @@ from os.path import dirname
from shutil import copyfile
from datetime import datetime, timedelta
from random import randint
import hashlib
from module_build_service.utils import to_text_type
import module_build_service.messaging
@@ -73,6 +74,8 @@ class FakeSCM(object):
self.mocked_scm.return_value.repository_root = "https://src.stg.fedoraproject.org/modules/"
self.mocked_scm.return_value.sourcedir = self.sourcedir
self.mocked_scm.return_value.get_module_yaml = self.get_module_yaml
self.mocked_scm.return_value.is_full_commit_hash.return_value = commit and len(commit) == 40
self.mocked_scm.return_value.get_full_commit_hash.return_value = self.get_full_commit_hash
def checkout(self, temp_dir):
self.sourcedir = path.join(temp_dir, self.name)
@@ -89,6 +92,12 @@ class FakeSCM(object):
def get_module_yaml(self):
return path.join(self.sourcedir, self.name + ".yaml")
def get_full_commit_hash(self, commit_hash=None):
if not commit_hash:
commit_hash = self.commit
sha1_hash = hashlib.sha1("random").hexdigest()
return commit_hash + sha1_hash[len(commit_hash):]
class FakeModuleBuilder(GenericBuilder):
"""

View File

@@ -20,6 +20,7 @@
import io
import tempfile
import hashlib
from os import path, mkdir
from shutil import copyfile, rmtree
from datetime import datetime
@@ -67,6 +68,8 @@ class FakeSCM(object):
self.mocked_scm.return_value.repository_root = "https://src.stg.fedoraproject.org/modules/"
self.mocked_scm.return_value.sourcedir = self.sourcedir
self.mocked_scm.return_value.get_module_yaml = self.get_module_yaml
self.mocked_scm.return_value.is_full_commit_hash.return_value = commit and len(commit) == 40
self.mocked_scm.return_value.get_full_commit_hash.return_value = self.get_full_commit_hash
def checkout(self, temp_dir):
self.sourcedir = path.join(temp_dir, self.name)
@@ -83,6 +86,12 @@ class FakeSCM(object):
def get_module_yaml(self):
return path.join(self.sourcedir, self.name + ".yaml")
def get_full_commit_hash(self, commit_hash=None):
if not commit_hash:
commit_hash = self.commit
sha1_hash = hashlib.sha1("random").hexdigest()
return commit_hash + sha1_hash[len(commit_hash):]
class TestUtilsComponentReuse:
def setup_method(self, test_method):

View File

@@ -102,6 +102,8 @@ class FakeSCM(object):
self.mocked_scm.return_value.branch = branch
self.mocked_scm.return_value.sourcedir = self.sourcedir
self.mocked_scm.return_value.get_module_yaml = self.get_module_yaml
self.mocked_scm.return_value.is_full_commit_hash.return_value = commit and len(commit) == 40
self.mocked_scm.return_value.get_full_commit_hash.return_value = self.get_full_commit_hash
def checkout(self, temp_dir):
try:
@@ -124,6 +126,12 @@ class FakeSCM(object):
def get_module_yaml(self):
return path.join(self.sourcedir, self.name + ".yaml")
def get_full_commit_hash(self, commit_hash=None):
if not commit_hash:
commit_hash = self.commit
sha1_hash = hashlib.sha1("random").hexdigest()
return commit_hash + sha1_hash[len(commit_hash):]
class TestViews:
def setup_method(self, test_method):