Commit 7fc79875 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Added option to check upload

parent e5053117
...@@ -46,6 +46,21 @@ formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s') ...@@ -46,6 +46,21 @@ formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter) ch.setFormatter(formatter)
class Upload:
def __init__(self):
self.data = {'download-binary-dir-url': 'http://www.shacache.org/shadir',
'signature_certificate_file': '/etc/slapos-cache/signature.cert',
'upload-dir-url': 'https://www.shacache.org/shadir',
'shadir-cert-file': '/etc/slapos-cache/shacache.cert',
'download-cache-url': 'https://www.shacache.org/shacache',
'upload-cache-url': 'https://www.shacache.org/shacache',
'shacache-cert-file': '/etc/slapos-cache/shacache.cert',
'upload-binary-cache-url': 'https://www.shacache.org/shacache',
'shacache-key-file': '/etc/slapos-cache/shacache.key',
'download-binary-cache-url': 'http://www.shacache.org/shacache',
'upload-binary-dir-url':'https://www.shacache.org/shadir',
'signature_private_key_file': '/etc/slapos-cache/signature.key',
'shadir-key-file': '/etc/slapos-cache/shacache.key'}
class Parser(OptionParser): class Parser(OptionParser):
""" """
...@@ -65,6 +80,10 @@ class Parser(OptionParser): ...@@ -65,6 +80,10 @@ class Parser(OptionParser):
help="path to slapos cron file", help="path to slapos cron file",
default='/etc/cron.d/slapos-node', default='/etc/cron.d/slapos-node',
type=str), type=str),
Option("--check-upload",
help="Check if upload parameters are ok (do not check certificates)",
default=False,
action="store_true"),
Option("-n", "--dry-run", Option("-n", "--dry-run",
help="Simulate the execution steps", help="Simulate the execution steps",
default=False, default=False,
...@@ -113,12 +132,15 @@ def slapos_conf_check (config): ...@@ -113,12 +132,15 @@ def slapos_conf_check (config):
else : else :
logger.info ("%s parameter:%s is good" % (key,files)) logger.info ("%s parameter:%s is good" % (key,files))
# Check network cache check_networkcache(config,logger,configuration_parser)
def check_networkcache(config,logger,configuration_parser):
# Check network cache download
slapos_cfg_example = get_slapos_conf_example() slapos_cfg_example = get_slapos_conf_example()
configuration_example_parser = ConfigParser.RawConfigParser() configuration_example_parser = ConfigParser.RawConfigParser()
configuration_example_parser.read(slapos_cfg_example) configuration_example_parser.read(slapos_cfg_example)
os.remove(slapos_cfg_example) os.remove(slapos_cfg_example)
section = "networkcache" section = "networkcache"
configuration_example_dict = dict(configuration_example_parser.items(section)) configuration_example_dict = dict(configuration_example_parser.items(section))
configuration_dict = dict(configuration_parser.items(section)) configuration_dict = dict(configuration_parser.items(section))
...@@ -129,7 +151,30 @@ def slapos_conf_check (config): ...@@ -129,7 +151,30 @@ def slapos_conf_check (config):
except KeyError: except KeyError:
logger.warn ("No %s parameter in your file" % key) logger.warn ("No %s parameter in your file" % key)
pass pass
if config.check_upload == True :
check_networkcache_upload(config,logger,configuration_dict)
def check_networkcache_upload(config,logger,configuration_dict):
# Check network cache upload
upload_parameters = Upload()
for key in upload_parameters.data:
try:
if not key.find("file") == -1:
file = configuration_dict[key]
if not os.path.exists(file) :
logger.critical ("%s file for %s parameters does not exist "
% (file,key))
else :
logger.info ("%s parameter:%s is good" % (key,file))
else :
if not configuration_dict[key] == upload_parameters.data[key]:
logger.warn("%s is %s sould be %s"
%(key,configuration_dict[key]
,upload_parameters.data[key]))
except KeyError:
logger.critical ("No %s parameter in your file" % key)
pass
def slapos_global_check (config): def slapos_global_check (config):
# Define logger for register # Define logger for register
......
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