Implement a upgrade check for 'numactl'

After the implementation of the cpu pinning feature [1], the program
'numactl' must exist. This commit implements a upgrade check for
existence of this binary.

[1] https://review.openstack.org/#/c/617928/

Change-Id: I255556fbff1b2303de2b41648538f7ec3871f1ba
This commit is contained in:
Hongbin Lu 2018-12-12 04:52:03 +00:00
parent dcd7cf35d4
commit 70a2332234
2 changed files with 34 additions and 8 deletions

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import shutil
import sys
from oslo_upgradecheck import upgradecheck
@ -30,17 +32,30 @@ class Checks(upgradecheck.UpgradeCommands):
and added to _upgrade_checks tuple.
"""
def _sample_check(self):
"""This is sample check added to test the upgrade check framework
def _cmd_exists(self, cmd):
try:
return shutil.which(cmd) is not None
except AttributeError:
# shutil.which is not available in python 2.x so try an
# alternative approach
return any(
os.access(os.path.join(path, cmd), os.X_OK)
for path in os.environ["PATH"].split(os.pathsep)
)
def _numactl_check(self):
"""This is a check for existence of numactl binary
It needs to be removed after adding any real upgrade check
"""
return upgradecheck.Result(upgradecheck.Code.SUCCESS, 'Sample detail')
if self._cmd_exists('numactl'):
return upgradecheck.Result(upgradecheck.Code.SUCCESS)
else:
msg = _("The program 'numactl' is currently not installed.")
return upgradecheck.Result(upgradecheck.Code.FAILURE, msg)
_upgrade_checks = (
# Sample check added for now.
# Whereas in future real checks must be added here in tuple
(_('Sample Check'), _sample_check),
(_('Numactl Check'), _numactl_check),
)

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_upgradecheck.upgradecheck import Code
from zun.cmd import status
@ -24,7 +26,16 @@ class TestUpgradeChecks(base.TestCase):
super(TestUpgradeChecks, self).setUp()
self.cmd = status.Checks()
def test__sample_check(self):
check_result = self.cmd._sample_check()
@mock.patch.object(status.Checks, "_cmd_exists")
def test__numactl_check_ok(self, mock_cmd_exists):
mock_cmd_exists.return_value = True
check_result = self.cmd._numactl_check()
self.assertEqual(
Code.SUCCESS, check_result.code)
@mock.patch.object(status.Checks, "_cmd_exists")
def test__numactl_check_fail(self, mock_cmd_exists):
mock_cmd_exists.return_value = False
check_result = self.cmd._numactl_check()
self.assertEqual(
Code.FAILURE, check_result.code)