>From 1c389b71b5ac220e16c9cb75c78333c1500e4c64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miroslav=20Such=C3=BD?= <msuchy@redhat.com>
Date: Thu, 21 May 2015 11:24:19 +0200
Subject: [PATCH] allow to set DNF or YUM per tag

Yum is default
---
 builder/kojid                    |  3 +++
 docs/schema-upgrade-1.9-1.10.sql |  5 +++++
 docs/schema.sql                  |  1 +
 hub/kojihub.py                   | 18 +++++++++++-------
 koji/__init__.py                 |  5 +++++
 5 files changed, 25 insertions(+), 7 deletions(-)
 create mode 100644 docs/schema-upgrade-1.9-1.10.sql

diff --git a/builder/kojid b/builder/kojid
index dcd0840..559ccd4 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -171,6 +171,7 @@ class BuildRoot(object):
         self.repo_info = self.session.repoInfo(self.repoid, strict=True)
         self.event_id = self.repo_info['create_event']
         self.br_arch = data['arch']
+        self.use_yum = data['use_yum']
         self.name = "%(tag_name)s-%(id)s-%(repoid)s" % vars(self)
         self.config = self.session.getBuildConfig(self.tag_id, event=self.event_id)
 
@@ -192,6 +193,7 @@ class BuildRoot(object):
         if self.config['id'] != repo_info['tag_id']:
             raise koji.BuildrootError, "tag/repo mismatch: %s vs %s" \
                     % (self.config['name'], repo_info['tag_name'])
+        self.use_yum = self.config['use_yum']
         repo_state = koji.REPO_STATES[repo_info['state']]
         if repo_state == 'EXPIRED':
             # This should be ok. Expired repos are still intact, just not
@@ -239,6 +241,7 @@ class BuildRoot(object):
         opts['maven_envs'] = self.maven_envs
         opts['bind_opts'] = self.bind_opts
         opts['target_arch'] = self.target_arch
+        opts['use_yum'] = self.use_yum
         output = koji.genMockConfig(self.name, self.br_arch, managed=True, **opts)
 
         #write config
diff --git a/docs/schema-upgrade-1.9-1.10.sql b/docs/schema-upgrade-1.9-1.10.sql
new file mode 100644
index 0000000..0d3b726
--- /dev/null
+++ b/docs/schema-upgrade-1.9-1.10.sql
@@ -0,0 +1,5 @@
+BEGIN;
+
+ALTER TABLE tag_config ADD COLUMN use_yum BOOLEAN NOT NULL DEFAULT 'true';
+
+COMMIT;
diff --git a/docs/schema.sql b/docs/schema.sql
index 3582b87..6e3618f 100644
--- a/docs/schema.sql
+++ b/docs/schema.sql
@@ -355,6 +355,7 @@ CREATE TABLE tag_config (
 	arches TEXT,
 	perm_id INTEGER REFERENCES permissions(id),
 	locked BOOLEAN NOT NULL DEFAULT 'false',
+    use_yum BOOLEAN NOT NULL DEFAULT 'true',
 	maven_support BOOLEAN NOT NULL DEFAULT FALSE,
 	maven_include_all BOOLEAN NOT NULL DEFAULT FALSE,
 -- versioned - see desc above
diff --git a/hub/kojihub.py b/hub/kojihub.py
index fb0acf4..a2d11e1 100644
--- a/hub/kojihub.py
+++ b/hub/kojihub.py
@@ -1090,10 +1090,10 @@ def list_tags(build=None, package=None, queryOpts=None):
              'LEFT OUTER JOIN permissions ON tag_config.perm_id = permissions.id']
     fields = ['tag.id', 'tag.name', 'tag_config.perm_id', 'permissions.name',
               'tag_config.arches', 'tag_config.locked', 'tag_config.maven_support',
-              'tag_config.maven_include_all']
+              'tag_config.maven_include_all', 'tag_config.use_yum']
     aliases = ['id', 'name', 'perm_id', 'perm',
                'arches', 'locked', 'maven_support',
-               'maven_include_all']
+               'maven_include_all', 'use_yum']
     clauses = ['tag_config.active = true']
 
     if build is not None:
@@ -2716,7 +2716,7 @@ def lookup_build_target(info,strict=False,create=False):
     """Get the id,name for build target"""
     return lookup_name('build_target',info,strict,create)
 
-def create_tag(name, parent=None, arches=None, perm=None, locked=False, maven_support=False, maven_include_all=False):
+def create_tag(name, parent=None, arches=None, perm=None, locked=False, maven_support=False, maven_include_all=False, use_yum=False):
     """Create a new tag"""
 
     context.session.assertPerm('admin')
@@ -2741,7 +2741,8 @@ def create_tag(name, parent=None, arches=None, perm=None, locked=False, maven_su
 
     insert = InsertProcessor('tag_config')
     insert.set(tag_id=tag_id, arches=arches, perm_id=perm, locked=locked)
-    insert.set(maven_support=maven_support, maven_include_all=maven_include_all)
+    insert.set(maven_support=maven_support, maven_include_all=maven_include_all,
+      use_yum=use_yum)
     insert.make_create()
     insert.execute()
 
@@ -2788,7 +2789,8 @@ def get_tag(tagInfo, strict=False, event=None):
               'tag_config.arches': 'arches',
               'tag_config.locked': 'locked',
               'tag_config.maven_support': 'maven_support',
-              'tag_config.maven_include_all': 'maven_include_all'
+              'tag_config.maven_include_all': 'maven_include_all',
+              'tag_config.use_yum': 'use_yum'
              }
     clauses = [eventCondition(event, table='tag_config')]
     if isinstance(tagInfo, int):
@@ -2821,6 +2823,7 @@ def edit_tag(tagInfo, **kwargs):
         maven_support: whether Maven repos should be generated for the tag
         maven_include_all: include every build in this tag (including multiple
                            versions of the same package) in the Maven repo
+        use_yum: boolean if to use Yum. Otherwise DNF is used.
     """
 
     context.session.assertPerm('admin')
@@ -2860,7 +2863,7 @@ def edit_tag(tagInfo, **kwargs):
     #check for changes
     data = tag.copy()
     changed = False
-    for key in ('perm_id','arches','locked','maven_support','maven_include_all'):
+    for key in ('perm_id','arches','locked','maven_support','maven_include_all', 'use_yum'):
         if kwargs.has_key(key) and data[key] != kwargs[key]:
             changed = True
             data[key] = kwargs[key]
@@ -2874,6 +2877,7 @@ def edit_tag(tagInfo, **kwargs):
     insert = InsertProcessor('tag_config', data=dslice(data, ('arches', 'perm_id', 'locked')))
     insert.set(tag_id=data['id'])
     insert.set(**dslice(data, ('maven_support', 'maven_include_all')))
+    insert.set(**dslice(data, ('use_yum')))
     insert.make_create()
     insert.execute()
 
@@ -5457,7 +5461,7 @@ def query_history(tables=None, **kwargs):
         'user_perms' : ['user_id', 'perm_id'],
         'user_groups' : ['user_id', 'group_id'],
         'tag_inheritance' : ['tag_id', 'parent_id', 'priority', 'maxdepth', 'intransitive', 'noconfig', 'pkg_filter'],
-        'tag_config' : ['tag_id', 'arches', 'perm_id', 'locked', 'maven_support', 'maven_include_all'],
+        'tag_config' : ['tag_id', 'arches', 'perm_id', 'locked', 'maven_support', 'maven_include_all', 'use_yum'],
         'build_target_config' : ['build_target_id', 'build_tag', 'dest_tag'],
         'external_repo_config' : ['external_repo_id', 'url'],
         'tag_external_repos' : ['tag_id', 'external_repo_id', 'priority'],
diff --git a/koji/__init__.py b/koji/__init__.py
index c3a0990..a8d7e83 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -1287,6 +1287,11 @@ def genMockConfig(name, arch, managed=False, repoid=None, tag_name=None, **opts)
         'rpmbuild_timeout': opts.get('rpmbuild_timeout', 86400)
     }
 
+    if opts.get('use_yum', True):
+        config_opts['package_manage'] = 'yum'
+    else:
+        config_opts['package_manage'] = 'dnf'
+
     # bind_opts are used to mount parts (or all of) /dev if needed.
     # See kojid::LiveCDTask for a look at this option in action.
     bind_opts = opts.get('bind_opts')
-- 
2.4.0

