-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AKS]
az aks command invoke
: Add progress spinner (#30274)
- Loading branch information
1 parent
e8bcbfb
commit eb55296
Showing
3 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from typing import Dict | ||
|
||
from azure.core.polling.base_polling import LocationPolling, _is_empty, BadResponse, _as_json | ||
|
||
|
||
class RunCommandLocationPolling(LocationPolling): | ||
"""Extends LocationPolling but uses the body content instead of the status code for the status""" | ||
|
||
@staticmethod | ||
def _get_provisioning_state(response): | ||
"""Attempt to get provisioning state from resource. | ||
:param azure.core.pipeline.transport.HttpResponse response: latest REST call response. | ||
:returns: Status if found, else 'None'. | ||
""" | ||
if _is_empty(response): | ||
return None | ||
body: Dict = _as_json(response) | ||
return body.get("properties", {}).get("provisioningState") | ||
|
||
def get_status(self, pipeline_response): | ||
"""Process the latest status update retrieved from the same URL as | ||
the previous request. | ||
:param azure.core.pipeline.PipelineResponse response: latest REST call response. | ||
:raises: BadResponse if status not 200 or 204. | ||
""" | ||
response = pipeline_response.http_response | ||
if _is_empty(response): | ||
raise BadResponse( | ||
"The response from long running operation does not contain a body." | ||
) | ||
|
||
status = self._get_provisioning_state(response) | ||
return status or "Unknown" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_pollers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import unittest | ||
from unittest.mock import Mock | ||
|
||
from azure.cli.command_modules.acs._polling import RunCommandLocationPolling | ||
from azure.core.pipeline import PipelineResponse | ||
from azure.core.rest import HttpRequest, HttpResponse | ||
|
||
|
||
class TestRunCommandPoller(unittest.TestCase): | ||
def test_get_status(self): | ||
poller = RunCommandLocationPolling() | ||
|
||
mock_response = Mock(spec=HttpResponse) | ||
mock_response.text.return_value = "{\"properties\": {\"provisioningState\": \"Scaling Up\"}}" | ||
|
||
pipeline_response: PipelineResponse[HttpRequest, HttpResponse] = PipelineResponse(Mock(spec=HttpRequest), mock_response, Mock()) | ||
|
||
status = poller.get_status(pipeline_response) | ||
assert status == "Scaling Up" | ||
|
||
def test_get_status_no_provisioning_state(self): | ||
poller = RunCommandLocationPolling() | ||
|
||
mock_response = Mock(spec=HttpResponse) | ||
mock_response.text.return_value = "{\"properties\": {\"status\": \"Scaling Up\"}}" | ||
|
||
pipeline_response: PipelineResponse[HttpRequest, HttpResponse] = PipelineResponse(Mock(spec=HttpRequest), mock_response, Mock()) | ||
|
||
status = poller.get_status(pipeline_response) | ||
assert status == "Unknown" |