diff --git a/ecchronos-binary/src/test/behave/ecc_step_library/common_steps.py b/ecchronos-binary/src/test/behave/ecc_step_library/common.py similarity index 78% rename from ecchronos-binary/src/test/behave/ecc_step_library/common_steps.py rename to ecchronos-binary/src/test/behave/ecc_step_library/common.py index ccec096af..f5c7523cc 100644 --- a/ecchronos-binary/src/test/behave/ecc_step_library/common_steps.py +++ b/ecchronos-binary/src/test/behave/ecc_step_library/common.py @@ -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): @@ -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 @@ -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 @@ -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())) @@ -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 diff --git a/ecchronos-binary/src/test/behave/features/demand_repair_job.json b/ecchronos-binary/src/test/behave/features/demand_repair_job.json deleted file mode 100644 index b98c38cb1..000000000 --- a/ecchronos-binary/src/test/behave/features/demand_repair_job.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "On Demand Repair job", - "description": "A on demand repair job containing virtual node state information", - "type": "object", - "properties": { - "keyspace": { - "type": "string" - }, - "table": { - "type": "string" - }, - "status": { - "type": "string", - "description": "The status of the repair with regards to its schedule and last successful repair" - }, - "repairedRatio": { - "type": "number", - "description": "Ratio of how much of the table that has been repaired" - }, - "lastRepairedAtInMs": { - "type": "integer", - "description": "When the table was last repaired in millis since epoch" - }, - "nextRepairInMs": { - "type": "integer", - "description": "When the table is scheduled for the next repair in millis since epoch" - }, - "id": { - "type": "string", - "description": "A unique identifier for the job" - }, - "repairType": { - "type": "string", - "description": "The type of repair for the schedule" - } - }, - "required": [ - "id", - "keyspace", - "table", - "status", - "repairedRatio", - "lastRepairedAtInMs", - "nextRepairInMs", - "repairType" - ] -} \ No newline at end of file diff --git a/ecchronos-binary/src/test/behave/features/ecc-rest-repair-info.feature b/ecchronos-binary/src/test/behave/features/ecc-rest-repair-info.feature index 01babc108..d90ffb815 100644 --- a/ecchronos-binary/src/test/behave/features/ecc-rest-repair-info.feature +++ b/ecchronos-binary/src/test/behave/features/ecc-rest-repair-info.feature @@ -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 \ No newline at end of file + And the response matches the json schema repair_info \ No newline at end of file diff --git a/ecchronos-binary/src/test/behave/features/ecc-rest-repair.feature b/ecchronos-binary/src/test/behave/features/ecc-rest-repair.feature index 3782d79d3..396437355 100644 --- a/ecchronos-binary/src/test/behave/features/ecc-rest-repair.feature +++ b/ecchronos-binary/src/test/behave/features/ecc-rest-repair.feature @@ -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 diff --git a/ecchronos-binary/src/test/behave/features/ecc-rest-schedule.feature b/ecchronos-binary/src/test/behave/features/ecc-rest-schedule.feature index ed9f0e054..5dcabcdab 100644 --- a/ecchronos-binary/src/test/behave/features/ecc-rest-schedule.feature +++ b/ecchronos-binary/src/test/behave/features/ecc-rest-schedule.feature @@ -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 \ No newline at end of file + And the response matches the json schema full_schedule \ No newline at end of file diff --git a/ecchronos-binary/src/test/behave/features/ecc-spring.feature b/ecchronos-binary/src/test/behave/features/ecc-spring.feature index e28406448..4d224fa82 100644 --- a/ecchronos-binary/src/test/behave/features/ecc-spring.feature +++ b/ecchronos-binary/src/test/behave/features/ecc-spring.feature @@ -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 \ No newline at end of file diff --git a/ecchronos-binary/src/test/behave/features/ecctool-get-repairs.feature b/ecchronos-binary/src/test/behave/features/ecctool-repairs.feature similarity index 97% rename from ecchronos-binary/src/test/behave/features/ecctool-get-repairs.feature rename to ecchronos-binary/src/test/behave/features/ecctool-repairs.feature index 2a6661c4d..3e90f9088 100644 --- a/ecchronos-binary/src/test/behave/features/ecctool-get-repairs.feature +++ b/ecchronos-binary/src/test/behave/features/ecctool-repairs.feature @@ -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 diff --git a/ecchronos-binary/src/test/behave/features/ecctool-run-repair.feature b/ecchronos-binary/src/test/behave/features/ecctool-run-repair.feature index 9a8ea4101..f984a9ac1 100644 --- a/ecchronos-binary/src/test/behave/features/ecctool-run-repair.feature +++ b/ecchronos-binary/src/test/behave/features/ecctool-run-repair.feature @@ -1,67 +1,67 @@ Feature: ecctool run-repair - Scenario: Run local repair for keyspace test2 and table table2 + Scenario: Run local parallel_vnode repair for keyspace test2 and table table2 Given we have access to ecctool When we run local repair for keyspace test2 and table table2 with type PARALLEL_VNODE - Then the repair output should contain a valid header - And the repair output should contain a valid repair row for test2.table2 with type PARALLEL_VNODE - And the repair output should not contain more rows + Then the output should contain a valid repair header + And the output should contain a repair row for test2.table2 with type PARALLEL_VNODE + And the output should not contain more rows And the output should contain a valid repair summary Scenario: Run local repair for keyspace test2 Given we have access to ecctool When we run local repair for keyspace test2 - Then the repair output should contain a valid header - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should contain a valid repair row for test2.table1 with type VNODE - And the repair output should not contain more rows + Then the output should contain a valid repair header + And the output should contain a repair row for test2.table2 with type VNODE + And the output should contain a repair row for test2.table1 with type VNODE + And the output should not contain more rows And the output should contain a valid repair summary Scenario: Run local repair for all keyspaces and tables Given we have access to ecctool When we run local repair - Then the repair output should contain a valid header - And the repair output should contain a valid repair row for keyspaceWithCamelCase.tableWithCamelCase with type VNODE - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should contain a valid repair row for test2.table1 with type VNODE - And the repair output should contain a valid repair row for test.table2 with type VNODE - And the repair output should contain a valid repair row for test.table1 with type VNODE - And the repair output should not contain more rows + Then the output should contain a valid repair header + And the output should contain a repair row for keyspaceWithCamelCase.tableWithCamelCase with type VNODE + And the output should contain a repair row for test2.table2 with type VNODE + And the output should contain a repair row for test2.table1 with type VNODE + And the output should contain a repair row for test.table2 with type VNODE + And the output should contain a repair row for test.table1 with type VNODE + And the output should not contain more rows And the output should contain a valid repair summary Scenario: Run cluster-wide repair for keyspace test2 and table table2 Given we have access to ecctool When we run repair for keyspace test2 and table table2 - Then the repair output should contain a valid header - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should not contain more rows + Then the output should contain a valid repair header + And the output should contain a repair row for test2.table2 with type VNODE + And the output should contain a repair row for test2.table2 with type VNODE + And the output should not contain more rows And the output should contain a valid repair summary Scenario: Run cluster-wide repair for keyspace test2 Given we have access to ecctool When we run repair for keyspace test2 - Then the repair output should contain a valid header - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should contain a valid repair row for test2.table1 with type VNODE - And the repair output should contain a valid repair row for test2.table1 with type VNODE - And the repair output should not contain more rows + Then the output should contain a valid repair header + And the output should contain a repair row for test2.table2 with type VNODE + And the output should contain a repair row for test2.table2 with type VNODE + And the output should contain a repair row for test2.table1 with type VNODE + And the output should contain a repair row for test2.table1 with type VNODE + And the output should not contain more rows And the output should contain a valid repair summary Scenario: Run cluster-wide repair for all keyspaces and tables Given we have access to ecctool When we run repair - Then the repair output should contain a valid header - And the repair output should contain a valid repair row for keyspaceWithCamelCase.tableWithCamelCase with type VNODE - And the repair output should contain a valid repair row for keyspaceWithCamelCase.tableWithCamelCase with type VNODE - And the repair output should contain a valid repair row for test.table2 with type VNODE - And the repair output should contain a valid repair row for test.table2 with type VNODE - And the repair output should contain a valid repair row for test.table1 with type VNODE - And the repair output should contain a valid repair row for test.table1 with type VNODE - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should contain a valid repair row for test2.table2 with type VNODE - And the repair output should contain a valid repair row for test2.table1 with type VNODE - And the repair output should contain a valid repair row for test2.table1 with type VNODE - And the repair output should not contain more rows + Then the output should contain a valid repair header + And the output should contain a repair row for keyspaceWithCamelCase.tableWithCamelCase with type VNODE + And the output should contain a repair row for keyspaceWithCamelCase.tableWithCamelCase with type VNODE + And the output should contain a repair row for test.table2 with type VNODE + And the output should contain a repair row for test.table2 with type VNODE + And the output should contain a repair row for test.table1 with type VNODE + And the output should contain a repair row for test.table1 with type VNODE + And the output should contain a repair row for test2.table2 with type VNODE + And the output should contain a repair row for test2.table2 with type VNODE + And the output should contain a repair row for test2.table1 with type VNODE + And the output should contain a repair row for test2.table1 with type VNODE + And the output should not contain more rows And the output should contain a valid repair summary \ No newline at end of file diff --git a/ecchronos-binary/src/test/behave/features/ecctool-get-schedule.feature b/ecchronos-binary/src/test/behave/features/ecctool-schedules.feature similarity index 88% rename from ecchronos-binary/src/test/behave/features/ecctool-get-schedule.feature rename to ecchronos-binary/src/test/behave/features/ecctool-schedules.feature index 42e08dc79..4e23f809b 100644 --- a/ecchronos-binary/src/test/behave/features/ecctool-get-schedule.feature +++ b/ecchronos-binary/src/test/behave/features/ecctool-schedules.feature @@ -1,6 +1,6 @@ Feature: ecctool schedules - Scenario: List tables + Scenario: Get all schedules Given we have access to ecctool When we list all schedules Then the output should contain a valid snapshot header @@ -13,7 +13,7 @@ Feature: ecctool schedules And the output should not contain more rows And the output should contain a valid schedule summary - Scenario: List tables with a limit + Scenario: Get all schedules with a limit Given we have access to ecctool When we list all schedules with a limit of 1 Then the output should contain a valid snapshot header @@ -21,7 +21,7 @@ Feature: ecctool schedules And the output should contain 1 row And the output should contain a valid schedule summary - Scenario: List tables for keyspace test + Scenario: Get schedules for keyspace test Given we have access to ecctool When we list all schedules for keyspace test Then the output should contain a valid snapshot header @@ -31,7 +31,7 @@ Feature: ecctool schedules And the output should not contain more rows And the output should contain a valid schedule summary - Scenario: List tables for keyspace test with a limit + Scenario: Get schedules for keyspace test with a limit Given we have access to ecctool When we list all schedules for keyspace test with a limit of 1 Then the output should contain a valid snapshot header @@ -40,7 +40,7 @@ Feature: ecctool schedules And the output should not contain more rows And the output should contain a valid schedule summary - Scenario: Show the table test.table1 + Scenario: Get schedule for table test.table1 Given we have access to ecctool When we list schedules for table test.table1 Then the output should contain a valid snapshot header @@ -49,18 +49,18 @@ Feature: ecctool schedules And the output should not contain more rows And the output should contain a valid schedule summary - Scenario: Show the table test.table2 with id + Scenario: Get schedule for table test.table2 with id Given we have access to ecctool When we fetch schedule test.table2 by id Then the output should contain a valid schedule for test.table2 with type VNODE - Scenario: Show the table test.table2 with a limit + Scenario: Get schedule for table test.table2 with a limit Given we have access to ecctool When we show schedule test.table2 with a limit of 5 Then the expected schedule header should be for test.table2 with type VNODE And the token list should contain 5 rows - Scenario: Show the table test.table1 with a limit + Scenario: Get schedule for table test.table1 with a limit Given we have access to ecctool When we show schedule test.table2 with a limit of 15 Then the expected schedule header should be for test.table2 with type VNODE diff --git a/ecchronos-binary/src/test/behave/features/full_schedule.json b/ecchronos-binary/src/test/behave/features/schemas/full_schedule.json similarity index 100% rename from ecchronos-binary/src/test/behave/features/full_schedule.json rename to ecchronos-binary/src/test/behave/features/schemas/full_schedule.json diff --git a/ecchronos-binary/src/test/behave/features/repair_info.json b/ecchronos-binary/src/test/behave/features/schemas/repair_info.json similarity index 100% rename from ecchronos-binary/src/test/behave/features/repair_info.json rename to ecchronos-binary/src/test/behave/features/schemas/repair_info.json diff --git a/ecchronos-binary/src/test/behave/features/repair_list_v2.json b/ecchronos-binary/src/test/behave/features/schemas/repairs.json similarity index 100% rename from ecchronos-binary/src/test/behave/features/repair_list_v2.json rename to ecchronos-binary/src/test/behave/features/schemas/repairs.json diff --git a/ecchronos-binary/src/test/behave/features/schedule.json b/ecchronos-binary/src/test/behave/features/schemas/schedule.json similarity index 100% rename from ecchronos-binary/src/test/behave/features/schedule.json rename to ecchronos-binary/src/test/behave/features/schemas/schedule.json diff --git a/ecchronos-binary/src/test/behave/features/schedule_list_v2.json b/ecchronos-binary/src/test/behave/features/schemas/schedules.json similarity index 100% rename from ecchronos-binary/src/test/behave/features/schedule_list_v2.json rename to ecchronos-binary/src/test/behave/features/schemas/schedules.json diff --git a/ecchronos-binary/src/test/behave/features/steps/ecc_rest_repair.py b/ecchronos-binary/src/test/behave/features/steps/ecc_rest_repairs.py similarity index 100% rename from ecchronos-binary/src/test/behave/features/steps/ecc_rest_repair.py rename to ecchronos-binary/src/test/behave/features/steps/ecc_rest_repairs.py diff --git a/ecchronos-binary/src/test/behave/features/steps/ecc_rest_scheule.py b/ecchronos-binary/src/test/behave/features/steps/ecc_rest_schedules.py similarity index 100% rename from ecchronos-binary/src/test/behave/features/steps/ecc_rest_scheule.py rename to ecchronos-binary/src/test/behave/features/steps/ecc_rest_schedules.py diff --git a/ecchronos-binary/src/test/behave/features/steps/ecc_spring_steps.py b/ecchronos-binary/src/test/behave/features/steps/ecc_spring.py similarity index 100% rename from ecchronos-binary/src/test/behave/features/steps/ecc_spring_steps.py rename to ecchronos-binary/src/test/behave/features/steps/ecc_spring.py diff --git a/ecchronos-binary/src/test/behave/features/steps/ecctool_get_repair_info_steps.py b/ecchronos-binary/src/test/behave/features/steps/ecctool_repair_info.py similarity index 95% rename from ecchronos-binary/src/test/behave/features/steps/ecctool_get_repair_info_steps.py rename to ecchronos-binary/src/test/behave/features/steps/ecctool_repair_info.py index 586b28e30..5c67fd0e4 100644 --- a/ecchronos-binary/src/test/behave/features/steps/ecctool_get_repair_info_steps.py +++ b/ecchronos-binary/src/test/behave/features/steps/ecctool_repair_info.py @@ -14,7 +14,7 @@ # from behave import when, then # pylint: disable=no-name-in-module -from ecc_step_library.common_steps import match_and_remove_row, validate_header, run_ecctool +from ecc_step_library.common import match_and_remove_row, validate_header, run_ecctool, table_row REPAIR_INFO_HEADER = r'| Keyspace | Table | Repaired (%) | Repair time taken |' @@ -25,10 +25,6 @@ def run_ecc_repair_info(context, params): run_ecctool(context, ["repair-info"] + params) -def table_row(keyspace, table): - return REPAIR_INFO_ROW_FORMAT_PATTERN.format(keyspace, table) - - def handle_repair_info_output(context): output_data = context.out.decode('ascii').lstrip().rstrip().split('\n') context.time_window = output_data[0:1] @@ -121,5 +117,5 @@ def step_validate_repair_info_header(context): @then('the output should contain a repair-info row for {keyspace}.{table}') def step_validate_repair_info_row(context, keyspace, table): - expected_row = table_row(keyspace, table) + expected_row = table_row(REPAIR_INFO_ROW_FORMAT_PATTERN, keyspace, table) match_and_remove_row(context.rows, expected_row) diff --git a/ecchronos-binary/src/test/behave/features/steps/ecctool_get_repairs_steps.py b/ecchronos-binary/src/test/behave/features/steps/ecctool_repairs.py similarity index 63% rename from ecchronos-binary/src/test/behave/features/steps/ecctool_get_repairs_steps.py rename to ecchronos-binary/src/test/behave/features/steps/ecctool_repairs.py index 12b52a401..9ee62457e 100644 --- a/ecchronos-binary/src/test/behave/features/steps/ecctool_get_repairs_steps.py +++ b/ecchronos-binary/src/test/behave/features/steps/ecctool_repairs.py @@ -13,28 +13,14 @@ # limitations under the License. # -import re from behave import when, then # pylint: disable=no-name-in-module -from ecc_step_library.common_steps import match_and_remove_row, validate_header, run_ecctool - - -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}' - -TABLE_REPAIR_HEADER = r'| Id | Host Id | Keyspace | Table | Status | Repaired(%) | Completed at | Repair type |' -TABLE_REPAIR_ROW_FORMAT_PATTERN = r'\| .* \| .* \| {0} \| {1} \| (COMPLETED|IN_QUEUE|WARNING|ERROR) \| \d+[.]\d+ \| .* \| {2} \|' # pylint: disable=line-too-long +from ecc_step_library.common import get_job_id, handle_repair_output, step_validate_repair_row, run_ecctool def run_ecc_repair_status(context, params): run_ecctool(context, ["repairs"] + params) -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:] - - @when('we list all repairs') def step_list_repairs(context): run_ecc_repair_status(context, []) @@ -62,9 +48,7 @@ def step_list_repairs_for_keyspace(context, keyspace): @when('we list repairs {keyspace}.{table} with a limit of {limit}') def step_show_repair_with_limit(context, keyspace, table, limit): run_ecc_repair_status(context, ['--keyspace', keyspace, '--table', table]) - job_id = re.search(ID_PATTERN, context.out.decode('ascii')).group(0) - assert job_id - run_ecc_repair_status(context, ['--id', job_id, '--limit', limit]) + run_ecc_repair_status(context, ['--id', get_job_id(context), '--limit', limit]) handle_repair_output(context) @@ -81,21 +65,6 @@ def step_show_repair_with_nodeid(context, keyspace, table): handle_repair_output(context) -@then('the output should contain a valid repair header') -def step_validate_list_tables_header(context): - validate_header(context.header, TABLE_REPAIR_HEADER) - - -@then('the output should contain a repair row for {keyspace}.{table} with type {repair_type}') -def step_validate_list_tables_row(context, keyspace, table, repair_type): - expected_row = table_row(keyspace, table, repair_type) - match_and_remove_row(context.rows, expected_row) - - -def table_row(keyspace, table, repair_type): - return TABLE_REPAIR_ROW_FORMAT_PATTERN.format(keyspace, table, repair_type) - - @then('the output should contain {limit:d} repair rows') def step_validate_list_repairs_contains_rows_with_limit(context, limit): rows = context.rows @@ -103,4 +72,4 @@ def step_validate_list_repairs_contains_rows_with_limit(context, limit): assert len(rows) == limit + 1, "Expecting only {0} table element from {1}".format(limit, rows) for _ in range(limit): - step_validate_list_tables_row(context, ".*", ".*", ".*") + step_validate_repair_row(context, ".*", ".*", ".*") diff --git a/ecchronos-binary/src/test/behave/features/steps/ecctool_run_repair_steps.py b/ecchronos-binary/src/test/behave/features/steps/ecctool_run_repair.py similarity index 52% rename from ecchronos-binary/src/test/behave/features/steps/ecctool_run_repair_steps.py rename to ecchronos-binary/src/test/behave/features/steps/ecctool_run_repair.py index 1a1a08d54..5d66a19d9 100644 --- a/ecchronos-binary/src/test/behave/features/steps/ecctool_run_repair_steps.py +++ b/ecchronos-binary/src/test/behave/features/steps/ecctool_run_repair.py @@ -13,12 +13,8 @@ # limitations under the License. # -from behave import when, then # pylint: disable=no-name-in-module -from ecc_step_library.common_steps import match_and_remove_row, validate_header, validate_last_table_row, run_ecctool # pylint: disable=line-too-long - - -TABLE_ROW_FORMAT_PATTERN = r'\| .* \| .* \| {0} \| {1} \| (COMPLETED|IN_QUEUE|WARNING|ERROR) \| \d+[.]\d+ \| .* \| {2} \|' # pylint: disable=line-too-long -TABLE_HEADER = r'| Id | Host Id | Keyspace | Table | Status | Repaired(%) | Completed at | Repair type |' +from behave import when # pylint: disable=no-name-in-module +from ecc_step_library.common import handle_repair_output, run_ecctool def run_ecc_run_repair(context, params): @@ -28,61 +24,34 @@ def run_ecc_run_repair(context, params): @when('we run repair for keyspace {keyspace} and table {table}') def step_run_repair(context, keyspace, table): run_ecc_run_repair(context, ['--keyspace', keyspace, '--table', table]) - split_output(context) + handle_repair_output(context) @when('we run repair for keyspace {keyspace}') def step_run_repair_keyspace(context, keyspace): run_ecc_run_repair(context, ['--keyspace', keyspace]) - split_output(context) + handle_repair_output(context) @when('we run repair') def step_run_repair_cluster(context): run_ecc_run_repair(context, []) - split_output(context) + handle_repair_output(context) @when('we run local repair for keyspace {keyspace} and table {table} with type {repair_type}') def step_run_local_repair(context, keyspace, table, repair_type): run_ecc_run_repair(context, ['--keyspace', keyspace, '--table', table, '--local', '--repair_type', repair_type]) - split_output(context) + handle_repair_output(context) @when('we run local repair for keyspace {keyspace}') def step_run_local_repair_for_keyspace(context, keyspace): run_ecc_run_repair(context, ['--keyspace', keyspace, '--local']) - split_output(context) + handle_repair_output(context) @when('we run local repair') def step_run_local_repair_cluster(context): run_ecc_run_repair(context, ['--local']) - split_output(context) - - -def split_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:] - - -@then('the repair output should contain a valid header') -def step_validate_tables_header(context): - validate_header(context.header, TABLE_HEADER) - - -@then('the repair output should contain a valid repair row for {keyspace}.{table} with type {repair_type}') -def step_validate_repair_row(context, keyspace, table, repair_type): - expected_row = repair_row(keyspace, table, repair_type) - match_and_remove_row(context.rows, expected_row) - - -def repair_row(keyspace, table, repair_type): - return TABLE_ROW_FORMAT_PATTERN.format(keyspace, table, repair_type) - - -@then('the repair output should not contain more rows') -def step_validate_list_rows_clear(context): - validate_last_table_row(context.rows) + handle_repair_output(context) diff --git a/ecchronos-binary/src/test/behave/features/steps/ecctool_get_schedules_steps.py b/ecchronos-binary/src/test/behave/features/steps/ecctool_schedules.py similarity index 82% rename from ecchronos-binary/src/test/behave/features/steps/ecctool_get_schedules_steps.py rename to ecchronos-binary/src/test/behave/features/steps/ecctool_schedules.py index 084356578..ce1f75342 100644 --- a/ecchronos-binary/src/test/behave/features/steps/ecctool_get_schedules_steps.py +++ b/ecchronos-binary/src/test/behave/features/steps/ecctool_schedules.py @@ -15,15 +15,13 @@ import re from behave import when, then # pylint: disable=no-name-in-module -from ecc_step_library.common_steps import match_and_remove_row, strip_and_collapse, validate_header, step_validate_list_rows_clear, run_ecctool # pylint: disable=line-too-long +from ecc_step_library.common import get_job_id, match_and_remove_row, strip_and_collapse, validate_header, step_validate_list_rows_clear, run_ecctool, table_row # pylint: disable=line-too-long - -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}' SCHEDULE_SUMMARY = r'Summary: \d+ completed, \d+ on time, \d+ blocked, \d+ late, \d+ overdue' -TABLE_SCHEDULE_HEADER = r'| Id | Keyspace | Table | Status | Repaired(%) | Completed at | Next repair | Repair type |' -TABLE_SNAPSHOT_HEADER = r'Snapshot as of .*' -TABLE_SCHEDULE_ROW_FORMAT_PATTERN = r'\| .* \| {0} \| {1} \| (COMPLETED|ON_TIME|LATE|OVERDUE) \| \d+[.]\d+ \| .* \| {2} \|' # pylint: disable=line-too-long +SCHEDULE_HEADER = r'| Id | Keyspace | Table | Status | Repaired(%) | Completed at | Next repair | Repair type |' +SNAPSHOT_HEADER = r'Snapshot as of .*' +SCHEDULE_ROW_FORMAT_PATTERN = r'\| .* \| {0} \| {1} \| (COMPLETED|ON_TIME|LATE|OVERDUE) \| \d+[.]\d+ \| .* \| {2} \|' # pylint: disable=line-too-long def run_ecc_schedule_status(context, params): @@ -65,9 +63,7 @@ def step_list_schedules_for_keyspace(context, keyspace): @when('we list schedules {keyspace}.{table} with a limit of {limit}') def step_list_schedule_with_limit(context, keyspace, table, limit): run_ecc_schedule_status(context, ['--keyspace', keyspace, '--table', table]) - job_id = re.search(ID_PATTERN, context.out.decode('ascii')).group(0) - assert job_id - run_ecc_schedule_status(context, ['--id', job_id, '--limit', limit]) + run_ecc_schedule_status(context, ['--id', get_job_id(context), '--limit', limit]) handle_schedule_output(context) @@ -79,17 +75,14 @@ def step_show_schedule(context, keyspace, table): @then('the output should contain a schedule row for {keyspace}.{table} with type {repair_type}') def step_validate_list_tables_row(context, keyspace, table, repair_type): - expected_row = table_row(keyspace, table, repair_type) + expected_row = table_row(SCHEDULE_ROW_FORMAT_PATTERN, keyspace, table, repair_type) match_and_remove_row(context.rows, expected_row) @when('we fetch schedule {keyspace}.{table} by id') def step_show_schedule_with_id(context, keyspace, table): run_ecc_schedule_status(context, ['--keyspace', keyspace, '--table', table]) - - job_id = re.search(ID_PATTERN, context.out.decode('ascii')).group(0) - assert job_id - run_ecc_schedule_status(context, ['--id', job_id]) + run_ecc_schedule_status(context, ['--id', get_job_id(context)]) output_data = context.out.decode('ascii').lstrip().rstrip().split('\n') context.table_info = output_data[0:8] context.conf = output_data[8:9] @@ -98,10 +91,7 @@ def step_show_schedule_with_id(context, keyspace, table): @when('we show schedule {keyspace}.{table} with a limit of {limit}') def step_show_schedule_with_limit(context, keyspace, table, limit): run_ecc_schedule_status(context, ['--keyspace', keyspace, '--table', table]) - - job_id = re.search(ID_PATTERN, context.out.decode('ascii')).group(0) - assert job_id - run_ecc_schedule_status(context, ['--id', job_id, '--limit', limit, '--full']) + run_ecc_schedule_status(context, ['--id', get_job_id(context), '--limit', limit, '--full']) output_data = context.out.decode('ascii').lstrip().rstrip().split('\n') context.table_info = output_data[0:8] @@ -127,12 +117,12 @@ def step_validate_list_schedule_contains_rows(context, keyspace, table, repair_t @then('the output should contain a valid snapshot header') def step_validate_list_snapshot_header(context): - match_and_remove_row(context.snapshot, TABLE_SNAPSHOT_HEADER) + match_and_remove_row(context.snapshot, SNAPSHOT_HEADER) @then('the output should contain a valid schedule header') def step_validate_list_schedule_header(context): - validate_header(context.header, TABLE_SCHEDULE_HEADER) + validate_header(context.header, SCHEDULE_HEADER) @then('the output should contain {limit:d} row') @@ -191,9 +181,5 @@ def remove_token_row(context): del context.rows[found_row] -def table_row(keyspace, table, repair_type): - return TABLE_SCHEDULE_ROW_FORMAT_PATTERN.format(keyspace, table, repair_type) - - def token_row(): return "\\| [-]?\\d+ \\| [-]?\\d+ \\| .* \\| .* \\| (True|False) \\|"