def test():
    host = res_ops.query_resource(res_ops.HOST)[0]
    host_uuid = host.uuid
    password = "******"
    host_option = test_util.HostOption()
    host_option.set_cluster_uuid(host.clusterUuid)
    host_option.set_username(host.username)
    host_option.set_password(password)
    host_option.set_management_ip(host.managementIp)
    host_option.set_name(host.name)
    host_option.set_description(host.description)
    system_tag="pageTableExtensionDisabled"
    host_option.set_system_tags([system_tag])

    host_ops.delete_host(host_uuid)
    new_added_host = host_ops.add_kvm_host(host_option)
    time.sleep(60)
    status = host_ops.get_ept_status(host.managementIp, host.username, password, host.sshPort)
    if status != "disable":
         test_util.test_fail('Fail to add host with ept disabled')

    host_ops.delete_host(new_added_host.uuid)
    host_option.set_system_tags([])
    host_ops.add_kvm_host(host_option)
    time.sleep(60)
    status = host_ops.get_ept_status(host.managementIp, host.username, password, host.sshPort)
    if status != "enable":
         test_util.test_fail('Fail to add host with ept enabled')

    test_util.test_pass('Add Host with EPT disabled/enabled Test Success')
def test():
    global host_config
    global ps_inv
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]

    host_config.set_name(host1_name)
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_management_ip(host1.managementIp)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    test_util.test_dsc('delete host')
    host_ops.delete_host(host1.uuid)

    test_util.test_dsc('delete primary storage')
    ps_name = os.environ.get('nfsPrimaryStorageName1')
    ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name)[0]
    ps_ops.delete_primary_storage(ps_inv.uuid)

    test_util.test_dsc("Recover Primary Storage")
    recover_ps()
    test_util.test_dsc("Recover Host")
    host_ops.add_kvm_host(host_config)

    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]
    ps1 = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name)[0]

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Host and Primary Storage Test Success')
Beispiel #3
0
def test():
    global host_config
    global ps_inv
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]

    host_config.set_name(host1_name)
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_management_ip(host1.managementIp)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    test_util.test_dsc('delete host')
    host_ops.delete_host(host1.uuid)

    test_util.test_dsc('delete primary storage')
    ps_name = os.environ.get('nfsPrimaryStorageName1')
    ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name=ps_name)[0]
    ps_ops.delete_primary_storage(ps_inv.uuid)

    test_util.test_dsc("Recover Primary Storage")
    recover_ps()
    test_util.test_dsc("Recover Host")
    host_ops.add_kvm_host(host_config)

    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]
    ps1 = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name=ps_name)[0]

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Host and Primary Storage Test Success')
def error_cleanup():
    global host_config
    test_lib.lib_error_cleanup(test_obj_dict)
    if not host1:
        try:
            host_ops.add_kvm_host(host_config)
        except Exception as e:
            test_util.test_warn('Fail to recover all [host:] %s resource. It will impact later test case.' % host1_name)
            raise e
def error_cleanup():
    global host_config
    test_lib.lib_error_cleanup(test_obj_dict)
    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)
    if not host1:
        try:
            host_ops.add_kvm_host(host_config)
        except Exception as e:
            test_util.test_warn('Fail to recover all [host:] %s resource. It will impact later test case.' % host1_name)
            raise e
def add_hosts(host_ips):
    for host_ip in host_ips:
        host_option = test_tuil.HostOption()
        host_option = set_cluster_uuid()
        host_option = set_username('root')
        host_option = set_password('password')
        host_option = set_management_ip(host_ip) 
        host_option = set_name(host_ip) 
        host_ops.add_kvm_host(host_option)
    test_util.test_logger('Add KVM hosts finished')
def test():
    global host_config
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up host1
    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_host_uuid(host1.uuid)
    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)

    host_config.set_name(host1_name)
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_management_ip(host1.managementIp)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    test_util.test_dsc('delete host')
    host_ops.delete_host(host1.uuid)
    test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED)
    vm1.update()
    vm1.set_state(vm_header.STOPPED)
    vm2.update()
    vm2.set_state(vm_header.STOPPED)

    test_lib.lib_robot_status_check(test_obj_dict)

    test_util.test_dsc('start vm on other host')
    vm1.start()
    vm2.start()

    test_lib.lib_robot_status_check(test_obj_dict)

    host_ops.add_kvm_host(host_config)

    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]
    #vm_creation_option.set_host_uuid(host1.uuid)
    #vm_creation_option.set_l3_uuids([])

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Host Test Success')
def error_cleanup():
    global host_config
    test_lib.lib_error_cleanup(test_obj_dict)
    host1_name = os.environ.get('hostName')
    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]
    if not host1:
        try:
            host_ops.add_kvm_host(host_config)
        except Exception as e:
            test_util.test_warn('Fail to recover all [host:] %s resource. It will impact later test case.' % host1_name)
            raise e
def add_host_by_ip(host_ip):
    host_config = test_util.HostOption()
    host_config.set_name(host_ip)
    host_config.set_cluster_uuid(cluster[0].uuid)
    host_config.set_management_ip(host_ip)
    host_config.set_username(hostname)
    host_config.set_password(password)
    try:
        host_ops.add_kvm_host(host_config)
    except:
        exc_info.append(sys.exc_info())
Beispiel #10
0
def add_host_by_ip(host_ip):
    host_config = test_util.HostOption()
    host_config.set_name(host_ip)
    host_config.set_cluster_uuid(cluster[0].uuid)
    host_config.set_management_ip(host_ip)
    host_config.set_username(hostname)
    host_config.set_password(password)
    try:
        host_ops.add_kvm_host(host_config)
    except:
        exc_info.append(sys.exc_info())
def test():
    global host_config
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up host1
    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_host_uuid(host1.uuid)
    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)

    host_config.set_name(host1_name)
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_management_ip(host1.managementIp)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    test_util.test_dsc('delete host')
    host_ops.delete_host(host1.uuid)
    test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED)
    vm1.update()
    vm1.set_state(vm_header.STOPPED)
    vm2.update()
    vm2.set_state(vm_header.STOPPED)

    test_lib.lib_robot_status_check(test_obj_dict)

    test_util.test_dsc('start vm on other host')
    vm1.start()
    vm2.start()

    test_lib.lib_robot_status_check(test_obj_dict)

    host_ops.add_kvm_host(host_config)

    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]
    #vm_creation_option.set_host_uuid(host1.uuid)
    #vm_creation_option.set_l3_uuids([])

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Host Test Success')
def error_cleanup():
    global host_config
    global ps_inv
    test_lib.lib_error_cleanup(test_obj_dict)
    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)
    if not host1:
        try:
            test_stub.recover_ps(ps_inv)
        except Exception as e:
            test_util.test_warn('Fail to recover all primary storage %s resource. It might impact later test case.' % ps_inv.name)
        try:
            host_ops.add_kvm_host(host_config)
        except Exception as e:
            test_util.test_warn('Fail to recover all [host:] %s resource. It will impact later test case.' % host1_name)
            raise e
Beispiel #13
0
def error_cleanup():
    global host_config
    global ps_inv
    test_lib.lib_error_cleanup(test_obj_dict)
    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)
    if not host1:
        try:
            test_stub.recover_ps(ps_inv)
        except Exception as e:
            test_util.test_warn(
                'Fail to recover all primary storage %s resource. It might impact later test case.'
                % ps_inv.name)
        try:
            host_ops.add_kvm_host(host_config)
        except Exception as e:
            test_util.test_warn(
                'Fail to recover all [host:] %s resource. It will impact later test case.'
                % host1_name)
            raise e
Beispiel #14
0
def test():
    global host_config
    global ps_inv
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]

    host_config.set_name(host1_name)
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_management_ip(host1.managementIp)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    test_util.test_dsc('delete host')
    host_ops.delete_host(host1.uuid)

    test_util.test_dsc('delete primary storage')
    zone_name = os.environ.get('zoneName1')
    zone_uuid = res_ops.get_resource(res_ops.ZONE, name=zone_name)[0].uuid
    cond = res_ops.gen_query_conditions('zoneUuid', '=', zone_uuid)
    ps_inv = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0]
    if ps_inv.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
        ps_name = os.environ.get('nfsPrimaryStorageName1')
    elif ps_inv.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
        ps_name = os.environ.get('cephPrimaryStorageName1')

    ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name=ps_name)[0]
    ps_ops.delete_primary_storage(ps_inv.uuid)

    test_util.test_dsc("Recover Primary Storage")
    test_stub.recover_ps(ps_inv)
    test_util.test_dsc("Recover Host")
    host_ops.add_kvm_host(host_config)

    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]
    ps1 = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name=ps_name)[0]

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Host and Primary Storage Test Success')
def test():
    global host_config
    global ps_inv
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]

    host_config.set_name(host1_name)
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_management_ip(host1.managementIp)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    test_util.test_dsc('delete host')
    host_ops.delete_host(host1.uuid)

    test_util.test_dsc('delete primary storage')
    zone_name = os.environ.get('zoneName1')
    zone_uuid = res_ops.get_resource(res_ops.ZONE, name = zone_name)[0].uuid
    cond = res_ops.gen_query_conditions('zoneUuid', '=', zone_uuid)
    ps_inv = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0]
    if ps_inv.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
        ps_name = os.environ.get('nfsPrimaryStorageName1')
    elif ps_inv.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
        ps_name = os.environ.get('cephPrimaryStorageName1')

    ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name)[0]
    ps_ops.delete_primary_storage(ps_inv.uuid)

    test_util.test_dsc("Recover Primary Storage")
    test_stub.recover_ps(ps_inv)
    test_util.test_dsc("Recover Host")
    host_ops.add_kvm_host(host_config)

    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]
    ps1 = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name)[0]

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Host and Primary Storage Test Success')
def test():
    global host_config
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up host1
    host1_name = os.environ.get('hostName')
    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]
    host3_name = os.environ.get('hostName3')
    host3 = res_ops.get_resource(res_ops.HOST, name=host3_name)[0]

    cond = res_ops.gen_query_conditions('clusterUuid', '=', host1.clusterUuid)
    cluster_hosts = res_ops.query_resource(res_ops.HOST, cond)
    if not len(cluster_hosts) > 1:
        test_util.test_skip(
            'Skip test, since [cluster:] %s did not include more than 1 host' %
            host1.clusterUuid)

    for host in cluster_hosts:
        if host.uuid != host1.uuid:
            host2 = host

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_host_uuid(host1.uuid)

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name)[0]
    vm_creation_option.set_l3_uuids([l3.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vr_vm_inv = test_lib.lib_find_vr_by_vm(vm1.get_vm())[0]
    vr_host_uuid = vr_vm_inv.hostUuid

    #migrate vr to host3.
    if vr_host_uuid != host3.uuid:
        vm_ops.migrate_vm(vr_vm_inv.uuid, host3.uuid)

    host_config.set_cluster_uuid(host3.clusterUuid)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))
    host_config.set_name(host3_name)
    host_config.set_management_ip(host3.managementIp)
    target_host_uuid = host3.uuid

    test_util.test_dsc(
        "Delete VR VM's host. VR should be migrated to Cluster1")
    host_ops.delete_host(target_host_uuid)

    vm1.check()

    #using the same L3 to create VM2 to check if VR is working well.
    vm_creation_option.set_host_uuid(None)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    host_ops.add_kvm_host(host_config)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test VR migration when deleting Host is Success')
def test():
    host = dict()
    host['Broadwell'] = []
    host['Haswell-noTSX'] = []
    _hosts = res_ops.query_resource(res_ops.HOST)
    if len(_hosts) < 4:
        test_util.test_fail("this case need at least 4 hosts")

    for i in _hosts[:2]:
        test_stub.set_host_cpu_model(i.managementIp, model='Broadwell')
        host['Broadwell'].append(i)

    for i in _hosts[2:]:
        test_stub.set_host_cpu_model(i.managementIp, model='Haswell-noTSX')
        host['Haswell-noTSX'].append(i)

    hosts = host['Broadwell'] + host['Haswell-noTSX']
    clusters = res_ops.query_resource(res_ops.CLUSTER)
    for i in clusters:
        cls_ops.delete_cluster(i.uuid)
    clusters = []
    zone = res_ops.query_resource(res_ops.ZONE)[0]
    cluster_option = test_util.ClusterOption()
    cluster_option.set_hypervisor_type('KVM')
    cluster_option.set_zone_uuid(zone.uuid)

    cluster_option.set_name('Broadwell_1')
    cluster1 = cls_ops.create_cluster(cluster_option)
    tag_ops.create_system_tag('ClusterVO',
                              cluster1.uuid,
                              tag="clusterKVMCpuModel::Broadwell")
    clusters.append(cluster1)

    cluster_option.set_name('Broadwell_2')
    cluster2 = cls_ops.create_cluster(cluster_option)
    tag_ops.create_system_tag('ClusterVO',
                              cluster2.uuid,
                              tag="clusterKVMCpuModel::Broadwell")
    clusters.append(cluster2)

    cluster_option.set_name('Haswell-noTSX_1')
    cluster3 = cls_ops.create_cluster(cluster_option)
    tag_ops.create_system_tag('ClusterVO',
                              cluster3.uuid,
                              tag="clusterKVMCpuModel::Haswell-noTSX")
    clusters.append(cluster3)

    conditions = res_ops.gen_query_conditions('name', '=', 'vlan-test9')
    l2 = res_ops.query_resource(res_ops.L2_VLAN_NETWORK, conditions)[0]

    conditions = res_ops.gen_query_conditions('name', '=', 'l2-public')
    l2_public = res_ops.query_resource(res_ops.L2_NETWORK, conditions)[0]

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)

    _hosts = []
    for i in range(len(clusters)):
        net_ops.attach_l2(l2.uuid, clusters[i].uuid)
        net_ops.attach_l2(l2_public.uuid, clusters[i].uuid)
        for j in ps:
            ps_ops.attach_primary_storage(j.uuid, clusters[i].uuid)
        host_option = test_util.HostOption()
        host_option.set_cluster_uuid(clusters[i].uuid)
        host_option.set_username('root')
        host_option.set_password('password')
        host_option.set_name(hosts[i].managementIp)
        host_option.set_management_ip(hosts[i].managementIp)
        _hosts.append(host_ops.add_kvm_host(host_option))

    # test
    host_option = test_util.HostOption()
    host_option.set_cluster_uuid(clusters[0].uuid)
    host_option.set_username('root')
    host_option.set_password('password')
    host_option.set_name(hosts[3].managementIp)
    host_option.set_management_ip(hosts[3].managementIp)
    try:
        _hosts.append(host_ops.add_kvm_host(host_option))
    except Exception as e:
        test_util.test_logger(e)

    host_option.set_cluster_uuid(clusters[2].uuid)
    try:
        _hosts.append(host_ops.add_kvm_host(host_option))
    except Exception as e:
        test_util.test_fail("test cluster cpu model faild")

    # migrate vm
    conditions = res_ops.gen_query_conditions('name', '=', 'ttylinux')
    img = res_ops.query_resource(res_ops.IMAGE, conditions)[0]
    ins = res_ops.query_resource(res_ops.INSTANCE_OFFERING)[0]
    conditions = res_ops.gen_query_conditions('name', '=', 'l3VlanNetwork9')
    l3 = res_ops.query_resource(res_ops.L3_NETWORK, conditions)[0]

    vms = []
    for i in [0, 2]:
        vm_option = test_util.VmOption()
        vm_option.set_name("vm")
        vm_option.set_image_uuid(img.uuid)
        vm_option.set_cluster_uuid(clusters[i].uuid)
        vm_option.set_host_uuid(_hosts[i].uuid)
        vm_option.set_instance_offering_uuid(ins.uuid)
        vm_option.set_l3_uuids([l3.uuid])
        vm_option.set_default_l3_uuid(l3.uuid)
        vms.append(vm_ops.create_vm(vm_option))

    time.sleep(20)
    try:
        vm_ops.migrate_vm(vms[0].uuid, _hosts[1].uuid)
    except Exception as e:
        test_util.test_fail(e)

    try:
        vm_ops.migrate_vm(vms[1].uuid, _hosts[1].uuid)
    except Exception as e:
        test_util.test_logger(e)

    test_util.test_pass("test cluster cpu model pass")
 def add(self):
     self.host = host_ops.add_kvm_host(self.host_creation_option)
     super(ZstackTestKvmHost, self).create()
def test():
    global host_config
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up host1
    host1_name = os.environ.get('hostName')
    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]

    cond = res_ops.gen_query_conditions('clusterUuid', '=', host1.clusterUuid)
    cluster_hosts = res_ops.query_resource(res_ops.HOST, cond)
    if not len(cluster_hosts) > 1:
        test_util.test_skip(
            'Skip test, since [cluster:] %s did not include more than 1 host' %
            host1.clusterUuid)

    for host in cluster_hosts:
        if host.uuid != host1.uuid:
            host2 = host

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_host_uuid(host1.uuid)

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name)[0]
    vm_creation_option.set_l3_uuids([l3.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vr_vm_inv = test_lib.lib_find_vr_by_vm(vm1.get_vm())[0]
    vr_host_uuid = vr_vm_inv.hostUuid
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    if vr_host_uuid != host1.uuid:
        vr_host_inv = res_ops.get_resource(res_ops.HOST, uuid=vr_host_uuid)[0]
        host_config.set_name(vr_host_inv.name)
        host_config.set_management_ip(vr_host_inv.managementIp)
        target_host_uuid = vr_host_inv.uuid
    else:
        host_config.set_name(host1_name)
        host_config.set_management_ip(host1.managementIp)
        target_host_uuid = host1.uuid

    test_util.test_dsc("Delete VR VM's host")
    host_ops.delete_host(target_host_uuid)
    if vr_host_uuid == host1.uuid:
        #if the deleted Host is VM1's host, need to restart VM1.
        test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
        test_util.test_dsc('start vm on other host')
        vm1.start()

    vm1.check()

    #using the same L3 to create VM2 to check if VR is working well.
    vm_creation_option.set_host_uuid(None)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    vm1.reboot()
    vm1.check()

    host_ops.add_kvm_host(host_config)

    #update host1, since it is re-added again.
    host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0]
    test_util.test_dsc('Create new VM on new added Host')
    vm_creation_option.set_host_uuid(host1.uuid)
    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)
    vm3.check()

    #test_util.test_dsc('Delete VR Host again')
    #vr_new_inv = res_ops.get_resource(res_ops.VM_INSTANCE, \
    #        uuid = vr_vm_inv.uuid)[0]
    #vr_new_host_uuid = vr_new_inv.hostUuid
    #vr_new_host = res_ops.get_resource(res_ops.HOST, uuid = vr_new_host_uuid)[0]

    #host_config.set_name(vr_new_host.name)
    #host_config.set_management_ip(vr_new_host.managementIp)

    #host_ops.delete_host(target_host_uuid)
    #if vm1.get_vm().hostUuid == vr_new_host_uuid:
    #    test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    #    test_util.test_dsc('start vm on another host')
    #    vm1.start()

    #vm1.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test VR migration when deleting Host is Success')
def test():
    host = dict()
    host['Broadwell'] = []
    host['Haswell-noTSX'] = []
    _hosts = res_ops.query_resource(res_ops.HOST)
    if len(_hosts) < 4:
        test_util.test_fail("this case need at least 4 hosts")

    for i in _hosts[:2]:
        test_stub.set_host_cpu_model(i.managementIp, model='Broadwell')
        host['Broadwell'].append(i)

    for i in _hosts[2:]:
        test_stub.set_host_cpu_model(i.managementIp, model='Haswell-noTSX')
        host['Haswell-noTSX'].append(i)

    hosts = host['Broadwell'] + host['Haswell-noTSX']
    clusters = res_ops.query_resource(res_ops.CLUSTER)
    for i in clusters:
        cls_ops.delete_cluster(i.uuid)
    clusters = []
    zone = res_ops.query_resource(res_ops.ZONE)[0]
    cluster_option = test_util.ClusterOption()
    cluster_option.set_hypervisor_type('KVM')
    cluster_option.set_zone_uuid(zone.uuid)

    cluster_option.set_name('Broadwell_1')
    cluster1 = cls_ops.create_cluster(cluster_option)
    tag_ops.create_system_tag('ClusterVO',cluster1.uuid,tag="clusterKVMCpuModel::Broadwell")
    clusters.append(cluster1)

    cluster_option.set_name('Broadwell_2')
    cluster2 = cls_ops.create_cluster(cluster_option)
    tag_ops.create_system_tag('ClusterVO',cluster2.uuid,tag="clusterKVMCpuModel::Broadwell")
    clusters.append(cluster2)

    cluster_option.set_name('Haswell-noTSX_1')
    cluster3 = cls_ops.create_cluster(cluster_option)
    tag_ops.create_system_tag('ClusterVO',cluster3.uuid,tag="clusterKVMCpuModel::Haswell-noTSX")
    clusters.append(cluster3)

    conditions = res_ops.gen_query_conditions('name', '=', 'vlan-test9')
    l2 = res_ops.query_resource(res_ops.L2_VLAN_NETWORK, conditions)[0]

    conditions = res_ops.gen_query_conditions('name', '=', 'l2-public')
    l2_public = res_ops.query_resource(res_ops.L2_NETWORK, conditions)[0]

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)


    _hosts = []
    for i in range(len(clusters)):
        net_ops.attach_l2(l2.uuid, clusters[i].uuid)
        net_ops.attach_l2(l2_public.uuid, clusters[i].uuid)
        for j in ps:
            ps_ops.attach_primary_storage(j.uuid, clusters[i].uuid)
        host_option = test_util.HostOption()
        host_option.set_cluster_uuid(clusters[i].uuid)
        host_option.set_username('root')
        host_option.set_password('password')
        host_option.set_name(hosts[i].managementIp)
        host_option.set_management_ip(hosts[i].managementIp)
        _hosts.append(host_ops.add_kvm_host(host_option))

    # test
    host_option = test_util.HostOption()
    host_option.set_cluster_uuid(clusters[0].uuid)
    host_option.set_username('root')
    host_option.set_password('password')
    host_option.set_name(hosts[3].managementIp)
    host_option.set_management_ip(hosts[3].managementIp)
    try:
        _hosts.append(host_ops.add_kvm_host(host_option))
    except Exception as e:
        test_util.test_logger(e)

    cond = res_ops.gen_query_conditions('name', '=', hosts[3].managementIp)
    host_uuid = res_ops.query_resource(res_ops.HOST, cond)[0].uuid
    host_ops.delete_host(host_uuid)
    host_option.set_cluster_uuid(clusters[2].uuid)
    try:
        _hosts.append(host_ops.add_kvm_host(host_option))
    except Exception as e:
        test_util.test_fail("test cluster cpu model faild")

    # migrate vm
    conditions = res_ops.gen_query_conditions('name', '=', 'ttylinux')
    img = res_ops.query_resource(res_ops.IMAGE, conditions)[0]
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    ins = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0]
    conditions = res_ops.gen_query_conditions('name', '=', 'public network')
    l3 = res_ops.query_resource(res_ops.L3_NETWORK, conditions)[0]


    vms = []
    for i in [0,2]:
        vm_option = test_util.VmOption()
        vm_option.set_name("vm")
        vm_option.set_image_uuid(img.uuid)
        vm_option.set_cluster_uuid(clusters[i].uuid)
        vm_option.set_host_uuid(_hosts[i].uuid)
        vm_option.set_instance_offering_uuid(ins.uuid)
        vm_option.set_l3_uuids([l3.uuid])
        vm_option.set_default_l3_uuid(l3.uuid)
        vms.append(vm_ops.create_vm(vm_option))

    time.sleep(20)
    try:
        vm_ops.migrate_vm(vms[0].uuid, _hosts[1].uuid)
    except Exception as e:
        test_util.test_fail(e)

    try:
        vm_ops.migrate_vm(vms[1].uuid, _hosts[1].uuid)
    except Exception as e:
        test_util.test_logger(e)

    test_util.test_pass("test cluster cpu model pass")
 def add(self):
     self.host = host_ops.add_kvm_host(self.host_creation_option)
     super(ZstackTestKvmHost, self).create()
def test():
    global host_config
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up host1
    host1_name = os.environ.get('hostName')
    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]

    cond = res_ops.gen_query_conditions('clusterUuid', '=', host1.clusterUuid)
    cluster_hosts = res_ops.query_resource(res_ops.HOST, cond)
    if not len(cluster_hosts) > 1:
        test_util.test_skip('Skip test, since [cluster:] %s did not include more than 1 host' % host1.clusterUuid)

    for host in cluster_hosts:
        if host.uuid != host1.uuid:
            host2 = host

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_host_uuid(host1.uuid)

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0]
    vm_creation_option.set_l3_uuids([l3.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vr_vm_inv = test_lib.lib_find_vr_by_vm(vm1.get_vm())[0]
    vr_host_uuid = vr_vm_inv.hostUuid
    host_config.set_cluster_uuid(host1.clusterUuid)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))

    if vr_host_uuid != host1.uuid:
        vr_host_inv = res_ops.get_resource(res_ops.HOST, uuid = vr_host_uuid)[0]
        host_config.set_name(vr_host_inv.name)
        host_config.set_management_ip(vr_host_inv.managementIp)
        target_host_uuid = vr_host_inv.uuid
    else:
        host_config.set_name(host1_name)
        host_config.set_management_ip(host1.managementIp)
        target_host_uuid = host1.uuid

    test_util.test_dsc("Delete VR VM's host")
    host_ops.delete_host(target_host_uuid)
    if vr_host_uuid == host1.uuid:
        #if the deleted Host is VM1's host, need to restart VM1. 
        test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
        test_util.test_dsc('start vm on other host')
        vm1.start()

    vm1.check()

    #using the same L3 to create VM2 to check if VR is working well.
    vm_creation_option.set_host_uuid(None)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    vm1.reboot()
    vm1.check()

    host_ops.add_kvm_host(host_config)

    #update host1, since it is re-added again.
    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]
    test_util.test_dsc('Create new VM on new added Host')
    vm_creation_option.set_host_uuid(host1.uuid)
    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)
    vm3.check()

    #test_util.test_dsc('Delete VR Host again')
    #vr_new_inv = res_ops.get_resource(res_ops.VM_INSTANCE, \
    #        uuid = vr_vm_inv.uuid)[0]
    #vr_new_host_uuid = vr_new_inv.hostUuid
    #vr_new_host = res_ops.get_resource(res_ops.HOST, uuid = vr_new_host_uuid)[0]

    #host_config.set_name(vr_new_host.name)
    #host_config.set_management_ip(vr_new_host.managementIp)

    #host_ops.delete_host(target_host_uuid)
    #if vm1.get_vm().hostUuid == vr_new_host_uuid:
    #    test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    #    test_util.test_dsc('start vm on another host')
    #    vm1.start()

    #vm1.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test VR migration when deleting Host is Success')
def test():
    global host_config
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up host1
    host1_name = os.environ.get('hostName')
    host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0]
    host3_name = os.environ.get('hostName3')
    host3 = res_ops.get_resource(res_ops.HOST, name = host3_name)[0]

    cond = res_ops.gen_query_conditions('clusterUuid', '=', host1.clusterUuid)
    cluster_hosts = res_ops.query_resource(res_ops.HOST, cond)
    if not len(cluster_hosts) > 1:
        test_util.test_skip('Skip test, since [cluster:] %s did not include more than 1 host' % host1.clusterUuid)

    for host in cluster_hosts:
        if host.uuid != host1.uuid:
            host2 = host

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_host_uuid(host1.uuid)

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0]
    vm_creation_option.set_l3_uuids([l3.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vr_vm_inv = test_lib.lib_find_vr_by_vm(vm1.get_vm())[0]
    vr_host_uuid = vr_vm_inv.hostUuid

    #migrate vr to host3.
    if vr_host_uuid != host3.uuid:
        vm_ops.migrate_vm(vr_vm_inv.uuid, host3.uuid)


    host_config.set_cluster_uuid(host3.clusterUuid)
    host_config.set_username(os.environ.get('hostUsername'))
    host_config.set_password(os.environ.get('hostPassword'))
    host_config.set_name(host3_name)
    host_config.set_management_ip(host3.managementIp)
    target_host_uuid = host3.uuid

    test_util.test_dsc("Delete VR VM's host. VR should be migrated to Cluster1")
    host_ops.delete_host(target_host_uuid)

    vm1.check()

    #using the same L3 to create VM2 to check if VR is working well.
    vm_creation_option.set_host_uuid(None)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    host_ops.add_kvm_host(host_config)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test VR migration when deleting Host is Success')