def _get_metadata(self): metadata_file = self.conf.glance_store.filesystem_store_metadata_file if metadata_file is None: return {} try: with open(metadata_file, 'r') as fptr: metadata = jsonutils.load(fptr) glance_store.check_location_metadata(metadata) return metadata except exceptions.BackendException as bee: LOG.error(_('The JSON in the metadata file %(file)s could not ' 'be used: %(bee)s An empty dictionary will be ' 'returned to the client.') % dict(file=metadata_file, bee=str(bee))) return {} except IOError as ioe: LOG.error(_('The path for the metadata file %(file)s could not be ' 'opened: %(io)s An empty dictionary will be returned ' 'to the client.') % dict(file=metadata_file, io=ioe)) return {} except Exception as ex: LOG.exception(_('An error occurred processing the storage systems ' 'meta data file: %s. An empty dictionary will be ' 'returned to the client.') % str(ex)) return {}
def _get_metadata(self): metadata_file = self.conf.glance_store.filesystem_store_metadata_file if metadata_file is None: return {} try: with open(metadata_file, 'r') as fptr: metadata = jsonutils.load(fptr) glance_store.check_location_metadata(metadata) return metadata except exceptions.BackendException as bee: LOG.error( _('The JSON in the metadata file %(file)s could not ' 'be used: %(bee)s An empty dictionary will be ' 'returned to the client.') % dict(file=metadata_file, bee=str(bee))) return {} except IOError as ioe: LOG.error( _('The path for the metadata file %(file)s could not be ' 'opened: %(io)s An empty dictionary will be returned ' 'to the client.') % dict(file=metadata_file, io=ioe)) return {} except Exception as ex: LOG.exception( _('An error occurred processing the storage systems ' 'meta data file: %s. An empty dictionary will be ' 'returned to the client.') % str(ex)) return {}
def _validate_metadata(self, metadata_file): """Validate metadata against json schema. If metadata is valid then cache metadata and use it when creating new image. :param metadata_file: JSON metadata file path :raises: BadStoreConfiguration exception if metadata is not valid. """ try: with open(metadata_file, 'rb') as fptr: metadata = jsonutils.load(fptr) if isinstance(metadata, dict): # If metadata is of type dictionary # i.e. - it contains only one mountpoint # then convert it to list of dictionary. metadata = [metadata] # Validate metadata against json schema jsonschema.validate(metadata, MULTI_FILESYSTEM_METADATA_SCHEMA) glance_store.check_location_metadata(metadata) self.FILESYSTEM_STORE_METADATA = metadata except (jsonschema.exceptions.ValidationError, exceptions.BackendException, ValueError) as vee: err_msg = encodeutils.exception_to_unicode(vee) reason = _('The JSON in the metadata file %(file)s is ' 'not valid and it can not be used: ' '%(vee)s.') % dict(file=metadata_file, vee=err_msg) LOG.error(reason) raise exceptions.BadStoreConfiguration( store_name="filesystem", reason=reason) except IOError as ioe: err_msg = encodeutils.exception_to_unicode(ioe) reason = _('The path for the metadata file %(file)s could ' 'not be accessed: ' '%(ioe)s.') % dict(file=metadata_file, ioe=err_msg) LOG.error(reason) raise exceptions.BadStoreConfiguration( store_name="filesystem", reason=reason)
def test_unicode_dict_list(self): inner = {'key1': u'somevalue', 'key2': u'somevalue'} m = {'topkey': inner, 'list': [u'somevalue', u'2'], 'u': u'2'} glance_store.check_location_metadata(m)
def test_nested_dict(self): inner = {'key1': u'somevalue', 'key2': u'somevalue'} inner = {'newkey': inner} inner = {'anotherkey': inner} m = {'topkey': inner} glance_store.check_location_metadata(m)
def test_unicode_dict(self): inner = {'key1': u'somevalue', 'key2': u'somevalue'} m = {'topkey': inner} glance_store.check_location_metadata(m)
def test_unicode_list(self): m = {'key': [u'somevalue', u'2']} glance_store.check_location_metadata(m)
def test_unicode(self): m = {'key': u'somevalue'} glance_store.check_location_metadata(m)
def test_empty(self): glance_store.check_location_metadata({})
def check_location_metadata(self, val, key=''): store.check_location_metadata(val)