From 558148c6ded5ee6e05dedced154130b7b8cf8140 Mon Sep 17 00:00:00 2001 From: Jens Scheffler <95105677+jscheffl@users.noreply.github.com> Date: Sat, 7 Dec 2024 15:47:30 +0100 Subject: [PATCH] Remove Provider Deprecations in Microsoft-PSRP (#44761) --- .../providers/microsoft/psrp/CHANGELOG.rst | 9 +++++++++ .../providers/microsoft/psrp/hooks/psrp.py | 16 +--------------- .../tests/microsoft/psrp/hooks/test_psrp.py | 12 +----------- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/providers/src/airflow/providers/microsoft/psrp/CHANGELOG.rst b/providers/src/airflow/providers/microsoft/psrp/CHANGELOG.rst index 794ba1d6cb6a3..0fcec517f0b50 100644 --- a/providers/src/airflow/providers/microsoft/psrp/CHANGELOG.rst +++ b/providers/src/airflow/providers/microsoft/psrp/CHANGELOG.rst @@ -27,6 +27,15 @@ Changelog --------- +main +.... + +.. warning:: + All deprecated classes, parameters and features have been removed from the Microsoft.PSRP provider package. + The following breaking changes were introduced: + + * Passing kwargs to ``invoke_cmdlet`` was removed. Please use ``parameters`` instead. + 2.8.0 ..... diff --git a/providers/src/airflow/providers/microsoft/psrp/hooks/psrp.py b/providers/src/airflow/providers/microsoft/psrp/hooks/psrp.py index 9c855703f9dc0..cc5e2da178630 100644 --- a/providers/src/airflow/providers/microsoft/psrp/hooks/psrp.py +++ b/providers/src/airflow/providers/microsoft/psrp/hooks/psrp.py @@ -22,7 +22,6 @@ from copy import copy from logging import DEBUG, ERROR, INFO, WARNING from typing import TYPE_CHECKING, Any, Callable -from warnings import warn from weakref import WeakKeyDictionary from pypsrp.host import PSHost @@ -30,7 +29,7 @@ from pypsrp.powershell import PowerShell, PSInvocationState, RunspacePool from pypsrp.wsman import WSMan -from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning +from airflow.exceptions import AirflowException from airflow.hooks.base import BaseHook INFORMATIONAL_RECORD_LEVEL_MAP = { @@ -229,21 +228,8 @@ def invoke_cmdlet( use_local_scope: bool | None = None, arguments: list[str] | None = None, parameters: dict[str, str] | None = None, - **kwargs: str, ) -> PowerShell: """Invoke a PowerShell cmdlet and return session.""" - if kwargs: - if parameters: - raise ValueError("**kwargs not allowed when 'parameters' is used at the same time.") - warn( - "Passing **kwargs to 'invoke_cmdlet' is deprecated " - "and will be removed in a future release. Please use 'parameters' " - "instead.", - AirflowProviderDeprecationWarning, - stacklevel=2, - ) - parameters = kwargs - with self.invoke() as ps: ps.add_cmdlet(name, use_local_scope=use_local_scope) for argument in arguments or (): diff --git a/providers/tests/microsoft/psrp/hooks/test_psrp.py b/providers/tests/microsoft/psrp/hooks/test_psrp.py index 1f56e67a7a689..71251a216c956 100644 --- a/providers/tests/microsoft/psrp/hooks/test_psrp.py +++ b/providers/tests/microsoft/psrp/hooks/test_psrp.py @@ -25,7 +25,7 @@ from pypsrp.messages import MessageType from pypsrp.powershell import PSInvocationState -from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning +from airflow.exceptions import AirflowException from airflow.models import Connection from airflow.providers.microsoft.psrp.hooks.psrp import PsrpHook @@ -195,16 +195,6 @@ def test_invoke_cmdlet(self, *mocks): assert [call({"bar": "1", "baz": "2"})] == ps.add_parameters.mock_calls assert [call(arg) for arg in arguments] == ps.add_argument.mock_calls - def test_invoke_cmdlet_deprecated_kwargs(self, *mocks): - with PsrpHook(CONNECTION_ID) as hook: - with pytest.warns( - AirflowProviderDeprecationWarning, - match=r"Passing \*\*kwargs to 'invoke_cmdlet' is deprecated and will be removed in a future release. Please use 'parameters' instead.", - ): - ps = hook.invoke_cmdlet("foo", bar="1", baz="2") - assert [call("foo", use_local_scope=None)] == ps.add_cmdlet.mock_calls - assert [call({"bar": "1", "baz": "2"})] == ps.add_parameters.mock_calls - def test_invoke_powershell(self, *mocks): with PsrpHook(CONNECTION_ID) as hook: ps = hook.invoke_powershell("foo")