Exemplo n.º 1
0
 def test_resource_no_impl(self, mock_protection):
     for operation in constants.OPERATION_TYPES:
         kwargs = {}
         if operation == constants.OPERATION_RESTORE:
             kwargs['heat_template'] = restore_heat.HeatTemplate()
             kwargs['restore'] = None
         self._walk_operation(mock_protection, operation, **kwargs)
Exemplo n.º 2
0
 def test_resource_no_impl(self, mock_protection):
     for operation in constants.OPERATION_TYPES:
         heat_template = restore_heat.HeatTemplate() \
             if operation == constants.OPERATION_RESTORE else None
         self._walk_operation(mock_protection,
                              operation,
                              heat_template=heat_template)
Exemplo n.º 3
0
    def execute(self, context, heat_conf):
        LOG.info('Creating Heat template. Target: "%s"' %
                 heat_conf.get('auth_url', '(None)'))
        heat_client = client_factory.ClientFactory.create_client(
            'heat', context=context, **heat_conf)

        heat_template = restore_heat.HeatTemplate()

        return (heat_client, heat_template)
Exemplo n.º 4
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'}
        }

        def _compare_parameters(resource, func, expect_parameters):
            result = fake_operation.all_invokes[resource][func]
            for k, v in expect_parameters.items():
                self.assertEqual(v, result[k])

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

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

            args = kwargs.copy()
            if operation == constants.OPERATION_RESTORE:
                template = restore_heat.HeatTemplate()
                args['kwargs'] = {
                    'heat_template': template,
                    'restore': None,
                    'operation_log': None
                }
            else:
                args['kwargs'] = {
                    'operation_log': None
                }
            kwargs.update(args['kwargs'])

            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, {}))
                args['resource'] = resource
                args['parameters'] = resource_params
                _compare_parameters(resource, 'on_prepare_begin', args)
                _compare_parameters(resource, 'on_prepare_finish', args)
                _compare_parameters(resource, 'on_main', args)
                _compare_parameters(resource, 'on_complete', args)
Exemplo n.º 5
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)
Exemplo n.º 6
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))