OpenMetadata/ingestion/tests/integration/automations/test_connection_automation.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

137 lines
4.7 KiB
Python
Raw Normal View History

# Copyright 2025 Collate
# Licensed under the Collate Community License, Version 1.0 (the "License");
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
OpenMetadata high-level API Workflow test
"""
import sys
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
import pytest
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
from metadata.generated.schema.api.automations.createWorkflow import (
CreateWorkflowRequest,
)
from metadata.generated.schema.entity.automations.testServiceConnection import (
TestServiceConnectionRequest,
)
from metadata.generated.schema.entity.automations.workflow import (
Workflow,
WorkflowStatus,
WorkflowType,
)
from metadata.generated.schema.entity.services.connections.database.common.basicAuth import (
BasicAuth,
)
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
from metadata.generated.schema.entity.services.connections.database.mysqlConnection import (
MysqlConnection,
MySQLType,
)
from metadata.generated.schema.entity.services.connections.testConnectionResult import (
StatusType,
)
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
from metadata.generated.schema.entity.services.databaseService import DatabaseConnection
from metadata.generated.schema.entity.services.serviceType import ServiceType
from metadata.ingestion.source.connections import get_test_connection_fn
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
if sys.version_info < (3, 9):
pytest.skip("requires python 3.9+", allow_module_level=True)
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
def test_connection_workflow(metadata, mysql_container):
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
"""
Test all the steps related to the test connection automation workflow
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
"""
service_connection = MysqlConnection(
username=mysql_container.username,
authType=BasicAuth(password=mysql_container.password),
hostPort=f"localhost:{mysql_container.get_exposed_port(3306)}",
)
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
new_workflow_request = CreateWorkflowRequest(
name="test-connection-mysql",
description="description",
workflowType=WorkflowType.TEST_CONNECTION,
request=TestServiceConnectionRequest(
serviceType=ServiceType.Database,
connectionType=MySQLType.Mysql.value,
connection=DatabaseConnection(
config=service_connection,
),
[WIP] - Test Connection - Prepare the new test connection ingestion+UI logic (#10660) * Prepare the new test connection ingestion logic * Update test assert * Update Test Connection for SQA Sources * Correct return type and method doc * Handle decryption * Non SQA Database Sources * Add the run_automation script in ingestion-base * Dashboard Test Connection Changes * Pipeline, Messagin, MlModel & Metadata Sources * ui: test connect flow-1 * Unmask connection parameters before sending to Ariflow * ui: test connect flow-2 * Address review comments and pylint * pytest fix * ui: test connect flow-3 (refactoring and style fix) * ui: test connect flow-4 (fix test connection status logic) * sync local file * ui: test connect flow-5 (fix lowercase issue and styling) * ui: test connect flow-5 (show toast notifications) * test: add unit test * ui: test connect flow-5 (update service page test connection button) * Databrick fix & pytest fix * pylint * Update test * Fix merge * S3 Test connection * add style for mandatory step * sync locales * chore: add service name in workflow request * Unmask using original service connection parameters * Fix test connection unmasking * Wrap inspector function to eliminate error outside test conn * Fix linting * fix:cy test * Fix linting * address comment * refactor and fix connection type casing issue --------- Co-authored-by: ulixius9 <mayursingal9@gmail.com> Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com> Co-authored-by: Nahuel Verdugo Revigliono <nahuel@getcollate.io> Co-authored-by: Mayur Singal <39544459+ulixius9@users.noreply.github.com>
2023-03-28 06:29:13 +02:00
),
)
automation_workflow: Workflow = metadata.create_or_update(data=new_workflow_request)
test_connection_fn = get_test_connection_fn(service_connection)
test_connection_fn(metadata, automation_workflow=automation_workflow)
final_workflow: Workflow = metadata.get_by_name(
entity=Workflow, fqn="test-connection-mysql"
)
assert final_workflow.status == WorkflowStatus.Successful
assert len(final_workflow.response.steps) == 5
# Get queries is not passing since we're not enabling the logs in the container
assert final_workflow.response.status.value == StatusType.Failed.value
steps = [
step for step in final_workflow.response.steps if step.name != "GetQueries"
]
assert all(step.passed for step in steps)
metadata.delete(
entity=Workflow,
entity_id=str(automation_workflow.id.root),
hard_delete=True,
)
def test_connection_workflow_ko(metadata):
"""Test connection that will fail"""
wrong_service_connection = MysqlConnection(
username="openmetadata_user",
authType=BasicAuth(password="openmetadata_password"),
hostPort="localhost:8585", # There's something running there, but it's not MySQL
databaseSchema="openmetadata_db",
)
wrong_workflow_request = CreateWorkflowRequest(
name="test-connection-mysql-bad",
description="description",
workflowType=WorkflowType.TEST_CONNECTION,
request=TestServiceConnectionRequest(
serviceType=ServiceType.Database,
connectionType=MySQLType.Mysql.value,
connection=DatabaseConnection(
config=wrong_service_connection,
),
),
)
automation_workflow: Workflow = metadata.create_or_update(
data=wrong_workflow_request
)
test_connection_fn = get_test_connection_fn(wrong_service_connection)
test_connection_fn(metadata, automation_workflow=automation_workflow)
final_workflow: Workflow = metadata.get_by_name(
entity=Workflow, fqn="test-connection-mysql-bad"
)
assert final_workflow.response.status == StatusType.Failed
metadata.delete(
entity=Workflow,
entity_id=str(automation_workflow.id.root),
hard_delete=True,
)