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,
|
iso_8601_datetime_with_milliseconds,
|
||||||
camelcase_to_underscores,
|
camelcase_to_underscores,
|
||||||
)
|
)
|
||||||
|
from moto.iam.models import ACCOUNT_ID
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
CidrLimitExceeded,
|
CidrLimitExceeded,
|
||||||
DependencyViolationError,
|
DependencyViolationError,
|
||||||
@ -155,7 +156,7 @@ AMIS = _load_resource(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
OWNER_ID = "111122223333"
|
OWNER_ID = ACCOUNT_ID
|
||||||
|
|
||||||
|
|
||||||
def utc_date_and_time():
|
def utc_date_and_time():
|
||||||
@ -1341,7 +1342,7 @@ class AmiBackend(object):
|
|||||||
source_ami=None,
|
source_ami=None,
|
||||||
name=name,
|
name=name,
|
||||||
description=description,
|
description=description,
|
||||||
owner_id=context.get_current_user() if context else OWNER_ID,
|
owner_id=OWNER_ID,
|
||||||
)
|
)
|
||||||
self.amis[ami_id] = ami
|
self.amis[ami_id] = ami
|
||||||
return ami
|
return ami
|
||||||
@ -1392,14 +1393,7 @@ class AmiBackend(object):
|
|||||||
# Limit by owner ids
|
# Limit by owner ids
|
||||||
if owners:
|
if owners:
|
||||||
# support filtering by Owners=['self']
|
# support filtering by Owners=['self']
|
||||||
owners = list(
|
owners = list(map(lambda o: OWNER_ID if o == "self" else o, owners,))
|
||||||
map(
|
|
||||||
lambda o: context.get_current_user()
|
|
||||||
if context and o == "self"
|
|
||||||
else o,
|
|
||||||
owners,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
images = [ami for ami in images if ami.owner_id in owners]
|
images = [ami for ami in images if ami.owner_id in owners]
|
||||||
|
|
||||||
# Generic filters
|
# Generic filters
|
||||||
|
@ -12,6 +12,7 @@ import sure # noqa
|
|||||||
|
|
||||||
from moto import mock_ec2_deprecated, mock_ec2
|
from moto import mock_ec2_deprecated, mock_ec2
|
||||||
from moto.ec2.models import AMIS, OWNER_ID
|
from moto.ec2.models import AMIS, OWNER_ID
|
||||||
|
from moto.iam.models import ACCOUNT_ID
|
||||||
from tests.helpers import requires_boto_gte
|
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")
|
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
|
@mock_ec2_deprecated
|
||||||
def test_ami_filters():
|
def test_ami_filters():
|
||||||
conn = boto.connect_ec2("the_key", "the_secret")
|
conn = boto.connect_ec2("the_key", "the_secret")
|
||||||
@ -773,7 +787,7 @@ def test_ami_filter_wildcard():
|
|||||||
instance.create_image(Name="not-matching-image")
|
instance.create_image(Name="not-matching-image")
|
||||||
|
|
||||||
my_images = ec2_client.describe_images(
|
my_images = ec2_client.describe_images(
|
||||||
Owners=["111122223333"], Filters=[{"Name": "name", "Values": ["test*"]}]
|
Owners=[ACCOUNT_ID], Filters=[{"Name": "name", "Values": ["test*"]}]
|
||||||
)["Images"]
|
)["Images"]
|
||||||
my_images.should.have.length_of(1)
|
my_images.should.have.length_of(1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user