Fix for regression in get_console_output()
This commit is contained in:
parent
b17136e36c
commit
5b01071bd4
@ -5,7 +5,12 @@ from moto.core.responses import BaseResponse
|
|||||||
class General(BaseResponse):
|
class General(BaseResponse):
|
||||||
|
|
||||||
def get_console_output(self):
|
def get_console_output(self):
|
||||||
instance_id = self._get_multi_param('InstanceId')[0]
|
instance_id = self._get_param('InstanceId')
|
||||||
|
if not instance_id:
|
||||||
|
# For compatibility with boto.
|
||||||
|
# See: https://github.com/spulec/moto/pull/1152#issuecomment-332487599
|
||||||
|
instance_id = self._get_multi_param('InstanceId')[0]
|
||||||
|
|
||||||
instance = self.ec2_backend.get_instance(instance_id)
|
instance = self.ec2_backend.get_instance(instance_id)
|
||||||
template = self.response_template(GET_CONSOLE_OUTPUT_RESULT)
|
template = self.response_template(GET_CONSOLE_OUTPUT_RESULT)
|
||||||
return template.render(instance=instance)
|
return template.render(instance=instance)
|
||||||
|
@ -4,10 +4,11 @@ import tests.backport_assert_raises
|
|||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
|
import boto3
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
from moto import mock_ec2_deprecated
|
from moto import mock_ec2_deprecated, mock_ec2
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2_deprecated
|
@mock_ec2_deprecated
|
||||||
@ -15,7 +16,6 @@ def test_console_output():
|
|||||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
reservation = conn.run_instances('ami-1234abcd')
|
reservation = conn.run_instances('ami-1234abcd')
|
||||||
instance_id = reservation.instances[0].id
|
instance_id = reservation.instances[0].id
|
||||||
|
|
||||||
output = conn.get_console_output(instance_id)
|
output = conn.get_console_output(instance_id)
|
||||||
output.output.should_not.equal(None)
|
output.output.should_not.equal(None)
|
||||||
|
|
||||||
@ -29,3 +29,14 @@ def test_console_output_without_instance():
|
|||||||
cm.exception.code.should.equal('InvalidInstanceID.NotFound')
|
cm.exception.code.should.equal('InvalidInstanceID.NotFound')
|
||||||
cm.exception.status.should.equal(400)
|
cm.exception.status.should.equal(400)
|
||||||
cm.exception.request_id.should_not.be.none
|
cm.exception.request_id.should_not.be.none
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_console_output_boto3():
|
||||||
|
conn = boto3.resource('ec2', 'us-east-1')
|
||||||
|
instances = conn.create_instances(ImageId='ami-1234abcd',
|
||||||
|
MinCount=1,
|
||||||
|
MaxCount=1)
|
||||||
|
|
||||||
|
output = instances[0].console_output()
|
||||||
|
output.get('Output').should_not.equal(None)
|
||||||
|
Loading…
Reference in New Issue
Block a user