Exemplo n.º 1
0
def test_class_conf():
    # The tests handle only a single file at this point...
    ctx = context_wrap(LIMITS_CONF, path=LIMITS_CONF_PATH)
    data = LimitsConf(ctx)

    assert data.domains == \
        sorted(['oracle', 'root'])
Exemplo n.º 2
0
def test_class_bad():
    # The tests handle only a single file at this point...
    ctx = context_wrap(BAD_LIMITS_CONF, path=LIMITS_CONF_PATH)
    data = LimitsConf(ctx)

    assert data.domains == []
    bad_lines = BAD_LIMITS_CONF.strip().splitlines()
    assert data.bad_lines == bad_lines
Exemplo n.º 3
0
def test_all_limits_conf():
    data1 = LimitsConf(context_wrap(LIMITS_CONF, path=LIMITS_CONF_PATH))
    data2 = LimitsConf(context_wrap(LIMITS_D_CONF, path=LIMITS_D_PATH))
    all_data = AllLimitsConf([data1, data2])

    assert len(all_data.rules) == 7
    assert all_data.rules[0] == {'domain': 'oracle', 'type': 'soft', 'item': 'nofile', 'value': 1024, 'file': LIMITS_CONF_PATH}
    assert all_data.rules[1] == {'domain': 'oracle', 'type': 'hard', 'item': 'nofile', 'value': 65536, 'file': LIMITS_CONF_PATH}
    assert all_data.rules[2] == {'domain': 'oracle', 'type': 'soft', 'item': 'stack', 'value': 10240, 'file': LIMITS_CONF_PATH}
    assert all_data.rules[3] == {'domain': 'oracle', 'type': 'hard', 'item': 'stack', 'value': 3276, 'file': LIMITS_CONF_PATH}
    assert all_data.rules[4] == {'domain': 'root', 'type': 'soft', 'item': 'nproc', 'value': -1, 'file': LIMITS_CONF_PATH}
    assert all_data.rules[5] == {'domain': '@jackuser', 'type': '-', 'item': 'rtprio', 'value': 70, 'file': LIMITS_D_PATH}
    assert all_data.rules[6] == {'domain': '@jackuser', 'type': '-', 'item': 'memlock', 'value': 4194304, 'file': LIMITS_D_PATH}

    assert all_data.domains == set(['oracle', 'root', '@jackuser'])

    assert all_data.find_all(domain='root') == [all_data.rules[4]]

    data3 = LimitsConf(context_wrap(DUP_LIMITS_D_CONF, path=DUP_LIMITS_D_CONF_PATH))
    all_data = AllLimitsConf([data1, data3])
    # Check de-duplication of rules
    assert len(all_data.rules) == 5  # No extra rule
    assert all_data.rules[3] == {'domain': 'oracle', 'type': 'hard', 'item': 'stack', 'value': 1926, 'file': DUP_LIMITS_D_CONF_PATH}
Exemplo n.º 4
0
def test_class_complete():
    # The tests handle only a single file at this point...
    ctx = context_wrap(FULL_OPTS_LIMITS_CONF, path=LIMITS_CONF_PATH)
    data = LimitsConf(ctx)

    assert data.domains == \
        sorted(
            ['oracle', '@dbadmins', '*', ':1001', '1000:', '2000:2020',
            '@:101', '@100:', '@200:202', 'managers']
        )

    # Data check
    assert data.rules[0] == \
        {'domain': 'oracle', 'type': 'soft', 'item': 'nofile', 'value': 1024, 'file': LIMITS_CONF_PATH}

    # User domain match
    # oracle soft, wildcard, and oracle hard
    assert data.find_all(domain='oracle') == \
        [data.rules[x] for x in [0, 2, 9]]
    # Group domain match
    # dbadmins group and wildcard
    assert data.find_all(domain='@dbadmins') == \
        [data.rules[x] for x in [1, 2]]
    # UID domain match
    # wildcard, uid 1001 exact, and uid range 1000:
    assert data.find_all(domain=1001) == \
        [data.rules[x] for x in [2, 3, 4]]
    # UID min range domain match
    # wildcard and uid range 1000:
    assert data.find_all(domain=1002) == \
        [data.rules[x] for x in [2, 4]]
    # UID min:max range match
    # wildcard, uid range 1000:, and uid range 2000:2020
    assert data.find_all(domain=2001) == \
        [data.rules[x] for x in [2, 4, 5]]
    # GID domain match
    # wildcard, gid 101 exact, and gid range 100:
    assert data.find_all(domain='@101') == \
        [data.rules[x] for x in [2, 6, 7]]
    # GID min range domain match
    # wildcard and gid range 100:
    assert data.find_all(domain='@102') == \
        [data.rules[x] for x in [2, 7]]
    # GID min:max range match
    # wildcard, gid range 100:, and gid range 200:202
    assert data.find_all(domain='@201') == \
        [data.rules[x] for x in [2, 7, 8]]
    # soft type match
    # most rules but not the hard rule
    assert data.find_all(type='soft') == \
        [data.rules[x] for x in [0, 1, 2, 3, 4, 5, 6, 7, 8, 10]]
    # hard type match
    # hard and both
    assert data.find_all(type='hard') == \
        [data.rules[x] for x in [9, 10]]
    # No match at all
    assert data.find_all(domain='postgres', type='hard') == \
        []
    # No rules to match
    assert data.find_all() == \
        []