def _scheduleRestart(self, when: Union[datetime, str],
                         failTimeout) -> None:
        """
        Schedules node restart to a newer version

        :param version: version to restart to
        :param when: restart time
        """
        logger.info("{}'s restarter processing restart".format(self))
        if isinstance(when, str):
            when = dateutil.parser.parse(when)
        now = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())

        logger.info("Restart of node '{}' has been scheduled on {}".format(
            self.nodeName, when))

        ev_data = RestartLogData(when)
        self._actionLog.append_scheduled(ev_data)

        callAgent = partial(self._callRestartAgent, ev_data, failTimeout)
        delay = 0
        if now < when:
            delay = (when - now).total_seconds()
        self.scheduledAction = ev_data
        self._schedule(callAgent, delay)
Beispiel #2
0
def test_restarter_can_initialize_after_pool_restart(txnPoolNodeSet):
    '''
    1. Add restart schedule message to ActionLog
    2. Add start restart message to ActionLog
    3. Check that Restarter can be create (emulate case after node restart).
    '''
    unow = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
    restarted_node = txnPoolNodeSet[-1]
    ev_data = RestartLogData(unow)
    restarted_node.restarter._actionLog.append_scheduled(ev_data)
    restarted_node.restarter._actionLog.append_started(ev_data)
    Restarter(restarted_node.id,
              restarted_node.name,
              restarted_node.dataLocation,
              restarted_node.config,
              actionLog=restarted_node.restarter._actionLog)
Beispiel #3
0
def test_restart_log_append_api(log_file_path, ev_type):
    restart_log = RestartLog(log_file_path)
    ev_data = RestartLogData(datetime.datetime.utcnow())
    getattr(restart_log, "append_{}".format(ev_type.name))(ev_data)
    assert restart_log.last_event.data == ev_data
    assert restart_log.last_event.ev_type == ev_type
Beispiel #4
0
def test_restart_log_data_pack_unpack():
    delimiter = '|'
    data = RestartLogData(datetime.datetime.utcnow())
    assert data == RestartLogData.unpack(data.pack(delimiter=delimiter),
                                         delimiter=delimiter)