Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DBAAS] | Add API endpoint for applying cluster patches #332

Merged
merged 9 commits into from
Oct 15, 2024
132 changes: 132 additions & 0 deletions src/pydo/operations/_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/mocked/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down