Bug 1119758 - [RFE] Add support for cobbler "system add" command and "findks" function and make the proxy server "findks" aware (i.e. rewrite url's in kickstart to point to the Proxy server)
Summary: [RFE] Add support for cobbler "system add" command and "findks" function and ...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Spacewalk
Classification: Community
Component: Server
Version: 2.2
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Stephen Herr
QA Contact: Red Hat Satellite QA List
URL:
Whiteboard:
Depends On:
Blocks: space23
TreeView+ depends on / blocked
 
Reported: 2014-07-15 12:49 UTC by Stephen Herr
Modified: 2015-04-14 19:03 UTC (History)
6 users (show)

Fixed In Version: cobbler20-2.0.11-31
Doc Type: Enhancement
Doc Text:
Clone Of: 905129
Environment:
Last Closed: 2015-04-14 19:03:03 UTC


Attachments (Terms of Use)

Description Stephen Herr 2014-07-15 12:49:40 UTC
+++ This bug was initially created as a clone of Bug #905129 +++

Description of problem:

The kssendmac kickstart kernel argument does not select the correct Cobbler system profile with the 'findks' operation.


Version-Release number of selected component (if applicable):
cobbler-2.0.7-23.el6sat.noarch

How reproducible:
Always

Steps to Reproduce:
1. Create a cobbler system profile
2. Add a MAC address to the Cobbler system profile (eg 00:0c:29:a5:73:0a)
3. Issue a wget to the cobbler findks URI specifying the MAC address specified:

wget --header='X-RHN-Provisioning-MAC-0: eth0 00:0c:29:a5:73:0a' http://<rhn_satellite_fqdn>/cblr/svc/op/findks
  
Actual results:
500 Internal Server Error

Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230] mod_wsgi (pid=6555): Exception occurred processing WSGI script '/var/www/cobbler/svc/services.wsgi'.
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230] Traceback (most recent call last):
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230]   File "/var/www/cobbler/svc/services.wsgi", line 81, in application
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230]     content = func( **form )
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230]   File "/usr/lib/python2.6/site-packages/cobbler/services.py", line 230, in findks
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230]     name = self.autodetect(**rest)
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230]   File "/usr/lib/python2.6/site-packages/cobbler/services.py", line 191, in autodetect
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230]     ip = rest["REMOTE_ADDR"]
[Mon Jan 28 16:09:14 2013] [error] [client 192.168.2.230] KeyError: 'REMOTE_ADDR'

Expected results:
The kickstart script for the server to be returned.

Additional info:

The error seems to be in two scripts, and is normally masked by the fact that when a MAC address is added to a Cobbler system profile and a 'cobbler sync' is run, the PXE/tftp entry created adds the ks=path to the cobbler system profile (e.g. ks=http://172.16.204.51/cblr/svc/op/ks/system/test1) and so the kssendmac is not interpreted.

The problem becomes apparent when a separate PXE server is used, and a kernel kickstart line similar to the following is used to auto-select the correct kickstart profile based on MAC address:

kssendmac text ks=http://172.16.204.51/cblr/svc/op/findks

The following edits for the two erroneous files in cobbler-2.0.7-23.el6sat.noarch for RHN Satellite 5.5 seem to have fixed the problem:

/var/www/cobbler/svc/services.wsgi

--- services.wsgi.original_5.5	2013-01-28 15:42:22.104842450 +0000
+++ services.wsgi	2013-01-28 15:41:48.510009907 +0000
@@ -56,7 +56,11 @@ def application(environ, start_response)
     # This MAC header is set by anaconda during a kickstart booted with the 
     # kssendmac kernel option. The field will appear here as something 
     # like: eth0 XX:XX:XX:XX:XX:XX
-    form["REMOTE_MAC"]  = form.get("HTTP_X_RHN_PROVISIONING_MAC_0", None)
+    form["REMOTE_MAC"]  = environ.get("HTTP_X_RHN_PROVISIONING_MAC_0", None)
+
+    # REMOTE_ADDR isn't a required wsgi attribute so it may be naive to assume
+    # it's always present in this context.
+    form["REMOTE_ADDR"] = environ.get("REMOTE_ADDR", None)
 
     # Read config for the XMLRPC port to connect to:
     fd = open("/etc/cobbler/settings")


/usr/lib/python2.6/site-packages/cobbler/services.py

--- services.py.original_5.5	2013-01-28 15:36:04.866644349 +0000
+++ services.py	2013-01-28 14:56:29.024473937 +0000
@@ -30,7 +30,7 @@ import sys
 import time
 import urlgrabber
 import yaml # PyYAML
-
+import config
 # the following imports are largely for the test code
 import urlgrabber
 import remote
@@ -65,6 +65,7 @@ class CobblerSvc(object):
         self.apache = apache
         self.remote = None
         self.req    = req
+        self.config = config.Config(self)
 
     def __xmlrpc_setup(self):
         """
@@ -217,9 +218,7 @@ class CobblerSvc(object):
     def findks(self,system=None,profile=None,**rest):
         self.__xmlrpc_setup()
 
-        serverseg = self.server.replace("http://","")
-        serverseg = self.server.replace("/cobbler_api","")
-
+	serverseg = "http://%s" % self.config._settings.server
         name = "?"    
         type = "system"
         if system is not None:

--- Additional comment from Stephen Herr on 2014-07-14 16:29:07 EDT ---

These changes to cobbler look sane. Making it work through a Proxy is tricky because it's not Proxy that rewrites the urls in the kickstart file, it's Spacewalk. So the Spacewalk request has to have the appropriate headers so that Satellite knows to rewrite the urls in the ksfile.

I bet we can make cobbler return a 302 to the correct url instead of returing the ksfile directly, and that would make everything work correctly. I'm about 75% of the way there, will finish tomorrow.

Comment 1 Stephen Herr 2014-07-15 12:51:37 UTC
Committing to Spacewalk master:
ae3bdc54a56bfae89708e4bb84a5e4b71bc609b6

Comment 2 Grant Gainey 2015-03-23 16:59:01 UTC
Moving bugs to ON_QA as we move to release Spacewalk 2.3

Comment 3 Grant Gainey 2015-04-14 19:03:03 UTC
Spacewalk 2.3 has been released. See

https://fedorahosted.org/spacewalk/wiki/ReleaseNotes23


Note You need to log in before you can comment on or make changes to this bug.