Commit 7c3116eb authored by Marco Mariani's avatar Marco Mariani

bring out check_missing_parameters from mammoth

parent 32bd7c06
...@@ -58,12 +58,6 @@ from slapos.grid.utils import (md5digest, createPrivateDirectory, dropPrivileges ...@@ -58,12 +58,6 @@ from slapos.grid.utils import (md5digest, createPrivateDirectory, dropPrivileges
setRunning, setFinished, SlapPopen, updateFile) setRunning, setFinished, SlapPopen, updateFile)
import slapos.slap import slapos.slap
MANDATORY_PARAMETER_LIST = [
'computer_id',
'instance_root',
'master_url',
'software_root',
]
# XXX: should be moved to SLAP library # XXX: should be moved to SLAP library
COMPUTER_PARTITION_DESTROYED_STATE = 'destroyed' COMPUTER_PARTITION_DESTROYED_STATE = 'destroyed'
...@@ -85,6 +79,27 @@ class _formatXMLError(Exception): ...@@ -85,6 +79,27 @@ class _formatXMLError(Exception):
pass pass
def check_missing_parameters(options):
required = set([
'computer_id',
'instance_root',
'master_url',
'software_root',
])
if 'key_file' in options:
required.add('certificate_repository_path')
required.add('cert_file')
if 'cert_file' in options:
required.add('certificate_repository_path')
required.add('key_file')
missing = required.difference(options)
if missing:
raise RuntimeError('Missing mandatory parameters: %s' % ', '.join(sorted(missing)))
def parse_arguments_merge_config(*argument_tuple): def parse_arguments_merge_config(*argument_tuple):
"""Parse arguments and return options dictionary """Parse arguments and return options dictionary
merged with the config file.""" merged with the config file."""
...@@ -202,10 +217,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple): ...@@ -202,10 +217,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
setup_logger(options) setup_logger(options)
missing = [] check_missing_parameters(options)
for mandatory_parameter in MANDATORY_PARAMETER_LIST:
if not mandatory_parameter in options:
missing.append(mandatory_parameter)
if options.get('all'): if options.get('all'):
options['develop'] = True options['develop'] = True
...@@ -213,23 +225,6 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple): ...@@ -213,23 +225,6 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
if options.get('maximum_periodicity') is not None: if options.get('maximum_periodicity') is not None:
options['force_periodicity'] = True options['force_periodicity'] = True
repository_required = False
if 'key_file' in options:
repository_required = True
if not 'cert_file' in options:
missing.append('cert_file')
if 'cert_file' in options:
repository_required = True
if not 'key_file' in options:
missing.append('key_file')
if repository_required:
if 'certificate_repository_path' not in options:
missing.append('certificate_repository_path')
if missing:
raise RuntimeError('Missing mandatory parameters:\n%s' % '\n'.join(
missing))
key_file = options.get('key_file') key_file = options.get('key_file')
cert_file = options.get('cert_file') cert_file = options.get('cert_file')
master_ca_file = options.get('master_ca_file') master_ca_file = options.get('master_ca_file')
......
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