示例#1
0
    def test_resource_flow_callbacks(self, mock_protection):
        for operation in constants.OPERATION_TYPES:
            mock_operation = fakes.MockOperation()
            get_operation_attr = 'get_{}_operation'.format(operation)
            getattr(
                mock_protection,
                get_operation_attr
            ).return_value = mock_operation

            kwargs = {}
            if operation == constants.OPERATION_RESTORE:
                kwargs['new_resources'] = {}
                kwargs['restore'] = None
            elif operation == constants.OPERATION_VERIFY:
                kwargs['new_resources'] = {}
                kwargs['verify'] = None
            elif operation == constants.OPERATION_COPY:
                kwargs['checkpoint_copy'] = None
            self._walk_operation(mock_protection, operation, **kwargs)

            self.assertEqual(mock_operation.on_prepare_begin.call_count,
                             len(self.resource_graph))
            self.assertEqual(mock_operation.on_prepare_finish.call_count,
                             len(self.resource_graph))
            self.assertEqual(mock_operation.on_main.call_count,
                             len(self.resource_graph))
            self.assertEqual(mock_operation.on_complete.call_count,
                             len(self.resource_graph))
    def test_resource_flow_order(self, mock_protection):
        def test_order(order_list, hook_type, resource, *args, **kwargs):
            order_list.append((hook_type, resource.id))

        operation = constants.OPERATION_PROTECT
        mock_operation = fakes.MockOperation()
        get_operation_attr = 'get_{}_operation'.format(operation)
        getattr(mock_protection, get_operation_attr).return_value = \
            mock_operation

        order_list = []
        mock_operation.on_prepare_begin = partial(test_order, order_list,
                                                  'pre_begin')
        mock_operation.on_prepare_finish = partial(test_order, order_list,
                                                   'pre_finish')
        mock_operation.on_main = partial(test_order, order_list, 'main')
        mock_operation.on_complete = partial(test_order, order_list,
                                             'complete')

        self._walk_operation(mock_protection, operation)

        self.assertTrue(
            order_list.index(('pre_begin', parent.id)) < order_list.index((
                'pre_begin', child.id)))
        self.assertTrue(
            order_list.index(('pre_begin', child.id)) < order_list.index((
                'pre_begin', grandchild.id)))

        self.assertTrue(
            order_list.index(('pre_finish', parent.id)) > order_list.index((
                'pre_finish', child.id)))
        self.assertTrue(
            order_list.index(('pre_finish', child.id)) > order_list.index((
                'pre_finish', grandchild.id)))

        self.assertTrue(
            order_list.index(('complete', parent.id)) > order_list.index((
                'complete', child.id)))
        self.assertTrue(
            order_list.index(('complete', child.id)) > order_list.index((
                'complete', grandchild.id)))

        for resource_id in (parent.id, child.id, grandchild.id):
            self.assertTrue(
                order_list.index(('pre_begin',
                                  resource_id)) < order_list.index((
                                      'pre_finish', resource_id)))
            self.assertTrue(
                order_list.index(('pre_finish', resource_id
                                  )) < order_list.index(('main', resource_id)))
            self.assertTrue(
                order_list.index(('main', resource_id)) < order_list.index((
                    'complete', resource_id)))
示例#3
0
    def test_resource_flow_parameters(self, mock_protection):
        resource_a1_id = "{}#{}".format(parent_type, 'A1')
        resource_b1_id = "{}#{}".format(child_type, 'B1')
        parameters = {
            resource_a1_id: {
                'option1': 'value1'
            },
            resource_b1_id: {
                'option2': 'value2',
                'option3': 'value3'
            },
            parent_type: {
                'option4': 'value4'
            },
            child_type: {
                'option3': 'value5'
            }
        }

        for operation in constants.OPERATION_TYPES:
            mock_operation = fakes.MockOperation()
            get_operation_attr = 'get_{}_operation'.format(operation)
            getattr(mock_protection,
                    get_operation_attr).return_value = mock_operation

            kwargs = {
                'checkpoint': 'A',
                'context': 'B',
            }

            if operation == constants.OPERATION_RESTORE:
                kwargs['heat_template'] = restore_heat.HeatTemplate()
                kwargs['restore'] = None

            self._walk_operation(mock_protection,
                                 operation,
                                 parameters=parameters,
                                 **kwargs)

            for resource in self.resource_graph:
                resource_params = parameters.get(resource.type, {})
                resource_id = '{}#{}'.format(resource.type, resource.id)
                resource_params.update(parameters.get(resource_id, {}))
                mock_operation.on_prepare_begin.assert_any_call(
                    resource=resource, parameters=resource_params, **kwargs)
                mock_operation.on_prepare_finish.assert_any_call(
                    resource=resource, parameters=resource_params, **kwargs)
                mock_operation.on_main.assert_any_call(
                    resource=resource, parameters=resource_params, **kwargs)
                mock_operation.on_complete.assert_any_call(
                    resource=resource, parameters=resource_params, **kwargs)
示例#4
0
    def test_resource_flow_callbacks(self, mock_protection):
        for operation in constants.OPERATION_TYPES:
            mock_operation = fakes.MockOperation()
            get_operation_attr = 'get_{}_operation'.format(operation)
            getattr(mock_protection,
                    get_operation_attr).return_value = mock_operation

            kwargs = {}
            if operation == constants.OPERATION_RESTORE:
                kwargs['heat_template'] = restore_heat.HeatTemplate()
                kwargs['restore'] = None
            self._walk_operation(mock_protection, operation, **kwargs)

            self.assertEqual(mock_operation.on_prepare_begin.call_count,
                             len(self.resource_graph))
            self.assertEqual(mock_operation.on_prepare_finish.call_count,
                             len(self.resource_graph))
            self.assertEqual(mock_operation.on_main.call_count,
                             len(self.resource_graph))
            self.assertEqual(mock_operation.on_complete.call_count,
                             len(self.resource_graph))