Example #1
0
    def test_node_handle_exception(self):
        ex = exception.ResourceStatusError(resource_id='FAKE_ID',
                                           status='FAKE_STATUS',
                                           reason='FAKE_REASON')
        node = nodem.Node('node1', self.profile.id, None, self.context)
        node.store(self.context)
        node._handle_exception(self.context, 'ACTION', 'STATUS', ex)
        db_node = node_obj.Node.get(self.context, node.id)
        self.assertEqual(node.ERROR, db_node.status)
        self.assertEqual(
            'Profile failed in ACTIOing resource '
            '(FAKE_ID) due to: %s' % six.text_type(ex), db_node.status_reason)
        self.assertEqual('FAKE_ID', db_node.physical_id)

        # Exception happens before physical node creation started.
        ex = exception.ResourceCreationFailure(rtype='stack',
                                               code=400,
                                               message='Bad request')
        node = nodem.Node('node1', self.profile.id, None, self.context)
        node.store(self.context)
        node._handle_exception(self.context, 'CREATE', 'STATUS', ex)
        db_node = node_obj.Node.get(self.context, node.id)
        self.assertEqual(node.ERROR, db_node.status)
        self.assertEqual(
            'Profile failed in creating node due to: '
            '%s' % six.text_type(ex), db_node.status_reason)
        self.assertIsNone(db_node.physical_id)
Example #2
0
 def test_node_update_resource_status_error(self, mock_update, mock_status,
                                            mock_handle_exception):
     node = nodem.Node('node1', self.profile.id, self.cluster.id,
                       self.context)
     ex = exception.ResourceStatusError(resource_id='id',
                                        status='ERROR',
                                        reason='some reason')
     mock_update.side_effect = ex
     new_profile = self._create_profile('NEW_PROFILE_ID')
     node.physical_id = 'fake_id'
     res = node.do_update(self.context, {'new_profile_id': new_profile.id})
     self.assertFalse(res)
     mock_handle_exception.assert_called_once_with(self.context, 'update',
                                                   'ERROR', ex)
     self.assertNotEqual('NEW_PROFILE_ID', node.profile_id)
Example #3
0
 def test_node_update_resource_status_error(self, mock_update, mock_status,
                                            mock_handle_exception):
     node = nodem.Node('node1', PROFILE_ID, CLUSTER_ID, self.context)
     ex = exception.ResourceStatusError(resource_id='id',
                                        status='ERROR',
                                        reason='some reason')
     mock_update.side_effect = ex
     new_id = '71d8f4dd-1ef9-4308-b7ae-03298b04449e'
     new_profile = utils.create_profile(self.context, new_id)
     node.physical_id = 'd94d6333-82e6-4f87-b7ab-b786776df9d1'
     res = node.do_update(self.context, {'new_profile_id': new_profile.id})
     self.assertFalse(res)
     mock_handle_exception.assert_called_once_with(self.context, 'update',
                                                   'ERROR', ex)
     self.assertNotEqual(new_id, node.profile_id)
Example #4
0
 def test_node_delete_resource_status_error(self, mock_delete, mock_status,
                                            mock_handle_exception):
     ex = exception.ResourceStatusError(resource_id='id',
                                        status='ERROR',
                                        reason='some reason')
     mock_delete.side_effect = ex
     node = nodem.Node('node1', PROFILE_ID, CLUSTER_ID, self.context)
     node.physical_id = 'd94d6333-82e6-4f87-b7ab-b786776df9d1'
     res = node.do_delete(self.context)
     self.assertFalse(res)
     mock_delete.assert_called_once_with(self.context, node)
     mock_handle_exception.assert_called_once_with(self.context, 'delete',
                                                   'ERROR', ex)
     mock_status.assert_any_call(self.context,
                                 'ERROR',
                                 reason='Deletion failed')
Example #5
0
    def _check_action_complete(self, obj, action):
        stack = self.heat(obj).stack_get(self.stack_id)
        status = stack.status.split('_', 1)

        if status[0] == action:
            if status[1] == 'IN_PROGRESS':
                return False

            if status[1] == 'COMPLETE':
                return True

            raise exception.ResourceStatusError(resource_id=self.stack_id,
                                                status=stack.status,
                                                reason=stack.status_reason)
        else:
            return False
Example #6
0
 def test_node_delete_resource_status_error(self, mock_delete, mock_status,
                                            mock_handle_exception):
     ex = exception.ResourceStatusError(resource_id='id',
                                        status='ERROR',
                                        reason='some reason')
     mock_delete.side_effect = ex
     node = nodem.Node('node1', self.profile.id, self.cluster.id,
                       self.context)
     node.physical_id = 'fake_id'
     res = node.do_delete(self.context)
     self.assertFalse(res)
     mock_delete.assert_called_once_with(self.context, node)
     mock_handle_exception.assert_called_once_with(self.context, 'delete',
                                                   'ERROR', ex)
     mock_status.assert_any_call(self.context,
                                 'ERROR',
                                 reason='Deletion failed')