Remove pending_delete status for blobs

Currently if artifact is marked as deleted all
its blobs logicaly become 'pending_delete' and
can't be used anymore.

For this reason there is no need to have addtional
blob status and explicitely mark blobs - it's all
done when we change artifact status to 'deleted'

ApiImpact

Change-Id: Ide2bb3130d400b7ddcde0760246003b745ef4ff0
This commit is contained in:
Mike Fedosin 2017-06-22 12:00:56 +03:00
parent 84c31bac4c
commit 0cbb8b77f3
5 changed files with 21 additions and 58 deletions

View File

@ -164,7 +164,7 @@ using Representational State Transfer concept (ReST).
"external": {"type": "boolean"},
"id": {"type": "string"},
"status": {"type": "string",
"enum": ["saving", "active", "pending_delete"]},
"enum": ["saving", "active"]},
"content_type": {"type": ["string", "null"]},
},
"required": ["url", "size", "md5", "sha1", "sha256", "external",
@ -177,31 +177,20 @@ using Representational State Transfer concept (ReST).
* *active* - blob upload successfully finished.
* *pending_delete* - indicates that blob will be deleted soon by Scrubber
(if delayed delete is enabled) or by Glare itself.
.. list-table:: **Blob status transition table**
:header-rows: 1
* - Blob Status
- saving
- active
- pending delete
* - **saving**
- X
- finish blob upload
- request for artifact delete
* - **active**
- N/A
- X
- request for artifact delete
* - **pending_delete**
- N/A
- N/A
- X
* *Artifact Dict and List* - compound generic field types that
implement Dict or List interfaces respectively, and contain values of some

View File

@ -582,14 +582,6 @@ class BaseArtifact(base.VersionedObject):
for af in cls.db_api.list(
context, filters, marker, limit, sort, latest)]
@staticmethod
def _prepare_blob_delete(b, af, name):
if b['status'] == glare_fields.BlobFieldType.SAVING:
msg = _('Blob %(name)s is saving for artifact %(id)s'
) % {'name': name, 'id': af.id}
raise exception.Conflict(msg)
b['status'] = glare_fields.BlobFieldType.PENDING_DELETE
@classmethod
def _delete_blobs(cls, blobs, context, af):
for name, blob in blobs.items():
@ -623,24 +615,16 @@ class BaseArtifact(base.VersionedObject):
# marking artifact as deleted
cls.db_api.update(context, af.id, {'status': cls.STATUS.DELETED})
# marking all blobs as pending delete
# collect all uploaded blobs
blobs = {}
for name, field in af.fields.items():
if cls.is_blob(name):
b = getattr(af, name)
if b:
cls._prepare_blob_delete(b, af, name)
blobs[name] = b
elif cls.is_blob_dict(name):
bd = getattr(af, name)
if bd:
for key, b in bd.items():
cls._prepare_blob_delete(b, af, name)
blobs[name] = bd
LOG.debug("Marked artifact %(artifact)s as deleted and all its blobs "
"%(blobs) as pending delete.",
{'artifact': af.id, 'blobs': blobs})
cls.db_api.update_blob(context, af.id, blobs)
for name in af.fields:
if cls.is_blob(name) or cls.is_blob_dict(name):
field = getattr(af, name)
if field:
blobs[name] = field
LOG.debug("Marked artifact %(artifact)s as deleted.",
{'artifact': af.id})
if not CONF.delayed_delete:
if blobs:

View File

@ -54,8 +54,7 @@ class VersionField(fields.AutoTypedField):
class BlobFieldType(fields.FieldType):
"""Blob field contains reference to blob location.
"""
BLOB_STATUS = (SAVING, ACTIVE, PENDING_DELETE) = (
'saving', 'active', 'pending_delete')
BLOB_STATUS = (SAVING, ACTIVE) = ('saving', 'active')
BLOB_SCHEMA = {
'type': 'object',

View File

@ -178,8 +178,7 @@ fixtures = {
u'status': {
u'enum': [
u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -231,8 +230,7 @@ fixtures = {
u'status': {
u'enum': [
u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -412,8 +410,7 @@ fixtures = {
u'status': {
u'enum': [
u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -494,8 +491,7 @@ fixtures = {
u'size': {u'type': [u'number',
u'null']},
u'status': {u'enum': [u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -605,8 +601,7 @@ fixtures = {
u'size': {u'type': [u'number',
u'null']},
u'status': {u'enum': [u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -698,8 +693,7 @@ fixtures = {
u'size': {u'type': [u'number',
u'null']},
u'status': {u'enum': [u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -844,8 +838,7 @@ fixtures = {
u'size': {u'type': [u'number',
u'null']},
u'status': {u'enum': [u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -878,8 +871,7 @@ fixtures = {
u'size': {u'type': [u'number',
u'null']},
u'status': {u'enum': [u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',
@ -910,8 +902,7 @@ fixtures = {
u'size': {u'type': [u'number',
u'null']},
u'status': {u'enum': [u'saving',
u'active',
u'pending_delete'],
u'active'],
u'type': u'string'}},
u'required': [u'size',
u'md5', u'sha1', u'sha256',

View File

@ -163,7 +163,7 @@ class TestArtifactUpdate(base.BaseTestArtifactAPI):
self.artifact = self.controller.show(
self.req, 'sample_artifact', self.artifact['id'])
self.assertEqual('deleted', self.artifact['status'])
self.assertEqual('pending_delete', self.artifact['blob']['status'])
self.assertEqual('active', self.artifact['blob']['status'])
# Disable delayed delete
self.config(delayed_delete=False)
# Delete artifact and check that 'delete_blob' was called this time