diff --git a/module_build_service/builder/KojiContentGenerator.py b/module_build_service/builder/KojiContentGenerator.py index 079c766b..caabe857 100644 --- a/module_build_service/builder/KojiContentGenerator.py +++ b/module_build_service/builder/KojiContentGenerator.py @@ -32,6 +32,7 @@ import platform import shutil import subprocess import tempfile +import time import koji @@ -273,7 +274,7 @@ class KojiContentGenerator(object): u'filesize': len(self.mmd), u'checksum_type': u'md5', u'checksum': unicode(hashlib.md5(self.mmd).hexdigest()), - u'filename': u'modulemd.yaml', + u'filename': u'modulemd.txt', u'components': components } ) @@ -317,7 +318,7 @@ class KojiContentGenerator(object): Returns path to the temporary directory """ prepdir = tempfile.mkdtemp(prefix="koji-cg-import") - mmd_path = os.path.join(prepdir, "modulemd.yaml") + mmd_path = os.path.join(prepdir, "modulemd.txt") log.info("Writing modulemd.yaml to %r" % mmd_path) with open(mmd_path, "w") as mmd_f: mmd_f.write(self.mmd) @@ -331,6 +332,32 @@ class KojiContentGenerator(object): log.exception(e) return prepdir + def _upload_outputs(self, session, metadata, file_dir): + """ + Uploads output files to Koji hub. + """ + to_upload = [] + for info in metadata['output']: + if info.get('metadata_only', False): + continue + localpath = os.path.join(file_dir, info['filename']) + if not os.path.exists(localpath): + err = "Cannot upload %s to Koji. No such file." % localpath + log.error(err) + raise RuntimeError(err) + + to_upload.append([localpath, info]) + + # Create unique server directory. + serverdir = 'mbs/%r.%d' % (time.time(), self.module.id) + + for localpath, info in to_upload: + log.info("Uploading %s to Koji" % localpath) + session.uploadWrapper(localpath, serverdir, callback=None) + log.info("Upload of %s to Koji done" % localpath) + + return serverdir + def koji_import(self): """This method imports given module into the configured koji instance as a content generator based build @@ -341,7 +368,8 @@ class KojiContentGenerator(object): file_dir = self._prepare_file_directory() metadata = self._get_content_generator_metadata(file_dir) try: - build_info = session.CGImport(metadata, file_dir) + serverdir = self._upload_outputs(session, metadata, file_dir) + build_info = session.CGImport(metadata, serverdir) log.info("Content generator import done.") log.debug(json.dumps(build_info, sort_keys=True, indent=4)) diff --git a/tests/test_content_generator.py b/tests/test_content_generator.py index c811c596..a139fcdc 100644 --- a/tests/test_content_generator.py +++ b/tests/test_content_generator.py @@ -149,5 +149,5 @@ class TestBuild(unittest.TestCase): 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: + with open(path.join(dir_path, "modulemd.txt")) as mmd: self.assertEqual(len(mmd.read()), 1134) diff --git a/tests/test_get_generator_json_expected_output.json b/tests/test_get_generator_json_expected_output.json index de3aa3f8..2628ff04 100644 --- a/tests/test_get_generator_json_expected_output.json +++ b/tests/test_get_generator_json_expected_output.json @@ -44,7 +44,7 @@ }], "output": [ { - "filename": "modulemd.yaml", + "filename": "modulemd.txt", "buildroot_id": 1, "components": [ { diff --git a/tests/test_get_generator_json_expected_output_with_log.json b/tests/test_get_generator_json_expected_output_with_log.json index d5a16c73..1756b0e3 100644 --- a/tests/test_get_generator_json_expected_output_with_log.json +++ b/tests/test_get_generator_json_expected_output_with_log.json @@ -44,7 +44,7 @@ }], "output": [ { - "filename": "modulemd.yaml", + "filename": "modulemd.txt", "buildroot_id": 1, "components": [ {