Esempio n. 1
0
def verify_file_status(subtask: Subtask, client_public_key: bytes) -> None:
    """
     It is checked only when client is a requestor and subtask's state is FORCING_RESULT_TRANSFER.
    """
    if (subtask.state_enum == Subtask.SubtaskState.FORCING_RESULT_TRANSFER
            and subtask.requestor.public_key_bytes == client_public_key
            and subtask.result_upload_finished):
        subtask.state = Subtask.SubtaskState.RESULT_UPLOADED.name  # pylint: disable=no-member
        subtask.next_deadline = None
        subtask.full_clean()
        subtask.save()

        store_pending_message(
            response_type=PendingResponse.ResponseType.
            ForceGetTaskResultDownload,
            client_public_key=subtask.requestor.public_key_bytes,
            queue=PendingResponse.Queue.Receive,
            subtask=subtask,
        )
        logging.log(
            logger,
            f'File assigned to TASK_ID: {subtask.task_id} is already uploaded '
            f'REQUESTOR PUBLIC KEY: {subtask.requestor.public_key} '
            f'PROVIDER PUBLIC KEY {subtask.provider.public_key}',
            subtask_id=subtask.subtask_id)
Esempio n. 2
0
    def test_that_if_stored_messages_have_incompatible_protocol_version_function_should_return_false(
            self):
        with override_settings(
                GOLEM_MESSAGES_VERSION='1.11.1',
                MAJOR_MINOR_GOLEM_MESSAGES_VERSION='1.11',
        ):
            subtask = Subtask(
                task_id=self.task_to_compute.compute_task_def['task_id'],
                subtask_id=self.task_to_compute.compute_task_def['subtask_id'],
                provider=self.provider,
                requestor=self.requestor,
                result_package_size=self.size,
                state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
                next_deadline=None,
                computation_deadline=parse_timestamp_to_utc_datetime(
                    self.compute_task_def['deadline']),
                task_to_compute=store_message(self.task_to_compute,
                                              self.task_id, self.subtask_id),
                want_to_compute_task=store_message(
                    self.task_to_compute.want_to_compute_task, self.task_id,
                    self.subtask_id),
                report_computed_task=store_message(self.report_computed_task,
                                                   self.task_id,
                                                   self.subtask_id),
                protocol_version=settings.MAJOR_MINOR_GOLEM_MESSAGES_VERSION,
            )
            subtask.full_clean()
            subtask.save()

        self.assertFalse(
            is_protocol_version_compatible(
                subtask.task_to_compute.protocol_version, ))
Esempio n. 3
0
    def test_that_if_stored_messages_are_compatible_with_protocol_version_function_should_return_true(
            self):
        subtask = Subtask(
            task_id=self.task_to_compute.compute_task_def['task_id'],
            subtask_id=self.task_to_compute.compute_task_def['subtask_id'],
            provider=self.provider,
            requestor=self.requestor,
            result_package_size=self.size,
            state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            next_deadline=None,
            computation_deadline=parse_timestamp_to_utc_datetime(
                self.compute_task_def['deadline']),
            task_to_compute=store_message(self.task_to_compute, self.task_id,
                                          self.subtask_id),
            want_to_compute_task=store_message(
                self.task_to_compute.want_to_compute_task, self.task_id,
                self.subtask_id),
            report_computed_task=store_message(self.report_computed_task,
                                               self.task_id, self.subtask_id),
        )
        subtask.full_clean()
        subtask.save()

        self.assertTrue(
            is_protocol_version_compatible(
                subtask.task_to_compute.protocol_version, ))
Esempio n. 4
0
def update_subtask_state(subtask: Subtask, state: str, next_deadline: Union[int, float, None] = None) -> None:
    old_state = subtask.state
    subtask.state = state
    subtask.next_deadline = None if next_deadline is None else parse_timestamp_to_utc_datetime(next_deadline)
    subtask.full_clean()
    subtask.save()

    log(
        logger,
        f'Subtask changed its state from {old_state} to {subtask.state}',
        subtask_id=subtask.subtask_id
    )
Esempio n. 5
0
    def setUp(self):
        super().setUp()
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60
        self.want_to_compute_task = WantToComputeTaskFactory(
            node_name=1,
            task_id=self._get_uuid(),
            perf_index=3,
            price=4,
            max_resource_size=5,
            max_memory_size=6,
            num_cores=7,
        )
        self.task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            want_to_compute_task=self.want_to_compute_task,
            provider_public_key=self._get_provider_hex_public_key(),
            requestor_public_key=self._get_requestor_hex_public_key(),
        )
        self.size = 58

        with freeze_time("2017-11-17 10:00:00"):
            self.report_computed_task = message.tasks.ReportComputedTask(
                task_to_compute=self.task_to_compute,
                size=self.size
            )
            self.force_golem_data = message.concents.ForceReportComputedTask(
                report_computed_task=self.report_computed_task
            )
        message_timestamp = parse_timestamp_to_utc_datetime(get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.tasks.AckReportComputedTask(
            report_computed_task=self.report_computed_task
        )

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

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

        client_requestor = Client(
            public_key_bytes=self.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,
            want_to_compute_task=want_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()
Esempio n. 6
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 = parse_timestamp_to_utc_datetime(get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.tasks.AckReportComputedTask(
            report_computed_task=self.report_computed_task
        )

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

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

        client_requestor = Client(
            public_key_bytes=self.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,
            want_to_compute_task=want_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.send_request(
                url='core:receive',
                data=self._create_client_auth_message(self.REQUESTOR_PRIVATE_KEY, self.REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            self.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, self._create_timestamp_from_string("2017-11-17 12:00:00"))
        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.send_request(
                url='core:receive',
                data=self._create_client_auth_message(self.REQUESTOR_PRIVATE_KEY, self.REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            self.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, self._create_timestamp_from_string("2017-11-17 12:00:00"))
        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)
Esempio n. 7
0
    def test_receive_should_accept_valid_message(self):
        message_timestamp = parse_timestamp_to_utc_datetime(get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

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

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

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.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
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        subtask = Subtask(
            task_id                 = self.compute_task_def['task_id'],
            subtask_id              = self.compute_task_def['subtask_id'],
            task_to_compute         = task_to_compute_message,
            want_to_compute_task=want_to_compute_message,
            report_computed_task    = new_message,
            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()

        response = self.send_request(
            url='core:receive',
            data=self._create_client_auth_message(self.REQUESTOR_PRIVATE_KEY, self.REQUESTOR_PUBLIC_KEY),
        )
        decoded_response = load(
            response.content,
            self.REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(new_message.task_id,
                         decoded_response.report_computed_task.task_to_compute.compute_task_def['task_id'])
        self.assertEqual(new_message.subtask_id,
                         decoded_response.report_computed_task.task_to_compute.compute_task_def['subtask_id'])
Esempio n. 8
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()
Esempio n. 9
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)
Esempio n. 10
0
    def test_receive_should_accept_valid_message(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()

        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()

        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()

        subtask = Subtask(
            task_id=self.compute_task_def['task_id'],
            subtask_id=self.compute_task_def['subtask_id'],
            task_to_compute=task_to_compute_message,
            report_computed_task=new_message,
            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()

        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_response = load(
            response.content,
            REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            new_message.task_id, decoded_response.report_computed_task.
            task_to_compute.compute_task_def['task_id'])
        self.assertEqual(
            new_message.subtask_id, decoded_response.report_computed_task.
            task_to_compute.compute_task_def['subtask_id'])