Skip to content

Commit

Permalink
Refactor python ITs (#583)
Browse files Browse the repository at this point in the history
Closes #581
  • Loading branch information
masokol authored Sep 28, 2023
1 parent a6e5ba6 commit f022699
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
from behave import given, then, when # pylint: disable=no-name-in-module


ID_PATTERN = r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}'
REPAIR_SUMMARY_PATTERN = r'Summary: \d+ completed, \d+ in queue, \d+ blocked, \d+ warning, \d+ error'
REPAIR_HEADER = r'| Id | Host Id | Keyspace | Table | Status | Repaired(%) | Completed at | Repair type |'
REPAIR_ROW_FORMAT_PATTERN = r'\| .* \| .* \| {0} \| {1} \| (COMPLETED|IN_QUEUE|WARNING|ERROR) \| \d+[.]\d+ \| .* \| {2} \|' # pylint: disable=line-too-long


def table_row(template, keyspace, table, repair_type=None):
if repair_type:
return template.format(keyspace, table, repair_type)
return template.format(keyspace, table)


def strip_and_collapse(line):
Expand All @@ -46,6 +55,13 @@ def match_and_remove_row(rows, expected_row):
return found_row


def handle_repair_output(context):
output_data = context.out.decode('ascii').lstrip().rstrip().split('\n')
context.header = output_data[0:3]
context.rows = output_data[3:-1]
context.summary = output_data[-1:]


def validate_header(header, expected_main_header):
assert len(header) == 3, header

Expand All @@ -63,6 +79,13 @@ def validate_last_table_row(rows):
assert len(rows) == 1, "{0} not empty".format(rows)


def get_job_id(context):
out = context.out.decode('ascii')
job_id = re.search(ID_PATTERN, out).group(0)
assert job_id, "Could not find job id matching {0} in {1}".format(ID_PATTERN, out)
return job_id


@given('we have access to ecctool')
def step_init(context):
assert context.config.userdata.get("ecctool") is not False
Expand All @@ -82,14 +105,25 @@ def step_validate_list_rows_clear(context):
validate_last_table_row(context.rows)


@then('the output should contain a valid repair header')
def step_validate_list_tables_header(context):
validate_header(context.header, REPAIR_HEADER)


@then('the output should contain a repair row for {keyspace}.{table} with type {repair_type}')
def step_validate_repair_row(context, keyspace, table, repair_type):
expected_row = table_row(REPAIR_ROW_FORMAT_PATTERN, keyspace, table, repair_type)
match_and_remove_row(context.rows, expected_row)


def get_behave_dir():
current_dir = os.path.dirname(__file__)
return os.path.abspath(os.path.join(current_dir, '../features'))


@given('I have a json schema in {schema_name}.json')
@given('I have a json schema {schema_name}')
def step_import_schema(context, schema_name):
schema_file = os.path.join(get_behave_dir(), "{0}.json".format(schema_name))
schema_file = os.path.join(get_behave_dir(), "schemas", "{0}.json".format(schema_name))

with io.open(schema_file, "r", encoding="utf-8") as jsonfile:
setattr(context, schema_name, json.loads(jsonfile.read()))
Expand Down Expand Up @@ -138,7 +172,7 @@ def step_verify_response_is_successful(context):
assert context.response.status_code == 200


@then('the response matches the json {schema_name}')
@then('the response matches the json schema {schema_name}')
def step_verify_schema(context, schema_name):
schema = getattr(context, schema_name, None)
assert schema is not None
Expand Down
48 changes: 0 additions & 48 deletions ecchronos-binary/src/test/behave/features/demand_repair_job.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
Feature: API for repair info

Scenario: Get repair info for table test1.table1 in the last 5 minutes
Given I have a json schema in repair_info.json
Given I have a json schema repair_info
And I use the url localhost:8080/repair-management/v2/repairInfo?keyspace=test&table=table1&duration=5m
When I send a GET request
Then the response is successful
And the response matches the json repair_info
And the response matches the json schema repair_info

Scenario: Get local repair info for table test1.table1 in the last 5 minutes
Given I have a json schema in repair_info.json
Given I have a json schema repair_info
And I use the url localhost:8080/repair-management/v2/repairInfo?keyspace=test&table=table1&duration=5m&isLocal=true
When I send a GET request
Then the response is successful
And the response matches the json repair_info
And the response matches the json schema repair_info

Scenario: Get repair info for keyspace test1 in the last 5 minutes
Given I have a json schema in repair_info.json
Given I have a json schema repair_info
And I use the url localhost:8080/repair-management/v2/repairInfo?keyspace=test&duration=5m
When I send a GET request
Then the response is successful
And the response matches the json repair_info
And the response matches the json schema repair_info

Scenario: Get repair info for all tables in the last 5 minutes
Given I have a json schema in repair_info.json
Given I have a json schema repair_info
And I use the url localhost:8080/repair-management/v2/repairInfo?duration=5m
When I send a GET request
Then the response is successful
And the response matches the json repair_info
And the response matches the json schema repair_info

Scenario: Get repair info for all tables since epoch
Given I have a json schema in repair_info.json
Given I have a json schema repair_info
And I use the url localhost:8080/repair-management/v2/repairInfo?since=0
When I send a GET request
Then the response is successful
And the response matches the json repair_info
And the response matches the json schema repair_info

Scenario: Get repair info for all tables between epoch and epoch+5 minutes
Given I have a json schema in repair_info.json
Given I have a json schema repair_info
And I use the url localhost:8080/repair-management/v2/repairInfo?since=0&duration=5m
When I send a GET request
Then the response is successful
And the response matches the json repair_info
And the response matches the json schema repair_info

Scenario: Get local repair info for all tables between epoch and epoch+5 minutes
Given I have a json schema in repair_info.json
Given I have a json schema repair_info
And I use the url localhost:8080/repair-management/v2/repairInfo?since=0&duration=5m&isLocal=true
When I send a GET request
Then the response is successful
And the response matches the json repair_info
And the response matches the json schema repair_info
20 changes: 10 additions & 10 deletions ecchronos-binary/src/test/behave/features/ecc-rest-repair.feature
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
Feature: API for repairs

Scenario: Run local repair for table test.table1
Given I have a json schema in repair_list_v2.json
Given I have a json schema repairs
And I use the url localhost:8080/repair-management/v2/repairs?keyspace=test&table=table1&isLocal=true
When I send a POST request
Then the response is successful
And the response matches the json repair_list_v2
And the response matches the json schema repairs

Scenario: Get repair status for all repairs
Given I have a json schema in repair_list_v2.json
Given I have a json schema repairs
And I use the url localhost:8080/repair-management/v2/repairs
When I send a GET request
Then the response is successful
And the response matches the json repair_list_v2
And the response matches the json schema repairs

Scenario: Get repair status for all repairs in the keyspace test
Given I have a json schema in repair_list_v2.json
Given I have a json schema repairs
And I use the url localhost:8080/repair-management/v2/repairs?keyspace=test
When I send a GET request
Then the response is successful
And the response matches the json repair_list_v2
And the response matches the json schema repairs
And the job list contains only keyspace test

Scenario: Get repair status for table test.table1 and then get by id
Given I have a json schema in repair_list_v2.json
Given I have a json schema repairs
And I use the url localhost:8080/repair-management/v2/repairs?keyspace=test&table=table1
When I send a GET request
Then the response is successful
And the response matches the json repair_list_v2
And the response matches the json schema repairs
And the id from response is extracted for test.table1
Given I have a json schema in repair_list_v2.json
Given I have a json schema repairs
And I fetch repairs with id
When I send a GET request
Then the response is successful
And the response matches the json repair_list_v2
And the response matches the json schema repairs
24 changes: 12 additions & 12 deletions ecchronos-binary/src/test/behave/features/ecc-rest-schedule.feature
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
Feature: API to get schedule status

Scenario: Get schedule status for all repairs
Given I have a json schema in schedule_list_v2.json
Given I have a json schema schedules
And I use the url localhost:8080/repair-management/v2/schedules
When I send a GET request
Then the response is successful
And the response matches the json schedule_list_v2
And the response matches the json schema schedules

Scenario: Get schedule status for all repairs in the keyspace test
Given I have a json schema in schedule_list_v2.json
Given I have a json schema schedules
And I use the url localhost:8080/repair-management/v2/schedules?keyspace=test
When I send a GET request
Then the response is successful
And the response matches the json schedule_list_v2
And the response matches the json schema schedules
And the job list contains only keyspace test

Scenario: Get schedule status for table test.table1 and then get by id
Given I have a json schema in schedule_list_v2.json
Given I have a json schema schedules
And I use the url localhost:8080/repair-management/v2/schedules?keyspace=test&table=table1
When I send a GET request
Then the response is successful
And the response matches the json schedule_list_v2
And the response matches the json schema schedules
And the id from response is extracted for test.table1
Given I have a json schema in schedule.json
Given I have a json schema schedule
And I fetch schedules with id
When I send a GET request
Then the response is successful
And the response matches the json schedule
And the response matches the json schema schedule

Scenario: Get full schedule status for table test.table1 and then get by id
Given I have a json schema in schedule_list_v2.json
Given I have a json schema schedules
And I use the url localhost:8080/repair-management/v2/schedules?keyspace=test&table=table1
When I send a GET request
Then the response is successful
And the response matches the json schedule_list_v2
And the response matches the json schema schedules
And the id from response is extracted for test.table1
Given I have a json schema in full_schedule.json
Given I have a json schema full_schedule
And I fetch schedules with id and full
When I send a GET request
Then the response is successful
And the response matches the json full_schedule
And the response matches the json schema full_schedule
4 changes: 2 additions & 2 deletions ecchronos-binary/src/test/behave/features/ecc-spring.feature
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Feature: ecc-spring

Scenario: RestServer health check returns UP
Scenario: Get health status
Given I use the url localhost:8080/actuator/health
When I send a GET request
Then the response is successful
And the status is UP

Scenario: RestServer returns metrics
Scenario: Get metrics
Given I use the url localhost:8080/metrics
When I send a GET request
Then the response is successful
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature: ecctool repairs
Given we have access to ecctool
When we list all repairs for keyspace test2 with a limit of 1
Then the output should contain a valid repair header
And the repair output should contain a valid repair row for test2..* with type .*
And the output should contain a repair row for test2..* with type .*
And the output should not contain more rows
And the output should contain a valid repair summary

Expand Down
Loading

0 comments on commit f022699

Please sign in to comment.