Skip to content

Commit

Permalink
INDY-1236: add opportunity to send restart command with datetime=""
Browse files Browse the repository at this point in the history
Changes:
- added opportunity to send restart command with datetime=""
- added this fix to documentation

Signed-off-by: toktar <[email protected]>
  • Loading branch information
Toktar committed May 3, 2018
1 parent 4124883 commit 0f8d4ee
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion design/pool_restart_txn.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To send POOL_RESTART, fill the field "action" with the value "start".
To cancel the scheduled restart, you should set the field "action" value "cancel".

### POOL_RESTART - restart now
To restart as early as possible, send message without the "datetime" field or put in it value "0" or the past date on this place.
To restart as early as possible, send message without the "datetime" field or put in it value "0" or ""(empty string) or the past date on this place.
The restart is performed immediately and there is no guarantee of receiving an answer with Reply.

### POOL_RESTART - Reply
Expand Down
2 changes: 1 addition & 1 deletion docs/requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ The command to restart all nodes at the time specified in field "datetime"(sent
- `datetime` (string):

Restart time in datetime frmat/
To restart as early as possible, send message without the "datetime" field or put in it value "0" or the past date on this place.
To restart as early as possible, send message without the "datetime" field or put in it value "0" or ""(empty string) or the past date on this place.
The restart is performed immediately and there is no guarantee of receiving an answer with Reply.


Expand Down
2 changes: 1 addition & 1 deletion docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ POOL_RESTART is the command to restart all nodes at the time specified in field
- `datetime` (string):

Restart time in datetime frmat/
To restart as early as possible, send message without the "datetime" field or put in it value "0" or the past date on this place.
To restart as early as possible, send message without the "datetime" field or put in it value "0" or ""(empty string) or the past date on this place.
The restart is performed immediately and there is no guarantee of receiving an answer with Reply.


Expand Down
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion indy_node/server/action_req_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def doStaticValidation(self, request: Request):
self._doStaticValidationPoolRestart(identifier, req_id, operation)

def _doStaticValidationPoolRestart(self, identifier, req_id, operation):
if DATETIME in operation.keys() is None and operation[DATETIME] != "0":
if DATETIME in operation.keys() is None and not (
operation[DATETIME] in ["0", ""]):
try:
dateutil.parser.parse(operation[DATETIME])
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions indy_node/server/restarter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def handleActionTxn(self, req: Request) -> None:
action = txn[ACTION]
if action == START:
when = txn[DATETIME] if DATETIME in txn.keys() else None
if isinstance(when, str) and when != "0":
if isinstance(when, str) and when not in ["0", ""]:
when = dateutil.parser.parse(when)
now = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
if when is None or when == "0" or now >= when:
if when is None or when in ["0", ""] or now >= when:
msg = RestartMessage().toJson()
try:
asyncio.ensure_future(self._open_connection_and_send(msg))
Expand Down
35 changes: 28 additions & 7 deletions indy_node/test/pool_restart/test_pool_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from indy_common.constants import POOL_RESTART, ACTION, START, DATETIME, CANCEL
from indy_node.test.pool_restart.helper import _createServer, _stopServer
from plenum.common.constants import REPLY, TXN_TYPE, DATA
from plenum.common.constants import REPLY, TXN_TYPE
from plenum.common.types import f
from plenum.test.helper import sdk_gen_request, sdk_sign_and_submit_req_obj, \
sdk_get_reply, sdk_get_and_check_replies
Expand Down Expand Up @@ -57,11 +57,11 @@ def test_pool_restart_cancel(
)

unow = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
start_at = unow + timedelta(seconds=100)
start_at = unow + timedelta(seconds=1000)
op = {
TXN_TYPE: POOL_RESTART,
ACTION: START,
DATETIME: str(start_at)
DATETIME: str(datetime.isoformat(start_at))
}
req_obj = sdk_gen_request(op, identifier=sdk_wallet_trustee[1])
req = sdk_sign_and_submit_req_obj(looper,
Expand All @@ -70,10 +70,11 @@ def test_pool_restart_cancel(
req_obj)
for node in txnPoolNodeSet:
assert node.restarter.lastActionEventInfo[0] == RestartLog.SCHEDULED
cancel_at = start_at+timedelta(seconds=1000)
op = {
TXN_TYPE: POOL_RESTART,
ACTION: CANCEL,
DATETIME: str(datetime.isoformat(start_at))
DATETIME: str(datetime.isoformat(cancel_at))
}
req_obj = sdk_gen_request(op, identifier=sdk_wallet_trustee[1])
req = sdk_sign_and_submit_req_obj(looper,
Expand All @@ -85,10 +86,31 @@ def test_pool_restart_cancel(
assert node.restarter.lastActionEventInfo[0] == RestartLog.CANCELLED
_stopServer(server)
_comparison_reply(resp, req_obj)
assert resp[f.RESULT.nm][DATETIME] == str(datetime.isoformat(start_at))
assert resp[f.RESULT.nm][DATETIME] == str(datetime.isoformat(cancel_at))


def test_pool_restart_now_without_datetime(
sdk_pool_handle, sdk_wallet_trustee, looper, tdir, tconf):
op = {
TXN_TYPE: POOL_RESTART,
ACTION: START,
}
pool_restart_now(op, sdk_pool_handle, sdk_wallet_trustee, looper,
tdir, tconf)


def test_pool_restart_now(
def test_pool_restart_now_with_empty_datetime(
sdk_pool_handle, sdk_wallet_trustee, looper, tdir, tconf):
op = {
TXN_TYPE: POOL_RESTART,
ACTION: START,
DATETIME: ""
}
pool_restart_now(op, sdk_pool_handle, sdk_wallet_trustee, looper,
tdir, tconf)


def pool_restart_now(op,
sdk_pool_handle, sdk_wallet_trustee, looper, tdir, tconf):
server, indicator = looper.loop.run_until_complete(
_createServer(
Expand Down Expand Up @@ -137,4 +159,3 @@ def _comparison_reply(resp, req_obj):
assert resp[f.RESULT.nm][f.REQ_ID.nm] == req_obj.reqId
assert resp[f.RESULT.nm][ACTION]
assert resp[f.RESULT.nm][TXN_TYPE] == POOL_RESTART

0 comments on commit 0f8d4ee

Please sign in to comment.