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)
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)
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)
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)
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)))
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)))
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)
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)
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"])
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)
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
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
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
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
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
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
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
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
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 _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
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
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
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)
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)
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)
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)
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)
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)
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'])
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'])
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)