Skip to content

Commit d815fb9

Browse files
authored
SAT: test strictness level migration tooling (create issues script) (#19020)
1 parent aa5da75 commit d815fb9

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Tooling for `test_strictness_level` migration
2+
3+
This directory contains scripts that can help us manage the migration of connectors's `acceptance-test-config.yml` to `high` test strictness level.
4+
Before running these scripts you need to set up a local virtual environment in the **current directory**:
5+
```bash
6+
python -m venv .venv
7+
source .venv/bin/activate
8+
pip install -r requirements.txt
9+
```
10+
## Requirements
11+
* [GitHub CLI](https://cli.github.com/) (`brew install gh`)
12+
13+
## Create migration issue for GA connectors (`create_issues.py`)
14+
This script will create one issue per GA connectors to migrate to `high` test strictness level.
15+
16+
### What it does:
17+
1. Find all GA connectors in `../../../../../airbyte-config/init/src/main/resources/seed/source_definitions.yaml`
18+
2. Generate an issue content (title, body, labels, project), using `./templates/issue.md.j2`
19+
3. Find an already existing issue with the same title.
20+
4. Create the issue and return its url if it does not exist.
21+
22+
Issues get created with the following labels:
23+
* `area/connectors`
24+
* `team/connectors-python`
25+
* `type/enhancement`
26+
* `test-strictness-level`
27+
28+
Issues are added to the following project: `SAT-high-test-strictness-level`
29+
30+
### How to run:
31+
**Dry run**:
32+
`python create_issues.py`
33+
34+
**Real execution**:
35+
`python create_issues.py --dry False`
36+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
6+
import argparse
7+
import json
8+
import logging
9+
import os
10+
import subprocess
11+
import tempfile
12+
13+
from definitions import GA_DEFINITIONS
14+
from jinja2 import Environment, FileSystemLoader
15+
16+
TEMPLATES_FOLDER = "./templates/"
17+
COMMON_ISSUE_LABELS = ["area/connectors", "team/connectors-python", "type/enhancement", "test-strictness-level"]
18+
GITHUB_PROJECT_NAME = "SAT-high-test-strictness-level"
19+
20+
logging.basicConfig(level=logging.DEBUG)
21+
environment = Environment(loader=FileSystemLoader(TEMPLATES_FOLDER))
22+
23+
parser = argparse.ArgumentParser(description="Create issues for migration of GA connectors to high test strictness level in SAT")
24+
parser.add_argument("-d", "--dry", default=True)
25+
26+
27+
def get_issue_content(source_definition):
28+
issue_title = f"Source {source_definition['name']}: enable `high` test strictness level in SAT"
29+
30+
template = environment.get_template("issue.md.j2")
31+
issue_body = template.render(connector_name=source_definition["name"], release_stage=source_definition["releaseStage"])
32+
file_definition, issue_body_path = tempfile.mkstemp()
33+
34+
with os.fdopen(file_definition, "w") as tmp:
35+
# do stuff with temp file
36+
tmp.write(issue_body)
37+
38+
return {"title": issue_title, "body_file": issue_body_path, "labels": COMMON_ISSUE_LABELS}
39+
40+
41+
def create_issue(source_definition, dry_run=True):
42+
issue_content = get_issue_content(source_definition)
43+
list_command_arguments = ["gh", "issue", "list", "--state", "open", "--search", f"'{issue_content['title']}'", "--json", "url"]
44+
45+
create_command_arguments = [
46+
"gh",
47+
"issue",
48+
"create",
49+
"--title",
50+
issue_content["title"],
51+
"--body-file",
52+
issue_content["body_file"],
53+
"--project",
54+
GITHUB_PROJECT_NAME,
55+
]
56+
for label in issue_content["labels"]:
57+
create_command_arguments += ["--label", label]
58+
59+
list_existing_issue_process = subprocess.Popen(list_command_arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
60+
stdout, stderr = list_existing_issue_process.communicate()
61+
existing_issues = json.loads(stdout.decode())
62+
already_created = len(existing_issues) > 0
63+
if already_created:
64+
logging.warning(f"An issue was already created for this definition: {existing_issues[0]}")
65+
if not already_created:
66+
if not dry_run:
67+
process = subprocess.Popen(create_command_arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
68+
stdout, stderr = process.communicate()
69+
if stderr:
70+
logging.error(stderr.decode())
71+
else:
72+
created_issue_url = stdout.decode()
73+
logging.info(f"Created issue for {source_definition['name']}: {created_issue_url}")
74+
else:
75+
logging.info(f"[DRY RUN]: {' '.join(create_command_arguments)}")
76+
os.remove(issue_content["body_file"])
77+
78+
79+
if __name__ == "__main__":
80+
args = parser.parse_args()
81+
dry_run = False if args.dry == "False" or args.dry == "false" else True
82+
for definition in GA_DEFINITIONS:
83+
create_issue(definition, dry_run=dry_run)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
6+
import yaml
7+
8+
SOURCE_DEFINITIONS_FILE_PATH = "../../../../../airbyte-config/init/src/main/resources/seed/source_definitions.yaml"
9+
10+
11+
def read_source_definitions():
12+
with open(SOURCE_DEFINITIONS_FILE_PATH, "r") as source_definitions_file:
13+
return yaml.safe_load(source_definitions_file)
14+
15+
16+
def find_by_release_stage(source_definitions, release_stage):
17+
return [definition for definition in source_definitions if definition.get("releaseStage") == release_stage]
18+
19+
20+
ALL_DEFINITIONS = read_source_definitions()
21+
GA_DEFINITIONS = find_by_release_stage(ALL_DEFINITIONS, "generally_available")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Jinja2==3.1.2
2+
MarkupSafe==2.1.1
3+
pyaml==21.10.1
4+
PyYAML==6.0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## What
2+
A `test_strictness_level` field was introduced to Source Acceptance Tests (SAT).
3+
{{ connector_name }} is a {{ release_stage }} connector, we want it to have a `high` test strictness level.
4+
5+
**This will help**:
6+
- maximize the SAT coverage on this connector.
7+
- document its potential weaknesses in term of test coverage.
8+
9+
## How
10+
1. Migrate the existing `acceptance-test-config.yml` file to the latest configuration format. (See instructions [here](https://github.com/airbytehq/airbyte/blob/master/airbyte-integrations/bases/source-acceptance-test/README.md#L61))
11+
2. Enable `high` test strictness level in `acceptance-test-config.yml`. (See instructions [here](https://github.com/airbytehq/airbyte/blob/master/docs/connector-development/testing-connectors/source-acceptance-tests-reference.md#L240))
12+
3. Commit changes on `acceptance-test-config.yml` and open a PR.
13+
4. Run SAT with the `/test` command on the branch.
14+
5. If tests are failing please fix the failing test or use `bypass_reason` fields to explain why a specific test can't be run.
15+

0 commit comments

Comments
 (0)