Skip to content
Permalink
Browse files

Ability to filter cells capacity report by aggregate metadata key

Sometimes you may want to only report certain compute nodes when
calculating the capacity of a cell.

New option cells.capacity_aggregate_key to determine an aggregate
metadata key to filter hosts on. Only these hosts will be included
when reporting cell capacites to it's parents.

Change-Id: I7f9beb669c5d694706d404eb0971962a561ec70e
  • Loading branch information...
sorrison committed Nov 25, 2014
1 parent 60f669b commit 97921ef1010c5e5bca357d77682bd0ee42d6ffcc
@@ -46,6 +46,9 @@
help='Configuration file from which to read cells '
'configuration. If given, overrides reading cells '
'from the database.'),
cfg.StrOpt('capacity_aggregate_key',
help='Aggregate key to limit capacity reporting to '
'certain hosts'),
]


@@ -262,12 +265,19 @@ def _update_our_capacity(self, ctxt=None):
compute_hosts = {}

def _get_compute_hosts():
aggr_nodes = None
if CONF.cells.capacity_aggregate_key:
aggr_nodes = self.db.aggregate_host_get_by_metadata_key(
ctxt, key=CONF.cells.capacity_aggregate_key).keys()

compute_nodes = self.db.compute_node_get_all(ctxt)
for compute in compute_nodes:
service = compute['service']
if not service or service['disabled']:
continue
host = service['host']
if aggr_nodes is not None and host not in aggr_nodes:
continue
compute_hosts[host] = {
'free_ram_mb': compute['free_ram_mb'],
'free_disk_mb': compute['free_disk_gb'] * 1024,
@@ -32,7 +32,7 @@ def test_all_filters(self):
self.assertIn("TargetCellFilter", class_names)


class _FilterTestClass(test.NoDBTestCase):
class _FilterTestClass(test.TestCase):
"""Base class for testing individual filter plugins."""
filter_cls_name = None

@@ -43,7 +43,7 @@
dict(id=2, host='host2')]


class CellsManagerClassTestCase(test.NoDBTestCase):
class CellsManagerClassTestCase(test.TestCase):
"""Test case for CellsManager class."""

def setUp(self):
@@ -33,7 +33,7 @@
group='cells')


class CellsRPCDriverTestCase(test.NoDBTestCase):
class CellsRPCDriverTestCase(test.TestCase):
"""Test case for Cells communication via RPC."""

def setUp(self):
@@ -116,6 +116,37 @@ def test_capacity_no_reserve(self):
units = 5 # 4 on host 3, 1 on host4
self.assertEqual(units, cap['disk_free']['units_by_mb'][str(sz)])

@mock.patch.object(db, 'aggregate_host_get_by_metadata_key')
def test_capacity_no_reserve_with_aggregate(self, mock_aggregate_host):
cfg.CONF.set_override('capacity_aggregate_key', 'fakekey', 'cells')
# Fake an aggregate containing host 1-3
mock_aggregate_host.return_value = {
'host1': set([True]),
'host2': set([True]),
'host3': set([True]),
}
fake_computes_with_aggr = FAKE_COMPUTES[:-1]

# utilize entire cell
cap = self._capacity(0.0)

cell_free_ram = sum(compute[3] for compute in fake_computes_with_aggr)
self.assertEqual(cell_free_ram, cap['ram_free']['total_mb'])

cell_free_disk = 1024 * sum(compute[4] for compute in
fake_computes_with_aggr)
self.assertEqual(cell_free_disk, cap['disk_free']['total_mb'])

self.assertEqual(0, cap['ram_free']['units_by_mb']['0'])
self.assertEqual(0, cap['disk_free']['units_by_mb']['0'])

units = cell_free_ram / 50
self.assertEqual(units, cap['ram_free']['units_by_mb']['50'])

sz = 25 * 1024
units = 4 # 4 on host 3
self.assertEqual(units, cap['disk_free']['units_by_mb'][str(sz)])

def test_capacity_full_reserve(self):
# reserve the entire cell. (utilize zero percent)
cap = self._capacity(100.0)

0 comments on commit 97921ef

Please sign in to comment.
You can’t perform that action at this time.