Repository: cobbler/cobbler

Issue:
/usr/sbin/selinuxenabled does not exist on Debian/Ubuntu
Symptom:

```
null@steak:/srv/www/cobbler$ sudo koan --server=192.168.122.1 --port=8080 --virt --system=internal --virt-name=ppmaster02
- looking for Cobbler at http://192.168.122.1:8080/cobbler_api
install_tree: http://192.168.122.1:8080/cblr/links/ubuntu-precise-server-x86_64
/bin/sh: 1: rpm: not found
vgs -o vg_name
File descriptor 3 (/var/log/koan/koan.log) leaked on vgs invocation. Parent PID 9943: /bin/sh
File descriptor 4 (socket:[1408229]) leaked on vgs invocation. Parent PID 9943: /bin/sh
VG
vg0

LANG=C vgs --noheadings -o vg_free --units g vg0
File descriptor 3 (/var/log/koan/koan.log) leaked on vgs invocation. Parent PID 9945: /bin/sh
File descriptor 4 (socket:[1408229]) leaked on vgs invocation. Parent PID 9945: /bin/sh
(2651.89)
lvs --noheadings -o lv_name vg0
File descriptor 3 (/var/log/koan/koan.log) leaked on lvs invocation. Parent PID 9947: /bin/sh
File descriptor 4 (socket:[1408229]) leaked on lvs invocation. Parent PID 9947: /bin/sh
ppmaster02-disk0
root

<type 'exceptions.OSError'>
[Errno 2] No such file or directory
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 274, in main
k.run()
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 424, in run
self.virt()
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 800, in virt
return self.net_install(after_download)
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 669, in net_install
after_download(self, profile_data)
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 798, in after_download
self.virt_net_install(profile_data)
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 1397, in virt_net_install
path_list = self.calc_virt_path(pd, virtname)
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 1749, in calc_virt_path
path = self.calc_virt_path2(pd,name,offset=count,location=x,sizes=virt_sizes)
File "/usr/lib/python2.7/dist-packages/koan/app.py", line 1846, in calc_virt_path2
selinuxenabled = sub_process.call(args)
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception

null@steak:/srv/www/cobbler$ 
```

Cause: This bit in koan/app.py:

```
                # check whether we have SELinux enabled system
                args = "/usr/sbin/selinuxenabled"
                selinuxenabled = sub_process.call(args)
                if selinuxenabled == 0:
```

A good first step would be to tell users what, exactly, is failing, that is: Which file is it that we cannot find?

For now, I have solved this problem by symlinking `/usr/sbin/selinuxenabled` to `/bin/false`



Discussion:
Do you have selinux-utils installed?  That command is part of that package - perhaps we can setup a dependency if this is really a big problem. 

I highly recommend that! Thanks for the hint. I somehow neglected to simply check `apt-file search`

i not sure about requiring additional selinux stuff on ubuntu; since it's not enabled by default on ubuntu.

I concur, if selinux is a requirement install the packages.  Think we can close this.

What about:

if os.path.exists(args) and sub_process.call(args) == 0:
           # required context type
           context_type = "virt_image_t"


Resolving patch:
diff --git a/koan/app.py b/koan/app.py
--- a/koan/app.py
+++ b/koan/app.py
@@ -1872,8 +1872,7 @@ def calc_virt_path2(self,pd,name,offset=0,location=None,sizes=[]):
 
                 # check whether we have SELinux enabled system
                 args = "/usr/sbin/selinuxenabled"
-                selinuxenabled = sub_process.call(args)
-                if selinuxenabled == 0:
+                if os.path.exists(args) and sub_process.call(args) == 0:
                     # required context type
                     context_type = "virt_image_t"
 


Test patch: