Merge lp:~james-page/charm-helpers/lp1537155 into lp:charm-helpers

Proposed by James Page
Status: Merged
Merged at revision: 525
Proposed branch: lp:~james-page/charm-helpers/lp1537155
Merge into: lp:charm-helpers
Diff against target: 73 lines (+30/-7)
3 files modified
charmhelpers/contrib/openstack/context.py (+11/-7)
test_requirements.txt (+1/-0)
tests/contrib/openstack/test_os_contexts.py (+18/-0)
To merge this branch: bzr merge lp:~james-page/charm-helpers/lp1537155
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+284411@code.launchpad.net

Description of the change

Support number of cpu detection on Ubuntu 16.04

The version of psutil in 16.04 does not have NUM_CPUS.

Use the new cpu_count function if present, otherwise use NUM_CPUS.

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

Approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/openstack/context.py'
--- charmhelpers/contrib/openstack/context.py 2016-01-06 22:04:12 +0000
+++ charmhelpers/contrib/openstack/context.py 2016-01-29 09:25:13 +0000
@@ -90,6 +90,12 @@
90from charmhelpers.contrib.openstack.utils import get_host_ip90from charmhelpers.contrib.openstack.utils import get_host_ip
91from charmhelpers.core.unitdata import kv91from charmhelpers.core.unitdata import kv
9292
93try:
94 import psutil
95except ImportError:
96 apt_install('python-psutil', fatal=True)
97 import psutil
98
93CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'99CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
94ADDRESS_TYPES = ['admin', 'internal', 'public']100ADDRESS_TYPES = ['admin', 'internal', 'public']
95101
@@ -1258,13 +1264,11 @@
12581264
1259 @property1265 @property
1260 def num_cpus(self):1266 def num_cpus(self):
1261 try:1267 # NOTE: use cpu_count if present (16.04 support)
1262 from psutil import NUM_CPUS1268 if hasattr(psutil, 'cpu_count'):
1263 except ImportError:1269 return psutil.cpu_count()
1264 apt_install('python-psutil', fatal=True)1270 else:
1265 from psutil import NUM_CPUS1271 return psutil.NUM_CPUS
1266
1267 return NUM_CPUS
12681272
1269 def __call__(self):1273 def __call__(self):
1270 multiplier = config('worker-multiplier') or 01274 multiplier = config('worker-multiplier') or 0
12711275
=== modified file 'test_requirements.txt'
--- test_requirements.txt 2015-12-11 17:02:13 +0000
+++ test_requirements.txt 2016-01-29 09:25:13 +0000
@@ -17,3 +17,4 @@
17netifaces==0.10 # trusty is 0.8, but using py3 compatible version for tests.17netifaces==0.10 # trusty is 0.8, but using py3 compatible version for tests.
18Jinja2==2.6 # precise18Jinja2==2.6 # precise
19six==1.1 # precise19six==1.1 # precise
20psutil==1.2.1 # trusty
2021
=== modified file 'tests/contrib/openstack/test_os_contexts.py'
--- tests/contrib/openstack/test_os_contexts.py 2016-01-06 22:04:12 +0000
+++ tests/contrib/openstack/test_os_contexts.py 2016-01-29 09:25:13 +0000
@@ -2367,6 +2367,24 @@
2367 self.assertEquals(context.NotificationDriverContext()(),2367 self.assertEquals(context.NotificationDriverContext()(),
2368 {'notifications': 'True'})2368 {'notifications': 'True'})
23692369
2370 @patch.object(context, 'psutil')
2371 def test_workerconfig_context_xenial(self, _psutil):
2372 self.config.side_effect = fake_config({
2373 'worker-multiplier': 1,
2374 })
2375 _psutil.cpu_count.return_value = 4
2376 worker = context.WorkerConfigContext()
2377 self.assertTrue(worker.num_cpus, 4)
2378
2379 @patch.object(context, 'psutil')
2380 def test_workerconfig_context_trusty(self, _psutil):
2381 self.config.side_effect = fake_config({
2382 'worker-multiplier': 2,
2383 })
2384 _psutil.NUM_CPUS = 4
2385 worker = context.WorkerConfigContext()
2386 self.assertTrue(worker.num_cpus, 2)
2387
2370 def test_workerconfig_context_noconfig(self):2388 def test_workerconfig_context_noconfig(self):
2371 self.config.return_value = None2389 self.config.return_value = None
2372 with patch.object(context.WorkerConfigContext, 'num_cpus', 2):2390 with patch.object(context.WorkerConfigContext, 'num_cpus', 2):

Subscribers

People subscribed via source and target branches