Merge "Fix Galera_common.grow/shrink to propogate exceptions"

This commit is contained in:
Jenkins 2016-11-23 20:12:39 +00:00 committed by Gerrit Code Review
commit 36a54ed6d8
3 changed files with 36 additions and 1 deletions

View File

@ -25,7 +25,6 @@ pymongo!=3.1,>=3.0.2 # Apache-2.0
redis>=2.10.0 # MIT
psycopg2>=2.5 # LGPL/ZPL
cassandra-driver!=3.6.0,>=2.1.4 # Apache-2.0
pycrypto>=2.6 # Public Domain
couchdb>=0.8 # Apache-2.0
os-testr>=0.8.0 # Apache-2.0
astroid<1.4.0 # LGPLv2.1 # breaks pylint 1.4.4

View File

@ -168,6 +168,7 @@ class GaleraCommonCluster(cluster_models.Cluster):
db_info.id, [instance.id for instance in new_instances])
except Exception:
db_info.update(task_status=ClusterTasks.NONE)
raise
return self.__class__(context, db_info,
datastore, datastore_version)
@ -191,6 +192,7 @@ class GaleraCommonCluster(cluster_models.Cluster):
for instance in removal_instances])
except Exception:
self.db_info.update(task_status=ClusterTasks.NONE)
raise
return self.__class__(self.context, self.db_info,
self.ds, self.ds_version)

View File

@ -25,6 +25,8 @@ from trove.common import exception
from trove.common import remote
from trove.common.strategies.cluster.experimental.galera_common import (
api as galera_api)
from trove.common.strategies.cluster.experimental.galera_common import (
taskmanager as galera_task)
from trove.instance import models as inst_models
from trove.quota.quota import QUOTAS
from trove.taskmanager import api as task_api
@ -327,6 +329,20 @@ class ClusterTest(trove_testtools.TestCase):
[mock_inst_create.return_value.id] * 3)
self.assertEqual(3, mock_inst_create.call_count)
@patch.object(DBCluster, 'update')
@patch.object(galera_api, 'CONF')
@patch.object(inst_models.Instance, 'create')
@patch.object(QUOTAS, 'check_quotas')
@patch.object(remote, 'create_nova_client')
def test_grow_exception(self, mock_client, mock_check_quotas,
mock_inst_create, mock_conf, mock_update):
mock_client.return_value.flavors = Mock()
with patch.object(task_api, 'load') as mock_load:
mock_load.return_value.grow_cluster = Mock(
side_effect=exception.BadRequest)
self.assertRaises(exception.BadRequest, self.cluster.grow,
self.instances)
@patch.object(inst_models.DBInstance, 'find_all')
@patch.object(inst_models.Instance, 'load')
@patch.object(Cluster, 'validate_cluster_available')
@ -356,3 +372,21 @@ class ClusterTest(trove_testtools.TestCase):
self.db_info.id, [mock_load.return_value.id])
mock_init.assert_called_with(self.context, self.db_info,
self.datastore, self.datastore_version)
@patch.object(galera_task.GaleraCommonClusterTasks, 'shrink_cluster')
@patch.object(galera_api.GaleraCommonCluster, '__init__')
@patch.object(DBCluster, 'update')
@patch.object(inst_models.DBInstance, 'find_all')
@patch.object(inst_models.Instance, 'load')
@patch.object(Cluster, 'validate_cluster_available')
def test_shrink_exception(self, mock_validate, mock_load, mock_find_all,
mock_update, mock_init, mock_shrink):
mock_init.return_value = None
existing_instances = [Mock(), Mock()]
mock_find_all.return_value.all.return_value = existing_instances
instance = Mock()
with patch.object(task_api, 'load') as mock_load:
mock_load.return_value.shrink_cluster = Mock(
side_effect=exception.BadRequest)
self.assertRaises(exception.BadRequest, self.cluster.shrink,
[instance])