Exemplo n.º 1
0
def test():
    global test_obj_dict

    pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE)
    if pss[0].type != "LocalStorage":
        test_util.test_skip(
            "this test is designed to run on localstorage, skip on other ps type."
        )

    vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)
    vm.check()

    vm_nic_uuid = vm.vm.vmNics[0].uuid
    net_ops.detach_l3(vm_nic_uuid)

    vm.stop()
    vm.check()

    #test_stub.migrate_vm_to_random_host(vm)
    target_host = test_lib.lib_find_random_host(vm.vm)
    vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid)

    l3_name = os.environ.get('l3VlanNetwork3')
    l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    net_ops.attach_l3(l3_uuid, vm.vm.uuid)

    vm.start()
    vm.check()

    test_util.test_pass('test detach l3, migrate and attaching passed.')
Exemplo n.º 2
0
def test():

    pub_l3_vm, flat_l3_vm, vr_l3_vm = test_stub.generate_pub_test_vm(
        tbj=test_obj_dict)

    net_ops.attach_l3(flat_l3_vm.get_vm().vmNics[0].l3NetworkUuid,
                      pub_l3_vm.get_vm().uuid)
    net_ops.attach_l3(vr_l3_vm.get_vm().vmNics[0].l3NetworkUuid,
                      pub_l3_vm.get_vm().uuid)

    for action in ('update', 'stop', 'start'):
        getattr(pub_l3_vm, action)()

    pub_nic_l3uuid_list = [
        nic.l3NetworkUuid for nic in pub_l3_vm.get_vm().vmNics
    ]
    assert len(pub_l3_vm.get_vm().vmNics) == 3
    assert flat_l3_vm.get_vm().vmNics[0].l3NetworkUuid in pub_nic_l3uuid_list
    assert vr_l3_vm.get_vm().vmNics[0].l3NetworkUuid in pub_nic_l3uuid_list

    pub_l3_vm.remove_nic([
        nic.uuid for nic in pub_l3_vm.get_vm().vmNics
        if nic.l3NetworkUuid == flat_l3_vm.get_vm().vmNics[0].l3NetworkUuid
    ][0])
    pub_l3_vm.remove_nic([
        nic.uuid for nic in pub_l3_vm.get_vm().vmNics
        if nic.l3NetworkUuid == vr_l3_vm.get_vm().vmNics[0].l3NetworkUuid
    ][0])
    assert len(pub_l3_vm.get_vm().vmNics) == 1

    for action in ('update', 'stop', 'start', 'check'):
        getattr(pub_l3_vm, action)()
Exemplo n.º 3
0
def test():
    test_util.test_dsc(
        'Create vrouter vm and check if the second public nic attached to vrouter'
    )
    vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm1)
    vm1_ip = vm1.get_vm().vmNics[0].ip
    vr1 = test_lib.lib_find_vr_by_vm(vm1.vm)[0]
    vr1_uuid = vr1.uuid
    vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1)
    vr1_private_ip = test_lib.lib_find_vr_private_ip(vr1)
    l3network1_uuid = vm1.get_vm().vmNics[0].l3NetworkUuid
    cond = res_ops.gen_query_conditions('uuid', '=', l3network1_uuid)
    l3network1_cidr = res_ops.query_resource(res_ops.L3_NETWORK,
                                             cond)[0].ipRanges[0].networkCidr

    cond = res_ops.gen_query_conditions('name', '=', 'l3_user_defined_vlan1')
    second_public_l3network_uuid = res_ops.query_resource(
        res_ops.L3_NETWORK, cond)[0].uuid
    net_ops.attach_l3(second_public_l3network_uuid, vr1_uuid)

    #Attach second public network to vrouter
    cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid)
    vr1_vm = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)
    vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics
    second_public_l3network_attached = False
    for vm_nic in vr1_nics:
        if vm_nic.l3NetworkUuid == second_public_l3network_uuid:
            second_public_l3network_attached = True
    if not second_public_l3network_attached:
        net_ops.attach_l3(second_public_l3network_uuid, vr1_uuid)

    #Get vr1 nic_uuid on second public network
    vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics
    vr1_second_pub_nic_uuid = ''
    for vm_nic in vr1_nics:
        if vm_nic.l3NetworkUuid == second_public_l3network_uuid:
            vr1_second_pub_nic_uuid = vm_nic.uuid
            vm1.destroy()
            net_ops.destroy_vrouter(vr1_uuid)
            test_util.test_pass('The Second Public Nic Is Attached To Vrouter')
    if vr1_second_pub_nic_uuid != '':
        net_ops.detach_l3(vr1_second_pub_nic_uuid)
    vm1.destroy()
    net_ops.destroy_vrouter(vr1_uuid)
    test_util.test_fail('The Second Public Nic Does Not Attached To Vrouter')
def test():

    pub_l3_vm, flat_l3_vm, vr_l3_vm = test_stub.generate_pub_test_vm(tbj=test_obj_dict)

    net_ops.attach_l3(flat_l3_vm.get_vm().vmNics[0].l3NetworkUuid, pub_l3_vm.get_vm().uuid)
    net_ops.attach_l3(vr_l3_vm.get_vm().vmNics[0].l3NetworkUuid, pub_l3_vm.get_vm().uuid)

    for action in ('update', 'stop', 'start'):
        getattr(pub_l3_vm, action)()

    pub_nic_l3uuid_list = [nic.l3NetworkUuid for nic in pub_l3_vm.get_vm().vmNics]
    assert len(pub_l3_vm.get_vm().vmNics) == 3
    assert flat_l3_vm.get_vm().vmNics[0].l3NetworkUuid in pub_nic_l3uuid_list
    assert vr_l3_vm.get_vm().vmNics[0].l3NetworkUuid in pub_nic_l3uuid_list

    pub_l3_vm.remove_nic([nic.uuid for nic in pub_l3_vm.get_vm().vmNics if nic.l3NetworkUuid == flat_l3_vm.get_vm().vmNics[0].l3NetworkUuid][0])
    pub_l3_vm.remove_nic([nic.uuid for nic in pub_l3_vm.get_vm().vmNics if nic.l3NetworkUuid == vr_l3_vm.get_vm().vmNics[0].l3NetworkUuid][0])
    assert len(pub_l3_vm.get_vm().vmNics) == 1

    for action in ('update', 'stop', 'start', 'check'):
        getattr(pub_l3_vm, action)()
def test():
    global test_obj_dict

    pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE)
    if pss[0].type != "LocalStorage":
        test_util.test_skip("this test is designed to run on localstorage, skip on other ps type.")    

    l3_name = os.environ.get('l3VlanNetwork3')
    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")


    vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)
    vm.check()

    vm_nic_uuid = vm.vm.vmNics[0].uuid
    net_ops.detach_l3(vm_nic_uuid)

    vm.stop()
    vm.check()

    #test_stub.migrate_vm_to_random_host(vm)
    target_host = test_lib.lib_find_random_host(vm.vm)
    vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid)

    l3_name = os.environ.get('l3VlanNetwork3')
    l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    net_ops.attach_l3(l3_uuid, vm.vm.uuid)

    vm.start()
    vm.check()

    test_util.test_pass('test detach l3, migrate and attaching passed.')
Exemplo n.º 6
0
 def add_nic(self, l3_uuid):
     '''
     Add a new NIC device to VM. The NIC device will connect with l3_uuid.
     '''
     self.vm = net_ops.attach_l3(l3_uuid, self.get_vm().uuid)
     return self.get_vm()
Exemplo n.º 7
0
 def add_nic(self, l3_uuid):
     '''
     Add a new NIC device to VM. The NIC device will connect with l3_uuid.
     '''
     self.inv = net_ops.attach_l3(l3_uuid, self.inv.uuid)
def common_operations(vm,bss,status):

   vm_uuid = vm.get_vm().uuid 
   #image operations
   vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
   root_volume_uuid = vm_root_volume_inv.uuid
   image_option = test_util.ImageOption()
   image_option.set_root_volume_uuid(root_volume_uuid)
   image_option.set_name('image_base_on_%s_vm' % status)
   image_option.set_backup_storage_uuid_list([bss[0].uuid])
   image = img_ops.create_root_volume_template(image_option)
   test_util.test_logger('create image success')
   image_base_on_stopped_vm_uuid = test_lib.lib_get_image_by_name("image_base_on_%s_vm" % status).uuid
   base_on_image_vm = test_stub.create_vm(image_uuid=image_base_on_stopped_vm_uuid)
   vm_ops.destroy_vm(base_on_image_vm.get_vm().uuid)
   vm_ops.expunge_vm(base_on_image_vm.get_vm().uuid)

   #volume operations
   volume = test_stub.create_volume()
   vol_uuid = volume.get_volume().uuid
   test_lib.lib_attach_volume(vol_uuid, vm_uuid)
   test_util.test_logger('attach volume success')
   vm_ops.set_vm_disk_qos(vol_uuid,'20480')
   test_util.test_logger('set volume qos success')
   vm_ops.del_vm_disk_qos(vol_uuid)
   test_util.test_logger('delete volume qos success')
   test_lib.lib_detach_volume(vol_uuid)
   test_util.test_logger('detach volume success')
   test_lib.lib_delete_volume(vol_uuid)
   test_util.test_logger('delete volume success')

   #network operations
   nic_uuid = vm.get_vm().vmNics[0].uuid
   l3_uuid = test_lib.lib_get_random_l3(zone_uuid = vm.get_vm().zoneUuid).uuid
   test_util.test_logger("l3_uuid:%s"% l3_uuid)
   net_ops.detach_l3(nic_uuid)
   test_util.test_logger("l3_uuid:%s"% l3_uuid)
   net_ops.attach_l3(l3_uuid,vm_uuid)

   vm_uuid = vm.get_vm().uuid
   #set/del console password
   console_ops.set_vm_console_password(vm_uuid,'testpassword')
   console_ops.delete_vm_console_password(vm_uuid)

   #add/del sshkey
   sshkeyimage_uuid = test_lib.lib_get_image_by_name('sshkeyimage').uuid
   sshkey_vm = test_stub.create_vm(image_uuid = sshkeyimage_uuid)
   sshkey_vm_uuid = sshkey_vm.get_vm().uuid
   test_lib.lib_add_vm_sshkey(sshkey_vm_uuid,'testsshkey')
   vm_ops.delete_vm_ssh_key(sshkey_vm_uuid)
   vm_ops.destroy_vm(sshkey_vm_uuid)
   vm_ops.expunge_vm(sshkey_vm_uuid)

   #change owner
   account_name = uuid.uuid1().get_hex()
   account_pass = uuid.uuid1().get_hex()
   #account_pass = hashlib.sha512(account_name).hexdigest()
   test_account = account_operations.create_normal_account(account_name,account_pass)
   test_account_uuid = test_account.uuid
   admin_uuid = res_ops.get_resource_owner([vm_uuid])
   res_ops.change_recource_owner(test_account_uuid,vm_uuid)
   res_ops.change_recource_owner(admin_uuid,vm_uuid)
   account_operations.delete_account(test_account_uuid)

   #create/delete user tag
   tag = tag_ops.create_user_tag('VmInstanceVO',vm_uuid,'a simulator vm')
   tag_ops.delete_tag(tag.uuid)
      
   #set vm monitor number
   vm_ops.set_vm_monitor_number(vm_uuid,'2')

   #set vm usb redirect
   vm_ops.set_vm_usb_redirect(vm_uuid,'true')
   vm_ops.set_vm_usb_redirect(vm_uuid,'false')

   #set vm rdp
   vm_ops.set_vm_rdp(vm_uuid,'true')
   vm_ops.set_vm_rdp(vm_uuid,'false')
def test():
    test_util.test_dsc('Create vrouter vm and check multi nics')
    vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm1)
    vm1_ip = vm1.get_vm().vmNics[0].ip
    vm1_nic_uuid = vm1.get_vm().vmNics[0].uuid
    vr1 = test_lib.lib_find_vr_by_vm(vm1.vm)[0]
    vr1_uuid = vr1.uuid
    vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1)
    vr1_private_ip = test_lib.lib_find_vr_private_ip(vr1)
    l3network1_uuid = vm1.get_vm().vmNics[0].l3NetworkUuid
    cond = res_ops.gen_query_conditions('uuid', '=', l3network1_uuid)
    l3network1_cidr = res_ops.query_resource(res_ops.L3_NETWORK,
                                             cond)[0].ipRanges[0].networkCidr

    cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid)
    vr_offering_mn_network_uuid = res_ops.query_resource(
        res_ops.APPLIANCE_VM, cond)[0].managementNetworkUuid
    vr1_pub_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM,
                                          cond)[0].managementNetworkUuid
    vr_offering_image_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM,
                                                    cond)[0].imageUuid
    vr_offering_zone_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM,
                                                   cond)[0].zoneUuid
    vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics

    cond = res_ops.gen_query_conditions('name', '=',
                                        os.environ.get('l3PublicNetworkName'))
    public_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK,
                                                   cond)[0].uuid
    cond = res_ops.gen_query_conditions('name', '=',
                                        os.environ.get('l3NoVlanNetworkName1'))
    second_public_l3network_uuid = res_ops.query_resource(
        res_ops.L3_NETWORK, cond)[0].uuid
    second_public_l3network_cidr = res_ops.query_resource(
        res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr

    #Attach second public network to vrouter
    second_public_l3network_attached = False
    for vm_nic in vr1_nics:
        if vm_nic.l3NetworkUuid == second_public_l3network_uuid:
            second_public_l3network_attached = True
    if not second_public_l3network_attached:
        net_ops.attach_l3(second_public_l3network_uuid, vr1_uuid)

    #Get vr1 nic_uuid on second public network
    cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid)
    vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics
    vr1_second_pub_nic_uuid = ''
    for vm_nic in vr1_nics:
        if vm_nic.l3NetworkUuid == second_public_l3network_uuid:
            vr1_second_pub_nic_uuid = vm_nic.uuid
    #Create new vrouter offering
    vr_offering_name = "virtual_router_offering1"
    vr_offering_cpu_num = 2
    vr_offering_mem_size = 536870912  #512MB
    vr_offering = net_ops.create_virtual_router_offering(
        vr_offering_name, vr_offering_cpu_num, vr_offering_mem_size,
        vr_offering_image_uuid, vr_offering_zone_uuid,
        vr_offering_mn_network_uuid, second_public_l3network_uuid)

    vr_offering_uuid = vr_offering.uuid
    cond = res_ops.gen_query_conditions('name', '=',
                                        os.environ.get('l3VlanNetworkName4'))
    user_defined_l3network_uuid = res_ops.query_resource(
        res_ops.L3_NETWORK, cond)[0].uuid

    #Attach Virtual Router Offering
    tag = tag_ops.create_system_tag(
        'InstanceOfferingVO', vr_offering_uuid,
        'guestL3Network::%s' % user_defined_l3network_uuid)

    #Create vms for each public network eip attach
    vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName'))
    vm2_ip = vm2.get_vm().vmNics[0].ip
    vm2_nic_uuid = vm2.get_vm().vmNics[0].uuid
    l3network2_uuid = vm2.get_vm().vmNics[0].l3NetworkUuid
    vm3 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4'))
    vm3_ip = vm3.get_vm().vmNics[0].ip
    vm3_nic_uuid = vm3.get_vm().vmNics[0].uuid
    l3network3_uuid = vm3.get_vm().vmNics[0].l3NetworkUuid

    #Create eip for each vms, vm1 has 2 eip on each public network
    vip11 = test_stub.create_vip('vm1_vip1', public_l3network_uuid)
    vip11_uuid = vip11.get_vip().uuid
    eip11 = test_stub.create_eip('vm1_eip1', vip11_uuid, vm_obj=vm1)
    vip11.attach_eip(eip11)
    eip11_pub_ip = eip11.get_eip().vipIp
    vip11.check()
    eip11.attach(vm1_nic_uuid, vm1)
    vip12 = test_stub.create_vip('vm1_vip2', second_public_l3network_uuid)
    vip12_uuid = vip12.get_vip().uuid
    eip12 = test_stub.create_eip('vm1_eip2', vip12_uuid, vm_obj=vm1)
    vip12.attach_eip(eip12)
    eip12_pub_ip = eip12.get_eip().vipIp
    vip12.check()
    eip12.attach(vm1_nic_uuid, vm1)
    vip2 = test_stub.create_vip('vm2_vip', public_l3network_uuid)
    vip2_uuid = vip2.get_vip().uuid
    eip2 = test_stub.create_eip('vm2_eip', vip2_uuid, vm_obj=vm2)
    vip2.attach_eip(eip2)
    eip2_pub_ip = eip2.get_eip().vipIp
    vip2.check()
    eip2.attach(vm2_nic_uuid, vm2)
    vip3 = test_stub.create_vip('vm3_vip', second_public_l3network_uuid)
    vip3_uuid = vip3.get_vip().uuid
    eip3 = test_stub.create_eip('vm3_eip', vip3_uuid, vm_obj=vm3)
    vip3.attach_eip(eip3)
    eip3_pub_ip = eip3.get_eip().vipIp
    vip3.check()
    eip3.attach(vm3_nic_uuid, vm3)

    #Check if the network is able to ping with eip
    user_name = "root"
    user_password = "******"
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" %
                         (user_password, user_name, vm1_ip, eip2_pub_ip))
    if rsp_ping != 0:
        if vr1_second_pub_nic_uuid != '':
            net_ops.detach_l3(vr1_second_pub_nic_uuid)
        test_util.test_fail(
            'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.'
            % (vm1_ip, eip2_pub_ip))
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" %
                         (user_password, user_name, vm1_ip, eip3_pub_ip))
    if rsp_ping != 0:
        if vr1_second_pub_nic_uuid != '':
            net_ops.detach_l3(vr1_second_pub_nic_uuid)
        test_util.test_fail(
            'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.'
            % (vm1_ip, eip3_pub_ip))
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" %
                         (user_password, user_name, vm2_ip, eip11_pub_ip))
    if rsp_ping != 0:
        if vr1_second_pub_nic_uuid != '':
            net_ops.detach_l3(vr1_second_pub_nic_uuid)
        test_util.test_fail(
            'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.'
            % (vm2_ip, eip11_pub_ip))
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" %
                         (user_password, user_name, vm3_ip, eip12_pub_ip))
    if rsp_ping != 0:
        if vr1_second_pub_nic_uuid != '':
            net_ops.detach_l3(vr1_second_pub_nic_uuid)
        test_util.test_fail(
            'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.'
            % (vm3_ip, eip12_pub_ip))

    #Delete vips and vr offering
    vip11.delete()
    vip12.delete()
    vip2.delete()
    vip3.delete()
    vm_ops.delete_instance_offering(vr_offering_uuid)

    #Dettach the route table to vrouter and second public nework
    if vr1_second_pub_nic_uuid != '':
        net_ops.detach_l3(vr1_second_pub_nic_uuid)

    vm1.destroy()
    vm2.destroy()
    vm3.destroy()
    net_ops.destroy_vrouter(vr1_uuid)
    test_util.test_pass('Check Multi Nics Success')
def common_operations(vm, bss, status):

    vm_uuid = vm.get_vm().uuid
    #image operations
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    root_volume_uuid = vm_root_volume_inv.uuid
    image_option = test_util.ImageOption()
    image_option.set_root_volume_uuid(root_volume_uuid)
    image_option.set_name('image_base_on_%s_vm' % status)
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image = img_ops.create_root_volume_template(image_option)
    test_util.test_logger('create image success')
    image_base_on_stopped_vm_uuid = test_lib.lib_get_image_by_name(
        "image_base_on_%s_vm" % status).uuid
    base_on_image_vm = test_stub.create_vm(
        image_uuid=image_base_on_stopped_vm_uuid)
    vm_ops.destroy_vm(base_on_image_vm.get_vm().uuid)
    vm_ops.expunge_vm(base_on_image_vm.get_vm().uuid)

    #volume operations
    volume = test_stub.create_volume()
    vol_uuid = volume.get_volume().uuid
    test_lib.lib_attach_volume(vol_uuid, vm_uuid)
    test_util.test_logger('attach volume success')
    vm_ops.set_vm_disk_qos(vol_uuid, '20480')
    test_util.test_logger('set volume qos success')
    vm_ops.del_vm_disk_qos(vol_uuid)
    test_util.test_logger('delete volume qos success')
    test_lib.lib_detach_volume(vol_uuid)
    test_util.test_logger('detach volume success')
    test_lib.lib_delete_volume(vol_uuid)
    test_util.test_logger('delete volume success')

    #network operations
    nic_uuid = vm.get_vm().vmNics[0].uuid
    l3_uuid = test_lib.lib_get_random_l3(zone_uuid=vm.get_vm().zoneUuid).uuid
    test_util.test_logger("l3_uuid:%s" % l3_uuid)
    net_ops.detach_l3(nic_uuid)
    test_util.test_logger("l3_uuid:%s" % l3_uuid)
    net_ops.attach_l3(l3_uuid, vm_uuid)

    vm_uuid = vm.get_vm().uuid
    #set/del console password
    console_ops.set_vm_console_password(vm_uuid, 'testpassword')
    console_ops.delete_vm_console_password(vm_uuid)

    #add/del sshkey
    sshkeyimage_uuid = test_lib.lib_get_image_by_name('sshkeyimage').uuid
    sshkey_vm = test_stub.create_vm(image_uuid=sshkeyimage_uuid)
    sshkey_vm_uuid = sshkey_vm.get_vm().uuid
    test_lib.lib_add_vm_sshkey(sshkey_vm_uuid, 'testsshkey')
    vm_ops.delete_vm_ssh_key(sshkey_vm_uuid)
    vm_ops.destroy_vm(sshkey_vm_uuid)
    vm_ops.expunge_vm(sshkey_vm_uuid)

    #change owner
    account_name = uuid.uuid1().get_hex()
    account_pass = uuid.uuid1().get_hex()
    #account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = account_operations.create_normal_account(
        account_name, account_pass)
    test_account_uuid = test_account.uuid
    admin_uuid = res_ops.get_resource_owner([vm_uuid])
    res_ops.change_recource_owner(test_account_uuid, vm_uuid)
    res_ops.change_recource_owner(admin_uuid, vm_uuid)
    account_operations.delete_account(test_account_uuid)

    #create/delete user tag
    tag = tag_ops.create_user_tag('VmInstanceVO', vm_uuid, 'a simulator vm')
    tag_ops.delete_tag(tag.uuid)

    #set vm monitor number
    vm_ops.set_vm_monitor_number(vm_uuid, '2')

    #set vm usb redirect
    vm_ops.set_vm_usb_redirect(vm_uuid, 'true')
    vm_ops.set_vm_usb_redirect(vm_uuid, 'false')

    #set vm rdp
    vm_ops.set_vm_rdp(vm_uuid, 'true')
    vm_ops.set_vm_rdp(vm_uuid, 'false')
Exemplo n.º 11
0
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')

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    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 tracepath in [vm:] %s" %
                            (vm.get_vm().uuid))
    os.unlink(script_file.name)

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('''
while [ 1 -eq 1 ]; do
	route -n | grep 0.0.0.0
	if [ $? -ne 0 ]; then
		pkill dhclient
		dhclient
	fi
	sleep 40
done
''')
    script_file.close()
    try:
        test_lib.lib_execute_shell_script_in_vm(vm.get_vm(),
                                                script_file.name,
                                                timeout=2)
    except:
        test_util.test_logger('ignore')
    os.unlink(script_file.name)

    net_ops.detach_l3(vm_nic_uuid)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail(
            'expected to not be able to ping vip while it success')

    #vm.stop()
    net_ops.attach_l3(pri_l3_uuid, vm.get_vm().uuid)

    #vm.start()
    vm.check()
    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    net_ops.attach_eip(eip.get_eip().uuid, vm_nic_uuid)
    vm.check()
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    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 tracepath in [vm:] %s" %
                            (vm.get_vm().uuid))
    os.unlink(script_file.name)

    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')
Exemplo n.º 12
0
 def add_nic(self, l3_uuid):
     '''
     Add a new NIC device to VM. The NIC device will connect with l3_uuid.
     '''
     self.inv = net_ops.attach_l3(l3_uuid, self.inv.uuid)
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')

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    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 tracepath in [vm:] %s" % (vm.get_vm().uuid))
    os.unlink(script_file.name)

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('''
while [ 1 -eq 1 ]; do
	route -n | grep 0.0.0.0
	if [ $? -ne 0 ]; then
		pkill dhclient
		dhclient
	fi
	sleep 40
done
''')
    script_file.close()
    try:
        test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name, timeout=2)
    except:
        test_util.test_logger('ignore')
    os.unlink(script_file.name)

    net_ops.detach_l3(vm_nic_uuid)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to not be able to ping vip while it success')

    #vm.stop()
    net_ops.attach_l3(pri_l3_uuid, vm.get_vm().uuid)

    #vm.start()
    vm.check()
    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    net_ops.attach_eip(eip.get_eip().uuid, vm_nic_uuid)
    vm.check()
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    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 tracepath in [vm:] %s" % (vm.get_vm().uuid))
    os.unlink(script_file.name)

    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('Create vrouter vm and check multi nics')
    vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm1)
    vm1_ip = vm1.get_vm().vmNics[0].ip
    vm1_nic_uuid = vm1.get_vm().vmNics[0].uuid
    vr1 = test_lib.lib_find_vr_by_vm(vm1.vm)[0]
    vr1_uuid = vr1.uuid
    vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1)
    vr1_private_ip = test_lib.lib_find_vr_private_ip(vr1)
    l3network1_uuid = vm1.get_vm().vmNics[0].l3NetworkUuid
    cond = res_ops.gen_query_conditions('uuid', '=', l3network1_uuid)
    l3network1_cidr = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr

    cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid)
    vr_offering_mn_network_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].managementNetworkUuid
    vr1_pub_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].managementNetworkUuid
    vr_offering_image_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].imageUuid
    vr_offering_zone_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].zoneUuid
    vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics

    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3PublicNetworkName'))
    public_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid
    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3NoVlanNetworkName1'))
    second_public_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid
    second_public_l3network_cidr = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr

    #Attach second public network to vrouter
    second_public_l3network_attached = False
    for vm_nic in vr1_nics:
        if vm_nic.l3NetworkUuid == second_public_l3network_uuid:
            second_public_l3network_attached = True
    if not second_public_l3network_attached:
        net_ops.attach_l3(second_public_l3network_uuid, vr1_uuid) 

    #Get vr1 nic_uuid on second public network
    cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid)
    vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics
    vr1_second_pub_nic_uuid = ''
    for vm_nic in vr1_nics:
        if vm_nic.l3NetworkUuid == second_public_l3network_uuid:
           vr1_second_pub_nic_uuid = vm_nic.uuid
    #Create new vrouter offering
    vr_offering_name = "virtual_router_offering1"
    vr_offering_cpu_num = 2
    vr_offering_mem_size = 536870912 #512MB
    vr_offering = net_ops.create_virtual_router_offering(vr_offering_name, vr_offering_cpu_num, vr_offering_mem_size, vr_offering_image_uuid, vr_offering_zone_uuid, vr_offering_mn_network_uuid, second_public_l3network_uuid)

    vr_offering_uuid = vr_offering.uuid
    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3VlanNetworkName4'))
    user_defined_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid

    #Attach Virtual Router Offering
    tag = tag_ops.create_system_tag('InstanceOfferingVO',vr_offering_uuid, 'guestL3Network::%s' % user_defined_l3network_uuid)

    #Create vms for each public network eip attach
    vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName'))
    vm2_ip = vm2.get_vm().vmNics[0].ip
    vm2_nic_uuid = vm2.get_vm().vmNics[0].uuid
    l3network2_uuid = vm2.get_vm().vmNics[0].l3NetworkUuid
    vm3 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4'))
    vm3_ip = vm3.get_vm().vmNics[0].ip
    vm3_nic_uuid = vm3.get_vm().vmNics[0].uuid
    l3network3_uuid = vm3.get_vm().vmNics[0].l3NetworkUuid    

    #Create eip for each vms, vm1 has 2 eip on each public network
    vip11 = test_stub.create_vip('vm1_vip1', public_l3network_uuid)
    vip11_uuid = vip11.get_vip().uuid
    eip11 = test_stub.create_eip('vm1_eip1', vip11_uuid, vm_obj=vm1)
    vip11.attach_eip(eip11)
    eip11_pub_ip = eip11.get_eip().vipIp
    vip11.check()
    eip11.attach(vm1_nic_uuid, vm1)
    vip12 = test_stub.create_vip('vm1_vip2', second_public_l3network_uuid)
    vip12_uuid = vip12.get_vip().uuid
    eip12 = test_stub.create_eip('vm1_eip2', vip12_uuid, vm_obj=vm1)
    vip12.attach_eip(eip12)
    eip12_pub_ip = eip12.get_eip().vipIp
    vip12.check()
    eip12.attach(vm1_nic_uuid, vm1)
    vip2 = test_stub.create_vip('vm2_vip', public_l3network_uuid)
    vip2_uuid = vip2.get_vip().uuid
    eip2 = test_stub.create_eip('vm2_eip', vip2_uuid, vm_obj=vm2)
    vip2.attach_eip(eip2)
    eip2_pub_ip = eip2.get_eip().vipIp
    vip2.check()
    eip2.attach(vm2_nic_uuid, vm2)
    vip3 = test_stub.create_vip('vm3_vip', second_public_l3network_uuid)
    vip3_uuid = vip3.get_vip().uuid
    eip3 = test_stub.create_eip('vm3_eip', vip3_uuid, vm_obj=vm3)
    vip3.attach_eip(eip3)
    eip3_pub_ip = eip3.get_eip().vipIp
    vip3.check()
    eip3.attach(vm3_nic_uuid, vm3)
    
    time.sleep(40) #waiting for eip binding

    #Check if the network is able to ping with eip
    user_name = "root"
    user_password = "******"
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm1_ip, eip2_pub_ip))
    if rsp_ping != 0:
        test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm1_ip, eip2_pub_ip))
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm1_ip, eip3_pub_ip))
    if rsp_ping != 0:
        test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm1_ip, eip3_pub_ip))
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm2_ip, eip11_pub_ip))
    if rsp_ping != 0:
        test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm2_ip, eip11_pub_ip))
    rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm3_ip, eip12_pub_ip))
    if rsp_ping != 0:
        test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm3_ip, eip12_pub_ip))

    #Delete vips and vr offering
    vip11.delete()
    vip12.delete()
    vip2.delete()
    vip3.delete()
    vm_ops.delete_instance_offering(vr_offering_uuid)

    #Dettach the route table to vrouter and second public nework
    if vr1_second_pub_nic_uuid != '':
        net_ops.detach_l3(vr1_second_pub_nic_uuid)

    vm1.destroy()
    vm2.destroy()
    vm3.destroy()
    net_ops.destroy_vrouter(vr1_uuid)
    test_util.test_pass('Check Multi Nics Success')
def test():
    test_util.test_logger("start dhcp test for l3 public network")

    test_util.test_dsc("get no vlan network uuid")
    private_vpcnetwork = test_stub_dhcp.VpcNetwork_IP_For_Dhcp()
    private_vpcnetwork.set_l2_query_resource(l2_query_resource)
    private_vpcnetwork.set_l2_type(type_l2[1])
    l2_no_vlan_uuid = private_vpcnetwork.get_l2uuid()
    test_util.test_logger("antony @@@debug : %s" % (l2_no_vlan_uuid))

    test_util.test_logger("create l3 network")
    private_vpcnetwork.set_ipVersion(ip_Version[0])
    private_vpcnetwork.create_l3uuid(l3_name)
    test_util.test_logger(
        "antony @@@debug : %s" %
        (private_vpcnetwork.get_l3uuid()))
    private_vpcnetwork.add_service_to_l3_vpcnetwork()

    test_util.test_logger("add ip v4 range to l3 network")
    private_vpcnetwork.add_ip_range(
        ip_range_name,
        start_ip,
        endip,
        gate_way,
        net_mask,
        dhcp_system_tags)
    if private_vpcnetwork.check_dhcp_ipaddress().find(dhcp_ip_for_private_vpc) == -1:
        test_util.test_fail("dhcp server ip create fail")

    test_util.test_logger("add extra networksegment")
    private_vpcnetwork.add_ip_range(
        ip_range_name,
        start_ip1,
        end_ip1,
        gate_way,
        net_mask)

    test_util.test_logger("crete vpc vrouter")
    vm_object = test_stub_dhcp.Create_Vm_Instance()
    vm_object.create_vpc_vrouter()
    net_ops.attach_l3(
        private_vpcnetwork.get_l3uuid(),
        vm_object.get_vr_inv().uuid)

    list_vm = []
    for i in range(0, len(ip_range_for_private_vpc) +
                   len(ip_range_for_networksegment) - 1):
        list_vm.append(vm_object.create_vm(private_vpcnetwork.get_l3uuid()))

    try:
        vm_object.create_vm(private_vpcnetwork.get_l3uuid())
    except BaseException:
        test_util.test_logger("Catch expected exception,try to delete vm")

        test_util.test_logger("delete vm")
        for vm in list_vm:
            vm.clean()
        test_util.test_logger("delete l3 network")
        private_vpcnetwork.del_l3uuid()
        vm_object.delete_vpc_vrouter()
        test_util.test_pass("test dhcp server pass")

    test_util.test_fail("dhcp server ip create successfully")