From 1e492091129ff06126f826297c9c3b9f092e95cb Mon Sep 17 00:00:00 2001 From: Qixiang Wan Date: Jun 24 2019 03:14:55 +0000 Subject: Also get builds in 'garbage' state while checking existing builds While checking the existing modules builds, we need to check the garbaged builds as well, as these builds can be added in koji inheritance and then be garbaged in MBS, if we only check the 'ready' builds, these garbaged builds in tag inheritance will not be removed and can result in conflict. --- diff --git a/tests/test_add_tag_handler.py b/tests/test_add_tag_handler.py index d093d07..38148eb 100644 --- a/tests/test_add_tag_handler.py +++ b/tests/test_add_tag_handler.py @@ -30,7 +30,7 @@ import tempfile from argparse import Namespace from tests import UrsaMajorTestCase, MockResponse, make_mmd -from ursa_major import ModuleConfig, MBS_BUILD_READY_STATE +from ursa_major import ModuleConfig, MBS_BUILD_STATES from ursa_major.handlers.add_tag import ModuleInfo, AddTagHandler from ursa_major.mbs import MBS @@ -154,7 +154,7 @@ class TestAddTagHandler(AddTagHandlerTestCase): ci_message = json.dumps(dict( id=123, - state=MBS_BUILD_READY_STATE, + state=MBS_BUILD_STATES['ready'], state_name='ready', koji_tag='module-123456' )) @@ -219,7 +219,7 @@ class TestAddTagHandler(AddTagHandlerTestCase): def test_skip_module(self, log): ci_message = json.dumps(dict( id=123, - state=MBS_BUILD_READY_STATE, + state=MBS_BUILD_STATES['ready'], state_name='ready', koji_tag='module-d243299e85d7e9aa' )) diff --git a/ursa_major/__init__.py b/ursa_major/__init__.py index 7da77a7..94fa7c0 100644 --- a/ursa_major/__init__.py +++ b/ursa_major/__init__.py @@ -21,7 +21,16 @@ # # Written by Chenxiong Qi -MBS_BUILD_READY_STATE = 5 +# Copied from MBS code +MBS_BUILD_STATES = { + "init": 0, + "wait": 1, + "build": 2, + "done": 3, + "failed": 4, + "ready": 5, + "garbage": 6, +} class ModuleConfigCmp(object): diff --git a/ursa_major/handlers/add_module.py b/ursa_major/handlers/add_module.py index 39275ad..33e5aed 100644 --- a/ursa_major/handlers/add_module.py +++ b/ursa_major/handlers/add_module.py @@ -23,7 +23,7 @@ # Qixiang Wan from ursa_major.handlers.base import BaseHandler -from ursa_major import ModuleConfig, ModuleConfigCmp, MBS_BUILD_READY_STATE +from ursa_major import ModuleConfig, ModuleConfigCmp, MBS_BUILD_STATES from ursa_major.logger import log @@ -289,7 +289,7 @@ class AddModuleHandler(BaseHandler): requires=module_config.requires, name=module_config.name, stream=module_config.stream, - state=MBS_BUILD_READY_STATE, + state=MBS_BUILD_STATES['ready'], page=1) # we only need the default first page items if modules: return modules[0]['koji_tag'] diff --git a/ursa_major/handlers/base.py b/ursa_major/handlers/base.py index df81acc..cdd64bd 100644 --- a/ursa_major/handlers/base.py +++ b/ursa_major/handlers/base.py @@ -27,7 +27,7 @@ import json from ursa_major.koji_service import KojiService from ursa_major.logger import log from ursa_major.mbs import MBS -from ursa_major import MBS_BUILD_READY_STATE +from ursa_major import MBS_BUILD_STATES class BaseHandler(object): @@ -118,6 +118,6 @@ class BaseHandler(object): modules = self.mbs.get_modules( name=module_config.name, stream=module_config.stream, - state=MBS_BUILD_READY_STATE) + state=[MBS_BUILD_STATES['ready'], MBS_BUILD_STATES['garbage']]) tags_from_mbs = set(module['koji_tag'] for module in modules) return list(set(tags_from_koji) & set(tags_from_mbs)) diff --git a/ursa_major/handlers/check_config.py b/ursa_major/handlers/check_config.py index 52399ec..77387f1 100644 --- a/ursa_major/handlers/check_config.py +++ b/ursa_major/handlers/check_config.py @@ -26,7 +26,7 @@ import six import sys import json -from ursa_major import MBS_BUILD_READY_STATE +from ursa_major import MBS_BUILD_STATES from ursa_major.handlers.base import BaseHandler from ursa_major.logger import log @@ -116,7 +116,7 @@ class CheckConfigHandler(BaseHandler): buildrequires=module_config.get('buildrequires'), name=module_config['name'], stream=module_config['stream'], - state=MBS_BUILD_READY_STATE, + state=MBS_BUILD_STATES['ready'], page=1, # we only need the default first page items ) @@ -124,7 +124,16 @@ class CheckConfigHandler(BaseHandler): log.error("Can't find ready modules in MBS with config: %s", module_config) continue - module_tags = [m['koji_tag'] for m in modules_of_config] + # checking existing NAME+STREAM modules, don't include criteria + # of requires or buildrequires, and not limit to ready modules as + # some old tags may be garbaged + existing_modules = self.mbs.get_modules( + name=module_config['name'], + stream=module_config['stream'], + state=[MBS_BUILD_STATES['ready'], MBS_BUILD_STATES['garbage']] + ) + module_tags = [m['koji_tag'] for m in existing_modules] + non_priorities = [t['priority'] for t in tag_inheritance if t['name'] not in module_tags] if module_config['priority'] in non_priorities: