示例#1
0
def test_update_log():
    """
    Test for UpgradeLog class.
    Adds record to it, gets it back and compares.
    Then opens the same file file another instance and tries to
    read added record
    """
    tmpFilePath = path.join(tmpDir, tmpFileName)
    if not os.path.exists(tmpDir):
        os.makedirs(tmpDir)
    elif os.path.exists(tmpFilePath):
        os.remove(tmpFilePath)
    log = UpgradeLog(tmpFilePath)
    assert log.lastEvent is None

    now = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
    version = "1.2.3"
    upgrade_id = '1'

    # Check that we can add and then get event
    log.appendScheduled(now, version, upgrade_id)
    last = log.lastEvent
    assert last[1] is UpgradeLog.UPGRADE_SCHEDULED
    assert last[2] == now
    assert last[3] == version
    assert last[4] == upgrade_id

    # Check that the we can load and parse the line we appended before
    assert UpgradeLog(tmpFilePath).lastEvent == last
示例#2
0
def test_update_log():
    """
    Test for UpgradeLog class.
    Adds record to it, gets it back and compares.
    Then opens the same file file another instance and tries to
    read added record
    """
    tmpFilePath = path.join(tmpDir, tmpFileName)
    if not os.path.exists(tmpDir):
        os.makedirs(tmpDir)
    elif os.path.exists(tmpFilePath):
        os.remove(tmpFilePath)
    log = UpgradeLog(tmpFilePath)
    assert log.lastEvent is None

    now = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
    version = "1.2.3"
    upgrade_id = '1'

    # Check that we can add and then get event
    log.appendScheduled(now, version, upgrade_id)
    last = log.lastEvent
    assert last[1] is UpgradeLog.UPGRADE_SCHEDULED
    assert last[2] == now
    assert last[3] == version
    assert last[4] == upgrade_id

    # Check that the we can load and parse the line we appended before
    assert UpgradeLog(tmpFilePath).lastEvent == last
示例#3
0
def test_upgrade_log_append_api(log_file_path, ev_type):
    upgrade_log = UpgradeLog(log_file_path)
    ev_data = UpgradeLogData(datetime.datetime.utcnow(), '1.2.3', 'some_id',
                             'some_pkg')
    getattr(upgrade_log, "append_{}".format(ev_type.name))(ev_data)
    assert upgrade_log.last_event.data == ev_data
    assert upgrade_log.last_event.ev_type == ev_type
def test_upgrade_log_loads_legacy_data(monkeypatch, log_file_path):

    ev_index = None
    tss = [
        '2019-02-28 07:36:23.135789', '2019-02-28 07:37:11.008484',
        '2019-02-28 07:38:33.721644'
    ]

    class datetime_wrapper(datetime.datetime):
        def utcnow():
            return tss[ev_index]

    monkeypatch.setattr(datetime, 'datetime', datetime_wrapper)

    legacy_logs = (
        "{}\tscheduled\t2019-02-28 07:37:11+00:00\t1.6.83\t15513393820971606221\r\n"
        .format(tss[0]) +
        "{}\tstarted\t2019-02-28 07:37:11+00:00\t1.6.83\t15513393820971606221\tindy-node\r\n"
        .format(tss[1]) +
        "{}\tsucceeded\t2019-02-28 07:37:11+00:00\t1.6.83\t15513393820971606221\tindy-node\r\n"
        .format(tss[2]))

    new_logs = (
        "{}\tscheduled\t2019-02-28 07:37:11+00:00\t1.6.83\t15513393820971606221\tindy-node\r\n"
        .format(tss[0]) +
        "{}\tstarted\t2019-02-28 07:37:11+00:00\t1.6.83\t15513393820971606221\tindy-node\r\n"
        .format(tss[1]) +
        "{}\tsucceeded\t2019-02-28 07:37:11+00:00\t1.6.83\t15513393820971606221\tindy-node\r\n"
        .format(tss[2]))

    with open(log_file_path, 'w', newline='') as f:
        f.write(legacy_logs)
    upgrade_log_legacy = UpgradeLog(log_file_path)

    log_file_path_new = log_file_path + '_new'
    upgrade_log_new = UpgradeLog(log_file_path_new)

    for ev_index, ev in enumerate(upgrade_log_legacy):
        getattr(upgrade_log_new, 'append_' + ev.ev_type.name)(ev.data)

    with open(log_file_path_new, 'r', newline='') as f:
        new_logs_read = f.read()

    assert new_logs_read == new_logs
示例#5
0
def populate_log_with_upgrade_events(tdir_with_pool_txns, pool_txn_node_names,
                                     tconf, version: Tuple[str, str, str]):
    for nm in pool_txn_node_names:
        path = os.path.join(tdir_with_pool_txns, tconf.nodeDataDir, nm)
        os.makedirs(path)
        log = UpgradeLog(os.path.join(path, tconf.upgradeLogFile))
        when = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
        log.appendScheduled(when, version, randomString(10))
        log.appendStarted(when, version, randomString(10))
示例#6
0
def populate_log_with_upgrade_events(
        pool_txn_node_names, tdir, tconf, version: Tuple[str, str, str]):
    for nm in pool_txn_node_names:
        config_helper = NodeConfigHelper(nm, tconf, chroot=tdir)
        ledger_dir = config_helper.ledger_dir
        os.makedirs(ledger_dir)
        log = UpgradeLog(os.path.join(ledger_dir, tconf.upgradeLogFile))
        when = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
        log.appendScheduled(when, version, randomString(10))
        log.appendStarted(when, version, randomString(10))
示例#7
0
 def __defaultLog(self, dataDir, config):
     log = os.path.join(dataDir, config.upgradeLogFile)
     return UpgradeLog(filePath=log)