def _test_data_model_impl(
            self,
            end_func,
            expected_end_status,
            expected_end_node_counts,
            expected_before_end_func,
            expected_after_end_func,
            expected_after_end_count,
            expected_after_end_runtime_property):

        def node_assertions(num, deploy_num, planned_num):
            node = self.client.nodes.get(deployment.id, 'node1')
            self.assertEqual(node.number_of_instances, num)
            self.assertEqual(node.planned_number_of_instances, planned_num)
            self.assertEqual(node.deploy_number_of_instances, deploy_num)

        _, _, _, deployment = self.put_deployment(
            deployment_id=str(uuid.uuid4()),
            blueprint_file_name='modify1.yaml')

        node_assertions(num=1, deploy_num=1, planned_num=1)

        mock_context = {'some': 'data'}

        node1_instance = self.client.node_instances.list(
            deployment_id=deployment.id, node_name='node1')[0]
        self.client.node_instances.update(
            node1_instance.id,
            runtime_properties={'test': 'before_start'},
            version=0)
        node2_instance = self.client.node_instances.list(
            deployment_id=deployment.id, node_name='node2')[0]
        self.client.node_instances.update(
            node2_instance.id,
            runtime_properties={'test': 'before_start'},
            version=0)

        before_modification = self.list_items(self.client.node_instances.list,
                                              deployment.id)
        modified_nodes = {'node1': {'instances': 2}}
        modification = self.client.deployment_modifications.start(
            deployment.id, nodes=modified_nodes, context=mock_context)
        self.assertEqual(modification.node_instances.before_modification,
                         before_modification)
        self.assertIsNone(modification.ended_at)

        self.client.node_instances.update(
            node1_instance.id,
            runtime_properties={'test': 'after_start'},
            version=1)
        self.client.node_instances.update(
            node2_instance.id,
            runtime_properties={'test': 'after_start'},
            version=1)

        node_assertions(num=1, deploy_num=1, planned_num=2)

        modification_id = modification.id
        self.assertEqual(modification.status,
                         DeploymentModification.STARTED)

        before_end = self.list_items(self.client.node_instances.list,
                                     deployment.id)

        end_func(modification_id)

        after_end = self.list_items(self.client.node_instances.list,
                                    deployment.id)

        node_assertions(**expected_end_node_counts)

        modification = self.client.deployment_modifications.get(
            modification.id)
        self.assertEqual(modification.id, modification_id)
        self.assertEqual(modification.status, expected_end_status)
        self.assertEqual(modification.deployment_id, deployment.id)
        self.assertEqual(modification.modified_nodes, modified_nodes)
        created_at = dateutil.parser.parse(modification.created_at)
        ended_at = dateutil.parser.parse(modification.ended_at)
        self.assertTrue(datetime.now() - timedelta(seconds=5) <=
                        created_at <= ended_at <= datetime.now())
        all_modifications = self.list_items(
            self.client.deployment_modifications.list)
        dep_modifications = self.list_items(
            self.client.deployment_modifications.list,
            deployment_id=deployment.id)
        self.assertEqual(len(dep_modifications), 1)
        self.assertEqual(dep_modifications[0], modification)
        self.assertEqual(all_modifications, dep_modifications)
        self.assertEqual([], self.list_items(
            self.client.deployment_modifications.list,
            deployment_id='i_really_should_not_exist'))
        self.assertEqual(modification.node_instances.before_modification,
                         before_modification)
        self.assertEqual(modification.node_instances.before_rollback,
                         expected_before_end_func(before_end))

        self.assertEqual(after_end,
                         expected_after_end_func(before_modification,
                                                 before_end))

        self.assertEqual(modification.context, mock_context)

        self.assertEqual(expected_after_end_count, len(after_end))

        self.assertEqual(
            self.client.node_instances.get(
                node1_instance.id).runtime_properties['test'],
            expected_after_end_runtime_property)
        self.assertEqual(
            self.client.node_instances.get(
                node2_instance.id).runtime_properties['test'],
            expected_after_end_runtime_property)
dataset/ETHPy150Open cloudify-cosmo/cloudify-manager/rest-service/manager_rest/test/test_modify.py/ModifyTests._test_data_model_impl/original