提交 33a3322a 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!117 针对数据库初始化配置文件格式或内容错误时,命令行中提示信息的修改

Merge pull request !117 from gongzhengtang/master
...@@ -188,12 +188,12 @@ class TableColView(Resource): ...@@ -188,12 +188,12 @@ class TableColView(Resource):
('version', 'Version', True), ('version', 'Version', True),
('release', 'Release', True), ('release', 'Release', True),
('url', 'Url', True), ('url', 'Url', True),
('linense', 'License', False), ('rpm_license', 'License', False),
('feature', 'Feature', False), ('feature', 'Feature', False),
('maintainer', 'Maintainer', True), ('maintainer', 'Maintainer', True),
('maintainlevel', 'Maintenance Level', True), ('maintainlevel', 'Maintenance Level', True),
('release_time', 'Release Time', False), ('release_time', 'Release Time', False),
('end_of_lifecycle', 'End of Life Cycle', True), ('used_time', 'Used Time', True),
('maintainer_status', 'Maintain Status', True), ('maintainer_status', 'Maintain Status', True),
('latest_version', 'Latest Version', False), ('latest_version', 'Latest Version', False),
('latest_version_time', 'Latest Version Release Time', False), ('latest_version_time', 'Latest Version Release Time', False),
......
...@@ -85,16 +85,20 @@ class ResponseCode(): ...@@ -85,16 +85,20 @@ class ResponseCode():
TABLE_NAME_NOT_EXIST_IN_DATABASE: "the table name dose not match the existed database", TABLE_NAME_NOT_EXIST_IN_DATABASE: "the table name dose not match the existed database",
YAML_FILE_ERROR: "Data error in yaml file", YAML_FILE_ERROR: "Data error in yaml file",
EMPTY_FOLDER: "This is an empty folder, no yaml file" EMPTY_FOLDER: "This is an empty folder, no yaml file"
} }
@classmethod @classmethod
def response_json(cls, code, data=None): def response_json(cls, code, data=None, msg=None):
""" """
Description: classmethod Description: classmethod
""" """
try:
_msg = cls.CODE_MSG_MAP[code]
except KeyError:
_msg = msg
return { return {
"code": code, "code": code,
"msg": cls.CODE_MSG_MAP[code], "msg": _msg,
"data": data "data": data
} }
......
...@@ -17,6 +17,7 @@ from packageship.libs.configutils.readconfig import ReadConfig ...@@ -17,6 +17,7 @@ from packageship.libs.configutils.readconfig import ReadConfig
from packageship.libs.exception import Error from packageship.libs.exception import Error
from packageship.libs.exception import ContentNoneException from packageship.libs.exception import ContentNoneException
from packageship.libs.exception import DataMergeException from packageship.libs.exception import DataMergeException
from packageship.libs.exception import ConfigurationException
from packageship.libs.log import Log from packageship.libs.log import Log
from packageship.system_config import DATABASE_FILE_INFO from packageship.system_config import DATABASE_FILE_INFO
from .function.constants import ResponseCode from .function.constants import ResponseCode
...@@ -601,6 +602,10 @@ class InitSystem(Resource): ...@@ -601,6 +602,10 @@ class InitSystem(Resource):
except TypeError as type_error: except TypeError as type_error:
LOGGER.logger.error(type_error) LOGGER.logger.error(type_error)
abnormal = ResponseCode.TYPE_ERROR abnormal = ResponseCode.TYPE_ERROR
except ConfigurationException as error:
LOGGER.logger.error(error)
abnormal = error
return jsonify(ResponseCode.response_json('5000', msg=abnormal.message))
except DataMergeException as data_merge_error: except DataMergeException as data_merge_error:
LOGGER.logger.error(data_merge_error) LOGGER.logger.error(data_merge_error)
abnormal = ResponseCode.DATA_MERGE_ERROR abnormal = ResponseCode.DATA_MERGE_ERROR
......
...@@ -12,6 +12,7 @@ from packageship.libs.dbutils.sqlalchemy_helper import DBHelper ...@@ -12,6 +12,7 @@ from packageship.libs.dbutils.sqlalchemy_helper import DBHelper
from packageship.libs.exception import ContentNoneException from packageship.libs.exception import ContentNoneException
from packageship.libs.exception import DatabaseRepeatException from packageship.libs.exception import DatabaseRepeatException
from packageship.libs.exception import Error from packageship.libs.exception import Error
from packageship.libs.exception import ConfigurationException
from packageship.libs.configutils.readconfig import ReadConfig from packageship.libs.configutils.readconfig import ReadConfig
from packageship.libs.log import Log from packageship.libs.log import Log
from packageship.application.models.package import SrcPack from packageship.application.models.package import SrcPack
...@@ -90,21 +91,25 @@ class InitDataBase(): ...@@ -90,21 +91,25 @@ class InitDataBase():
init_database_config = yaml.load( init_database_config = yaml.load(
file_context.read(), Loader=yaml.FullLoader) file_context.read(), Loader=yaml.FullLoader)
except yaml.YAMLError as yaml_error: except yaml.YAMLError as yaml_error:
raise Error(
'The format of the yaml configuration file is wrong, please check and try again\ raise ConfigurationException(' '.join("The format of the yaml configuration\
:%s' % yaml_error) file is wrong please check and try again:{0}".format(yaml_error).split()))
if init_database_config is None: if init_database_config is None:
raise ContentNoneException( raise ConfigurationException(
'The content of the database initialization configuration file cannot be empty') 'The content of the database initialization configuration file cannot be empty')
if not isinstance(init_database_config, list): if not isinstance(init_database_config, list):
raise TypeError( raise ConfigurationException(
'The format of the initial database configuration file is incorrect:%s' ' '.join('The format of the initial database configuration file\
% self.config_file_path) is incorrect.When multiple databases need to be initialized, \
it needs to be configured in the form of multiple \
nodes:{}'.format(self.config_file_path).split()))
for config_item in init_database_config: for config_item in init_database_config:
if not isinstance(config_item, dict): if not isinstance(config_item, dict):
raise TypeError('The format of the initial database configuration file is \ raise ConfigurationException(' '.join('The format of the initial database\
incorrect:%s' % self.config_file_path) configuration file is incorrect, and the value in a single node should\
be presented in the form of key - val pairs: \
{}'.format(self.config_file_path).split()))
return init_database_config return init_database_config
def init_data(self): def init_data(self):
......
...@@ -7,6 +7,11 @@ from packageship.libs.exception.ext import DatabaseRepeatException ...@@ -7,6 +7,11 @@ from packageship.libs.exception.ext import DatabaseRepeatException
from packageship.libs.exception.ext import DataMergeException from packageship.libs.exception.ext import DataMergeException
from packageship.libs.exception.ext import Error from packageship.libs.exception.ext import Error
from packageship.libs.exception.ext import DbnameNoneException from packageship.libs.exception.ext import DbnameNoneException
from packageship.libs.exception.ext import ConfigurationException
__all__ = ['ContentNoneException', __all__ = ['ContentNoneException',
'DatabaseRepeatException', 'DataMergeException', 'Error', 'DbnameNoneException'] 'DatabaseRepeatException',
'DataMergeException',
'Error',
'DbnameNoneException',
'ConfigurationException']
...@@ -62,3 +62,12 @@ class DataMergeException(Error): ...@@ -62,3 +62,12 @@ class DataMergeException(Error):
def __init__(self, message): def __init__(self, message):
Error.__init__(self, 'DataMerge exception: %r' % (message,)) Error.__init__(self, 'DataMerge exception: %r' % (message,))
class ConfigurationException(Error):
"""
Description: Configuration file exception information
"""
def __init__(self, message):
Error.__init__(self, 'Configuration exception : %r' % (message,))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册