Move all tasks objects into progress module

Change-Id: I45666b885161f6d92554683f9a652a34513d7933
This commit is contained in:
Pavlo Shchelokovskyy 2015-08-18 19:43:55 +03:00
parent e7ae699652
commit 3b2c92905e
7 changed files with 88 additions and 88 deletions

View File

@ -177,52 +177,6 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
return True
# NOTE(pshchelo): these Volume*Progress classes are simple key-value storages
# meant to be passed between handle_<action> and check_<action>_complete,
# being mutated during subsequent check_<action>_complete calls.
class VolumeDetachProgress(object):
def __init__(self, srv_id, vol_id, attach_id, val=False):
self.called = val
self.cinder_complete = val
self.nova_complete = val
self.srv_id = srv_id
self.vol_id = vol_id
self.attach_id = attach_id
class VolumeAttachProgress(object):
def __init__(self, srv_id, vol_id, device, val=False):
self.called = val
self.complete = val
self.srv_id = srv_id
self.vol_id = vol_id
self.device = device
class VolumeDeleteProgress(object):
def __init__(self, val=False):
self.backup = {'called': val,
'complete': val}
self.delete = {'called': val,
'complete': val}
self.backup_id = None
class VolumeResizeProgress(object):
def __init__(self, val=False, size=None):
self.called = val
self.complete = val
self.size = size
class VolumeBackupRestoreProgress(object):
def __init__(self, vol_id, backup_id):
self.called = False
self.complete = False
self.vol_id = vol_id
self.backup_id = backup_id
class VolumeConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.EntityNotFound,)

View File

@ -32,25 +32,27 @@ class ServerUpdateProgress(ServerCreateProgress):
``handler`` is a method of client plugin performing
required update operation.
It must accept ``server_id`` as first positional argument and
be resilent to intermittent failures, returning ``True`` if
API was successfully called, ``False`` otherwise.
Its first positional argument must be ``server_id``
and this method must be resilent to intermittent failures,
returning ``True`` if API was successfully called, ``False`` otherwise.
If result of API call is asyncronous, client plugin must have
corresponding ``check_<handler>`` method
accepting ``server_id`` as first positional argument and
returning ``True`` or ``False``.
corresponding ``check_<handler>`` method.
Its first positional argument must be ``server_id``
and it must return ``True`` or ``False`` indicating completeness
of the update operation.
For syncronous API calls,
set ``complete`` attribute of this object to ``True``.
``*_extra`` arguments, if passed to constructor, should be dictionaries of
``[handler|checker]_extra`` arguments, if passed to constructor,
should be dictionaries of
{'args': tuple(), 'kwargs': dict()}
structure and contain parameters with which corresponding ``handler`` and
``check_<handler>`` methods of client plugin must be called.
(``args`` is automatically prepended with ``server_id``).
``args`` is automatically prepended with ``server_id``.
Missing ``args`` or ``kwargs`` are interpreted
as empty tuple/dict respectively.
Defaults are interpreted as both ``args`` and ``kwargs`` being empty.
@ -80,3 +82,54 @@ class ServerDeleteProgress(object):
self.server_id = server_id
self.image_id = image_id
self.image_complete = image_complete
class VolumeDetachProgress(object):
def __init__(self, srv_id, vol_id, attach_id, task_complete=False):
self.called = task_complete
self.cinder_complete = task_complete
self.nova_complete = task_complete
self.srv_id = srv_id
self.vol_id = vol_id
self.attach_id = attach_id
class VolumeAttachProgress(object):
def __init__(self, srv_id, vol_id, device, task_complete=False):
self.called = task_complete
self.complete = task_complete
self.srv_id = srv_id
self.vol_id = vol_id
self.device = device
class VolumeDeleteProgress(object):
def __init__(self, task_complete=False):
self.backup = {'called': task_complete,
'complete': task_complete}
self.delete = {'called': task_complete,
'complete': task_complete}
self.backup_id = None
class VolumeResizeProgress(object):
def __init__(self, task_complete=False, size=None):
self.called = task_complete
self.complete = task_complete
self.size = size
class VolumeBackupRestoreProgress(object):
def __init__(self, vol_id, backup_id):
self.called = False
self.complete = False
self.vol_id = vol_id
self.backup_id = backup_id
class PoolDeleteProgress(object):
def __init__(self, task_complete=False):
self.pool = {'delete_called': task_complete,
'deleted': task_complete}
self.vip = {'delete_called': task_complete,
'deleted': task_complete}

View File

@ -22,7 +22,6 @@ from heat.common.i18n import _
from heat.common.i18n import _LI
from heat.common.i18n import _LW
from heat.engine import attributes
from heat.engine.clients.os import cinder as cinder_cp
from heat.engine.clients import progress
from heat.engine import constraints
from heat.engine import properties
@ -571,8 +570,8 @@ class Instance(resource.Resource):
creator = progress.ServerCreateProgress(server.id)
attachers = []
for vol_id, device in self.volumes():
attachers.append(cinder_cp.VolumeAttachProgress(self.resource_id,
vol_id, device))
attachers.append(progress.VolumeAttachProgress(self.resource_id,
vol_id, device))
return creator, tuple(attachers)
def check_create_complete(self, cookie):

View File

@ -19,7 +19,7 @@ from heat.common import exception
from heat.common.i18n import _
from heat.common.i18n import _LI
from heat.engine import attributes
from heat.engine.clients.os import cinder as heat_cinder
from heat.engine.clients import progress
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
@ -373,7 +373,7 @@ class CinderVolume(vb.BaseVolume):
cinder.volumes.update_readonly_flag(self.resource_id, flag)
# restore the volume from backup
if self.BACKUP_ID in prop_diff:
prg_backup_restore = heat_cinder.VolumeBackupRestoreProgress(
prg_backup_restore = progress.VolumeBackupRestoreProgress(
vol_id=self.resource_id,
backup_id=prop_diff.get(self.BACKUP_ID))
# extend volume size
@ -386,7 +386,7 @@ class CinderVolume(vb.BaseVolume):
raise exception.NotSupported(feature=_("Shrinking volume"))
elif new_size > vol.size:
prg_resize = heat_cinder.VolumeResizeProgress(size=new_size)
prg_resize = progress.VolumeResizeProgress(size=new_size)
if vol.attachments:
# NOTE(pshchelo):
# this relies on current behavior of cinder attachments,
@ -398,9 +398,9 @@ class CinderVolume(vb.BaseVolume):
server_id = vol.attachments[0]['server_id']
device = vol.attachments[0]['device']
attachment_id = vol.attachments[0]['id']
prg_detach = heat_cinder.VolumeDetachProgress(
prg_detach = progress.VolumeDetachProgress(
server_id, vol.id, attachment_id)
prg_attach = heat_cinder.VolumeAttachProgress(
prg_attach = progress.VolumeAttachProgress(
server_id, vol.id, device)
return prg_backup_restore, prg_detach, prg_resize, prg_attach
@ -623,7 +623,7 @@ class CinderVolumeAttachment(vb.BaseVolumeAttachment):
server_id = self._stored_properties_data.get(self.INSTANCE_ID)
self.client_plugin('nova').detach_volume(server_id,
self.resource_id)
prg_detach = heat_cinder.VolumeDetachProgress(
prg_detach = progress.VolumeDetachProgress(
server_id, volume_id, self.resource_id)
prg_detach.called = True
@ -636,7 +636,7 @@ class CinderVolumeAttachment(vb.BaseVolumeAttachment):
if self.INSTANCE_ID in prop_diff:
server_id = prop_diff.get(self.INSTANCE_ID)
prg_attach = heat_cinder.VolumeAttachProgress(
prg_attach = progress.VolumeAttachProgress(
server_id, volume_id, device)
return prg_detach, prg_attach

View File

@ -16,6 +16,7 @@ import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import attributes
from heat.engine.clients import progress
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
@ -510,22 +511,15 @@ class Pool(neutron.NeutronResource):
def handle_delete(self):
class PoolDeleteProgress(object):
def __init__(self, val=False):
self.pool = {'delete_called': val,
'deleted': val}
self.vip = {'delete_called': val,
'deleted': val}
if not self.resource_id:
progress = PoolDeleteProgress(True)
return progress
prg = progress.PoolDeleteProgress(True)
return prg
progress = PoolDeleteProgress()
prg = progress.PoolDeleteProgress()
if not self.metadata_get():
progress.vip['delete_called'] = True
progress.vip['deleted'] = True
return progress
prg.vip['delete_called'] = True
prg.vip['deleted'] = True
return prg
def _delete_vip(self):
return self._not_found_in_call(

View File

@ -13,7 +13,7 @@
from heat.common import exception
from heat.common.i18n import _
from heat.engine.clients.os import cinder as heat_cinder
from heat.engine.clients import progress
from heat.engine import resource
@ -84,18 +84,18 @@ class BaseVolume(resource.Resource):
def handle_snapshot_delete(self, state):
backup = state not in ((self.CREATE, self.FAILED),
(self.UPDATE, self.FAILED))
progress = heat_cinder.VolumeDeleteProgress()
progress.backup['called'] = not backup
progress.backup['complete'] = not backup
return progress
prg = progress.VolumeDeleteProgress()
prg.backup['called'] = not backup
prg.backup['complete'] = not backup
return prg
def handle_delete(self):
if self.resource_id is None:
return heat_cinder.VolumeDeleteProgress(True)
progress = heat_cinder.VolumeDeleteProgress()
progress.backup['called'] = True
progress.backup['complete'] = True
return progress
return progress.VolumeDeleteProgress(True)
prg = progress.VolumeDeleteProgress()
prg.backup['called'] = True
prg.backup['complete'] = True
return prg
def _create_backup(self):
backup = self.client().backups.create(self.resource_id)
@ -184,7 +184,7 @@ class BaseVolumeAttachment(resource.Resource):
vol_id = self.properties[self.VOLUME_ID]
self.client_plugin('nova').detach_volume(server_id,
self.resource_id)
prg = heat_cinder.VolumeDetachProgress(
prg = progress.VolumeDetachProgress(
server_id, vol_id, self.resource_id)
prg.called = True
return prg