Do not set cpuset-cpus if cconfig['cpuset_cpus'] == 'all'

In the case of nova_libvirt container, we want to use all CPUs that are
reported online.
Rather than computing the list with Python (which has proven to be
problematic on PPC), let the container engine figuring it out by itself
like it was the case before.

Change-Id: I5d1b88c90dbc4114d996008a407cd1dd9a6eb9da
Closes-Bug: #1868135
(cherry picked from commit 9b62765121)
This commit is contained in:
Emilien Macchi 2020-03-19 12:47:57 -04:00
parent 37ac1e99a6
commit ebc49c444f
6 changed files with 13 additions and 26 deletions

View File

@ -82,12 +82,13 @@ class ComposeV1Builder(base.BaseBuilder):
for extra_host in cconfig.get('extra_hosts', []):
if extra_host:
cmd.append('--add-host=%s' % extra_host)
if 'cpuset_cpus' in cconfig and cconfig['cpuset_cpus'] != '':
if 'cpuset_cpus' in cconfig:
# 'all' is a special value to directly configure all CPUs
# that are available.
if cconfig['cpuset_cpus'] == 'all':
cmd.append('--cpuset-cpus=%s' % common.get_all_cpus())
else:
# that are available. Without specifying --cpuset-cpus, we'll
# let the container engine to figure out what CPUs are online.
# https://bugs.launchpad.net/tripleo/+bug/1868135
# https://bugzilla.redhat.com/show_bug.cgi?id=1813091
if cconfig['cpuset_cpus'] != 'all':
cmd.append('--cpuset-cpus=%s' % cconfig['cpuset_cpus'])
else:
cmd.append('--cpuset-cpus=%s' % common.get_cpus_allowed_list())

View File

@ -91,12 +91,13 @@ class PodmanBuilder(base.BaseBuilder):
for extra_host in cconfig.get('extra_hosts', []):
if extra_host:
cmd.append('--add-host=%s' % extra_host)
if 'cpuset_cpus' in cconfig and cconfig['cpuset_cpus'] != '':
if 'cpuset_cpus' in cconfig:
# 'all' is a special value to directly configure all CPUs
# that are available.
if cconfig['cpuset_cpus'] == 'all':
cmd.append('--cpuset-cpus=%s' % common.get_all_cpus())
else:
# that are available. Without specifying --cpuset-cpus, we'll
# let the container engine to figure out what CPUs are online.
# https://bugs.launchpad.net/tripleo/+bug/1868135
# https://bugzilla.redhat.com/show_bug.cgi?id=1813091
if cconfig['cpuset_cpus'] != 'all':
cmd.append('--cpuset-cpus=%s' % cconfig['cpuset_cpus'])
else:
cmd.append('--cpuset-cpus=%s' % common.get_cpus_allowed_list())

View File

@ -36,7 +36,6 @@ class TestBaseBuilder(base.TestCase):
'one': {
'start_order': 0,
'image': 'centos:7',
'cpuset_cpus': '',
},
'two': {
'start_order': 1,

View File

@ -41,6 +41,7 @@ class TestComposeV1Builder(tbb.TestBaseBuilder):
'env_file': '/tmp/foo.env',
'log_tag': '{{.ImageName}}/{{.Name}}/{{.ID}}',
'cpu_shares': 600,
'cpuset_cpus': 'all',
'mem_limit': '1G',
'memswap_limit': '1G',
'mem_swappiness': '60',
@ -77,7 +78,6 @@ class TestComposeV1Builder(tbb.TestBaseBuilder):
'--hostname=foohostname',
'--add-host=foohost:127.0.0.1',
'--add-host=barhost:127.0.0.2',
'--cpuset-cpus=0,1,2,3',
'--cap-add=SYS_ADMIN', '--cap-add=SETUID', '--cap-drop=NET_RAW',
'centos:7'],
cmd

View File

@ -27,12 +27,6 @@ class TestUtilsCommonCpu(base.TestCase):
actual_list = common.get_cpus_allowed_list()
self.assertEqual(actual_list, expected_list)
@mock.patch("psutil.cpu_count", return_value=4)
def test_get_all_cpus(self, mock_cpu):
expected_list = '0-3'
actual_list = common.get_all_cpus()
self.assertEqual(actual_list, expected_list)
class TestUtilsCommonConfig(base.TestCase):

View File

@ -78,14 +78,6 @@ def get_cpus_allowed_list(**args):
return ','.join([str(c) for c in psutil.Process().cpu_affinity()])
def get_all_cpus(**args):
"""Returns a single list of all CPUs.
:return: Value computed by psutil, e.g. '0-3'
"""
return "0-" + str(psutil.cpu_count() - 1)
def load_config(config, name=None, overrides=None):
container_config = {}
if overrides is None: