예제 #1
0
 def _get_deserialized_ack_report_computed_task(
     self,
     task_to_compute: TaskToCompute,
     timestamp: Union[str, datetime.datetime, None] = None,
     deadline: Union[str, int, None] = None,
     subtask_id: str = '1',
     report_computed_task: Optional[ReportComputedTask] = None,
     signer_private_key: Optional[bytes] = None,
 ) -> AckReportComputedTask:
     """ Returns AckReportComputedTask deserialized. """
     with freeze_time(timestamp or get_timestamp_string()):
         ack_report_computed_task = message.AckReportComputedTask(
             report_computed_task=(
                 report_computed_task if report_computed_task is not None
                 else self._get_deserialized_report_computed_task(
                     task_to_compute=(task_to_compute or self.
                                      _get_deserialized_task_to_compute(
                                          timestamp=timestamp,
                                          deadline=deadline,
                                          subtask_id=subtask_id)), )))
     if signer_private_key is not None:
         ack_report_computed_task = self._sign_message(
             ack_report_computed_task,
             signer_private_key,
         )
     return ack_report_computed_task
예제 #2
0
    def test_send_should_return_http_400_if_task_to_compute_deadline_exceeded(self):
        compute_task_def = message.ComputeTaskDef()
        compute_task_def['task_id'] = '8'
        compute_task_def['deadline'] = self.message_timestamp - 9000

        with freeze_time(datetime.datetime.fromtimestamp(self.message_timestamp - 10000)):
            task_to_compute = tasks.TaskToComputeFactory(
                compute_task_def     = self.compute_task_def,
                provider_public_key  = PROVIDER_PUBLIC_KEY,
                requestor_public_key = REQUESTOR_PUBLIC_KEY,
                price=0,
            )

        serialized_task_to_compute      = dump(task_to_compute,             REQUESTOR_PRIVATE_KEY,   PROVIDER_PUBLIC_KEY)
        deserialized_task_to_compute    = load(serialized_task_to_compute,  PROVIDER_PRIVATE_KEY,  REQUESTOR_PUBLIC_KEY, check_time = False)

        ack_report_computed_task = message.AckReportComputedTask()
        ack_report_computed_task.report_computed_task = message.ReportComputedTask(
            task_to_compute = deserialized_task_to_compute
        )

        response_400 = self.client.post(
            reverse('core:send'),
            data = dump(
                ack_report_computed_task,
                PROVIDER_PRIVATE_KEY,
                CONCENT_PUBLIC_KEY
            ),
            content_type                    = 'application/octet-stream',
        )

        self._test_400_response(
            response_400,
            error_code=ErrorCode.QUEUE_COMMUNICATION_NOT_STARTED
        )
def ack_report_computed_task(timestamp=None, report_computed_task=None):
    with freeze_time(timestamp):
        return sign_message(
            message.AckReportComputedTask(
                report_computed_task=report_computed_task, ),
            REQUESTOR_PRIVATE_KEY,
        )
예제 #4
0
파일: utils.py 프로젝트: etsangsplk/concent
 def _get_deserialized_ack_report_computed_task(
     self,
     timestamp       = None,
     deadline        = None,
     subtask_id      = '1',
     report_computed_task = None,
     task_to_compute = None
 ):
     """ Returns AckReportComputedTask deserialized. """
     with freeze_time(timestamp or self._get_timestamp_string()):
         ack_report_computed_task = message.AckReportComputedTask(
             report_computed_task = (
                 report_computed_task if report_computed_task is not None else message.ReportComputedTask(
                     task_to_compute = (
                         task_to_compute or
                         self._get_deserialized_task_to_compute(
                             timestamp = timestamp,
                             deadline  = deadline,
                             subtask_id=subtask_id
                         )
                     ),
                 )
             )
         )
     return ack_report_computed_task
예제 #5
0
    def setUp(self):
        super().setUp()

        compute_task_def = message.ComputeTaskDef()
        task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=compute_task_def)
        serialized_task_to_compute = dump(task_to_compute,
                                          REQUESTOR_PRIVATE_KEY,
                                          PROVIDER_PUBLIC_KEY)
        deserialized_task_to_compute = load(serialized_task_to_compute,
                                            PROVIDER_PRIVATE_KEY,
                                            REQUESTOR_PUBLIC_KEY,
                                            check_time=False)

        self.ack_report_computed_task = message.AckReportComputedTask()
        self.ack_report_computed_task.report_computed_task = message.ReportComputedTask(
            task_to_compute=deserialized_task_to_compute)
예제 #6
0
    def setUp(self):
        super().setUp()
        self.compute_task_def = message.ComputeTaskDef()
        self.compute_task_def['task_id'] = '1'
        self.compute_task_def['subtask_id'] = '1'
        self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60
        self.task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            provider_public_key=PROVIDER_PUBLIC_KEY,
            requestor_public_key=REQUESTOR_PUBLIC_KEY,
            price=0,
        )
        self.size = 58

        with freeze_time("2017-11-17 10:00:00"):
            self.force_golem_data = message.ForceReportComputedTask(
                report_computed_task=message.tasks.ReportComputedTask(
                    task_to_compute=self.task_to_compute, size=self.size))
        message_timestamp = datetime.datetime.now(timezone.utc)
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        new_message.full_clean()
        new_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.TYPE,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.AckReportComputedTask(
            report_computed_task=message.tasks.ReportComputedTask(
                task_to_compute=self.task_to_compute, ))

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(public_key_bytes=PROVIDER_PUBLIC_KEY)
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(public_key_bytes=REQUESTOR_PUBLIC_KEY)
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id=self.compute_task_def['task_id'],
            subtask_id=self.compute_task_def['subtask_id'],
            report_computed_task=new_message,
            task_to_compute=task_to_compute_message,
            ack_report_computed_task=stored_ack_report_computed_task,
            state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider=client_provider,
            requestor=client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(
                self.compute_task_def['deadline']))
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.
            name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()
예제 #7
0
    def test_receive_should_return_first_messages_in_order_they_were_added_to_queue_if_the_receive_queue_contains_only_force_report_and_its_past_deadline(
            self):
        message_timestamp = datetime.datetime.now(timezone.utc)
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        new_message.full_clean()
        new_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.TYPE,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.AckReportComputedTask(
            report_computed_task=message.ReportComputedTask(
                task_to_compute=self.task_to_compute, ))

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(public_key_bytes=PROVIDER_PUBLIC_KEY)
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(public_key_bytes=REQUESTOR_PUBLIC_KEY)
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id=self.compute_task_def['task_id'],
            subtask_id=self.compute_task_def['subtask_id'],
            report_computed_task=new_message,
            task_to_compute=task_to_compute_message,
            ack_report_computed_task=stored_ack_report_computed_task,
            state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider=client_provider,
            requestor=client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(
                self.compute_task_def['deadline']))
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.
            name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.Receive.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()

        new_message_inbox_out_of_band = PendingResponse(
            response_type=PendingResponse.ResponseType.
            VerdictReportComputedTask.name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox_out_of_band.full_clean()
        new_message_inbox_out_of_band.save()

        with freeze_time("2017-11-17 12:00:00"):
            response = self.client.post(
                reverse('core:receive'),
                content_type='application/octet-stream',
                data=self._create_client_auth_message(REQUESTOR_PRIVATE_KEY,
                                                      REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
            check_time=False,
        )

        self.assertIsInstance(decoded_message,
                              message.concents.ForceReportComputedTask)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            decoded_message.timestamp,
            int(dateutil.parser.parse("2017-11-17 12:00:00").timestamp()))
        self.assertEqual(decoded_message.report_computed_task.task_to_compute.
                         compute_task_def,
                         self.task_to_compute.compute_task_def)  # pylint: disable=no-member
        self.assertEqual(
            decoded_message.report_computed_task.task_to_compute.sig,
            self.task_to_compute.sig)

        with freeze_time("2017-11-17 12:00:00"):
            response = self.client.post(
                reverse('core:receive_out_of_band'),
                content_type='application/octet-stream',
                data=self._create_client_auth_message(REQUESTOR_PRIVATE_KEY,
                                                      REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
            check_time=False,
        )

        self.assertIsInstance(decoded_message,
                              message.concents.VerdictReportComputedTask)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            decoded_message.timestamp,
            int(dateutil.parser.parse("2017-11-17 12:00:00").timestamp()))
        self.assertEqual(decoded_message.ack_report_computed_task.
                         report_computed_task.task_to_compute.compute_task_def,
                         self.task_to_compute.compute_task_def)  # pylint: disable=no-member
        self.assertEqual(
            decoded_message.ack_report_computed_task.report_computed_task.
            task_to_compute.sig, self.task_to_compute.sig)
예제 #8
0
def ack_report_computed_task(timestamp=None, report_computed_task=None):
    with freeze_time(timestamp):
        return message.AckReportComputedTask(
            report_computed_task=report_computed_task, )