Merge "Don't hide exception messages during package load"
This commit is contained in:
commit
d99ab6ce56
@ -33,7 +33,7 @@ class MuranoClassLoader(object):
|
||||
self._packages_cache = {}
|
||||
principal_objects.register(self)
|
||||
|
||||
def _get_package(self, class_name):
|
||||
def _get_package_for_class(self, class_name):
|
||||
package_name = self.find_package_name(class_name)
|
||||
if package_name is None:
|
||||
raise exceptions.NoPackageForClassFound(class_name)
|
||||
@ -48,7 +48,7 @@ class MuranoClassLoader(object):
|
||||
|
||||
try:
|
||||
data = self.load_definition(name)
|
||||
package = self._get_package(name)
|
||||
package = self._get_package_for_class(name)
|
||||
except (exceptions.NoPackageForClassFound, exceptions.NoClassFound):
|
||||
if create_missing:
|
||||
data = {'Name': name}
|
||||
|
@ -13,6 +13,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from murano.dsl import class_loader
|
||||
@ -20,6 +22,7 @@ from murano.dsl import exceptions
|
||||
from murano.dsl import murano_package
|
||||
from murano.engine.system import yaql_functions
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.packages import exceptions as pkg_exceptions
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -43,9 +46,16 @@ class PackageClassLoader(class_loader.MuranoClassLoader):
|
||||
def load_definition(self, name):
|
||||
try:
|
||||
package = self._get_package_for(name)
|
||||
if package is None:
|
||||
raise exceptions.NoPackageForClassFound(name)
|
||||
return package.get_class(name)
|
||||
except Exception:
|
||||
raise exceptions.NoClassFound(name)
|
||||
# (sjmc7) This is used as a control condition for system classes;
|
||||
# do not delete (although I think it needs a better solution)
|
||||
except exceptions.NoPackageForClassFound:
|
||||
raise
|
||||
except Exception as e:
|
||||
msg = "Error loading {0}: {1}".format(name, str(e))
|
||||
raise pkg_exceptions.PackageLoadError(msg), None, sys.exc_info()[2]
|
||||
|
||||
def load_package(self, name):
|
||||
package = murano_package.MuranoPackage()
|
||||
|
@ -16,6 +16,7 @@
|
||||
import abc
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import uuid
|
||||
|
||||
@ -51,21 +52,21 @@ class ApiPackageLoader(PackageLoader):
|
||||
|
||||
def get_package_by_class(self, name):
|
||||
filter_opts = {'class_name': name, 'limit': 1}
|
||||
|
||||
try:
|
||||
package_definition = self._get_definition(filter_opts)
|
||||
return self._get_package_by_definition(package_definition)
|
||||
except(LookupError, pkg_exc.PackageLoadError):
|
||||
raise exceptions.NoPackageForClassFound(name)
|
||||
except LookupError:
|
||||
exc_info = sys.exc_info()
|
||||
raise exceptions.NoPackageForClassFound(name), None, exc_info[2]
|
||||
return self._get_package_by_definition(package_definition)
|
||||
|
||||
def get_package(self, name):
|
||||
filter_opts = {'fqn': name, 'limit': 1}
|
||||
|
||||
try:
|
||||
package_definition = self._get_definition(filter_opts)
|
||||
return self._get_package_by_definition(package_definition)
|
||||
except(LookupError, pkg_exc.PackageLoadError):
|
||||
raise exceptions.NoPackageFound(name)
|
||||
except LookupError:
|
||||
exc_info = sys.exc_info()
|
||||
raise exceptions.NoPackageFound(name), None, exc_info[2]
|
||||
return self._get_package_by_definition(package_definition)
|
||||
|
||||
@staticmethod
|
||||
def _get_cache_directory():
|
||||
@ -74,8 +75,7 @@ class ApiPackageLoader(PackageLoader):
|
||||
directory = os.path.abspath(directory)
|
||||
os.makedirs(directory)
|
||||
|
||||
LOG.debug('Cache for package loader is located at: '
|
||||
'{0}'.format(directory))
|
||||
LOG.debug('Cache for package loader is located at: %s' % directory)
|
||||
return directory
|
||||
|
||||
@staticmethod
|
||||
@ -143,10 +143,12 @@ class ApiPackageLoader(PackageLoader):
|
||||
shutil.rmtree(package_directory, ignore_errors=True)
|
||||
try:
|
||||
package_data = self._client.packages.download(package_id)
|
||||
except muranoclient_exc.HTTPException:
|
||||
LOG.exception('Unable to download '
|
||||
'package with id {0}'.format(package_id))
|
||||
raise pkg_exc.PackageLoadError()
|
||||
except muranoclient_exc.HTTPException as e:
|
||||
msg = 'Error loading package id {0}: {1}'.format(
|
||||
package_id, str(e)
|
||||
)
|
||||
exc_info = sys.exc_info()
|
||||
raise pkg_exc.PackageLoadError(msg), None, exc_info[2]
|
||||
package_file = None
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as package_file:
|
||||
@ -159,8 +161,9 @@ class ApiPackageLoader(PackageLoader):
|
||||
loader=yaql_yaml_loader.YaqlYamlLoader
|
||||
)
|
||||
except IOError:
|
||||
LOG.exception('Unable to write package file')
|
||||
raise pkg_exc.PackageLoadError()
|
||||
msg = 'Unable to extract package data for %s' % package_id
|
||||
exc_info = sys.exc_info()
|
||||
raise pkg_exc.PackageLoadError(msg), None, exc_info[2]
|
||||
finally:
|
||||
try:
|
||||
if package_file:
|
||||
|
Loading…
Reference in New Issue
Block a user