Commit ae837389 authored by Marco Mariani's avatar Marco Mariani

fixed error messages and logging levels

parent 4cabab29
...@@ -72,7 +72,7 @@ def do_configure_client(logger, master_url_web, token, config_path, master_url): ...@@ -72,7 +72,7 @@ def do_configure_client(logger, master_url_web, token, config_path, master_url):
# where we expect to create them. If so, ask the use to manually remove them. # where we expect to create them. If so, ask the use to manually remove them.
if os.path.exists(config_path): if os.path.exists(config_path):
logger.critical('There is file in %s. ' logger.critical('There is a file in %s. '
'Please remove it before creating a new configuration.', config_path) 'Please remove it before creating a new configuration.', config_path)
sys.exit(1) sys.exit(1)
...@@ -119,4 +119,4 @@ def do_configure_client(logger, master_url_web, token, config_path, master_url): ...@@ -119,4 +119,4 @@ def do_configure_client(logger, master_url_web, token, config_path, master_url):
logger.debug('Writing key to %s', key_path) logger.debug('Writing key to %s', key_path)
fout.write(key) fout.write(key)
logger.info('SlapOS client configuration: DONE') logger.info('SlapOS client configuration written to %s', config_path)
...@@ -213,10 +213,8 @@ def slapconfig(conf): ...@@ -213,10 +213,8 @@ def slapconfig(conf):
key_file = os.path.join(user_certificate_repository_path, 'key') key_file = os.path.join(user_certificate_repository_path, 'key')
cert_file = os.path.join(user_certificate_repository_path, 'certificate') cert_file = os.path.join(user_certificate_repository_path, 'certificate')
for src, dst in [
(conf.key, key_file), for src, dst in [(conf.key, key_file), (conf.certificate, cert_file)]:
(conf.certificate, cert_file)
]:
conf.logger.info('Copying to %r, and setting minimum privileges', dst) conf.logger.info('Copying to %r, and setting minimum privileges', dst)
if not dry_run: if not dry_run:
with open(dst, 'w') as destination: with open(dst, 'w') as destination:
...@@ -231,8 +229,8 @@ def slapconfig(conf): ...@@ -231,8 +229,8 @@ def slapconfig(conf):
os.mkdir(certificate_repository_path, 0o711) os.mkdir(certificate_repository_path, 0o711)
# Put slapos configuration file # Put slapos configuration file
slap_conf_file = os.path.join(slap_conf_dir, 'slapos.cfg') config_path = os.path.join(slap_conf_dir, 'slapos.cfg')
conf.logger.info('Creating slap configuration: %s', slap_conf_file) conf.logger.info('Creating slap configuration: %s', config_path)
# Get example configuration file # Get example configuration file
slapos_cfg_example = get_slapos_conf_example() slapos_cfg_example = get_slapos_conf_example()
...@@ -257,10 +255,10 @@ def slapconfig(conf): ...@@ -257,10 +255,10 @@ def slapconfig(conf):
new_configp.set('slapformat', 'ipv6_interface', conf.ipv6_interface) new_configp.set('slapformat', 'ipv6_interface', conf.ipv6_interface)
if not dry_run: if not dry_run:
with open(slap_conf_file, 'w') as fout: with open(config_path, 'w') as fout:
new_configp.write(fout) new_configp.write(fout)
conf.logger.info('SlapOS configuration: DONE') conf.logger.info('SlapOS configuration written to %s', config_path)
class RegisterConfig(object): class RegisterConfig(object):
......
...@@ -301,8 +301,7 @@ class Computer(object): ...@@ -301,8 +301,7 @@ class Computer(object):
self.backup_xml(path_to_archive, path_to_xml) self.backup_xml(path_to_archive, path_to_xml)
except: except:
# give up trying # give up trying
logger.warning("Can't backup %s: %s" % logger.exception("Can't backup %s:", path_to_xml)
(path_to_xml, traceback.format_exc()))
with open(path_to_xml, 'wb') as fout: with open(path_to_xml, 'wb') as fout:
fout.write(new_pretty_xml) fout.write(new_pretty_xml)
...@@ -985,7 +984,7 @@ def parse_computer_xml(conf, xml_path): ...@@ -985,7 +984,7 @@ def parse_computer_xml(conf, xml_path):
ipv6_interface=conf.ipv6_interface) ipv6_interface=conf.ipv6_interface)
if os.path.exists(xml_path): if os.path.exists(xml_path):
conf.logger.info('Loading previous computer data from %r' % xml_path) conf.logger.debug('Loading previous computer data from %r' % xml_path)
computer = Computer.load(xml_path, computer = Computer.load(xml_path,
reference=conf.computer_id, reference=conf.computer_id,
ipv6_interface=conf.ipv6_interface) ipv6_interface=conf.ipv6_interface)
...@@ -993,7 +992,7 @@ def parse_computer_xml(conf, xml_path): ...@@ -993,7 +992,7 @@ def parse_computer_xml(conf, xml_path):
computer.interface = interface computer.interface = interface
else: else:
# If no pre-existent configuration found, create a new computer object # If no pre-existent configuration found, create a new computer object
conf.logger.warning('Creating new data computer with id %r' % conf.computer_id) conf.logger.warning('Creating new computer data with id %r', conf.computer_id)
computer = Computer( computer = Computer(
reference=conf.computer_id, reference=conf.computer_id,
interface=interface, interface=interface,
...@@ -1005,13 +1004,15 @@ def parse_computer_xml(conf, xml_path): ...@@ -1005,13 +1004,15 @@ def parse_computer_xml(conf, xml_path):
partition_amount = int(conf.partition_amount) partition_amount = int(conf.partition_amount)
existing_partition_amount = len(computer.partition_list) existing_partition_amount = len(computer.partition_list)
if partition_amount < existing_partition_amount:
raise ValueError('Requested amount of computer partitions (%s) is lower '
'then already configured (%s), cannot continue' % (partition_amount,
existing_partition_amount))
conf.logger.info('Adding %s new partitions' % if partition_amount < existing_partition_amount:
(partition_amount - existing_partition_amount)) conf.logger.critical('Requested amount of computer partitions (%s) is lower '
'than already configured (%s), cannot continue',
partition_amount, existing_partition_amount)
sys.exit(1)
elif partition_amount > existing_partition_amount:
conf.logger.info('Adding %s new partitions',
partition_amount - existing_partition_amount)
for i in range(existing_partition_amount, partition_amount): for i in range(existing_partition_amount, partition_amount):
# add new partitions # add new partitions
...@@ -1092,7 +1093,7 @@ def do_format(conf): ...@@ -1092,7 +1093,7 @@ def do_format(conf):
logger=conf.logger) logger=conf.logger)
conf.logger.info('Posting information to %r' % conf.master_url) conf.logger.info('Posting information to %r' % conf.master_url)
computer.send(conf) computer.send(conf)
conf.logger.info('slapformat successfully prepared computer.') conf.logger.info('slapos successfully prepared the computer.')
class FormatConfig(object): class FormatConfig(object):
...@@ -1232,7 +1233,7 @@ class FormatConfig(object): ...@@ -1232,7 +1233,7 @@ class FormatConfig(object):
file_location) file_location)
sys.exit(1) sys.exit(1)
self.logger.info("Started.") self.logger.debug('Started.')
if self.dry_run: if self.dry_run:
self.logger.info("Dry-run mode enabled.") self.logger.info("Dry-run mode enabled.")
if self.create_tap: if self.create_tap:
......
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