Merge pull request #2738 from bblommers/bugfix/2732
EC2 AMI Creation bugfix - Fix AMI owner
This commit is contained in:
commit
200cd7c3e1
@ -27,6 +27,7 @@ from moto.core.utils import (
|
||||
iso_8601_datetime_with_milliseconds,
|
||||
camelcase_to_underscores,
|
||||
)
|
||||
from moto.iam.models import ACCOUNT_ID
|
||||
from .exceptions import (
|
||||
CidrLimitExceeded,
|
||||
DependencyViolationError,
|
||||
@ -155,7 +156,7 @@ AMIS = _load_resource(
|
||||
)
|
||||
|
||||
|
||||
OWNER_ID = "111122223333"
|
||||
OWNER_ID = ACCOUNT_ID
|
||||
|
||||
|
||||
def utc_date_and_time():
|
||||
@ -1341,7 +1342,7 @@ class AmiBackend(object):
|
||||
source_ami=None,
|
||||
name=name,
|
||||
description=description,
|
||||
owner_id=context.get_current_user() if context else OWNER_ID,
|
||||
owner_id=OWNER_ID,
|
||||
)
|
||||
self.amis[ami_id] = ami
|
||||
return ami
|
||||
@ -1392,14 +1393,7 @@ class AmiBackend(object):
|
||||
# Limit by owner ids
|
||||
if owners:
|
||||
# support filtering by Owners=['self']
|
||||
owners = list(
|
||||
map(
|
||||
lambda o: context.get_current_user()
|
||||
if context and o == "self"
|
||||
else o,
|
||||
owners,
|
||||
)
|
||||
)
|
||||
owners = list(map(lambda o: OWNER_ID if o == "self" else o, owners,))
|
||||
images = [ami for ami in images if ami.owner_id in owners]
|
||||
|
||||
# Generic filters
|
||||
|
@ -12,6 +12,7 @@ import sure # noqa
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
from moto.ec2.models import AMIS, OWNER_ID
|
||||
from moto.iam.models import ACCOUNT_ID
|
||||
from tests.helpers import requires_boto_gte
|
||||
|
||||
|
||||
@ -251,6 +252,19 @@ def test_ami_pulls_attributes_from_instance():
|
||||
image.kernel_id.should.equal("test-kernel")
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
def test_ami_uses_account_id_if_valid_access_key_is_supplied():
|
||||
access_key = "AKIAXXXXXXXXXXXXXXXX"
|
||||
conn = boto.connect_ec2(access_key, "the_secret")
|
||||
reservation = conn.run_instances("ami-1234abcd")
|
||||
instance = reservation.instances[0]
|
||||
instance.modify_attribute("kernel", "test-kernel")
|
||||
|
||||
image_id = conn.create_image(instance.id, "test-ami", "this is a test ami")
|
||||
images = conn.get_all_images(owners=["self"])
|
||||
[(ami.id, ami.owner_id) for ami in images].should.equal([(image_id, ACCOUNT_ID)])
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
def test_ami_filters():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
@ -773,7 +787,7 @@ def test_ami_filter_wildcard():
|
||||
instance.create_image(Name="not-matching-image")
|
||||
|
||||
my_images = ec2_client.describe_images(
|
||||
Owners=["111122223333"], Filters=[{"Name": "name", "Values": ["test*"]}]
|
||||
Owners=[ACCOUNT_ID], Filters=[{"Name": "name", "Values": ["test*"]}]
|
||||
)["Images"]
|
||||
my_images.should.have.length_of(1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user