def test_upgrade_does_not_get_into_loop_if_reinstall( looper, tconf, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_trustee, monkeypatch): new_version = bumpedVersion() upgr1 = deepcopy(validUpgrade) upgr1[VERSION] = new_version upgr1[REINSTALL] = True # An upgrade scheduled, it should pass sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr1[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) # here we make nodes think they have upgraded successfully monkeypatch.setattr(indy_node.__metadata__, '__version__', new_version) check_no_loop(nodeSet, UpgradeLog.SUCCEEDED)
def test_do_upgrade_to_the_same_version_if_reinstall(looper, tconf, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_trustee): upgr1 = deepcopy(validUpgrade) upgr1[VERSION] = codeVersion() upgr1[REINSTALL] = True # An upgrade scheduled, it should pass sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr1[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled()))
def test_do_not_upgrade_to_the_same_version(looper, tconf, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_trustee): upgr1 = deepcopy(validUpgrade) upgr1[VERSION] = codeVersion() # An upgrade is not scheduled sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) with pytest.raises(AssertionError): looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr1[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled()))
def test_node_does_not_reschedule_cancelled_upgrade_after_restart( upgradeScheduled, looper, nodeSet, validUpgrade, testNodeClass, tdir, tconf, allPluginsPath, sdk_pool_handle, sdk_wallet_trustee): # Cancel the scheduled upgrade valid_upgrade_cancel = deepcopy(validUpgrade) valid_upgrade_cancel[ACTION] = CANCEL del valid_upgrade_cancel[SCHEDULE] sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, valid_upgrade_cancel) # Verify that no upgrade is scheduled now looper.run( eventually( checkNoUpgradeScheduled, nodeSet, retryWait=1, timeout=waits.expectedNoUpgradeScheduled())) # Restart all the nodes names = [] while nodeSet: node = nodeSet.pop() names.append(node.name) node.cleanupOnStopping = False looper.removeProdable(node) node.stop() del node for nm in names: config_helper = NodeConfigHelper(nm, tconf, chroot=tdir) node = testNodeClass(nm, config_helper=config_helper, config=tconf, pluginPaths=allPluginsPath) looper.add(node) nodeSet.append(node) looper.run(checkNodesConnected(nodeSet)) ensureElectionsDone(looper=looper, nodes=nodeSet, retryWait=1) # Verify that still no upgrade is scheduled looper.run( eventually( checkNoUpgradeScheduled, nodeSet, retryWait=1, timeout=waits.expectedNoUpgradeScheduled()))
def test_update_with_demoted_node(looper, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_stewards, sdk_wallet_trustee): # demote one node demote_node(looper, sdk_wallet_stewards[3], sdk_pool_handle, nodeSet[3]) # remove demoted node from upgrade schedule upgr = validUpgrade del upgr[SCHEDULE][nodeSet[3].id] # send upgrade sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr) # check upg scheduled looper.run(eventually(checkUpgradeScheduled, nodeSet[:3], upgr[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled()))
def test_node_reschedules_upgrade_for_proper_datetime( looper, tconf, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_trustee): upgr1 = deepcopy(validUpgrade) # Upgrade 1 of each node will be scheduled for tomorrow for nodeId in upgr1[SCHEDULE]: nodeUpgradeDateTime = dateutil.parser.parse(upgr1[SCHEDULE][nodeId]) nodeUpgradeDateTime += timedelta(days=1) upgr1[SCHEDULE][nodeId] = nodeUpgradeDateTime.isoformat() upgr2 = deepcopy(upgr1) upgr2[VERSION] = bumpVersion(upgr1[VERSION]) upgr2[NAME] += randomString(32) upgr2[SHA256] = 'ef9c3984e7a31994d4f692139116120bd0dd1ff7e270b6a2d773f8f2f9214d4c' # Upgrade 2 of each node will be scheduled for its own day # (since today with one day step) deltaDays = -1 for nodeId in upgr2[SCHEDULE]: nodeUpgradeDateTime = dateutil.parser.parse(upgr2[SCHEDULE][nodeId]) nodeUpgradeDateTime += timedelta(days=deltaDays) upgr2[SCHEDULE][nodeId] = nodeUpgradeDateTime.isoformat() deltaDays += 1 # Upgrade 1 is scheduled sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr1[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) # Upgrade 2 cancels Upgrade 1 and is scheduled itself # according its own schedule sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr2) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr2[VERSION], upgr2[SCHEDULE], retryWait=1, timeout=waits.expectedUpgradeScheduled()))
def test_upgrade_does_not_get_into_loop_if_failed(looper, tconf, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_trustee, monkeypatch): new_version = bumpedVersion() upgr1 = deepcopy(validUpgrade) upgr1[VERSION] = new_version # An upgrade scheduled, it should pass sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr1[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) # we have not patched indy_node version so nodes think the upgrade had # failed check_no_loop(nodeSet, UpgradeLog.FAILED)
def test_node_schedules_upgrade_for_proper_datetime( looper, tconf, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_trustee): upgr1 = deepcopy(validUpgrade) # Upgrade of each node will be scheduled for its own day # (since today with one day step) deltaDays = 0 for nodeId in upgr1[SCHEDULE]: nodeUpgradeDateTime = dateutil.parser.parse(upgr1[SCHEDULE][nodeId]) nodeUpgradeDateTime += timedelta(days=deltaDays) upgr1[SCHEDULE][nodeId] = nodeUpgradeDateTime.isoformat() deltaDays += 1 # Upgrade is scheduled for the proper datetime for each node sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr1[VERSION], upgr1[SCHEDULE], retryWait=1, timeout=waits.expectedUpgradeScheduled()))
def testRescheduleUpgradeToLowerVersionThanPreviouslyScheduled( looper, tconf, nodeSet, validUpgrade, sdk_pool_handle, sdk_wallet_trustee): """ A node starts at version 1.2 running has scheduled upgrade for version 1.5 but get a txn for upgrade 1.4, it will schedule it and cancel upgrade to 1.5. """ upgr1 = deepcopy(validUpgrade) upgr2 = deepcopy(upgr1) upgr2[VERSION] = bumpVersion(upgr1[VERSION]) upgr2[NAME] += randomString(3) # upgr2[SHA256] = get_valid_code_hash() upgr2[SHA256] = 'ef9c3984e7a31994d4f692139116120bd0dd1ff7e270b6a2d773f8f2f9214d4c' # An upgrade for higher version scheduled, it should pass sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr2) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr2[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) # An upgrade for lower version scheduled, the transaction should pass and # the upgrade should be scheduled sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) looper.run( eventually( checkUpgradeScheduled, nodeSet, upgr1[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled()))
def validUpgradeSentExpForceFalse(looper, nodeSet, tdir, sdk_pool_handle, sdk_wallet_trustee, validUpgradeExpForceFalse): sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, validUpgradeExpForceFalse)
def test_state_recovery_with_xfer(looper, tconf, tdir, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, do_post_node_creation, nodeSetWithIntegratedTokenPlugin, helpers, valid_upgrade, mint_tokens, addresses, fees_set, fees, monkeypatch): version1 = "1.1.50" version2 = "1.1.88" current_amount = get_amount_from_token_txn(mint_tokens) seq_no = 1 node_set = nodeSetWithIntegratedTokenPlugin current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, fees_set, seq_no, looper, addresses, current_amount) # send POOL_UPGRADE to write in a ledger last_ordered = node_set[0].master_last_ordered_3PC[1] sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, valid_upgrade) looper.run(eventually(lambda: assertEquality(node_set[0].master_last_ordered_3PC[1], last_ordered + 1))) send_node_upgrades(node_set, version1, looper) for n in node_set: handler = n.write_manager.request_handlers.get(XFER_PUBLIC)[0] handler_for_1_0_0 = n.write_manager._request_handlers_with_version.get((XFER_PUBLIC, "1.0.0"))[0] monkeypatch.setattr(handler, 'update_state', handler_for_1_0_0.update_state) current_amount, seq_no, _ = send_and_check_transfer(helpers, [addresses[0], addresses[1]], fees_set, looper, current_amount, seq_no, transfer_summ=current_amount) send_node_upgrades(node_set, version2, looper) monkeypatch.undo() current_amount, seq_no, _ = send_and_check_transfer(helpers, [addresses[1], addresses[0]], fees_set, looper, current_amount, seq_no, transfer_summ=current_amount) node_to_stop = node_set[-1] state_db_pathes = [state._kv.db_path for state in node_to_stop.states.values()] node_to_stop.cleanupOnStopping = False node_to_stop.stop() looper.removeProdable(node_to_stop) ensure_node_disconnected(looper, node_to_stop, node_set[:-1]) for path in state_db_pathes: shutil.rmtree(path) config_helper = NodeConfigHelper(node_to_stop.name, tconf, chroot=tdir) restarted_node = TestNode( node_to_stop.name, config_helper=config_helper, config=tconf, pluginPaths=allPluginsPath, ha=node_to_stop.nodestack.ha, cliha=node_to_stop.clientstack.ha) do_post_node_creation(restarted_node) looper.add(restarted_node) node_set[-1] = restarted_node looper.run(checkNodesConnected(node_set)) waitNodeDataEquality(looper, restarted_node, *node_set[:-1], exclude_from_check=['check_last_ordered_3pc_backup']) current_amount, seq_no, _ = send_and_check_transfer(helpers, [addresses[0], addresses[1]], {}, looper, current_amount, seq_no, transfer_summ=1) waitNodeDataEquality(looper, restarted_node, *node_set[:-1], exclude_from_check=['check_last_ordered_3pc_backup'])
def testUpgradeLatestUncancelledVersion(looper, txnPoolNodeSet, tconf, sdk_node_theta_added, validUpgrade, sdk_pool_handle, sdk_wallet_trustee, tdirWithPoolTxns, allPluginsPath): """ A node starts and finds several upgrades but selects the latest one which is not cancelled, eg node is on version 1.2 but finds 1.3, 1.4 and 1.5 but since 1.5 is cancelled, it selects 1.4 """ nodeSet = txnPoolNodeSet _, newNode = sdk_node_theta_added for node in nodeSet[:-1]: node.nodestack.removeRemoteByName(newNode.nodestack.name) newNode.nodestack.removeRemoteByName(node.nodestack.name) newNode.stop() nodeSet = nodeSet[:-1] looper.removeProdable(newNode) upgr1 = deepcopy(validUpgrade) upgr2 = deepcopy(upgr1) upgr2[VERSION] = bumpVersion(upgr1[VERSION]) upgr2[NAME] += randomString(3) # upgr2[SHA256] = get_valid_code_hash() upgr2[SHA256] = 'db34a72a90d026dae49c3b3f0436c8d3963476c77468ad955845a1ccf7b03f55' upgr3 = deepcopy(upgr2) upgr3[VERSION] = bumpVersion(upgr2[VERSION]) upgr3[NAME] += randomString(3) # upgr3[SHA256] = get_valid_code_hash() upgr3[SHA256] = '112c060527e8cecfafe64dcb5bdabc4010cc7b64e0bf9bc2a43d23c37d927128' upgr4 = deepcopy(upgr3) upgr4[ACTION] = CANCEL sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr1) looper.run(eventually(checkUpgradeScheduled, nodeSet[:-1], upgr1[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr2) looper.run(eventually(checkUpgradeScheduled, nodeSet[:-1], upgr2[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr3) looper.run(eventually(checkUpgradeScheduled, nodeSet[:-1], upgr3[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, upgr4) looper.run(eventually(checkUpgradeScheduled, nodeSet[:-1], upgr2[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled())) newNode = TestNode(newNode.name, basedirpath=tdirWithPoolTxns, base_data_dir=tdirWithPoolTxns, config=tconf, pluginPaths=allPluginsPath, ha=newNode.nodestack.ha, cliha=newNode.clientstack.ha) looper.add(newNode) nodeSet.append(newNode) looper.run(checkNodesConnected(nodeSet)) looper.run(eventually(checkUpgradeScheduled, [newNode, ], upgr2[VERSION], retryWait=1, timeout=waits.expectedUpgradeScheduled()))