To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit ff6ee5b0 authored by Reto Da Forno's avatar Reto Da Forno

bugfix and new check for xmllint added to validator script

parent f0ff4713
......@@ -137,9 +137,9 @@ def main(argv):
# Open the log and create logger:
try:
logging.config.fileConfig(scriptpath + '/logging.conf')
logger = logging.getLogger("testconfig_validator.py")
logger = logging.getLogger(os.path.basename(__file__))
except:
syslog.syslog(syslog.LOG_ERR, "testconfig_validator.py: Could not open logger because: %s: %s" %(str(sys.exc_info()[0]), str(sys.exc_info()[1])))
syslog.syslog(syslog.LOG_ERR, "%s: Could not open logger because: %s: %s" % (os.path.basename(__file__), str(sys.exc_info()[0]), str(sys.exc_info()[1])))
# Get the config file:
config = flocklab.get_config()
......@@ -148,7 +148,7 @@ def main(argv):
sys.exit(errno.EAGAIN)
# Get command line parameters.
try:
try:
opts, args = getopt.getopt(argv, "hvqu:s:x:t:", ["help", "version", "quiet", "userid=", "schema=", "xml=", "testid="])
except getopt.GetoptError, err:
logger.warn(str(err))
......@@ -207,7 +207,17 @@ def main(argv):
# Set the schemapath:
if not schemapath:
schemapath = config.get('xml', 'schemapath')
# check if xmllint is installed
try:
subprocess.check_call(['which', 'xmllint'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# if check_call doesn't raise an exception, then return code was zero (success)
except:
if not quiet:
print "xmllint not found!"
logger.warn("xmllint not found!")
sys.exit(errno.EINVAL)
# Connect to the DB:
try:
db = MySQLdb.connect(host=config.get('database','host'), user=config.get('database','user'), passwd=config.get('database','password'), db=config.get('database','database'))
......@@ -251,18 +261,24 @@ def main(argv):
# Validate the XML against the XML schema
#===========================================================================
if errcnt == 0:
p = subprocess.Popen(['xmllint', '--noout', xmlpath, '--schema', schemapath], stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
for err in stderr.split('\n'):
tmp = err.split(':')
if len(tmp) >= 7:
if not quiet:
print "<b>Line " + tmp[1] + "</b>:" + tmp[2] + ":" + ":".join(tmp[6:])
errcnt = errcnt + 1
elif not ((err.find('fails to validate') != -1) or (err.find('validates') != -1) or (err == '\n') or (err == '')):
if not quiet:
print err
errcnt = errcnt + 1
try:
p = subprocess.Popen(['xmllint', '--noout', xmlpath, '--schema', schemapath], stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
for err in stderr.split('\n'):
tmp = err.split(':')
if len(tmp) >= 7:
if not quiet:
print "<b>Line " + tmp[1] + "</b>:" + tmp[2] + ":" + ":".join(tmp[6:])
errcnt = errcnt + 1
elif not ((err.find('fails to validate') != -1) or (err.find('validates') != -1) or (err == '\n') or (err == '')):
if not quiet:
print err
errcnt = errcnt + 1
except:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print "%s %s, %s %s" % (exc_type, sys.exc_info()[1], fname, exc_tb.tb_lineno)
errcnt = errcnt + 1
#===========================================================================
# If XML is valid, do additional checks on <generalConf> and <targetConf> elements
......@@ -273,6 +289,7 @@ def main(argv):
# * If specified, end time has to be after start time
f = open(xmlpath, 'r')
parser = etree.XMLParser(remove_comments=True)
#tree = etree.fromstring(f.read(), parser)
tree = etree.parse(f, parser)
f.close()
ns = {'d': config.get('xml', 'namespace')}
......@@ -395,7 +412,11 @@ def main(argv):
# Get os and platform and put it into dictionary for later use:
opersys = imageconf[0].xpath('d:os', namespaces=ns)[0].text
platform = imageconf[0].xpath('d:platform', namespaces=ns)[0].text
core = int(imageconf[0].xpath('d:core', namespaces=ns)[0].text)
try:
core = int(imageconf[0].xpath('d:core', namespaces=ns)[0].text)
except:
# not a mandatory field, use the default value
core = 0
for obsid in obsids:
if obsid not in obsiddict:
obsiddict[obsid] = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment