Ejemplo n.º 1
0
    def _setup_test_clouddbinstance(self, name, t):
        stack_name = '%s_stack' % name
        template = parser.Template(t)
        stack = parser.Stack(utils.dummy_context(),
                             stack_name,
                             template,
                             stack_id=str(uuid.uuid4()))

        instance = os_database.OSDBInstance(
            '%s_name' % name,
            template.resource_definitions(stack)['MySqlCloudDB'], stack)
        return instance
Ejemplo n.º 2
0
    def _setup_test_clouddbinstance(self, name, parsed_t):
        stack_name = '%s_stack' % name
        t = parsed_t
        template = parser.Template(t)
        stack = parser.Stack(utils.dummy_context(),
                             stack_name,
                             template,
                             environment.Environment({'name': 'test'}),
                             stack_id=str(uuid.uuid4()))

        instance = os_database.OSDBInstance('%s_name' % name,
                                            t['Resources']['MySqlCloudDB'],
                                            stack)
        return instance
Ejemplo n.º 3
0
    def _setup_test_clouddbinstance(self, name, parsed_t):
        stack_name = '%s_stack' % name
        t = parsed_t
        template = parser.Template(t)
        stack = parser.Stack(None,
                             stack_name,
                             template,
                             environment.Environment({'name': 'test'}),
                             stack_id=str(uuid.uuid4()))

        instance = os_database.OSDBInstance('%s_name' % name,
                                            t['Resources']['MySqlCloudDB'],
                                            stack)
        instance.t = instance.stack.resolve_runtime_data(instance.t)
        return instance
Ejemplo n.º 4
0
    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)

        trove_mock = mock.Mock()
        self.patchobject(osdb_res, 'trove', return_value=trove_mock)

        # test for bad statuses
        mock_input = mock.Mock()
        mock_input.status = 'ERROR'
        trove_mock.instances.get.return_value = mock_input
        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'
        trove_mock.instances.get.return_value = mock_input
        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"')
        trove_mock.instances.get.return_value = mock_input
        exc = self.assertRaises(resource.ResourceInError,
                                osdb_res.check_create_complete,
                                mock_input)
        self.assertIn(error_string, six.text_type(exc))