def test_aggregate_get(self): """Ensure we can get aggregate with all its relations.""" ctxt = context.get_admin_context() result = _create_aggregate_with_hosts(context=ctxt) expected = db.aggregate_get(ctxt, result.id) self.assertEqual(_get_fake_aggr_hosts(), expected.hosts) self.assertEqual(_get_fake_aggr_metadata(), expected.metadetails)
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 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_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 _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 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 _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 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 get_by_id(cls, context, aggregate_id): db_aggregate = db.aggregate_get(context, aggregate_id) return cls._from_db_object(context, cls(), db_aggregate)
def test_get_by_id(self): self.mox.StubOutWithMock(db, 'aggregate_get') db.aggregate_get(self.context, 123).AndReturn(fake_aggregate) self.mox.ReplayAll() agg = aggregate.Aggregate.get_by_id(self.context, 123) self.compare_obj(agg, fake_aggregate, subs=SUBS)
def get_by_id(cls, context, aggregate_id): try: db_aggregate = _aggregate_get_from_db(context, aggregate_id) except exception.AggregateNotFound: db_aggregate = db.aggregate_get(context, aggregate_id) return cls._from_db_object(context, cls(), db_aggregate)
def test_get_by_id(self): self.mox.StubOutWithMock(db, "aggregate_get") db.aggregate_get(self.context, 123).AndReturn(fake_aggregate) self.mox.ReplayAll() agg = aggregate.Aggregate.get_by_id(self.context, 123) compare(agg, fake_aggregate)