2014-08-25 22:09:38 +00:00
|
|
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
|
|
|
import tests.backport_assert_raises
|
|
|
|
from nose.tools import assert_raises
|
|
|
|
|
2013-02-22 04:13:01 +00:00
|
|
|
import boto
|
2013-02-23 19:22:09 +00:00
|
|
|
from boto.exception import EC2ResponseError
|
|
|
|
|
2013-08-03 21:21:25 +00:00
|
|
|
import sure # noqa
|
2013-02-22 04:13:01 +00:00
|
|
|
|
|
|
|
from moto import mock_ec2
|
|
|
|
|
|
|
|
|
|
|
|
@mock_ec2
|
2013-02-23 19:22:09 +00:00
|
|
|
def test_ami_create_and_delete():
|
|
|
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
2013-03-05 13:14:43 +00:00
|
|
|
reservation = conn.run_instances('ami-1234abcd')
|
2013-02-23 19:22:09 +00:00
|
|
|
instance = reservation.instances[0]
|
2013-02-28 05:08:35 +00:00
|
|
|
image = conn.create_image(instance.id, "test-ami", "this is a test ami")
|
2013-02-23 19:22:09 +00:00
|
|
|
|
|
|
|
all_images = conn.get_all_images()
|
|
|
|
all_images[0].id.should.equal(image)
|
|
|
|
|
|
|
|
success = conn.deregister_image(image)
|
|
|
|
success.should.be.true
|
|
|
|
|
2014-08-25 17:54:47 +00:00
|
|
|
with assert_raises(EC2ResponseError) as cm:
|
|
|
|
conn.deregister_image(image)
|
|
|
|
cm.exception.code.should.equal('InvalidAMIID.NotFound')
|
|
|
|
cm.exception.status.should.equal(400)
|
|
|
|
cm.exception.request_id.should_not.be.none
|
2013-03-11 04:12:22 +00:00
|
|
|
|
2013-02-23 19:22:09 +00:00
|
|
|
|
2014-05-11 23:00:28 +00:00
|
|
|
@mock_ec2
|
|
|
|
def test_ami_tagging():
|
|
|
|
conn = boto.connect_vpc('the_key', 'the_secret')
|
|
|
|
reservation = conn.run_instances('ami-1234abcd')
|
|
|
|
instance = reservation.instances[0]
|
|
|
|
conn.create_image(instance.id, "test-ami", "this is a test ami")
|
|
|
|
image = conn.get_all_images()[0]
|
|
|
|
|
|
|
|
image.add_tag("a key", "some value")
|
|
|
|
|
|
|
|
tag = conn.get_all_tags()[0]
|
|
|
|
tag.name.should.equal("a key")
|
|
|
|
tag.value.should.equal("some value")
|
|
|
|
|
|
|
|
# Refresh the DHCP options
|
|
|
|
image = conn.get_all_images()[0]
|
|
|
|
image.tags.should.have.length_of(1)
|
|
|
|
image.tags["a key"].should.equal("some value")
|
|
|
|
|
|
|
|
|
2013-02-23 19:22:09 +00:00
|
|
|
@mock_ec2
|
|
|
|
def test_ami_create_from_missing_instance():
|
|
|
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
2013-03-05 13:14:43 +00:00
|
|
|
args = ["i-abcdefg", "test-ami", "this is a test ami"]
|
2014-08-25 17:54:47 +00:00
|
|
|
|
|
|
|
with assert_raises(EC2ResponseError) as cm:
|
|
|
|
conn.create_image(*args)
|
|
|
|
cm.exception.code.should.equal('InvalidInstanceID.NotFound')
|
|
|
|
cm.exception.status.should.equal(400)
|
|
|
|
cm.exception.request_id.should_not.be.none
|
2013-02-23 19:22:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_ec2
|
|
|
|
def test_ami_pulls_attributes_from_instance():
|
|
|
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
2013-03-05 13:14:43 +00:00
|
|
|
reservation = conn.run_instances('ami-1234abcd')
|
2013-02-23 19:22:09 +00:00
|
|
|
instance = reservation.instances[0]
|
|
|
|
instance.modify_attribute("kernel", "test-kernel")
|
|
|
|
|
2013-02-28 05:08:35 +00:00
|
|
|
image_id = conn.create_image(instance.id, "test-ami", "this is a test ami")
|
2013-02-23 19:22:09 +00:00
|
|
|
image = conn.get_image(image_id)
|
2013-03-05 13:35:18 +00:00
|
|
|
image.kernel_id.should.equal('test-kernel')
|
2014-01-28 23:14:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_ec2
|
|
|
|
def test_getting_missing_ami():
|
|
|
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
2014-08-25 17:54:47 +00:00
|
|
|
|
|
|
|
with assert_raises(EC2ResponseError) as cm:
|
|
|
|
conn.get_image('ami-missing')
|
|
|
|
cm.exception.code.should.equal('InvalidAMIID.NotFound')
|
|
|
|
cm.exception.status.should.equal(400)
|
|
|
|
cm.exception.request_id.should_not.be.none
|
|
|
|
|