Skip to content

Commit c7d7804

Browse files
clnollBenGalewsky
authored andcommitted
airbyte-ci: run live tests against connection listed in metadata (airbytehq#42574)
1 parent 14a5c97 commit c7d7804

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

.github/workflows/connectors_tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ jobs:
8686
- name: Check PAT rate limits
8787
run: |
8888
./tools/bin/find_non_rate_limited_PAT \
89-
${{ secrets.GH_PAT_BUILD_RUNNER_OSS }} \
90-
${{ secrets.GH_PAT_BUILD_RUNNER_BACKUP }}
89+
${{ secrets.GH_PAT_MAINTENANCE_OSS }}
9190
- name: Extract branch name [WORKFLOW DISPATCH]
9291
shell: bash
9392
if: github.event_name == 'workflow_dispatch'
@@ -126,6 +125,7 @@ jobs:
126125
docker_hub_password: ${{ secrets.DOCKER_HUB_PASSWORD }}
127126
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
128127
gcp_gsm_credentials: ${{ secrets.GCP_GSM_CREDENTIALS }}
128+
gcp_integration_tester_credentials: ${{ secrets.GCLOUD_INTEGRATION_TESTER }}
129129
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
130130
git_branch: ${{ github.head_ref }}
131131
git_revision: ${{ steps.fetch_last_commit_id_pr.outputs.commit_id }}

airbyte-ci/connectors/pipelines/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ E.G.: running Poe tasks on the modified internal packages of the current branch:
773773

774774
| Version | PR | Description |
775775
| ------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
776+
| 4.27.0 | [#42574](https://github.com/airbytehq/airbyte/pull/42574) | Live tests: run from connectors test pipeline for connectors with sandbox connections |
776777
| 4.26.1 | [#42905](https://github.com/airbytehq/airbyte/pull/42905) | Rename the docker cache volume to avoid using the corrupted previous volume. |
777778
| 4.26.0 | [#42849](https://github.com/airbytehq/airbyte/pull/42849) | Send publish failures messages to `#connector-publish-failures` |
778779
| 4.25.4 | [#42463](https://github.com/airbytehq/airbyte/pull/42463) | Add validation before live test runs |

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/connectors/test/commands.py

-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
GITHUB_GLOBAL_CONTEXT_FOR_TESTS = "Connectors CI tests"
2727
GITHUB_GLOBAL_DESCRIPTION_FOR_TESTS = "Running connectors tests"
2828
REGRESSION_TEST_MANUAL_APPROVAL_CONTEXT = "Regression Test Results Reviewed and Approved"
29-
TESTS_SKIPPED_BY_DEFAULT = [
30-
CONNECTOR_TEST_STEP_ID.CONNECTOR_LIVE_TESTS,
31-
]
3229

3330

3431
@click.command(
@@ -120,7 +117,6 @@ async def test(
120117
raise click.UsageError("Cannot use both --only-step and --skip-step at the same time.")
121118
if not only_steps:
122119
skip_steps = list(skip_steps)
123-
skip_steps += TESTS_SKIPPED_BY_DEFAULT
124120
if ctx.obj["is_ci"]:
125121
fail_if_missing_docker_hub_creds(ctx)
126122

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/connectors/test/context.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"unitTests": CONNECTOR_TEST_STEP_ID.UNIT,
2020
"integrationTests": CONNECTOR_TEST_STEP_ID.INTEGRATION,
2121
"acceptanceTests": CONNECTOR_TEST_STEP_ID.ACCEPTANCE,
22+
"liveTests": CONNECTOR_TEST_STEP_ID.CONNECTOR_LIVE_TESTS,
2223
}
2324

2425

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/connectors/test/steps/common.py

+52-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from functools import cached_property
1414
from pathlib import Path
1515
from textwrap import dedent
16-
from typing import ClassVar, List, Optional, Set
16+
from typing import Any, ClassVar, Dict, List, Optional, Set
1717

1818
import requests # type: ignore
1919
import semver
@@ -445,7 +445,7 @@ async def _run(self, current_acceptance_tests_result: StepResult) -> StepResult:
445445

446446

447447
class LiveTestSuite(Enum):
448-
ALL = "all"
448+
ALL = "live"
449449
REGRESSION = "regression"
450450
VALIDATION = "validation"
451451

@@ -557,13 +557,10 @@ def __init__(self, context: ConnectorContext) -> None:
557557
self.connector_image = context.docker_image.split(":")[0]
558558
options = self.context.run_step_options.step_params.get(CONNECTOR_TEST_STEP_ID.CONNECTOR_LIVE_TESTS, {})
559559

560-
self.connection_id = self.context.run_step_options.get_item_or_default(options, "connection-id", None)
561-
self.pr_url = self.context.run_step_options.get_item_or_default(options, "pr-url", None)
560+
self.test_suite = self.context.run_step_options.get_item_or_default(options, "test-suite", LiveTestSuite.REGRESSION.value)
561+
self.connection_id = self._get_connection_id(options)
562+
self.pr_url = self._get_pr_url(options)
562563

563-
if not self.connection_id and self.pr_url:
564-
raise ValueError("`connection-id` and `pr-url` are required to run live tests.")
565-
566-
self.test_suite = self.context.run_step_options.get_item_or_default(options, "test-suite", LiveTestSuite.ALL.value)
567564
self.test_dir = self.test_suite_to_dir[LiveTestSuite(self.test_suite)]
568565
self.control_version = self.context.run_step_options.get_item_or_default(options, "control-version", None)
569566
self.target_version = self.context.run_step_options.get_item_or_default(options, "target-version", "dev")
@@ -573,6 +570,26 @@ def __init__(self, context: ConnectorContext) -> None:
573570
self.connection_subset = self.context.run_step_options.get_item_or_default(options, "connection-subset", "sandboxes")
574571
self.run_id = os.getenv("GITHUB_RUN_ID") or str(int(time.time()))
575572

573+
def _get_connection_id(self, options: Dict[str, List[Any]]) -> Optional[str]:
574+
if self.context.is_pr:
575+
connection_id = self._get_connection_from_test_connections()
576+
self.logger.info(
577+
f"Context is {self.context.ci_context}; got connection_id={connection_id} from metadata.yaml liveTests testConnections."
578+
)
579+
else:
580+
connection_id = self.context.run_step_options.get_item_or_default(options, "connection-id", None)
581+
self.logger.info(f"Context is {self.context.ci_context}; got connection_id={connection_id} from input options.")
582+
return connection_id
583+
584+
def _get_pr_url(self, options: Dict[str, List[Any]]) -> Optional[str]:
585+
if self.context.is_pr:
586+
pull_request = self.context.pull_request.url if self.context.pull_request else None
587+
self.logger.info(f"Context is {self.context.ci_context}; got pull_request={pull_request} from context.")
588+
else:
589+
pull_request = self.context.run_step_options.get_item_or_default(options, "pr-url", None)
590+
self.logger.info(f"Context is {self.context.ci_context}; got pull_request={pull_request} from input options.")
591+
return pull_request
592+
576593
def _validate_job_can_run(self) -> None:
577594
connector_type = self.context.connector.metadata.get("connectorType")
578595
connector_subtype = self.context.connector.metadata.get("connectorSubtype")
@@ -582,6 +599,30 @@ def _validate_job_can_run(self) -> None:
582599
self.connection_subset == "sandboxes"
583600
), f"Live tests for database sources may only be run against sandbox connections, got `connection_subset={self.connection_subset}`."
584601

602+
assert self.connection_id, "`connection-id` is required to run live tests."
603+
assert self.pr_url, "`pr_url` is required to run live tests."
604+
605+
if self.context.is_pr:
606+
connection_id_is_valid = False
607+
for test_suite in self.context.connector.metadata.get("connectorTestSuitesOptions", []):
608+
if test_suite["suite"] == "liveTests":
609+
assert self.connection_id in [
610+
option["id"] for option in test_suite.get("testConnections", [])
611+
], f"Connection ID {self.connection_id} was not in the list of valid test connections."
612+
connection_id_is_valid = True
613+
break
614+
assert connection_id_is_valid, f"Connection ID {self.connection_id} is not a valid sandbox connection ID."
615+
616+
def _get_connection_from_test_connections(self) -> Optional[str]:
617+
for test_suite in self.context.connector.metadata.get("connectorTestSuitesOptions", []):
618+
if test_suite["suite"] == "liveTests":
619+
for option in test_suite.get("testConnections", []):
620+
connection_id = option["id"]
621+
connection_name = option["name"]
622+
self.logger.info(f"Using connection name={connection_name}; id={connection_id}")
623+
return connection_id
624+
return None
625+
585626
async def _run(self, connector_under_test_container: Container) -> StepResult:
586627
"""Run the regression test suite.
587628
@@ -594,9 +635,10 @@ async def _run(self, connector_under_test_container: Container) -> StepResult:
594635
try:
595636
self._validate_job_can_run()
596637
except AssertionError as exc:
638+
self.logger.info(f"Skipping live tests for {self.context.connector.technical_name} due to validation error {str(exc)}.")
597639
return StepResult(
598640
step=self,
599-
status=StepStatus.FAILURE,
641+
status=StepStatus.SKIPPED,
600642
exc_info=exc,
601643
)
602644

@@ -624,6 +666,7 @@ async def _run(self, connector_under_test_container: Container) -> StepResult:
624666
stdout=stdout,
625667
output=container,
626668
report=regression_test_report,
669+
consider_in_overall_status=False if self.context.is_pr else True,
627670
)
628671

629672
async def _build_test_container(self, target_container_id: str) -> Container:

airbyte-ci/connectors/pipelines/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pipelines"
7-
version = "4.26.1"
7+
version = "4.27.0"
88
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
99
authors = ["Airbyte <[email protected]>"]
1010

0 commit comments

Comments
 (0)