def test_destroy(self): self.mox.StubOutWithMock(db, 'aggregate_delete') db.aggregate_delete(self.context, 123) self.mox.ReplayAll() agg = aggregate.Aggregate(context=self.context) agg.id = 123 agg.destroy()
def test_aggregate_host_add(self): aggregate_ref = self._setup_aggregate_with_host() self.assertTrue(any([host == 'bar' for host in aggregate_ref['hosts']])) db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
def migrate_aggregates(ctxt, count): main_db_ids = _get_main_db_aggregate_ids(ctxt, count) if not main_db_ids: return 0, 0 count_all = len(main_db_ids) count_hit = 0 for aggregate_id in main_db_ids: try: aggregate = Aggregate.get_by_id(ctxt, aggregate_id) remove = ['metadata', 'hosts'] values = {field: getattr(aggregate, field) for field in aggregate.fields if field not in remove} _aggregate_create_in_db(ctxt, values, metadata=aggregate.metadata) for host in aggregate.hosts: _host_add_to_db(ctxt, aggregate_id, host) count_hit += 1 db.aggregate_delete(ctxt, aggregate.id) except exception.AggregateNotFound: LOG.warning( _LW('Aggregate id %(id)i disappeared during migration'), {'id': aggregate_id}) except (exception.AggregateNameExists) as e: LOG.error(str(e)) return count_all, count_hit
def test_destroy(self): self.mox.StubOutWithMock(db, 'aggregate_delete') db.aggregate_delete(self.context, 123) self.mox.ReplayAll() agg = aggregate.Aggregate() agg.id = 123 agg.destroy(self.context)
def migrate_aggregates(ctxt, count): main_db_ids = _get_main_db_aggregate_ids(ctxt, count) if not main_db_ids: return 0, 0 count_all = len(main_db_ids) count_hit = 0 for aggregate_id in main_db_ids: try: aggregate = Aggregate.get_by_id(ctxt, aggregate_id) remove = ['metadata', 'hosts'] values = { field: getattr(aggregate, field) for field in aggregate.fields if field not in remove } _aggregate_create_in_db(ctxt, values, metadata=aggregate.metadata) for host in aggregate.hosts: _host_add_to_db(ctxt, aggregate_id, host) count_hit += 1 db.aggregate_delete(ctxt, aggregate.id) except exception.AggregateNotFound: LOG.warning( _LW('Aggregate id %(id)i disappeared during migration'), {'id': aggregate_id}) except (exception.AggregateNameExists) as e: LOG.error(six.text_type(e)) return count_all, count_hit
def test_aggregate_delete(self): """Ensure we can delete an aggregate.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata=None) db.aggregate_delete(ctxt, result['id']) expected = db.aggregate_get_all(ctxt, read_deleted='no') self.assertEqual(0, len(expected))
def test_aggregate_create_avoid_name_conflict(self): """Test we can avoid conflict on deleted aggregates.""" r1 = _create_aggregate(metadata=None) db.aggregate_delete(context.get_admin_context(), r1.id) values = {'name': r1.name, 'availability_zone': 'new_zone'} r2 = _create_aggregate(values=values) self.assertEqual(r2.name, values['name']) self.assertEqual(r2.availability_zone, values['availability_zone'])
def test_aggregate_delete(self): """Ensure we can delete an aggregate.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata=None) db.aggregate_delete(ctxt, result['id']) expected = db.aggregate_get_all(ctxt, read_deleted='no') self.assertEqual(0, len(expected)) aggregate = db.aggregate_get(ctxt, result['id'], read_deleted='yes') self.assertEqual(aggregate["operational_state"], "dismissed")
def test_aggregate_create_avoid_name_conflict(self): """Test we can avoid conflict on deleted aggregates.""" r1 = _create_aggregate(metadata=None) db.aggregate_delete(context.get_admin_context(), r1.id) values = {"name": r1.name, "availability_zone": "new_zone"} r2 = _create_aggregate(values=values) self.assertEqual(r2.name, values["name"]) self.assertEqual(r2.availability_zone, values["availability_zone"]) self.assertEqual(r2.operational_state, "created")
def test_aggregate_delete(self): """Ensure we can delete an aggregate.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata=None) db.aggregate_delete(ctxt, result["id"]) expected = db.aggregate_get_all(ctxt) self.assertEqual(0, len(expected)) aggregate = db.aggregate_get(ctxt.elevated(read_deleted="yes"), result["id"]) self.assertEqual(aggregate.deleted, True)
def test_aggregate_host_delete(self): aggregate_ref = self._setup_aggregate_with_host() self.conductor.aggregate_host_delete(self.context, aggregate_ref, "bar") aggregate_ref = db.aggregate_get(self.context.elevated(), aggregate_ref["id"]) self.assertFalse(any([host == "bar" for host in aggregate_ref["hosts"]])) db.aggregate_delete(self.context.elevated(), aggregate_ref["id"])
def test_aggregate_create_delete_create_with_metadata(self): """Ensure aggregate metadata is deleted bug 1052479.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt) expected_metadata = db.aggregate_metadata_get(ctxt, result['id']) self.assertDictMatch(expected_metadata, _get_fake_aggr_metadata()) db.aggregate_delete(ctxt, result['id']) result = _create_aggregate(metadata=None) expected_metadata = db.aggregate_metadata_get(ctxt, result['id']) self.assertEqual(expected_metadata, {})
def test_aggregate_host_delete(self): aggregate_ref = self._setup_aggregate_with_host() self.conductor.aggregate_host_delete(self.context, aggregate_ref, 'bar') aggregate_ref = db.aggregate_get(self.context.elevated(), aggregate_ref['id']) self.assertFalse( any([host == 'bar' for host in aggregate_ref['hosts']])) db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
def test_aggregate_host_delete(self): aggregate_ref = self._setup_aggregate_with_host() self.conductor.aggregate_host_delete(self.context, aggregate_ref, 'bar') aggregate_ref = db.aggregate_get(self.context.elevated(), aggregate_ref['id']) self.assertFalse(any([host == 'bar' for host in aggregate_ref['hosts']])) db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
def test_aggregate_get_all_non_deleted(self): """Ensure we get only non-deleted aggregates.""" ctxt = context.get_admin_context() add_counter = 5 remove_counter = 2 aggregates = [] for c in xrange(1, add_counter): values = {"name": "fake_aggregate_%d" % c, "availability_zone": "fake_avail_zone"} aggregates.append(_create_aggregate(context=ctxt, values=values, metadata=None)) for c in xrange(1, remove_counter): db.aggregate_delete(ctxt, aggregates[c - 1].id) results = db.aggregate_get_all(ctxt) self.assertEqual(len(results), add_counter - remove_counter)
def test_aggregate_get_all_non_deleted(self): """Ensure we get only non-deleted aggregates.""" ctxt = context.get_admin_context() add_counter = 5 remove_counter = 2 aggregates = [] for c in xrange(1, add_counter): values = {'name': 'fake_aggregate_%d' % c, 'availability_zone': 'fake_avail_zone'} aggregates.append(_create_aggregate(context=ctxt, values=values, metadata=None)) for c in xrange(1, remove_counter): db.aggregate_delete(ctxt, aggregates[c - 1].id) results = db.aggregate_get_all(ctxt, read_deleted='no') self.assertEqual(len(results), add_counter - remove_counter)
def test_aggregate_host_add(self): aggregate_ref = self._setup_aggregate_with_host() self.assertTrue(any([host == "bar" for host in aggregate_ref["hosts"]])) db.aggregate_delete(self.context.elevated(), aggregate_ref["id"])
def destroy(self, context): db.aggregate_delete(context, self.id)
def tearDown(self): db.aggregate_delete(self.context, self.agg['id']) super(AvailabilityZoneTestCases, self).tearDown()
def destroy(self): db.aggregate_delete(self._context, self.id)
def test_aggregate_get(self): aggregate_ref = self._setup_aggregate_with_host() aggregate = self.conductor.aggregate_get(self.context, aggregate_ref['id']) self.assertEqual(jsonutils.to_primitive(aggregate_ref), aggregate) db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
def destroy(self): try: _aggregate_delete_from_db(self._context, self.id) except exception.AggregateNotFound: db.aggregate_delete(self._context, self.id)
def test_aggregate_get(self): aggregate_ref = self._setup_aggregate_with_host() aggregate = self.conductor.aggregate_get(self.context, aggregate_ref["id"]) self.assertEqual(jsonutils.to_primitive(aggregate_ref), aggregate) db.aggregate_delete(self.context.elevated(), aggregate_ref["id"])