Esempio n. 1
0
def test_fail_update_instance_changes_from_db(instance_change_provider, tconf,
                                              node_status_db, time_provider,
                                              logsearch):
    # test updating cache with view without votes
    node_status_db.iterator = lambda include_value=True: {
        "3": node_status_db_serializer.serialize(None)
    }.items()
    provider = InstanceChangeProvider(
        tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL, node_status_db,
        time_provider)
    assert not provider.has_view(3)

    # test updating cache with Vote with incorrect timestamp format
    node_status_db.iterator = lambda include_value=True: {
        "3": node_status_db_serializer.serialize({"voter": ["a", 10.4]})
    }.items()
    logs, _ = logsearch(msgs=[
        "InstanceChangeProvider: timestamp in Vote .* : .* - .* must "
        "be of float or int type"
    ])
    InstanceChangeProvider(tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL,
                           node_status_db, time_provider)
    assert logs

    # test updating cache with Vote with incorrect reason format
    node_status_db.iterator = lambda include_value=True: {
        "3": node_status_db_serializer.serialize({"voter": [5, 10.4]})
    }.items()
    logs, _ = logsearch(msgs=[
        "InstanceChangeProvider: reason in Vote .* : .* - .* must "
        "be of int type"
    ])
    InstanceChangeProvider(tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL,
                           node_status_db, time_provider)
    assert logs

    # test updating cache with incorrect view_no format
    node_status_db.iterator = lambda include_value=True: {
        "a": node_status_db_serializer.serialize({"voter": [5, 25]})
    }.items()
    logs, _ = logsearch(
        msgs=["InstanceChangeProvider: view_no='.*' "
              "must be of int type"])
    InstanceChangeProvider(tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL,
                           node_status_db, time_provider)
    assert logs
def test_update_instance_changes_in_db(instance_change_provider, tconf,
                                       node_status_db, time_provider):
    frm = "Node1"
    view_no = 1
    msg = InstanceChange(view_no, Suspicions.PRIMARY_DEGRADED.code)

    assert not instance_change_provider.has_view(view_no)
    assert not instance_change_provider.has_inst_chng_from(view_no, frm)
    assert not _is_view_in_db(view_no, instance_change_provider)

    instance_change_provider.add_vote(msg, frm)
    assert instance_change_provider.has_view(view_no)
    assert instance_change_provider.has_inst_chng_from(view_no, frm)
    assert _is_view_in_db(view_no, instance_change_provider)

    instance_change_provider._node_status_db.close()
    assert instance_change_provider._node_status_db.closed
    instance_change_provider._node_status_db.open()

    new_instance_change_provider = InstanceChangeProvider(
        tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL, node_status_db,
        time_provider)
    assert new_instance_change_provider.has_view(view_no)
    assert new_instance_change_provider.has_inst_chng_from(view_no, frm)