mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 11:48:33 +08:00
Don't run KojiModuleBuilder.buildroot_connect in the stale module builds poller
This commit is contained in:
@@ -486,21 +486,34 @@ chmod 644 %buildroot/%_sysconfdir/rpm/macros.zz-modules
|
||||
:param artifacts: a list of NVRs to untag
|
||||
:return: None
|
||||
"""
|
||||
dest_tag = self._get_tag(self.module_tag)['id']
|
||||
build_tag = self._get_tag(self.module_build_tag)['id']
|
||||
build_tag_name = self.tag_name + '-build'
|
||||
dest_tag = self._get_tag(self.tag_name, strict=False)
|
||||
build_tag = self._get_tag(build_tag_name, strict=False)
|
||||
# Get the NVRs in the tags to make sure the builds exist and they're tagged before
|
||||
# untagging them
|
||||
dest_tagged_nvrs = self._get_tagged_nvrs(self.module_tag['name'])
|
||||
build_tagged_nvrs = self._get_tagged_nvrs(self.module_build_tag['name'])
|
||||
if dest_tag:
|
||||
dest_tagged_nvrs = self._get_tagged_nvrs(dest_tag['name'])
|
||||
else:
|
||||
log.info('The tag "{0}" doesn\'t exist'.format(self.tag_name))
|
||||
dest_tagged_nvrs = []
|
||||
if build_tag:
|
||||
build_tagged_nvrs = self._get_tagged_nvrs(build_tag['name'])
|
||||
else:
|
||||
log.info('The tag "{0}" doesn\'t exist'.format(build_tag_name))
|
||||
build_tagged_nvrs = []
|
||||
|
||||
# If there is nothing to untag, then just return
|
||||
if not dest_tagged_nvrs and not build_tagged_nvrs:
|
||||
return
|
||||
|
||||
self.koji_session.multicall = True
|
||||
for nvr in artifacts:
|
||||
if nvr in dest_tagged_nvrs:
|
||||
log.info("%r untagging %r from %r" % (self, nvr, dest_tag))
|
||||
self.koji_session.untagBuild(dest_tag, nvr)
|
||||
log.info("%r untagging %r from %r" % (self, nvr, dest_tag['id']))
|
||||
self.koji_session.untagBuild(dest_tag['id'], nvr)
|
||||
if nvr in build_tagged_nvrs:
|
||||
log.info("%r untagging %r from %r" % (self, nvr, build_tag))
|
||||
self.koji_session.untagBuild(build_tag, nvr)
|
||||
log.info("%r untagging %r from %r" % (self, nvr, build_tag['id']))
|
||||
self.koji_session.untagBuild(build_tag['id'], nvr)
|
||||
self.koji_session.multiCall(strict=True)
|
||||
|
||||
def wait_task(self, task_id):
|
||||
|
||||
@@ -124,7 +124,7 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
|
||||
raise ValueError("Builder backend='%s' not recognized" % backend)
|
||||
|
||||
@classmethod
|
||||
def create_from_module(cls, session, module, config, proxy_user=True):
|
||||
def create_from_module(cls, session, module, config, proxy_user=True, buildroot_connect=True):
|
||||
"""
|
||||
Creates new GenericBuilder instance based on the data from module
|
||||
and config and connects it to buildroot.
|
||||
@@ -132,7 +132,10 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
|
||||
:param session: SQLAlchemy databa session.
|
||||
:param module: module_build_service.models.ModuleBuild instance.
|
||||
:param config: module_build_service.config.Config instance.
|
||||
:param proxy_user: a boolean that determines if the Koji session should use the module
|
||||
:kwarg proxy_user: a boolean that determines if the builder should use the module owner as
|
||||
a proxy user.
|
||||
:kwarg buildroot_connect: a boolean that determines if the builder should run
|
||||
buildroot_connect on instantiation.
|
||||
owner as a proxy user.
|
||||
"""
|
||||
owner = None
|
||||
@@ -142,7 +145,8 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
|
||||
builder = GenericBuilder.create(
|
||||
owner, module, config.system, config, tag_name=module.koji_tag, components=components)
|
||||
groups = GenericBuilder.default_buildroot_groups(session, module)
|
||||
builder.buildroot_connect(groups)
|
||||
if buildroot_connect is True:
|
||||
builder.buildroot_connect(groups)
|
||||
return builder
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -161,8 +161,9 @@ class MBSProducer(PollingProducer):
|
||||
# If there are no completed artifacts, then there is nothing to tag
|
||||
if artifacts:
|
||||
# Set proxy_user=False to not authenticate as the module owner for these tasks
|
||||
# Set buildroot_connect=False so it doesn't recreate the Koji target and etc.
|
||||
builder = GenericBuilder.create_from_module(
|
||||
session, module, conf, proxy_user=False)
|
||||
session, module, conf, proxy_user=False, buildroot_connect=False)
|
||||
builder.untag_artifacts([c.nvr for c in artifacts])
|
||||
# Mark the artifacts as untagged in the database
|
||||
for c in artifacts:
|
||||
|
||||
@@ -243,6 +243,26 @@ class TestKojiBuilder(unittest.TestCase):
|
||||
builder.koji_session.tagBuild.assert_called_once_with(
|
||||
builder.module_tag["id"], "new-1.0-1.module_e0095747")
|
||||
|
||||
@patch.object(FakeKojiModuleBuilder, 'get_session')
|
||||
@patch.object(FakeKojiModuleBuilder, '_get_tagged_nvrs')
|
||||
def test_untagged_artifacts(self, mock_get_tagged_nvrs, mock_get_session):
|
||||
"""
|
||||
Tests that only tagged artifacts will be untagged
|
||||
"""
|
||||
mock_session = mock.Mock()
|
||||
mock_session.getTag.side_effect = [
|
||||
{'name': 'foobar', 'id': 1}, {'name': 'foobar-build', 'id': 2}]
|
||||
mock_get_session.return_value = mock_session
|
||||
mock_get_tagged_nvrs.side_effect = [['foo', 'bar'], ['foo']]
|
||||
builder = FakeKojiModuleBuilder(
|
||||
owner=self.module.owner, module=self.module, config=conf, tag_name='module-foo',
|
||||
components=[])
|
||||
|
||||
builder.untag_artifacts(['foo', 'bar'])
|
||||
self.assertEqual(mock_session.untagBuild.call_count, 3)
|
||||
expected_calls = [mock.call(1, 'foo'), mock.call(2, 'foo'), mock.call(1, 'bar')]
|
||||
self.assertEqual(mock_session.untagBuild.mock_calls, expected_calls)
|
||||
|
||||
@patch('module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session')
|
||||
def test_get_build_weights(self, get_session):
|
||||
session = MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user