Skip to content

Commit bb389da

Browse files
zzn2GitHub Copilot
andauthored
{Cognitive Services} Add agent status command (#32691)
Co-authored-by: GitHub Copilot <copilot@users.noreply.github.com>
1 parent a0e5cf8 commit bb389da

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

src/azure-cli/azure/cli/command_modules/cognitiveservices/_help.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,18 @@
697697
text: az cognitiveservices agent stop --account-name myAccount --project-name myProject --name myAgent --agent-version 1
698698
"""
699699

700+
helps[
701+
"cognitiveservices agent status"
702+
] = """
703+
type: command
704+
short-summary: Get the status of a hosted agent deployment.
705+
long-summary: |
706+
Calls the agent container status endpoint and returns the raw service payload.
707+
examples:
708+
- name: Get hosted agent deployment status.
709+
text: az cognitiveservices agent status --account-name myAccount --project-name myProject --name myAgent --agent-version 1
710+
"""
711+
700712
helps[
701713
"cognitiveservices agent update"
702714
] = """

src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ def load_arguments(self, _):
387387
)
388388
c.argument("agent_version", help="Cognitive Services hosted agent version")
389389

390+
with self.argument_context("cognitiveservices agent status") as c:
391+
c.argument(
392+
"agent_version",
393+
help="Cognitive Services hosted agent version",
394+
required=True,
395+
)
396+
390397
with self.argument_context('cognitiveservices agent create') as c:
391398
c.argument(
392399
'agent_name',

src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def load_command_table(self, _):
124124
g.custom_command('update', 'agent_update')
125125
g.custom_command('stop', 'agent_stop')
126126
g.custom_command('start', 'agent_start')
127+
g.custom_show_command('status', 'agent_status')
127128
g.custom_command('delete-deployment', 'agent_delete_deployment')
128129
g.custom_command('delete', 'agent_delete')
129130
g.custom_command('list', 'agent_list')

src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,17 @@ def agent_show(
16721672
return response.json()
16731673

16741674

1675+
def agent_status(
1676+
client,
1677+
account_name,
1678+
project_name,
1679+
agent_name,
1680+
agent_version,
1681+
): # pylint: disable=unused-argument
1682+
"""Get the status of a hosted agent deployment (default container)."""
1683+
return _get_agent_container_status(client, agent_name, agent_version)
1684+
1685+
16751686
def _get_resource_group_by_account_name(cmd, account_name):
16761687
"""
16771688
Get resource group name for a Cognitive Services account by querying ARM.

src/azure-cli/azure/cli/command_modules/cognitiveservices/tests/latest/test_agent.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import os
4040
import tempfile
4141
import shutil
42+
from unittest import mock
43+
from urllib.parse import urlparse, parse_qs
4244

4345
from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer
4446
from azure.cli.testsdk.decorators import serial_test
@@ -55,12 +57,42 @@
5557
_is_docker_running,
5658
_is_fully_qualified_image,
5759
_validate_path_for_subprocess,
60+
_get_agent_container_status,
61+
AGENT_API_VERSION_PARAMS,
5862
)
5963
from azure.cli.command_modules.cognitiveservices._params import _environment_variables_type
6064

6165

6266
class CognitiveServicesAgentHelperTests(unittest.TestCase):
6367
"""Unit tests for agent helper functions."""
68+
69+
def test_get_agent_container_status_builds_expected_request(self):
70+
"""Test that agent status calls the default container endpoint and returns payload."""
71+
expected_payload = {"status": "Running"}
72+
73+
client = mock.Mock()
74+
response = mock.Mock()
75+
response.json.return_value = expected_payload
76+
client.send_request.return_value = response
77+
78+
result = _get_agent_container_status(client, "myAgent", "10")
79+
80+
self.assertEqual(result, expected_payload)
81+
client.send_request.assert_called_once()
82+
response.raise_for_status.assert_called_once()
83+
84+
request = client.send_request.call_args[0][0]
85+
self.assertEqual(getattr(request, "method", None), "GET")
86+
87+
parsed = urlparse(getattr(request, "url", ""))
88+
self.assertEqual(
89+
parsed.path,
90+
"/agents/myAgent/versions/10/containers/default",
91+
)
92+
self.assertEqual(
93+
parse_qs(parsed.query).get("api-version"),
94+
[AGENT_API_VERSION_PARAMS["api-version"]],
95+
)
6496

6597
def test_validate_image_tag_valid(self):
6698
"""Test tag validation and extraction from valid image URIs."""

0 commit comments

Comments
 (0)