def stub_out_db_instance_api(test, injected=True):

    def _create_instance_type(**updates):
        instance_type = {'id': 2,
                         'name': 'm1.tiny',
                         'memory_mb': 512,
                         'vcpus': 1,
                         'vcpu_weight': None,
                         'root_gb': 0,
                         'ephemeral_gb': 10,
                         'flavorid': 1,
                         'rxtx_factor': 1.0,
                         'swap': 0,
                         'deleted_at': None,
                         'created_at': datetime.datetime(2014, 8, 8, 0, 0, 0),
                         'updated_at': None,
                         'deleted': False,
                         'disabled': False,
                         'is_public': True,
                         'extra_specs': {},
                        }
        if updates:
            instance_type.update(updates)
        return instance_type

    INSTANCE_TYPES = {
        'm1.tiny': _create_instance_type(
                        id=2,
                        name='m1.tiny',
                        memory_mb=512,
                        vcpus=1,
                        vcpu_weight=None,
                        root_gb=0,
                        ephemeral_gb=10,
                        flavorid=1,
                        rxtx_factor=1.0,
                        swap=0),
        'm1.small': _create_instance_type(
                        id=5,
                        name='m1.small',
                        memory_mb=2048,
                        vcpus=1,
                        vcpu_weight=None,
                        root_gb=20,
                        ephemeral_gb=0,
                        flavorid=2,
                        rxtx_factor=1.0,
                        swap=1024),
        'm1.medium': _create_instance_type(
                        id=1,
                         name='m1.medium',
                         memory_mb=4096,
                         vcpus=2,
                         vcpu_weight=None,
                         root_gb=40,
                         ephemeral_gb=40,
                         flavorid=3,
                         rxtx_factor=1.0,
                         swap=0),
        'm1.large': _create_instance_type(
                        id=3,
                         name='m1.large',
                         memory_mb=8192,
                         vcpus=4,
                         vcpu_weight=10,
                         root_gb=80,
                         ephemeral_gb=80,
                         flavorid=4,
                         rxtx_factor=1.0,
                         swap=0),
        'm1.xlarge': _create_instance_type(
                         id=4,
                         name='m1.xlarge',
                         memory_mb=16384,
                         vcpus=8,
                         vcpu_weight=None,
                         root_gb=160,
                         ephemeral_gb=160,
                         flavorid=5,
                         rxtx_factor=1.0,
                         swap=0)}

    fixed_ip_fields = {'address': '10.0.0.3',
                       'address_v6': 'fe80::a00:3',
                       'network_id': 'fake_flat'}

    def fake_flavor_get_all(*a, **k):
        return INSTANCE_TYPES.values()

    @classmethod
    def fake_flavor_get_by_name(cls, context, name):
        return INSTANCE_TYPES[name]

    @classmethod
    def fake_flavor_get(cls, context, id):
        for name, inst_type in six.iteritems(INSTANCE_TYPES):
            if str(inst_type['id']) == str(id):
                return inst_type
        return None

    def fake_fixed_ip_get_by_instance(context, instance_id):
        return [FakeModel(fixed_ip_fields)]

    funcs = {
        'nova.objects.flavor._flavor_get_all_from_db': (
            fake_flavor_get_all),
        'nova.objects.Flavor._flavor_get_by_name_from_db': (
            fake_flavor_get_by_name),
        'nova.objects.Flavor._flavor_get_from_db': fake_flavor_get,
        'nova.db.api.fixed_ip_get_by_instance': fake_fixed_ip_get_by_instance,
    }
    stub_out(test, funcs)
Test that the client iterator works.
dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/tests/unit/db/fakes.py/stub_out_db_instance_api--crossover with--dataset/ETHPy150Open google/grr/grr/lib/flow_test.py/GeneralFlowsTest.testIteratedDirectoryListing