initial support for tag extra options

tag_extra table in schema
report tag extras in taginfo and buildconfig
This commit is contained in:
Mike McLean 2015-06-04 12:05:57 -04:00
parent 22f720f085
commit ba7eb75886
2 changed files with 56 additions and 19 deletions

View file

@ -371,6 +371,22 @@ CREATE TABLE tag_config (
UNIQUE (tag_id,active)
) WITHOUT OIDS;
CREATE TABLE tag_extra (
tag_id INTEGER NOT NULL REFERENCES tag(id),
key TEXT NOT NULL,
value TEXT NOT NULL, -- TODO - move this to jsonb when we can
-- versioned - see desc above
create_event INTEGER NOT NULL REFERENCES events(id) DEFAULT get_event(),
revoke_event INTEGER REFERENCES events(id),
creator_id INTEGER NOT NULL REFERENCES users(id),
revoker_id INTEGER REFERENCES users(id),
active BOOLEAN DEFAULT 'true' CHECK (active),
CONSTRAINT active_revoke_sane CHECK (
(active IS NULL AND revoke_event IS NOT NULL AND revoker_id IS NOT NULL)
OR (active IS NOT NULL AND revoke_event IS NULL AND revoker_id IS NULL)),
PRIMARY KEY (create_event, tag_id, key),
UNIQUE (tag_id, key, active)
) WITHOUT OIDS;
-- the tag_updates table provides a mechanism to indicate changes relevant to tag
-- that are not reflected in a versioned table. For example: builds changing volumes,

View file

@ -2761,14 +2761,15 @@ def get_tag(tagInfo, strict=False, event=None):
a string (the tag name) or an int (the tag ID).
Returns a map containing the following keys:
- id
- name
- perm_id (may be null)
- perm (name, may be null)
- arches (may be null)
- locked
- maven_support
- maven_include_all
- id : unique id for the tag
- name : name of the tag
- perm_id : permission id (may be null)
- perm : permission name (may be null)
- arches : tag arches (string, may be null)
- locked : lock setting (boolean)
- maven_support : maven support flag (boolean)
- maven_include_all : maven include all flag (boolean)
- extra : extra tag parameters (dictionary)
If there is no tag matching the given tagInfo, and strict is False,
return None. If strict is True, raise a GenericError.
@ -2807,8 +2808,28 @@ def get_tag(tagInfo, strict=False, event=None):
if strict:
raise koji.GenericError, "Invalid tagInfo: %r" % tagInfo
return None
result['extra'] = get_tag_extra(result)
return result
def get_tag_extra(tagInfo, event=None):
""" Get tag extra info (no inheritance) """
tables = ['tag_extra']
fields = ['key', 'value']
clauses = [eventCondition(event, table='tag_extra'), "tag_id = %(id)i"]
query = QueryProcessor(columns=fields, tables=tables, clauses=clauses, values=tagInfo,
opts={'asList': True})
result = {}
for key, value in query.execute():
try:
value = simplejson.loads(value)
except Exception:
# this should not happen
raise koji.GenericError("Invalid tag extra data: %s : %r", key, value)
result[key] = value
return result
def edit_tag(tagInfo, **kwargs):
"""Edit information for an existing tag.
@ -8755,17 +8776,17 @@ class RootExports(object):
def getBuildConfig(self,tag,event=None):
"""Return build configuration associated with a tag"""
taginfo = get_tag(tag,strict=True,event=event)
arches = taginfo['arches']
if arches is None:
#follow inheritance for arches
order = readFullInheritance(taginfo['id'],event=event)
for link in order:
if link['noconfig']:
continue
arches = get_tag(link['parent_id'],strict=True,event=event)['arches']
if arches is not None:
taginfo['arches'] = arches
break
order = readFullInheritance(taginfo['id'], event=event)
#follow inheritance for arches and extra
for link in order:
if link['noconfig']:
continue
ancestor = get_tag(link['parent_id'], strict=True, event=event)
if taginfo['arches'] is None and ancestor['arches'] is not None:
taginfo['arches'] = ancestor['arches']
for key in ancestor['extra']:
if key not in taginfo['extra']:
taginfo['extra'][key] = ancestor['extra'][key]
return taginfo
def getRepo(self,tag,state=None,event=None):