summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2011-05-17 10:45:19 -0500
committerRick Harris <rick.harris@rackspace.com>2011-05-17 10:45:19 -0500
commit23bbbfcd3317859d44dba7da7996a978ad922543 (patch)
tree0cada1d996b4aacb341274c98c5b26d65ef1c682 /nova/tests
parent68e34c790612f3250bd902cc87a0ab9d3d69abfb (diff)
First cut at least cost scheduler
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_least_cost_scheduler.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/nova/tests/test_least_cost_scheduler.py b/nova/tests/test_least_cost_scheduler.py
new file mode 100644
index 000000000..a3a18a09f
--- /dev/null
+++ b/nova/tests/test_least_cost_scheduler.py
@@ -0,0 +1,39 @@
+from nova import test
+from nova.scheduler import least_cost
+
+MB = 1024 * 1024
+
+class FakeHost(object):
+ def __init__(self, host_id, free_ram, io):
+ self.id = host_id
+ self.free_ram = free_ram
+ self.io = io
+
+class WeightedSumTest(test.TestCase):
+ def test_empty_domain(self):
+ domain = []
+ weighted_fns = []
+ result = least_cost.weighted_sum(domain, weighted_fns)
+ expected = []
+ self.assertEqual(expected, result)
+
+ def test_basic_costing(self):
+ hosts = [
+ FakeHost(1, 512 * MB, 100),
+ FakeHost(2, 256 * MB, 400),
+ FakeHost(3, 512 * MB, 100)
+ ]
+
+ weighted_fns = [
+ (1, lambda h: h.free_ram), # Fill-first, free_ram is a *cost*
+ (2, lambda h: h.io), # Avoid high I/O
+ ]
+
+ costs = least_cost.weighted_sum(domain=hosts, weighted_fns=weighted_fns)
+
+ # Each 256 MB unit of free-ram contributes 0.5 points by way of:
+ # cost = weight * (score/max_score) = 1 * (256/512) = 0.5
+ # Each 100 iops of IO adds 0.5 points by way of:
+ # cost = 2 * (100/400) = 2 * 0.25 = 0.5
+ expected = [1.5, 2.5, 1.5]
+ self.assertEqual(expected, costs)