2017-09-27 14:56:45 +00:00
|
|
|
import boto3
|
2023-11-30 15:55:51 +00:00
|
|
|
import pytest
|
2021-07-26 14:21:17 +00:00
|
|
|
from botocore.exceptions import ClientError
|
2013-02-22 04:13:01 +00:00
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws
|
2021-01-13 09:02:11 +00:00
|
|
|
from tests import EXAMPLE_AMI_ID
|
2013-02-22 04:13:01 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2022-04-18 20:44:56 +00:00
|
|
|
def test_console_output():
|
2017-09-27 14:56:45 +00:00
|
|
|
conn = boto3.resource("ec2", "us-east-1")
|
2021-01-13 09:02:11 +00:00
|
|
|
instances = conn.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1)
|
2017-09-27 14:56:45 +00:00
|
|
|
|
|
|
|
output = instances[0].console_output()
|
2023-07-18 15:33:16 +00:00
|
|
|
assert output.get("Output") is not None
|
2021-09-25 11:13:07 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2022-04-18 20:44:56 +00:00
|
|
|
def test_console_output_without_instance():
|
2021-09-25 11:13:07 +00:00
|
|
|
client = boto3.client("ec2", "us-east-1")
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.get_console_output(InstanceId="i-1234abcd")
|
2023-07-17 09:31:05 +00:00
|
|
|
assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
|
|
|
assert ex.value.response["ResponseMetadata"]["RequestId"] is not None
|
|
|
|
assert ex.value.response["Error"]["Code"] == "InvalidInstanceID.NotFound"
|