Ejemplo n.º 1
0
 def comm_test_LockSet_init_with_para(self, data):
     """
     Test the __init__ method of LockSet
     """
     # with lock_list
     assert len(config.nodelist) >= 2, \
            "the length of nodelist in config must greater or equal to 2, "\
            "please check and edit it"
     lockspace = dlm.LockSpace(config.nodelist, config.lockspace, 0, False, display_len=10)
     node1 = lockspace._nodes[config.nodelist[0]]
     lock1 = dlm.Lock(node1)
     lock1.append(dlm.Shot(data[0]))
     lock1.append(dlm.Shot(data[1]))
     node2 = lockspace._nodes[config.nodelist[1]]
     lock2 = dlm.Lock(node2)
     lock2.append(dlm.Shot(data[3]))
     lock2.append(dlm.Shot(data[4]))
     lockset = dlm.LockSet([lock1])
     assert lockset.key_index == 0, "LockSet __init__ function test error"
     assert lockset.node_to_lock_dict == {}, "LockSet __init__ function test error"
     assert lockset._lock_list == [lock1, lock2], "LockSet __init__ function test error"
     assert lockset._nodes_count == 2, "LockSet __init__ function test error"
     assert lockset._name == lock1.name, "LockSet __init__ function test error"
     lockspace = dlm.LockSpace(config.nodelist, config.lockspace, 0, False, display_len=10)
     node1 = lockspace._nodes[config.nodelist[0]]
     node1.process_one_shot(data[0])
     shot_name = dlm.Shot(data[0]).name
     #assert shot_name == ''
     lock1 = node1.locks[shot_name]
     lockset = dlm.LockSet([lock1])
Ejemplo n.º 2
0
 def test_LockSet_append(self, data):
     """
     Test the append method of LockSet
     """
     lockspace = dlm.LockSpace(config.nodelist, config.lockspace, 0, False, display_len=10)
     node1 = lockspace._nodes[config.nodelist[0]]
     lock1 = dlm.Lock(node1)
     shot1 = dlm.Shot(data[0])
     shot2 = dlm.Shot(data[1])
     lock1.append(shot1)
     lock1.append(shot2)
     lockset = dlm.LockSet()
     lockset.append(lock1)
     assert lock1.name == lockset.name
     assert lock1.name._name == 'M000000000000000000000561bea619'
     with pytest.raises(AssertionError):
         lockset.append(lock1)
     node2 = lockspace._nodes[config.nodelist[1]]
     lock2 = dlm.Lock(node2)
     shot1 = dlm.Shot(data[3])
     shot2 = dlm.Shot(data[4])
     lock2.append(shot1)
     lock2.append(shot2)
     lockset.append(lock2)
     assert len(lockset.node_to_lock_dict) == 2, \
     "LockSet append function test error"
     assert lockset.node_to_lock_dict[lock1.node] == lock1, \
     "LockSet append function test error"
     assert lockset.node_to_lock_dict[lock2.node] == lock2, \
     "LockSet append function test error"
Ejemplo n.º 3
0
 def test_lock_name_to_lock_set(self, data):
     """
     Test the lock_name_to_lock_set method of LockSpace
     """
     lockspace = dlm.LockSpace(config.nodelist, config.lockspace, 10, True, 100)
     for node in config.nodelist:
         node = lockspace[node]
         node.process_one_shot(data[0])
         node.process_one_shot(data[1])
     lockset = lockspace.lock_name_to_lock_set(dlm.Shot(data[0]).name)
     assert lockset.name == dlm.Shot(data[0]).name
     assert len(lockset._lock_list) == len(config.nodelist)
Ejemplo n.º 4
0
 def test_gettitem(self, node, data):
     """
     Test the __getitem__ method of Node
     """
     node["node"].process_one_shot(data[0])
     shot = dlm.Shot(data[0])
     assert node["node"][shot.name] != None,\
     "Node __getitem__ method test error"
Ejemplo n.º 5
0
 def test_contains(self, node, data):
     """
     Test the __contains__ method of Node
     """
     node["node"].process_one_shot(data[0])
     shot = dlm.Shot(data[0])
     assert shot.name in node["node"],\
     "Node __contains__ method test error"
Ejemplo n.º 6
0
def complete_lockset(data):
    """
    To get the LockSet object for net step text
    """
    lockspace = dlm.LockSpace(config.nodelist, config.lockspace, 0, False, display_len=10)
    node1 = lockspace._nodes[config.nodelist[0]]
    lock1 = dlm.Lock(node1)
    shot1 = dlm.Shot(data[0])
    shot2 = dlm.Shot(data[1])
    lock1.append(shot1)
    lock1.append(shot2)
    lockset = dlm.LockSet()
    lockset.append(lock1)
    node2 = lockspace._nodes[config.nodelist[1]]
    lock2 = dlm.Lock(node2)
    shot1 = dlm.Shot(data[3])
    shot2 = dlm.Shot(data[4])
    lock2.append(shot1)
    lock2.append(shot2)
    lockset.append(lock2)
    return lockset
Ejemplo n.º 7
0
def test_class_lock():
    """
    Test the Lock class in dlm.py
    """
    lockspace = dlm.LockSpace(config.nodelist, config.lockspace, 0, False, display_len=10)
    node = lockspace._nodes[config.nodelist[0]]
    lock = dlm.Lock(node)
    # at this time, the lock have no data
    assert not lock.name
    assert node is lock.node
    assert lockspace is lock.lock_space
    assert not lock.inode_num
    assert not lock.lock_type
    assert not lock.has_delta()
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_EX) == (0, 0, 0)
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_PR) == (0, 0, 0)
    # at this time, the lock have one shot
    shot1 = dlm.Shot(LOCKING_STATE_STR1)
    lock.append(shot1)
    assert lock.name == shot1.name
    assert node is lock.node
    assert lockspace is lock.lock_space
    assert lock.inode_num == 5
    assert lock.lock_type == 'M'
    assert not lock.has_delta()
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_EX) == (0, 0, 0)
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_PR) == (0, 0, 0)
    # at this time, the lock also have one shot, because add an useless shot
    shot0 = dlm.Shot(LOCKING_STATE_STR0)
    with pytest.raises(AssertionError):
        lock.append(shot0)
    assert lock.name == shot1.name
    assert node is lock.node
    assert lockspace is lock.lock_space
    assert lock.inode_num == 5
    assert lock.lock_type == 'M'
    assert not lock.has_delta()
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_EX) == (0, 0, 0)
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_PR) == (0, 0, 0)
Ejemplo n.º 8
0
def test_class_shot():
    """
    Test the Shot class in dlm.py
    """
    shot = dlm.Shot(LOCKING_STATE_STR1)
    assert shot.legal(), "got an ilegal shot"
    assert shot.inode_num == 5, "Shot inode number test failed"
    assert shot.lock_type == "M", "Shot lock_type test failed"

    shot = dlm.Shot(LOCKING_STATE_STR0)
    assert shot.legal(), "got an ilegal shot"
    assert shot.inode_num == 50690, "Shot inode number test failed"
    assert shot.lock_type == "N", "Shot lock_type test failed"


    assert shot.debug_ver == 4
    assert shot.name == dlm.LockName("N00000000000000050000c602")
    assert shot.l_level == '3'
    assert shot.l_flags == '0x41'
    assert shot.l_action == '0x0'
    assert shot.l_unlock_action == '0x0'
    assert shot.l_ro_holders == '0'
    assert shot.l_ex_holders == '0'
    assert shot.l_requested == '3'
    assert shot.l_blocking == '-1'
    assert shot.lvb_64B == '0x00x00x00x00x00x00x00x00x00x00x00x0'\
                           '0x00x00x00x00x00x00x00x00x00x00x00x0'\
                           '0x00x00x00x00x00x00x00x00x00x00x00x0'\
                           '0x00x00x00x00x00x00x00x00x00x00x00x0'\
                           '0x00x00x00x00x00x00x00x00x00x00x00x0'\
                           '0x00x00x00x0'
    assert shot.lock_num_prmode == '1'
    assert shot.lock_num_exmode == '0'
    assert shot.lock_num_prmode_failed == '0'
    assert shot.lock_num_exmode_failed == '0'
    assert shot.lock_total_prmode == '21937'
    assert shot.lock_total_exmode == '0'
    assert shot.lock_max_exmode == '0'
    assert shot.lock_refresh == '0'
Ejemplo n.º 9
0
 def test_process_one_shot(self, node, data):
     """
     Test the process_one_shot method of Node
     """
     node["node"].process_one_shot(data[0])
     assert len(node["node"]._locks) == 1,\
     "Node process_one_shot method test error"
     shot = dlm.Shot(data[0])
     assert node["node"]._locks[shot.name] != None,\
     "Node process_one_shot method test error"
     assert len(node["node"]._lock_space._lock_names) == 1,\
     "Node process_one_shot method test error"
     assert len(node["node"]._lock_space._lock_types) == 0,\
     "Node process_one_shot method test error"
     node["node"].process_one_shot(data[0])
     assert len(node["node"]._locks) == 1,\
     "Node process_one_shot method test error"
     assert len(node["node"]._lock_space._lock_names) == len(config.nodelist),\
     "Node process_one_shot method test error"
     assert len(node["node"]._lock_space._lock_types) == 0,\
     "Node process_one_shot method test error"
     node["node"]._lock_space.reduce_lock_name()
     assert len(node["node"]._lock_space._lock_names) == 1,\
     "LockSpace reduce_lock_name method test error"
Ejemplo n.º 10
0
def test_class_lock_2():
    """
    Test the Lock class in dlm.py use anthor method
    """
    lockspace = dlm.LockSpace(["127.0.0.1"], config.lockspace, 0, False, display_len=10)
    node = lockspace._nodes["127.0.0.1"]
    lock = dlm.Lock(node)

    # test for _lock_level_2_field in class Lock
    assert lock._lock_level_2_field(dlm.LOCK_LEVEL_EX) == ('lock_total_exmode', 'lock_num_exmode'),\
    "test _lock_level_2_field in class Lock failed"
    assert lock._lock_level_2_field(dlm.LOCK_LEVEL_PR) == ('lock_total_prmode', 'lock_num_prmode'),\
    "test _lock_level_2_field in class Lock failed"


    # at this time, the lock have no data
    assert not lock.name
    assert node is lock.node
    assert lockspace is lock.lock_space
    assert not lock.inode_num, "test __init__ in class Lock failed"
    assert not lock.lock_type, "test __init__ in class Lock failed"
    assert not lock.has_delta(), "test __init__ in class Lock failed"
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_EX) == (0, 0, 0),\
    "test __init__ in class Lock failed"
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_PR) == (0, 0, 0),\
    "test __init__ in class Lock failed"
    # at this time, the lock have one shot
    shot1 = dlm.Shot(LOCKING_STATE_STR1)
    lock.append(shot1)
    assert lock.name == shot1.name
    assert node is lock.node
    assert lockspace is lock.lock_space
    assert lock.inode_num == 5
    assert lock.lock_type == 'M'
    assert not lock.has_delta()
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_EX) == (0, 0, 0)
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_PR) == (0, 0, 0)

    # test get_key_index in class Lock
    assert lock.get_key_index() == 0

    # at this time, the lock have two shots
    shot2 = dlm.Shot(LOCKING_STATE_STR2)
    assert shot1.name == shot2.name
    lock.append(shot2)
    shot = lock._shots[-1]
    # 34      22      0       0           21278   15984   36      15      1       22484   22484
    assert shot.lock_num_prmode == '34'
    assert shot.lock_num_exmode == '22'
    assert shot.lock_num_prmode_failed == '0'
    assert shot.lock_num_exmode_failed == '0'
    assert shot.lock_total_prmode == '21278'
    assert shot.lock_total_exmode == '15984'
    assert shot.lock_max_exmode == '15'
    assert shot.lock_refresh == '1'
    total_time_field, total_num_field = lock._lock_level_2_field(dlm.LOCK_LEVEL_EX)
    assert total_time_field == 'lock_total_exmode'
    assert total_num_field == 'lock_num_exmode'
    assert lock._get_data_field_indexed(total_time_field, -1) == "15984"
    assert lock._get_data_field_indexed(total_num_field, -1) == "22"
    total_time_field, total_num_field = lock._lock_level_2_field(dlm.LOCK_LEVEL_PR)
    assert total_time_field == 'lock_total_prmode'
    assert total_num_field == 'lock_num_prmode'
    assert lock._get_data_field_indexed(total_time_field, -1) == "21278"
    assert lock._get_data_field_indexed(total_num_field, -1) == "34"
    #lock._get_latest_data_field_delta(total_time_field)
    assert lock.name == shot2.name
    assert node is lock.node
    assert lockspace is lock.lock_space
    assert lock.inode_num == 5
    assert lock.lock_type == 'M'
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_EX) == (100, 20, 5)
    assert lock.get_lock_level_info(dlm.LOCK_LEVEL_PR) == (100, 10, 10)
    assert lock.has_delta()


    # chage the order of shot1 and shot2, so the will get the negative data
    lock.append(shot2)
    lock.append(shot1)
    total_time_field, total_num_field = lock._lock_level_2_field(dlm.LOCK_LEVEL_PR)
    assert lock._get_latest_data_field_delta(total_time_field) == -100
    assert lock._get_latest_data_field_delta(total_num_field) == -10
    assert lock._get_latest_data_field_delta_abs(total_time_field) == \
           int(getattr(lock._shots[-1], total_time_field))
    assert lock._get_latest_data_field_delta_abs(total_num_field) == \
           int(getattr(lock._shots[-1], total_num_field))


    # test for _get_data_field_indexed in class Lock
    assert lock._get_data_field_indexed('lock_num_prmode', -2) == '34'
    assert lock._get_data_field_indexed('lock_total_exmode', -2) == '15984'
    assert lock._get_data_field_indexed('lock_total_exmode', -1) == '15884'
    assert lock._get_data_field_indexed('lock_total_exmode_suse', -1) == None
    assert lock._get_data_field_indexed('lock_total_exmode_suse', -2) == None
    assert lock._get_data_field_indexed('lock_total_exmode_suse', 100) == None

    # test get_key_index in class Lock
    assert lock.get_key_index() == 4412, "test get_key_index in class Lock failed"