Ejemplo n.º 1
0
    def test_check_restart_timestamps(self, get_service_start_time, log,
                                      clear_deferred_restarts,
                                      get_deferred_restarts):
        deferred_restarts = [
            # 'Tue 2021-02-02 10:19:55 UTC'
            deferred_events.ServiceEvent(timestamp=1612261195.0,
                                         service='svcA',
                                         reason='ReasonA',
                                         action='restart')
        ]
        get_deferred_restarts.return_value = deferred_restarts
        get_service_start_time.return_value = datetime.datetime.strptime(
            'Tue 2021-02-02 13:19:55 UTC', '%a %Y-%m-%d %H:%M:%S %Z')
        deferred_events.check_restart_timestamps()
        clear_deferred_restarts.assert_called_once_with(['svcA'])

        clear_deferred_restarts.reset_mock()
        get_service_start_time.return_value = datetime.datetime.strptime(
            'Tue 2021-02-02 10:10:55 UTC', '%a %Y-%m-%d %H:%M:%S %Z')
        deferred_events.check_restart_timestamps()
        self.assertFalse(clear_deferred_restarts.called)
        log.assert_called_once_with(
            ('Restart still required, svcA was started at 2021-02-02 10:10:55,'
             ' restart was requested after that at 2021-02-02 10:19:55'),
            level='DEBUG')
 def custom_assess_status_check(self):
     """Report deferred events in charm status message."""
     state = None
     message = None
     deferred_events.check_restart_timestamps()
     events = collections.defaultdict(set)
     for e in deferred_events.get_deferred_events():
         events[e.action].add(e.service)
     for action, svcs in events.items():
         svc_msg = "Services queued for {}: {}".format(
             action, ', '.join(sorted(svcs)))
         state = 'active'
         if message:
             message = "{}. {}".format(message, svc_msg)
         else:
             message = svc_msg
     deferred_hooks = deferred_events.get_deferred_hooks()
     if deferred_hooks:
         state = 'active'
         svc_msg = "Hooks skipped due to disabled auto restarts: {}".format(
             ', '.join(sorted(deferred_hooks)))
         if message:
             message = "{}. {}".format(message, svc_msg)
         else:
             message = svc_msg
     return state, message
Ejemplo n.º 3
0
def assess_status(configs):
    """Assess status of current unit
    Decides what the state of the unit should be based on the current
    configuration.
    SIDE EFFECT: calls set_os_workload_status(...) which sets the workload
    status of the unit.
    Also calls status_set(...) directly if paused state isn't complete.
    @param configs: a templating.OSConfigRenderer() object
    @returns None - this function is executed for its side-effect
    """
    check_restart_timestamps()
    exclude_services = []
    if is_unit_paused_set():
        exclude_services = ['openvswitch-switch']
    assess_status_func(configs, exclude_services)()
    os_application_version_set(VERSION_PACKAGE)