Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State diagrams #432

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
09eda83
Fix for rejecting ForceGetTaskResult that comes too early
Jun 11, 2018
93db558
Update tests after fixing rejecting ForceGetTaskResult that comes too…
Jun 11, 2018
7e67384
Fix for making right side of time window acceptance use case closed
Jun 11, 2018
d25c06a
Fix for rejecting SubtaskResultsVerify that comes too early
Jun 11, 2018
159f266
Add test for rejecting SubtaskResultsVerify that comes too early
Jun 11, 2018
56d88f9
Add test for rejecting ForceGetTaskResult that comes too early
Jun 11, 2018
4239e1a
Fix for force-get-task-result cluster test after fixing checking time…
Jun 13, 2018
66b8418
Fix Static Files Collecting
wyspiansky87 Jun 13, 2018
0066766
Move checksum validation to separate function
Jakub89 Jun 12, 2018
b72a5d4
Move HashingAlgorithm class from gatekeeper to core module
Jakub89 Jun 13, 2018
76db34c
Add check for golem_messages.message.tasks.TaskMessage if it 'is_vali…
Jakub89 Jun 12, 2018
2de6639
Add package_hash validation for FRCT and TTC messages
Jakub89 Jun 12, 2018
81829d9
Transfer verification_result from verifier to core
kbeker Jun 13, 2018
5f7a332
Change celery settings
kbeker Jun 13, 2018
99e86da
Transfer tests for verification_result function from verifier to core
kbeker Jun 13, 2018
13afe89
Change imports in verifier test after transfer verification_result fu…
kbeker Jun 13, 2018
d55004d
Add next_deadline as parameter to update_subtask_state function
kbeker Jun 13, 2018
357fc24
Add SVT time to next_deadline in ADDITIONAL_VERIFICATION state
kbeker Jun 13, 2018
cd4ba5b
Switch ReportComputedTask massage creation to golem factories in api-…
Jakub89 Jun 14, 2018
51629e6
Fix for report_upload view in conductor to require POST HTTP method
Jun 15, 2018
d70ea97
Fix for missing check before scheduling upload_finished task
Jun 14, 2018
e338a30
Fix for http method used for calls to report-upload endpoint in tests
Jun 15, 2018
82428d4
Add decorator for logging
Jun 13, 2018
9add105
Improve current logging system in core receive
Jun 14, 2018
c43b411
Fix handling of ForceSubtaskResultsResponse
Jun 18, 2018
ee93452
Fix for logging warning when VerificationRequest is already acknowled…
Jun 15, 2018
4234ded
Add ADDITIONAL_VERIFICATION_CALL_TIME to protocol constants
May 19, 2018
86ff4ab
Add cluster test for additional verification use case
May 20, 2018
d3b2907
Change default value for parameters in funciton to create signed task…
kbeker Jun 19, 2018
eacdf03
Add concent crash logger to django settings
Jun 14, 2018
71fd04f
Verifier: uploading rendering result to the storage server
Apr 24, 2018
aa39075
Remove unnecessary upload_file_to_storage_cluster function from clust…
Jun 19, 2018
465cdde
Add _create_datetime_from_string utilty function
Jun 19, 2018
7953780
Add handling for VERIFICATION_FILE_TRANSFER state
Jun 15, 2018
b31b8f1
Add log_task_errors decorator
Jun 18, 2018
e5906bf
Add test for log_task_errors decorator
Jun 18, 2018
51569ab
Add usage of log_task_errors decorator
Jun 18, 2018
b3776b5
Merge branch 'feature-reporting-worker-errors-to-sentry'
Jun 19, 2018
b7f325e
Fix for returning HTML on 5xx errors when Accept header is */*
Jun 18, 2018
8740b7a
Merge branch 'fix-5xx-errors-are-returned-as5-html-by-default'
Jun 19, 2018
125d006
Add logging in verifier
Jun 19, 2018
cc6b51b
Add logging in conductor wiews
Jun 19, 2018
3c6e67f
Add logging in conductor tasks
Jun 19, 2018
eccbd6a
Unify logging keys
Jun 19, 2018
af2efee
Merge branch 'feature-more-logging-in-conductor-verifier-and-workers'
kbeker Jun 20, 2018
88426e1
Refactor log_string_message and log_error_message
Jun 20, 2018
a0aa853
Merge pull request #526 from golemfactory/chore-refactor-logging-func…
kbeker Jun 20, 2018
806c027
Feature wrap all Celery tasks in transactions
Jun 18, 2018
46a7605
Merge branch 'feature-wrap-all-celery-tasks-in-transactions'
Jun 20, 2018
35d9c6f
Diagrams of possible internal states of Concent (simple and detailed …
cameel Feb 15, 2018
6416d75
fixup! Diagrams of possible internal states of Concent (simple and de…
cameel Jun 21, 2018
749d984
State diagrams: Additional state for file upload in additional verifi…
cameel Feb 20, 2018
fcf7ce5
State diagrams: In acceptance phase requestor submits ForceSubtaskRes…
cameel Feb 22, 2018
8b4a40f
State diagrams: Add acceptance timeout to detailed state diagram
cameel Mar 6, 2018
1dc1719
State diagrams: Make time inequalities consistent on the detailed dia…
cameel Mar 6, 2018
a866c28
State diagrams: Add missing state transition for the case where Conce…
cameel Mar 7, 2018
dff90d3
State diagrams: Use bridges to intersecting lines on exported state d…
cameel Mar 22, 2018
f42d09b
State diagrams: Add short description of used elements to the detaile…
cameel Jun 6, 2018
3162b82
fixup! State diagrams: Add short description of used elements to the …
cameel Jun 7, 2018
b0424b9
State diagrams: Make timeout conditions mutually exclusive with other…
cameel Jun 7, 2018
ebb131d
State diagrams: Update conditions to match specification changes
cameel Jun 7, 2018
8250795
fixup! State diagrams: Update conditions to match specification changes
cameel Jun 21, 2018
422710e
State diagrams: The arrow between VERIFICATION FILE TRANSFER and ADDI…
cameel Jun 7, 2018
712e8a7
State diagrams: Fix the name of ForceSubtaskResultsResponse on the de…
cameel Jun 7, 2018
3e0e4ff
State diagrams: Add missing conditions for SubtaskResultsVerify on th…
cameel Jun 7, 2018
8ab30a4
fixup! State diagrams: Add missing conditions for SubtaskResultsVerif…
cameel Jun 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions api-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

printf "=================== RUNNING API INTEGRATION TESTS ====================\n"
python3 concent_api/api-integration-force-accept-or-reject-results-test.py $1 &&
python3 concent_api/api-integration-force-get-task-result-test.py $1 &&
python3 concent_api/api-integration-force-payment.py $1 &&
python3 concent_api/api-integration-force-accept-or-reject-results-test.py $1
python3 concent_api/api-integration-force-get-task-result-test.py $1
python3 concent_api/api-integration-force-payment.py $1
python3 concent_api/api-integration-force-report-computed-task-test.py $1
python3 concent_api/api-integration-additional-verification-test.py $1
356 changes: 356 additions & 0 deletions concent_api/api-integration-additional-verification-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,356 @@
#!/usr/bin/env python3

import hashlib
import os
import sys
import time
from freezegun import freeze_time

from golem_messages import message

from utils.helpers import get_current_utc_timestamp
from utils.helpers import upload_file_to_storage_cluster
from api_testing_common import api_request
from api_testing_common import assert_condition
from api_testing_common import count_fails
from api_testing_common import create_client_auth_message
from api_testing_common import create_signed_task_to_compute
from api_testing_common import get_task_id_and_subtask_id
from api_testing_common import PROVIDER_PRIVATE_KEY
from api_testing_common import PROVIDER_PUBLIC_KEY
from api_testing_common import REQUESTOR_PRIVATE_KEY
from api_testing_common import REQUESTOR_PUBLIC_KEY
from api_testing_common import run_tests
from api_testing_common import timestamp_to_isoformat

import requests

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "concent_api.settings")

# TODO NEGATIVE TEST CASES


def get_subtask_results_verify(
task_id,
subtask_id,
current_time,
cluster_consts,
reason,
report_computed_task_size,
report_computed_task_package_hash,
task_to_compute_size,
task_to_compute_package_hash,
requestor_ethereum_public_key=None,
provider_ethereum_public_key=None,
price=1,
):
task_to_compute = create_signed_task_to_compute(
task_id=task_id,
subtask_id=subtask_id,
deadline=current_time + cluster_consts.additional_verification_call_time,
price=price if price is not None else 1,
size=task_to_compute_size,
package_hash=task_to_compute_package_hash,
requestor_ethereum_public_key=requestor_ethereum_public_key,
provider_ethereum_public_key=provider_ethereum_public_key
)

report_computed_task = message.ReportComputedTask(
task_to_compute=task_to_compute,
subtask_id=subtask_id,
size=report_computed_task_size,
package_hash=report_computed_task_package_hash,
)
report_computed_task.sign_message(
PROVIDER_PRIVATE_KEY,
report_computed_task.get_short_hash()
)

with freeze_time(timestamp_to_isoformat(current_time - 10)):
subtask_results_rejected = message.tasks.SubtaskResultsRejected(
reason=reason,
report_computed_task=report_computed_task,
)
subtask_results_rejected.sign_message(
REQUESTOR_PRIVATE_KEY,
subtask_results_rejected.get_short_hash(),
)

subtask_results_verify = message.concents.SubtaskResultsVerify(
subtask_results_rejected=subtask_results_rejected,
)

return subtask_results_verify


@count_fails
def test_case_1_test_for_positive_case(cluster_consts, cluster_url, test_id):
current_time = get_current_utc_timestamp()
(subtask_id, task_id) = get_task_id_and_subtask_id(test_id, 'existing_file')

result_file_content_1 = task_id
source_file_content_2 = subtask_id
result_file_size_1 = len(result_file_content_1)
source_file_size_2 = len(source_file_content_2)
result_file_check_sum_1 = 'sha1:' + hashlib.sha1(result_file_content_1.encode()).hexdigest()
source_file_check_sum_2 = 'sha1:' + hashlib.sha1(source_file_content_2.encode()).hexdigest()

ack_subtask_results_verify = api_request(
cluster_url,
'send',
PROVIDER_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
get_subtask_results_verify(
task_id,
subtask_id,
current_time,
cluster_consts,
reason=message.tasks.SubtaskResultsRejected.REASON.VerificationNegative,
report_computed_task_size=result_file_size_1,
report_computed_task_package_hash=result_file_check_sum_1,
task_to_compute_size=source_file_size_2,
task_to_compute_package_hash=source_file_check_sum_2,
),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.AckSubtaskResultsVerify.TYPE,
expected_content_type='application/octet-stream',
)

response = upload_file_to_storage_cluster(
result_file_content_1,
ack_subtask_results_verify.file_transfer_token.files[0]['path'],
ack_subtask_results_verify.file_transfer_token,
PROVIDER_PRIVATE_KEY,
PROVIDER_PUBLIC_KEY,
)
assert_condition(response.status_code, 200, 'File has not been stored on cluster')
print('\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'.format(
task_id,
result_file_check_sum_1,
result_file_size_1
))

response = upload_file_to_storage_cluster(
source_file_content_2,
ack_subtask_results_verify.file_transfer_token.files[1]['path'],
ack_subtask_results_verify.file_transfer_token,
PROVIDER_PRIVATE_KEY,
PROVIDER_PUBLIC_KEY,
)
assert_condition(response.status_code, 200, 'File has not been stored on cluster')
print('\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'.format(
task_id,
source_file_check_sum_2,
source_file_size_2
))

time.sleep(10)

api_request(
cluster_url,
'receive-out-of-band',
REQUESTOR_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.SubtaskResultsSettled.TYPE,
expected_content_type='application/octet-stream',
)

api_request(
cluster_url,
'receive-out-of-band',
PROVIDER_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.SubtaskResultsSettled.TYPE,
expected_content_type='application/octet-stream',
)


@count_fails
def test_case_2_test_for_resources_failure_reason(cluster_consts, cluster_url, test_id):
current_time = get_current_utc_timestamp()
(subtask_id, task_id) = get_task_id_and_subtask_id(test_id, 'existing_file')

file_content = task_id
file_size = len(file_content)
file_check_sum = 'sha1:' + hashlib.sha1(file_content.encode()).hexdigest()

api_request(
cluster_url,
'send',
PROVIDER_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
get_subtask_results_verify(
task_id,
subtask_id,
current_time,
cluster_consts,
reason=message.tasks.SubtaskResultsRejected.REASON.ResourcesFailure,
report_computed_task_size=file_size,
report_computed_task_package_hash=file_check_sum,
task_to_compute_size=file_size,
task_to_compute_package_hash=file_check_sum,
),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.ServiceRefused.TYPE,
expected_content_type='application/octet-stream',
)


@count_fails
def test_case_3_test_for_invalid_time(cluster_consts, cluster_url, test_id):
current_time = get_current_utc_timestamp()
(subtask_id, task_id) = get_task_id_and_subtask_id(test_id, 'existing_file')

file_content = task_id
file_size = len(file_content)
file_check_sum = 'sha1:' + hashlib.sha1(file_content.encode()).hexdigest()

api_request(
cluster_url,
'send',
PROVIDER_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
get_subtask_results_verify(
task_id,
subtask_id,
current_time - 2 * cluster_consts.additional_verification_call_time,
cluster_consts,
reason=message.tasks.SubtaskResultsRejected.REASON.VerificationNegative,
report_computed_task_size=file_size,
report_computed_task_package_hash=file_check_sum,
task_to_compute_size=file_size,
task_to_compute_package_hash=file_check_sum,
),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.ServiceRefused.TYPE,
expected_content_type='application/octet-stream',
)


@count_fails
def test_case_4_test_for_duplicated_request(cluster_consts, cluster_url, test_id):
current_time = get_current_utc_timestamp()
(subtask_id, task_id) = get_task_id_and_subtask_id(test_id, 'existing_file')

result_file_content_1 = task_id
source_file_content_2 = subtask_id
result_file_size_1 = len(result_file_content_1)
source_file_size_2 = len(source_file_content_2)
result_file_check_sum_1 = 'sha1:' + hashlib.sha1(result_file_content_1.encode()).hexdigest()
source_file_check_sum_2 = 'sha1:' + hashlib.sha1(source_file_content_2.encode()).hexdigest()

api_request(
cluster_url,
'send',
PROVIDER_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
get_subtask_results_verify(
task_id,
subtask_id,
current_time,
cluster_consts,
reason=message.tasks.SubtaskResultsRejected.REASON.VerificationNegative,
report_computed_task_size=result_file_size_1,
report_computed_task_package_hash=result_file_check_sum_1,
task_to_compute_size=source_file_size_2,
task_to_compute_package_hash=source_file_check_sum_2,
),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.AckSubtaskResultsVerify.TYPE,
expected_content_type='application/octet-stream',
)

api_request(
cluster_url,
'send',
PROVIDER_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
get_subtask_results_verify(
task_id,
subtask_id,
current_time,
cluster_consts,
reason=message.tasks.SubtaskResultsRejected.REASON.VerificationNegative,
report_computed_task_size=result_file_size_1,
report_computed_task_package_hash=result_file_check_sum_1,
task_to_compute_size=source_file_size_2,
task_to_compute_package_hash=source_file_check_sum_2,
),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.ServiceRefused.TYPE,
expected_content_type='application/octet-stream',
)


@count_fails
def test_case_5_test_requestor_status_account_negative(cluster_consts, cluster_url, test_id):
current_time = get_current_utc_timestamp()
(subtask_id, task_id) = get_task_id_and_subtask_id(test_id, 'existing_file')

result_file_content_1 = task_id
source_file_content_2 = subtask_id
result_file_size_1 = len(result_file_content_1)
source_file_size_2 = len(source_file_content_2)
result_file_check_sum_1 = 'sha1:' + hashlib.sha1(result_file_content_1.encode()).hexdigest()
source_file_check_sum_2 = 'sha1:' + hashlib.sha1(source_file_content_2.encode()).hexdigest()

api_request(
cluster_url,
'send',
PROVIDER_PRIVATE_KEY,
CONCENT_PUBLIC_KEY,
get_subtask_results_verify(
task_id,
subtask_id,
current_time,
cluster_consts,
reason=message.tasks.SubtaskResultsRejected.REASON.VerificationNegative,
report_computed_task_size=result_file_size_1,
report_computed_task_package_hash=result_file_check_sum_1,
task_to_compute_size=source_file_size_2,
task_to_compute_package_hash=source_file_check_sum_2,
requestor_ethereum_public_key='33' * 64,
provider_ethereum_public_key='32' * 64,
price=0
),
headers = {
'Content-Type': 'application/octet-stream',
},
expected_status=200,
expected_message_type=message.concents.ServiceRefused.TYPE,
expected_content_type='application/octet-stream',
)


if __name__ == '__main__':
try:
from concent_api.settings import CONCENT_PUBLIC_KEY
run_tests(globals())
except requests.exceptions.ConnectionError as exception:
print("\nERROR: Failed connect to the server.\n", file=sys.stderr)
sys.exit(str(exception))
Loading