Merge "Implement a upgrade check for 'numactl'"

This commit is contained in:
Zuul 2019-01-07 02:20:26 +00:00 committed by Gerrit Code Review
commit 8f7a4695c3
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)