summaryrefslogtreecommitdiffstats
path: root/cobbler/action_validate.py
blob: c0b1f4acc5d12c690ee5e9bea398e16935f22002 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Validates rendered kickstart files.

Copyright 2007, Red Hat, Inc
Michael DeHaan <mdehaan@redhat.com>

This software may be freely redistributed under the terms of the GNU
general public license.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""

import os
import re
import sub_process
from utils import _
import utils

class Validate:

    def __init__(self,config):
        """
        Constructor
        """
        self.config   = config
        self.settings = config.settings()

    def run(self):
        """
        Returns None if there are no errors, otherwise returns a list
        of things to correct prior to running application 'for real'.
        (The CLI usage is "cobbler check" before "cobbler sync")
        """

        if not os.path.exists("/usr/bin/ksvalidator"):
            print _("ksvalidator not installed, please install pykickstart")
            return False 

        failed = False
        for x in self.config.profiles():
            if not self.checkfile(x, True):
                failed = True
        for x in self.config.systems():
            if not self.checkfile(x, False):
                failed = True
 
        if failed:
            print _("*** potential errors detected in kickstarts ***")
        else:
            print _("*** all kickstarts seem to be ok ***")

        return failed

    def checkfile(self,obj,is_profile):
        blended = utils.blender(self.config.api, False, obj)
        ks = blended["kickstart"]
        breed = blended["breed"]
        if breed != "redhat":
            print "%s has a breed of %s, skipping" % (obj.name, breed)
            return True
        if ks is None or ks == "":
            print "%s has no kickstart, skipping" % obj.name
            return True

        server = blended["server"] 
        if not ks.startswith("/"):
            url = self.kickstart
        elif is_profile:
            url = "http://%s/cblr/svc/op/ks/profile/%s" % (server,obj.name)
        else:
            url = "http://%s/cblr/svc/op/ks/system/%s" % (server,obj.name)

        print "----------------------------"
        print "checking url: %s" % url


        rc = os.system("/usr/bin/ksvalidator \"%s\"" % url)
        if rc != 0:
            return False
       
        return True