MCPcopy Create free account
hub / github.com/apache/cloudstack / check_selinux

Function check_selinux

python/lib/cloud_utils.py:317–341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

315
316#check function
317def check_selinux():
318 if distro not in [Fedora,CentOS,RHEL6,SUSE]: return # no selinux outside of those
319 enforcing = False
320 config_enforcing = False
321 try:
322 output = getenforce().stdout.decode('utf-8').strip()
323 if "nforcing" in output:
324 enforcing = True
325 if any ( [ s.startswith("SELINUX=enforcing") for s in open("/etc/selinux/config").readlines() ] ):
326 config_enforcing = True
327 else:
328 config_enforcing = False
329 except (IOError,OSError) as e:
330 if e.errno == 2: pass
331 else: raise CheckFailed("An unknown error (%s) took place while checking for SELinux"%str(e))
332 if enforcing:
333 raise CheckFailed('''SELinux is set to enforcing. There are two options:
3341> Set it permissive in /etc/selinux/config, then reboot the machine.
3352> Type 'setenforce Permissive' in commandline, after which you can run this program again.
336
337We strongly suggest you doing the option 1 that makes sure SELinux goes into permissive after system reboot.\n''')
338
339 if config_enforcing:
340 print("WARNING: We detected that your SELinux is not configured in permissive. to make sure cloudstack won't block by \
341SELinux after system reboot, we strongly suggest you setting it in permissive in /etc/selinux/config, then reboot the machine.")
342
343
344def preflight_checks(do_check_kvm=True):

Callers

nothing calls this directly

Calls 4

anyFunction · 0.85
CheckFailedClass · 0.85
readlinesMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected