Commit fa09225f authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

enhanced slaptes

	 - Check if all parameters are in section 'slapos' and 'slapformat'
	 - Detect duplicated lines in cron.d
	 - Added comments
parent f9e93aa6
......@@ -108,14 +108,11 @@ def get_slapos_conf_example():
return path
def check_networkcache(config,logger,configuration_parser):
def check_networkcache(config,logger,configuration_parser
,configuration_example_parser):
"""
Check network cache download
"""
slapos_cfg_example = get_slapos_conf_example()
configuration_example_parser = ConfigParser.RawConfigParser()
configuration_example_parser.read(slapos_cfg_example)
os.remove(slapos_cfg_example)
section = "networkcache"
configuration_example_dict = dict(configuration_example_parser.items(section))
configuration_dict = dict(configuration_parser.items(section))
......@@ -124,7 +121,7 @@ def check_networkcache(config,logger,configuration_parser):
if not configuration_dict[key] == configuration_example_dict[key] :
logger.warn("%s parameter in %s section is out of date" % (key, section))
except KeyError:
logger.warn("No %s parameter in your file" % key)
logger.warn("No %s parameter in %s section" % (key,section))
pass
if config.test_agent:
......@@ -176,10 +173,14 @@ def check_networkcache_upload(config,logger,configuration_dict):
%(key,configuration_dict[key]
,upload_parameters.data[key]))
except KeyError:
logger.critical ("No %s parameter in your file" % key)
logger.critical("No %s parameter in networkcache section "
% (key))
pass
def get_computer_name(certificate):
"""
Extract computer_id for certificate
"""
certificate = open(certificate,"r")
for line in certificate:
i=0
......@@ -191,6 +192,9 @@ def get_computer_name(certificate):
return -1
def check_computer_id(logger,computer_id,cert_file):
"""
Get computer id from cert_file and compare with computer_id
"""
comp_cert = get_computer_name(cert_file)
if comp_cert == "":
logger.error("Certificate file indicated is corrupted (no computer id)")
......@@ -214,22 +218,34 @@ def slapos_conf_check (config):
,'slapos.cfg')
configuration_parser = ConfigParser.SafeConfigParser()
configuration_parser.read(configuration_file_path)
# Check if files for slapos and slapformat exists
# Get example configuration file
slapos_cfg_example = get_slapos_conf_example()
configuration_example_parser = ConfigParser.RawConfigParser()
configuration_example_parser.read(slapos_cfg_example)
os.remove(slapos_cfg_example)
# Check if parameters for slapos and slapformat exists
for section in ("slapos","slapformat"):
configuration_dict = dict(configuration_parser.items(section))
for key in configuration_dict:
if key in ("key_file","cert_file","certificate_repository_path"):
configuration_example_dict = dict(configuration_example_parser.items(section))
for key in configuration_example_dict:
if not key in configuration_dict:
logger.critical("No %s parameter in %s section "
% (key,section))
# check if necessary files exist
elif key in ("key_file","cert_file","certificate_repository_path"):
files = configuration_dict[key]
if not os.path.exists(files) :
logger.critical ("%s file for %s parameters does not exist "
% (files,key))
else :
logger.info ("%s parameter:%s does exists" % (key,files))
# check if computer id is the same in slapos.cfg and certificate
if key == "cert_file":
check_computer_id(logger,configuration_dict["computer_id"],
configuration_dict["cert_file"])
# Check networkcache
check_networkcache(config,logger,configuration_parser)
check_networkcache(config,logger,configuration_parser,
configuration_example_parser)
class CronFile:
......@@ -252,12 +268,22 @@ class CronFile:
""" Parse cron line and give value to attributes """
line = cron_line.split()
command = line[6]
if "slapformat" in command : self.slapformat = self.compare(self.slapformat_base.split() , line)
if "slapgrid-ur" in command : self.slapgrid_ur = self.compare(self.slapgrid_ur_base.split() , line)
if "slapgrid-cp" in command : self.slapgrid_cp = self.compare(self.slapgrid_cp_base.split() , line)
if "slapgrid-sr" in command : self.slapgrid_sr = self.compare(self.slapgrid_sr_base.split() , line)
if "slapformat" in command :
self.slapformat = self.compare(self.slapformat,
self.slapformat_base.split() , line)
if "slapgrid-ur" in command :
self.slapgrid_ur = self.compare(self.slapgrid_ur,
self.slapgrid_ur_base.split() , line)
if "slapgrid-cp" in command :
self.slapgrid_cp = self.compare(self.slapgrid_cp,
self.slapgrid_cp_base.split() , line)
if "slapgrid-sr" in command :
self.slapgrid_sr = self.compare(self.slapgrid_sr,
self.slapgrid_sr_base.split() , line)
def compare(self,reference,cron_line):
def compare(self,state,reference,cron_line):
if not state == -1 :
return 2
for i in range(0,6):
if not reference[i] == cron_line[i] :
return 0
......@@ -276,6 +302,9 @@ class CronFile:
logger.error("No line found for %s command" % key)
elif elements[key] == 1 :
logger.info("Line for %s command is good" % key)
elif elements[key] == 2 :
logger.error("You have a duplicated line for %s command" % key)
def cron_check (config):
......
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