Moved default parameters from code to config file

The following parameters are configured via stackalytics.conf:
 * default_metric
 * default_project_type
 * default_release (latest from default_data if None)

Implements blueprint: move-defaults-to-config

Change-Id: Ie3cacb9594f86401afa8b9a60621712b72fbf002
This commit is contained in:
Ilya Shakhat
2014-04-14 17:53:45 +04:00
parent 4e2726b27c
commit eb3bebbaa6
5 changed files with 38 additions and 10 deletions

View File

@@ -14,8 +14,10 @@
# limitations under the License. # limitations under the License.
import flask import flask
from oslo.config import cfg
from six.moves.urllib import parse from six.moves.urllib import parse
from dashboard import vault
from stackalytics.openstack.common import log as logging from stackalytics.openstack.common import log as logging
@@ -23,9 +25,6 @@ LOG = logging.getLogger(__name__)
DEFAULTS = { DEFAULTS = {
'metric': 'commits',
'release': 'icehouse',
'project_type': 'openstack',
'review_nth': 5, 'review_nth': 5,
} }
@@ -33,7 +32,6 @@ METRIC_LABELS = {
'loc': 'Lines of code', 'loc': 'Lines of code',
'commits': 'Commits', 'commits': 'Commits',
'marks': 'Reviews', 'marks': 'Reviews',
'tm_marks': 'Top Mentors',
'emails': 'Emails', 'emails': 'Emails',
'bpd': 'Drafted Blueprints', 'bpd': 'Drafted Blueprints',
'bpc': 'Completed Blueprints', 'bpc': 'Completed Blueprints',
@@ -43,7 +41,6 @@ METRIC_TO_RECORD_TYPE = {
'loc': 'commit', 'loc': 'commit',
'commits': 'commit', 'commits': 'commit',
'marks': 'mark', 'marks': 'mark',
'tm_marks': 'mark',
'emails': 'email', 'emails': 'email',
'bpd': 'bpd', 'bpd': 'bpd',
'bpc': 'bpc', 'bpc': 'bpc',
@@ -54,6 +51,19 @@ DEFAULT_STATIC_ACTIVITY_SIZE = 100
def get_default(param_name): def get_default(param_name):
if 'release' not in DEFAULTS:
release = cfg.CONF.default_release
if not release:
runtime_storage_inst = vault.get_vault()['runtime_storage']
releases = runtime_storage_inst.get_by_key('releases')
if releases:
release = releases[-1]['release_name']
else:
release = 'all'
DEFAULTS['release'] = release.lower()
DEFAULTS['metric'] = cfg.CONF.default_metric.lower()
DEFAULTS['project_type'] = cfg.CONF.default_project_type.lower()
if param_name in DEFAULTS: if param_name in DEFAULTS:
return DEFAULTS[param_name] return DEFAULTS[param_name]
else: else:

View File

@@ -37,3 +37,12 @@
# The address of file with list of programs # The address of file with list of programs
# program_list_uri = https://raw.github.com/openstack/governance/master/reference/programs.yaml # program_list_uri = https://raw.github.com/openstack/governance/master/reference/programs.yaml
# Default metric
# default_metric = marks
# Default release, the most recent if not set
# default_release =
# Default project type
# default_project_type = openstack

View File

@@ -46,4 +46,10 @@ OPTS = [
default=('https://raw.github.com/openstack/governance/' default=('https://raw.github.com/openstack/governance/'
'master/reference/programs.yaml'), 'master/reference/programs.yaml'),
help='The address of file with list of programs'), help='The address of file with list of programs'),
cfg.StrOpt('default-metric', default='marks',
help='Default metric'),
cfg.StrOpt('default-release',
help='Default release, the most recent if not set'),
cfg.StrOpt('default-project-type', default='openstack',
help='Default project type'),
] ]

View File

@@ -37,7 +37,8 @@ class TestAPIModules(test_api.TestAPI):
test_api.make_records(record_type=['commit'], test_api.make_records(record_type=['commit'],
module=['glance', 'nova', 'nova-cli'])): module=['glance', 'nova', 'nova-cli'])):
response = self.app.get('/api/1.0/modules?project_type=all') response = self.app.get('/api/1.0/modules?'
'project_type=all&metric=commits')
modules = json.loads(response.data)['modules'] modules = json.loads(response.data)['modules']
self.assertEqual( self.assertEqual(
[{'id': 'glance', 'text': 'glance', 'tag': 'module'}, [{'id': 'glance', 'text': 'glance', 'tag': 'module'},
@@ -50,7 +51,7 @@ class TestAPIModules(test_api.TestAPI):
'project type') 'project type')
response = self.app.get('/api/1.0/modules?module=nova-group&' response = self.app.get('/api/1.0/modules?module=nova-group&'
'project_type=integrated') 'project_type=integrated&metric=commits')
modules = json.loads(response.data)['modules'] modules = json.loads(response.data)['modules']
self.assertEqual( self.assertEqual(
[{'id': 'glance', 'text': 'glance', 'tag': 'module'}, [{'id': 'glance', 'text': 'glance', 'tag': 'module'},
@@ -61,7 +62,7 @@ class TestAPIModules(test_api.TestAPI):
'project type') 'project type')
response = self.app.get('/api/1.0/modules?query=glance&' response = self.app.get('/api/1.0/modules?query=glance&'
'project_type=all') 'project_type=all&metric=commits')
modules = json.loads(response.data)['modules'] modules = json.loads(response.data)['modules']
self.assertEqual( self.assertEqual(
[{'id': 'glance', 'text': 'glance', 'tag': 'module'}], [{'id': 'glance', 'text': 'glance', 'tag': 'module'}],

View File

@@ -34,7 +34,8 @@ class TestAPIUsers(test_api.TestAPI):
'modules': ['nova', 'glance']}]}, 'modules': ['nova', 'glance']}]},
test_api.make_records(record_type=['commit'], module=['nova'], test_api.make_records(record_type=['commit'], module=['nova'],
user_id=['john_doe', 'bill_smith'])): user_id=['john_doe', 'bill_smith'])):
response = self.app.get('/api/1.0/users?module=nova') response = self.app.get('/api/1.0/users?'
'module=nova&metric=commits')
users = json.loads(response.data)['users'] users = json.loads(response.data)['users']
self.assertEqual(2, len(users)) self.assertEqual(2, len(users))
self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users)
@@ -49,7 +50,8 @@ class TestAPIUsers(test_api.TestAPI):
'modules': ['nova', 'glance']}]}, 'modules': ['nova', 'glance']}]},
test_api.make_records(record_type=['commit'], module=['nova'], test_api.make_records(record_type=['commit'], module=['nova'],
user_name=['John Doe', 'Bill Smith'])): user_name=['John Doe', 'Bill Smith'])):
response = self.app.get('/api/1.0/users?module=nova&query=doe') response = self.app.get('/api/1.0/users?'
'module=nova&query=doe&metric=commits')
users = json.loads(response.data)['users'] users = json.loads(response.data)['users']
self.assertEqual(1, len(users)) self.assertEqual(1, len(users))
self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users)