[fix] Avoid double log if name change

This commit is contained in:
ljf 2018-06-05 17:38:46 +02:00
parent 65d8d88a09
commit 9e1dac99f7
2 changed files with 17 additions and 3 deletions

View file

@ -278,6 +278,7 @@ class UnitOperation(object):
self.started_at = None self.started_at = None
self.ended_at = None self.ended_at = None
self.logger = None self.logger = None
self._name = None
self.path = OPERATIONS_PATH self.path = OPERATIONS_PATH
@ -324,6 +325,9 @@ class UnitOperation(object):
Name of the operation Name of the operation
This name is used as filename, so don't use space This name is used as filename, so don't use space
""" """
if self._name is not None:
return self._name
name = [self.started_at.strftime("%Y%m%d-%H%M%S")] name = [self.started_at.strftime("%Y%m%d-%H%M%S")]
name += [self.operation] name += [self.operation]
if self.related_to: if self.related_to:
@ -331,7 +335,8 @@ class UnitOperation(object):
name += [self.related_to[0][1]] name += [self.related_to[0][1]]
else: else:
name += self.related_to[0].values() name += self.related_to[0].values()
return '-'.join(name) self._name = '-'.join(name)
return self._name
@property @property
def metadata(self): def metadata(self):

View file

@ -290,8 +290,6 @@ def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False
""" """
result = {} result = {}
if not dry_run:
uo.start()
# Return the list of pending conf # Return the list of pending conf
if list_pending: if list_pending:
pending_conf = _get_pending_conf(names) pending_conf = _get_pending_conf(names)
@ -305,6 +303,12 @@ def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False
} }
return pending_conf return pending_conf
if not dry_run:
uo.related_to = [('service', x) for x in names]
if not names:
uo.related_to = [('service', 'all')]
uo.start()
# Clean pending conf directory # Clean pending conf directory
if os.path.isdir(PENDING_CONF_DIR): if os.path.isdir(PENDING_CONF_DIR):
if not names: if not names:
@ -340,8 +344,13 @@ def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False
# Set the processing method # Set the processing method
_regen = _process_regen_conf if not dry_run else lambda *a, **k: True _regen = _process_regen_conf if not dry_run else lambda *a, **k: True
uo.related_to = []
# Iterate over services and process pending conf # Iterate over services and process pending conf
for service, conf_files in _get_pending_conf(names).items(): for service, conf_files in _get_pending_conf(names).items():
if not dry_run:
uo.related_to.append(('service', service))
logger.info(m18n.n( logger.info(m18n.n(
'service_regenconf_pending_applying' if not dry_run else 'service_regenconf_pending_applying' if not dry_run else
'service_regenconf_dry_pending_applying', 'service_regenconf_dry_pending_applying',