# Path: loadsbroker/tests/util.py
# def clear_boto_context():
#     endpoints = os.environ.get('BOTO_ENDPOINTS')
#     if endpoints is not None:
#         del os.environ['BOTO_ENDPOINTS']
#     s = StringIO()
#     boto.config.write(s)
#     s.seek(0)
#     boto.config.clear()
#     return s.read(), endpoints
# 
# def load_boto_context(config, endpoints=None):
#     s = StringIO()
#     s.write(config)
#     boto.config.clear()
#     boto.config.read(s)
#     if endpoints is not None:
#         os.environ['BOTO_ENDPOINTS'] = endpoints
# 
# def create_image(region="us-west-2"):
#     conn = boto.ec2.connect_to_region(region)
#     reservation = conn.run_instances('ami-1234abcd')
#     instance = reservation.instances[0]
#     conn.create_image(instance.id, "Core OS stable")


import unittest
import boto
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
from datetime import datetime, timedelta
from tornado.testing import AsyncTestCase, gen_test
from moto import mock_ec2
from freezegun import freeze_time
from loadsbroker.tests.util import (clear_boto_context, load_boto_context,
                                    create_image)
        from loadsbroker.aws import available_instance
        from loadsbroker.aws import EC2Collection
        from loadsbroker.aws import EC2Pool




ec2_mocker = mock_ec2()
_OLD_CONTEXT = []


def setUp():
    _OLD_CONTEXT[:] = list(clear_boto_context())
    ec2_mocker.start()
    create_image()


def tearDown():
    ec2_mocker.stop()
    load_boto_context(*_OLD_CONTEXT)


def nuke_backend():
    for backend in ec2_mocker.backends.values():
        backend.reset()


class Test_populate_ami_ids(unittest.TestCase):
    def setUp(self):
        # Nuke the backend
        nuke_backend()


# Path: loadsbroker/tests/util.py
# def clear_boto_context():
#     endpoints = os.environ.get('BOTO_ENDPOINTS')
#     if endpoints is not None:
#         del os.environ['BOTO_ENDPOINTS']
#     s = StringIO()
#     boto.config.write(s)
#     s.seek(0)
#     boto.config.clear()
#     return s.read(), endpoints
# 
# def load_boto_context(config, endpoints=None):
#     s = StringIO()
#     s.write(config)
#     boto.config.clear()
#     boto.config.read(s)
#     if endpoints is not None:
#         os.environ['BOTO_ENDPOINTS'] = endpoints
# 
# def create_image(region="us-west-2"):
#     conn = boto.ec2.connect_to_region(region)
#     reservation = conn.run_instances('ami-1234abcd')
#     instance = reservation.instances[0]
#     conn.create_image(instance.id, "Core OS stable")


# Path: loadsbroker/tests/test_units/test_aws.py
import unittest
import boto
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
        import loadsbroker.aws
from datetime import datetime, timedelta
from tornado.testing import AsyncTestCase, gen_test
from moto import mock_ec2
from freezegun import freeze_time
from loadsbroker.tests.util import (clear_boto_context, load_boto_context,
                                    create_image)
        from loadsbroker.aws import available_instance
        from loadsbroker.aws import EC2Collection
        from loadsbroker.aws import EC2Pool





ec2_mocker = mock_ec2()
_OLD_CONTEXT = []


def setUp():
    _OLD_CONTEXT[:] = list(clear_boto_context())
    ec2_mocker.start()
    create_image()


def tearDown():
    ec2_mocker.stop()
    load_boto_context(*_OLD_CONTEXT)


def nuke_backend():
    for backend in ec2_mocker.backends.values():
        backend.reset()


class Test_populate_ami_ids(unittest.TestCase):
    def setUp(self):
        # Nuke the backend
        nuke_backend()


    def tearDown(self):