def get_share_type_by_name(context, name): """Retrieves single share type by name.""" if name is None: msg = _("name cannot be None") raise exception.InvalidShareType(reason=msg) return db.share_type_get_by_name(context, name)
def destroy(context, id): """Marks share types as deleted.""" if id is None: msg = _("id cannot be None") raise exception.InvalidShareType(reason=msg) else: db.share_type_destroy(context, id)
def create(context, name, extra_specs=None, is_public=True, projects=None, description=None): """Creates share types.""" extra_specs = extra_specs or {} projects = projects or [] try: get_valid_required_extra_specs(extra_specs) get_valid_optional_extra_specs(extra_specs) except exception.InvalidExtraSpec as e: raise exception.InvalidShareType(reason=six.text_type(e)) extra_specs = sanitize_extra_specs(extra_specs) try: type_ref = db.share_type_create(context, dict(name=name, description=description, extra_specs=extra_specs, is_public=is_public), projects=projects) except db_exception.DBError: LOG.exception('DB error.') raise exception.ShareTypeCreateFailed(name=name, extra_specs=extra_specs) return type_ref
def get_share_type(ctxt, id, expected_fields=None): """Retrieves single share type by id.""" if id is None: msg = _("id cannot be None") raise exception.InvalidShareType(reason=msg) if ctxt is None: ctxt = context.get_admin_context() return db.share_type_get(ctxt, id, expected_fields=expected_fields)
def create(context, name, extra_specs=None, is_public=True, projects=None): """Creates share types.""" extra_specs = extra_specs or {} projects = projects or [] if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in list(extra_specs): extra_specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = 'True' try: get_valid_required_extra_specs(extra_specs) except exception.InvalidExtraSpec as e: raise exception.InvalidShareType(reason=six.text_type(e)) try: type_ref = db.share_type_create(context, dict(name=name, extra_specs=extra_specs, is_public=is_public), projects=projects) except db_exception.DBError as e: LOG.exception(_LE('DB error: %s'), e) raise exception.ShareTypeCreateFailed(name=name, extra_specs=extra_specs) return type_ref
def remove_share_type_access(context, share_type_id, project_id): """Remove access to share type for project_id.""" if share_type_id is None: msg = _("share_type_id cannot be None") raise exception.InvalidShareType(reason=msg) return db.share_type_access_remove(context, share_type_id, project_id)
def test_invalid_share_type(self): # Verify response code for exception.InvalidShareType reason = "fake_reason" e = exception.InvalidShareType(reason=reason) self.assertEqual(400, e.code) self.assertIn(reason, e.msg)