Merge "Pass status reason when trove misbehaves"

This commit is contained in:
Jenkins 2014-12-03 17:34:46 +00:00 committed by Gerrit Code Review
commit b36dfd335f
2 changed files with 54 additions and 3 deletions

View File

@ -39,8 +39,16 @@ class OSDBInstance(resource.Resource):
'ERROR', 'FAILED', 'ACTIVE',
)
BAD_STATUSES = (ERROR, FAILED)
TROVE_STATUS_REASON = {
FAILED: _('The database instance was created, but heat failed to set '
'up the datastore. If a database instance is in the FAILED '
'state, it should be deleted and a new one should be '
'created.'),
ERROR: _('The last operation for the database instance failed due to '
'an error.'),
}
BAD_STATUSES = (ERROR, FAILED)
PROPERTIES = (
NAME, FLAVOR, SIZE, DATABASES, USERS, AVAILABILITY_ZONE,
RESTORE_POINT, DATASTORE_TYPE, DATASTORE_VERSION, NICS,
@ -345,7 +353,9 @@ class OSDBInstance(resource.Resource):
self._refresh_instance(instance) # get updated attributes
if instance.status in self.BAD_STATUSES:
raise resource.ResourceInError(
resource_status=instance.status)
resource_status=instance.status,
status_reason=self.TROVE_STATUS_REASON.get(instance.status,
_("Unknown")))
if instance.status != self.ACTIVE:
return False

View File

@ -11,11 +11,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from troveclient.openstack.common.apiclient import exceptions as troveexc
import uuid
import mock
import six
from troveclient.openstack.common.apiclient import exceptions as troveexc
from heat.common import exception
from heat.common import template_format
@ -23,7 +23,9 @@ from heat.engine.clients.os import neutron
from heat.engine.clients.os import nova
from heat.engine.clients.os import trove
from heat.engine import parser
from heat.engine import resource
from heat.engine.resources import os_database
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests import common
from heat.tests import utils
@ -164,6 +166,45 @@ class OSDBInstanceTest(common.HeatTestCase):
self.assertEqual((instance.CREATE, instance.COMPLETE), instance.state)
self.m.VerifyAll()
def test_create_failed(self):
mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None
res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
osdb_res = os_database.OSDBInstance("test", res_def, mock_stack)
# test for bad statuses
mock_input = mock.Mock()
mock_input.status = 'ERROR'
error_string = ('Went to status ERROR due to "The last operation for '
'the database instance failed due to an error."')
exc = self.assertRaises(resource.ResourceInError,
osdb_res.check_create_complete,
mock_input)
self.assertIn(error_string, six.text_type(exc))
mock_input = mock.Mock()
mock_input.status = 'FAILED'
error_string = ('Went to status FAILED due to "The database instance '
'was created, but heat failed to set up the '
'datastore. If a database instance is in the FAILED '
'state, it should be deleted and a new one should '
'be created."')
exc = self.assertRaises(resource.ResourceInError,
osdb_res.check_create_complete,
mock_input)
self.assertIn(error_string, six.text_type(exc))
# test if error string is not defined
osdb_res.TROVE_STATUS_REASON = {}
mock_input = mock.Mock()
mock_input.status = 'ERROR'
error_string = ('Went to status ERROR due to "Unknown"')
exc = self.assertRaises(resource.ResourceInError,
osdb_res.check_create_complete,
mock_input)
self.assertIn(error_string, six.text_type(exc))
def test_osdatabase_restore_point(self):
fake_dbinstance = FakeDBInstance()
t = template_format.parse(db_template)