Merge "Add cluster action to profile"
This commit is contained in:
commit
ea728ba7f6
|
@ -13,6 +13,7 @@
|
|||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
from senlin.common import consts
|
||||
from senlin.common import exception
|
||||
|
@ -248,10 +249,23 @@ class Cluster(object):
|
|||
return False
|
||||
|
||||
self.set_status(context, consts.CS_CREATING, _('Creation in progress'))
|
||||
try:
|
||||
pfb.Profile.create_cluster_object(context, self)
|
||||
except exception.EResourceCreation as ex:
|
||||
self.set_status(context, consts.CS_ERROR, six.text_type(ex))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def do_delete(self, context, **kwargs):
|
||||
"""Additional logic at the end of cluster deletion process."""
|
||||
self.set_status(context, consts.CS_DELETING, _('Deletion in progress'))
|
||||
|
||||
try:
|
||||
pfb.Profile.delete_cluster_object(context, self)
|
||||
except exception.EResourceDeletion as ex:
|
||||
self.set_status(context, consts.CS_ERROR, six.text_type(ex))
|
||||
return False
|
||||
|
||||
co.Cluster.delete(context, self.id)
|
||||
return True
|
||||
|
|
|
@ -223,12 +223,32 @@ class Profile(object):
|
|||
profile = cls.load(ctx, profile_id=obj.profile_id)
|
||||
return profile.do_create(obj)
|
||||
|
||||
@classmethod
|
||||
@profiler.trace('Profile.create_cluster_object', hide_args=False)
|
||||
def create_cluster_object(cls, ctx, obj):
|
||||
profile = cls.load(ctx, profile_id=obj.profile_id)
|
||||
try:
|
||||
ret = profile.do_cluster_create(obj)
|
||||
except NotImplementedError:
|
||||
return None
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
@profiler.trace('Profile.delete_object', hide_args=False)
|
||||
def delete_object(cls, ctx, obj, **params):
|
||||
profile = cls.load(ctx, profile_id=obj.profile_id)
|
||||
return profile.do_delete(obj, **params)
|
||||
|
||||
@classmethod
|
||||
@profiler.trace('Profile.delete_cluster_object', hide_args=False)
|
||||
def delete_cluster_object(cls, ctx, obj, **params):
|
||||
profile = cls.load(ctx, profile_id=obj.profile_id)
|
||||
try:
|
||||
ret = profile.do_cluster_delete(obj, **params)
|
||||
except NotImplementedError:
|
||||
return None
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
@profiler.trace('Profile.update_object', hide_args=False)
|
||||
def update_object(cls, ctx, obj, new_profile_id=None, **params):
|
||||
|
@ -417,10 +437,18 @@ class Profile(object):
|
|||
"""For subclass to override."""
|
||||
raise NotImplementedError
|
||||
|
||||
def do_cluster_create(self, obj):
|
||||
"""For subclass to override."""
|
||||
raise NotImplementedError
|
||||
|
||||
def do_delete(self, obj, **params):
|
||||
"""For subclass to override."""
|
||||
raise NotImplementedError
|
||||
|
||||
def do_cluster_delete(self, obj):
|
||||
"""For subclass to override."""
|
||||
raise NotImplementedError
|
||||
|
||||
def do_update(self, obj, new_profile, **params):
|
||||
"""For subclass to override."""
|
||||
LOG.warning("Update operation not supported.")
|
||||
|
|
|
@ -350,7 +350,10 @@ class TestCluster(base.SenlinTestCase):
|
|||
mock_update.assert_called_once_with(self.context, CLUSTER_ID,
|
||||
{'status': consts.CS_WARNING})
|
||||
|
||||
def test_do_create(self):
|
||||
@mock.patch.object(pfb.Profile, "create_cluster_object")
|
||||
def test_do_create(self, mock_create_cluster):
|
||||
mock_create_cluster.return_value = None
|
||||
|
||||
cluster = cm.Cluster('test-cluster', 0, PROFILE_ID)
|
||||
mock_status = self.patchobject(cluster, 'set_status')
|
||||
|
||||
|
@ -368,17 +371,22 @@ class TestCluster(base.SenlinTestCase):
|
|||
|
||||
self.assertFalse(res)
|
||||
|
||||
@mock.patch.object(pfb.Profile, "delete_cluster_object")
|
||||
@mock.patch.object(co.Cluster, 'delete')
|
||||
def test_do_delete(self, mock_delete):
|
||||
def test_do_delete(self, mock_delete, mock_delete_cluster):
|
||||
mock_delete.return_value = None
|
||||
mock_delete_cluster.return_value = None
|
||||
|
||||
cluster = cm.Cluster('test-cluster', 0, PROFILE_ID)
|
||||
cluster.id = CLUSTER_ID
|
||||
mock_status = self.patchobject(cluster, 'set_status')
|
||||
|
||||
res = cluster.do_delete(self.context)
|
||||
|
||||
mock_delete.assert_called_once_with(self.context, CLUSTER_ID)
|
||||
self.assertTrue(res)
|
||||
mock_status.assert_called_once_with(
|
||||
self.context, consts.CS_DELETING, 'Deletion in progress')
|
||||
|
||||
def test_do_update(self):
|
||||
cluster = cm.Cluster('test-cluster', 0, PROFILE_ID)
|
||||
|
|
Loading…
Reference in New Issue