Exemplo n.º 1
0
def test_lock__two_hosts_get_host_count(ilm_daemon):
    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)

    ret, s2 = ilm.ilm_connect()
    assert ret == 0
    assert s2 > 0

    host_id = HOST2
    ret = ilm.ilm_set_host_id(s2, host_id, 32)

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_lock(s2, lock_id, lock_op)
    assert ret == 0

    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 1
    assert self == 1

    ret = ilm.ilm_unlock(s1, lock_id)
    assert ret == 0

    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 1
    assert self == 0

    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == 0

    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 0
    assert self == 0

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret = ilm.ilm_disconnect(s2)
    assert ret == 0
Exemplo n.º 2
0
def test_lock__two_hosts_convert_exclusive_timeout_to_exclusive_success(
        ilm_daemon):
    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)

    ret, s2 = ilm.ilm_connect()
    assert ret == 0
    assert s2 > 0

    host_id = HOST2
    ret = ilm.ilm_set_host_id(s2, host_id, 32)

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK2_VG_UUID)
    lock_id.set_lv_uuid(LOCK2_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_EXCLUSIVE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 20000  # Timeout: 20s

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_stop_renew(s1)
    assert ret == 0

    time.sleep(30)

    ret = ilm.ilm_lock(s2, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_convert(s2, lock_id, ilm.IDM_MODE_SHAREABLE)
    assert ret == 0

    ret, mode = ilm.ilm_get_mode(s2, lock_id, lock_op)
    assert ret == 0
    assert mode == ilm.IDM_MODE_SHAREABLE

    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret = ilm.ilm_disconnect(s2)
    assert ret == 0
Exemplo n.º 3
0
def test_lock__two_hosts_exclusive_success_shareable_fail(ilm_daemon):
    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)

    ret, s2 = ilm.ilm_connect()
    assert ret == 0
    assert s2 > 0

    host_id = HOST2
    ret = ilm.ilm_set_host_id(s2, host_id, 32)

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_EXCLUSIVE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s2, lock_id, lock_op)
    assert ret == -1

    ret = ilm.ilm_unlock(s1, lock_id)
    assert ret == 0

    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == -1

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret = ilm.ilm_disconnect(s2)
    assert ret == 0
Exemplo n.º 4
0
def test_lock__one_host_release_twice(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == -1

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 5
0
def test_lock__convert_exclusive_to_exclusive(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_EXCLUSIVE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_convert(s, lock_id, ilm.IDM_MODE_EXCLUSIVE)
    assert ret == 0

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 6
0
def test_lock__shareable_100_times(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    for i in range(100):
        lock_op = ilm.idm_lock_op()
        lock_op.mode = ilm.IDM_MODE_SHAREABLE
        lock_op.drive_num = 2
        lock_op.set_drive_names(0, DRIVE1)
        lock_op.set_drive_names(1, DRIVE2)
        lock_op.timeout = 60000  # Timeout: 60s

        ret = ilm.ilm_lock(s, lock_id, lock_op)
        assert ret == 0

        ret = ilm.ilm_unlock(s, lock_id)
        assert ret == 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 7
0
def test_lock__timeout(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 3000  # Timeout: 3s

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_stop_renew(s)
    assert ret == 0

    time.sleep(5)

    # Unlock will receive 0 if timeout
    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 8
0
def test_inject_fault_10_percent__2_drives_renew(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 3000  # Timeout: 3s

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 0)
    assert ret == 0

    time.sleep(5)

    ret = ilm.ilm_stop_renew(s)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 0)
    assert ret == 0

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 9
0
def test_lockspace(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 10
0
def test_inject_fault__4_drives_unlock(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 4
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.set_drive_names(2, DRIVE3)
    lock_op.set_drive_names(3, DRIVE4)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 100)
    assert ret == 0

    # Return -EIO
    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == -5

    # Return -EIO
    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == -5

    ret = ilm.ilm_inject_fault(s, 0)
    assert ret == 0

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 50)
    assert ret == 0

    # Return -EIO
    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == -5

    ret = ilm.ilm_inject_fault(s, 0)
    assert ret == 0

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 11
0
def test_version(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    ret, version = ilm.ilm_version(s, DRIVE1)
    assert ret == 0
    assert version == 0x100

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 12
0
def test_lock__lvb_write(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_EXCLUSIVE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    a = ilm.charArray(8)

    ret = ilm.ilm_read_lvb(s, lock_id, a, 8)
    assert ret == 0

    a[0] = 'a'
    ret = ilm.ilm_write_lvb(s, lock_id, a, 8)
    assert ret == 0

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    a[0] = '0'
    ret = ilm.ilm_read_lvb(s, lock_id, a, 8)
    assert ret == 0
    assert a[0] == 'a'

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 13
0
def test_lock__wrong_mode(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = 0
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == -22

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 14
0
def test_lock__get_mode_not_existed(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    # Return unlock mode if the IDM has not been created
    ret, mode = ilm.ilm_get_mode(s, lock_id, lock_op)
    assert ret == 0
    assert mode == ilm.IDM_MODE_UNLOCK

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 15
0
def test_lock__lvb_read_two_hosts(ilm_daemon):
    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)

    ret, s2 = ilm.ilm_connect()
    assert ret == 0
    assert s2 > 0

    host_id = HOST2
    ret = ilm.ilm_set_host_id(s2, host_id, 32)

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_EXCLUSIVE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    a = ilm.charArray(8)

    ret = ilm.ilm_read_lvb(s1, lock_id, a, 8)
    assert ret == 0
    assert ord(a[0]) == 0
    assert ord(a[1]) == 0
    assert ord(a[2]) == 0
    assert ord(a[3]) == 0
    assert ord(a[4]) == 0
    assert ord(a[5]) == 0
    assert ord(a[6]) == 0
    assert ord(a[7]) == 0

    a[0] = 'a'
    a[1] = 'b'
    a[2] = 'c'
    a[3] = 'd'
    a[4] = 'e'
    a[5] = 'f'
    a[6] = 'g'
    a[7] = 'h'

    ret = ilm.ilm_write_lvb(s1, lock_id, a, 8)
    assert ret == 0

    ret = ilm.ilm_unlock(s1, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    b = ilm.charArray(8)

    ret = ilm.ilm_read_lvb(s1, lock_id, b, 8)
    assert ret == 0
    assert b[0] == 'a'
    assert b[1] == 'b'
    assert b[2] == 'c'
    assert b[3] == 'd'
    assert b[4] == 'e'
    assert b[5] == 'f'
    assert b[6] == 'g'
    assert ord(b[7]) == 0

    ret = ilm.ilm_unlock(s1, lock_id)
    assert ret == 0

    ret = ilm.ilm_lock(s2, lock_id, lock_op)
    assert ret == 0

    c = ilm.charArray(8)

    ret = ilm.ilm_read_lvb(s2, lock_id, c, 8)
    assert ret == 0
    assert c[0] == 'a'
    assert c[1] == 'b'
    assert c[2] == 'c'
    assert c[3] == 'd'
    assert c[4] == 'e'
    assert c[5] == 'f'
    assert c[6] == 'g'
    assert ord(c[7]) == 0

    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret = ilm.ilm_disconnect(s2)
    assert ret == 0
Exemplo n.º 16
0
def test_lock__lvb_read_timeout(ilm_daemon):
    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)

    ret, s2 = ilm.ilm_connect()
    assert ret == 0
    assert s2 > 0

    host_id = HOST2
    ret = ilm.ilm_set_host_id(s2, host_id, 32)

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_EXCLUSIVE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 5000  # Timeout: 5s

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_stop_renew(s1)
    assert ret == 0

    time.sleep(6)

    ret = ilm.ilm_lock(s2, lock_id, lock_op)
    assert ret == 0

    a = ilm.charArray(8)

    ret = ilm.ilm_read_lvb(s2, lock_id, a, 8)
    assert ret == 0
    assert a[0] == '\xff'
    assert a[1] == '\xff'
    assert a[2] == '\xff'
    assert a[3] == '\xff'
    assert a[4] == '\xff'
    assert a[5] == '\xff'
    assert a[6] == '\xff'
    assert a[7] == '\xff'

    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == 0

    ret = ilm.ilm_unlock(s1, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret = ilm.ilm_disconnect(s2)
    assert ret == 0
Exemplo n.º 17
0
def test_inject_fault__3_drives_renew(ilm_daemon):
    ret, s = ilm.ilm_connect()
    assert ret == 0
    assert s > 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 3
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.set_drive_names(2, DRIVE3)
    lock_op.timeout = 3000  # Timeout: 3s

    ## Test for 100 percentage fault
    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 100)
    assert ret == 0

    time.sleep(5)

    ret = ilm.ilm_stop_renew(s)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 0)
    assert ret == 0

    # Return success after timeout
    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_start_renew(s)
    assert ret == 0

    ## Test for 50 percentage fault
    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    # Inject fault for renewal in lockspace
    ret = ilm.ilm_inject_fault(s, 50)
    assert ret == 0

    time.sleep(5)

    ret = ilm.ilm_stop_renew(s)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 0)
    assert ret == 0

    # Return success after timeout
    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_start_renew(s)
    assert ret == 0

    ## Test for 0 percentage fault
    ret = ilm.ilm_lock(s, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_inject_fault(s, 0)
    assert ret == 0

    time.sleep(5)

    ret = ilm.ilm_stop_renew(s)
    assert ret == 0

    ret = ilm.ilm_unlock(s, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s)
    assert ret == 0
Exemplo n.º 18
0
def test_lock__two_hosts_get_mode(ilm_daemon):
    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)

    ret, s2 = ilm.ilm_connect()
    assert ret == 0
    assert s2 > 0

    host_id = HOST2
    ret = ilm.ilm_set_host_id(s2, host_id, 32)

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    ret, mode = ilm.ilm_get_mode(s1, lock_id, lock_op)
    assert ret == 0
    assert mode == ilm.IDM_MODE_SHAREABLE

    # Before host2 acquires the lock, let's see if
    # can read out correct mode or not
    ret, mode = ilm.ilm_get_mode(s2, lock_id, lock_op)
    assert ret == 0
    assert mode == ilm.IDM_MODE_SHAREABLE

    ret = ilm.ilm_lock(s2, lock_id, lock_op)
    assert ret == 0

    ret, mode = ilm.ilm_get_mode(s1, lock_id, lock_op)
    assert ret == 0
    assert mode == ilm.IDM_MODE_SHAREABLE

    ret, mode = ilm.ilm_get_mode(s2, lock_id, lock_op)
    assert ret == 0
    assert mode == ilm.IDM_MODE_SHAREABLE

    ret = ilm.ilm_unlock(s1, lock_id)
    assert ret == 0

    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == 0

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret = ilm.ilm_disconnect(s2)
    assert ret == 0
Exemplo n.º 19
0
def test_lock__three_hosts_get_host_count(ilm_daemon):
    ret, s1 = ilm.ilm_connect()
    assert ret == 0
    assert s1 > 0

    host_id = HOST1
    ret = ilm.ilm_set_host_id(s1, host_id, 32)
    assert ret == 0

    ret, s2 = ilm.ilm_connect()
    assert ret == 0
    assert s2 > 0

    host_id = HOST2
    ret = ilm.ilm_set_host_id(s2, host_id, 32)
    assert ret == 0

    ret, s3 = ilm.ilm_connect()
    assert ret == 0
    assert s3 > 0

    host_id = HOST3
    ret = ilm.ilm_set_host_id(s3, host_id, 32)
    assert ret == 0

    lock_id = ilm.idm_lock_id()
    lock_id.set_vg_uuid(LOCK1_VG_UUID)
    lock_id.set_lv_uuid(LOCK1_LV_UUID)

    lock_op = ilm.idm_lock_op()
    lock_op.mode = ilm.IDM_MODE_SHAREABLE
    lock_op.drive_num = 2
    lock_op.set_drive_names(0, DRIVE1)
    lock_op.set_drive_names(1, DRIVE2)
    lock_op.timeout = 60000  # Timeout: 60s

    ret = ilm.ilm_lock(s1, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_lock(s2, lock_id, lock_op)
    assert ret == 0

    ret = ilm.ilm_lock(s3, lock_id, lock_op)
    assert ret == 0

    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 2
    assert self == 1

    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == 0

    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 1
    assert self == 1

    # Duplicate unlocking, so received error
    ret = ilm.ilm_unlock(s2, lock_id)
    assert ret == -1

    # Check if the host count is 2 (s0 and s2 are granted)
    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 1
    assert self == 1

    ret = ilm.ilm_unlock(s3, lock_id)
    assert ret == 0

    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 0
    assert self == 1

    ret = ilm.ilm_unlock(s1, lock_id)
    assert ret == 0

    # All hosts have released the IDM, so return -ENOENT
    ret, count, self = ilm.ilm_get_host_count(s1, lock_id, lock_op)
    assert ret == 0
    assert count == 0
    assert self == 0

    ret = ilm.ilm_disconnect(s1)
    assert ret == 0

    ret = ilm.ilm_disconnect(s2)
    assert ret == 0

    ret = ilm.ilm_disconnect(s3)
    assert ret == 0