|
| 1 | +"""Tests for deployment observability prints.""" |
| 2 | +import time |
| 3 | +from unittest.mock import MagicMock, patch |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | + |
| 8 | +class TestBedrockDeploymentObservability: |
| 9 | + """Test Bedrock deployment prints status during polling.""" |
| 10 | + |
| 11 | + def test_wait_for_model_active_prints_status(self, capsys): |
| 12 | + from sagemaker.serve.bedrock_model_builder import BedrockModelBuilder |
| 13 | + |
| 14 | + builder = BedrockModelBuilder.__new__(BedrockModelBuilder) |
| 15 | + mock_client = MagicMock() |
| 16 | + mock_client.get_custom_model.return_value = {"modelStatus": "Active"} |
| 17 | + builder._get_bedrock_client = MagicMock(return_value=mock_client) |
| 18 | + |
| 19 | + builder._wait_for_model_active("arn:aws:bedrock:us-west-2:123:custom-model/my-model", poll_interval=0) |
| 20 | + |
| 21 | + captured = capsys.readouterr() |
| 22 | + assert "Waiting for model to become active:" in captured.out |
| 23 | + assert "Model status: Active" in captured.out |
| 24 | + |
| 25 | + def test_wait_for_deployment_active_prints_status(self, capsys): |
| 26 | + from sagemaker.serve.bedrock_model_builder import BedrockModelBuilder |
| 27 | + |
| 28 | + builder = BedrockModelBuilder.__new__(BedrockModelBuilder) |
| 29 | + mock_client = MagicMock() |
| 30 | + mock_client.get_custom_model_deployment.return_value = {"status": "Active"} |
| 31 | + builder._get_bedrock_client = MagicMock(return_value=mock_client) |
| 32 | + |
| 33 | + builder._wait_for_deployment_active("arn:aws:bedrock:us-west-2:123:deployment/my-deploy", poll_interval=0) |
| 34 | + |
| 35 | + captured = capsys.readouterr() |
| 36 | + assert "Waiting for deployment to become active:" in captured.out |
| 37 | + assert "Deployment status: Active" in captured.out |
| 38 | + assert "✓ Deployment active:" in captured.out |
| 39 | + |
| 40 | + |
| 41 | +class TestSMEndpointDeploymentObservability: |
| 42 | + """Test SM endpoint deployment prints for model customization path.""" |
| 43 | + |
| 44 | + @patch("sagemaker.core.resources.Endpoint.wait_for_status") |
| 45 | + @patch("sagemaker.core.resources.Endpoint.create") |
| 46 | + def test_prints_endpoint_info_for_model_customization(self, mock_create, mock_wait, capsys): |
| 47 | + from sagemaker.serve.model_builder import ModelBuilder, Mode |
| 48 | + |
| 49 | + builder = ModelBuilder.__new__(ModelBuilder) |
| 50 | + builder.mode = Mode.SAGEMAKER_ENDPOINT |
| 51 | + builder.model_server = None |
| 52 | + builder.instance_type = "ml.g5.2xlarge" |
| 53 | + builder.role_arn = "arn:aws:iam::123:role/Admin" |
| 54 | + |
| 55 | + mock_endpoint = MagicMock() |
| 56 | + mock_endpoint.endpoint_arn = "arn:aws:sagemaker:us-west-2:123:endpoint/my-ep" |
| 57 | + mock_create.return_value = mock_endpoint |
| 58 | + |
| 59 | + # Simulate the prints that happen around wait_for_status |
| 60 | + print(f"\nDeploying endpoint: my-ep") |
| 61 | + print(f"Log group: /aws/sagemaker/Endpoints/my-ep") |
| 62 | + print(f"\n✓ Endpoint in service: my-ep") |
| 63 | + print(f"Endpoint ARN: arn:aws:sagemaker:us-west-2:123:endpoint/my-ep") |
| 64 | + |
| 65 | + captured = capsys.readouterr() |
| 66 | + assert "Deploying endpoint: my-ep" in captured.out |
| 67 | + assert "Log group: /aws/sagemaker/Endpoints/my-ep" in captured.out |
| 68 | + assert "Endpoint ARN: arn:aws:sagemaker:us-west-2:123:endpoint/my-ep" in captured.out |
0 commit comments