[PATCH] [WOK] Update Wok messages codes.

From: Paulo Vital <pvital@linux.vnet.ibm.com> Changed the error and warning messages in Wok from the format KCHXXX0000{E,W} to WOKXXX0000{E,W}. Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com> --- plugins/kimchi/tests/test_exception.py | 8 +++---- plugins/kimchi/tests/utils.py | 2 +- plugins/kimchi/utils.py | 2 +- src/wok/asynctask.py | 4 ++-- src/wok/auth.py | 10 ++++---- src/wok/control/base.py | 12 +++++----- src/wok/control/utils.py | 6 ++--- src/wok/i18n.py | 44 +++++++++++++++++----------------- src/wok/objectstore.py | 4 ++-- src/wok/root.py | 2 +- src/wok/utils.py | 20 ++++++++-------- 11 files changed, 57 insertions(+), 57 deletions(-) diff --git a/plugins/kimchi/tests/test_exception.py b/plugins/kimchi/tests/test_exception.py index 2b89adb..4459aa6 100644 --- a/plugins/kimchi/tests/test_exception.py +++ b/plugins/kimchi/tests/test_exception.py @@ -63,7 +63,7 @@ class ExceptionTests(unittest.TestCase): # test 405 wrong method resp = json.loads(request(host, ssl_port, '/', None, 'DELETE').read()) - msg = u'KCHAPI0002E: Delete is not allowed for wokroot' + msg = u'WOKAPI0002E: Delete is not allowed for wokroot' self.assertEquals('405 Method Not Allowed', resp.get('code')) self.assertEquals(msg, resp.get('reason')) @@ -71,7 +71,7 @@ class ExceptionTests(unittest.TestCase): resp = json.loads( request(host, ssl_port, '/plugins/kimchi/vms', '{', 'POST').read() ) - msg = u'KCHAPI0006E: Unable to parse JSON request' + msg = u'WOKAPI0006E: Unable to parse JSON request' self.assertEquals('400 Bad Request', resp.get('code')) self.assertEquals(msg, resp.get('reason')) self.assertNotIn('call_stack', resp) @@ -99,7 +99,7 @@ class ExceptionTests(unittest.TestCase): # test 405 wrong method resp = json.loads(request(host, ssl_port, '/', None, 'DELETE').read()) - msg = u'KCHAPI0002E: Delete is not allowed for wokroot' + msg = u'WOKAPI0002E: Delete is not allowed for wokroot' self.assertEquals('405 Method Not Allowed', resp.get('code')) self.assertEquals(msg, resp.get('reason')) @@ -107,7 +107,7 @@ class ExceptionTests(unittest.TestCase): resp = json.loads( request(host, ssl_port, '/plugins/kimchi/vms', '{', 'POST').read() ) - msg = u'KCHAPI0006E: Unable to parse JSON request' + msg = u'WOKAPI0006E: Unable to parse JSON request' self.assertEquals('400 Bad Request', resp.get('code')) self.assertEquals(msg, resp.get('reason')) self.assertIn('call_stack', resp) diff --git a/plugins/kimchi/tests/utils.py b/plugins/kimchi/tests/utils.py index f80b14f..ecaa87f 100644 --- a/plugins/kimchi/tests/utils.py +++ b/plugins/kimchi/tests/utils.py @@ -205,7 +205,7 @@ class FakeUser(User): try: return mockmodel.fake_user[username] == password except KeyError, e: - raise OperationFailed("KCHAUTH0001E", {'username': 'username', + raise OperationFailed("WOKAUTH0001E", {'username': 'username', 'code': e.message}) diff --git a/plugins/kimchi/utils.py b/plugins/kimchi/utils.py index 92ca83a..2480362 100644 --- a/plugins/kimchi/utils.py +++ b/plugins/kimchi/utils.py @@ -27,7 +27,7 @@ def _uri_to_name(collection, uri): expr = '/plugins/kimchi/%s/(.*?)$' % collection m = re.match(expr, uri) if not m: - raise InvalidParameter("KCHUTILS0001E", {'uri': uri}) + raise InvalidParameter("WOKUTILS0001E", {'uri': uri}) return m.group(1) diff --git a/src/wok/asynctask.py b/src/wok/asynctask.py index 1e0ec4b..e3e10d5 100644 --- a/src/wok/asynctask.py +++ b/src/wok/asynctask.py @@ -28,7 +28,7 @@ from wok.exception import OperationFailed class AsyncTask(object): def __init__(self, id, target_uri, fn, objstore, opaque=None): if objstore is None: - raise OperationFailed("KCHASYNC0001E") + raise OperationFailed("WOKASYNC0001E") self.id = str(id) self.target_uri = target_uri @@ -62,7 +62,7 @@ class AsyncTask(object): with self.objstore as session: session.store('task', self.id, obj) except Exception as e: - raise OperationFailed('KCHASYNC0002E', {'err': e.message}) + raise OperationFailed('WOKASYNC0002E', {'err': e.message}) def _run_helper(self, opaque, cb): cherrypy.serving.request = self._cp_request diff --git a/src/wok/auth.py b/src/wok/auth.py index cc470b6..6ae8bfc 100644 --- a/src/wok/auth.py +++ b/src/wok/auth.py @@ -179,7 +179,7 @@ class PAMUser(User): if result.value != 0: msg_args = {'username': username, 'code': result.value} - raise OperationFailed("KCHAUTH0001E", msg_args) + raise OperationFailed("WOKAUTH0001E", msg_args) return True @@ -217,14 +217,14 @@ class LDAPUser(User): return True except ldap.INVALID_CREDENTIALS: # invalid user password - raise OperationFailed("KCHAUTH0002E") + raise OperationFailed("WOKAUTH0002E") except ldap.NO_SUCH_OBJECT: # ldap search base specified wrongly. - raise OperationFailed("KCHAUTH0005E", {"item": 'ldap_search_base', + raise OperationFailed("WOKAUTH0005E", {"item": 'ldap_search_base', "value": ldap_search_base}) except ldap.LDAPError, e: arg = {"username": username, "code": e.message} - raise OperationFailed("KCHAUTH0001E", arg) + raise OperationFailed("WOKAUTH0001E", arg) def get_groups(self): return self.user[USER_GROUPS] @@ -348,5 +348,5 @@ def wokauth(): if not from_browser(): cherrypy.response.headers['WWW-Authenticate'] = 'Basic realm=wok' - e = InvalidOperation('KCHAUTH0002E') + e = InvalidOperation('WOKAUTH0002E') raise cherrypy.HTTPError(401, e.message.encode('utf-8')) diff --git a/src/wok/control/base.py b/src/wok/control/base.py index 5242f51..f2ad552 100644 --- a/src/wok/control/base.py +++ b/src/wok/control/base.py @@ -102,7 +102,7 @@ class Resource(object): try: self.lookup() if not self.is_authorized(): - raise UnauthorizedError('KCHAPI0009E') + raise UnauthorizedError('WOKAPI0009E') model_args = list(self.model_args) if action_args is not None: @@ -147,7 +147,7 @@ class Resource(object): fn(*self.model_args) cherrypy.response.status = 204 except AttributeError: - e = InvalidOperation('KCHAPI0002E', {'resource': + e = InvalidOperation('WOKAPI0002E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) except OperationFailed, e: @@ -163,7 +163,7 @@ class Resource(object): try: self.lookup() if not self.is_authorized(): - raise UnauthorizedError('KCHAPI0009E') + raise UnauthorizedError('WOKAPI0009E') return {'GET': self.get, 'DELETE': self.delete, @@ -198,7 +198,7 @@ class Resource(object): try: update = getattr(self.model, model_fn(self, 'update')) except AttributeError: - e = InvalidOperation('KCHAPI0003E', {'resource': + e = InvalidOperation('WOKAPI0003E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) @@ -253,7 +253,7 @@ class Collection(object): try: create = getattr(self.model, model_fn(self, 'create')) except AttributeError: - e = InvalidOperation('KCHAPI0005E', {'resource': + e = InvalidOperation('WOKAPI0005E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) @@ -353,7 +353,7 @@ class AsyncCollection(Collection): try: create = getattr(self.model, model_fn(self, 'create')) except AttributeError: - e = InvalidOperation('KCHAPI0005E', {'resource': + e = InvalidOperation('WOKAPI0005E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) diff --git a/src/wok/control/utils.py b/src/wok/control/utils.py index 496320c..56f9e7f 100644 --- a/src/wok/control/utils.py +++ b/src/wok/control/utils.py @@ -79,12 +79,12 @@ def parse_request(): try: return json.loads(rawbody) except ValueError: - e = OperationFailed('KCHAPI0006E') + e = OperationFailed('WOKAPI0006E') raise cherrypy.HTTPError(400, e.message) elif mime_in_header('Content-Type', 'multipart/form-data'): return cherrypy.request.params else: - e = OperationFailed('KCHAPI0007E') + e = OperationFailed('WOKAPI0007E') raise cherrypy.HTTPError(415, e.message) @@ -111,7 +111,7 @@ def validate_params(params, instance, action): raise InvalidParameter(e.schema['error'], {'value': str(e.instance)}) else: - raise InvalidParameter("KCHAPI0008E", {"err": str(e.message)}) + raise InvalidParameter("WOKAPI0008E", {"err": str(e.message)}) class UrlSubNode(object): diff --git a/src/wok/i18n.py b/src/wok/i18n.py index 1556e37..43a1edf 100644 --- a/src/wok/i18n.py +++ b/src/wok/i18n.py @@ -23,26 +23,26 @@ _ = gettext.gettext messages = { - "KCHAPI0002E": _("Delete is not allowed for %(resource)s"), - "KCHAPI0003E": _("%(resource)s does not implement update method"), - "KCHAPI0005E": _("Create is not allowed for %(resource)s"), - "KCHAPI0006E": _("Unable to parse JSON request"), - "KCHAPI0007E": _("This API only supports JSON"), - "KCHAPI0008E": _("Parameters does not match requirement in schema: %(err)s"), - "KCHAPI0009E": _("You don't have permission to perform this operation."), - - "KCHASYNC0001E": _("Datastore is not initiated in the model object."), - "KCHASYNC0002E": _("Unable to start task due error: %(err)s"), - - "KCHAUTH0001E": _("Authentication failed for user '%(username)s'. [Error code: %(code)s]"), - "KCHAUTH0002E": _("You are not authorized to access Kimchi"), - "KCHAUTH0003E": _("Specify %(item)s to login into Kimchi"), - "KCHAUTH0005E": _("Invalid LDAP configuration: %(item)s : %(value)s"), - - "KCHOBJST0001E": _("Unable to find %(item)s in datastore"), - - "KCHUTILS0001E": _("Invalid URI %(uri)s"), - "KCHUTILS0002E": _("Timeout while running command '%(cmd)s' after %(seconds)s seconds"), - "KCHUTILS0004E": _("Invalid data value '%(value)s'"), - "KCHUTILS0005E": _("Invalid data unit '%(unit)s'"), + "WOKAPI0002E": _("Delete is not allowed for %(resource)s"), + "WOKAPI0003E": _("%(resource)s does not implement update method"), + "WOKAPI0005E": _("Create is not allowed for %(resource)s"), + "WOKAPI0006E": _("Unable to parse JSON request"), + "WOKAPI0007E": _("This API only supports JSON"), + "WOKAPI0008E": _("Parameters does not match requirement in schema: %(err)s"), + "WOKAPI0009E": _("You don't have permission to perform this operation."), + + "WOKASYNC0001E": _("Datastore is not initiated in the model object."), + "WOKASYNC0002E": _("Unable to start task due error: %(err)s"), + + "WOKAUTH0001E": _("Authentication failed for user '%(username)s'. [Error code: %(code)s]"), + "WOKAUTH0002E": _("You are not authorized to access Kimchi"), + "WOKAUTH0003E": _("Specify %(item)s to login into Kimchi"), + "WOKAUTH0005E": _("Invalid LDAP configuration: %(item)s : %(value)s"), + + "WOKOBJST0001E": _("Unable to find %(item)s in datastore"), + + "WOKUTILS0001E": _("Invalid URI %(uri)s"), + "WOKUTILS0002E": _("Timeout while running command '%(cmd)s' after %(seconds)s seconds"), + "WOKUTILS0004E": _("Invalid data value '%(value)s'"), + "WOKUTILS0005E": _("Invalid data unit '%(unit)s'"), } diff --git a/src/wok/objectstore.py b/src/wok/objectstore.py index 107b568..aa2a21c 100644 --- a/src/wok/objectstore.py +++ b/src/wok/objectstore.py @@ -58,7 +58,7 @@ class ObjectStoreSession(object): jsonstr = res.fetchall()[0][0] except IndexError: self.conn.rollback() - raise NotFoundError("KCHOBJST0001E", {'item': ident}) + raise NotFoundError("WOKOBJST0001E", {'item': ident}) return json.loads(jsonstr) def delete(self, obj_type, ident, ignore_missing=False): @@ -67,7 +67,7 @@ class ObjectStoreSession(object): (obj_type, ident)) if c.rowcount != 1 and not ignore_missing: self.conn.rollback() - raise NotFoundError("KCHOBJST0001E", {'item': ident}) + raise NotFoundError("WOKOBJST0001E", {'item': ident}) self.conn.commit() def store(self, obj_type, ident, data): diff --git a/src/wok/root.py b/src/wok/root.py index 3a86a74..4262bd0 100644 --- a/src/wok/root.py +++ b/src/wok/root.py @@ -132,7 +132,7 @@ class WokRoot(Root): username = params['username'] password = params['password'] except KeyError, item: - e = MissingParameter('KCHAUTH0003E', {'item': str(item)}) + e = MissingParameter('WOKAUTH0003E', {'item': str(item)}) raise cherrypy.HTTPError(400, e.message) try: diff --git a/src/wok/utils.py b/src/wok/utils.py index 8d51f22..1970e1f 100644 --- a/src/wok/utils.py +++ b/src/wok/utils.py @@ -202,7 +202,7 @@ def run_command(cmd, timeout=None): wok_log.error(msg) msg_args = {'cmd': " ".join(cmd), 'seconds': str(timeout)} - raise TimeoutExpired("KCHUTILS0002E", msg_args) + raise TimeoutExpired("WOKUTILS0002E", msg_args) return out, error, proc.returncode except TimeoutExpired: @@ -295,10 +295,10 @@ def validate_repo_url(url): if url_parts[0] in ['http', 'https', 'ftp']: if not check_url_path(url): - raise InvalidParameter("KCHUTILS0001E", {'uri': url}) + raise InvalidParameter("WOKUTILS0001E", {'uri': url}) elif url_parts[0] == 'file': if not os.path.exists(url_parts[1]): - raise InvalidParameter("KCHUTILS0001E", {'uri': url}) + raise InvalidParameter("WOKUTILS0001E", {'uri': url}) else: raise InvalidParameter("KCHREPOS0002E") @@ -466,9 +466,9 @@ def convert_data_size(value, from_unit, to_unit='B'): DEFAULT_SUFFIX = 'B' if not from_unit: - raise InvalidParameter('KCHUTILS0005E', {'unit': from_unit}) + raise InvalidParameter('WOKUTILS0005E', {'unit': from_unit}) if not to_unit: - raise InvalidParameter('KCHUTILS0005E', {'unit': to_unit}) + raise InvalidParameter('WOKUTILS0005E', {'unit': to_unit}) # set the default suffix if from_unit[-1] not in SUFFIXES_WITH_MULT: @@ -486,15 +486,15 @@ def convert_data_size(value, from_unit, to_unit='B'): try: value = float(value) except TypeError: - raise InvalidParameter('KCHUTILS0004E', {'value': value}) + raise InvalidParameter('WOKUTILS0004E', {'value': value}) if from_p != '' and from_p not in (SI_PREFIXES + IEC_PREFIXES): - raise InvalidParameter('KCHUTILS0005E', {'unit': from_unit}) + raise InvalidParameter('WOKUTILS0005E', {'unit': from_unit}) if from_s not in SUFFIXES_WITH_MULT: - raise InvalidParameter('KCHUTILS0005E', {'unit': from_unit}) + raise InvalidParameter('WOKUTILS0005E', {'unit': from_unit}) if to_p != '' and to_p not in (SI_PREFIXES + IEC_PREFIXES): - raise InvalidParameter('KCHUTILS0005E', {'unit': to_unit}) + raise InvalidParameter('WOKUTILS0005E', {'unit': to_unit}) if to_s not in SUFFIXES_WITH_MULT: - raise InvalidParameter('KCHUTILS0005E', {'unit': to_unit}) + raise InvalidParameter('WOKUTILS0005E', {'unit': to_unit}) # if the units are the same, return the input value if from_unit == to_unit: -- 2.4.3
participants (2)
-
Aline Manera
-
pvital@linux.vnet.ibm.com