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 = 1
    cpuSpeed = 222
    memorySize = 666 * 1024 * 1024
    new_offering = test_lib.lib_create_instance_offering(cpuNum = cpuNum,\
            cpuSpeed = cpuSpeed, memorySize = memorySize)
    test_obj_dict.add_instance_offering(new_offering)
    new_offering_uuid = new_offering.uuid
    vm.change_instance_offering(new_offering_uuid)
    vm.check()
    test_lib.lib_execute_command_in_vm(vm.get_vm(), 'ls -d /sys/devices/system/cpu/cpu*')
    test_lib.lib_execute_command_in_vm(vm.get_vm(), 'ls -d /sys/devices/system/memory/memory*')

    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('VM online change instance offering Test Pass')
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')
예제 #3
0
def test():
    global test_obj_dict, VM_RUNGGING_OPS, VM_STOPPED_OPS, VM_STATE_OPS, backup

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]
    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        VM_RUNGGING_OPS.append("VM_TEST_MIGRATE")
        VM_STOPPED_OPS.append("VM_TEST_MIGRATE")
    else:
        VM_RUNGGING_OPS.append("VM_TEST_MIGRATE")

    vm_name = "test_vm"
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate",
                                        cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    vm = test_stub.create_vm(vm_name, img_name, l3_name)

    i = 0
    while True:
        i += 1
        if i == 10:
            vm_op_test(vm, "VM_TEST_STOP")
            vm_op_test(vm, "VM_TEST_RESET")
            vm.start()
            time.sleep(60)
            vm.check()
            i = 0

        vm_op_test(vm, random.choice(VM_STATE_OPS))
        VM_OPS = VM_STATE_OPS
        if vm.state == "Running":
            VM_OPS = VM_RUNGGING_OPS
            if not backup_list:
                VM_OPS.remove("VM_TEST_BACKUP_IMAGE")
        elif vm.state == "Stopped":
            VM_OPS = VM_STOPPED_OPS
            if not backup_list:
                VM_OPS.remove("VM_TEST_REVERT_BACKUP")
                VM_OPS.remove("VM_TEST_BACKUP_IMAGE")

        vm_op_test(vm, random.choice(VM_OPS))

        if vm.state == "Stopped":
            vm.start()

        if test_lib.lib_is_vm_l3_has_vr(vm.vm):
            test_lib.TestHarness = test_lib.TestHarnessVR
        time.sleep(60)
        cmd = "echo 111 > /root/" + str(int(time.time()))
        test_lib.lib_execute_command_in_vm(vm.vm, cmd)
        vm.suspend()
        # create_snapshot/backup
        vm_op_test(vm, "VM_TEST_BACKUP")
        # compare vm & image created by backup
        compare(ps, vm, backup)

        vm.resume()
def test():
    vm = test_stub.create_user_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    out = test_lib.lib_execute_command_in_vm(vm.get_vm(), 'ps -ef |grep qemu-ga | grep -v grep')
    if not out.find('qemu-ga'):
        test_util.test_skip('qemu-ga not running on VM, skip testing')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid)
    if time.time()-current_time >= 10:
        test_util.test_fail("VM should shutdown with default grace method in %s seconds" % (time.time()-current_time))
    vm.set_state(vm_header.STOPPED)
    vm.check()

    vm.start()
    vm.check()
    test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid, force='cold')
    if time.time()-current_time >= 5:
        test_util.test_fail("VM should shutdown immediately with cold method, while it taks %s seconds" % (time.time()-current_time))

    vm.set_state(vm_header.STOPPED)
    vm.check()
  
    vm.destroy()
    test_util.test_pass('Stop VM with qemu-guest-agent 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')
def test():
    vm = test_stub.create_user_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    out = test_lib.lib_execute_command_in_vm(vm.get_vm(), 'ps -ef |grep qemu-ga | grep -v grep')
    if not out.find('qemu-ga'):
        test_util.test_skip('qemu-ga not running on VM, skip testing')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid)
    if time.time()-current_time >= 20:
        test_util.test_fail("VM should shutdown with default grace method in %s seconds" % (time.time()-current_time))
    vm.set_state(vm_header.STOPPED)
    vm.check()

    vm.start()
    vm.check()
    test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid, force='cold')
    if time.time()-current_time >= 5:
        test_util.test_fail("VM should shutdown immediately with cold method, while it taks %s seconds" % (time.time()-current_time))

    vm.set_state(vm_header.STOPPED)
    vm.check()
  
    vm.destroy()
    test_util.test_pass('Stop VM with qemu-guest-agent Test Success')
예제 #7
0
def update_default_gw(vm_inv, gw, eth_id):
    cmd = 'ip route del 0/0'
    if not test_lib.lib_execute_command_in_vm(vm_inv, cmd):
        test_util.test_fail("fail to set default route for testing in vm")
    cmd = 'ip route add default via %s dev eth%s' % (gw, eth_id)
    if not test_lib.lib_execute_command_in_vm(vm_inv, cmd):
        test_util.test_fail("fail to set default route for testing in 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 = 1
    cpuSpeed = 222
    memorySize = 666 * 1024 * 1024
    new_offering = test_lib.lib_create_instance_offering(cpuNum = cpuNum,\
            cpuSpeed = cpuSpeed, memorySize = memorySize)
    test_obj_dict.add_instance_offering(new_offering)
    new_offering_uuid = new_offering.uuid
    vm.change_instance_offering(new_offering_uuid)
    vm.check()
    test_lib.lib_execute_command_in_vm(vm.get_vm(),
                                       'ls -d /sys/devices/system/cpu/cpu*')
    test_lib.lib_execute_command_in_vm(
        vm.get_vm(), 'ls -d /sys/devices/system/memory/memory*')

    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    vm = test_stub.create_user_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_lib.lib_execute_command_in_vm(
        vm.get_vm(),
        'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid)
    if time.time() - current_time <= 10:
        test_util.test_fail(
            "VM should not shutdown with default grace method in %s seconds" %
            (time.time() - current_time))
    vm.set_state(vm_header.STOPPED)
    vm.check()

    vm.start()
    vm.check()
    test_lib.lib_execute_command_in_vm(
        vm.get_vm(),
        'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid, force='cold')
    if time.time() - current_time >= 5:
        test_util.test_fail(
            "VM should shutdown immediately with cold method, while it taks %s seconds"
            % (time.time() - current_time))

    vm.set_state(vm_header.STOPPED)
    vm.check()

    vm.destroy()
    test_util.test_pass('Force Stop VM Test Success')
예제 #10
0
def test():
    global test_obj_dict, VM_RUNGGING_OPS, VM_STOPPED_OPS, VM_STATE_OPS, backup

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]
    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        VM_RUNGGING_OPS.append("VM_TEST_MIGRATE")
        VM_STOPPED_OPS.append("VM_TEST_MIGRATE")
    else:
        VM_RUNGGING_OPS.append("VM_TEST_MIGRATE")

    vm_name = "test_vm"
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK,cond)[0].name
    vm = test_stub.create_vm(vm_name, img_name, l3_name)

    i = 0
    while True:
        i += 1
        if i == 10:
            vm_op_test(vm, "VM_TEST_STOP")
            vm_op_test(vm, "VM_TEST_RESET")
            vm.start()
            time.sleep(60)
            vm.check()
            i = 0

        vm_op_test(vm, random.choice(VM_STATE_OPS))
        VM_OPS = VM_STATE_OPS
        if vm.state == "Running":
            VM_OPS = VM_RUNGGING_OPS
            if not backup_list:
                VM_OPS.remove("VM_TEST_BACKUP_IMAGE")
        elif vm.state == "Stopped":
            VM_OPS = VM_STOPPED_OPS
            if not backup_list:
                VM_OPS.remove("VM_TEST_REVERT_BACKUP")
                VM_OPS.remove("VM_TEST_BACKUP_IMAGE")       

        vm_op_test(vm, random.choice(VM_OPS))

        if vm.state == "Stopped":
            vm.start()

        if test_lib.lib_is_vm_l3_has_vr(vm.vm):
            test_lib.TestHarness = test_lib.TestHarnessVR
        time.sleep(60)
        cmd = "echo 111 > /root/" + str(int(time.time()))
        test_lib.lib_execute_command_in_vm(vm.vm,cmd)
        vm.suspend()
        # create_snapshot/backup
        vm_op_test(vm, "VM_TEST_BACKUP")
        # compare vm & image created by backup
        compare(ps, vm, backup)

        vm.resume()
def test():
    global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]

    vm_name = "test_vm"
    utility_vm_name = "utility_vm"

    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate",
                                        cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    disk_offering_uuids = [disk_offering.uuid]
    vm = test_stub.create_vm(vm_name,
                             img_name,
                             l3_name,
                             disk_offering_uuids=disk_offering_uuids)
    utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name)

    dvol = zstack_volume_header.ZstackTestVolume()
    dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0])
    dvol.set_state(volume_header.ATTACHED)
    dvol.set_target_vm(vm)

    while True:
        OPS = VOL_OPS + VM_STATE_OPS
        if not backup_list:
            OPS.remove("VM_TEST_BACKUP_IMAGE")

        dvol = zstack_volume_header.ZstackTestVolume()
        dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0])
        dvol.set_state(volume_header.ATTACHED)
        dvol.set_target_vm(vm)

        vm_op_test(vm, dvol, random.choice(OPS))

        if vm.state == "Stopped":
            if backup_list:
                vm_op_test(vm, dvol, "VM_TEST_REVERT_BACKUP")
            vm.start()

        if test_lib.lib_is_vm_l3_has_vr(vm.vm):
            test_lib.TestHarness = test_lib.TestHarnessVR
        time.sleep(60)

        cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1"
        test_lib.lib_execute_command_in_vm(vm.vm, cmd)

        vm.suspend()
        vm_op_test(vm, dvol, "DVOL_BACKUP")
        compare(ps, vm, dvol, backup)

        vm.resume()
예제 #12
0
def test():
    global vm
    global default_mode
#    default_mode = conf_ops.get_global_config_value('kvm', 'videoType')
    default_mode = conf_ops.change_global_config('vm', 'videoType', 'qxl')
    vm = test_stub.create_sg_vm()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid)
    test_util.test_logger('[vm:] %s console is on %s:%s' % (vm.get_vm().uuid, console.hostIp, console.port))
    display = str(int(console.port)-5900)
    vm.check()
    vm_mode = test_lib.lib_get_vm_video_type(vm.get_vm())
    if vm_mode != 'qxl':
        test_util.test_fail('VM is expected to work in qxl mode instead of %s' % (vm_mode))
    client = api.connect(console.hostIp+":"+display)
    client.captureScreen('tmp.png')
    image = Image.open('tmp.png')
    if image.width != 720 or image.height != 400:
        test_util.test_fail("VM is expected to work in 720x400 while its %sx%s" % (image.width, image.height))
    box = image.getbbox()
    if box != (0, 18, 403, 79) and box != (0, 18, 403, 80):
        test_util.test_fail("VM is expected to display text in area (0, 18, 403, 79) while it's actually: (%s, %s, %s, %s)" % (box[0], box[1], box[2], box[3]))

    test_util.test_logger('[vm:] change vga mode to vga=794 which is 1280x1024')
    cmd = 'sed -i "s/115200$/115200 vga=794/g" /boot/grub2/grub.cfg'
    test_lib.lib_execute_command_in_vm(vm.get_vm(), cmd)
    vm.reboot()
    vm.check()
    client = api.connect(console.hostIp+":"+display)
    client.captureScreen('tmp.png')
    image = Image.open('tmp.png')
    if image.width != 1280 or image.height != 1024:
        test_util.test_fail("VM is expected to work in 1280x1024 while its %sx%s" % (image.width, image.height))
    box = image.getbbox()
    if box != (0, 18, 359, 79) and box != (0, 18, 359, 80):
        test_util.test_fail("VM is expected to display text in area (0, 18, 359, 79) while it's actually: (%s, %s, %s, %s)" % (box[0], box[1], box[2], box[3]))

    test_util.test_logger('[vm:] change vga mode to vga=907 which is 2560x1600')
    cmd = 'sed -i "s/vga=794/vga=907/g" /boot/grub2/grub.cfg'
    test_lib.lib_execute_command_in_vm(vm.get_vm(), cmd)
    vm.reboot()
    vm.check()
    client = api.connect(console.hostIp+":"+display)
    client.captureScreen('tmp.png')
    image = Image.open('tmp.png')
    if image.width != 2560 or image.height != 1600:
        test_util.test_fail("VM is expected to work in 2560x1600 while its %sx%s" % (image.width, image.height))
    box = image.getbbox()
    if box != (0, 18, 359, 79) and box != (0, 18, 359, 80):
        test_util.test_fail("VM is expected to display text in area (0, 18, 359, 79) while it's actually: (%s, %s, %s, %s)" % (box[0], box[1], box[2], box[3]))

    vm.destroy()
    vm.check()
    conf_ops.change_global_config('vm', 'videoType', default_mode)
    test_util.test_pass('Create VM Test Success')
def test():
    global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]

    vm_name = "test_vm"
    utility_vm_name = "utility_vm"
    
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    disk_offering_uuids = [disk_offering.uuid]
    vm = test_stub.create_vm(vm_name, img_name, l3_name, disk_offering_uuids=disk_offering_uuids)
    utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name)

    dvol = zstack_volume_header.ZstackTestVolume()
    dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0])
    dvol.set_state(volume_header.ATTACHED)
    dvol.set_target_vm(vm)

    while True:
        OPS = VOL_OPS + VM_STATE_OPS
        if not backup_list:
            OPS.remove("VM_TEST_BACKUP_IMAGE")

        dvol = zstack_volume_header.ZstackTestVolume()
        dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0])
        dvol.set_state(volume_header.ATTACHED)
        dvol.set_target_vm(vm)


        vm_op_test(vm, dvol, random.choice(OPS))

        if vm.state == "Stopped":
            if backup_list:
                vm_op_test(vm, dvol, "VM_TEST_REVERT_BACKUP")
            vm.start()

	if test_lib.lib_is_vm_l3_has_vr(vm.vm):
            test_lib.TestHarness = test_lib.TestHarnessVR
        time.sleep(60)
        
        cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1" 
	test_lib.lib_execute_command_in_vm(vm.vm,cmd)

        vm.suspend()
        vm_op_test(vm, dvol, "DVOL_BACKUP")
        compare(ps, vm, dvol, backup)

        vm.resume()
def test():
    global sftp_backup_storage_uuid
    global sftp_backup_storage_hostname
    global recnt_timeout
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    if res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE, conditions):
        sftp_backup_storage_uuid = res_ops.query_resource(
            res_ops.SFTP_BACKUP_STORAGE, conditions)[0].uuid
        sftp_backup_storage_hostname = res_ops.query_resource(
            res_ops.SFTP_BACKUP_STORAGE, conditions)[0].hostname
    else:
        test_util.test_skip(
            "current test suite is for ceph, and there is no sftp. Skip test")

    local_ip = socket.gethostbyname(socket.gethostname())
    sftp_hostname = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE,
                                           conditions)[0].hostname
    test_util.test_dsc("local ip:%s, sftp ip:%s" % (local_ip, sftp_hostname))
    if local_ip != sftp_hostname:
        test_util.test_skip(
            "host of sftp and host of MN are not the same one. Skip test")

    test_util.test_dsc('Test SFTP Backup Storage Update Infomation: hostname')

    test_util.test_dsc('Update Hostname')
    test_util.test_dsc('Create New VM as Sftp')
    vm = test_stub.create_basic_vm()
    test_obj_dict.add_vm(vm)

    vm_inv = vm.get_vm()
    vm_ip = vm_inv.vmNics[0].ip

    vm.check()
    test_lib.lib_execute_command_in_vm(vm.get_vm(),
                                       'mkdir /home/sftpBackupStorage')

    bs_ops.update_sftp_backup_storage_info(sftp_backup_storage_uuid,
                                           'hostname', vm_ip)
    host_ops.reconnect_sftp_backup_storage(sftp_backup_storage_uuid,
                                           timeout=600000)

    test_util.test_dsc('Recover Sftp Hostname')
    bs_ops.update_sftp_backup_storage_info(sftp_backup_storage_uuid,
                                           'hostname',
                                           sftp_backup_storage_hostname)
    host_ops.reconnect_sftp_backup_storage(sftp_backup_storage_uuid)

    vm.destroy()
    test_obj_dict.rm_vm(vm)

    test_util.test_pass('SFTP Backup Storage Update Infomation SUCCESS')
예제 #15
0
def test():
    global vm
    global default_mode
    #    default_mode = conf_ops.get_global_config_value('kvm', 'videoType')
    default_mode = conf_ops.change_global_config('vm', 'videoType', 'cirrus')
    vm = test_stub.create_sg_vm()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid)
    test_util.test_logger('[vm:] %s console is on %s:%s' %
                          (vm.get_vm().uuid, console.hostIp, console.port))
    display = str(int(console.port) - 5900)
    vm.check()
    vm_mode = test_lib.lib_get_vm_video_type(vm.get_vm())
    if vm_mode != 'cirrus':
        test_util.test_fail(
            'VM is expected to work in cirrus mode instead of %s' % (vm_mode))
    client = api.connect(console.hostIp + ":" + display)
    client.captureScreen('tmp.png')
    image = Image.open('tmp.png')
    if image.width != 720 or image.height != 400:
        test_util.test_fail(
            "VM is expected to work in 720x400 while its %sx%s" %
            (image.width, image.height))
    box = image.getbbox()
    if box != (0, 18, 403, 79):
        test_util.test_fail(
            "VM is expected to display text in area (0, 18, 403, 79) while it's actually: (%s, %s, %s, %s)"
            % (box[0], box[1], box[2], box[3]))

    cmd = 'sed -i "s/115200$/115200 vga=794/g" /boot/grub2/grub.cfg'
    test_lib.lib_execute_command_in_vm(vm.get_vm(), cmd)
    vm.reboot()
    vm.check()
    client = api.connect(console.hostIp + ":" + display)
    client.captureScreen('tmp.png')
    image = Image.open('tmp.png')
    if image.width != 1280 or image.height != 1024:
        test_util.test_fail(
            "VM is expected to work in 1280x1024 while its %sx%s" %
            (image.width, image.height))
    box = image.getbbox()
    if box != (0, 18, 359, 80):
        test_util.test_fail(
            "VM is expected to display text in area (0, 18, 359, 80) while it's actually: (%s, %s, %s, %s)"
            % (box[0], box[1], box[2], box[3]))

    vm.destroy()
    vm.check()
    conf_ops.change_global_config('vm', 'videoType', default_mode)
    test_util.test_pass('Create VM Test Success')
def test():
    global test_obj_dict
    test_util.test_dsc('Create a VM with 3 additional data volumes with 1 of them using virtio-scsi')
    disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    disk_offering_uuids = []
    for i in range(0, 8):
        disk_offering_uuids.append(disk_offering1.uuid)
    disk_offering2 = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName'))
    for i in range(0, 14):
        disk_offering_uuids.append(disk_offering2.uuid)
    vm = test_stub.create_vlan_vm(system_tags=["virtio::diskOffering::%s::num::14" % (disk_offering2.uuid) ,"virtio::diskOffering::%s::num::14" % (disk_offering1.uuid)], l3_name=os.environ.get('l3VlanNetworkName1'), disk_offering_uuids=disk_offering_uuids)
    test_obj_dict.add_vm(vm)
    vm.check()
    volumes_number = len(test_lib.lib_get_all_volumes(vm.vm))
    if volumes_number != 23:
        test_util.test_fail('Did not find 23 volumes for [vm:] %s. But we assigned 22 data volume when create the vm. We only catch %s volumes' % (vm.vm.uuid, volumes_number))
    else:
        test_util.test_logger('Find 23 volumes for [vm:] %s.' % vm.vm.uuid)

    scsi_cmd = 'ls /dev/sd* | wc -l'
    if test_lib.lib_execute_command_in_vm(vm.get_vm(), scsi_cmd).strip() != '22':
        test_util.test_fail('Only expect 22 disk in virtio scsi mode')

    vm.destroy()
    test_util.test_pass('Create a VM with 22 additional data volumes with 22 of them using virtio-scsi PASS')
def test():
    global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]

    vm_name = "test_vm"
    utility_vm_name = "utility_vm"
    
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    vm = test_stub.create_vm(vm_name, img_name, l3_name)
    utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name)
    dvol = test_stub.create_volume()
    dvol.attach(vm)
 

    path = "VM_TEST_NONE --> DVOL_BACKUP --> DVOL_TEST_CREATE_IMG --> DVOL_BACKUP --> VM_TEST_NONE --> DVOL_BACKUP --> VM_TEST_NONE --> DVOL_BACKUP --> DVOL_TEST_CREATE_IMG --> DVOL_BACKUP --> DVOL_TEST_RESIZE --> DVOL_BACKUP"
    path_array = path.split(" --> ")

    for i in path_array:
        if vm.state == "Stopped":
            vm.start()

        if i == "DVOL_BACKUP":
            if test_lib.lib_is_vm_l3_has_vr(vm.vm):
                test_lib.TestHarness = test_lib.TestHarnessVR
            time.sleep(60)
            
            cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1" 
            test_lib.lib_execute_command_in_vm(vm.vm,cmd)

            vm.suspend()
            vm_op_test(vm, dvol, "DVOL_BACKUP")
            compare(ps, vm, dvol, backup)

            vm.resume()
        else:
            vm_op_test(vm, dvol, i)
예제 #18
0
def test():
    global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]

    vm_name = "test_vm"
    utility_vm_name = "utility_vm"

    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate",
                                        cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    vm = test_stub.create_vm(vm_name, img_name, l3_name)
    utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name)
    dvol = test_stub.create_volume()
    dvol.attach(vm)

    path = "VM_TEST_NONE --> DVOL_BACKUP --> DVOL_TEST_CREATE_IMG --> DVOL_BACKUP --> VM_TEST_NONE --> DVOL_BACKUP --> VM_TEST_NONE --> DVOL_BACKUP --> DVOL_TEST_CREATE_IMG --> DVOL_BACKUP --> DVOL_TEST_RESIZE --> DVOL_BACKUP"
    path_array = path.split(" --> ")

    for i in path_array:
        if vm.state == "Stopped":
            vm.start()

        if i == "DVOL_BACKUP":
            if test_lib.lib_is_vm_l3_has_vr(vm.vm):
                test_lib.TestHarness = test_lib.TestHarnessVR
            time.sleep(60)

            cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1"
            test_lib.lib_execute_command_in_vm(vm.vm, cmd)

            vm.suspend()
            vm_op_test(vm, dvol, "DVOL_BACKUP")
            compare(ps, vm, dvol, backup)

            vm.resume()
        else:
            vm_op_test(vm, dvol, i)
def test():
    global test_obj_dict, VM_RUNGGING_OPS, VM_STOPPED_OPS, VM_STATE_OPS, backup

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]

    vm_name = "test_vm"
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK,cond)[0].name
    vm = test_stub.create_vm(vm_name, img_name, l3_name)

    path = "VM_TEST_REBOOT --> VM_TEST_MIGRATE --> VM_TEST_BACKUP --> VM_TEST_NONE --> VM_TEST_CREATE_IMG --> VM_TEST_BACKUP"
    path_array = path.split(" --> ")

    for i in path_array:
        if i == "VM_TEST_MIGRATE" and ps.type == inventory.LOCAL_STORAGE_TYPE:
            vm.stop()
            vm_op_test(vm, i)
            continue

        if vm.state == "Stopped":
            vm.start()

        if i == "VM_TEST_BACKUP":
            if test_lib.lib_is_vm_l3_has_vr(vm.vm):
                test_lib.TestHarness = test_lib.TestHarnessVR
            time.sleep(60)
            cmd = "echo 111 > /root/" + str(int(time.time()))
            test_lib.lib_execute_command_in_vm(vm.vm,cmd)
            vm.suspend()
            # create_snapshot/backup
            vm_op_test(vm, "VM_TEST_BACKUP")
            # compare vm & image created by backup
            compare(ps, vm, backup)
            vm.resume()
        else:
            vm_op_test(vm, i)
    test_util.test_pass("path: " + path + " test pass")
def test():
    vm = test_stub.create_user_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_lib.lib_execute_command_in_vm(vm.get_vm(), 'systemctl stop qemu-guest-agent')
    test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid)
    if time.time()-current_time <= 10:
        test_util.test_fail("VM should not shutdown with default grace method in %s seconds" % (time.time()-current_time))
    vm.set_state(vm_header.STOPPED)
    vm.check()

    vm.start()
    vm.check()
    test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &')
    current_time = time.time()
    vm_ops.stop_vm(vm.get_vm().uuid, force='cold')
    if time.time()-current_time >= 5:
        test_util.test_fail("VM should shutdown immediately with cold method, while it taks %s seconds" % (time.time()-current_time))

    vm.set_state(vm_header.STOPPED)
    vm.check()
  
    vm.destroy()
    test_util.test_pass('Force Stop VM Test Success')
예제 #21
0
def create_test_file(vm_inv, test_file):
    '''
    the bandwidth is for calculate the test file size,
    since the test time should be finished in 60s.
    bandwidth unit is KB.
    '''
    file_size = 1024 * 2
    seek_size = file_size / 1024 - 1

    cmd = 'dd if=/dev/zero of=%s bs=1K count=1 seek=%d' \
           % (test_file, seek_size)

    if not test_lib.lib_execute_command_in_vm(vm_inv, cmd):
        test_util.test_fail('test file is not created')
예제 #22
0
def create_test_file(vm_inv, test_file):
    '''
    the bandwidth is for calculate the test file size,
    since the test time should be finished in 60s.
    bandwidth unit is KB.
    '''
    file_size = 1024 * 2
    seek_size = file_size / 1024 - 1

    cmd = 'dd if=/dev/zero of=%s bs=1K count=1 seek=%d' \
           % (test_file, seek_size)

    if not test_lib.lib_execute_command_in_vm(vm_inv, cmd):
        test_util.test_fail('test file is not created')
예제 #23
0
def test():
    global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]

    DVOL_OP = flavor['vm_op']
    STATE_OP = flavor['state_op']

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]
    if ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE or ps.type == "AliyunNAS":
        test_util.test_skip(
            "VolumeBackup does not support Ceph and AliyunNAS for now")

    vm_name = "test_vm"
    utility_vm_name = "utility_vm"

    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate",
                                        cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    disk_offering_uuids = [disk_offering.uuid]
    vm = test_stub.create_vm(vm_name,
                             img_name,
                             l3_name,
                             disk_offering_uuids=disk_offering_uuids)
    vm.check()
    test_obj_dict.add_vm(vm)
    utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name)
    vm.check()
    test_obj_dict.add_vm(utility_vm)

    dvol = zstack_volume_header.ZstackTestVolume()
    dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0])
    dvol.set_state(volume_header.ATTACHED)
    dvol.set_target_vm(vm)
    test_obj_dict.add_volume(dvol)

    if "VM_TEST_BACKUP_IMAGE" in DVOL_OP or "VM_TEST_REVERT_BACKUP" in DVOL_OP:
        vm_op_test(vm, dvol, "DVOL_BACKUP")

    if "DVOL_DEL_SNAPSHOT" in DVOL_OP:
        vm_op_test(vm, dvol, "DVOL_TEST_SNAPSHOT")

    for i in DVOL_OP:
        vm_op_test(vm, dvol, random.choice(STATE_OP))
        if not backup_list and "VM_TEST_BACKUP_IMAGE" == i:
            i = "VM_TEST_NONE"

        vm_op_test(vm, dvol, i)

        if vm.state == "Stopped":
            vm.start()
            vm.check()

        if test_lib.lib_is_vm_l3_has_vr(vm.vm):
            test_lib.TestHarness = test_lib.TestHarnessVR

        cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1"
        test_lib.lib_execute_command_in_vm(vm.vm, cmd)

        vm.suspend()
        vm_op_test(vm, dvol, "DVOL_BACKUP")
        compare(ps, vm, dvol, backup)

        vm.resume()
        print_path(Path)
        test_lib.lib_error_cleanup(test_obj_dict)
def test():
    test_util.test_dsc('Test Set Data Volume WWN')
    vm1=test_stub.create_basic_vm()
    vm2=test_stub.create_basic_vm()
    vm1.check()
    vm2.check()
    test_obj_dict.add_vm(vm1)
    test_obj_dict.add_vm(vm2)

    volume1 = test_stub.create_volume()
    tag_ops.create_system_tag('VolumeVO',volume1.get_volume().uuid,"capability::virtio-scsi")
    volume2 = test_stub.create_volume()
    tag_ops.create_system_tag('VolumeVO',volume2.get_volume().uuid,"capability::virtio-scsi")
    test_obj_dict.add_volume(volume1)
    test_obj_dict.add_volume(volume2)
    vm1_inv = vm1.get_vm()
    vm2_inv = vm2.get_vm()
    mount_point_1 = '/tmp/zstack/test1'
    mount_point_2 = '/tmp/zstack/test2'
    test_lib.lib_mkfs_for_volume(volume1.get_volume().uuid, vm1_inv)
    test_stub.attach_mount_volume(volume1, vm1, mount_point_1)
    test_lib.lib_mkfs_for_volume(volume2.get_volume().uuid, vm1_inv)
    test_stub.attach_mount_volume(volume2, vm1, mount_point_2)
    wwn_dev_cmd=" ls /dev/disk/by-id -la | awk '$9~/^wwn-.*-part1/ {print $9,$11}'"
    wwn_dev_list=test_lib.lib_execute_command_in_vm(vm1_inv,wwn_dev_cmd)
    if not wwn_dev_list or wwn_dev_list == "<no stdout output>":
        test_util.test_fail('vm [%s] cannot show data volume wwn '%(vm1.get_vm().uuid))

    for wwn_dev in wwn_dev_list.strip().split('\n'):
        wwn = wwn_dev.split()[0]
        device = wwn_dev.split()[1].split('/')[-1]
        path_cmd = "mount | awk '/^\/dev\/"+device+"/ {print $3}'"
        mount_point = test_lib.lib_execute_command_in_vm(vm1_inv, path_cmd).strip()
        test_stub.create_test_file(vm1_inv,mount_point+'/'+wwn)
        test_lib.lib_execute_command_in_vm(vm1_inv, 'umount '+mount_point+' >/dev/null')
    volume1.detach()
    volume2.detach()

    wwn_cmd="ls /dev/disk/by-id -la | awk '$9~/^wwn-.*-part1/ {print $9}'"

    test_stub.attach_mount_volume(volume1, vm2, mount_point_1)
    set_wwn_1 = test_lib.lib_execute_command_in_vm(vm2_inv, wwn_cmd).strip()
    check_file_cmd = "ls "+mount_point_1
    file_list = test_lib.lib_execute_command_in_vm(vm2_inv, check_file_cmd)
    if set_wwn_1 not in file_list.split():
        test_util.test_fail('wwn [%s] file does not exist in wwn [%s] volume' % (set_wwn_1, set_wwn_1))
    wwn_1 = set_wwn_1.split('-')[1]
    cond = res_ops.gen_query_conditions('resourceUuid', '=', volume1.get_volume().uuid)
    cond = res_ops.gen_query_conditions('tag','=','kvm::volume::%s' % (wwn_1),cond)
    volume1_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)
    if not volume1_tag_invs:
        cond = res_ops.gen_query_conditions('resourceUuid', '=', volume1.get_volume().uuid)
        volume1_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)
	for tag_inv in volume1_tag_invs:
            if tag_inv.tag.startswith("kvm::volume::"):
                volume1_tag = tag_inv.tag.split("::")[2]
                test_util.test_fail('data volume [%s] with tag [%s] does not match its wwn number [%s] in vm' % (volume2.get_volume().uuid,volume1_tag, wwn_1))
                break
    volume1.detach()

    test_stub.attach_mount_volume(volume2, vm2, mount_point_2)
    set_wwn_2 = test_lib.lib_execute_command_in_vm(vm2_inv, wwn_cmd).strip()
    check_file_cmd = "ls "+mount_point_2
    file_list = test_lib.lib_execute_command_in_vm(vm2_inv, check_file_cmd)
    if set_wwn_2 not in file_list.split():
        test_util.test_fail('wwn [%s] file does not exist in wwn [%s] volume' % (set_wwn_2, set_wwn_2))
    wwn_2 = set_wwn_2.split('-')[1]
    cond = res_ops.gen_query_conditions('resourceUuid', '=', volume2.get_volume().uuid)
    cond = res_ops.gen_query_conditions('tag','=','kvm::volume::%s'%(wwn_2),cond)
    volume2_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)
    if not volume2_tag_invs:
        cond = res_ops.gen_query_conditions('resourceUuid', '=', volume2.get_volume().uuid)
        volume2_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)
	for tag_inv in volume2_tag_invs:
            if tag_inv.tag.startswith("kvm::volume::"):
                volume2_tag = tag_inv.tag.split("::")[2]
                test_util.test_fail('data volume [%s] with tag [%s] does not match its wwn number [%s] in vm' % (volume2.get_volume().uuid,volume2_tag, wwn_2))
                break
    volume2.detach()

    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Set Data Volume WWN Test Pass')
def test():
    global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]

    DVOL_OP = flavor['vm_op']
    STATE_OP = flavor['state_op']

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]
    if ps.type == "AliyunNAS":
        test_util.test_skip("VolumeBackup does not support AliyunNAS for now")

    vm_name = "test_vm"
    utility_vm_name = "utility_vm"
    
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    cond = res_ops.gen_query_conditions("name", '=', "image_for_sg_test", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    disk_offering_uuids = [disk_offering.uuid]
    vm = test_stub.create_vm(vm_name, img_name, l3_name, disk_offering_uuids=disk_offering_uuids)
    vm.check()
    test_obj_dict.add_vm(vm)
    hostuuid = vm.get_vm().hostUuid
    utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name, host_uuid=hostuuid)
    utility_vm.check()
    test_obj_dict.add_vm(utility_vm)

    dvol = zstack_volume_header.ZstackTestVolume()
    dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0])
    dvol.set_state(volume_header.ATTACHED)
    dvol.set_target_vm(vm)
    test_obj_dict.add_volume(dvol)

    if "VM_TEST_BACKUP_IMAGE" in DVOL_OP or "VM_TEST_REVERT_BACKUP" in DVOL_OP:
        vm_op_test(vm, dvol, "DVOL_BACKUP")

    if "DVOL_DEL_SNAPSHOT" in DVOL_OP:
        vm_op_test(vm, dvol, "DVOL_TEST_SNAPSHOT")

    for i in DVOL_OP:
        vm_op_test(vm, dvol, random.choice(STATE_OP))
        if not backup_list and "VM_TEST_BACKUP_IMAGE" == i:
            i = "VM_TEST_NONE"

        vm_op_test(vm, dvol, i)

        if vm.state == "Stopped":
            vm.start()
            vm.check()

	if test_lib.lib_is_vm_l3_has_vr(vm.vm):
            test_lib.TestHarness = test_lib.TestHarnessVR
        
            cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1" 
    	    test_lib.lib_execute_command_in_vm(vm.vm,cmd)

        vm.suspend()
        vm_op_test(vm, dvol, "DVOL_BACKUP")
        if ps.type != inventory.CEPH_PRIMARY_STORAGE_TYPE:
            compare(ps, vm, dvol, backup)

        vm.resume()
        print_path(Path)
        test_lib.lib_error_cleanup(test_obj_dict)
예제 #26
0
def test():
    global eip_snatInboundTraffic_default_value
    global pf_snatInboundTraffic_default_value
    #enable snatInboundTraffic and save global config value
    eip_snatInboundTraffic_default_value = \
            conf_ops.change_global_config('eip', 'snatInboundTraffic', 'true')
    pf_snatInboundTraffic_default_value = \
            conf_ops.change_global_config('portForwarding', \
            'snatInboundTraffic', 'true')

    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('l3VlanDNATNetworkName')
    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, '2_l3_pf_vm')
    test_obj_dict.add_vm(vm)

    l3_name = os.environ.get('l3NoVlanNetworkName1')
    vr_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid)
    temp_vm1 = None
    if not vrs:
        #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding
        temp_vm1 = test_stub.create_user_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]

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

    vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1)
    
    vm.check()

    vm_nic1 = vm.vm.vmNics[0]
    vm_nic1_uuid = vm_nic1.uuid
    vm_nic2 = vm.vm.vmNics[1]
    vm_nic2_uuid = vm_nic2.uuid
    pri_l3_uuid = vm_nic1.l3NetworkUuid
    vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0]
#    if vr.applianceVmType == "vrouter":
#        test_util.test_skip("vrouter VR does not support single VM multiple EIP")

    vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr)
    l3_uuid = vr_pub_nic.l3NetworkUuid
    vip1 = test_stub.create_vip('vip1_2l3s_vm_test', l3_uuid)
    test_obj_dict.add_vip(vip1)
    vip1_uuid = vip1.get_vip().uuid
    vip2 = test_stub.create_vip('vip2_2l3s_vm_test', l3_uuid)
    test_obj_dict.add_vip(vip2)
    vip2_uuid = vip2.get_vip().uuid

    eip1 = test_stub.create_eip('2l3 eip test1', vip_uuid=vip1.get_vip().uuid)
    vip1.attach_eip(eip1)
    vip1.check()
    eip1.attach(vm_nic1_uuid, vm)
    cmd = 'ip route | grep %s | grep eth0' % (os.environ.get('vlanIpRangeGateway1'))
    if vr1.applianceVmType == "vrouter":
        if not test_lib.lib_execute_command_in_vm(vm.get_vm(), cmd):
           default_eth = 1
           non_default_eth = 0
        else:
           default_eth = 0
           non_default_eth = 1

        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway2'), non_default_eth)
    vip1.check()

    eip2 = test_stub.create_eip('2l3 eip test2', vip_uuid=vip2.get_vip().uuid)
    vip2.attach_eip(eip2)
    vip2.check()
    eip2.attach(vm_nic2_uuid, vm)
    if vr1.applianceVmType == "vrouter":
        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway1'), default_eth)
    vip2.check()

    vm.stop()
    vm.start()

    vm.check()
    if vr1.applianceVmType == "vrouter":
        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway2'), non_default_eth)
    vip1.check()

    if vr1.applianceVmType == "vrouter":
        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway1'), default_eth)
    vip2.check()

    eip1.detach()
    eip2.detach()

    vip1.check()
    vip2.check()

    vip1.delete()
    test_obj_dict.rm_vip(vip1)
    vip2.delete()
    test_obj_dict.rm_vip(vip2)
    vm.destroy()
    test_obj_dict.rm_vm(vm)
    conf_ops.change_global_config('eip', 'snatInboundTraffic', \
            eip_snatInboundTraffic_default_value )
    conf_ops.change_global_config('portForwarding', 'snatInboundTraffic', \
            pf_snatInboundTraffic_default_value)
    test_util.test_pass('Create 1 VM with 2 l3_network with 2 VIP PF testing successfully.')
예제 #27
0
def set_httpd_in_vm(vm, ip):
    cmd = "systemctl start httpd; iptables -F; echo %s > /var/www/html/index.html" % ip
    test_lib.lib_execute_command_in_vm(vm, cmd)
예제 #28
0
def set_httpd_in_vm(vm, ip):
    cmd = "systemctl start httpd; iptables -F; echo %s > /var/www/html/index.html" % ip
    test_lib.lib_execute_command_in_vm(vm, cmd)
예제 #29
0
def test():
    global eip_snatInboundTraffic_default_value
    global pf_snatInboundTraffic_default_value
    #enable snatInboundTraffic and save global config value
    eip_snatInboundTraffic_default_value = \
            conf_ops.change_global_config('eip', 'snatInboundTraffic', 'true')
    pf_snatInboundTraffic_default_value = \
            conf_ops.change_global_config('portForwarding', \
            'snatInboundTraffic', 'true')

    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('l3VlanDNATNetworkName')
    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, '2_l3_pf_vm')
    test_obj_dict.add_vm(vm)

    l3_name = os.environ.get('l3NoVlanNetworkName1')
    vr_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid)
    temp_vm1 = None
    if not vrs:
        #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding
        temp_vm1 = test_stub.create_user_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]

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

    vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1)

    vm.check()

    vm_nic1 = vm.vm.vmNics[0]
    vm_nic1_uuid = vm_nic1.uuid
    vm_nic2 = vm.vm.vmNics[1]
    vm_nic2_uuid = vm_nic2.uuid
    pri_l3_uuid = vm_nic1.l3NetworkUuid
    vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0]
    #    if vr.applianceVmType == "vrouter":
    #        test_util.test_skip("vrouter VR does not support single VM multiple EIP")

    vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr)
    l3_uuid = vr_pub_nic.l3NetworkUuid
    vip1 = test_stub.create_vip('vip1_2l3s_vm_test', l3_uuid)
    test_obj_dict.add_vip(vip1)
    vip1_uuid = vip1.get_vip().uuid
    vip2 = test_stub.create_vip('vip2_2l3s_vm_test', l3_uuid)
    test_obj_dict.add_vip(vip2)
    vip2_uuid = vip2.get_vip().uuid

    eip1 = test_stub.create_eip('2l3 eip test1', vip_uuid=vip1.get_vip().uuid)
    vip1.attach_eip(eip1)
    vip1.check()
    eip1.attach(vm_nic1_uuid, vm)
    cmd = 'ip route | grep %s | grep eth0' % (
        os.environ.get('vlanIpRangeGateway1'))
    if vr1.applianceVmType == "vrouter":
        if not test_lib.lib_execute_command_in_vm(vm.get_vm(), cmd):
            default_eth = 1
            non_default_eth = 0
        else:
            default_eth = 0
            non_default_eth = 1

        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway2'),
                          non_default_eth)
    vip1.check()

    eip2 = test_stub.create_eip('2l3 eip test2', vip_uuid=vip2.get_vip().uuid)
    vip2.attach_eip(eip2)
    vip2.check()
    eip2.attach(vm_nic2_uuid, vm)
    if vr1.applianceVmType == "vrouter":
        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway1'),
                          default_eth)
    vip2.check()

    vm.stop()
    vm.start()

    vm.check()
    if vr1.applianceVmType == "vrouter":
        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway2'),
                          non_default_eth)
    vip1.check()

    if vr1.applianceVmType == "vrouter":
        update_default_gw(vm.get_vm(), os.environ.get('vlanIpRangeGateway1'),
                          default_eth)
    vip2.check()

    eip1.detach()
    eip2.detach()

    vip1.check()
    vip2.check()

    vip1.delete()
    test_obj_dict.rm_vip(vip1)
    vip2.delete()
    test_obj_dict.rm_vip(vip2)
    vm.destroy()
    test_obj_dict.rm_vm(vm)
    conf_ops.change_global_config('eip', 'snatInboundTraffic', \
            eip_snatInboundTraffic_default_value )
    conf_ops.change_global_config('portForwarding', 'snatInboundTraffic', \
            pf_snatInboundTraffic_default_value)
    test_util.test_pass(
        'Create 1 VM with 2 l3_network with 2 VIP PF testing successfully.')
def test():
    global test_obj_dict, VM_RUNNING_OPS, VM_STOPPED_OPS, VM_STATE_OPS, backup, dvol, utility_vm
    #flavor = case_flavor[os.environ.get('CASE_FLAVOR')]

    #VM_OP = flavor['vm_op']
    #STATE_OP = flavor['state_op']

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]
    if ps.type == "AliyunNAS":
        test_util.test_skip("VolumeBackup does not support AliyunNAS for now")
#    if ps.type != inventory.LOCAL_STORAGE_TYPE and 'VM_TEST_MIGRATE' in VM_OP and "VM_TEST_STOP" in STATE_OP:
#        test_util.test_skip("Shared Storage does not support migration")

    vm_name = "test_vm"
    utility_vm_name = "utility_vm"

    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    cond = res_ops.gen_query_conditions("name", '=', "image_for_sg_test", cond)
    img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name
    cond = res_ops.gen_query_conditions("category", '=', "Private")
    l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    disk_offering_uuids = [disk_offering.uuid]
    vm = test_stub.create_vm(vm_name, img_name, l3_name, disk_offering_uuids=disk_offering_uuids)
    vm.check()
    test_obj_dict.add_vm(vm)
    hostuuid = vm.get_vm().hostUuid
    utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name, host_uuid=hostuuid)
    utility_vm.check()
    test_obj_dict.add_vm(utility_vm)

    dvol = zstack_volume_header.ZstackTestVolume()
    dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0])
    dvol.set_state(volume_header.ATTACHED)
    dvol.set_target_vm(vm)
    test_obj_dict.add_volume(dvol)

    for i in range(1,20):
        vm_op_test(vm, random.choice(VM_STATE_OPS))
        if vm.state == "Running":
            VM_OPS = VM_RUNNING_OPS
            if not backup_list:
                VM_OPS.remove("VM_TEST_BACKUP_IMAGE")
        elif vm.state == "Stopped":
            VM_OPS = VM_STOPPED_OPS
            if not backup_list:
                VM_OPS.remove("VM_TEST_REVERT_BACKUP")
                VM_OPS.remove("VM_TEST_BACKUP_IMAGE")
                VM_OPS.remove("VM_TEST_REVERT_VM_BACKUP")


        vm_op_test(vm, random.choice(VM_OPS))

        if vm.state == "Stopped":
            vm.start()
            vm.check()

        if test_lib.lib_is_vm_l3_has_vr(vm.vm):
            test_lib.TestHarness = test_lib.TestHarnessVR
            cmd = "echo 111 > /home/" + str(int(time.time()))
            test_lib.lib_execute_command_in_vm(vm.vm,cmd)
            cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1"
            test_lib.lib_execute_command_in_vm(vm.vm,cmd)

        vm.suspend()
        # create_snapshot/backup
        vm_op_test(vm, "VM_TEST_BACKUP")
        # compare vm & image created by backup
        if ps.type != inventory.CEPH_PRIMARY_STORAGE_TYPE:
            compare(ps, vm, backup)

        vm.resume()
    print_path(Path)
    test_lib.lib_error_cleanup(test_obj_dict)