예제 #1
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, locked_by=None),
        fakes.stub_instance(2, uuid=UUID2, task_state="task-2", vm_state="vm-2", power_state=2, locked_by="admin"),
    ]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1], instance_obj.InstanceList(), db_list, fields)
def fake_compute_get_all(*args, **kwargs):
    db_list = [
        fakes.stub_instance(1, uuid=UUID1, host="host-1", node="node-1"),
        fakes.stub_instance(2, uuid=UUID2, host="host-2", node="node-2"),
    ]
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj._make_instance_list(args[1], instance_obj.InstanceList(), db_list, fields)
예제 #3
0
def fake_compute_get_all(*args, **kwargs):
    return [
        fakes.stub_instance(1, uuid=UUID1, task_state="task-1",
                vm_state="vm-1", power_state="power-1"),
        fakes.stub_instance(2, uuid=UUID2, task_state="task-2",
                vm_state="vm-2", power_state="power-2"),
    ]
예제 #4
0
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], instance_obj.InstanceList(), db_list, fields)
예제 #5
0
def fake_compute_get_all(*args, **kwargs):
    return [
        fakes.stub_instance(1, uuid=UUID1, task_state="task%s" % UUID1,
                vm_state="vm%s" % UUID1, power_state="power%s" % UUID1),
        fakes.stub_instance(2, uuid=UUID2, task_state="task%s" % UUID2,
                vm_state="vm%s" % UUID2, power_state="power%s" % UUID2),
    ]
예제 #6
0
def fake_compute_get_all(*args, **kwargs):
    return [
        fakes.stub_instance(2, uuid=UUID1, launched_at=DATE2,
                            terminated_at=DATE3),
        fakes.stub_instance(3, uuid=UUID2, launched_at=DATE1,
                            terminated_at=DATE3),
    ]
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],
                                            instance_obj.InstanceList(),
                                            db_list, fields)
예제 #8
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], instance_obj.InstanceList(), db_list, fields)
예제 #9
0
    def test_rebuild_accessIP(self):
        attributes = {
            'access_ip_v4': '172.19.0.1',
            'access_ip_v6': 'fe80::1',
        }

        body = {
            "rebuild": {
                "imageRef": self._image_href,
                "accessIPv4": "172.19.0.1",
                "accessIPv6": "fe80::1",
            },
        }

        update = self.mox.CreateMockAnything()
        self.stubs.Set(nova.compute.API, 'update', update)
        req = fakes.HTTPRequest.blank(self.url)
        context = req.environ['nova.context']
        update(context, mox.IgnoreArg(),
                image_ref=self._image_href,
                task_state=task_states.REBUILDING,
                expected_task_state=None,
                progress=0, **attributes).AndReturn(
                        fakes.stub_instance(1, host='fake_host'))
        self.mox.ReplayAll()

        self.controller._action_rebuild(req, FAKE_UUID, body)
예제 #10
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))
예제 #11
0
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)
예제 #12
0
 def test_add_image_ref(self, mock_root_metadata):
     mock_root_metadata.return_value = {'image_id': 'fake_image'}
     fake_instance = fakes.stub_instance(id=1, uuid=fakes.FAKE_UUID,
                                         image_ref='')
     ctx = context.RequestContext('fake-user', 'fake-project')
     new_instance = instance.add_image_ref(ctx, fake_instance)
     self.assertEqual('fake_image', new_instance['image_ref'])
예제 #13
0
def fake_instance_get(context, instance_id, columns_to_join=None):
    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": "foo", "instance_uuid": result["uuid"]}
    return result
 def setUp(self):
     super(SchedulerHintsTestCase, self).setUp()
     self.fake_instance = fakes.stub_instance(1, uuid=UUID)
     self.flags(
         osapi_compute_extension=[
             'nova.api.openstack.compute.contrib.select_extensions'],
         osapi_compute_ext_list=['Scheduler_hints'])
     self.app = compute.APIRouter(init_only=('servers',))
예제 #15
0
    def setUp(self):
        super(SchedulerHintsTestCase, self).setUp()

        self.fake_instance = fakes.stub_instance(1, uuid=UUID)

        app = compute.APIRouter()
        app = extensions.ExtensionMiddleware(app)
        app = wsgi.LazySerializationMiddleware(app)
        self.app = app
예제 #16
0
def fake_instance_get(self, context, instance_id):
    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': 'foo',
                            'instance_uuid': result['uuid']}
    return result
예제 #17
0
 def fake_instance(self):
     fake_instance = fakes.stub_instance(id=2, access_ipv4="1.2.3.4", access_ipv6="::1")
     fake_instance["scheduled_at"] = None
     fake_instance["terminated_at"] = None
     fake_instance["deleted_at"] = None
     fake_instance["created_at"] = None
     fake_instance["updated_at"] = None
     fake_instance["launched_at"] = fake_instance["launched_at"].replace(tzinfo=iso8601.iso8601.Utc(), microsecond=0)
     return fake_instance
예제 #18
0
def fake_instance_get(context, instance_id, columns_to_join=None):
    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
예제 #19
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))
예제 #20
0
    def test_get_devs_non_object(self):
        def _fake_pci_device_get_by_instance_uuid(context, uuid):
            self._get_by_uuid = True
            return []

        instance = fakes.stub_instance(id=1)
        self.stubs.Set(db, 'pci_device_get_all_by_instance_uuid',
            _fake_pci_device_get_by_instance_uuid)
        self._get_by_uuid = False
        devices = pci_manager.get_instance_pci_devs(instance)
        self.assertEqual(self._get_by_uuid, True)
예제 #21
0
def fake_compute_get_all(*args, **kwargs):
    base = {'id': 1, 'description': 'foo', 'user_id': 'bar',
            'project_id': 'baz', 'deleted': False, 'deleted_at': None,
            'updated_at': None, 'created_at': None}
    db_list = [
        fakes.stub_instance(
            1, uuid=UUID1,
            security_groups=[dict(base, **{'name': 'fake-0-0'}),
                             dict(base, **{'name': 'fake-0-1'})]),
        fakes.stub_instance(
            2, uuid=UUID2,
            security_groups=[dict(base, **{'name': 'fake-1-0'}),
                             dict(base, **{'name': 'fake-1-1'})])
    ]

    return instance_obj._make_instance_list(args[1],
                                            instance_obj.InstanceList(),
                                            db_list,
                                            ['metadata', 'system_metadata',
                                             'security_groups', 'info_cache'])
    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], instance_obj.InstanceList(), instances, fields)

        self.stubs.Set(compute.api.API, "get_all", get_all)
        res = self._make_request("/v3/servers/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)
예제 #23
0
 def fake_instance(self):
     fake_instance = fakes.stub_instance(id=2, access_ipv4="1.2.3.4", access_ipv6="::1")
     fake_instance["scheduled_at"] = None
     fake_instance["terminated_at"] = None
     fake_instance["deleted_at"] = None
     fake_instance["created_at"] = None
     fake_instance["updated_at"] = None
     fake_instance["launched_at"] = fake_instance["launched_at"].replace(tzinfo=iso8601.iso8601.Utc(), microsecond=0)
     fake_instance["deleted"] = False
     fake_instance["info_cache"]["instance_uuid"] = fake_instance["uuid"]
     fake_instance["security_groups"] = None
     return fake_instance
예제 #24
0
 def fake_instance(self):
     fake_instance = fakes.stub_instance(id=2,
                                         access_ipv4='1.2.3.4',
                                         access_ipv6='::1')
     fake_instance['scheduled_at'] = None
     fake_instance['terminated_at'] = None
     fake_instance['deleted_at'] = None
     fake_instance['created_at'] = None
     fake_instance['updated_at'] = None
     fake_instance['launched_at'] = (
         fake_instance['launched_at'].replace(
             tzinfo=iso8601.iso8601.Utc(), microsecond=0))
     return fake_instance
예제 #25
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):
            return instances

        self.stubs.Set(compute.api.API, 'get_all', get_all)
        res = self._make_request('/v2/fake/servers/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)
예제 #26
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(nova.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"])
예제 #27
0
def fake_compute_get_all(*args, **kwargs):
    base = {
        "id": 1,
        "description": "foo",
        "user_id": "bar",
        "project_id": "baz",
        "deleted": False,
        "deleted_at": None,
        "updated_at": None,
        "created_at": None,
    }
    db_list = [
        fakes.stub_instance(
            1, uuid=UUID1, security_groups=[dict(base, **{"name": "fake-0-0"}), dict(base, **{"name": "fake-0-1"})]
        ),
        fakes.stub_instance(
            2, uuid=UUID2, security_groups=[dict(base, **{"name": "fake-1-0"}), dict(base, **{"name": "fake-1-1"})]
        ),
    ]

    return instance_obj._make_instance_list(
        args[1], objects.InstanceList(), db_list, ["metadata", "system_metadata", "security_groups", "info_cache"]
    )
예제 #28
0
 def fake_instance(self, id, updates=None):
     fake_instance = fakes.stub_instance(id=2, access_ipv4="1.2.3.4", access_ipv6="::1")
     fake_instance["scheduled_at"] = None
     fake_instance["terminated_at"] = None
     fake_instance["deleted_at"] = None
     fake_instance["created_at"] = None
     fake_instance["updated_at"] = None
     fake_instance["launched_at"] = fake_instance["launched_at"].replace(tzinfo=iso8601.iso8601.Utc(), microsecond=0)
     fake_instance["info_cache"] = {"network_info": "foo", "instance_uuid": fake_instance["uuid"]}
     fake_instance["security_groups"] = []
     fake_instance["deleted"] = 0
     if updates:
         fake_instance.update(updates)
     return fake_instance
예제 #29
0
 def fake_instance(self):
     fake_instance = fakes.stub_instance(id=2,
                                         access_ipv4='1.2.3.4',
                                         access_ipv6='::1')
     fake_instance['scheduled_at'] = None
     fake_instance['terminated_at'] = None
     fake_instance['deleted_at'] = None
     fake_instance['created_at'] = None
     fake_instance['updated_at'] = None
     fake_instance['launched_at'] = (
         fake_instance['launched_at'].replace(
             tzinfo=iso8601.iso8601.Utc(), microsecond=0))
     fake_instance['deleted'] = False
     fake_instance['info_cache']['instance_uuid'] = fake_instance['uuid']
     fake_instance['security_groups'] = None
     return fake_instance
예제 #30
0
 def fake_instance(self):
     fake_instance = fakes.stub_instance(id=2, access_ipv4="1.2.3.4", access_ipv6="::1")
     fake_instance["cell_name"] = "api!child"
     fake_instance["scheduled_at"] = None
     fake_instance["terminated_at"] = None
     fake_instance["deleted_at"] = None
     fake_instance["created_at"] = None
     fake_instance["updated_at"] = None
     fake_instance["launched_at"] = fake_instance["launched_at"].replace(tzinfo=iso8601.iso8601.Utc(), microsecond=0)
     fake_instance["deleted"] = False
     fake_instance["info_cache"]["instance_uuid"] = fake_instance["uuid"]
     fake_instance["security_groups"] = []
     fake_instance["pci_devices"] = []
     fake_instance["user_id"] = self.context.user_id
     fake_instance["project_id"] = self.context.project_id
     return fake_instance
예제 #31
0
def instance_update(context, instance_uuid, kwargs):
    inst = fakes.stub_instance(INSTANCE_IDS[instance_uuid], host='fake_host')
    return (inst, inst)
예제 #32
0
def fake_compute_get_all(*args, **kwargs):
    return [
        fakes.stub_instance(1, uuid=UUID1, nw_cache=NW_CACHE),
        fakes.stub_instance(2, uuid=UUID2, nw_cache=NW_CACHE),
    ]
예제 #33
0
    def setUp(self):
        super(DiskConfigTestCase, self).setUp()
        self.flags(verbose=True)
        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(nova.db.api, 'instance_get', fake_instance_get)
        self.stubs.Set(nova.db, 'instance_get', fake_instance_get)

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

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

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

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

        def fake_instance_create(context, inst_, session=None):
            class FakeModel(dict):
                def save(self, session=None):
                    pass

            inst = FakeModel(**inst_)
            inst['id'] = 1
            inst['uuid'] = AUTO_INSTANCE_UUID
            inst['created_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
            inst['updated_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
            inst['progress'] = 0
            inst['name'] = 'instance-1'  # this is a property

            def fake_instance_get_for_create(context, id_, session=None):
                return inst

            self.stubs.Set(nova.db, 'instance_get',
                           fake_instance_get_for_create)
            self.stubs.Set(nova.db.api, 'instance_get',
                           fake_instance_get_for_create)
            self.stubs.Set(nova.db.sqlalchemy.api, 'instance_get',
                           fake_instance_get_for_create)

            def fake_instance_add_security_group(context, instance_id,
                                                 security_group_id):
                pass

            self.stubs.Set(nova.db.sqlalchemy.api,
                           'instance_add_security_group',
                           fake_instance_add_security_group)

            return inst

        self.stubs.Set(nova.db, 'instance_create', fake_instance_create)

        app = v2.APIRouter()
        app = extensions.ExtensionMiddleware(app)
        app = wsgi.LazySerializationMiddleware(app)
        self.app = app
예제 #34
0
 def _return_server(*_args, **_kwargs):
     inst = fakes.stub_instance(*args, **kwargs)
     return fake_instance.fake_instance_obj(_args[1], **inst)
예제 #35
0
def fake_compute_get(*args, **kwargs):
    return fakes.stub_instance(1, uuid=UUID1)
예제 #36
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)
예제 #37
0
 def _return_server(*_args, **_kwargs):
     return fakes.stub_instance(*args, **kwargs)
예제 #38
0
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID1)
    return fake_instance.fake_instance_obj(args[1], **inst)
예제 #39
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],
                                            instance_obj.InstanceList(),
                                            db_list, fields)
예제 #40
0
def fake_compute_get(*args, **kwargs):
    return fakes.stub_instance(1,
                               uuid=UUID3,
                               task_state="kayaking",
                               vm_state="slightly crunchy",
                               power_state="empowered")
예제 #41
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)
예제 #42
0
def instance_update(context, instance_id, kwargs):
    return fakes.stub_instance(instance_id)
예제 #43
0
def fake_compute_get(*args, **kwargs):
    return fakes.stub_instance(1, uuid=UUID3, host="host-fake")
예제 #44
0
def fake_compute_get_all(*args, **kwargs):
    return [
        fakes.stub_instance(1, uuid=UUID1, host="host-1"),
        fakes.stub_instance(2, uuid=UUID2, host="host-2")
    ]
예제 #45
0
 def setUp(self):
     super(SchedulerHintsTestCase, self).setUp()
     self.fake_instance = fakes.stub_instance(1, uuid=UUID)
     self.app = compute.APIRouter()
예제 #46
0
def fake_compute_get(*args, **kwargs):
    return fakes.stub_instance(1,
                               uuid=UUID3,
                               launched_at=DATE1,
                               terminated_at=DATE2)
예제 #47
0
    def setUp(self):
        super(DiskConfigTestCase, self).setUp()
        self.flags(verbose=True)
        nova.tests.image.fake.stub_out_image_service(self.stubs)

        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(nova.db, 'instance_get', fake_instance_get)

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

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

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

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

        def fake_instance_create(context, inst_, session=None):
            class FakeModel(dict):
                def save(self, session=None):
                    pass

            inst = FakeModel(**inst_)
            inst['id'] = 1
            inst['uuid'] = AUTO_INSTANCE_UUID
            inst['created_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
            inst['updated_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
            inst['progress'] = 0
            inst['name'] = 'instance-1'  # this is a property
            inst['task_state'] = ''
            inst['vm_state'] = ''
            # NOTE(vish): db create translates security groups into model
            #             objects. Translate here so tests pass
            inst['security_groups'] = [{'name': group}
                                       for group in inst['security_groups']]

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

            self.stubs.Set(nova.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(nova.db, 'instance_get_all',
                           fake_instance_get_all_for_create)
            self.stubs.Set(nova.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(nova.db,
                           'instance_add_security_group',
                           fake_instance_add_security_group)

            return inst

        self.stubs.Set(nova.db, 'instance_create', fake_instance_create)

        self.app = compute.APIRouter()
예제 #48
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'],
                    })

            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)
예제 #49
0
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)
예제 #50
0
def fake_compute_get(*args, **kwargs):
    inst = fakes.stub_instance(1, uuid=UUID3,
                               security_groups=[{'name': 'fake-2-0'},
                                                {'name': 'fake-2-1'}])
    return fake_instance.fake_instance_obj(args[1],
               expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS, **inst)
예제 #51
0
 def setUp(self):
     super(SchedulerHintsTestCase, self).setUp()
     self.fake_instance = fakes.stub_instance(1, uuid=FAKE_UUID)
     self.app = compute.APIRouterV3(init_only=('servers',
                                               'os-scheduler-hints'))
예제 #52
0
 def fake_show(*args, **kwargs):
     instance_meta['kernel_id'] = kwargs.get('kernel_id')
     instance_meta['ramdisk_id'] = kwargs.get('ramdisk_id')
     inst = fakes.stub_instance(INSTANCE_IDS[FAKE_UUID],
                                host='fake_host')
     return inst
예제 #53
0
def fake_compute_get(*args, **kwargs):
    return fakes.stub_instance(1, uuid=UUID3, nw_cache=NW_CACHE)
예제 #54
0
def instance_update(context, instance_uuid, kwargs, update_cells=True):
    inst = fakes.stub_instance(INSTANCE_IDS[instance_uuid], host='fake_host')
    return inst
예제 #55
0
 def setUp(self):
     super(SchedulerHintsTestCaseV21, self).setUp()
     self.fake_instance = fakes.stub_instance(1, uuid=UUID)
     self._set_up_router()
def fake_compute_get(*args, **kwargs):
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
    return instance_obj.Instance._from_db_object(
        args[1], instance_obj.Instance(),
        fakes.stub_instance(1, uuid=UUID3, host="host-fake", node="node-fake"),
        fields)
예제 #57
0
    def setUp(self):
        super(DiskConfigTestCase, self).setUp()
        self.flags(verbose=True,
            osapi_compute_extension=[
                'nova.api.openstack.compute.contrib.select_extensions'],
            osapi_compute_ext_list=['Disk_config'])
        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):
            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)

        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'],
                    })

            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)

        self.app = compute.APIRouter(init_only=('servers', 'images'))
 def _fake_instance_update_and_get_original(context, instance_uuid,
                                            values):
     inst = fakes.stub_instance(INSTANCE_IDS.get(instance_uuid),
                                name=values.get('display_name'))
     return (inst, inst)
예제 #59
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)
예제 #60
0
    def setUp(self):
        super(DiskConfigTestCase, self).setUp()
        nova.tests.image.fake.stub_out_image_service(self.stubs)

        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):
            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)

        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'],
                })

            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)

        self.app = fakes.wsgi_app_v3(init_only=('servers', 'os-disk-config'))
        CONF.set_override('extensions_blacklist', 'os-disk-config', 'osapi_v3')
        self.no_disk_config_app = fakes.wsgi_app_v3(init_only=('servers'))