Example #1
0
def check_memvalue(job_desc):
    '''Check if the correct memory limit is applied'''

    specified_memory_value = job_desc.get('memory-limit', default_memory_limit)
    if isinstance(specified_memory_value, int):
        expected_memory_value = specified_memory_value
    else:
        expected_memory_value = \
            memory_size_human_to_bytes(specified_memory_value)

    with patch('resource.setrlimit') as resource_setrlimit:
        set_memory_limit(job_desc)

    eq_(resource_setrlimit.mock_calls,
        [call(resource.RLIMIT_AS, (expected_memory_value, -1))])
Example #2
0
def test_memory_conversion():
    eq_(memory_size_human_to_bytes('1'), 1)
    eq_(memory_size_human_to_bytes('1k'), 1024)
    eq_(memory_size_human_to_bytes('1K'), 1024)
    eq_(memory_size_human_to_bytes('1 k'), 1024)
    eq_(memory_size_human_to_bytes('1 K'), 1024)
    eq_(memory_size_human_to_bytes('1kb'), 1024)
    eq_(memory_size_human_to_bytes('1KB'), 1024)
    eq_(memory_size_human_to_bytes('1 kb'), 1024)
    eq_(memory_size_human_to_bytes('1 KB'), 1024)
    eq_(memory_size_human_to_bytes('1  k'), 1024)
    eq_(memory_size_human_to_bytes('1M'), pow(1024, 2))
    eq_(memory_size_human_to_bytes('1MB'), pow(1024, 2))
    eq_(memory_size_human_to_bytes('1G'), pow(1024, 3))
    eq_(memory_size_human_to_bytes('1GB'), pow(1024, 3))
    eq_(memory_size_human_to_bytes('1T'), pow(1024, 4))
    eq_(memory_size_human_to_bytes('1TB'), pow(1024, 4))
    eq_(memory_size_human_to_bytes('1P'), pow(1024, 5))
    eq_(memory_size_human_to_bytes('1PB'), pow(1024, 5))
    eq_(memory_size_human_to_bytes('1E'), pow(1024, 6))
    eq_(memory_size_human_to_bytes('1EB'), pow(1024, 6))
    eq_(memory_size_human_to_bytes('1Z'), pow(1024, 7))
    eq_(memory_size_human_to_bytes('1ZB'), pow(1024, 7))
    eq_(memory_size_human_to_bytes('1Y'), pow(1024, 8))
    eq_(memory_size_human_to_bytes('1YB'), pow(1024, 8))
    eq_(memory_size_human_to_bytes('2.5 GB'), int(2.5 * pow(1024, 3)))