[Kimchi-devel] [PATCHv6] Fix wrong config param of repository creation

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Mon Sep 29 08:54:07 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Wrong config param for repository creation needs to be rejected,
also fix correspoding testcases.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py         |  1 +
 src/kimchi/repositories.py | 11 ++++++++++-
 tests/test_model.py        | 13 +++++++++++--
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index d402dde..1b543ce 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -288,4 +288,5 @@ messages = {
     "KCHREPOS0025E": _("Unable to retrieve repository information. Details: '%(err)s'"),
     "KCHREPOS0026E": _("Unable to add repository. Details: '%(err)s'"),
     "KCHREPOS0027E": _("Unable to remove repository. Details: '%(err)s'"),
+    "KCHREPOS0028E": _("Configuration items: '%(items)s' are not supported by repository manager"),
 }
diff --git a/src/kimchi/repositories.py b/src/kimchi/repositories.py
index 19edc22..f826ac9 100644
--- a/src/kimchi/repositories.py
+++ b/src/kimchi/repositories.py
@@ -26,7 +26,7 @@ from ConfigParser import ConfigParser
 
 from kimchi.basemodel import Singleton
 from kimchi.config import kimchiLock
-from kimchi.exception import InvalidOperation
+from kimchi.exception import InvalidOperation, InvalidParameter
 from kimchi.exception import OperationFailed, NotFoundError, MissingParameter
 from kimchi.utils import validate_repo_url
 
@@ -52,6 +52,13 @@ class Repositories(object):
         """
         Add and enable a new repository
         """
+        config = params.get('config', {})
+        extra_keys = list(
+            set(config.keys()).difference(set(self._pkg_mnger.CONFIG_ENTRY)))
+        if len(extra_keys) > 0:
+            raise InvalidParameter("KCHREPOS0028E",
+                                   {'items': ",".join(extra_keys)})
+
         return self._pkg_mnger.addRepo(params)
 
     def getRepositories(self):
@@ -105,6 +112,7 @@ class YumRepo(object):
     """
     TYPE = 'yum'
     DEFAULT_CONF_DIR = "/etc/yum.repos.d"
+    CONFIG_ENTRY = ('repo_name', 'mirrorlist')
 
     def __init__(self):
         self._yb = getattr(__import__('yum'), 'YumBase')
@@ -319,6 +327,7 @@ class AptRepo(object):
     """
     TYPE = 'deb'
     KIMCHI_LIST = "kimchi-source.list"
+    CONFIG_ENTRY = ('dist', 'comps')
 
     def __init__(self):
         getattr(__import__('apt_pkg'), 'init_config')()
diff --git a/tests/test_model.py b/tests/test_model.py
index 63032f5..1f2e79c 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -1309,8 +1309,7 @@ class ModelTests(unittest.TestCase):
                       'baseurl': 'http://www.fedora.org'},
                      {'repo_id': 'fedora-updates-fake',
                       'config':
-                      {'mirrorlist': 'http://www.fedoraproject.org',
-                       'gpgkey': 'file:///tmp/KEY-fedora-updates-fake-19'}}]
+                      {'mirrorlist': 'http://www.fedoraproject.org'}}]
 
         deb_repos = [{'baseurl': 'http://archive.ubuntu.com/ubuntu/',
                       'config': {'dist': 'quantal'}},
@@ -1325,12 +1324,22 @@ class ModelTests(unittest.TestCase):
             wrong_mirrorlist = {'repo_id': 'wrong-id',
                                 'baseurl': 'www.example.com',
                                 'config': {'mirrorlist': url}}
+            wrong_config_item = {
+                'repo_id': 'wrong-id',
+                'baseurl': 'www.example.com',
+                'config': {
+                    'gpgkey': 'file:///tmp/KEY-fedora-updates-fake-19'}}
 
             yum_invalid_repos.append(wrong_baseurl)
             yum_invalid_repos.append(wrong_mirrorlist)
+            yum_invalid_repos.append(wrong_config_item)
 
             wrong_baseurl['config'] = {'dist': 'tasty'}
+            wrong_config = {'baseurl': deb_repos[0]['baseurl'],
+                            'config': {
+                                'unsupported_item': "a_unsupported_item"}}
             deb_invalid_repos.append(wrong_baseurl)
+            deb_invalid_repos.append(wrong_config)
 
         repo_type = inst.capabilities_lookup()['repo_mngt_tool']
         if repo_type == 'yum':
-- 
1.8.3.2




More information about the Kimchi-devel mailing list