

def test_action_log_updating(self):

    def check_write_logs_from_receiver(**kwargs):
        task = objects.Task.create({
            'name': kwargs['task_name'],
            'cluster_id': kwargs['cluster_id'],
        })
        action_log_kwargs = {
            'action_group': 'test_cluster_changes',
            'action_name': kwargs['task_name'],
            'action_type': consts.ACTION_TYPES.nailgun_task,
            'additional_info': {
                
            },
            'is_sent': False,
            'cluster_id': task.cluster.id,
            'task_uuid': task.uuid,
            'start_timestamp': datetime.datetime.now(),
        }
        al = objects.ActionLog.create(action_log_kwargs)
        rpc_resp_kwargs = {
            'task_uuid': task.uuid,
            'status': kwargs['task_status'],
            'nodes': [{
                'uid': node_id,
                'status': kwargs['status_for_nodes'],
                'progress': 100,
            } for node_id in kwargs['node_ids']],
        }
        kwargs['rpc_resp'](**rpc_resp_kwargs)
        self.db.flush()
        self.db.refresh(al)
        self.assertIsNotNone(al.end_timestamp)
        self.assertIn('nodes_from_resp', al.additional_info)
        self.assertEqual(set(al.additional_info['nodes_from_resp']), set(kwargs['node_ids']))
        self.assertEqual(kwargs['task_status'], al.additional_info.get('ended_with_status'))
        self.db.delete(task)
        self.db.delete(al)
        self.db.commit()
    cluster = self.env.create(nodes_kwargs=[{
        'api': False,
    }, {
        'api': False,
    }])
    (node, node2) = self.env.nodes
    test_cases_kwargs = [{
        'task_name': consts.TASK_NAMES.provision,
        'task_status': consts.TASK_STATUSES.ready,
        'status_for_nodes': consts.NODE_STATUSES.provisioned,
        'rpc_resp': self.receiver.provision_resp,
    }, {
        'task_name': 'deployment',
        'task_status': consts.TASK_STATUSES.error,
        'status_for_nodes': consts.NODE_STATUSES.error,
        'rpc_resp': self.receiver.deploy_resp,
    }]
    for kw in test_cases_kwargs:
        kw['cluster_id'] = cluster.id
        kw['node_ids'] = [node.id, node2.id]
        check_write_logs_from_receiver(**kw)

dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/test/integration/test_rpc_consumer.py TestConsumer.test_action_log_updating/original