Implement import content generator output into koji

This commit prepares a directory with outputs that will be uploaded to
koji (just the mmd file for now). It also adjusts koji_import to call
CGImport with the metadata and the directory to import the results.

Last step will be to call this method at the end of successful module
build
This commit is contained in:
Stanislav Ochotnicky
2017-05-04 10:31:26 +02:00
parent bb464b80b2
commit 9127687fee
2 changed files with 41 additions and 2 deletions

View File

@@ -23,9 +23,13 @@
import calendar
import logging
import platform
import hashlib
import logging
import json
import os
import platform
import shutil
import tempfile
import koji
@@ -164,7 +168,34 @@ class KojiContentGenerator(object):
return ret
def _prepare_file_directory(self):
""" Creates a temporary directory that will contain all the files
mentioned in the outputs section
Returns path to the temporary directory
"""
prepdir = tempfile.mkdtemp(prefix="koji-cg-import")
mmd_path = os.path.join(prepdir, "modulemd.yaml")
with open(mmd_path, "w") as mmd_f:
mmd_f.write(self.mmd)
return prepdir
def koji_import(self):
"""This method imports given module into the configured koji instance as
a content generator based build
Raises an exception when error is encountered during import"""
session = KojiModuleBuilder.get_session(self.config, self.owner)
metadata = self._get_content_generator_metadata()
file_dir = self._prepare_file_directory()
try:
build_info = session.CGImport(metadata, file_dir)
log.debug("Content generator import done: %s",
json.dumps(build_info, sort_keys=True, indent=4))
except Exception, e:
log.error("Content generator import failed: %s", e)
raise e
finally:
shutil.rmtree(file_dir)

View File

@@ -74,6 +74,7 @@ class TestBuild(unittest.TestCase):
@patch("platform.machine")
@patch("module_build_service.builder.KojiContentGenerator.KojiContentGenerator._koji_rpms_in_tag")
def test_get_generator_json(self, rpms_in_tag, machine, distro, pkg_res):
""" Test generation of content generator json """
self.maxDiff = None
distro.return_value = ("Fedora", "25", "Twenty Five")
machine.return_value = "i686"
@@ -93,3 +94,10 @@ class TestBuild(unittest.TestCase):
ret = self.cg._get_content_generator_metadata()
rpms_in_tag.assert_called_once()
self.assertEqual(expected_output, ret)
def test_prepare_file_directory(self):
""" Test preparation of directory with output files """
dir_path = self.cg._prepare_file_directory()
with open(path.join(dir_path, "modulemd.yaml")) as mmd:
self.assertEqual(len(mmd.read()), 1134)