Exemplo n.º 1
0
    def _get_curr_info(cls, package):
        from stp_core.common.log import getlogger
        import os
        logger = getlogger()
        if package == APP_NAME:
            return (
                "Package: {}\nStatus: install ok installed\nPriority: extra\nSection: default\n"
                "Installed-Size: 21\nMaintainer: maintainer\nArchitecture: amd64\nVersion: {}\n"
            ).format(APP_NAME, releaseVersion())

        raise ValueError("Only {} is expected, got: {}".format(APP_NAME, package))
def testNodeControlPerformsMigrations(monkeypatch, tdir, looper, tconf):
    version = bumpedVersion()
    stdout = 'teststdout'
    migrationFile = 'migrationProof'
    migrationText = "{} {}".format(releaseVersion(), version)

    old_call_upgrade_script = None

    def mock_call_upgrade_script(*args, **kwargs):
        old_call_upgrade_script(*args, **kwargs)
        monkeypatch.setattr(
            NodeControlUtil,
            '_get_curr_info',
            lambda *x, **y: (
                "Package: {}\nVersion: {}\n".format(APP_NAME, version)
            )
        )

    def mock_migrate(curr_src_ver: str, new_src_ver: str):
        with open(os.path.join(tdir, migrationFile), 'w') as f:
            f.write("{} {}".format(curr_src_ver, new_src_ver))

    def transform(tool):
        nonlocal old_call_upgrade_script
        nodeControlGeneralMonkeypatching(tool, monkeypatch, tdir, stdout)
        monkeypatch.setattr(tool, '_do_migration', mock_migrate)
        old_call_upgrade_script = getattr(tool, '_call_upgrade_script')
        monkeypatch.setattr(tool, '_call_upgrade_script', mock_call_upgrade_script)

    def checkMigration():
        with open(os.path.join(tdir, migrationFile)) as f:
            assert f.read() == migrationText

    monkeypatch.setattr(
        NodeControlUtil, 'get_latest_pkg_version',
        lambda *x, **y: DebianVersion(
            version, upstream_cls=src_version_cls())
    )

    nct = NCT(backup_dir=tdir, backup_target=tdir, transform=transform, config=tconf)
    try:
        sendUpgradeMessage(version)
        looper.run(eventually(checkMigration))
    finally:
        nct.stop()
import pytest

import indy_node
from indy_node.server.upgrade_log import UpgradeLog
from indy_common.constants import COMPLETE
from indy_node.test.upgrade.helper import populate_log_with_upgrade_events, \
    check_node_sent_acknowledges_upgrade, check_node_do_not_sent_acknowledges_upgrade, \
    emulate_restart_pool_for_upgrade, emulate_view_change_pool_for_upgrade

from indy_node.test.upgrade.helper import releaseVersion

whitelist = ['unable to send message']
# TODO: Implement a client in node

version = releaseVersion()


@pytest.fixture(scope="module")
def tdirWithPoolTxns(tdirWithPoolTxns, poolTxnNodeNames, tdir, tconf):
    # For each node, adding a file with he current version number which makes the node
    # think that an upgrade has been performed
    populate_log_with_upgrade_events(poolTxnNodeNames, tdir, tconf, version)
    return tdirWithPoolTxns


def test_node_detected_upgrade_done(nodeSet):
    '''
    Test that each node checks Upgrade Log on startup (after Upgrade restart), and writes SUCCESS to it
    because the current version equals to the one in Upgrade log.
    Upgrade log already created START event (see fixture above emulating real upgrade)
    '''