mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-05-12 10:57:58 +08:00
Change exception information for errors when parsing modulemd file.
This fixes #1149 Signed-off-by: Valerij Maljulin <vmaljuli@redhat.com>
This commit is contained in:
@@ -699,7 +699,19 @@ def load_mmd(yaml, is_file=False):
|
|||||||
# If the modulemd was v1, it will be upgraded to v2
|
# If the modulemd was v1, it will be upgraded to v2
|
||||||
mmd.upgrade()
|
mmd.upgrade()
|
||||||
except Exception:
|
except Exception:
|
||||||
error = 'The following invalid modulemd was encountered: {0}'.format(yaml)
|
if is_file:
|
||||||
|
error = 'The modulemd {} is invalid. Please verify the syntax is correct'.format(
|
||||||
|
os.path.basename(yaml)
|
||||||
|
)
|
||||||
|
if os.path.exists(yaml):
|
||||||
|
with open(yaml, 'rt') as yaml_hdl:
|
||||||
|
log.debug('Modulemd content:\n%s', yaml_hdl.read())
|
||||||
|
else:
|
||||||
|
error = 'The modulemd file {} not found!'.format(os.path.basename(yaml))
|
||||||
|
log.error('The modulemd file %s not found!', yaml)
|
||||||
|
else:
|
||||||
|
error = 'The modulemd is invalid. Please verify the syntax is correct'
|
||||||
|
log.debug('Modulemd content:\n%s', yaml)
|
||||||
log.exception(error)
|
log.exception(error)
|
||||||
raise UnprocessableEntity(error)
|
raise UnprocessableEntity(error)
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ from requests.utils import quote
|
|||||||
import hashlib
|
import hashlib
|
||||||
import pytest
|
import pytest
|
||||||
from module_build_service.utils import to_text_type
|
from module_build_service.utils import to_text_type
|
||||||
|
import re
|
||||||
|
|
||||||
from tests import app, init_data, clean_database, reuse_component_init_data
|
from tests import app, init_data, clean_database, reuse_component_init_data
|
||||||
from tests import read_staged_data
|
from tests import read_staged_data
|
||||||
@@ -972,7 +973,8 @@ class TestViews:
|
|||||||
{'branch': 'master', 'scmurl': 'https://src.stg.fedoraproject.org/modules/'
|
{'branch': 'master', 'scmurl': 'https://src.stg.fedoraproject.org/modules/'
|
||||||
'testmodule.git?#68931c90de214d9d13feefbd35246a81b6cb8d49'}))
|
'testmodule.git?#68931c90de214d9d13feefbd35246a81b6cb8d49'}))
|
||||||
data = json.loads(rv.data)
|
data = json.loads(rv.data)
|
||||||
assert data['message'].startswith('The following invalid modulemd was encountered') is True
|
assert re.match(r'The modulemd .* is invalid\. Please verify the syntax is correct',
|
||||||
|
data['message'])
|
||||||
assert data['status'] == 422
|
assert data['status'] == 422
|
||||||
assert data['error'] == 'Unprocessable Entity'
|
assert data['error'] == 'Unprocessable Entity'
|
||||||
|
|
||||||
@@ -1596,7 +1598,8 @@ class TestViews:
|
|||||||
data = json.loads(rv.data)
|
data = json.loads(rv.data)
|
||||||
|
|
||||||
assert data['error'] == 'Unprocessable Entity'
|
assert data['error'] == 'Unprocessable Entity'
|
||||||
assert data['message'].startswith('The following invalid modulemd was encountered')
|
assert re.match(r'The modulemd .* is invalid\. Please verify the syntax is correct',
|
||||||
|
data['message'])
|
||||||
|
|
||||||
@pytest.mark.parametrize('api_version', [1, 2])
|
@pytest.mark.parametrize('api_version', [1, 2])
|
||||||
@patch('module_build_service.auth.get_user', return_value=import_module_user)
|
@patch('module_build_service.auth.get_user', return_value=import_module_user)
|
||||||
|
|||||||
Reference in New Issue
Block a user