Merge pull request #31809 from jan--f/c-v-check-selinux

ceph-volume: check if we run in an selinux environment

Reviewed-by: Alfredo Deza <adeza@redhat.com>
This commit is contained in:
Alfredo Deza 2019-11-22 09:28:21 -05:00 committed by GitHub
commit 842b10180d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import getpass
import pytest
from textwrap import dedent
from ceph_volume.util import system
from mock.mock import patch
class TestMkdirP(object):
@ -260,8 +261,9 @@ class TestSetContext(object):
system.set_context('/tmp/foo')
assert len(fake_run.calls)
def test_selinuxenabled_doesnt_exist(self, stub_call, fake_run):
stub_call(('', 'command not found: selinuxenabled', 127))
@patch('ceph_volume.process.call')
def test_selinuxenabled_doesnt_exist(self, mocked_call, fake_run):
mocked_call.side_effect = FileNotFoundError()
system.set_context('/tmp/foo')
assert fake_run.calls == []

View File

@ -297,7 +297,13 @@ def set_context(path, recursive=False):
)
return
stdout, stderr, code = process.call(['selinuxenabled'], verbose_on_failure=False)
try:
stdout, stderr, code = process.call(['selinuxenabled'],
verbose_on_failure=False)
except FileNotFoundError:
logger.info('No SELinux found, skipping call to restorecon')
return
if code != 0:
logger.info('SELinux is not enabled, will not call restorecon')
return