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:
commit
2b037a0b81
@ -15,6 +15,7 @@
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from ConfigParser import ConfigParser
|
||||
from collections import OrderedDict
|
||||
import io
|
||||
import os
|
||||
import operator
|
||||
@ -108,6 +109,26 @@ DEFAULT = {
|
||||
'remote-config': False,
|
||||
'delreq-review': None,
|
||||
'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):
|
||||
"""Add sane default into the configuration."""
|
||||
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)
|
||||
if match:
|
||||
project = match.group('project')
|
||||
|
@ -1,5 +1,6 @@
|
||||
import unittest
|
||||
from osc import conf
|
||||
from osclib.conf import DEFAULT
|
||||
from osclib.conf import Config
|
||||
from osclib.stagingapi import StagingAPI
|
||||
|
||||
@ -32,3 +33,25 @@ class TestConfig(unittest.TestCase):
|
||||
self.config.apply_remote(self.api)
|
||||
# Ensure blank file not overridden.
|
||||
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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user