def test_aggregate_host_delete(self): """Ensure we can add host to the aggregate.""" ctxt = context.get_admin_context() result = _create_aggregate_with_hosts(context=ctxt, metadata=None) db.aggregate_host_delete(ctxt, result.id, _get_fake_aggr_hosts()[0]) expected = db.aggregate_host_get_all(ctxt, result.id) self.assertEqual(0, len(expected))
def delete_host(self, host): if self.in_api: _host_delete_from_db(self._context, self.id, host) else: db.aggregate_host_delete(self._context, self.id, host) self.hosts.remove(host) self.obj_reset_changes(fields=['hosts'])
def test_aggregate_host_add_deleted(self): """Ensure we can add a host that was previously deleted.""" ctxt = context.get_admin_context() result = _create_aggregate_with_hosts(context=ctxt, metadata=None) host = _get_fake_aggr_hosts()[0] db.aggregate_host_delete(ctxt, result.id, host) db.aggregate_host_add(ctxt, result.id, host) expected = db.aggregate_host_get_all(ctxt, result.id) self.assertEqual(len(expected), 1)
def test_delete_host(self): self.mox.StubOutWithMock(db, 'aggregate_host_delete') db.aggregate_host_delete(self.context, 123, 'foo') self.mox.ReplayAll() agg = aggregate.Aggregate() agg.id = 123 agg.hosts = ['foo', 'bar'] agg._context = self.context agg.delete_host('foo') self.assertEqual(agg.hosts, ['bar'])
def test_delete_host(self): self.mox.StubOutWithMock(db, "aggregate_host_delete") db.aggregate_host_delete(self.context, 123, "foo") self.mox.ReplayAll() agg = aggregate.Aggregate() agg.id = 123 agg.hosts = ["foo", "bar"] agg._context = self.context agg.delete_host("foo") self.assertEqual(agg.hosts, ["bar"])
def test_aggregate_filter_fails_extra_specs_deleted_host(self): self._stub_service_is_up(True) filt_cls = self.class_map['AggregateInstanceExtraSpecsFilter']() extra_specs = {'opt1': '1', 'opt2': '2'} self._create_aggregate_with_host(metadata={'opt1': '1'}) agg2 = self._create_aggregate_with_host(name='fake2', metadata={'opt2': '2'}) filter_properties = {'context': self.context, 'instance_type': {'memory_mb': 1024, 'extra_specs': extra_specs}} host = fakes.FakeHostState('host1', 'compute', {'free_ram_mb': 1024}) db.aggregate_host_delete(self.context.elevated(), agg2.id, 'host1') self.assertFalse(filt_cls.host_passes(host, filter_properties))
def test_aggregate_filter_fails_extra_specs_deleted_host(self): self._stub_service_is_up(True) filt_cls = self.class_map['AggregateInstanceExtraSpecsFilter']() extra_specs = {'opt1': '1', 'opt2': '2'} self._create_aggregate_with_host(metadata={'opt1': '1'}) agg2 = self._create_aggregate_with_host(name='fake2', metadata={'opt2': '2'}) filter_properties = { 'context': self.context, 'instance_type': { 'memory_mb': 1024, 'extra_specs': extra_specs } } host = fakes.FakeHostState('host1', 'compute', {'free_ram_mb': 1024}) db.aggregate_host_delete(self.context.elevated(), agg2.id, 'host1') self.assertFalse(filt_cls.host_passes(host, filter_properties))
def _delete_from_aggregate(self, service, aggregate): return db.aggregate_host_delete(self.context, aggregate['id'], service['host'])
def delete_host(self, context, host): db.aggregate_host_delete(context, self.id, host) self.hosts.remove(host) self.obj_reset_changes(fields=['hosts'])
def delete_host(self, context, host): db.aggregate_host_delete(context, self.id, host) self.hosts.remove(host) self.obj_reset_changes(fields=["hosts"])
def _delete_from_aggregate(self, service, aggregate): return db.aggregate_host_delete(self.context, aggregate["id"], service["host"])