def test():

    image_name = os.environ.get('ipv6ImageName')
    ipv4_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName')).uuid
    ipv6_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName1')).uuid
    print "ipv4_net_uuid is : %s , ipv6_net_uuid is : %s" %(ipv4_net_uuid, ipv6_net_uuid)
    vm1 = test_stub.create_vm(l3_name = os.environ.get('l3PublicNetworkName'), vm_name = 'vm_1 IPv6 2 stack test', system_tags = ["dualStackNic::%s::%s" %(ipv4_net_uuid, ipv6_net_uuid)], image_name = image_name)
    vm2 = test_stub.create_vm(l3_name = os.environ.get('l3PublicNetworkName'), vm_name = 'vm_2 IPv6 2 stack test', system_tags = ["dualStackNic::%s::%s" %(ipv4_net_uuid, ipv6_net_uuid)], image_name = image_name)
    time.sleep(120) #waiting for vm bootup
    ipv4 = None
    ipv6 = None
    vms = res_ops.query_resource(res_ops.VM_INSTANCE)
    vm1_nic1 = vms[1].vmNics[0].usedIps[0].ip
    vm1_nic2 = vms[1].vmNics[0].usedIps[1].ip
    vm2_nic1 = vms[0].vmNics[0].usedIps[0].ip
    vm2_nic2 = vms[0].vmNics[0].usedIps[1].ip

    for ip in [vm1_nic1, vm1_nic2]:
        if "172.20" in ip:
            ipv4 = ip
    for ip in [vm2_nic1, vm2_nic2]:
        if "1000:2000" in ip:
            ipv6 = ip
    for ip in [vm2_nic1, vm2_nic2]:
        if "172" in ip:
            vm2_ipv4 = ip
    print "vm1_nic1 : %s, vm1_nic2: %s, vm2_nic1 :%s,vm2_nic2 :%s, ipv4 :%s, ipv6 :%s." %(vm1_nic1, vm1_nic2, vm2_nic1, vm2_nic2, ipv4, ipv6)
    cmd = "ping6 -c 4 %s" %(ipv6)
    (retcode, output, erroutput) = ssh.execute(cmd, ipv4, "root", "password", True, 22)
    cmd1 = "ping -c 4 %s" %(vm2_ipv4)
    (retcode1, output1, erroutput1) = ssh.execute(cmd1, ipv4, "root", "password", True, 22)
    print "retcode is: %s; output is : %s.; erroutput is: %s" %(retcode, output , erroutput)
    print "retcode1 is: %s; output1 is : %s.; erroutput1 is: %s" %(retcode1, output1 , erroutput1)
    if retcode != 0 and retcode1 != 0:
        test_util.test_fail('Test Create IPv6 VM Failed.')
def test():
    test_util.test_dsc('Create test vm with EIP and check.')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)
    
    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_l3_uuid)
    test_obj_dict.add_vip(vip)
    eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm)
    
    vip.attach_eip(eip)
    
    vm.check()
    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')
    vm.destroy()
    test_obj_dict.rm_vm(vm)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('not expected to be able to ping vip while it succeed')

    eip.delete()
    vip.delete()

    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Create EIP for VM Success')
def test():
    test_util.test_dsc('''
    Test Description:
        Will create 1 VM with 3 l3 networks. 1 l3_network is not using VR; 1 l3_network is using novlan VR; 1 l3_network is using vlan VR. 
    Resource required:
        Need support 3 VMs (1 test VM + 2 VR VMs) existing at the same time. 
        This test required a special image, which was configed with at least 3 enabled NICs (e.g. eth0, eth1, eth2).
    ''')
    image_name = os.environ.get('imageName_net')
    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
    l3_net_list = [l3_net_uuid]
    l3_name = os.environ.get('l3VlanNetworkName3')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    l3_net_list.append(l3_net_uuid)
    l3_name = os.environ.get('l3VlanNetworkName4')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    l3_net_list.append(l3_net_uuid)

    vm = test_stub.create_vm(l3_net_list, image_uuid, '3_l3_vm')
    test_obj_dict.add_vm(vm)
    vm.check()

    if len(vm.vm.vmNics) == 3:
        test_util.test_logger("Find 3 expected Nics in new created VM.")
    else:
        test_util.test_fail("New create VM doesn't not have 3 Nics. It only have %s" % len(vm.get_vm().vmNics))

    vm.destroy()
    test_util.test_pass('Create 1 VM with 3 l3_network (1 vlan VR, 1 novlan VR and 1 no VR L3network) successfully.')
def test():
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc")
    for vpc_name in vpc_name_list:
        vr_list.append(test_stub.create_vpc_vrouter(vpc_name))
    for vr, l3_list in izip(vr_list, vpc_l3_list):
        test_stub.attach_l3_to_vpc_vr(vr, l3_list)

    for vpc1_l3 in vpc_l3_list[0]:
        vpc1_l3_uuid.append(test_lib.lib_get_l3_by_name(vpc1_l3).uuid)
    for vpc2_l3 in vpc_l3_list[1]:
        vpc2_l3_uuid.append(test_lib.lib_get_l3_by_name(vpc2_l3).uuid)

    vpc1_l3_uuid.append(test_lib.lib_get_l3_by_name(public_net).uuid)
    vpc2_l3_uuid.append(test_lib.lib_get_l3_by_name(public_net).uuid)


    test_util.test_dsc("disable snat before create ospf")
    for vr in vr_list:
        vpc_ops.set_vpc_vrouter_network_service_state(vr.inv.uuid, networkService='SNAT', state='disable')

    test_util.test_dsc("create ospf")
    vpc_ops.create_vrouter_ospf_area(areaId=ospf_area_id, areaType=ospf_area_type, areaAuth=area_auth_type, password=area_auth_password)
    area_uuid = test_lib.lib_get_ospf_area_by_area_id(areaId=ospf_area_id).uuid

    test_util.test_dsc("add vpc to ospf")
    for vr in vr_list:
        vr_uuid.append(vr.inv.uuid)

    test_util.test_dsc("change router id")
    for i in range(2):
        vpc_ops.set_vrouter_router_id(vRouterUuid=vr_uuid[i], routerId=new_router_id[i])

    test_util.test_dsc("get router id and check")
    result = []
    for vrouter_uuid in vr_uuid:
        result.append(vpc_ops.get_vrouter_router_id(vRouterUuid=vrouter_uuid))

    if result != new_router_id:
        test_util.test_fail('change router id failed')

    for vpc_l3 in vpc1_l3_uuid:
        vpc_ops.add_vrouter_networks_to_ospf_area(vr_uuid[0], [vpc_l3], area_uuid)
    for vpc_l3 in vpc2_l3_uuid:
        vpc_ops.add_vrouter_networks_to_ospf_area(vr_uuid[1], [vpc_l3], area_uuid)

    time.sleep(60)

    test_util.test_dsc("check ospf neighbor state")
    for vr in vr_uuid:
        if vpc_ops.get_vrouter_ospf_neighbor(vr):
            if 'Full' not in vpc_ops.get_vrouter_ospf_neighbor(vr)[0]['state']:
                print vpc_ops.get_vrouter_ospf_neighbor(vr)[0]['state']
                test_util.test_fail('cannot form ospf neighbor, test fail')
        else:
            test_util.test_fail('cannot form ospf neighbor, test fail')

    test_lib.lib_error_cleanup(test_obj_dict)
    test_stub.remove_all_vpc_vrouter()
    test_stub.delete_all_ospf_area()
def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    test_util.test_dsc('Create test vm and check')
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    vr_uuid = vr.uuid
    
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()
    #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    #ps_uuid = ps.uuid
    #ps_ops.change_primary_storage_state(ps_uuid, 'disable')
    test_stub.disable_all_pss()
    if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to runnning when PS change to disable state')

    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.suspend()
    vm.check()

    #ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    test_stub.enable_all_pss()
    host_ops.reconnect_host(host_uuid)
    vm_ops.reconnect_vr(vr_uuid)
    test_util.test_pass('PS disable mode Test Success')
def test():
    test_util.test_dsc('Create test vm with EIP and check.')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)
    
    l3_name = os.environ.get('l3VlanNetworkName1')
    vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid)
    temp_vm1 = None
    if not vrs:
        #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding
        temp_vm1 = test_stub.create_vlan_vm()
        test_obj_dict.add_vm(temp_vm1)
        vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0]
    else:
        vr1 = vrs[0]

    l3_name = os.environ.get('l3NoVlanNetworkName1')
    vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid)
    temp_vm2 = None
    if not vrs:
        #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding
        temp_vm2 = test_stub.create_user_vlan_vm()
        test_obj_dict.add_vm(temp_vm2)
        vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0]
    else:
        vr2 = vrs[0]

    #we do not need temp_vm1 and temp_vm2, since we just use their VRs.
    if temp_vm1:
        temp_vm1.destroy()
        test_obj_dict.rm_vm(temp_vm1)
    if temp_vm2:
        temp_vm2.destroy()
        test_obj_dict.rm_vm(temp_vm2)

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    pri_l3_uuid = vm_nic.l3NetworkUuid
    vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0]
    vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr)
    l3_uuid = vr_pub_nic.l3NetworkUuid
    vip = test_stub.create_vip('create_eip_test', l3_uuid)
    test_obj_dict.add_vip(vip)
    eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm)
    
    vip.attach_eip(eip)
    
    vm.check()
    vip.check()
    vm.destroy()
    test_obj_dict.rm_vm(vm)
    vip.check()
    eip.delete()
    vip.delete()
    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Create EIP for VM Success')
def test():
    test_util.test_dsc('Create test vm with EIP and check.')
    vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm1)

    vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm2)

    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm1_nic = vm1.vm.vmNics[0]
    vm1_nic_uuid = vm1_nic.uuid

    vm2_nic = vm2.vm.vmNics[0]
    vm2_nic_uuid = vm2_nic.uuid

    [test_stub.run_command_in_vm(vm.get_vm(), 'iptables -F') for vm in (vm1, vm2)]

    vip = test_stub.create_vip('create_eip_test', pub_l3_uuid)
    vip_ip = vip.get_vip().ip
    test_obj_dict.add_vip(vip)
    eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm1_nic_uuid, vm_obj=vm1)

    vip.attach_eip(eip)

    vm1.check()

    pri_l3_gateway = os.environ.get('vlanIpRangeGateway1')

    cmd1 = "ping -c 5 %s" % (vip_ip)
    (retcode1, output1, erroutput1) = ssh.execute(cmd1, ext_host_ip, "root", ext_host_pwd, True, 22)
    print "retcode1 is: %s; output1 is : %s.; erroutput1 is: %s" % (retcode1, output1, erroutput1)

    cmd2 = "arp -n | grep -w %s" % (pri_l3_gateway)
    if test_lib.lib_execute_command_in_flat_vm(vm2.vm, cmd2, l3_uuid=pri_l3_uuid):
        vm1.destroy()
        vm2.destroy()
        vm1.expunge()
        vm2.expunge()
        eip.delete()
        vip.delete()
        test_util.test_fail('Gateway leak to other vm, test failed.')

    vm1.destroy()
    vm2.destroy()
    vm1.expunge()
    vm2.expunge()
    eip.delete()
    vip.delete()
def test():
    test_util.test_dsc('''Will mainly doing random test for all kinds of snapshot operations. VM, Volume and Image operations will also be tested. If reach 1 hour successful running condition, testing will success and quit.  SG actions, and VIP actions are removed in this robot test.
        VM resources: a special Utility vm is required to do volume attach/detach operation. 
        ''')
    target_running_vm = 4

    public_l3 = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName'))

    vm_create_option = test_util.VmOption()
    #image has to use virtual router image, as it needs to do port checking
    vm_create_option.set_image_uuid(test_lib.lib_get_image_by_name(img_name=os.environ.get('imageName_net')).uuid)

    utility_vm_create_option = test_util.VmOption()
    utility_vm_create_option.set_image_uuid(test_lib.lib_get_image_by_name(img_name=os.environ.get('imageName_net')).uuid)
    l3_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetworkName1')).uuid
    utility_vm_create_option.set_l3_uuids([l3_uuid])

    priority_actions = test_state.TestAction.snapshot_actions * 4
    utility_vm = test_lib.lib_create_vm(utility_vm_create_option)
    test_dict.add_utility_vm(utility_vm)
    if os.environ.get('ZSTACK_SIMULATOR') != "yes":
        utility_vm.check()

    test_util.test_dsc('Random Test Begin. Test target: 4 coexisting running VM (not include VR and SG target test VMs.).')
    robot_test_obj = test_util.Robot_Test_Object()
    robot_test_obj.set_test_dict(test_dict)
    robot_test_obj.set_vm_creation_option(vm_create_option)
    priority_action_obj = action_select.ActionPriority()
    priority_action_obj.add_priority_action_list(priority_actions)
    robot_test_obj.set_priority_actions(priority_action_obj)
    robot_test_obj.set_exclusive_actions_list(\
            test_state.TestAction.vip_actions + \
            test_state.TestAction.image_actions + \
            test_state.TestAction.sg_actions + \
            [ test_state.TestAction.create_volume ])
    robot_test_obj.set_public_l3(public_l3)
    robot_test_obj.set_utility_vm(utility_vm)
    robot_test_obj.set_random_type(action_select.fair_strategy)

    rounds = 1
    current_time = time.time()
    timeout_time = current_time + 3600
    while time.time() <= timeout_time:
        test_util.test_dsc('New round %s starts: random operation pickup.' % rounds)
        test_lib.lib_vm_random_operation(robot_test_obj)
        test_util.test_dsc('===============Round %s finished. Begin status checking.================' % rounds)
        rounds += 1
        test_lib.lib_robot_status_check(test_dict)

    test_util.test_dsc('Reach test pass exit criterial: 1 hour.')
    test_lib.lib_robot_cleanup(test_dict)
    test_util.test_pass('Snapshots Robot Test Success')
def test():
    test_util.test_dsc('''
    Test Description:
        This case is test for detach a NIC from a stop or a running windows VM 
        Will create 1 test windows VM with 1 NIC firstly. 
        Then attach a new NIC to Stopped VM with different L3 Network.
        Then Stop the VM.
        Then detach the new NIC
        Then start the VM and check the network.
        Then attach a new NIC again
        Then detach the NIC
    ''')
    image_name = os.environ.get('imageName_windows')
    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
    l3_net_list = [l3_net_uuid]
    l3_name2 = os.environ.get('l3VlanNetworkName5')
    l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name2).uuid
    vm_instance_offering = test_lib.lib_create_instance_offering(cpuNum = 2,
                                                                memorySize = 2048 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instance_offering)

    vm = test_stub.create_vm(l3_net_list, image_uuid, 'windows2012_vm', \
            default_l3_uuid = l3_net_uuid, instance_offering_uuid = vm_instance_offering.uuid)
    test_obj_dict.add_vm(vm)

    vm.add_nic(l3_net_uuid2)
    attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm())
    if l3_net_uuid2 != attached_nic.l3NetworkUuid:
        test_util.test_fail("After attach a nic, VM:%s last nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2))

    vm.stop()
    time.sleep(5)
    
    vm.remove_nic(attached_nic.uuid)
    time.sleep(5)

    vm.start()
    time.sleep(50)

    vm.add_nic(l3_net_uuid2)
    attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm())
    if l3_net_uuid2 != attached_nic.l3NetworkUuid:
        test_util.test_fail("After attach a nic again, VM:%s last nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2))
    
    time.sleep(5)
    vm.remove_nic(attached_nic.uuid)
    time.sleep(5)

    vm.destroy()
    test_util.test_pass('Test Attach Nic with VM reboot action successfully.')
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():
    test_util.test_dsc('''
    Test Description:
        Will create 1 test VM with 1 NIC firstly. 
        Then will attach a new NIC to VM with different L3 Network.
    ''')
    image_name = os.environ.get('imageName_net')
    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
    l3_net_list = [l3_net_uuid]
    l3_name = os.environ.get('l3VlanNetworkName3')
    l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name).uuid

    vm = test_stub.create_vm(l3_net_list, image_uuid, 'attach_nic_vm', \
            default_l3_uuid = l3_net_uuid)
    test_obj_dict.add_vm(vm)
    #vm.check()

    #change static IP need to stop VM firstly.
    vm.stop()
    vm.add_nic(l3_net_uuid2)
    ip_address2 = net_ops.get_free_ip(l3_net_uuid2)[0].ip
    static_ip_system_tag2 = test_lib.lib_create_vm_static_ip_tag(\
            l3_net_uuid2, \
            ip_address2)
    tag_ops.create_system_tag('VmInstanceVO', vm.get_vm().uuid, \
            static_ip_system_tag2)

    vm.start()
    attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm())
    if l3_net_uuid2 != attached_nic.l3NetworkUuid:
        test_util.test_fail("After attach a nic, VM:%s last nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2))
    test_lib.lib_restart_vm_network(vm.get_vm())

    if attached_nic.ip != ip_address2:
        test_util.test_fail('new added NIC ip address:%s is not static ip: %s' \
                % (attached_nic.ip, ip_address2))

    vm.check()

    vm.remove_nic(attached_nic.uuid)

    attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm())
    if l3_net_uuid != attached_nic.l3NetworkUuid:
        test_util.test_fail("After detached NIC, VM:%s only nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2))

    vm.destroy()
    test_util.test_pass('Test Attach Nic to VM successfully.')
def test():
    test_util.test_dsc('''
        Will doing random test for VIP operations, including VIP create/delete, PF create/attach/detach/remove, EIP create/attach/detach/remove. VM operations will also be tested. If reach max 4 coexisting running vm, testing will success and quit.  SG actions, Volume actions and Image actions are removed in this robot test.
        VM resources: VIP testing needs at least 3 VRs are running. 
        ''')
    target_running_vm = 4

    public_l3 = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName'))

    vm_create_option = test_util.VmOption()
    #image has to use virtual router image, as it needs to do port checking
    vm_create_option.set_image_uuid(test_lib.lib_get_image_by_name(img_name=os.environ.get('imageName_net')).uuid)

    priority_actions = test_state.TestAction.snapshot_actions * 4
    utility_vm_create_option = test_util.VmOption()
    utility_vm_create_option.set_image_uuid(test_lib.lib_get_image_by_name(img_name=os.environ.get('imageName_net')).uuid)
    l3_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetworkName1')).uuid
    utility_vm_create_option.set_l3_uuids([l3_uuid])
    utility_vm = test_lib.lib_create_vm(utility_vm_create_option)
    test_dict.add_utility_vm(utility_vm)
    if os.environ.get('ZSTACK_SIMULATOR') != "yes":
        utility_vm.check()

    test_util.test_dsc('Random Test Begin. Test target: 4 coexisting running VM (not include VR and SG target test VMs.).')
    robot_test_obj = test_util.Robot_Test_Object()
    robot_test_obj.set_test_dict(test_dict)
    robot_test_obj.set_vm_creation_option(vm_create_option)
    priority_action_obj = action_select.ActionPriority()
    priority_action_obj.add_priority_action_list(priority_actions)
    robot_test_obj.set_priority_actions(priority_action_obj)
    robot_test_obj.set_exclusive_actions_list(\
            test_state.TestAction.vip_actions + \
            test_state.TestAction.image_actions + \
            test_state.TestAction.sg_actions + \
            [test_state.TestAction.create_volume])
    robot_test_obj.set_public_l3(public_l3)
    robot_test_obj.set_utility_vm(utility_vm)

    rounds = 1
    while len(test_dict.get_vm_list(vm_header.RUNNING)) < target_running_vm:
        test_util.test_dsc('New round %s starts: random operation pickup.' % rounds)
        test_lib.lib_vm_random_operation(robot_test_obj)
        test_util.test_dsc('===============Round %s finished. Begin status checking.================' % rounds)
        rounds += 1
        test_lib.lib_robot_status_check(test_dict)

    test_util.test_dsc('Reach test pass exit criterial.')
    test_lib.lib_robot_cleanup(test_dict)
    test_util.test_pass('Snapshots Robot Test Success')
def test():
    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
    l3_uuid_list = [l3_net_uuid]
    vm_creation_option = test_util.VmOption()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_name = '10k_vm-' + str(time.time())
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_l3_uuids(l3_uuid_list)
    vm_creation_option.set_image_uuid(image_uuid)
    #disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    #disk_offering_uuids = [disk_offering.uuid]
    #vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    vm_creation_option.set_name(vm_name)
    vm = zstack_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    test_obj_dict.add_vm(vm)
 
    time.sleep(1)
    vm.destroy()
    test_util.test_pass('Create/Destroy VM successfully')
def prepare_host_with_different_cpu_scenario():
    """
    Prepare vms in hosts
    """
    global pre_vms
    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('l3NoVlanNetworkName1')
    #l3_name = os.environ.get('l3PublicNetworkName')


    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    #instance_offering_uuid = new_offering.uuid
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)

    ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0].uuid
    hosts = test_lib.lib_find_hosts_by_ps_uuid(ps_uuid)
    host_id = 0
    for host, max_vm_num in zip(hosts,[2,3,1,2]):
        host_id +=1
        for i in range(max_vm_num):
            print "host_id=%s; i=%s" %(host_id, i)
            vm_creation_option.set_name('pre-create-vm-%s-%s' %(host_id, i))
            vm = test_vm_header.ZstackTestVm()
            vm_creation_option.set_host_uuid(host.uuid)
            vm.set_creation_option(vm_creation_option)
            vm.create()
            pre_vms.append(vm)
def test():
    test_util.test_dsc('Create test vm with static ip address and check. VR has DNS SNAT EIP PF and DHCP services')
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    ip_address = net_ops.get_free_ip(l3_uuid)[0].ip
    static_ip_system_tag = test_lib.lib_create_vm_static_ip_tag(l3_uuid, \
            ip_address)
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'), system_tags=[static_ip_system_tag])
    test_obj_dict.add_vm(vm)
    vm.stop()
    
    cond = res_ops.gen_query_conditions('tag', '=', static_ip_system_tag)
    system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0]

    ip_address2 = net_ops.get_free_ip(l3_uuid)[0].ip
    static_ip_system_tag2 = test_lib.lib_create_vm_static_ip_tag(l3_uuid, \
            ip_address2)
    vm_ops.change_vm_static_ip(vm.get_vm().uuid, l3_uuid, ip_address2)

    vm.start()
    if ip_address2 != vm.get_vm().vmNics[0].ip:
        test_util.test_fail('VM static ip test failed')
    vm.check()
    vm.destroy()
    test_util.test_pass('Create VM with static IP and change static IP Test Success')
def test():
    if "test-config-vpc-dns.xml" != os.path.basename(os.environ.get('WOODPECKER_TEST_CONFIG_FILE')).strip():
        test_util.test_skip('Skip test on test config except test-config-vpc-dns.xml')

    test_util.test_dsc("1. create vpc vrouter")
    vr = test_stub.create_vpc_vrouter(vpc_vr_name)
    vr_uuid = vr.inv.uuid

    vpc_l3_uuid = test_lib.lib_get_l3_by_name(vpc_l3_name).uuid

    test_util.test_dsc("2. attach vpc network to vpc router")
    test_stub.attach_l3_to_vpc_vr_by_uuid(vr, vpc_l3_uuid)

    test_util.test_dsc("3. add dns to vpc network and vpc router")
    for dns in l3_dns_list:
        vpcdns_ops.add_dns_to_l3_network(vpc_l3_uuid, dns)

    vpcdns_ops.add_dns_to_vpc_router(vr_uuid, default_dns)

    test_util.test_dsc("4. get vpc dns list and check")
    vpc_dns_info = test_stub.query_vpc_vrouter(vpc_vr_name).inv.dns
    for vpc_dns in vpc_dns_info:
        vpc_dns_list_end.append(vpc_dns['dns'])

    if vpc_dns_list_end != vpc_dns_list_begin:
        test_util.test_fail("add dns to vpc network take effect on vpc router, not expected.")
    else:
        for dns in l3_dns_list:
            vpcdns_ops.remove_dns_from_l3_network(vpc_l3_uuid, dns)
        test_util.test_pass("add dns to vpc network take no effect on vpc router, expected result.")
def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)

    test_util.test_dsc('Create test vm and check')

    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None)
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    test_lib.lib_set_delete_policy('vm', 'Delay')
    test_lib.lib_set_delete_policy('volume', 'Delay')
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    vr_uuid = vr.uuid
    
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()

    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi'])
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.attach(vm)

    #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    #ps_uuid = ps.uuid
    #ps_ops.change_primary_storage_state(ps_uuid, 'disable')
    test_stub.disable_all_pss()
    if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to running when PS change to disable state')

    vm.set_state(vm_header.RUNNING)
    vm.check()
    volume.delete()
    volume.check()
    volume.expunge()
    volume.check()

    #ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    test_stub.enable_all_pss()
    host_ops.reconnect_host(host_uuid)
    vm_ops.reconnect_vr(vr_uuid)
    vm.destroy()
    test_lib.lib_set_delete_policy('vm', 'Direct')
    test_lib.lib_set_delete_policy('volume', 'Direct')
    test_util.test_pass('Delete volume under PS disable mode Test Success')
def test():
    global vm, host3_uuid

    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    conf_ops.change_global_config('ha', 'allow.slibing.cross.clusters', 'true')

    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('l3NoVlanNetworkName1')
    #l3_name = os.environ.get('l3VlanNetworkName1')
    l3_name = os.environ.get('l3PublicNetworkName')
    host3_name = os.environ.get('hostName3')
    host4_name = os.environ.get('hostName4')

    conditions1 = res_ops.gen_query_conditions('name', '=', host3_name)
    host3_uuid = res_ops.query_resource(res_ops.HOST, conditions1)[0].uuid
    host3_ip = res_ops.query_resource(res_ops.HOST, conditions1)[0].managementIp

    conditions2 = res_ops.gen_query_conditions('name', '=', host4_name)
    host4_uuid = res_ops.query_resource(res_ops.HOST, conditions2)[0].uuid
    host4_ip = res_ops.query_resource(res_ops.HOST, conditions2)[0].managementIp

    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    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_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multihost_basic_vm')
    vm_creation_option.set_host_uuid(host3_uuid)
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    time.sleep(30)
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
    time.sleep(5)
    vm.check()
    
    ssh_cmd1 = 'ssh  -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s' % host3_ip    
    cmd = '%s "poweroff" ' % ssh_cmd1
    process_result = test_stub.execute_shell_in_process(cmd, tmp_file)
        
    time.sleep(360)
    host3_status = res_ops.query_resource(res_ops.HOST, conditions1)[0].status    
    if host3_status == "Disconnected":
        conditions3 = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid)
        vm_status = res_ops.query_resource(res_ops.VM_INSTANCE, conditions3)[0].state
        vm_host_uuid = res_ops.query_resource(res_ops.VM_INSTANCE, conditions3)[0].hostUuid
        if vm_status != "Running" or vm_host_uuid != host4_uuid:         
            test_util.test_fail('Test fail vm status: %s, vm_host_uuid: %s,' %(vm_status, vm_host_uuid))
    vm.destroy()
    conf_ops.change_global_config('ha', 'allow.slibing.cross.clusters', 'false')

    conditions4 = res_ops.gen_query_conditions('vmNics.ip', '=', host3_ip)
    vm3_uuid = sce_ops.query_resource(zstack_management_ip, res_ops.VM_INSTANCE, conditions4).inventories[0].uuid
    sce_ops.start_vm(zstack_management_ip, vm3_uuid)
    test_util.test_pass('VM auto ha across cluster Test Success')
def test():
    global default_l3_mtu
    test_util.test_dsc('Create test vm and check. VR has DNS SNAT EIP PF and DHCP services')
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    default_l3_mtu = net_ops.get_l3_mtu(l3_net_uuid)

    vm = test_stub.create_vlan_vm(l3_name)
    test_obj_dict.add_vm(vm)
    vrs = test_lib.lib_find_vr_by_vm(vm.vm)
    for vr in vrs:
        if vr.applianceVmType != "vrouter":
            test_util.test_skip("Skip l3 mtu test for non vrouter")

    vm.check()
    if not test_lib.lib_execute_command_in_vm(vm.get_vm(), 'tracepath -n yyk.net | tail -1 | grep "pmtu %s"' % (default_l3_mtu)):
        test_util.test_fail("fail to check mtu in [vm:] %s" % (vm.get_vm().uuid))

    net_ops.set_l3_mtu(l3_net_uuid, 1200)
    vm.reboot()
    vm.check()
    if not test_lib.lib_execute_command_in_vm(vm.get_vm(), 'tracepath -n yyk.net | tail -1 | grep "pmtu 1200"'):
        test_util.test_fail("fail to check mtu in [vm:] %s" % (vm.get_vm().uuid))

    vm.destroy()
    test_util.test_pass('Create VirtualRouter VM DNS DHCP SANT EIP PF Test Success')
Example #20
0
def create_vm(vm_name = 'vm_for_baremetal', image_name = None, \
             l3_name = None, instance_offering_uuid = None, \
             host_uuid = None, disk_offering_uuid = None, cluster_uuid = None, \
             system_tags = None, password = None, session_uuid = None):
    if not instance_offering_uuid:
        instance_offering_name = os.environ.get('instanceOfferingName_m')
        instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(instance_offering_name).uuid
    if not image_name:
        image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    if not l3_name:
        l3_name = os.environ.get('scenl3VPCNetworkName1')
    l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    vm_creation_option = test_util.VmOption()
    vm_creation_option.set_name(vm_name)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_l3_uuids([l3_uuid])
    if cluster_uuid:
        vm_creation_option.set_cluster_uuid(cluster_uuid)
    if system_tags: 
        vm_creation_option.set_system_tags(system_tags)
    if disk_offering_uuid:
        vm_creation_option.set_data_disk_uuids(disk_offering_uuid)
    if password:
        vm_creation_option.set_root_password(password)
    if host_uuid:
        vm_creation_option.set_host_uuid(host_uuid)
    if session_uuid:
        vm_creation_option.set_session_uuid(session_uuid)
    vm = zstack_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    return vm
def test():
    test_util.test_dsc('Test VM online change instance offering')

    image_name = os.environ.get('imageName_net')
    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
    l3_net_list = [l3_net_uuid]

    vm = test_stub.create_vm(l3_net_list, image_uuid, 'online_chg_offering_vm', system_tags=['instanceOfferingOnlinechange::true'])
    test_obj_dict.add_vm(vm)

    vm.check()
    cpuNum = 2
    memorySize = 666 * 1024 * 1024
    new_offering = test_lib.lib_create_instance_offering(cpuNum = cpuNum,\
            memorySize = memorySize)

    test_obj_dict.add_instance_offering(new_offering)
    new_offering_uuid = new_offering.uuid

    new_offering2 = test_lib.lib_create_instance_offering(cpuNum = cpuNum,\
            memorySize = memorySize)
    test_obj_dict.add_instance_offering(new_offering2)
    new_offering_uuid2 = new_offering2.uuid

    vm.change_instance_offering(new_offering_uuid)
    vm.change_instance_offering(new_offering_uuid2)

    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)

    #create VRs.
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)
    if not vrs:
        vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
        vm.destroy()
        vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    else:
        vr1 = vrs[0]

    vm_ops.stop_vm(vr1.uuid)
    if test_lib.lib_get_ha_enable() != 'true' or vr1.applianceVmType != "vrouter":
        vm_ops.start_vm(vr1.uuid)

    vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1)
    if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120):
        test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid)

    timeout = time.time() + 60
    while time.time() < timeout:
        cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) 
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
        if vms[0].status == 'Connected':
            test_util.test_pass('Test Reconnect VR VM start VRs success')
        time.sleep(1)

    test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
def test():
    global vm

    testHosts = test_lib.lib_get_all_hosts_from_plan()
    for host in testHosts:
        node_ip = host.managementIp_
        print str(node_ip)+" is host.managementIp_"
        break

    host_username = "******"
    host_password = "******"

    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
    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_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multihost_basic_vm')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()

    cmd = "zstack-ctl setenv ZSTACK_HOME=/usr/local/zstacktest/apache-tomcat/webapps/zstack/; zstack-ctl dump_mysql --file-name mysql_dump"
    rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180)
    dump_file = rsp.split()[-1]

    cmd = "mysqldump -uroot -pzstack.mysql.password -A -r /tmp/mysql_before_restore.dump"
    rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180)

    vm.check()

    cmd = "zstack-ctl restore_mysql -f %s --mysql-root-password %s"%(dump_file, host_password)
    rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180)

    cmd = '''mysql -uroot -pzstack.mysql.password -D zstack -e "delete from VmInstanceVO where uuid='%s';"''' % (vm.get_vm().uuid)
    rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180)

    cmd = "mysqldump -uroot -pzstack.mysql.password -A -r /tmp/mysql_after_restore.dump"
    rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180)

    cmd = "zstack-ctl start"
    rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180)

    #cmd = "diff /tmp/mysql_before_restore.dump /tmp/mysql_after_restore.dump |wc -l"
    #rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180)

    #diff mysql dump alway has 4 or 8 lines difference because the dump time is different. 
    #and sometime here has 12 lines difference,So we suppose the when the different lines
    # more than 12, Restore mysql db failed.
    #if int(rsp.rstrip()) > 12:
    #    test_util.test_fail('Restore Mysql Failed')

    vm.destroy()
    test_util.test_pass('Restore Mysql Success')
def test():
    image_name = os.environ.get('imageName')
    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
    l3_uuid_list = [l3_net_uuid]
    vm_creation_option = test_util.VmOption()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_name = 'parallel_vm-'
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_l3_uuids(l3_uuid_list)
    vm_creation_option.set_image_uuid(image_uuid)
    #vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    for i in range(parallel_num):
        i = i + 1
        vm_creation_option.set_name(vm_name + str(i))
        vm = zstack_vm_header.ZstackTestVm()
        vm.set_creation_option(vm_creation_option)
        vm.create()
        test_obj_dict.add_vm(vm)
 
    #vm.destroy()
    test_util.test_pass('Parallelly Create 10 VM successfully')
def test():
    global vm
    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
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_name('multihost_basic_vm')

    for i in range(1, 10):
        vm_creation_option.set_cpu_num(random.choice(VM_CPU))
        vm_creation_option.set_memory_size(random.choice(VM_MEM))
        vm = test_vm_header.ZstackTestVm()
        vm.set_creation_option(vm_creation_option)
        vm.create()
        vm_uuid = vm.get_vm()['uuid']
        vm.check()
        time.sleep(30)
        prometheus_test(vm_uuid)
        vm.destroy()
        vm.expunge()
        time.sleep(30)
def test():
    image_name = os.environ.get('imageName_net')
    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
    l3_uuid_list = [l3_net_uuid]
    vm_creation_option = test_util.VmOption()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    times = 1
    vm_name = '24hr_vm-'
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_l3_uuids(l3_uuid_list)
    vm_creation_option.set_image_uuid(image_uuid)
    #vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    current_time = time.time()
    end_time = current_time + duration
    while current_time < end_time:
        times = times + 1
        vm_creation_option.set_name(vm_name + str(times))
        vm = zstack_vm_header.ZstackTestVm()
        vm.set_creation_option(vm_creation_option)
        vm.create()
        time.sleep(5)
        vm.destroy()
    test_util.test_pass('Keep create/destroy %s VMs in 24 hrs pass' % times)
def test():
    if "test-config-vpc-dns.xml" != os.path.basename(os.environ.get('WOODPECKER_TEST_CONFIG_FILE')).strip():
        test_util.test_skip('Skip test on test config except test-config-vpc-dns.xml')

    test_util.test_dsc("1. create vpc vrouter")
    vr = test_stub.create_vpc_vrouter(vpc_vr_name)
    vr_uuid = vr.inv.uuid

    vpc_l3_uuid = test_lib.lib_get_l3_by_name(vpc_l3_name).uuid

    test_util.test_dsc("2. attach vpc network to vpc router")
    test_stub.attach_l3_to_vpc_vr_by_uuid(vr, vpc_l3_uuid)

    test_util.test_dsc("3. disable and enable vpc snat service for 100 times")
    for i in range(1,100):
        vpc_ops.set_vpc_vrouter_network_service_state(vr_uuid, networkService='SNAT', state='disable')
        vpc_ops.set_vpc_vrouter_network_service_state(vr_uuid, networkService='SNAT', state='enable')

    serviceState = vpc_ops.get_vpc_vrouter_network_service_state(vr_uuid, networkService='SNAT')
    if serviceState.env.state != 'enable':
        test_util.test_fail("enable SNAT failed.")

    test_util.test_dsc("4. enable and disable vpc snat service for 100 times")
    for i in range(1,100):
        vpc_ops.set_vpc_vrouter_network_service_state(vr_uuid, networkService='SNAT', state='enable')
        vpc_ops.set_vpc_vrouter_network_service_state(vr_uuid, networkService='SNAT', state='disable')

    serviceState = vpc_ops.get_vpc_vrouter_network_service_state(vr_uuid, networkService='SNAT')
    if serviceState.env.state != 'disable':
        test_util.test_fail("disable SNAT failed.")
Example #28
0
def create_vm(vm_name='virt-vm', \
        image_name = None, \
        l3_name = None, \
        instance_offering_uuid = None, \
        host_uuid = None, \
        disk_offering_uuids=None, system_tags=None, session_uuid = None):

    if not image_name:
        image_name = os.environ.get('imageName_net') 
    if not l3_name:
        l3_name = os.environ.get('l3PublicNetworkName')

    vm_creation_option = test_util.VmOption()
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    if not instance_offering_uuid:
	instance_offering_name = os.environ.get('instanceOfferingName_s')
        instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(instance_offering_name).uuid

    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name(vm_name)
    vm_creation_option.set_system_tags(system_tags)
    vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    if host_uuid:
        vm_creation_option.set_host_uuid(host_uuid)
    vm = zstack_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    return vm 
Example #29
0
def create_vm(vm_name='virt-vm', \
        image_name = None, \
        l3_name = None, \
        instance_offering_uuid = None, \
        host_uuid = None, \
        disk_offering_uuids=None, system_tags=None, session_uuid = None):

    if not image_name:
        image_name = os.environ.get('imageName_net') 
    if not l3_name:
        l3_name = os.environ.get('l3PublicNetworkName')

    vm_creation_option = test_util.VmOption()
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    if not instance_offering_uuid:
        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_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name(vm_name)
    vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    if host_uuid:
        vm_creation_option.set_host_uuid(host_uuid)
    vm = zstack_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    return vm 
def test():
    global default_l3_mtu
    test_util.test_dsc('Create test vm and check. VR has DNS SNAT EIP PF and DHCP services')
    l3_name = os.environ.get('l3PublicNetworkName')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    default_l3_mtu = net_ops.get_l3_mtu(l3_net_uuid)
    vm = test_stub.create_vlan_vm(l3_name)
    test_obj_dict.add_vm(vm)
    vm.check()
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('tracepath -n yyk.net | tail -1 | grep "pmtu %s"' % (default_l3_mtu))
    script_file.close()
    if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name):
        test_util.test_fail("fail to check mtu in [vm:] %s" % (vm.get_vm().uuid))
    os.unlink(script_file.name)

    net_ops.set_l3_mtu(l3_net_uuid, 1200)
    vm.reboot()
    vm.check()
    
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('tracepath -n yyk.net | tail -1 | grep "pmtu 1200"')
    script_file.close()
    if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name):
        test_util.test_fail("fail to check mtu in [vm:] %s" % (vm.get_vm().uuid))
    os.unlink(script_file.name)

    vm.destroy()
    test_util.test_pass('Create VirtualRouter VM DNS DHCP SANT EIP PF Test Success')
Example #31
0
def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid

    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
            break
    else:
        vm.destroy()
        test_util.test_skip('Not find ceph type backup storage.')

    l3_1_name = os.environ.get('l3VlanNetwork3')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    vr_uuid = vr.uuid

    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    ps_uuid = ps.uuid
    ps_ops.change_primary_storage_state(ps_uuid, 'disable')
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail(
            'VM is expected to stop when PS change to disable state')

    vm.set_state(vm_header.STOPPED)
    vm.check()
    test_stub.migrate_vm_to_random_host(vm)
    vm.check()
    volume.check()

    ps_ops.change_primary_storage_state(ps_uuid, 'Enabled')
    host_ops.reconnect_host(host_uuid)
    vm_ops.reconnect_vr(vr_uuid)
    test_util.test_pass('PS disable mode Test Success')
Example #32
0
def create_instance_vm(image_name, instance_offering_uuid, l3_name=None, disk_offering_uuids = None, default_l3_uuid = None):
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    if not l3_name:
        l3_name = os.environ.get('l3PublicNetworkName')

    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vm_name = 'zs_install_%s' % image_name

    vm_creation_option = test_util.VmOption()
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_name(vm_name)
    vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    vm_creation_option.set_default_l3_uuid(default_l3_uuid)
    vm = zstack_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    return vm
Example #33
0
def create_vm(vm_creation_option=None,
              volume_uuids=None,
              root_disk_uuid=None,
              image_uuid=None,
              session_uuid=None):
    if not vm_creation_option:
        instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(
            os.environ.get('instanceOfferingName_s')).uuid
        cond = res_ops.gen_query_conditions('mediaType', '!=', 'ISO')
        cond = res_ops.gen_query_conditions('platform', '=', 'Linux', cond)
        l3net_uuid = test_lib.lib_get_l3_by_name(
            os.environ.get('l3VlanNetwork3')).uuid
        if image_uuid:
            image_uuid = image_uuid
        else:
            image_uuid = res_ops.query_resource(res_ops.IMAGE, cond,
                                                session_uuid)[0].uuid
        vm_creation_option = test_util.VmOption()
        vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
        vm_creation_option.set_image_uuid(image_uuid)
        vm_creation_option.set_l3_uuids([l3net_uuid])

    if volume_uuids:
        if isinstance(volume_uuids, list):
            vm_creation_option.set_data_disk_uuids(volume_uuids)
        else:
            test_util.test_fail('volume_uuids type: %s is not "list".' %
                                type(volume_uuids))

    if root_disk_uuid:
        vm_creation_option.set_root_disk_uuid(root_disk_uuid)

    if image_uuid:
        vm_creation_option.set_image_uuid(image_uuid)

    if session_uuid:
        vm_creation_option.set_session_uuid(session_uuid)

    vm = test_vm.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    return vm
def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    test_util.test_dsc('Create test vm and check')

    test_lib.lib_set_delete_policy('vm', 'Delay')
    test_lib.lib_set_delete_policy('volume', 'Delay')

    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    vr_uuid = vr.uuid

    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()
    #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    #ps_uuid = ps.uuid
    #ps_ops.change_primary_storage_state(ps_uuid, 'disable')
    test_stub.disable_all_pss()
    if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail(
            'VM is expected to running when PS change to disable state')

    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.destroy()
    vm.check()

    #ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    test_stub.enable_all_pss()
    host_ops.reconnect_host(host_uuid)
    vm_ops.reconnect_vr(vr_uuid)

    test_lib.lib_set_delete_policy('vm', 'Direct')
    test_lib.lib_set_delete_policy('volume', 'Direct')

    test_util.test_pass('PS disable mode Test Success')
Example #35
0
def create_windows_vm(vm_creation_option=None,
                      volume_uuids=None,
                      root_disk_uuid=None,
                      image_uuid=None,
                      session_uuid=None):
    if not vm_creation_option:
        instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(
            os.environ.get('instanceOfferingName_win')).uuid
        cond = res_ops.gen_query_conditions('mediaType', '!=', 'ISO')
        cond = res_ops.gen_query_conditions('platform', '=', 'Windows', cond)
        image_uuid = res_ops.query_resource(res_ops.IMAGE, cond,
                                            session_uuid)[0].uuid
        l3net_uuid = test_lib.lib_get_l3_by_name(
            os.environ.get('l3VlanNetworkName3')).uuid
        vm_creation_option = test_util.VmOption()
        vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
        vm_creation_option.set_image_uuid(image_uuid)
        vm_creation_option.set_l3_uuids([l3net_uuid])
    return create_vm(vm_creation_option, volume_uuids, root_disk_uuid,
                     image_uuid, session_uuid)
Example #36
0
def test():
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)

    #create VRs.
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)
    if not vrs:
        vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
        vm.destroy()
        vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    else:
        vr1 = vrs[0]

    vm_ops.reconnect_vr(vr1.uuid)

    cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid)
    vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
    if not vms[0].status == 'Connected':
        test_util.test_fail('VR VM: %s is not connected' % vr1.uuid)

    test_util.test_pass('Test Reconnect VR VM start VRs success')
Example #37
0
def create_vm(vm_name='virt-vm', \
        image_name = None, \
        l3_name = None, \
        instance_offering_uuid = None, \
        host_uuid = None, \
        disk_offering_uuids=None, system_tags=None, session_uuid = None):

    if not image_name:
        image_name = os.environ.get('imageName_net')
    if not l3_name:
        l3_name = os.environ.get('l3PublicNetworkName')

    vm_creation_option = test_util.VmOption()
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_names = l3_name.split(',')
    print 'shuang: %s' % (l3_names)
    l3_net_uuids = []
    for l3_n in l3_names:
        l3_net_uuid = test_lib.lib_get_l3_by_name(l3_n).uuid
        l3_net_uuids.append(l3_net_uuid)
    if not instance_offering_uuid:
        instance_offering_name = os.environ.get('instanceOfferingName_s')
        instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(
            instance_offering_name).uuid

    vm_creation_option.set_l3_uuids(l3_net_uuids)
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name(vm_name)
    vm_creation_option.set_system_tags(system_tags)
    vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    if host_uuid:
        vm_creation_option.set_host_uuid(host_uuid)
    vm = zstack_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    return vm
Example #38
0
def test():
    image_name = os.environ.get('imageName')
    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
    l3_uuid_list = [l3_net_uuid]
    vm_creation_option = test_util.VmOption()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_name = '10k_vm-' + str(time.tim())
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_l3_uuids(l3_uuid_list)
    vm_creation_option.set_image_uuid(image_uuid)
    #vm_creation_option.set_data_disk_uuids(disk_offering_uuids)
    vm_creation_option.set_name(vm_name)
    vm = zstack_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    test_obj_dict.add_vm(vm)
 
    time.sleep(3)
    vm.destroy()
    test_util.test_pass('Create/Destroy VM successfully')