예제 #1
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, "aggregate_create")
     db.aggregate_create(self.context, {"name": "foo"}, metadata={"one": "two"}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = "foo"
     agg.metadata = {"one": "two"}
     agg.create()
     self.assertRaises(exception.ObjectActionError, agg.create, self.context)
예제 #2
0
 def test_create(self):
     self.mox.StubOutWithMock(db, "aggregate_create")
     db.aggregate_create(self.context, {"name": "foo"}, metadata={"one": "two"}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = "foo"
     agg.metadata = {"one": "two"}
     agg.create()
     self.compare_obj(agg, fake_aggregate, subs=SUBS)
예제 #3
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.compare_obj(agg, fake_aggregate, subs=SUBS)
예제 #4
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate()
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create(self.context)
     self.compare_obj(agg, fake_aggregate, subs=SUBS)
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.assertRaises(exception.ObjectActionError, agg.create)
예제 #6
0
 def test_migration(self):
     db.aggregate_create(self.context, {'name': 'foo'})
     main_aggregates_len = len(db.aggregate_get_all(self.context))
     match, done = aggregate_obj.migrate_aggregates(self.context, 50)
     self.assertEqual(1, main_aggregates_len)
     self.assertEqual(main_aggregates_len, match)
     self.assertEqual(main_aggregates_len, done)
     self.assertEqual(0, len(db.aggregate_get_all(self.context)))
     self.assertEqual(main_aggregates_len,
                      len(aggregate_obj.AggregateList.get_all(
                                                             self.context)))
예제 #7
0
 def test_migration(self):
     db.aggregate_create(self.context, {'name': 'foo'})
     main_aggregates_len = len(db.aggregate_get_all(self.context))
     match, done = aggregate_obj.migrate_aggregates(self.context, 50)
     self.assertEqual(1, main_aggregates_len)
     self.assertEqual(main_aggregates_len, match)
     self.assertEqual(main_aggregates_len, done)
     self.assertEqual(0, len(db.aggregate_get_all(self.context)))
     self.assertEqual(
         main_aggregates_len,
         len(aggregate_obj.AggregateList.get_all(self.context)))
예제 #8
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.assertRaises(exception.ObjectActionError, agg.create,
                       self.context)
예제 #9
0
def create_aggregate(context, db_id, in_api=True):
    if in_api:
        fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False)
        aggregate_obj._aggregate_create_in_db(context, fake_aggregate,
                                       metadata=_get_fake_metadata(db_id))
        for host in _get_fake_hosts(db_id):
            aggregate_obj._host_add_to_db(context, fake_aggregate['id'], host)
    else:
        fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False)
        db.aggregate_create(context, fake_aggregate,
                            metadata=_get_fake_metadata(db_id))
        for host in _get_fake_hosts(db_id):
            db.aggregate_host_add(context, fake_aggregate['id'], host)
예제 #10
0
def create_aggregate(context, db_id, in_api=True):
    if in_api:
        fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False)
        aggregate_obj._aggregate_create_in_db(context, fake_aggregate,
                                       metadata=_get_fake_metadata(db_id))
        for host in _get_fake_hosts(db_id):
            aggregate_obj._host_add_to_db(context, fake_aggregate['id'], host)
    else:
        fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False)
        db.aggregate_create(context, fake_aggregate,
                            metadata=_get_fake_metadata(db_id))
        for host in _get_fake_hosts(db_id):
            db.aggregate_host_add(context, fake_aggregate['id'], host)
예제 #11
0
    def test_create_instance_with_availability_zone(self):
        def create(*args, **kwargs):
            self.assertIn("availability_zone", kwargs)
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, "create", create)
        image_href = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
        flavor_ref = "http://localhost/v3/flavors/3"
        body = {
            "server": {
                "name": "config_drive_test",
                "image_ref": image_href,
                "flavor_ref": flavor_ref,
                "metadata": {"hello": "world", "open": "stack"},
                "personality": {},
                "availability_zone": "nova",
            }
        }

        req = fakes.HTTPRequestV3.blank("/v3/servers")
        req.method = "POST"
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        admin_context = context.get_admin_context()
        service1 = db.service_create(
            admin_context, {"host": "host1_zones", "binary": "nova-compute", "topic": "compute", "report_count": 0}
        )
        agg = db.aggregate_create(admin_context, {"name": "agg1"}, {"availability_zone": "nova"})
        db.aggregate_host_add(admin_context, agg["id"], "host1_zones")
        res = self.controller.create(req, body).obj
        server = res["server"]
        self.assertEqual(FAKE_UUID, server["id"])
예제 #12
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     self._assert_no_hosts('create')
     updates = self.obj_get_changes()
     payload = dict(updates)
     if 'metadata' in updates:
         # NOTE(danms): For some reason the notification format is weird
         payload['meta_data'] = payload.pop('metadata')
     if 'uuid' not in updates:
         updates['uuid'] = uuidutils.generate_uuid()
         LOG.debug('Generated uuid %(uuid)s for aggregate',
                   dict(uuid=updates['uuid']))
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "create.start",
                                                 payload)
     metadata = updates.pop('metadata', None)
     db_aggregate = db.aggregate_create(self._context, updates,
                                        metadata=metadata)
     self._from_db_object(self._context, self, db_aggregate)
     payload['aggregate_id'] = self.id
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "create.end",
                                                 payload)
예제 #13
0
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn("availability_zone", kwargs)
            self.assertEqual("nova", kwargs["availability_zone"])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, "create", create)
        image_href = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
        flavor_ref = "http://localhost" + self.base_url + "flavors/3"
        body = {
            "server": {
                "name": "server_test",
                "imageRef": image_href,
                "flavorRef": flavor_ref,
                "metadata": {"hello": "world", "open": "stack"},
                "availability_zone": zone_name,
            }
        }

        req = fakes.HTTPRequest.blank(self.base_url + "servers")
        req.method = "POST"
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        admin_context = context.get_admin_context()
        db.service_create(
            admin_context, {"host": "host1_zones", "binary": "nova-compute", "topic": "compute", "report_count": 0}
        )
        agg = db.aggregate_create(admin_context, {"name": "agg1"}, {"availability_zone": "nova"})
        db.aggregate_host_add(admin_context, agg["id"], "host1_zones")
        return req, body
예제 #14
0
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, 'create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = ('http://localhost' + self.base_url + 'flavors/3')
        body = {
            'server': {
                'name': 'server_test',
                'imageRef': image_href,
                'flavorRef': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                'availability_zone': zone_name,
            },
        }

        admin_context = context.get_admin_context()
        db.service_create(
            admin_context, {
                'host': 'host1_zones',
                'binary': "nova-compute",
                'topic': 'compute',
                'report_count': 0
            })
        agg = db.aggregate_create(admin_context, {'name': 'agg1'},
                                  {'availability_zone': 'nova'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        return self.req, body
예제 #15
0
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, 'create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = ('http://localhost' + self.base_url + 'flavors/3')
        body = {
            'server': {
                'name': 'server_test',
                'imageRef': image_href,
                'flavorRef': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                'availability_zone': zone_name,
            },
        }

        admin_context = context.get_admin_context()
        db.service_create(admin_context, {'host': 'host1_zones',
                                          'binary': "nova-compute",
                                          'topic': 'compute',
                                          'report_count': 0})
        agg = db.aggregate_create(admin_context,
                {'name': 'agg1'}, {'availability_zone': 'nova'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        return self.req, body
예제 #16
0
파일: aggregate.py 프로젝트: unicell/nova
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     self._assert_no_hosts('create')
     updates = self.obj_get_changes()
     payload = dict(updates)
     if 'metadata' in updates:
         # NOTE(danms): For some reason the notification format is weird
         payload['meta_data'] = payload.pop('metadata')
     if 'uuid' not in updates:
         updates['uuid'] = uuidutils.generate_uuid()
         LOG.debug('Generated uuid %(uuid)s for aggregate',
                   dict(uuid=updates['uuid']))
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "create.start",
                                                 payload)
     metadata = updates.pop('metadata', None)
     db_aggregate = db.aggregate_create(self._context, updates,
                                        metadata=metadata)
     self._from_db_object(self._context, self, db_aggregate)
     payload['aggregate_id'] = self.id
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "create.end",
                                                 payload)
예제 #17
0
    def _create_az(self, agg_name, az_name):
        agg_meta = {'name': agg_name, 'uuid': uuidsentinel.agg_uuid}
        agg = db.aggregate_create(self.context, agg_meta)

        metadata = {'availability_zone': az_name}
        db.aggregate_metadata_add(self.context, agg['id'], metadata)

        return agg
예제 #18
0
    def _create_az(self, agg_name, az_name):
        agg_meta = {"name": agg_name}
        agg = db.aggregate_create(self.context, agg_meta)

        metadata = {"availability_zone": az_name}
        db.aggregate_metadata_add(self.context, agg["id"], metadata)

        return agg
예제 #19
0
    def _create_az(self, agg_name, az_name):
        agg_meta = {'name': agg_name}
        agg = db.aggregate_create(self.context, agg_meta)

        metadata = {'availability_zone': az_name}
        db.aggregate_metadata_add(self.context, agg['id'], metadata)

        return agg
예제 #20
0
    def _setup_aggregate_with_host(self):
        aggregate_ref = db.aggregate_create(self.context.elevated(), {"name": "foo", "availability_zone": "foo"})

        self.conductor.aggregate_host_add(self.context, aggregate_ref, "bar")

        aggregate_ref = db.aggregate_get(self.context.elevated(), aggregate_ref["id"])

        return aggregate_ref
예제 #21
0
 def _create_aggregate_with_host(self, name='fake_aggregate',
                       metadata=None,
                       hosts=['host1']):
     values = {'name': name,
                 'availability_zone': 'fake_avail_zone', }
     result = db.aggregate_create(self.context.elevated(), values, metadata)
     for host in hosts:
         db.aggregate_host_add(self.context.elevated(), result.id, host)
     return result
예제 #22
0
파일: utils.py 프로젝트: alanmeadows/cobalt
def create_availability_zone(context, hosts):

    az = create_uuid()
    # Create a new host aggregate
    aggregate = db.aggregate_create(context, {'name': az}, metadata={'availability_zone': az})
    for host in hosts:
        db.aggregate_host_add(context, aggregate['id'], host)

    return az
예제 #23
0
    def _setup_aggregate_with_host(self):
        aggregate_ref = db.aggregate_create(self.context.elevated(),
                {'name': 'foo'}, metadata={'availability_zone': 'foo'})

        self.conductor.aggregate_host_add(self.context, aggregate_ref, 'bar')

        aggregate_ref = db.aggregate_get(self.context.elevated(),
                                         aggregate_ref['id'])

        return aggregate_ref
예제 #24
0
    def _setup_aggregate_with_host(self):
        aggregate_ref = db.aggregate_create(self.context.elevated(),
                {'name': 'foo', 'availability_zone': 'foo'})

        self.conductor.aggregate_host_add(self.context, aggregate_ref, 'bar')

        aggregate_ref = db.aggregate_get(self.context.elevated(),
                                         aggregate_ref['id'])

        return aggregate_ref
예제 #25
0
파일: utils.py 프로젝트: cattings/cobalt
def create_availability_zone(context, hosts):

    az = create_uuid()
    # Create a new host aggregate
    aggregate = db.aggregate_create(context, {'name': az},
                                    metadata={'availability_zone': az})
    for host in hosts:
        db.aggregate_host_add(context, aggregate['id'], host)

    return az
 def _create_aggregate_with_host(self,
                                 name='fake_aggregate',
                                 metadata=None,
                                 hosts=['host1']):
     values = {
         'name': name,
         'availability_zone': 'fake_avail_zone',
     }
     result = db.aggregate_create(self.context.elevated(), values, metadata)
     for host in hosts:
         db.aggregate_host_add(self.context.elevated(), result.id, host)
     return result
예제 #27
0
    def setUp(self):
        super(AvailabilityZoneTestCases, self).setUp()
        self.host = 'me'
        self.availability_zone = 'nova-test'
        self.default_az = CONF.default_availability_zone
        self.default_in_az = CONF.internal_service_availability_zone
        self.context = context.get_admin_context()

        agg = {'name': 'agg1'}
        self.agg = db.aggregate_create(self.context, agg)

        metadata = {'availability_zone': self.availability_zone}
        db.aggregate_metadata_add(self.context, self.agg['id'], metadata)
예제 #28
0
 def create(self, context):
     self._assert_no_hosts("create")
     updates = self.obj_get_changes()
     payload = dict(updates)
     if "metadata" in updates:
         # NOTE(danms): For some reason the notification format is weird
         payload["meta_data"] = payload.pop("metadata")
     compute_utils.notify_about_aggregate_update(context, "create.start", payload)
     metadata = updates.pop("metadata", None)
     db_aggregate = db.aggregate_create(context, updates, metadata=metadata)
     self._from_db_object(context, self, db_aggregate)
     payload["aggregate_id"] = self.id
     compute_utils.notify_about_aggregate_update(context, "create.end", payload)
예제 #29
0
    def setUp(self):
        super(AvailabilityZoneTestCases, self).setUp()
        self.host = 'me'
        self.availability_zone = 'nova-test'
        self.default_az = CONF.default_availability_zone
        self.default_in_az = CONF.internal_service_availability_zone
        self.context = context.get_admin_context()

        agg = {'name': 'agg1'}
        self.agg = db.aggregate_create(self.context, agg)

        metadata = {'availability_zone': self.availability_zone}
        db.aggregate_metadata_add(self.context, self.agg['id'], metadata)
예제 #30
0
    def test_in_api(self):
        ca1 = _create_aggregate(self.context, values={'name': 'fake_agg_1',
                                                      'id': 1,
                                                      'uuid': 'nonce'})
        ca2 = db.aggregate_create(self.context, {'name': 'fake_agg_2',
                                                 'id': 2,
                                                 'uuid': 'nonce'})

        api_db_agg = aggregate_obj.Aggregate.get_by_id(self.context, ca1['id'])
        cell_db_agg = aggregate_obj.Aggregate.get_by_id(
                                                    self.context, ca2['id'])

        self.assertTrue(api_db_agg.in_api)
        self.assertFalse(cell_db_agg.in_api)
예제 #31
0
    def test_in_api(self):
        ca1 = _create_aggregate(self.context, values={'name': 'fake_agg_1',
                                                      'id': 1,
                                                      'uuid': 'nonce'})
        ca2 = db.aggregate_create(self.context, {'name': 'fake_agg_2',
                                                 'id': 2,
                                                 'uuid': 'nonce'})

        api_db_agg = aggregate_obj.Aggregate.get_by_id(self.context, ca1['id'])
        cell_db_agg = aggregate_obj.Aggregate.get_by_id(
                                                    self.context, ca2['id'])

        self.assertEqual(api_db_agg.in_api, True)
        self.assertEqual(cell_db_agg.in_api, False)
예제 #32
0
 def create(self, context):
     self._assert_no_hosts('create')
     updates = self.obj_get_changes()
     payload = dict(updates)
     if 'metadata' in updates:
         # NOTE(danms): For some reason the notification format is weird
         payload['meta_data'] = payload.pop('metadata')
     compute_utils.notify_about_aggregate_update(context, "create.start",
                                                 payload)
     metadata = updates.pop('metadata', None)
     db_aggregate = db.aggregate_create(context, updates, metadata=metadata)
     self._from_db_object(context, self, db_aggregate)
     payload['aggregate_id'] = self.id
     compute_utils.notify_about_aggregate_update(context, "create.end",
                                                 payload)
예제 #33
0
 def create(self, context):
     self._assert_no_hosts('create')
     updates = {}
     for key in self.obj_what_changed():
         updates[key] = self[key]
     payload = dict(updates)
     if 'metadata' in updates:
         # NOTE(danms): For some reason the notification format is weird
         payload['meta_data'] = payload.pop('metadata')
     compute_utils.notify_about_aggregate_update(context,
                                                 "create.start",
                                                 payload)
     metadata = updates.pop('metadata', None)
     db_aggregate = db.aggregate_create(context, updates, metadata=metadata)
     self._from_db_object(context, self, db_aggregate)
     payload['aggregate_id'] = self.id
     compute_utils.notify_about_aggregate_update(context,
                                                 "create.end",
                                                 payload)
예제 #34
0
    def test_create_instance_with_availability_zone(self):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, 'create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = 'http://localhost/v3/flavors/3'
        body = {
            'server': {
                'name': 'config_drive_test',
                'image_ref': image_href,
                'flavor_ref': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                availability_zone.ATTRIBUTE_NAME: "nova",
            },
        }

        req = fakes.HTTPRequestV3.blank('/v3/servers')
        req.method = 'POST'
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        admin_context = context.get_admin_context()
        service1 = db.service_create(
            admin_context, {
                'host': 'host1_zones',
                'binary': "nova-compute",
                'topic': 'compute',
                'report_count': 0
            })
        agg = db.aggregate_create(admin_context, {'name': 'agg1'},
                                  {'availability_zone': 'nova'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        res = self.controller.create(req, body=body).obj
        server = res['server']
        self.assertEqual(FAKE_UUID, server['id'])
예제 #35
0
    def test_create_instance_with_availability_zone(self):
        self.ext_mgr.extensions = {'os-availability-zone': 'fake'}

        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, 'create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = 'http://localhost/v2/fake/flavors/3'
        body = {
            'server': {
                'name': 'config_drive_test',
                'imageRef': image_href,
                'flavorRef': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                'availability_zone': 'nova',
            },
        }

        req = fakes.HTTPRequest.blank('/v2/fake/servers')
        req.method = 'POST'
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        admin_context = context.get_admin_context()
        db.service_create(admin_context, {'host': 'host1_zones',
                                          'binary': "nova-compute",
                                          'topic': 'compute',
                                          'report_count': 0})
        agg = db.aggregate_create(admin_context,
                {'name': 'agg1'}, {'availability_zone': 'nova'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        res = self.controller.create(req, body=body).obj
        server = res['server']
        self.assertEqual(fakes.FAKE_UUID, server['id'])
예제 #36
0
파일: test_db_api.py 프로젝트: matiu2/nova
def _create_aggregate(context=context.get_admin_context(),
                      values=_get_fake_aggr_values(),
                      metadata=_get_fake_aggr_metadata()):
    return db.aggregate_create(context, values, metadata)
예제 #37
0
def _create_aggregate(context=context.get_admin_context(),
                      values=_get_fake_aggr_values(),
                      metadata=_get_fake_aggr_metadata()):
    return db.aggregate_create(context, values, metadata)