Skip to content

Commit

Permalink
Not count disabled compute node for statistics
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yjiang5 committed Jun 19, 2014
1 parent 33c1a19 commit 8cd2b89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nova/db/sqlalchemy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions nova/tests/db/test_db_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5684,6 +5684,13 @@ def test_compute_node_statistics(self):
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)
Expand Down

0 comments on commit 8cd2b89

Please sign in to comment.