def test_build_chain(self): from amitools import build_chain all_images = [ MockImage('ami-33333333', {'source_image' : 'ami-44444444'}), MockImage('ami-77777777', {'source_image' : 'ami-88888888'}), MockImage('ami-44444444', {'source_image' : 'ami-55555555'}), MockImage('ami-55555555', {'source_image' : 'ami-66666666'}), MockImage('ami-11111111', {'source_image' : 'ami-22222222'}), MockImage('ami-66666666', {'source_image' : 'ami-77777777'}), MockImage('ami-22222222', {'source_image' : 'ami-33333333'}), ] expected = [ 'ami-11111111', 'ami-22222222', 'ami-33333333', 'ami-44444444', 'ami-55555555', 'ami-66666666', 'ami-77777777', 'ami-88888888', ] actual = build_chain('ami-11111111', all_images) self.assertSequenceEqual(expected, actual) expected = [ 'ami-44444444', 'ami-55555555', 'ami-66666666', 'ami-77777777', 'ami-88888888', ] actual = build_chain('ami-44444444', all_images) self.assertSequenceEqual(expected, actual)
def test_build_chain(self): from amitools import build_chain all_images = [ MockImage('ami-33333333', {'source_image': 'ami-44444444'}), MockImage('ami-77777777', {'source_image': 'ami-88888888'}), MockImage('ami-44444444', {'source_image': 'ami-55555555'}), MockImage('ami-55555555', {'source_image': 'ami-66666666'}), MockImage('ami-11111111', {'source_image': 'ami-22222222'}), MockImage('ami-66666666', {'source_image': 'ami-77777777'}), MockImage('ami-22222222', {'source_image': 'ami-33333333'}), ] expected = [ 'ami-11111111', 'ami-22222222', 'ami-33333333', 'ami-44444444', 'ami-55555555', 'ami-66666666', 'ami-77777777', 'ami-88888888', ] actual = build_chain('ami-11111111', all_images) self.assertSequenceEqual(expected, actual) expected = [ 'ami-44444444', 'ami-55555555', 'ami-66666666', 'ami-77777777', 'ami-88888888', ] actual = build_chain('ami-44444444', all_images) self.assertSequenceEqual(expected, actual)
def main(args): from amitools import ( ec2connect, build_chain, ) conn = ec2connect(args.region) all_images = conn.get_all_images(filters={'tag-key':'source_image'}) try: chain = build_chain(args.image_id, all_images) exit_code = CHAIN_SUCCESS except AssertionError: chain = [] exit_code = CHAIN_NO_AMI return { 'exit_code' : exit_code, 'chain' : chain, }