Allow regen-conf to manage new files already when they're already present on the system (#311)

This commit is contained in:
Alexandre Aubin 2017-05-22 15:24:47 +02:00 committed by GitHub
parent c0a40dd2df
commit 7af130d81b
2 changed files with 14 additions and 7 deletions

View file

@ -216,10 +216,11 @@
"service_conf_file_copy_failed": "Unable to copy the new configuration file '{new}' to '{conf}'", "service_conf_file_copy_failed": "Unable to copy the new configuration file '{new}' to '{conf}'",
"service_conf_file_manually_modified": "The configuration file '{conf}' has been manually modified and will not be updated", "service_conf_file_manually_modified": "The configuration file '{conf}' has been manually modified and will not be updated",
"service_conf_file_manually_removed": "The configuration file '{conf}' has been manually removed and will not be created", "service_conf_file_manually_removed": "The configuration file '{conf}' has been manually removed and will not be created",
"service_conf_file_not_managed": "The configuration file '{conf}' is not managed yet and will not be updated",
"service_conf_file_remove_failed": "Unable to remove the configuration file '{conf}'", "service_conf_file_remove_failed": "Unable to remove the configuration file '{conf}'",
"service_conf_file_removed": "The configuration file '{conf}' has been removed", "service_conf_file_removed": "The configuration file '{conf}' has been removed",
"service_conf_file_updated": "The configuration file '{conf}' has been updated", "service_conf_file_updated": "The configuration file '{conf}' has been updated",
"service_conf_new_managed_file": "The configuration file '{conf}' is now managed by the service {service}.",
"service_conf_file_kept_back": "The configuration file '{conf}' is expected to be deleted by service {service} but has been kept back.",
"service_conf_up_to_date": "The configuration is already up-to-date for service '{service}'", "service_conf_up_to_date": "The configuration is already up-to-date for service '{service}'",
"service_conf_updated": "The configuration has been updated for service '{service}'", "service_conf_updated": "The configuration has been updated for service '{service}'",
"service_conf_would_be_updated": "The configuration would have been updated for service '{service}'", "service_conf_would_be_updated": "The configuration would have been updated for service '{service}'",

View file

@ -391,15 +391,21 @@ def service_regen_conf(names=[], with_diff=False, force=False, dry_run=False,
logger.debug("> no changes to system conf has been made") logger.debug("> no changes to system conf has been made")
conf_status = 'managed' conf_status = 'managed'
regenerated = True regenerated = True
elif force and to_remove: elif not to_remove:
# If the conf exist but is not managed yet, and is not to be removed,
# we assume that it is safe to regen it, since the file is backuped
# anyway (by default in _regen), as long as we warn the user
# appropriately.
logger.warning(m18n.n('service_conf_new_managed_file',
conf=system_path, service=service))
regenerated = _regen(system_path, pending_path)
conf_status = 'new'
elif force:
regenerated = _regen(system_path) regenerated = _regen(system_path)
conf_status = 'force-removed' conf_status = 'force-removed'
elif force:
regenerated = _regen(system_path, pending_path)
conf_status = 'force-updated'
else: else:
logger.warning(m18n.n('service_conf_file_not_managed', logger.warning(m18n.n('service_conf_file_kept_back',
conf=system_path)) conf=system_path, service=service))
conf_status = 'unmanaged' conf_status = 'unmanaged'
# -> system conf has not been manually modified # -> system conf has not been manually modified
elif system_hash == saved_hash: elif system_hash == saved_hash: