2020-10-06 05:54:49 +00:00
|
|
|
import pytest
|
2014-08-25 22:09:38 +00:00
|
|
|
|
2013-02-22 04:13:01 +00:00
|
|
|
import boto
|
2017-09-27 14:56:45 +00:00
|
|
|
import boto3
|
2013-03-06 03:11:58 +00:00
|
|
|
from boto.exception import EC2ResponseError
|
2021-10-18 19:44:29 +00:00
|
|
|
import sure # noqa # pylint: disable=unused-import
|
2021-07-26 14:21:17 +00:00
|
|
|
from botocore.exceptions import ClientError
|
2013-02-22 04:13:01 +00:00
|
|
|
|
2017-09-27 14:56:45 +00:00
|
|
|
from moto import mock_ec2_deprecated, mock_ec2
|
2021-01-13 09:02:11 +00:00
|
|
|
from tests import EXAMPLE_AMI_ID
|
2013-02-22 04:13:01 +00:00
|
|
|
|
|
|
|
|
2021-09-25 11:13:07 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_ec2_deprecated
|
2013-03-06 03:11:58 +00:00
|
|
|
def test_console_output():
|
2019-10-31 15:44:26 +00:00
|
|
|
conn = boto.connect_ec2("the_key", "the_secret")
|
2021-01-13 09:02:11 +00:00
|
|
|
reservation = conn.run_instances(EXAMPLE_AMI_ID)
|
2013-03-06 03:11:58 +00:00
|
|
|
instance_id = reservation.instances[0].id
|
|
|
|
output = conn.get_console_output(instance_id)
|
|
|
|
output.output.should_not.equal(None)
|
|
|
|
|
|
|
|
|
2021-09-25 11:13:07 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_ec2_deprecated
|
2013-03-06 03:11:58 +00:00
|
|
|
def test_console_output_without_instance():
|
2019-10-31 15:44:26 +00:00
|
|
|
conn = boto.connect_ec2("the_key", "the_secret")
|
2014-08-25 17:54:47 +00:00
|
|
|
|
2020-10-06 05:54:49 +00:00
|
|
|
with pytest.raises(EC2ResponseError) as cm:
|
2019-10-31 15:44:26 +00:00
|
|
|
conn.get_console_output("i-1234abcd")
|
2021-07-26 14:21:17 +00:00
|
|
|
cm.value.error_code.should.equal("InvalidInstanceID.NotFound")
|
2020-10-06 06:04:09 +00:00
|
|
|
cm.value.status.should.equal(400)
|
|
|
|
cm.value.request_id.should_not.be.none
|
2017-09-27 14:56:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_ec2
|
|
|
|
def test_console_output_boto3():
|
2019-10-31 15:44:26 +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()
|
2019-10-31 15:44:26 +00:00
|
|
|
output.get("Output").should_not.equal(None)
|
2021-09-25 11:13:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_ec2
|
|
|
|
def test_console_output_without_instance_boto3():
|
|
|
|
client = boto3.client("ec2", "us-east-1")
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.get_console_output(InstanceId="i-1234abcd")
|
|
|
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
ex.value.response["ResponseMetadata"]["RequestId"].shouldnt.be.none
|
|
|
|
ex.value.response["Error"]["Code"].should.equal("InvalidInstanceID.NotFound")
|