Skip to content

Commit

Permalink
Merge pull request #1327 from jberry-suse/conf-allow-arbitrary-project
Browse files Browse the repository at this point in the history
osclib/conf: order config defaults by priority and allow devel projects to utilize.
  • Loading branch information
jberry-suse committed Jan 9, 2018
2 parents 7eaed34 + 61c8350 commit 2b037a0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
24 changes: 23 additions & 1 deletion osclib/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +109,26 @@
'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.
},
}

Expand Down Expand Up @@ -144,7 +165,8 @@ def conf(self):
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')
Expand Down
23 changes: 23 additions & 0 deletions tests/config_tests.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -32,3 +33,25 @@ def test_remote_none(self):
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))

0 comments on commit 2b037a0

Please sign in to comment.