def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h1[0].uuid)
    assert vm1.get_vm().hostUuid == h1[0].uuid
    test_obj_dict.add_vm(vm1)

    h2_name = os.environ.get("hostName2")
    cond = res_ops.gen_query_conditions('name', '=', h2_name)
    h2 = res_ops.query_resource(res_ops.HOST, cond)
    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h2[0].uuid)
    assert vm2.get_vm().hostUuid == h2[0].uuid
    test_obj_dict.add_vm(vm2)

    try:
        vm1.migrate(vm2.get_vm().hostUuid)
    except:
        test_util.test_logger("vm1 is not expected to migrate to host2 [uuid: %s]" % vm2.get_vm().hostUuid)

    h3_name = os.environ.get("hostName3")
    cond = res_ops.gen_query_conditions('name', '=', h3_name)
    h3 = res_ops.query_resource(res_ops.HOST, cond)

    vm1.migrate(h3[0].uuid)
    vm1.migrate(h1[0].uuid)

    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h1[0].uuid)
    assert vm1.get_vm().hostUuid == h1[0].uuid
    test_obj_dict.add_vm(vm1)

    h2_name = os.environ.get("hostName2")
    cond = res_ops.gen_query_conditions('name', '=', h2_name)
    h2 = res_ops.query_resource(res_ops.HOST, cond)
    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h2[0].uuid)
    assert vm2.get_vm().hostUuid == h2[0].uuid
    test_obj_dict.add_vm(vm2)

    try:
        vm3 = None
        vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h2[0].uuid)
    except:
        if not vm3:
            test_util.test_logger("vm3 isn't created as expected")
    finally:
        if vm3:
            test_util.test_fail("Test Fail, vm3 [uuid:%s] is not expected to be created" % vm3.get_vm().uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(host_uuid=h1[0].uuid)
    assert vm1.get_vm().hostUuid == h1[0].uuid
    test_obj_dict.add_vm(vm1)

    new_vm = vm1.clone(names=["clone-vm1", "clone-vm2", "clone-vm3"], systemtag=["affinityGroupUuid::%s" % ag1.uuid])
    test_obj_dict.add_vm(new_vm[0])
    test_obj_dict.add_vm(new_vm[1])
    test_obj_dict.add_vm(new_vm[2])
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert new_vm[0].get_vm().uuid in vmuuids
    assert new_vm[1].get_vm().uuid in vmuuids
    assert new_vm[2].get_vm().uuid in vmuuids
    assert len(vmuuids) == 3
    
    try:
        ag_ops.add_vm_to_affinity_group(ag1.uuid, vm1.get_vm().uuid) 
    except:
        test_util.test_logger("vm1 is not expected to add into affinity group [uuid: %s]" % ag1.uuid)
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert vm1.get_vm().uuid not in vmuuids
 
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
Esempio n. 4
0
def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid,
                                 host_uuid=h1[0].uuid)
    assert vm1.get_vm().hostUuid == h1[0].uuid
    test_obj_dict.add_vm(vm1)

    h2_name = os.environ.get("hostName2")
    cond = res_ops.gen_query_conditions('name', '=', h2_name)
    h2 = res_ops.query_resource(res_ops.HOST, cond)
    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid,
                                 host_uuid=h2[0].uuid)
    assert vm2.get_vm().hostUuid == h2[0].uuid
    test_obj_dict.add_vm(vm2)

    try:
        vm1.migrate(vm2.get_vm().hostUuid)
    except:
        test_util.test_logger(
            "vm1 is not expected to migrate to host2 [uuid: %s]" %
            vm2.get_vm().hostUuid)

    h3_name = os.environ.get("hostName3")
    cond = res_ops.gen_query_conditions('name', '=', h3_name)
    h3 = res_ops.query_resource(res_ops.HOST, cond)

    vm1.migrate(h3[0].uuid)
    vm1.migrate(h1[0].uuid)

    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm1)

    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm2)
    assert vm1.get_vm().hostUuid != vm2.get_vm().hostUuid
  
    vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm3)
    assert vm1.get_vm().hostUuid != vm3.get_vm().hostUuid
    assert vm2.get_vm().hostUuid != vm3.get_vm().hostUuid

    vm2.stop()
  
    vm4 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm4)
    assert vm2.get_vm().hostUuid != vm1.get_vm().hostUuid
    assert vm2.get_vm().hostUuid != vm3.get_vm().hostUuid

    try:
        vm2.start()
    except:
        test_util.test_logger("vm2 isn't started as expected")
    finally:
        if vm2.state == 'Running':
            test_util.test_fail("Test Fail, vm2 [uuid:%s] is not expected to be started" % vm2.get_vm().uuid)
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")

    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid,
                                 host_uuid=h1[0].uuid)
    assert vm1.get_vm().hostUuid == h1[0].uuid
    test_obj_dict.add_vm(vm1)

    h2_name = os.environ.get("hostName2")
    cond = res_ops.gen_query_conditions('name', '=', h2_name)
    h2 = res_ops.query_resource(res_ops.HOST, cond)
    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid,
                                 host_uuid=h2[0].uuid)
    assert vm2.get_vm().hostUuid == h2[0].uuid
    test_obj_dict.add_vm(vm2)

    try:
        vm3 = None
        vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid,
                                     host_uuid=h2[0].uuid)
    except:
        if not vm3:
            test_util.test_logger("vm3 isn't created as expected")
    finally:
        if vm3:
            test_util.test_fail(
                "Test Fail, vm3 [uuid:%s] is not expected to be created" %
                vm3.get_vm().uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm1)

    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm2)
    assert vm1.get_vm().hostUuid != vm2.get_vm().hostUuid
  
    vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm3)
    assert vm1.get_vm().hostUuid != vm3.get_vm().hostUuid
    assert vm2.get_vm().hostUuid != vm3.get_vm().hostUuid

    try:
        vm4 = None
        vm4 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    except:
        if not vm4:
            test_util.test_logger("vm4 isn't created as expected")
    finally:
        if vm4:
            test_util.test_fail("Test Fail, vm4 [uuid:%s] is not expected to be created" % vm4.get_vm().uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
Esempio n. 8
0
def error_cleanup():
    test_lib.lib_error_cleanup(test_obj_dict)
    if affinity_group_inv:
        ag_ops.delete_affinity_group(affinity_group_inv[0].uuid)
    if project_uuid:
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)
    if project_operator_uuid:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(host_uuid=h1[0].uuid)
    assert vm1.get_vm().hostUuid == h1[0].uuid
    test_obj_dict.add_vm(vm1)

    h2_name = os.environ.get("hostName2")
    cond = res_ops.gen_query_conditions('name', '=', h2_name)
    h2 = res_ops.query_resource(res_ops.HOST, cond)
    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid,
                                 host_uuid=h2[0].uuid)
    assert vm2.get_vm().hostUuid == h2[0].uuid
    test_obj_dict.add_vm(vm2)

    h3_name = os.environ.get("hostName3")
    cond = res_ops.gen_query_conditions('name', '=', h3_name)
    h3 = res_ops.query_resource(res_ops.HOST, cond)
    vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid,
                                 host_uuid=h3[0].uuid)
    assert vm3.get_vm().hostUuid == h3[0].uuid
    test_obj_dict.add_vm(vm3)

    new_vm = vm3.clone(names=["clone-vm"],
                       systemtag=["affinityGroupUuid::%s" % ag1.uuid])
    assert new_vm[0].get_vm().hostUuid == h1[0].uuid
    test_obj_dict.add_vm(new_vm[0])

    try:
        ag_ops.add_vm_to_affinity_group(ag1.uuid, vm1.get_vm().uuid)
    except:
        test_util.test_logger(
            "vm1 is not expected to add into affinity group [uuid: %s]" %
            ag1.uuid)
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert vm1.get_vm().uuid not in vmuuids

    ag_ops.remove_vm_from_affinity_group(affinityGroupUuid=ag1.uuid,
                                         vm_uuid=new_vm[0].get_vm().uuid)
    ag_ops.add_vm_to_affinity_group(ag1.uuid, vm1.get_vm().uuid)
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert vm1.get_vm().uuid in vmuuids

    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm1)

    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm2)
    assert vm1.get_vm().hostUuid != vm2.get_vm().hostUuid

    vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm3)
    assert vm1.get_vm().hostUuid != vm3.get_vm().hostUuid
    assert vm2.get_vm().hostUuid != vm3.get_vm().hostUuid

    try:
        vm4 = None
        vm4 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    except:
        if not vm4:
            test_util.test_logger("vm4 isn't created as expected")
    finally:
        if vm4:
            test_util.test_fail(
                "Test Fail, vm4 [uuid:%s] is not expected to be created" %
                vm4.get_vm().uuid)
    vm1.destroy()
    vm1.expunge()
    vm4 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm4)
    assert vm4.get_vm().hostUuid != vm2.get_vm().hostUuid
    assert vm4.get_vm().hostUuid != vm3.get_vm().hostUuid
    vmuuids = []
    #vm2.stop()
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert vm2.get_vm().uuid in vmuuids

    try:
        vm5 = None
        vm5 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    except:
        if not vm5:
            test_util.test_logger("vm5 isn't created as expected")
    finally:
        if vm5:
            test_util.test_fail(
                "Test Fail, vm5 [uuid:%s] is not expected to be created" %
                vm5.uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm1)
    vm2 = test_stub.create_ag_vm(host_uuid=vm1.get_vm().hostUuid)
    test_obj_dict.add_vm(vm2)
    assert vm2.get_vm().hostUuid == vm1.get_vm().hostUuid
    vm2.stop()
    ag_ops.add_vm_to_affinity_group(ag1.uuid, vm2.get_vm().uuid)
    vm2.start()
    assert vm2.get_vm().hostUuid != vm1.get_vm().hostUuid
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(host_uuid=h1[0].uuid)
    assert vm1.get_vm().hostUuid == h1[0].uuid
    ag_ops.add_vm_to_affinity_group(ag1.uuid, vm1.get_vm().uuid)
    test_obj_dict.add_vm(vm1)

    h2_name = os.environ.get("hostName2")
    cond = res_ops.gen_query_conditions('name', '=', h2_name)
    h2 = res_ops.query_resource(res_ops.HOST, cond)
    vm2 = test_stub.create_ag_vm(host_uuid=h2[0].uuid)
    assert vm2.get_vm().hostUuid == h2[0].uuid
    ag_ops.add_vm_to_affinity_group(ag1.uuid, vm2.get_vm().uuid)
    test_obj_dict.add_vm(vm2)

    h3_name = os.environ.get("hostName3")
    cond = res_ops.gen_query_conditions('name', '=', h3_name)
    h3 = res_ops.query_resource(res_ops.HOST, cond)
    vm3 = test_stub.create_ag_vm(host_uuid=h3[0].uuid)
    assert vm3.get_vm().hostUuid == h3[0].uuid
    ag_ops.add_vm_to_affinity_group(ag1.uuid, vm3.get_vm().uuid)
    test_obj_dict.add_vm(vm3)

    vm4 = test_stub.create_ag_vm(host_uuid=h1[0].uuid)
    test_obj_dict.add_vm(vm4)

    try:
        ag_ops.add_vm_to_affinity_group(ag1.uuid, vm4.get_vm().uuid) 
    except:
        test_util.test_logger("vm4 is not expected to add into affinity group [uuid: %s]" % ag1.uuid)
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert vm4.get_vm().uuid not in vmuuids
 
    ag_ops.remove_vm_from_affinity_group(affinityGroupUuid=ag1.uuid, vm_uuid=vm1.get_vm().uuid)
    ag_ops.add_vm_to_affinity_group(ag1.uuid, vm4.get_vm().uuid)
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert vm4.get_vm().uuid in vmuuids

    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm1)
    vm2 = test_stub.create_ag_vm(host_uuid=vm1.get_vm().hostUuid)
    test_obj_dict.add_vm(vm2)
    assert vm2.get_vm().hostUuid == vm1.get_vm().hostUuid
    vm2.stop()
    ag_ops.add_vm_to_affinity_group(ag1.uuid, vm2.get_vm().uuid)
    vm2.start()
    assert vm2.get_vm().hostUuid != vm1.get_vm().hostUuid
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    h1_name = os.environ.get("hostName")
    cond = res_ops.gen_query_conditions('name', '=', h1_name)
    h1 = res_ops.query_resource(res_ops.HOST, cond)
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h1[0].uuid)
    test_obj_dict.add_vm(vm1)

    vm1.stop()
    
    hosts = vm_ops.get_vm_starting_candidate(vm1.get_vm().uuid, systemtag=["affinityGroupUuid::%s" % ag1.uuid])
    assert len(hosts) == 3
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm1)

    vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm2)
    assert vm1.get_vm().hostUuid != vm2.get_vm().hostUuid
  
    vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm3)
    assert vm1.get_vm().hostUuid != vm3.get_vm().hostUuid
    assert vm2.get_vm().hostUuid != vm3.get_vm().hostUuid

    try:
        vm4 = None
        vm4 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    except:
        if not vm4:
            test_util.test_logger("vm4 isn't created as expected")
    finally:
        if vm4:
            test_util.test_fail("Test Fail, vm4 [uuid:%s] is not expected to be created" % vm4.get_vm().uuid)
    vm1.destroy()
    vm1.expunge()
    vm4 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    test_obj_dict.add_vm(vm4)
    assert vm4.get_vm().hostUuid != vm2.get_vm().hostUuid
    assert vm4.get_vm().hostUuid != vm3.get_vm().hostUuid
    vmuuids = []
    #vm2.stop()
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    assert vm2.get_vm().uuid in vmuuids       

    try:
        vm5 = None
        vm5 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid)
    except:
        if not vm5:
            test_util.test_logger("vm5 isn't created as expected")
    finally:
        if vm5:
            test_util.test_fail("Test Fail, vm5 [uuid:%s] is not expected to be created" % vm5.uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    for i in range(5):
        t = threading.Thread(target=create_vm, args=(ag1.uuid,))
        t.start()
    time.sleep(5)
    check_exception(2)
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    test_util.test_logger("czhou %s" % vmuuids[0])
    assert len(vmuuids) == 3

    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")
def test():
    ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard")
    for i in range(3):
        t = threading.Thread(target=create_vm, args=(ag1.uuid, ))
        t.start()
    time.sleep(5)
    check_exception(0)
    vmuuids = []
    ag = test_lib.lib_get_affinity_group_by_name(name="ag1")
    for usage in ag.usages:
        vmuuids.append(usage.resourceUuid)
    test_util.test_logger("czhou %s" % vmuuids[0])
    assert len(vmuuids) == 3

    test_lib.lib_error_cleanup(test_obj_dict)
    ag_ops.delete_affinity_group(ag1.uuid)
    test_util.test_pass("Affinity Group antiHard policy pass")