Merge pull request #1327 from jberry-suse/conf-allow-arbitrary-project

osclib/conf: order config defaults by priority and allow devel projects to utilize.
This commit is contained in:
Jimmy Berry 2018-01-09 16:12:11 -06:00 committed by GitHub
commit 2b037a0b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -15,6 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from collections import OrderedDict
import io import io
import os import os
import operator import operator
@ -108,6 +109,26 @@ DEFAULT = {
'remote-config': False, 'remote-config': False,
'delreq-review': None, 'delreq-review': None,
'main-repo': 'standard', 'main-repo': 'standard',
'priority': 100, # Lower than SLE-15 since less specific.
},
# Allows devel projects to utilize tools that require config, but not
# complete StagingAPI support.
r'(?P<project>.*$)': {
'staging': '%(project)s', # Allows for dashboard/config if desired.
'staging-group': None,
'staging-archs': '',
'staging-dvd-archs': '',
'rings': None,
'nonfree': None,
'rebuild': None,
'product': None,
'openqa': None,
'lock': None,
'lock-ns': None,
'delreq-review': None,
'main-repo': 'openSUSE_Factory',
'remote-config': False,
'priority': 1000, # Lowest priority as only a fallback.
}, },
} }
@ -144,7 +165,8 @@ class Config(object):
def populate_conf(self): def populate_conf(self):
"""Add sane default into the configuration.""" """Add sane default into the configuration."""
defaults = {} defaults = {}
for prj_pattern in DEFAULT: default_ordered = OrderedDict(sorted(DEFAULT.items(), key=lambda i: i[1].get('priority', 99)))
for prj_pattern in default_ordered:
match = re.match(prj_pattern, self.project) match = re.match(prj_pattern, self.project)
if match: if match:
project = match.group('project') project = match.group('project')

View File

@ -1,5 +1,6 @@
import unittest import unittest
from osc import conf from osc import conf
from osclib.conf import DEFAULT
from osclib.conf import Config from osclib.conf import Config
from osclib.stagingapi import StagingAPI from osclib.stagingapi import StagingAPI
@ -32,3 +33,25 @@ class TestConfig(unittest.TestCase):
self.config.apply_remote(self.api) self.config.apply_remote(self.api)
# Ensure blank file not overridden. # Ensure blank file not overridden.
self.assertEqual(self.obs.dashboard_counts['config'], 1) self.assertEqual(self.obs.dashboard_counts['config'], 1)
def test_pattern_order(self):
# Add pattern to defaults in order to identify which was matched.
for pattern in DEFAULT:
DEFAULT[pattern]['pattern'] = pattern
# A list of projects that should match each of the DEFAULT patterns.
projects = (
'openSUSE:Factory',
'openSUSE:Leap:15.0',
'SUSE:SLE-15:GA',
'SUSE:SLE-12:GA',
'GNOME:Factory',
)
# Ensure each pattern is match instead of catch-all pattern.
patterns = set()
for project in projects:
config = Config(project)
patterns.add(conf.config[project]['pattern'])
self.assertEqual(len(patterns), len(DEFAULT))