From 386de5167af9b362a65305472540278164cc39dc Mon Sep 17 00:00:00 2001 From: "v.sharma" Date: Tue, 17 Sep 2024 18:06:42 +0530 Subject: [PATCH 1/4] [DBAAS] | Add API endpoint for applying cluster patches --- src/pydo/operations/_operations.py | 132 +++++++++++++++++++++++++++++ tests/mocked/test_databases.py | 17 ++++ 2 files changed, 149 insertions(+) diff --git a/src/pydo/operations/_operations.py b/src/pydo/operations/_operations.py index c0250817..36c81aec 100644 --- a/src/pydo/operations/_operations.py +++ b/src/pydo/operations/_operations.py @@ -1864,6 +1864,29 @@ def build_databases_promote_replica_request( return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) +def build_databases_install_update_request( + database_cluster_uuid: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/databases/{database_cluster_uuid}/install_update" + path_format_arguments = { + "database_cluster_uuid": _SERIALIZER.url( + "database_cluster_uuid", database_cluster_uuid, "str" + ), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) + + def build_databases_list_users_request( database_cluster_uuid: str, **kwargs: Any ) -> HttpRequest: @@ -103371,6 +103394,115 @@ def promote_replica( return deserialized # type: ignore + @distributed_trace + def install_update( + self, database_cluster_uuid: str, **kwargs: Any + ) -> Optional[JSON]: + # pylint: disable=line-too-long + """Start Installation of Updates. + + To start installation of update for a database cluster, + send a PUT request to ``/v2/databases/$DATABASE_ID/install_update``. + A successful request will receive a 204 No Content status code with no body in response. + + A status of 204 will be given. This indicates that the request was processed successfully, but + that no response body is needed. + + :param database_cluster_uuid: A unique identifier for a database cluster. Required. + :type database_cluster_uuid: str + :return: JSON object or None + :rtype: JSON or None + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[Optional[JSON]] = kwargs.pop("cls", None) + + _request = build_databases_install_update_request( + database_cluster_uuid=database_cluster_uuid, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [204, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + deserialized = None + response_headers = {} + if response.status_code == 204: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + @distributed_trace def list_users(self, database_cluster_uuid: str, **kwargs: Any) -> JSON: # pylint: disable=line-too-long diff --git a/tests/mocked/test_databases.py b/tests/mocked/test_databases.py index 79e09ec8..9294c319 100644 --- a/tests/mocked/test_databases.py +++ b/tests/mocked/test_databases.py @@ -940,6 +940,23 @@ def test_databases_update_maintenance_window(mock_client: Client, mock_client_ur assert resp is None +@responses.activate +def test_databases_update_install_update(mock_client: Client, mock_client_url): + """Mocks the databases Starts installation of updates.""" + + cluster_uuid = "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30" + + responses.add( + responses.PUT, + f"{mock_client_url}/v2/databases/{cluster_uuid}/install_update", + status=204, + ) + + resp = mock_client.databases.install_update( + cluster_uuid, + ) + + assert resp is None @responses.activate def test_databases_update_online_migration(mock_client: Client, mock_client_url): From ac6487a5d9c95ed58e86e8c2c3c95648dfb8a094 Mon Sep 17 00:00:00 2001 From: "v.sharma" Date: Tue, 17 Sep 2024 21:59:33 +0530 Subject: [PATCH 2/4] removed un-necessary changes --- src/pydo/operations/_operations.py | 130 ----------------------------- 1 file changed, 130 deletions(-) diff --git a/src/pydo/operations/_operations.py b/src/pydo/operations/_operations.py index c3b12594..f637a9da 100644 --- a/src/pydo/operations/_operations.py +++ b/src/pydo/operations/_operations.py @@ -1887,28 +1887,6 @@ def build_databases_promote_replica_request( return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) -def build_databases_install_update_request( - database_cluster_uuid: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = "/v2/databases/{database_cluster_uuid}/install_update" - path_format_arguments = { - "database_cluster_uuid": _SERIALIZER.url( - "database_cluster_uuid", database_cluster_uuid, "str" - ), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) - def build_databases_list_users_request( database_cluster_uuid: str, **kwargs: Any @@ -103587,114 +103565,6 @@ def promote_replica( return deserialized # type: ignore - @distributed_trace - def install_update( - self, database_cluster_uuid: str, **kwargs: Any - ) -> Optional[JSON]: - # pylint: disable=line-too-long - """Start Installation of Updates. - - To start installation of update for a database cluster, - send a PUT request to ``/v2/databases/$DATABASE_ID/install_update``. - A successful request will receive a 204 No Content status code with no body in response. - - A status of 204 will be given. This indicates that the request was processed successfully, but - that no response body is needed. - - :param database_cluster_uuid: A unique identifier for a database cluster. Required. - :type database_cluster_uuid: str - :return: JSON object or None - :rtype: JSON or None - :raises ~azure.core.exceptions.HttpResponseError: - - Example: - .. code-block:: python - - # response body for status code(s): 404 - response == { - "id": "str", # A short identifier corresponding to the HTTP status code - returned. For example, the ID for a response returning a 404 status code would - be "not_found.". Required. - "message": "str", # A message providing additional information about the - error, including details to help resolve it when possible. Required. - "request_id": "str" # Optional. Optionally, some endpoints may include a - request ID that should be provided when reporting bugs or opening support - tickets to help identify the issue. - } - """ - error_map: MutableMapping[int, Type[HttpResponseError]] = { - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - 401: cast( - Type[HttpResponseError], - lambda response: ClientAuthenticationError(response=response), - ), - 429: HttpResponseError, - 500: HttpResponseError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = kwargs.pop("params", {}) or {} - - cls: ClsType[Optional[JSON]] = kwargs.pop("cls", None) - - _request = build_databases_install_update_request( - database_cluster_uuid=database_cluster_uuid, - headers=_headers, - params=_params, - ) - _request.url = self._client.format_url(_request.url) - - _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) - ) - - response = pipeline_response.http_response - - if response.status_code not in [204, 404]: - if _stream: - response.read() # Load the body in memory and close the socket - map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore - raise HttpResponseError(response=response) - - deserialized = None - response_headers = {} - if response.status_code == 204: - response_headers["ratelimit-limit"] = self._deserialize( - "int", response.headers.get("ratelimit-limit") - ) - response_headers["ratelimit-remaining"] = self._deserialize( - "int", response.headers.get("ratelimit-remaining") - ) - response_headers["ratelimit-reset"] = self._deserialize( - "int", response.headers.get("ratelimit-reset") - ) - - if response.status_code == 404: - response_headers["ratelimit-limit"] = self._deserialize( - "int", response.headers.get("ratelimit-limit") - ) - response_headers["ratelimit-remaining"] = self._deserialize( - "int", response.headers.get("ratelimit-remaining") - ) - response_headers["ratelimit-reset"] = self._deserialize( - "int", response.headers.get("ratelimit-reset") - ) - - if response.content: - deserialized = response.json() - else: - deserialized = None - - if cls: - return cls(pipeline_response, deserialized, response_headers) # type: ignore - - return deserialized # type: ignore @distributed_trace def list_users(self, database_cluster_uuid: str, **kwargs: Any) -> JSON: From 8cde882c90ed6d70059c3ee1648fcb9b272e2fb3 Mon Sep 17 00:00:00 2001 From: "v.sharma" Date: Tue, 17 Sep 2024 22:00:54 +0530 Subject: [PATCH 3/4] removed unused lines --- src/pydo/operations/_operations.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pydo/operations/_operations.py b/src/pydo/operations/_operations.py index f637a9da..8197261e 100644 --- a/src/pydo/operations/_operations.py +++ b/src/pydo/operations/_operations.py @@ -1887,7 +1887,6 @@ def build_databases_promote_replica_request( return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) - def build_databases_list_users_request( database_cluster_uuid: str, **kwargs: Any ) -> HttpRequest: @@ -103565,7 +103564,6 @@ def promote_replica( return deserialized # type: ignore - @distributed_trace def list_users(self, database_cluster_uuid: str, **kwargs: Any) -> JSON: # pylint: disable=line-too-long From 5341f54c6ac618c8ed3e4caa787edcafcef66a48 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Tue, 15 Oct 2024 17:02:05 -0400 Subject: [PATCH 4/4] Address linter issue --- tests/mocked/test_databases.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/mocked/test_databases.py b/tests/mocked/test_databases.py index 58bdafbf..bd39b88a 100644 --- a/tests/mocked/test_databases.py +++ b/tests/mocked/test_databases.py @@ -963,6 +963,7 @@ def test_databases_update_maintenance_window(mock_client: Client, mock_client_ur assert resp is None + @responses.activate def test_databases_update_install_update(mock_client: Client, mock_client_url): """Mocks the databases Starts installation of updates.""" @@ -981,6 +982,7 @@ def test_databases_update_install_update(mock_client: Client, mock_client_url): assert resp is None + @responses.activate def test_databases_update_online_migration(mock_client: Client, mock_client_url): """Mocks the databases update firewall rules operation."""