From e786c78f528ab3f9f8073ad1b4dc7323b8e5a0ce Mon Sep 17 00:00:00 2001 From: Kalyan R Date: Sat, 7 Dec 2024 20:21:47 +0530 Subject: [PATCH] Remove Provider Deprecations in Yandex provider (#44754) --- .../airflow/providers/yandex/CHANGELOG.rst | 13 ++++++ .../airflow/providers/yandex/hooks/yandex.py | 24 +---------- .../yandex/hooks/yandexcloud_dataproc.py | 30 ------------- .../providers/yandex/operators/dataproc.py | 12 ------ .../yandex/operators/yandexcloud_dataproc.py | 30 ------------- providers/tests/yandex/hooks/test_yandex.py | 42 ------------------- 6 files changed, 15 insertions(+), 136 deletions(-) delete mode 100644 providers/src/airflow/providers/yandex/hooks/yandexcloud_dataproc.py delete mode 100644 providers/src/airflow/providers/yandex/operators/yandexcloud_dataproc.py diff --git a/providers/src/airflow/providers/yandex/CHANGELOG.rst b/providers/src/airflow/providers/yandex/CHANGELOG.rst index a34d53265e92f..2f3b6822448e9 100644 --- a/providers/src/airflow/providers/yandex/CHANGELOG.rst +++ b/providers/src/airflow/providers/yandex/CHANGELOG.rst @@ -27,6 +27,19 @@ Changelog --------- +main +.... + +.. warning:: + All deprecated classes, parameters and features have been removed from the {provider_name} provider package. + The following breaking changes were introduced: + + * removed ``YandexCloudBaseHook.provider_user_agent`` . Use ``utils.user_agent.provider_user_agent`` instead. + * removed ``connection_id`` parameter from ``YandexCloudBaseHook``. Use ``yandex_conn_id`` parameter. + * removed ``yandex.hooks.yandexcloud_dataproc`` module. + * removed ``yandex.operators.yandexcloud_dataproc`` module. + * removed implicit passing of ``yandex_conn_id`` in ``DataprocBaseOperator``. Please pass it as a parameter. + 3.12.0 ...... diff --git a/providers/src/airflow/providers/yandex/hooks/yandex.py b/providers/src/airflow/providers/yandex/hooks/yandex.py index f132b708229c2..a8e796c08c143 100644 --- a/providers/src/airflow/providers/yandex/hooks/yandex.py +++ b/providers/src/airflow/providers/yandex/hooks/yandex.py @@ -16,12 +16,10 @@ # under the License. from __future__ import annotations -import warnings from typing import Any import yandexcloud -from airflow.exceptions import AirflowProviderDeprecationWarning from airflow.hooks.base import BaseHook from airflow.providers.yandex.utils.credentials import ( CredentialsType, @@ -38,7 +36,6 @@ class YandexCloudBaseHook(BaseHook): A base hook for Yandex.Cloud related tasks. :param yandex_conn_id: The connection ID to use when fetching connection info - :param connection_id: Deprecated, use yandex_conn_id instead :param default_folder_id: The folder ID to use instead of connection folder ID :param default_public_ssh_key: The key to use instead of connection key :param default_service_account_id: The service account ID to use instead of key service account ID @@ -96,16 +93,6 @@ def get_connection_form_widgets(cls) -> dict[str, Any]: ), } - @classmethod - def provider_user_agent(cls) -> str | None: - warnings.warn( - "Using `provider_user_agent` in `YandexCloudBaseHook` is deprecated. " - "Please use it in `utils.user_agent` instead.", - AirflowProviderDeprecationWarning, - stacklevel=2, - ) - return provider_user_agent() - @classmethod def get_ui_field_behaviour(cls) -> dict[str, Any]: """Return custom UI field behaviour for Yandex connection.""" @@ -116,21 +103,14 @@ def get_ui_field_behaviour(cls) -> dict[str, Any]: def __init__( self, - # connection_id is deprecated, use yandex_conn_id instead - connection_id: str | None = None, yandex_conn_id: str | None = None, default_folder_id: str | None = None, default_public_ssh_key: str | None = None, default_service_account_id: str | None = None, ) -> None: super().__init__() - if connection_id: - warnings.warn( - "Using `connection_id` is deprecated. Please use `yandex_conn_id` parameter.", - AirflowProviderDeprecationWarning, - stacklevel=2, - ) - self.connection_id = yandex_conn_id or connection_id or default_conn_name + + self.connection_id = yandex_conn_id or default_conn_name self.connection = self.get_connection(self.connection_id) self.extras = self.connection.extra_dejson self.credentials: CredentialsType = get_credentials( diff --git a/providers/src/airflow/providers/yandex/hooks/yandexcloud_dataproc.py b/providers/src/airflow/providers/yandex/hooks/yandexcloud_dataproc.py deleted file mode 100644 index 6256769c9230f..0000000000000 --- a/providers/src/airflow/providers/yandex/hooks/yandexcloud_dataproc.py +++ /dev/null @@ -1,30 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -"""This module is deprecated. Please use :mod:`airflow.providers.yandex.hooks.dataproc` instead.""" - -from __future__ import annotations - -import warnings - -from airflow.exceptions import AirflowProviderDeprecationWarning -from airflow.providers.yandex.hooks.dataproc import * # noqa: F403 - -warnings.warn( - "This module is deprecated. Please use `airflow.providers.yandex.hooks.dataproc` instead.", - AirflowProviderDeprecationWarning, - stacklevel=2, -) diff --git a/providers/src/airflow/providers/yandex/operators/dataproc.py b/providers/src/airflow/providers/yandex/operators/dataproc.py index eb5ce140f55e3..20f992496da0a 100644 --- a/providers/src/airflow/providers/yandex/operators/dataproc.py +++ b/providers/src/airflow/providers/yandex/operators/dataproc.py @@ -16,12 +16,10 @@ # under the License. from __future__ import annotations -import warnings from collections.abc import Iterable, Sequence from dataclasses import dataclass from typing import TYPE_CHECKING -from airflow.exceptions import AirflowProviderDeprecationWarning from airflow.models import BaseOperator from airflow.providers.yandex.hooks.dataproc import DataprocHook @@ -269,16 +267,6 @@ def __init__(self, *, yandex_conn_id: str | None = None, cluster_id: str | None def _setup(self, context: Context) -> DataprocHook: if self.cluster_id is None: self.cluster_id = context["task_instance"].xcom_pull(key="cluster_id") - if self.yandex_conn_id is None: - xcom_yandex_conn_id = context["task_instance"].xcom_pull(key="yandexcloud_connection_id") - if xcom_yandex_conn_id: - warnings.warn( - "Implicit pass of `yandex_conn_id` is deprecated, please pass it explicitly", - AirflowProviderDeprecationWarning, - stacklevel=2, - ) - self.yandex_conn_id = xcom_yandex_conn_id - return DataprocHook(yandex_conn_id=self.yandex_conn_id) def execute(self, context: Context): diff --git a/providers/src/airflow/providers/yandex/operators/yandexcloud_dataproc.py b/providers/src/airflow/providers/yandex/operators/yandexcloud_dataproc.py deleted file mode 100644 index 1f7db5d512c77..0000000000000 --- a/providers/src/airflow/providers/yandex/operators/yandexcloud_dataproc.py +++ /dev/null @@ -1,30 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -"""This module is deprecated. Please use :mod:`airflow.providers.yandex.operators.dataproc` instead.""" - -from __future__ import annotations - -import warnings - -from airflow.exceptions import AirflowProviderDeprecationWarning -from airflow.providers.yandex.operators.dataproc import * # noqa: F403 - -warnings.warn( - "This module is deprecated. Please use `airflow.providers.yandex.operators.dataproc` instead.", - AirflowProviderDeprecationWarning, - stacklevel=2, -) diff --git a/providers/tests/yandex/hooks/test_yandex.py b/providers/tests/yandex/hooks/test_yandex.py index 7066c3e7553b1..92188cd07f319 100644 --- a/providers/tests/yandex/hooks/test_yandex.py +++ b/providers/tests/yandex/hooks/test_yandex.py @@ -17,15 +17,12 @@ # under the License. from __future__ import annotations -import os from unittest import mock -from unittest.mock import MagicMock import pytest yandexcloud = pytest.importorskip("yandexcloud") -from airflow.exceptions import AirflowProviderDeprecationWarning from airflow.providers.yandex.hooks.yandex import YandexCloudBaseHook from tests_common.test_utils.config import conf_vars @@ -55,23 +52,6 @@ def test_client_created_without_exceptions(self, mock_get_credentials, mock_get_ ) assert hook.client is not None - @mock.patch("airflow.hooks.base.BaseHook.get_connection") - @mock.patch("airflow.providers.yandex.utils.credentials.get_credentials") - def test_provider_user_agent(self, mock_get_credentials, mock_get_connection): - mock_get_connection.return_value = mock.Mock(yandex_conn_id="yandexcloud_default", extra_dejson="{}") - mock_get_credentials.return_value = {"token": 122323} - sdk_prefix = "MyAirflow" - - hook = YandexCloudBaseHook() - with ( - conf_vars({("yandex", "sdk_user_agent_prefix"): sdk_prefix}), - pytest.warns( - AirflowProviderDeprecationWarning, - match="Using `provider_user_agent` in `YandexCloudBaseHook` is deprecated. Please use it in `utils.user_agent` instead.", - ), - ): - assert hook.provider_user_agent().startswith(sdk_prefix) - @mock.patch("airflow.hooks.base.BaseHook.get_connection") @mock.patch("airflow.providers.yandex.utils.credentials.get_credentials") def test_sdk_user_agent(self, mock_get_credentials, mock_get_connection): @@ -83,28 +63,6 @@ def test_sdk_user_agent(self, mock_get_credentials, mock_get_connection): hook = YandexCloudBaseHook() assert hook.sdk._channels._client_user_agent.startswith(sdk_prefix) - @pytest.mark.parametrize( - "uri", - [ - pytest.param( - "a://?extra__yandexcloud__folder_id=abc&extra__yandexcloud__public_ssh_key=abc", id="prefix" - ), - pytest.param("a://?folder_id=abc&public_ssh_key=abc", id="no-prefix"), - ], - ) - @mock.patch("airflow.providers.yandex.utils.credentials.get_credentials", new=MagicMock()) - def test_backcompat_prefix_works(self, uri): - with ( - mock.patch.dict(os.environ, {"AIRFLOW_CONN_MY_CONN": uri}), - pytest.warns( - AirflowProviderDeprecationWarning, - match="Using `connection_id` is deprecated. Please use `yandex_conn_id` parameter.", - ), - ): - hook = YandexCloudBaseHook("my_conn") - assert hook.default_folder_id == "abc" - assert hook.default_public_ssh_key == "abc" - @mock.patch("airflow.hooks.base.BaseHook.get_connection") @mock.patch("airflow.providers.yandex.utils.credentials.get_credentials") def test_get_endpoint_specified(self, mock_get_credentials, mock_get_connection):