Fix #467 - Inject modules.yaml to mock repository

This commit is contained in:
Jan Kaluza
2017-03-30 17:58:55 +02:00
parent c5f9d713cc
commit 47c4363601

View File

@@ -47,6 +47,7 @@ import xmlrpclib
import shutil import shutil
import subprocess import subprocess
import threading import threading
import yaml
import munch import munch
from OpenSSL.SSL import SysCallError from OpenSSL.SSL import SysCallError
@@ -1288,14 +1289,24 @@ mdpolicy=group:primary
""" """
log.debug("Creating repository in %s" % self.resultsdir) log.debug("Creating repository in %s" % self.resultsdir)
path = self.resultsdir path = self.resultsdir
if os.path.exists(path + '/repodata/repomd.xml'): repodata_path = os.path.join(path, "repodata")
comm = ['/usr/bin/createrepo_c', '--update', path]
else: # Remove old repodata files
comm = ['/usr/bin/createrepo_c', path] if os.path.exists(repodata_path):
cmd = subprocess.Popen( for name in os.listdir(repodata_path):
comm, stdout=subprocess.PIPE, stderr=subprocess.PIPE) os.remove(os.path.join(repodata_path, name))
out, err = cmd.communicate()
return out, err # Generate the mmd the same way as pungi does.
m1 = ModuleBuild.query.filter(ModuleBuild.name == self.module_str).one()
modules = {"modules": []}
modules["modules"].append(yaml.safe_load(m1.mmd().dumps()))
mmd_path = os.path.join(path, "modules.yaml")
with open(mmd_path, "w") as outfile:
outfile.write(yaml.safe_dump(modules))
# Generate repo and inject modules.yaml there.
_execute_cmd(['/usr/bin/createrepo_c', path])
_execute_cmd(['/usr/bin/modifyrepo_c', '--mdtype=modules', mmd_path, repodata_path])
def _add_repo(self, name, baseurl, extra = ""): def _add_repo(self, name, baseurl, extra = ""):
""" """