Not count disabled compute node for statistics

No server will be scheduled to disabled compute service, thus we
should not count the corresponding compute node information.

It's arguable if we should count for 'down' service, since service
may be marked down because of communication error. If we do want to
exclude the down service, we need passing the information from caller
because the up/down state is not kepts in database, and it means compute
and cell api changes.

Closes-Bug: #1285259

Change-Id: I5e3e71ef30683c5eb5cc4462f58fa5f29d7c3f4b
This commit is contained in:
Yunhong Jiang 2014-03-13 16:29:26 -07:00 committed by yunhong-jiang
parent 33c1a195c8
commit 8cd2b89071
2 changed files with 13 additions and 1 deletions

View File

@ -684,7 +684,12 @@ def compute_node_statistics(context):
func.sum(models.ComputeNode.running_vms),
func.sum(models.ComputeNode.disk_available_least),
base_model=models.ComputeNode,
read_deleted="no").first()
read_deleted="no").\
filter(models.Service.disabled == False).\
filter(
models.Service.id ==
models.ComputeNode.service_id).\
first()
# Build a dict of the info--making no assumptions about result
fields = ('count', 'vcpus', 'memory_mb', 'local_gb', 'vcpus_used',

View File

@ -5684,6 +5684,13 @@ class ComputeNodeTestCase(test.TestCase, ModelsObjectComparatorMixin):
for k, v in stats.iteritems():
self.assertEqual(v, self.item[k])
def test_compute_node_statistics_disabled_service(self):
serv = db.service_get_by_host_and_topic(
self.ctxt, 'host1', CONF.compute_topic)
db.service_update(self.ctxt, serv['id'], {'disabled': True})
stats = db.compute_node_statistics(self.ctxt)
self.assertEqual(stats.pop('count'), 0)
def test_compute_node_not_found(self):
self.assertRaises(exception.ComputeHostNotFound, db.compute_node_get,
self.ctxt, 100500)