From 1970d84bec2106c8c53d8e611b74d41eb5286e9b Mon Sep 17 00:00:00 2001 From: Jonas L Date: Wed, 3 Jul 2024 09:31:27 +0200 Subject: [PATCH] feat!: return full rebuild response in `Client.servers.rebuild` (#406) The single action returned was deprecated and is now removed in favor of the full rebuild response with a root password. --- hcloud/servers/client.py | 20 ++++---------------- tests/unit/servers/test_client.py | 5 ----- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/hcloud/servers/client.py b/hcloud/servers/client.py index e4b26795..7eb66daf 100644 --- a/hcloud/servers/client.py +++ b/hcloud/servers/client.py @@ -1,6 +1,5 @@ from __future__ import annotations -import warnings from datetime import datetime from typing import TYPE_CHECKING, Any, NamedTuple @@ -1006,9 +1005,9 @@ def rebuild( self, server: Server | BoundServer, image: Image | BoundImage, - *, - return_response: bool = False, - ) -> RebuildResponse | BoundAction: + # pylint: disable=unused-argument + **kwargs: Any, + ) -> RebuildResponse: """Rebuilds a server overwriting its disk with the content of an image, thereby destroying all data on the target server. :param server: Server to rebuild @@ -1022,22 +1021,11 @@ def rebuild( json=data, ) - rebuild_response = RebuildResponse( + return RebuildResponse( action=BoundAction(self._client.actions, response["action"]), root_password=response.get("root_password"), ) - if not return_response: - warnings.warn( - "Returning only the 'action' is deprecated, please set the " - "'return_response' keyword argument to 'True' to return the full " - "rebuild response and update your code accordingly.", - DeprecationWarning, - stacklevel=2, - ) - return rebuild_response.action - return rebuild_response - def enable_backup(self, server: Server | BoundServer) -> BoundAction: """Enables and configures the automatic daily backup option for the server. Enabling automatic backups will increase the price of the server by 20%. diff --git a/tests/unit/servers/test_client.py b/tests/unit/servers/test_client.py index 70823c30..b338979b 100644 --- a/tests/unit/servers/test_client.py +++ b/tests/unit/servers/test_client.py @@ -1085,11 +1085,6 @@ def test_rebuild(self, servers_client, server, generic_action): assert response.action.progress == 0 assert response.root_password is None or isinstance(response.root_password, str) - def test_rebuild_return_response_deprecation(self, servers_client, generic_action): - servers_client._client.request.return_value = generic_action - with pytest.deprecated_call(): - servers_client.rebuild(Server(id=1), Image(name="ubuntu-20.04")) - @pytest.mark.parametrize( "server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))] )