def test():
    global l2_net_uuid
    global cluster_uuid
    global vm
    cluster1 = res_ops.get_resource(res_ops.CLUSTER)[0]
    cluster2 = res_ops.get_resource(res_ops.CLUSTER)[1]
    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
    l3_name = os.environ.get('l3VlanNetworkName1')

    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    l2_net_uuid = test_lib.lib_get_l3_by_name(l3_name).l2NetworkUuid
    l2_net_type = res_ops.get_resource(res_ops.L2_NETWORK, uuid=l2_net_uuid)[0].type

    test_util.test_logger("l2_network.type@@:%s" %(l2_net_type))
    if l2_net_type == "VxlanNetwork":
        test_util.test_skip("Vxlan network not support detach l2 network, therefore, skip the test")

    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_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_cluster_uuid(cluster1.uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multicluster_basic_vm')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()

    vm2 = test_vm_header.ZstackTestVm()
    vm_creation_option.set_cluster_uuid(cluster2.uuid)
    vm2.set_creation_option(vm_creation_option)
    vm2.create()
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    if len(vrs) == 0:
        test_util.test_skip("skip the test for non vr")
    vr = vrs[0]
    cluster_uuid = vr.clusterUuid
    net_ops.detach_l2(l2_net_uuid, cluster_uuid)
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    if len(vrs) == 0:
        test_util.test_skip("skip the test for non vr")
    vr = vrs[0]
    if vr.clusterUuid == cluster_uuid:
        test_util.test_logger('vr is expected to migrate to another cluster')
    vm.destroy()
    vm2.destroy()
    net_ops.attach_l2(l2_net_uuid, cluster_uuid)
    test_util.test_pass('Create detach l2 from clsuter vr migrate Test Success')
def test():

    # create l3 network
    global l3, l2

    name = 'mini_network_test'
    test_util.test_dsc('create L2_vlan network mini_l2_network_test')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER)[0].uuid
    l2 = net_ops.create_l2_vlan('l2_vlan', 'zsn0', zone_uuid, '1998')
    l2_uuid = l2.inventory.uuid
    net_ops.attach_l2(l2_uuid, cluster_uuid)

    type='L3BasicNetwork'
    categry='Private'
    l3=net_ops.create_l3(name, l2_uuid, category=categry, Type=type)

    # add dns to l3 network
    l3_dns = '223.5.5.5'
    net_ops.add_dns_to_l3(l3.uuid, l3_dns)
    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')

    # add ip range to l3 network
    ip_range_option = test_util.IpRangeOption()
    ip_range_option.set_l3_uuid(l3.uuid)
    ip_range_option.set_startIp('192.168.40.2')
    ip_range_option.set_endIp('192.168.40.20')
    ip_range_option.set_gateway('192.168.40.1')
    ip_range_option.set_netmask('255.255.255.0')
    ip_range_option.set_name('ip_range_test')

    net_ops.add_ip_range(ip_range_option)

    #attach network service to l3 network
    cond = res_ops.gen_query_conditions('type', '=', 'flat')
    provider1_uuid = res_ops.query_resource(res_ops.NETWORK_SERVICE_PROVIDER, cond)[0].uuid
    cond = res_ops.gen_query_conditions('type', '=', 'SecurityGroup')
    provider2_uuid = res_ops.query_resource(res_ops.NETWORK_SERVICE_PROVIDER, cond)[0].uuid
    providers = {provider1_uuid:['DHCP','Eip'], provider2_uuid:['SecurityGroup']}
    attach_network_service_to_l3network(l3.uuid, providers)
    test_util.test_dsc('a network with dns, ip range and network services has been created successfully')
    net_ops.delete_l3(l3.uuid)
    net_ops.delete_l2(l2_uuid)
    test_util.test_dsc('delete l3 network after test')
Esempio n. 3
0
def error_cleanup():
    global l2_net_uuid
    global cluster_uuid

    try:
        net_ops.attach_l2(l2_net_uuid, cluster_uuid)
    except:
        pass
    #time.sleep(5)
    global vm
    if vm:
        try:
            vm.destroy()
        except:
            pass
    global vm2
    if vm2:
        try:
            vm2.destroy()
        except:
            pass
def error_cleanup():
    global l2_net_uuid
    global cluster_uuid

    try:
        net_ops.attach_l2(l2_net_uuid, cluster_uuid)
    except:
        pass
    #time.sleep(5)
    global vm
    if vm:
        try:
            vm.destroy()
        except:
            pass
    global vm2
    if vm2:
        try:
            vm2.destroy()
        except:
            pass
def test():
    test_util.test_dsc('Create Baremetal Cluster')
    global cluster_uuid
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = test_stub.create_cluster(zone_uuid).uuid

    test_util.test_dsc('Attach l3 Network to Baremetal Cluster')
    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3NoVlanNetworkName1'))
    l3_network = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0]
    cidr = l3_network.ipRanges[0].networkCidr
    cond = res_ops.gen_query_conditions('l3Network.uuid', '=', l3_network.uuid)
    l2_uuid = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    sys_tags = "l2NetworkUuid::%s::clusterUuid::%s::cidr::{%s}" %(l2_uuid, cluster_uuid, cidr)
    net_ops.attach_l2(l2_uuid, cluster_uuid, [sys_tags])
    cond = res_ops.gen_query_conditions('attachedClusterUuids', '=', cluster_uuid)
    attatched_networks = res_ops.query_resource(res_ops.L2_NETWORK, cond)

    test_util.test_dsc('Check if the L3 Network is attached on Baremetal Cluster')
    net_attached = False
    for net in attatched_networks:
        if net.uuid == l2_uuid:
            net_attached = True
    if net_attached == False:
        test_util.test_fail('Attach L2 to Baremetal Cluster Failed')

    net_ops.detach_l2(l2_uuid, cluster_uuid)    

    test_util.test_dsc('Check disable/enable Baremetal Cluster')
    cluster_ops.change_cluster_state(cluster_uuid, 'disable')
    cond = res_ops.gen_query_conditions('uuid', '=', cluster_uuid)
    if res_ops.query_resource(res_ops.CLUSTER, cond)[0].state != 'Disabled':
        test_util.test_fail('Fail to disable Baremetal Cluster') 
    cluster_ops.change_cluster_state(cluster_uuid, 'enable')
    if res_ops.query_resource(res_ops.CLUSTER, cond)[0].state != 'Enabled':
        test_util.test_fail('Fail to enable Baremetal Cluster')

    cluster_ops.delete_cluster(cluster_uuid)
    test_util.test_pass('Test Baremetal Cluster Test 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 test():
    global cluster_uuid
    global l2_uuid
    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 l3
    l3_1 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name1)[0]
    l3_2 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name2)[0]
    
    l2_2 = res_ops.get_resource(res_ops.L2_NETWORK, \
            uuid = l3_2.l2NetworkUuid)[0]

    l2_uuid = l2_2.uuid

    all_attached_clusters = l2_2.attachedClusterUuids
    l2_name2 = l2_2.name

    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_l3_uuids([l3_1.uuid, l3_2.uuid])

    cluster1_name = os.environ.get('clusterName2')
    cluster1 = res_ops.get_resource(res_ops.CLUSTER, name = cluster1_name)[0]
    cluster_uuid = cluster1.uuid
    vm_creation_option.set_cluster_uuid(cluster_uuid)

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

    net_ops.detach_l2(l2_uuid, cluster_uuid)
    test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    vm1.update()
    vm1.set_state(vm_header.STOPPED)

    check_detach_l2(cluster_uuid, l2_uuid, vm1, True)
    #for num in range(len(all_attached_clusters)):
    #    curr_cluster_uuid = vm1.get_vm().clusterUuid
    #
    #    test_util.test_dsc('Detach l2_2')
    #    net_ops.detach_l2(l2_uuid, curr_cluster_uuid)
    #
    #    test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    #    vm1.update()
    #    vm1.set_state(vm_header.STOPPED)
    #
    #    vm1.check()
    #
    #    if num != len(all_attached_clusters) - 1:
    #        check_detach_l2(curr_cluster_uuid, l2_uuid, vm1, True)
    #    else:
    #        check_detach_l2(curr_cluster_uuid, l2_uuid, vm1, False)

    #for cluster in all_attached_clusters:
    #    net_ops.attach_l2(l2_uuid, cluster)
    net_ops.attach_l2(l2_uuid, cluster_uuid)

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

    #check vm1 vm2 status.
    vm2.check()

    vm1.destroy()
    vm2.destroy()
    test_util.test_pass('Detach L2 Test Success')
def error_cleanup():
    global cluster_uuid
    global l2_uuid
    test_lib.lib_error_cleanup(test_obj_dict)
    net_ops.attach_l2(l2_uuid, cluster_uuid)
def test():
    global vm, baremetal_cluster_uuid, pxe_uuid, host_ip
    test_util.test_dsc('Create baremetal cluster and attach network')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cond = res_ops.gen_query_conditions('type', '=', 'baremetal')
    origin_bm_clusters = res_ops.query_resource(res_ops.CLUSTER, cond)
    if origin_bm_clusters != []:
        for i in range(len(origin_bm_clusters)):
            cluster_ops.delete_cluster(origin_bm_clusters[i].uuid)
    baremetal_cluster_uuid = test_stub.create_cluster(zone_uuid).uuid
    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3NoVlanNetworkName1'))
    l3_network = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0]
    cidr = l3_network.ipRanges[0].networkCidr
    cond = res_ops.gen_query_conditions('l3Network.uuid', '=', l3_network.uuid)
    l2_uuid = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    sys_tags = "l2NetworkUuid::%s::clusterUuid::%s::cidr::{%s}" %(l2_uuid, baremetal_cluster_uuid, cidr)
    net_ops.attach_l2(l2_uuid, baremetal_cluster_uuid, [sys_tags])

    test_util.test_dsc('Create pxe server')
    pxe_servers = res_ops.query_resource(res_ops.PXE_SERVER)
    [pxe_ip, interface] = test_stub.get_pxe_info()
    if not pxe_servers:
        pxe_uuid = test_stub.create_pxe(dhcp_interface = interface, hostname = pxe_ip, zoneUuid = zone_uuid).uuid
        baremetal_operations.attach_pxe_to_cluster(pxe_uuid, baremetal_cluster_uuid)
    else:
        pxe_uuid = pxe_servers[0].uuid
 
    test_util.test_dsc('Create a vm to simulate baremetal host')
    #mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    #cond = res_ops.gen_query_conditions('managementIp', '=', mn_ip) 
    host = res_ops.query_resource(res_ops.HOST)[0]
    host_uuid = host.uuid
    host_ip = host.managementIp
    cond = res_ops.gen_query_conditions('hypervisorType', '=', 'KVM')
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER, cond)[0].uuid
    vm = test_stub.create_vm(host_uuid = host_uuid, cluster_uuid = cluster_uuid)

    test_util.test_dsc('Create chassis')
    test_stub.create_vbmc(vm, host_ip, 623)
    chassis = test_stub.create_chassis(baremetal_cluster_uuid, address = host_ip)
    chassis_uuid = chassis.uuid
    #Hack inspect ks file to support vbmc, include ipmi device logic and ipmi addr to 127.0.0.1
    test_stub.hack_inspect_ks(pxe_ip, host_ip)

    test_util.test_dsc('Inspect chassis, Because vbmc have bugs, \
	reset vm unable to enable boot options, power off/on then reset is worked')
    baremetal_operations.inspect_chassis(chassis_uuid)
    baremetal_operations.power_off_baremetal(chassis_uuid)
    time.sleep(10)
    baremetal_operations.power_on_baremetal(chassis_uuid)
    time.sleep(30)
    baremetal_operations.inspect_chassis(chassis_uuid)
    hwinfo = test_stub.check_hwinfo(chassis_uuid)
    if not hwinfo:
        test_util.test_fail('Fail to get hardware info during the first inspection')

    test_util.test_dsc('Create baremetal instance')
    #Hack iso ks file to support unattended installation
    test_stub.hack_generic_ks(pxe_ip)
    #test_stub.ca_pem_workaround(host_ip)
    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('imageName_iso')) 
    image_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid
    time.sleep(30)
    baremetal_ins = test_stub.create_baremetal_ins(image_uuid, chassis_uuid)
    baremetal_ins_uuid = baremetal_ins.uuid
    ins_status = test_stub.check_baremetal_ins(baremetal_ins_uuid, 'password', \
	baremetal_ins.managementIp, host_ip, chassis_uuid, os.environ.get('ipmiaddress'))
    if not ins_status:
        test_util.test_fail('Baremetal instance installation failed')

    test_util.test_dsc('Check baremetal instance operations')
    cond = res_ops.gen_query_conditions('uuid', '=', baremetal_ins_uuid)
    new_name = 'New Baremetal Instance'
    baremetal_operations.update_baremetal_instance(baremetal_ins_uuid, name = new_name)
    udated_name = res_ops.query_resource(res_ops.BAREMETAL_INS, cond)[0].name
    if udated_name != new_name:
        test_util.test_fail('Update baremetal instance name failed, expected: %s, real: %s'%(new_name, udated_name))
    baremetal_operations.stop_baremetal_instance(baremetal_ins_uuid)
    state = res_ops.query_resource(res_ops.BAREMETAL_INS, cond)[0].state
    if state != 'Stopped':
        test_util.test_fail('Fail to stop baremetal instance, current status: %s'%state)
    baremetal_operations.start_baremetal_instance(baremetal_ins_uuid)
    time.sleep(60)
    state = res_ops.query_resource(res_ops.BAREMETAL_INS, cond)[0].state
    if state != 'Running' and state != 'Starting':
        test_util.test_fail('Fail to start baremetal instance, current status: %s'%state)
    baremetal_operations.reboot_baremetal_instance(baremetal_ins_uuid)

    #test_util.test_dsc('Clear env')
    baremetal_operations.destory_baremetal_instance(baremetal_ins_uuid)
    baremetal_operations.expunge_baremetal_instance(baremetal_ins_uuid)
    test_stub.delete_vbmc(vm, host_ip)
    baremetal_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    baremetal_operations.delete_pxe(pxe_uuid)
    cluster_ops.delete_cluster(baremetal_cluster_uuid)
    test_util.test_pass('Create chassis Test 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")
Esempio n. 11
0
def test():
    global vm, baremetal_cluster_uuid, pxe_uuid, host_ip
    test_util.test_dsc('Create baremetal cluster and attach network')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cond = res_ops.gen_query_conditions('type', '=', 'baremetal')
    cluster = res_ops.query_resource(res_ops.CLUSTER, cond)
    if not cluster:
        baremetal_cluster_uuid = test_stub.create_cluster(zone_uuid).uuid
    else:
        baremetal_cluster_uuid = cluster[0].uuid
    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3NoVlanNetworkName1'))
    l3_network = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0]
    cidr = l3_network.ipRanges[0].networkCidr
    cond = res_ops.gen_query_conditions('l3Network.uuid', '=', l3_network.uuid)
    l2_uuid = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    sys_tags = "l2NetworkUuid::%s::clusterUuid::%s::cidr::{%s}" %(l2_uuid, baremetal_cluster_uuid, cidr)
    net_ops.attach_l2(l2_uuid, baremetal_cluster_uuid, [sys_tags])

    test_util.test_dsc('Create pxe server')
    pxe_servers = res_ops.query_resource(res_ops.PXE_SERVER)
    [pxe_ip, interface] = test_stub.get_pxe_info()
    if not pxe_servers:
        pxe_uuid = test_stub.create_pxe(dhcp_interface = interface, hostname = pxe_ip, zoneUuid = zone_uuid).uuid
        baremetal_operations.attach_pxe_to_cluster(pxe_uuid, baremetal_cluster_uuid)
 
    test_util.test_dsc('Create a vm to simulate baremetal host')
    #mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    #cond = res_ops.gen_query_conditions('managementIp', '=', mn_ip) 
    #host = res_ops.query_resource(res_ops.HOST, cond)[0]
    host = res_ops.query_resource(res_ops.HOST)[0]
    host_uuid = host.uuid
    host_ip = host.managementIp
    cond = res_ops.gen_query_conditions('hypervisorType', '=', 'KVM')
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER, cond)[0].uuid
    vm = test_stub.create_vm(host_uuid = host_uuid, cluster_uuid = cluster_uuid)

    test_util.test_dsc('Create chassis')
    test_stub.create_vbmc(vm, host_ip, 623)
    chassis = test_stub.create_chassis(baremetal_cluster_uuid, address = host_ip)
    chassis_uuid = chassis.uuid 
    #Hack inspect ks file to support vbmc, include ipmi device logic and ipmi addr to 127.0.0.1
    test_stub.hack_inspect_ks(pxe_ip, host_ip)

    test_util.test_dsc('Inspect chassis, Because vbmc have bugs, \
	reset vm unable to enable boot options, power off/on then reset is worked')
    baremetal_operations.inspect_chassis(chassis_uuid)
    baremetal_operations.power_off_baremetal(chassis_uuid)
    time.sleep(3)
    status = baremetal_operations.get_power_status(chassis_uuid).status
    if status != "Chassis Power is off":
        test_util.test_fail('Fail to power off chassis %s, current status is %s' %(chassis_uuid, status))
    baremetal_operations.power_on_baremetal(chassis_uuid)
    time.sleep(3)
    status = baremetal_operations.get_power_status(chassis_uuid).status
    if status != "Chassis Power is on":
        test_util.test_fail('Fail to power on chassis %s, current status is %s' %(chassis_uuid, status))

    test_util.test_dsc('Disable/Enable chassis and check')
    cond = res_ops.gen_query_conditions('uuid','=', chassis_uuid)
    baremetal_operations.change_baremetal_chassis_state(chassis_uuid, 'disable')
    state = res_ops.query_resource(res_ops.CHASSIS, cond)[0].state
    if state != 'Disabled':
        test_util.test_fail('Disable chassis %s failed, current state is %s' %(chassis_uuid, state))
    baremetal_operations.change_baremetal_chassis_state(chassis_uuid, 'enable')
    state = res_ops.query_resource(res_ops.CHASSIS, cond)[0].state
    if state != 'Enabled':
        test_util.test_fail('Enable chassis %s failed, current state is %s' %(chassis_uuid, state))

    test_util.test_dsc('Inspect chassis and check hardware info')
    baremetal_operations.inspect_chassis(chassis_uuid)
    hwinfo = test_stub.check_hwinfo(chassis_uuid)
    if not hwinfo:
        test_util.test_fail('Fail to get hardware info during the first inspection')

    baremetal_operations.power_reset_baremetal(chassis_uuid)
    time.sleep(30)

    test_util.test_dsc('Clear env')
    test_stub.delete_vbmc(vm, host_ip)
    baremetal_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    baremetal_operations.delete_pxe(pxe_uuid)
    cluster_ops.delete_cluster(baremetal_cluster_uuid)
    test_util.test_pass('Create chassis Test Success')