Merge lp:~billy-olsen/charm-helpers/lp1602444 into lp:charm-helpers

Proposed by Billy Olsen
Status: Merged
Merged at revision: 604
Proposed branch: lp:~billy-olsen/charm-helpers/lp1602444
Merge into: lp:charm-helpers
Diff against target: 53 lines (+31/-1)
2 files modified
charmhelpers/contrib/openstack/context.py (+4/-1)
tests/contrib/openstack/test_os_contexts.py (+27/-0)
To merge this branch: bzr merge lp:~billy-olsen/charm-helpers/lp1602444
Reviewer Review Type Date Requested Status
David Ames (community) Approve
Review via email: mp+299880@code.launchpad.net
To post a comment you must log in.
Revision history for this message
David Ames (thedac) wrote :

Looks good to me. Merging.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/context.py'
2--- charmhelpers/contrib/openstack/context.py 2016-07-12 18:23:03 +0000
3+++ charmhelpers/contrib/openstack/context.py 2016-07-12 23:06:41 +0000
4@@ -1196,7 +1196,10 @@
5
6 def __call__(self):
7 multiplier = config('worker-multiplier') or 0
8- ctxt = {"workers": self.num_cpus * multiplier}
9+ count = int(self.num_cpus * multiplier)
10+ if multiplier > 0 and count == 0:
11+ count = 1
12+ ctxt = {"workers": count}
13 return ctxt
14
15
16
17=== modified file 'tests/contrib/openstack/test_os_contexts.py'
18--- tests/contrib/openstack/test_os_contexts.py 2016-07-05 22:41:39 +0000
19+++ tests/contrib/openstack/test_os_contexts.py 2016-07-12 23:06:41 +0000
20@@ -2451,6 +2451,33 @@
21 worker = context.WorkerConfigContext()
22 self.assertTrue(worker.num_cpus, 2)
23
24+ def test_workerconfig_context_float(self):
25+ self.config.side_effect = fake_config({
26+ 'worker-multiplier': 0.3
27+ })
28+ with patch.object(context.WorkerConfigContext, 'num_cpus', 4):
29+ worker = context.WorkerConfigContext()
30+ self.assertTrue(worker.num_cpus, 1)
31+
32+ def test_workerconfig_context_not_quite_0(self):
33+ # Make sure that the multiplier evaluating to somewhere between
34+ # 0 and 1 in the floating point range still has at least one
35+ # worker.
36+ self.config.side_effect = fake_config({
37+ 'worker-multiplier': 0.001
38+ })
39+ with patch.object(context.WorkerConfigContext, 'num_cpus', 100):
40+ worker = context.WorkerConfigContext()
41+ self.assertTrue(worker.num_cpus, 1)
42+
43+ def test_workerconfig_context_0(self):
44+ self.config.side_effect = fake_config({
45+ 'worker-multiplier': 0
46+ })
47+ with patch.object(context.WorkerConfigContext, 'num_cpus', 2):
48+ worker = context.WorkerConfigContext()
49+ self.assertTrue(worker.num_cpus, 0)
50+
51 def test_workerconfig_context_noconfig(self):
52 self.config.return_value = None
53 with patch.object(context.WorkerConfigContext, 'num_cpus', 2):

Subscribers

People subscribed via source and target branches