def fake_compute_get_all(*args, **kwargs):
    db_list = [
        fakes.stub_instance(1, uuid=UUID1, nw_cache=NW_CACHE),
        fakes.stub_instance(2, uuid=UUID2, nw_cache=NW_CACHE),
    ]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1], objects.InstanceList(),
                                            db_list, fields)
def fake_compute_get_all(*args, **kwargs):
    db_list = [
        fakes.stub_instance(1, uuid=UUID1, nw_cache=NW_CACHE),
        fakes.stub_instance(2, uuid=UUID2, nw_cache=NW_CACHE),
    ]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1],
                                            objects.InstanceList(),
                                            db_list, fields)
Exemple #3
0
def fake_compute_get_all(*args, **kwargs):
    inst1 = fakes.stub_instance(1, uuid=UUID1, host="all-host",
                                vm_state=vm_states.ACTIVE)
    inst2 = fakes.stub_instance(2, uuid=UUID2, host="all-host",
                                vm_state=vm_states.ACTIVE)
    db_list = [inst1, inst2]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1],
                                            objects.InstanceList(),
                                            db_list, fields)
Exemple #4
0
def fake_compute_get_all(*args, **kwargs):
    db_list = [
        fakes.stub_instance(2, uuid=UUID1, launched_at=DATE2,
                            terminated_at=DATE3),
        fakes.stub_instance(3, uuid=UUID2, launched_at=DATE1,
                            terminated_at=DATE3),
    ]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1],
                                            objects.InstanceList(),
                                            db_list, fields)
def fake_compute_get_all(*args, **kwargs):
    db_list = [
        fakes.stub_instance(1, uuid=UUID1, task_state="task-1",
                vm_state="vm-1", power_state=1),
        fakes.stub_instance(2, uuid=UUID2, task_state="task-2",
                vm_state="vm-2", power_state=2),
    ]

    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1],
                                            objects.InstanceList(),
                                            db_list, fields)
Exemple #6
0
def get_fake_db_instance(start,
                         end,
                         instance_id,
                         tenant_id,
                         vm_state=vm_states.ACTIVE):
    sys_meta = utils.dict_to_metadata(
        flavors.save_flavor_info({}, FAKE_INST_TYPE))
    # NOTE(mriedem): We use fakes.stub_instance since it sets the fields
    # needed on the db instance for converting it to an object, but we still
    # need to override system_metadata to use our fake flavor.
    inst = fakes.stub_instance(
        id=instance_id,
        uuid='00000000-0000-0000-0000-00000000000000%02d' % instance_id,
        image_ref='1',
        project_id=tenant_id,
        user_id='fakeuser',
        display_name='name',
        flavor_id=FAKE_INST_TYPE['id'],
        launched_at=start,
        terminated_at=end,
        vm_state=vm_state,
        memory_mb=MEMORY_MB,
        vcpus=VCPUS,
        root_gb=ROOT_GB,
        ephemeral_gb=EPHEMERAL_GB,
    )
    inst['system_metadata'] = sys_meta
    return inst
Exemple #7
0
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1,
                               uuid=UUID3,
                               task_state="kayaking",
                               vm_state="slightly crunchy",
                               power_state=1)
    return fake_instance.fake_instance_obj(args[1], **inst)
Exemple #8
0
    def test_get_instance_availability_zone_default_value(self):
        """Test get right availability zone by given an instance."""
        fake_inst_id = 162
        fake_inst = fakes.stub_instance(fake_inst_id, host=self.host)

        self.assertEqual(self.default_az,
                az.get_instance_availability_zone(self.context, fake_inst))
def instance_update_and_get_original(context, instance_uuid, values,
                                     update_cells=True,
                                     columns_to_join=None,
                                     ):
    inst = fakes.stub_instance(INSTANCE_IDS[instance_uuid], host='fake_host')
    inst = dict(inst, **values)
    return (inst, inst)
Exemple #10
0
def fake_compute_get_all(*args, **kwargs):
    db_list = [
        fakes.stub_instance(1,
                            uuid=UUID1,
                            task_state="task-1",
                            vm_state="vm-1",
                            power_state=1),
        fakes.stub_instance(2,
                            uuid=UUID2,
                            task_state="task-2",
                            vm_state="vm-2",
                            power_state=2),
    ]

    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1], objects.InstanceList(),
                                            db_list, fields)
def fake_instance_get(context, instance_id,
                      columns_to_join=None, use_slave=False):
    result = fakes.stub_instance(id=1, uuid=instance_id)
    result['created_at'] = None
    result['deleted_at'] = None
    result['updated_at'] = None
    result['deleted'] = 0
    result['info_cache'] = {'network_info': '[]',
                            'instance_uuid': result['uuid']}
    return result
def fake_compute_get_all(*args, **kwargs):
    db_list = [
        fakes.stub_instance(1, uuid=UUID1, host="host-1", node="node-1",
                            reservation_id="r-1", launch_index=0,
                            kernel_id=UUID4, ramdisk_id=UUID5,
                            display_name="hostname-1",
                            root_device_name="/dev/vda",
                            user_data="userdata"),
        fakes.stub_instance(2, uuid=UUID2, host="host-2", node="node-2",
                            reservation_id="r-2", launch_index=1,
                            kernel_id=UUID4, ramdisk_id=UUID5,
                            display_name="hostname-2",
                            root_device_name="/dev/vda",
                            user_data="userdata")
    ]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1],
                                            objects.InstanceList(),
                                            db_list, fields)
def fake_compute_get(*args, **kwargs):
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return objects.Instance._from_db_object(
        args[1], objects.Instance(),
        fakes.stub_instance(1, uuid=UUID3, host="host-fake",
                            node="node-fake",
                            reservation_id="r-1", launch_index=0,
                            kernel_id=UUID4, ramdisk_id=UUID5,
                            display_name="hostname-1",
                            root_device_name="/dev/vda",
                            user_data="userdata"), fields)
Exemple #14
0
    def test_get_instance_availability_zone_from_aggregate(self):
        """Test get availability zone from aggregate by given an instance."""
        host = 'host170'
        service = self._create_service_with_topic('compute', host)
        self._add_to_aggregate(service, self.agg)

        fake_inst_id = 174
        fake_inst = fakes.stub_instance(fake_inst_id, host=host)

        self.assertEqual(self.availability_zone,
                az.get_instance_availability_zone(self.context, fake_inst))
Exemple #15
0
    def test_detail_hides_building_server_addresses(self):
        instance_0 = fakes.stub_instance(0, uuid=fakes.get_fake_uuid(0),
                                         vm_state=vm_states.ACTIVE)
        instance_1 = fakes.stub_instance(1, uuid=fakes.get_fake_uuid(1),
                                         vm_state=vm_states.BUILDING)
        instances = [instance_0, instance_1]

        def get_all(*args, **kwargs):
            fields = instance_obj.INSTANCE_DEFAULT_FIELDS
            return instance_obj._make_instance_list(
                args[1], objects.InstanceList(), instances, fields)

        self.stubs.Set(compute.api.API, 'get_all', get_all)
        res = self._make_request(self.base_url + '/detail')

        self.assertEqual(res.status_int, 200)
        servers = self._get_servers(res.body)

        self.assertEqual(len(servers), len(instances))

        for instance, server in itertools.izip(instances, servers):
            addresses = self._get_addresses(server)
            exists = (instance['vm_state'] == vm_states.ACTIVE)
            self._check_addresses(addresses, exists=exists)
Exemple #16
0
    def test_get_devs_object(self):
        def _fake_obj_load_attr(foo, attrname):
            if attrname == 'pci_devices':
                self.load_attr_called = True
                foo.pci_devices = objects.PciDeviceList()

        inst = fakes.stub_instance(id='1')
        self.mox.StubOutWithMock(db, 'instance_get')
        db.instance_get(self.fake_context, '1', columns_to_join=[]
                        ).AndReturn(inst)
        self.mox.ReplayAll()
        inst = objects.Instance.get_by_id(self.fake_context, '1',
                                          expected_attrs=[])
        self.stubs.Set(objects.Instance, 'obj_load_attr', _fake_obj_load_attr)

        self.load_attr_called = False
        manager.get_instance_pci_devs(inst)
        self.assertEqual(self.load_attr_called, True)
Exemple #17
0
    def test_delete_security_group_in_use(self):
        sg = self._create_sg_template().get('security_group')
        self._create_network()
        db_inst = fakes.stub_instance(id=1, nw_cache=[], security_groups=[])
        _context = context.get_admin_context()
        instance = instance_obj.Instance._from_db_object(
            _context, instance_obj.Instance(), db_inst,
            expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS)
        neutron = neutron_api.API()
        with mock.patch.object(patron.db, 'instance_get_by_uuid',
                               return_value=db_inst):
            neutron.allocate_for_instance(_context, instance,
                                          security_groups=[sg['id']])

        req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/%s'
                                      % sg['id'])
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, sg['id'])
Exemple #18
0
    def test_get_devs_object(self):
        def _fake_obj_load_attr(foo, attrname):
            if attrname == 'pci_devices':
                self.load_attr_called = True
                foo.pci_devices = objects.PciDeviceList()

        inst = fakes.stub_instance(id='1')
        self.mox.StubOutWithMock(db, 'instance_get')
        db.instance_get(self.fake_context, '1',
                        columns_to_join=[]).AndReturn(inst)
        self.mox.ReplayAll()
        inst = objects.Instance.get_by_id(self.fake_context,
                                          '1',
                                          expected_attrs=[])
        self.stubs.Set(objects.Instance, 'obj_load_attr', _fake_obj_load_attr)

        self.load_attr_called = False
        manager.get_instance_pci_devs(inst)
        self.assertEqual(self.load_attr_called, True)
def get_fake_db_instance(start, end, instance_id, tenant_id,
                         vm_state=vm_states.ACTIVE):
    sys_meta = utils.dict_to_metadata(
        flavors.save_flavor_info({}, FAKE_INST_TYPE))
    # NOTE(mriedem): We use fakes.stub_instance since it sets the fields
    # needed on the db instance for converting it to an object, but we still
    # need to override system_metadata to use our fake flavor.
    inst = fakes.stub_instance(
            id=instance_id,
            uuid='00000000-0000-0000-0000-00000000000000%02d' % instance_id,
            image_ref='1',
            project_id=tenant_id,
            user_id='fakeuser',
            display_name='name',
            flavor_id=FAKE_INST_TYPE['id'],
            launched_at=start,
            terminated_at=end,
            vm_state=vm_state,
            memory_mb=MEMORY_MB,
            vcpus=VCPUS,
            root_gb=ROOT_GB,
            ephemeral_gb=EPHEMERAL_GB,)
    inst['system_metadata'] = sys_meta
    return inst
Exemple #20
0
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID3, launched_at=DATE1,
                               terminated_at=DATE2)
    return fake_instance.fake_instance_obj(args[1], **inst)
Exemple #21
0
def instance_update(context, instance_uuid, kwargs, update_cells=True):
    inst = fakes.stub_instance(INSTANCE_IDS[instance_uuid], host='fake_host')
    return inst
Exemple #22
0
 def _return_server(*_args, **_kwargs):
     inst = fakes.stub_instance(*args, **kwargs)
     return fake_instance.fake_instance_obj(_args[1], **inst)
 def setUp(self):
     super(SchedulerHintsTestCaseV21, self).setUp()
     self.fake_instance = fakes.stub_instance(1, uuid=UUID)
     self._set_up_router()
Exemple #24
0
    def setUp(self):
        super(DiskConfigTestCaseV21, self).setUp()
        self._set_up_app()
        self._setup_fake_image_service()

        fakes.stub_out_nw_api(self.stubs)

        FAKE_INSTANCES = [
            fakes.stub_instance(1,
                                uuid=MANUAL_INSTANCE_UUID,
                                auto_disk_config=False),
            fakes.stub_instance(2,
                                uuid=AUTO_INSTANCE_UUID,
                                auto_disk_config=True)
        ]

        def fake_instance_get(context, id_):
            for instance in FAKE_INSTANCES:
                if id_ == instance['id']:
                    return instance

        self.stubs.Set(db, 'instance_get', fake_instance_get)

        def fake_instance_get_by_uuid(context, uuid,
                                      columns_to_join=None, use_slave=False):
            for instance in FAKE_INSTANCES:
                if uuid == instance['uuid']:
                    return instance

        self.stubs.Set(db, 'instance_get_by_uuid',
                       fake_instance_get_by_uuid)

        def fake_instance_get_all(context, *args, **kwargs):
            return FAKE_INSTANCES

        self.stubs.Set(db, 'instance_get_all', fake_instance_get_all)
        self.stubs.Set(db, 'instance_get_all_by_filters',
                       fake_instance_get_all)

        self.stubs.Set(objects.Instance, 'save',
                       lambda *args, **kwargs: None)

        def fake_rebuild(*args, **kwargs):
            pass

        self.stubs.Set(compute_api.API, 'rebuild', fake_rebuild)

        def fake_instance_create(context, inst_, session=None):
            inst = fake_instance.fake_db_instance(**{
                    'id': 1,
                    'uuid': AUTO_INSTANCE_UUID,
                    'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'updated_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'progress': 0,
                    'name': 'instance-1',  # this is a property
                    'task_state': '',
                    'vm_state': '',
                    'auto_disk_config': inst_['auto_disk_config'],
                    'security_groups': inst_['security_groups'],
                    'instance_type': flavors.get_default_flavor(),
                    })

            def fake_instance_get_for_create(context, id_, *args, **kwargs):
                return (inst, inst)

            self.stubs.Set(db, 'instance_update_and_get_original',
                          fake_instance_get_for_create)

            def fake_instance_get_all_for_create(context, *args, **kwargs):
                return [inst]
            self.stubs.Set(db, 'instance_get_all',
                           fake_instance_get_all_for_create)
            self.stubs.Set(db, 'instance_get_all_by_filters',
                           fake_instance_get_all_for_create)

            def fake_instance_add_security_group(context, instance_id,
                                                 security_group_id):
                pass

            self.stubs.Set(db,
                           'instance_add_security_group',
                           fake_instance_add_security_group)

            return inst

        self.stubs.Set(db, 'instance_create', fake_instance_create)
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID3, task_state="kayaking",
            vm_state="slightly crunchy", power_state=1)
    return fake_instance.fake_instance_obj(args[1], **inst)
Exemple #26
0
    def setUp(self):
        super(DiskConfigTestCaseV21, self).setUp()
        self._set_up_app()
        self._setup_fake_image_service()

        fakes.stub_out_nw_api(self.stubs)

        FAKE_INSTANCES = [
            fakes.stub_instance(1,
                                uuid=MANUAL_INSTANCE_UUID,
                                auto_disk_config=False),
            fakes.stub_instance(2,
                                uuid=AUTO_INSTANCE_UUID,
                                auto_disk_config=True)
        ]

        def fake_instance_get(context, id_):
            for instance in FAKE_INSTANCES:
                if id_ == instance['id']:
                    return instance

        self.stubs.Set(db, 'instance_get', fake_instance_get)

        def fake_instance_get_by_uuid(context,
                                      uuid,
                                      columns_to_join=None,
                                      use_slave=False):
            for instance in FAKE_INSTANCES:
                if uuid == instance['uuid']:
                    return instance

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)

        def fake_instance_get_all(context, *args, **kwargs):
            return FAKE_INSTANCES

        self.stubs.Set(db, 'instance_get_all', fake_instance_get_all)
        self.stubs.Set(db, 'instance_get_all_by_filters',
                       fake_instance_get_all)

        self.stubs.Set(objects.Instance, 'save', lambda *args, **kwargs: None)

        def fake_rebuild(*args, **kwargs):
            pass

        self.stubs.Set(compute_api.API, 'rebuild', fake_rebuild)

        def fake_instance_create(context, inst_, session=None):
            inst = fake_instance.fake_db_instance(
                **{
                    'id': 1,
                    'uuid': AUTO_INSTANCE_UUID,
                    'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'updated_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'progress': 0,
                    'name': 'instance-1',  # this is a property
                    'task_state': '',
                    'vm_state': '',
                    'auto_disk_config': inst_['auto_disk_config'],
                    'security_groups': inst_['security_groups'],
                    'instance_type': flavors.get_default_flavor(),
                })

            def fake_instance_get_for_create(context, id_, *args, **kwargs):
                return (inst, inst)

            self.stubs.Set(db, 'instance_update_and_get_original',
                           fake_instance_get_for_create)

            def fake_instance_get_all_for_create(context, *args, **kwargs):
                return [inst]

            self.stubs.Set(db, 'instance_get_all',
                           fake_instance_get_all_for_create)
            self.stubs.Set(db, 'instance_get_all_by_filters',
                           fake_instance_get_all_for_create)

            def fake_instance_add_security_group(context, instance_id,
                                                 security_group_id):
                pass

            self.stubs.Set(db, 'instance_add_security_group',
                           fake_instance_add_security_group)

            return inst

        self.stubs.Set(db, 'instance_create', fake_instance_create)
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID1)
    return fake_instance.fake_instance_obj(args[1], **inst)
def fake_compute_get_all(*args, **kwargs):
    db_list = [fakes.stub_instance(1), fakes.stub_instance(2)]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1],
                                            objects.InstanceList(),
                                            db_list, fields)
Exemple #29
0
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID1)
    return fake_instance.fake_instance_obj(args[1], **inst)
Exemple #30
0
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID3, host="get-host",
                               vm_state=vm_states.ACTIVE)
    return fake_instance.fake_instance_obj(args[1], **inst)
Exemple #31
0
def fake_compute_get_empty(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID3, host="",
                               vm_state=vm_states.ACTIVE,
                               availability_zone='fakeaz')
    return fake_instance.fake_instance_obj(args[1], **inst)
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID3, nw_cache=NW_CACHE)
    return fake_instance.fake_instance_obj(args[1],
              expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS, **inst)
Exemple #33
0
def fake_compute_get_all(*args, **kwargs):
    db_list = [fakes.stub_instance(1), fakes.stub_instance(2)]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1], objects.InstanceList(),
                                            db_list, fields)