2016-04-21 10:20:31 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-04-06 13:28:33 +00:00
|
|
|
import json
|
2016-04-21 10:20:31 +00:00
|
|
|
import mock
|
|
|
|
import os
|
2017-06-20 14:26:30 +00:00
|
|
|
import re
|
2018-04-06 13:28:33 +00:00
|
|
|
import sys
|
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
|
|
|
from pungi.phases.pkgset.sources import source_koji
|
|
|
|
from tests import helpers
|
2018-03-16 06:15:01 +00:00
|
|
|
from pungi import Modulemd
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
EVENT_INFO = {'id': 15681980, 'ts': 1460956382.81936}
|
|
|
|
TAG_INFO = {
|
|
|
|
"maven_support": False,
|
|
|
|
"locked": False,
|
|
|
|
"name": "f25",
|
|
|
|
"extra": {
|
|
|
|
"mock.package_manager": "dnf"
|
|
|
|
},
|
|
|
|
"perm": None,
|
|
|
|
"id": 335,
|
|
|
|
"arches": None,
|
|
|
|
"maven_include_all": None,
|
|
|
|
"perm_id": None
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetKojiEvent(helpers.PungiTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestGetKojiEvent, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
|
|
|
|
self.event_file = self.topdir + '/work/global/koji-event'
|
|
|
|
|
|
|
|
def test_use_preconfigured_event(self):
|
|
|
|
koji_wrapper = mock.Mock()
|
|
|
|
self.compose.koji_event = 123456
|
|
|
|
self.compose.DEBUG = False
|
|
|
|
|
|
|
|
koji_wrapper.koji_proxy.getEvent.return_value = EVENT_INFO
|
|
|
|
|
|
|
|
event = source_koji.get_koji_event_info(self.compose, koji_wrapper)
|
|
|
|
|
|
|
|
self.assertEqual(event, EVENT_INFO)
|
|
|
|
self.assertItemsEqual(
|
|
|
|
koji_wrapper.mock_calls,
|
|
|
|
[mock.call.koji_proxy.getEvent(123456)])
|
|
|
|
with open(self.event_file) as f:
|
|
|
|
self.assertEqual(json.load(f), EVENT_INFO)
|
|
|
|
|
|
|
|
def test_gets_last_event(self):
|
|
|
|
self.compose.DEBUG = False
|
|
|
|
self.compose.koji_event = None
|
|
|
|
koji_wrapper = mock.Mock()
|
|
|
|
|
|
|
|
koji_wrapper.koji_proxy.getLastEvent.return_value = EVENT_INFO
|
|
|
|
|
|
|
|
event = source_koji.get_koji_event_info(self.compose, koji_wrapper)
|
|
|
|
|
|
|
|
self.assertEqual(event, EVENT_INFO)
|
|
|
|
self.assertItemsEqual(
|
|
|
|
koji_wrapper.mock_calls,
|
|
|
|
[mock.call.koji_proxy.getLastEvent()])
|
|
|
|
with open(self.event_file) as f:
|
|
|
|
self.assertEqual(json.load(f), EVENT_INFO)
|
|
|
|
|
|
|
|
def test_gets_last_event_in_debug_mode(self):
|
|
|
|
self.compose.DEBUG = True
|
|
|
|
self.compose.koji_event = None
|
|
|
|
koji_wrapper = mock.Mock()
|
|
|
|
helpers.touch(self.event_file, json.dumps(EVENT_INFO))
|
|
|
|
|
|
|
|
event = source_koji.get_koji_event_info(self.compose, koji_wrapper)
|
|
|
|
|
|
|
|
self.assertEqual(event, EVENT_INFO)
|
|
|
|
self.assertItemsEqual(koji_wrapper.mock_calls, [])
|
|
|
|
with open(self.event_file) as f:
|
|
|
|
self.assertEqual(json.load(f), EVENT_INFO)
|
|
|
|
|
2017-06-14 12:04:54 +00:00
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
class TestPopulateGlobalPkgset(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestPopulateGlobalPkgset, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'pkgset_koji_tag': 'f25',
|
|
|
|
'sigkeys': mock.Mock(),
|
|
|
|
})
|
|
|
|
self.compose.DEBUG = False
|
|
|
|
self.koji_wrapper = mock.Mock()
|
|
|
|
self.pkgset_path = os.path.join(self.topdir, 'work', 'global', 'pkgset_global.pickle')
|
2018-03-20 09:37:43 +00:00
|
|
|
self.pdc_module_path = os.path.join(self.topdir, 'work', 'global', 'pdc-module-Server.yaml')
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
@mock.patch('six.moves.cPickle.dumps')
|
2016-04-21 10:20:31 +00:00
|
|
|
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
|
|
|
|
def test_populate(self, KojiPackageSet, pickle_dumps):
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
pickle_dumps.return_value = b'DATA'
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
orig_pkgset = KojiPackageSet.return_value
|
|
|
|
|
|
|
|
pkgset = source_koji.populate_global_pkgset(
|
2017-02-28 13:03:36 +00:00
|
|
|
self.compose, self.koji_wrapper, '/prefix', 123456)
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
self.assertIs(pkgset, orig_pkgset)
|
|
|
|
self.assertEqual(
|
|
|
|
pkgset.mock_calls,
|
2017-06-14 12:04:54 +00:00
|
|
|
[mock.call.populate('f25', 123456, inherit=True,
|
|
|
|
logfile=self.topdir + '/logs/global/packages_from_f25.global.log'),
|
2016-04-21 10:20:31 +00:00
|
|
|
mock.call.save_file_list(self.topdir + '/work/global/package_list/global.conf',
|
|
|
|
remove_path_prefix='/prefix')])
|
|
|
|
self.assertItemsEqual(pickle_dumps.call_args_list,
|
|
|
|
[mock.call(orig_pkgset)])
|
|
|
|
with open(self.pkgset_path) as f:
|
|
|
|
self.assertEqual(f.read(), 'DATA')
|
|
|
|
|
2018-03-16 06:15:01 +00:00
|
|
|
@unittest.skipUnless(Modulemd is not None, 'Modulemd not available') # noqa
|
2017-08-30 08:21:41 +00:00
|
|
|
@mock.patch('six.moves.cPickle.dumps')
|
|
|
|
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
|
|
|
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_module')
|
|
|
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_pdc_client_session')
|
2018-03-20 09:37:43 +00:00
|
|
|
def test_pdc_log(self, get_pdc_client_session, get_module, KojiPackageSet, pickle_dumps):
|
2017-08-30 08:21:41 +00:00
|
|
|
|
|
|
|
pickle_dumps.return_value = b'DATA'
|
|
|
|
|
2018-03-20 09:37:43 +00:00
|
|
|
modulemd = """
|
|
|
|
document: modulemd
|
|
|
|
version: 2
|
|
|
|
data:
|
|
|
|
name: foo
|
|
|
|
stream: bar
|
|
|
|
version: 1
|
|
|
|
summary: foo
|
|
|
|
description: foo
|
|
|
|
license:
|
|
|
|
module:
|
|
|
|
- MIT
|
|
|
|
"""
|
|
|
|
|
2018-04-16 12:47:49 +00:00
|
|
|
get_module.return_value = {
|
|
|
|
'abc': 'def',
|
|
|
|
'modulemd': modulemd,
|
|
|
|
'rpms': [],
|
|
|
|
'koji_tag': 'taggg',
|
|
|
|
'uid': 'modulenamefoo:rhel:1:00000000',
|
|
|
|
'name': 'modulenamefoo',
|
|
|
|
'stream': 'rhel',
|
|
|
|
'version': '1',
|
|
|
|
'context': '00000000'
|
|
|
|
}
|
2017-08-30 08:21:41 +00:00
|
|
|
for name, variant in self.compose.variants.items():
|
|
|
|
variant.get_modules = mock.MagicMock()
|
|
|
|
if name == 'Server':
|
2018-03-20 09:37:43 +00:00
|
|
|
variant.modules = [{'name': 'a'}]
|
|
|
|
variant.get_modules.return_value = variant.modules
|
2017-08-30 08:21:41 +00:00
|
|
|
|
|
|
|
source_koji.populate_global_pkgset(
|
|
|
|
self.compose, self.koji_wrapper, '/prefix', 123456)
|
2018-03-20 09:37:43 +00:00
|
|
|
mmds = Modulemd.Module.new_all_from_file(self.pdc_module_path)
|
|
|
|
self.assertEqual(mmds[0].get_name(), "foo")
|
2017-08-30 08:21:41 +00:00
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
@mock.patch('six.moves.cPickle.dumps')
|
2017-06-27 11:48:02 +00:00
|
|
|
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
|
|
|
|
def test_populate_with_multiple_koji_tags(self, KojiPackageSet, pickle_dumps):
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'pkgset_koji_tag': ['f25', 'f25-extra'],
|
|
|
|
'sigkeys': mock.Mock(),
|
|
|
|
})
|
|
|
|
self.compose.DEBUG = False
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
pickle_dumps.return_value = b'DATA'
|
2017-06-27 11:48:02 +00:00
|
|
|
|
|
|
|
orig_pkgset = KojiPackageSet.return_value
|
|
|
|
|
|
|
|
pkgset = source_koji.populate_global_pkgset(
|
|
|
|
self.compose, self.koji_wrapper, '/prefix', 123456)
|
|
|
|
|
|
|
|
self.assertIs(pkgset, orig_pkgset)
|
|
|
|
pkgset.assert_has_calls([mock.call.populate('f25', 123456, inherit=True,
|
|
|
|
logfile=self.topdir + '/logs/global/packages_from_f25.global.log')])
|
|
|
|
pkgset.assert_has_calls([mock.call.populate('f25-extra', 123456, inherit=True,
|
|
|
|
logfile=self.topdir + '/logs/global/packages_from_f25-extra.global.log')])
|
|
|
|
pkgset.assert_has_calls([mock.call.save_file_list(self.topdir + '/work/global/package_list/global.conf',
|
|
|
|
remove_path_prefix='/prefix')])
|
2018-03-07 12:59:12 +00:00
|
|
|
# for each tag, call pkgset.fast_merge once for each variant and once for global pkgset
|
|
|
|
self.assertEqual(pkgset.fast_merge.call_count, 2 * (len(self.compose.all_variants.values()) + 1))
|
2017-06-27 11:48:02 +00:00
|
|
|
self.assertItemsEqual(pickle_dumps.call_args_list,
|
|
|
|
[mock.call(orig_pkgset)])
|
|
|
|
with open(self.pkgset_path) as f:
|
|
|
|
self.assertEqual(f.read(), 'DATA')
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
@mock.patch('six.moves.cPickle.load')
|
2016-04-21 10:20:31 +00:00
|
|
|
def test_populate_in_debug_mode(self, pickle_load):
|
|
|
|
helpers.touch(self.pkgset_path, 'DATA')
|
|
|
|
self.compose.DEBUG = True
|
|
|
|
|
|
|
|
pickle_load.return_value
|
|
|
|
|
|
|
|
with mock.patch('pungi.phases.pkgset.sources.source_koji.open',
|
|
|
|
mock.mock_open(), create=True) as m:
|
|
|
|
pkgset = source_koji.populate_global_pkgset(
|
2017-02-28 13:03:36 +00:00
|
|
|
self.compose, self.koji_wrapper, '/prefix', 123456)
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
self.assertEqual(pickle_load.call_args_list,
|
|
|
|
[mock.call(m.return_value)])
|
|
|
|
self.assertIs(pkgset, pickle_load.return_value)
|
|
|
|
self.assertEqual(
|
|
|
|
pkgset.mock_calls,
|
|
|
|
[mock.call.save_file_list(self.topdir + '/work/global/package_list/global.conf',
|
|
|
|
remove_path_prefix='/prefix')])
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
@mock.patch('six.moves.cPickle.dumps')
|
2017-10-16 12:20:37 +00:00
|
|
|
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet.populate')
|
|
|
|
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet.save_file_list')
|
|
|
|
def test_populate_packages_to_gather(self, save_file_list, popuplate,
|
|
|
|
pickle_dumps):
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'gather_method': 'nodeps',
|
|
|
|
'pkgset_koji_tag': 'f25',
|
|
|
|
'sigkeys': mock.Mock(),
|
|
|
|
'additional_packages': [
|
|
|
|
('.*', {'*': ['pkg', 'foo.x86_64']}),
|
|
|
|
]
|
|
|
|
})
|
|
|
|
self.compose.DEBUG = False
|
2017-09-05 08:01:21 +00:00
|
|
|
pickle_dumps.return_value = b'DATA'
|
2017-10-16 12:20:37 +00:00
|
|
|
|
|
|
|
pkgset = source_koji.populate_global_pkgset(
|
|
|
|
self.compose, self.koji_wrapper, '/prefix', 123456)
|
|
|
|
self.assertItemsEqual(pkgset.packages, ["pkg", "foo"])
|
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
class TestGetPackageSetFromKoji(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestGetPackageSetFromKoji, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'pkgset_koji_tag': 'f25',
|
|
|
|
})
|
|
|
|
self.compose.koji_event = None
|
|
|
|
self.compose.DEBUG = False
|
|
|
|
self.koji_wrapper = mock.Mock()
|
|
|
|
self.koji_wrapper.koji_proxy.getLastEvent.return_value = EVENT_INFO
|
|
|
|
self.koji_wrapper.koji_proxy.getTag.return_value = TAG_INFO
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.create_arch_repos')
|
|
|
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.create_global_repo')
|
|
|
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.populate_arch_pkgsets')
|
|
|
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.populate_global_pkgset')
|
|
|
|
def test_get_package_sets(self, pgp, pap, cgr, car):
|
|
|
|
expected = {'x86_64': mock.Mock()}
|
|
|
|
pap.return_value = expected
|
|
|
|
expected['global'] = pgp.return_value
|
|
|
|
|
|
|
|
pkgsets = source_koji.get_pkgset_from_koji(self.compose, self.koji_wrapper, '/prefix')
|
|
|
|
|
|
|
|
self.assertItemsEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2017-02-28 13:03:36 +00:00
|
|
|
[mock.call.getLastEvent()]
|
2016-04-21 10:20:31 +00:00
|
|
|
)
|
2017-02-28 13:03:36 +00:00
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
self.assertEqual(pgp.call_args_list,
|
|
|
|
[mock.call(self.compose, self.koji_wrapper, '/prefix',
|
2017-02-28 13:03:36 +00:00
|
|
|
EVENT_INFO)])
|
2016-04-21 10:20:31 +00:00
|
|
|
self.assertEqual(pap.call_args_list,
|
|
|
|
[mock.call(self.compose, '/prefix', pgp.return_value)])
|
|
|
|
self.assertEqual(cgr.call_args_list,
|
|
|
|
[mock.call(self.compose, '/prefix')])
|
|
|
|
self.assertItemsEqual(car.call_args_list,
|
|
|
|
[mock.call(self.compose, 'x86_64', '/prefix'),
|
|
|
|
mock.call(self.compose, 'amd64', '/prefix')])
|
|
|
|
|
|
|
|
self.assertEqual(pkgsets, expected)
|
|
|
|
|
|
|
|
|
|
|
|
class TestSourceKoji(helpers.PungiTestCase):
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_pkgset_from_koji')
|
|
|
|
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
|
|
|
|
def test_run(self, KojiWrapper, gpfk):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'koji_profile': 'koji'
|
|
|
|
})
|
|
|
|
KojiWrapper.return_value.koji_module.config.topdir = '/prefix'
|
|
|
|
|
|
|
|
phase = source_koji.PkgsetSourceKoji(compose)
|
|
|
|
pkgsets, path_prefix = phase()
|
|
|
|
|
|
|
|
self.assertEqual(pkgsets, gpfk.return_value)
|
|
|
|
self.assertEqual(path_prefix, '/prefix/')
|
|
|
|
self.assertItemsEqual(KojiWrapper.mock_calls,
|
|
|
|
[mock.call('koji')])
|
|
|
|
|
|
|
|
|
2017-06-20 14:26:30 +00:00
|
|
|
class TestCorrectNVR(helpers.PungiTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestCorrectNVR, self).setUp()
|
2017-10-20 08:41:30 +00:00
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
2017-06-20 14:26:30 +00:00
|
|
|
self.nv = "base-runtime-f26"
|
|
|
|
self.nvr = "base-runtime-f26-20170502134116"
|
|
|
|
self.release_regex = re.compile("^(\d){14}$")
|
2017-10-20 08:41:30 +00:00
|
|
|
self.new_nv = "base-runtime:f26"
|
|
|
|
self.new_nvr = "base-runtime:f26:20170502134116"
|
|
|
|
self.new_nvrc = "base-runtime:f26:20170502134116:0123abcd"
|
2017-06-20 14:26:30 +00:00
|
|
|
|
|
|
|
def test_nv(self):
|
2017-10-20 08:41:30 +00:00
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nv)
|
2018-04-16 12:47:49 +00:00
|
|
|
expectedKeys = ["stream", "name"]
|
2017-06-20 14:26:30 +00:00
|
|
|
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
|
|
|
|
|
|
|
def test_nvr(self):
|
2017-10-20 08:41:30 +00:00
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
2018-04-16 12:47:49 +00:00
|
|
|
expectedKeys = ["stream", "name", "version"]
|
2017-06-20 14:26:30 +00:00
|
|
|
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
|
|
|
|
|
|
|
def test_correct_release(self):
|
2017-10-20 08:41:30 +00:00
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
2018-04-16 12:47:49 +00:00
|
|
|
self.assertIsNotNone(self.release_regex.match(module_info["version"]))
|
2017-06-20 14:26:30 +00:00
|
|
|
|
2017-10-20 08:41:30 +00:00
|
|
|
def test_new_nv(self):
|
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nv)
|
|
|
|
expected = {
|
2018-04-16 12:47:49 +00:00
|
|
|
'name': 'base-runtime',
|
|
|
|
'stream': 'f26'}
|
2017-10-20 08:41:30 +00:00
|
|
|
|
|
|
|
self.assertEqual(module_info, expected)
|
|
|
|
|
|
|
|
def test_new_nvr(self):
|
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvr)
|
|
|
|
expected = {
|
2018-04-16 12:47:49 +00:00
|
|
|
'name': 'base-runtime',
|
|
|
|
'stream': 'f26',
|
|
|
|
'version': '20170502134116'}
|
2017-10-20 08:41:30 +00:00
|
|
|
self.assertEqual(module_info, expected)
|
|
|
|
|
|
|
|
def test_new_nvrc(self):
|
|
|
|
self.assertRaises(ValueError, source_koji.variant_dict_from_str,
|
|
|
|
self.compose, self.new_nvrc)
|
2017-06-20 14:26:30 +00:00
|
|
|
|
2018-04-16 12:47:49 +00:00
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|