def test():
    global vm, vm2, image_uuid
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" %(root_password))
        vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag")

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

        vm.check()

        #add tag to vm
        tag_ops.create_system_tag('VmInstanceVO', vm.get_vm().uuid, "qemuga")

        vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password)

        #create image by the vm with tag
        vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
        root_volume_uuid = vm_root_volume_inv.uuid

        image_option1 = test_util.ImageOption()
        image_option1.set_root_volume_uuid(root_volume_uuid)
        image_option1.set_name('add_tag_vm_to_image')
        image_option1.set_format('qcow2')
        image_option1.set_backup_storage_uuid_list([bs.uuid])

        vm.stop()
        image = img_ops.create_root_volume_template(image_option1)

        #create vm by new image
        vm2 = test_stub.create_vm(vm_name = 'c7-vm-add-tag-from-previous-vm', image_name = "add_tag_vm_to_image")
        if not test_lib.lib_check_login_in_vm(vm2.get_vm(), "root", root_password):
            test_util.test_fail("create vm with user:%s password: %s failed", "root", root_password)

        vm_ops.change_vm_password(vm2.get_vm().uuid, "root", root_password)

        image_uuid = image.uuid
        if not image_uuid:
            img_ops.delete_image(image_uuid)
            img_ops.expunge_image(image_uuid)
            

    test_util.test_pass('add system tag on a no system tag image test passed')
def test():
    from vncdotool import api
    global vm1
    global vm2

    vm1 = test_stub.create_vm()
    vm1.check()
    console = test_lib.lib_get_vm_console_address(vm1.get_vm().uuid)
    test_util.test_logger('[vm:] %s console is on %s:%s' % (vm1.get_vm().uuid, console.hostIp, console.port))
    display = str(int(console.port)-5900)

    test_lib.lib_set_vm_console_password(vm1.get_vm().uuid, password1)
    test_util.test_logger('set [vm:] %s console with password %s' % (vm1.get_vm().uuid, password1))
    vm1.reboot()

    test_lib.lib_delete_vm_console_password(vm1.get_vm().uuid)
    test_util.test_logger('delete [vm:] %s console password after reboot' % (vm1.get_vm().uuid))
    vm1.reboot()
    if not test_lib.lib_wait_target_up(console.hostIp, console.port, timeout=60):
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' % (vm1.get_vm().uuid, console.hostIp, console.port))

    try:
        client = api.connect(console.hostIp+":"+display)
        client.keyPress('k')
        test_util.test_logger('[vm:] %s console on %s:%s is connectable without password' % (vm1.get_vm().uuid, console.hostIp, console.port))
    except:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable without password' % (vm1.get_vm().uuid, console.hostIp, console.port))

    vm2 = test_stub.create_vm()
    vm2.check()
    console = test_lib.lib_get_vm_console_address(vm2.get_vm().uuid)
    test_util.test_logger('[vm:] %s console is on %s:%s' % (vm2.get_vm().uuid, console.hostIp, console.port))
    display = str(int(console.port)-5900)

    test_lib.lib_set_vm_console_password(vm2.get_vm().uuid, password1)
    test_util.test_logger('set [vm:] %s console with password %s' % (vm2.get_vm().uuid, password1))
    test_lib.lib_delete_vm_console_password(vm2.get_vm().uuid)
    test_util.test_logger('delete [vm:] %s console password without reboot' % (vm2.get_vm().uuid))
    vm1.reboot()
    if not test_lib.lib_wait_target_up(console.hostIp, console.port, timeout=60):
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' % (vm2.get_vm().uuid, console.hostIp, console.port))

    try:
        client = api.connect(console.hostIp+":"+display)
        client.keyPress('k')
        test_util.test_logger('[vm:] %s console on %s:%s is connectable without password' % (vm2.get_vm().uuid, console.hostIp, console.port))
    except:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable without password' % (vm2.get_vm().uuid, console.hostIp, console.port))

    vm1.destroy()
    vm2.destroy()

    test_util.test_pass('Delete VM Console Password Test Success')
def test():
    '''
    Test Description:
        Test add volume with negative test. 
    Resource required:
        2 test VMs with additional 1*10M data volume.
 
    '''
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Create volume and check')
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

    test_util.test_dsc('Attach volume and check')
    volume.attach(vm)
    volume.check()

    test_util.test_dsc('Doing negative test. Try to reattach same volume to vm again.')
    try:
        volume.attach(vm)
    except:
        test_util.test_logger('Catch expected exception. [volume:] %s can not be attached to [vm:] %s twice.' % (volume.volume.uuid, vm.vm.uuid))
        test_util.test_dsc('Doing negative test. Try to delete an attached data volume.')
        vm2 = test_stub.create_vm()
        test_obj_dict.add_vm(vm2)
        test_util.test_dsc('Doing negative test. Try to attach an attached volume to 2nd vm.')
        try:
            volume.attach(vm2)
        except:
            test_util.test_logger('Catch expected exception. [volume:] %s can not be attached to another [vm:] %s, as it is already attached to [vm:] %s.' % (volume.volume.uuid, vm2.vm.uuid, vm.vm.uuid))
            volume.check()
            try:
                volume.delete()
            except:
                test_util.test_fail('Catch wrong logic: [volume:] %s can not be deleted, when it is assigned to [vm:] %s' % (volume.volume.uuid, vm.vm.uuid))
            test_obj_dict.rm_volume(volume)
            vm.destroy()
            test_obj_dict.rm_vm(vm)
            vm2.destroy()
            test_obj_dict.rm_vm(vm2)
            volume.check()
            test_util.test_pass('Data Volume Negative Test Success')
            return True
        
        test_util.test_fail('Catch wrong logic: [volume:] %s is attached to [vm:] %s again, although it is already attached to [vm:] %s .' % (volume.volume.uuid, vm2.vm.uuid, vm.vm.uuid))
    test_util.test_fail('Catch wrong logic: [volume:] %s is attached to [vm:] %s twice.' % (volume.volume.uuid, vm.vm.uuid))
Esempio n. 4
0
def test():
    global vms, ts, invs
    global ga_process_not_alive_num, keep_vm_num
    test_util.test_dsc('create VM with setting password')

    for i in range(vm_num):
        vms.append(
            test_stub.create_vm(vm_name='c7-vm' + str(i),
                                image_name="batch_test_image"))

    for vm in vms:
        t = threading.Thread(target=change_vm_password_wrapper,
                             args=(vm.get_vm().uuid, "root", "password"))
        ts.append(t)
        t.start()

    for t in ts:
        t.join()

    for cnt in range(max_cnt):
        test_util.test_dsc("this is loop:%d" % (cnt))

        for vm in vms:
            t = threading.Thread(target=vm_reboot_wrapper, args=(vm, cnt))
            ts.append(t)
            t.start()

        for t in ts:
            t.join()

        for vm in vms:
            if check_qemu_ga_is_alive(vm) != 0:
                keep_vm_num = keep_vm_num - 1
                vms.remove(vm)
                vms.append(
                    test_stub.create_vm(vm_name='c7-vm-new-' +
                                        str(keep_vm_num),
                                        image_name="batch_test_image"))
                if keep_vm_num < 0:
                    vm.destroy()
                    vm.expunge()

    for vm in vms:
        if vm:
            vm.destroy()
            vm.expunge()

    test_util.test_fail('total vm reboot times:%s; ga not existed vm:%s' %
                        (vm_num * max_cnt, ga_process_not_alive_num))
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    vm.suspend()
    vm.destroy()
    vm.check()
    vm = test_stub.create_vm()
    vm.check()
    vm.suspend()
    vm.stop()
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('Suspend VM Test Success')
def test():
    global vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" % (root_password))
        vm = test_stub.create_vm(vm_name='c7-vm-32',
                                 image_name="imageName_i_c7_32",
                                 root_password=root_password)

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

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root",
                                              root_password):
            test_util.test_fail("create vm with root password: %s failed",
                                root_password)

        vm.destroy()
        vm.check()

        vm.expunge()
        vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vm
    pxe_uuid = test_lib.lib_get_pxe_by_name(os.environ.get('pxename')).uuid
    # Create VM
    vm = test_stub.create_vm()
    vm.check()
    # Stop PXE
    bare_operations.stop_pxe(pxe_uuid)
    if test_lib.lib_get_pxe_by_name(
            os.environ.get('pxename')).status != "Stopped":
        test_util.test_fail('Fail to stop PXE')
    # Start PXE
    bare_operations.start_pxe(pxe_uuid)
    if test_lib.lib_get_pxe_by_name(
            os.environ.get('pxename')).status != "Running":
        test_util.test_fail('Fail to start PXE')
    # Create Virtual BMC
    test_stub.create_vbmc(vm=vm, port=6230)
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name=chassis)
    test_stub.hack_ks(port=6230)
    chassis_uuid = test_lib.lib_get_chassis_by_name(chassis).uuid
    # First time Provision
    bare_operations.provision_baremetal(chassis_uuid)
    hwinfo = test_stub.check_hwinfo(chassis_uuid)
    if not hwinfo:
        test_util.test_fail(
            'Fail to get hardware info during the first provision')
    test_stub.delete_vbmc(vm=vm)
    bare_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    test_util.test_pass('Start/Stop PXE Test Success')
Esempio n. 8
0
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    session_uuid = acc_ops.login_as_admin()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid,
                                                  session_uuid)
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_logger('[vm:] %s console on %s:%s is connectable' %
                              (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' %
                            (vm.get_vm().uuid, console.hostIp, console.port))
    vm.destroy()
    vm.check()
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_fail(
            '[vm:] %s console on %s:%s is connectable, while VM is already destroyed'
            % (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_logger('[vm:] %s console on %s:%s is not connectable' %
                              (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    test_util.test_pass('Request Access VM Console Test Success')
def test():
    global vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" %(root_password))
        vm = test_stub.create_vm(vm_name = 'u13-vm', image_name = "imageName_i_u13", root_password=root_password)
        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
        for bs in backup_storage_list:
            if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
                break
            if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE:
                break
            if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
                break
        else:
            vm.destroy()
            test_util.test_skip('Not find image store type backup storage.')

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root", root_password):
            test_util.test_fail("create vm with root password: %s failed", root_password)

        vm.destroy()
        vm.check()

        vm.expunge()
        vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
Esempio n. 10
0
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('Create VM Test Success')
Esempio n. 11
0
def test():
    global vm
    # Create VM
    vm = test_stub.create_vm()
    vm.check()
    # Create Virtual BMC
    test_stub.create_vbmc(vm=vm, port=6230)
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name=chassis)
    test_stub.hack_ks(port=6230)
    chassis_uuid = test_lib.lib_get_chassis_by_name(chassis).uuid

    bare_operations.power_off_baremetal(chassis_uuid)
    status = bare_operations.get_power_status(chassis_uuid)
    if status.status == "Chassis Power is off":
        bare_operations.power_reset_baremetal(chassis_uuid)
        status = bare_operations.get_power_status(chassis_uuid)
        if status.status != "Chassis Power is on":
            test_util.test_fail('Failed to power reset chassis')
    else:
        test_util.test_fail('Failed to power off chassis')

    test_stub.delete_vbmc(vm=vm)
    bare_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    test_util.test_pass('Test Power Reset Success')
def test():
    global vm
 
    import signal
    def handler(signum, frame):
        raise Exception()
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(30)
    boot_option_picture = os.environ.get('bootOptionPicture')
    
    vm = test_stub.create_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)

    client = api.connect(console.hostIp+":"+display)
    time.sleep(2)
    client.keyPress('esc')
    #client.captureRegion('/root/boot.png',0,100,600,600)
    client.expectRegion(boot_option_picture,0,100)
    test_util.test_logger('[vm:] %s support boot option' % (vm.get_vm().uuid))
#    except:
#        test_util.test_fail('[vm:] %s is expected to support boot option' % (vm.get_vm().uuid))

    vm.destroy()

    test_util.test_pass('Support VM Boot Option Test Success')
def test():
    global vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" %(root_password))
        #vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag", root_password=root_password)
        vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag")

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

        #if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root", root_password):
        #    test_util.test_fail("create vm with root password: %s failed", root_password)

        # stop vm && change vm password
        #vm.stop()
        vm.check()
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password)
        except Exception, e:
            if "CreateSystemTag" in str(e):
                test_util.test_pass("negative test of change a no system tag image passed.")
            else:
                test_util.test_fail("negative test failed with not expected log: %s", str(e))
def test():
    global vm
    # Create VM
    vm = test_stub.create_vm()
    vm.check()
    # Create Virtual BMC
    test_stub.create_vbmc(vm = vm, port = 6230)
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name = chassis)
    test_stub.hack_ks(port = 6230)
    chassis_uuid = test_lib.lib_get_chassis_by_name(chassis).uuid

    bare_operations.power_off_baremetal(chassis_uuid)
    status = bare_operations.get_power_status(chassis_uuid)
    if status.status == "Chassis Power is off":
        bare_operations.power_reset_baremetal(chassis_uuid)
        status = bare_operations.get_power_status(chassis_uuid)
        if status.status != "Chassis Power is on":
            test_util.test_fail('Failed to power reset chassis')
    else:
        test_util.test_fail('Failed to power off chassis')

    test_stub.delete_vbmc(vm = vm)
    bare_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    test_util.test_pass('Test Power Reset Success')
Esempio n. 15
0
def test():
    global vm
    vm = test_stub.create_vm()

    #1
    hostname = 'vm123.zstack.org'
    vm_ops.set_vm_hostname(vm.get_vm().uuid, 'vm123.zstack.org')
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    host_ops.reconnect_host(host.uuid)

    hostname_inv = vm_ops.get_vm_hostname(vm.get_vm().uuid)
    if hostname_inv != hostname:
        test_util.test_fail(
            'can not get the vm hostname after set vm hostname')

    vm_inv = res_ops.get_resource(res_ops.VM_INSTANCE,
                                  uuid=vm.get_vm().uuid)[0]
    if vm_inv.vmNics[0].ip != vm.get_vm().vmNics[0].ip:
        test_util.test_fail(
            'can not get the correct ip address after set vm hostname and reconnected host'
        )

    #2
    hostname = 'vm1234.zstack.org'
    vm_ops.set_vm_hostname(vm.get_vm().uuid, hostname)
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    vm_ops.reboot_vm(vm.get_vm().uuid)

    hostname_inv = vm_ops.get_vm_hostname(vm.get_vm().uuid)
    if hostname_inv != hostname:
        test_util.test_fail(
            'can not get the vm hostname after set vm hostname')

    vm_inv = res_ops.get_resource(res_ops.VM_INSTANCE,
                                  uuid=vm.get_vm().uuid)[0]
    if vm_inv.vmNics[0].ip != vm.get_vm().vmNics[0].ip:
        test_util.test_fail(
            'can not get the correct ip address after set vm hostname and reboot vm'
        )

    #3
    hostname = 'vm12345.zstack.org'
    vm_ops.set_vm_hostname(vm.get_vm().uuid, hostname)
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    host_ops.reconnect_host(host.uuid)
    vm_ops.reboot_vm(vm.get_vm().uuid)

    hostname_inv = vm_ops.get_vm_hostname(vm.get_vm().uuid)
    if hostname_inv != hostname:
        test_util.test_fail(
            'can not get the vm hostname after set vm hostname')

    vm_inv = res_ops.get_resource(res_ops.VM_INSTANCE,
                                  uuid=vm.get_vm().uuid)[0]
    if vm_inv.vmNics[0].ip != vm.get_vm().vmNics[0].ip:
        test_util.test_fail(
            'can not get the correct ip address after set vm hostname and reboot vm and reconnect host'
        )

    test_util.test_pass('SetVMHostname and get vm\'s correct ip')
def test():
    global test_obj_dict
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Create volume and check')
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.attach(vm)
    volume.check()
        
    test_util.test_dsc('Reboot vm and check volume again.')
    vm.reboot()
    vm.check()
    volume.check()

    volume.detach()
    volume.check()

    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)
        
    vm.destroy()
    test_util.test_pass('Create Data Volume for VM Test Success')
Esempio n. 17
0
def test():
    global vm, test_account_uuid, test_account_session
    import uuid
    account_name = uuid.uuid1().get_hex()
    account_pass = uuid.uuid1().get_hex()
    account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = acc_ops.create_normal_account(account_name, account_pass)
    test_account_uuid = test_account.uuid
    test_account_session = acc_ops.login_by_account(account_name, account_pass)
    test_stub.share_admin_resource([test_account_uuid])

    vm = test_stub.create_vm(vm_name='c7-vm-no-sys-tag',
                             image_name="imageName_i_c7_no_tag",
                             session_uuid=test_account_session)
    vm.check()

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

    for (usr, passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)

        #When vm is running:
        #res_ops.enable_change_vm_password("true", vm.get_vm().uuid, 'VmInstanceVO', session_uuid = test_account_session)
        vm_ops.set_vm_qga_enable(vm.get_vm().uuid,
                                 session_uuid=test_account_session)
        vm_ops.change_vm_password(vm.get_vm().uuid,
                                  usr,
                                  passwd,
                                  skip_stopped_vm=None,
                                  session_uuid=test_account_session)

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed",
                                usr, passwd)

        vm_ops.change_vm_password(vm.get_vm().uuid,
                                  "root",
                                  test_stub.original_root_password,
                                  session_uuid=test_account_session)
        vm.check()

    vm.destroy(test_account_session)
    vm.check()
    vm.expunge(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass(
        'enable and change vm password by normal user account Success')
Esempio n. 18
0
def test():
    global vm
    global trigger
    global media
    global trigger_action

    vm = test_stub.create_vm()
    vm.check()
    vm_ip = vm.get_vm().vmNics[0].ip
    vm_uuid = vm.get_vm().uuid
    vm_username = os.environ.get('Vm_Username')
    vm_password = os.environ.get('Vm_Password')
    vm_port = os.environ.get('Vm_Sshport')

    test_item = "vm.cpu.util"
    resource_type = "VmInstanceVO"
    vm_monitor_item = test_stub.get_monitor_item(resource_type)
    if test_item not in vm_monitor_item:
        test_util.test_fail('%s is not available for monitor' % test_item)

    duration = 300
    expression = "vm.cpu.util{}>125.6"
    monitor_trigger = mon_ops.create_monitor_trigger(vm_uuid, duration,
                                                     expression)

    send_email = test_stub.create_email_media()
    media = send_email.uuid
    trigger_action_name = "trigger" + ''.join(
        map(lambda xx: (hex(ord(xx))[2:]), os.urandom(8)))
    trigger = monitor_trigger.uuid
    receive_email = os.environ.get('receive_email')
    monitor_trigger_action = mon_ops.create_email_monitor_trigger_action(
        trigger_action_name, send_email.uuid, trigger.split(), receive_email)
    trigger_action = monitor_trigger_action.uuid

    ssh_cmd = test_stub.ssh_cmd_line(vm_ip, vm_username, vm_password, vm_port)
    test_stub.yum_install_stress_tool(ssh_cmd)
    for i in range(5):
        test_stub.run_all_cpus_load(ssh_cmd)

    status_problem, status_ok = test_stub.query_trigger_in_loop(trigger, 80)
    test_util.action_logger(
        'Trigger old status: %s triggered. Trigger new status: %s recovered' %
        (status_problem, status_ok))
    if status_problem != 1 or status_ok != 1:
        test_util.test_fail(
            '%s Monitor Test failed, expected Problem or OK status not triggered'
            % test_item)

    mail_list = test_stub.receive_email()
    keywords = "fired"
    mail_flag = test_stub.check_email(mail_list, keywords, trigger, vm_uuid)
    if mail_flag == 0:
        test_util.test_fail('Failed to Get Target: %s for: %s Trigger Mail' %
                            (vm_uuid, test_item))

    mon_ops.delete_monitor_trigger_action(trigger_action)
    mon_ops.delete_monitor_trigger(trigger)
    mon_ops.delete_email_media(media)
    vm.destroy()
def test():
    global vms
    for i in range(12):
        vms.append(test_stub.create_vm())

    session_uuid = acc_ops.login_as_admin()
    for vm in vms:
        if vm:
            vm.check()
            console = test_lib.lib_get_vm_console_address(
                vm.get_vm().uuid, session_uuid)
            if test_lib.lib_network_check(console.hostIp, console.port):
                test_util.test_logger(
                    '[vm:] %s console on %s:%s is connectable' %
                    (vm.get_vm().uuid, console.hostIp, console.port))
            else:
                test_util.test_fail(
                    '[vm:] %s console on %s:%s is not connectable' %
                    (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    for vm in vms:
        if vm:
            vm.destroy()
            vm.check()
    test_util.test_pass('Request Access Multiple VM Console Test Success')
Esempio n. 20
0
def test():
    global test_obj_dict

    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Create volume and check')
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

    test_util.test_dsc('Attach volume and check')
    volume.attach(vm)
    volume.check()

    test_util.test_dsc('Detach volume and check')
    volume.detach()
    volume.check()

    test_util.test_dsc('Delete volume and check')
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    vm.destroy()
    vm.check()

    test_util.test_pass('Create Data Volume for VM Test Success')
Esempio n. 21
0
def test():
    global vm
    pxe_uuid = test_lib.lib_get_pxe_by_name(os.environ.get('pxename')).uuid
    # Create VM
    vm = test_stub.create_vm()
    vm.check()
    # Stop PXE
    bare_operations.stop_pxe(pxe_uuid)
    if test_lib.lib_get_pxe_by_name(os.environ.get('pxename')).status != "Stopped":
        test_util.test_fail('Fail to stop PXE')
    # Start PXE
    bare_operations.start_pxe(pxe_uuid)
    if test_lib.lib_get_pxe_by_name(os.environ.get('pxename')).status != "Running":
        test_util.test_fail('Fail to start PXE')
    # Create Virtual BMC
    test_stub.create_vbmc(vm = vm, port = 6230)
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name = chassis)
    test_stub.hack_ks(port = 6230)
    chassis_uuid = test_lib.lib_get_chassis_by_name(chassis).uuid
    # First time Provision
    bare_operations.provision_baremetal(chassis_uuid)
    hwinfo = test_stub.check_hwinfo(chassis_uuid)
    if not hwinfo:
        test_util.test_fail('Fail to get hardware info during the first provision')
    test_stub.delete_vbmc(vm = vm)
    bare_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    test_util.test_pass('Start/Stop PXE Test Success')
def test():
    global vm
    pxe_uuid = test_lib.lib_get_pxe_by_name(os.environ.get('pxename')).uuid
    # Create VM
    vm = test_stub.create_vm()
    vm.check()
    # Create Virtual BMC
    test_stub.create_vbmc(vm=vm, port=6230)
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name=chassis)
    test_stub.hack_ks(port=6230)
    chassis_uuid = test_lib.lib_get_chassis_by_name(chassis).uuid
    # First time Provision
    bare_operations.provision_baremetal(chassis_uuid)
    bare_operations.stop_pxe(pxe_uuid)
    if not test_stub.verify_chassis_status(chassis_uuid, "PxeBootFailed"):
        test_util.test_fail(
            'Chassis failed to get PxeBootFailed after the first provision')
    bare_operations.start_pxe(pxe_uuid)
    if test_lib.lib_get_pxe_by_name(os.environ.get('pxename')).status != "Running":
                    test_util.test_fail('Fail to start PXE')
    test_stub.delete_vbmc(vm=vm)
    bare_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    test_util.test_pass('Create chassis Test Success')
Esempio n. 23
0
def test():
    global test_obj_dict

    test_util.test_dsc("Create test vm and check")
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc("Create volume and check")
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

    test_util.test_dsc("Attach volume and check")
    volume.attach(vm)
    volume.check()

    test_util.test_dsc("Detach volume and check")
    volume.detach()
    volume.check()

    test_util.test_dsc("Delete volume and check")
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    vm.destroy()
    vm.check()

    test_util.test_pass("Create Data Volume for VM Test Success")
def test():
    global vm
    # Create VM
    vm = test_stub.create_vm()
    vm.check()
    # Create Virtual BMC
    test_stub.create_vbmc(vm = vm, port = 6230)
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name = chassis)
    # Update Chassis
    chassis_uuid = test_lib.lib_get_chassis_by_name(chassis).uuid
    ipmiaddress = os.environ.get('ipmiaddress')
    ipmiuser = os.environ.get('ipmiusername')
    ipmipasswd = os.environ.get('ipmipassword')
    test_stub.delete_vbmc(vm = vm)
    test_stub.create_vbmc(vm = vm, port = 6231)
    bare_operations.update_chassis(chassis_uuid=chassis_uuid, address=ipmiaddress, username=ipmiuser, password=ipmipasswd, port=6231)
    test_stub.hack_ks(port = 6231)
    # First time Provision
    bare_operations.provision_baremetal(chassis_uuid)
    hwinfo = test_stub.check_hwinfo(chassis_uuid)
    if not hwinfo:
        test_util.test_fail('Fail to get hardware info during the first provision')
    new_port = test_lib.lib_get_chassis_by_name(chassis).ipmiPort
    if new_port != "6231":
        test_util.test_fail("Update Chassis's Port failed: port=%s" % new_port)
    test_stub.delete_vbmc(vm = vm)
    bare_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    test_util.test_pass('Update Chassis Test Success')
def test():
    global vm

    import signal

    def handler(signum, frame):
        raise Exception()

    signal.signal(signal.SIGALRM, handler)
    signal.alarm(30)
    boot_option_picture = os.environ.get('bootOptionPicture')

    vm = test_stub.create_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)

    client = api.connect(console.hostIp + ":" + display)
    time.sleep(2)
    client.keyPress('esc')
    #client.captureRegion('/root/boot.png',0,100,600,600)
    client.expectRegion(boot_option_picture, 0, 100)
    test_util.test_logger('[vm:] %s support boot option' % (vm.get_vm().uuid))
    #    except:
    #        test_util.test_fail('[vm:] %s is expected to support boot option' % (vm.get_vm().uuid))

    vm.destroy()

    test_util.test_pass('Support VM Boot Option Test Success')
def test():
    global vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" % (root_password))
        #vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag", root_password=root_password)
        vm = test_stub.create_vm(vm_name='c7-vm-no-sys-tag',
                                 image_name="imageName_i_c7_no_tag")

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

        #if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root", root_password):
        #    test_util.test_fail("create vm with root password: %s failed", root_password)

        # stop vm && change vm password
        #vm.stop()
        vm.check()
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password)
        except Exception, e:
            test_util.test_pass(
                "negative test of change a no system tag image passed.")
Esempio n. 27
0
def test():
    global test_obj_dict
    global vol_num
    global volume
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()
    for i in range(vol_num):
        volume_list.append(test_stub.create_volume())
        test_obj_dict.add_volume(volume_list[i])

    additional_vol = test_stub.create_volume()
    test_obj_dict.add_volume(additional_vol)

    for i in range(vol_num):
        volume_list[i].check()
    time.sleep(60)

    test_util.test_dsc('Test attach/detach 24 volumes operations.')
    for i in range(vol_num):
        volume_list[i].attach(vm)

    for i in range(vol_num):
        volume_list[i].check()

    for i in range(vol_num):
        volume_list[i].detach()
        volume_list[i].check()

    test_util.test_dsc('Redo attach/detach 24 volumes operations.')

    for i in range(vol_num):
        volume_list[i].attach(vm)
        volume_list[i].check()

    test_util.test_dsc('Try to attach the 25th data volume.')
    try:
        additional_vol.attach(vm)
    except:
        test_util.test_logger(
            'Catch expected exception: try to attach the 25th data [volume:] %s to [vm:] %s fail.'
            % (additional_vol.volume.uuid, vm.vm.uuid))

        for i in range(vol_num):
            volume_list[i].detach()
            volume_list[i].check()

        for i in range(vol_num):
            volume_list[i].delete()
            volume_list[i].check()

        vm.destroy()
        test_util.test_pass('Create Multi Data Volumes for VM Test Success')
        return True

    test_util.test_fail(
        'Fail: could attached the 25th data [volume:] %s to [vm:] %s .' %
        (additional_vol.volume.uuid, vm.vm.uuid))
    return False
def test():
    global vm
    global trigger
    global media
    global trigger_action

    vm = test_stub.create_vm()
    vm.check()
    vm_ip = vm.get_vm().vmNics[0].ip
    vm_uuid = vm.get_vm().uuid
    vm_username = os.environ.get('Vm_Username')
    vm_password = os.environ.get('Vm_Password')
    vm_port = os.environ.get('Vm_Sshport')

    test_item = "host.network.io"
    resource_type = "HostVO"
    vm_monitor_item = test_stub.get_monitor_item(resource_type)
    if test_item not in vm_monitor_item:
        test_util.test_fail('%s is not available for monitor' % test_item)

    hosts = res_ops.get_resource(res_ops.HOST)
    host = hosts[0]
    #duration = 60
    duration = 30
    #expression = "host.network.io{direction=\"tx\"} > 2000"
    expression = "host.network.io{direction=\"tx\"} > 100"
    monitor_trigger = mon_ops.create_monitor_trigger(host.uuid, duration, expression)

    send_email = test_stub.create_email_media()
    media = send_email.uuid
    trigger_action_name = "trigger_"+ ''.join(map(lambda xx:(hex(ord(xx))[2:]),os.urandom(8)))
    trigger = monitor_trigger.uuid
    receive_email = os.environ.get('receive_email')
    monitor_trigger_action = mon_ops.create_email_monitor_trigger_action(trigger_action_name, send_email.uuid, trigger.split(), receive_email)
    trigger_action = monitor_trigger_action.uuid

    host.password = os.environ.get('hostPassword')
    ssh_cmd = test_stub.ssh_cmd_line(host.managementIp, host.username, host.password, port=int(host.sshPort))
    
    t = threading.Thread(target=test_stub.run_network_tx,args=(ssh_cmd,vm_ip,))
    t.start()
    time.sleep(50)
    test_stub.kill(ssh_cmd)

    status_problem, status_ok = test_stub.query_trigger_in_loop(trigger,50)
    test_util.action_logger('Trigger old status: %s triggered. Trigger new status: %s recovered' % (status_problem, status_ok ))
    if status_problem != 1 or status_ok != 1:
        test_util.test_fail('%s Monitor Test failed, expected Problem or OK status not triggered' % test_item)

    mail_list = test_stub.receive_email()
    keywords = "fired"
    mail_flag = test_stub.check_email(mail_list, keywords, trigger, host.uuid)
    if mail_flag == 0:
        test_util.test_fail('Failed to Get Target: %s for: %s Trigger Mail' % (host.uuid, test_item))

    mon_ops.delete_monitor_trigger_action(trigger_action)
    mon_ops.delete_monitor_trigger(trigger)
    mon_ops.delete_email_media(media)
    vm.destroy()
def create_vm_wrapper(vm_name, image_name, root_password):
    global vms

    vm = test_stub.create_vm(vm_name=vm_name, image_name=image_name, root_password=root_password)
    if not vm:
        test_util.test_fail("failed to create vm")
    else:
        vms.append(vm)
def test():
    global vm, exist_users
    test_util.test_dsc('Change unexisted user password test')

    vm = test_stub.create_vm(vm_name = 'cknewusrvmpswd-u13-64', image_name = "imageName_i_u13")
    vm.check()

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

    for (usr,passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_util.test_logger("un-existed user:%s change vm password" %(usr))
            #if the user is not existed, it should report
            #try:
            #    vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)
            #except Exception,e:
            #    test_util.test_logger("unexisted user change vm password exception is %s" %(str(e)))
            #    normal_failed_string = "not exist"
            #    if normal_failed_string in str(e):
            #        test_util.test_logger("unexisted user return correct, create a the user for it.")
            #else:
            #    test_util.test_fail("user not exist in this OS, it should not raise exception, but return a failure.")

            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)


        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)
        
        #When vm is stopped:
        #vm.stop()
        vm_ops.change_vm_password(vm.get_vm().uuid, "root", test_stub.original_root_password)

        #vm.start()
        vm.check()


    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vm1
    global vm2
    # Create VM
    vm1 = test_stub.create_vm()
    vm1.check()
    vm2 = test_stub.create_vm()
    vm2.check()
    # Create Virtual BMC
    test_stub.create_vbmc(vm=vm1, port=int(os.environ.get('ipmiport')))
    test_stub.create_vbmc(vm=vm2, port=int(os.environ.get('ipmiport2')))
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name=chassis)
    test_stub.hack_ks(port=os.environ.get('ipmiport'))
    chassis_uuid1 = test_lib.lib_get_chassis_by_name(chassis).uuid
    # Provision VM1
    bare_operations.provision_baremetal(chassis_uuid1)
    hwinfo1 = test_stub.check_hwinfo(chassis_uuid1)

    chassis_option = test_util.ChassisOption()
    chassis_option.set_name(os.environ.get('ipminame2'))
    chassis_option.set_ipmi_address(os.environ.get('ipmiaddress'))
    chassis_option.set_ipmi_username(os.environ.get('ipmiusername'))
    chassis_option.set_ipmi_password(os.environ.get('ipmipassword'))
    chassis_option.set_ipmi_port(os.environ.get('ipmiport2'))

    test_stub.create_chassis(chassis_name=chassis,
                             chassis_option=chassis_option)
    test_stub.hack_ks(port=os.environ.get('ipmiport2'))
    chassis_uuid2 = test_lib.lib_get_chassis_by_name(
        os.environ.get('ipminame2')).uuid

    bare_operations.provision_baremetal(chassis_uuid2)
    hwinfo2 = test_stub.check_hwinfo(chassis_uuid2)
    if not hwinfo1 or not hwinfo2:
        test_util.test_fail(
            'Fail to get hardware info during the first provision')
    test_stub.delete_vbmc(vm=vm1)
    test_stub.delete_vbmc(vm=vm2)
    #bare_operations.delete_chassis(chassis_uuid1)
    #bare_operations.delete_chassis(chassis_uuid2)
    vm1.destroy()
    vm2.destroy()
    test_util.test_pass('Create chassis Test Success')
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    vm.reboot()
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('Reboot VM Test Success')
Esempio n. 33
0
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    vm.stop()
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass("Stop VM Test Success")
Esempio n. 34
0
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    vm.suspend()
    vm.check()
    vm.resume()
    vm.check()
    test_util.test_pass('Suspend VM Test Success')
Esempio n. 35
0
def test():
    global vm, exist_users, cur_usr, cur_passwd
    test_util.test_dsc('change VM with assigned password test')

    vm = test_stub.create_vm(vm_name='ckvmpswd-c6-32',
                             image_name="imageName_i_c6_32")
    vm.check()

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

    cur_usr = "******"
    cur_passwd = "password"

    for (usr, passwd) in zip(users, passwds):

        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid,
                                  usr,
                                  passwd,
                                  skip_stopped_vm=None,
                                  session_uuid=None)

        cur_usr = usr
        cur_passwd = passwd

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed",
                                usr, passwd)

        #When vm is stopped:
        #vm.stop()
        vm_ops.change_vm_password(vm.get_vm().uuid, "root",
                                  test_stub.original_root_password)

        cur_usr = "******"
        cur_passwd = "password"

        #vm.start()
        vm.check()

    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vm
    global trigger
    global media
    global trigger_action

    vm = test_stub.create_vm()
    vm.check()
    vm_ip = vm.get_vm().vmNics[0].ip
    vm_uuid = vm.get_vm().uuid
    vm_username = os.environ.get('Vm_Username')
    vm_password = os.environ.get('Vm_Password')
    vm_port = os.environ.get('Vm_Sshport')

    test_item = "vm.disk.io"
    resource_type = "VmInstanceVO"
    vm_monitor_item = test_stub.get_monitor_item(resource_type)
    if test_item not in vm_monitor_item:
        test_util.test_fail('%s is not available for monitor' % test_item)

    #duration = 60
    duration = 20
    #expression = "vm.disk.io{type=\"iops\", direction=\"write\"} > 100.0"
    expression = "vm.disk.io{type=\"iops\", direction=\"write\"} > 10.0"
    monitor_trigger = mon_ops.create_monitor_trigger(vm_uuid, duration, expression)

    send_email = test_stub.create_email_media()
    media = send_email.uuid
    trigger_action_name = "trigger"+ ''.join(map(lambda xx:(hex(ord(xx))[2:]),os.urandom(8)))
    trigger = monitor_trigger.uuid
    receive_email = os.environ.get('receive_email')
    monitor_trigger_action = mon_ops.create_email_monitor_trigger_action(trigger_action_name, send_email.uuid, trigger.split(), receive_email)
    trigger_action = monitor_trigger_action.uuid

    ssh_cmd = test_stub.ssh_cmd_line(vm_ip, vm_username, vm_password, vm_port)
    rw = 'write'
    t = threading.Thread(target=test_stub.run_disk_load1,args=(ssh_cmd, rw,))
    t.start()
    time.sleep(90)
    test_stub.kill(ssh_cmd)

    status_problem, status_ok = test_stub.query_trigger_in_loop(trigger,50)
    test_util.action_logger('Trigger old status: %s triggered. Trigger new status: %s recovered' % (status_problem, status_ok ))
    if status_problem != 1 or status_ok != 1:
        test_util.test_fail('%s Monitor Test failed, expected Problem or OK status not triggered' % test_item)

    mail_list = test_stub.receive_email()
    keywords = "fired"
    mail_flag = test_stub.check_email(mail_list, keywords, trigger, vm_uuid)
    if mail_flag == 0:
        test_util.test_fail('Failed to Get Target: %s for: %s Trigger Mail' % (vm_uuid, test_item))

    mon_ops.delete_monitor_trigger_action(trigger_action)
    mon_ops.delete_monitor_trigger(trigger)
    mon_ops.delete_email_media(media)
    vm.destroy()
Esempio n. 37
0
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    cmd = 'grep "^host_uuid" /etc/libvirt/libvirtd.conf'
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    if not test_lib.lib_execute_ssh_cmd(host, "root", "password", cmd):
        test_util.test_fail("Check host_uuid in libvirtd.conf failed")
    test_util.test_pass('Check host_uuid in libvirtd Success')
    vm.destroy()
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    cmd = 'grep "^host_uuid" /etc/libvirt/libvirtd.conf'
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    if not test_lib.lib_execute_ssh_cmd(host, "root", "password", cmd):
    	test_util.test_fail("Check host_uuid in libvirtd.conf failed")
    test_util.test_pass('Check host_uuid in libvirtd Success')
    vm.destroy()
Esempio n. 39
0
def create_vm_wrapper(vm_name, image_name, root_password):
    global vms

    vm = test_stub.create_vm(vm_name=vm_name,
                             image_name=image_name,
                             root_password=root_password)
    if not vm:
        test_util.test_fail("failed to create vm")
    else:
        vms.append(vm)
def test():
    global test_obj_dict
    global vol_num
    global volume
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()
    for i in range(vol_num):
        volume_list.append(test_stub.create_volume())
        test_obj_dict.add_volume(volume_list[i])

    additional_vol = test_stub.create_volume()
    test_obj_dict.add_volume(additional_vol)

    for i in range(vol_num):
        volume_list[i].check()
    time.sleep(60)

    test_util.test_dsc('Test attach/detach 20 volumes operations.')
    for i in range(vol_num):
        volume_list[i].attach(vm)

    for i in range(vol_num):
        volume_list[i].check()

    for i in range(vol_num):
        volume_list[i].detach()
        volume_list[i].check()

    test_util.test_dsc('Redo attach/detach 20 volumes operations.')

    for i in range(vol_num):
        volume_list[i].attach(vm)
        volume_list[i].check()

    test_util.test_dsc('Try to attach the 21th data volume.')
    try:
        additional_vol.attach(vm)
    except:
        test_util.test_logger('Catch expected exception: try to attach the 21th data [volume:] %s to [vm:] %s fail.' % (additional_vol.volume.uuid, vm.vm.uuid))
        
        for i in range(vol_num):
            volume_list[i].detach()
            volume_list[i].check()

        for i in range(vol_num):
            volume_list[i].delete()
            volume_list[i].check()

        vm.destroy()
        test_util.test_pass('Create Multi Data Volumes for VM Test Success')
        return True

    test_util.test_fail('Fail: could attached the 21th data [volume:] %s to [vm:] %s .' % (additional_vol.volume.uuid, vm.vm.uuid))
    return False
def test():
    global vm
    global trigger
    global media
    global trigger_action

    vm = test_stub.create_vm()
    vm.check()
    vm_ip = vm.get_vm().vmNics[0].ip
    vm_uuid = vm.get_vm().uuid
    vm_username = os.environ.get('Vm_Username')
    vm_password = os.environ.get('Vm_Password')
    vm_port = os.environ.get('Vm_Sshport')

    test_item = "vm.cpu.util"
    resource_type = "VmInstanceVO"
    vm_monitor_item = test_stub.get_monitor_item(resource_type)
    if test_item not in vm_monitor_item:
        test_util.test_fail('%s is not available for monitor' % test_item)

    duration = 60
    #expression = "vm.cpu.util{}>125.6"
    expression = "vm.cpu.util{}>40"
    monitor_trigger = mon_ops.create_monitor_trigger(vm_uuid, duration, expression)

    send_email = test_stub.create_email_media()
    media = send_email.uuid
    trigger_action_name = "trigger"+ ''.join(map(lambda xx:(hex(ord(xx))[2:]),os.urandom(8)))
    trigger = monitor_trigger.uuid
    receive_email = os.environ.get('receive_email')
    monitor_trigger_action = mon_ops.create_email_monitor_trigger_action(trigger_action_name, send_email.uuid, trigger.split(), receive_email)
    trigger_action = monitor_trigger_action.uuid

    stateevent = "disable"
    mon_ops.change_monitor_trigger_action_state(trigger_action,stateevent)

    ssh_cmd = test_stub.ssh_cmd_line(vm_ip, vm_username, vm_password, vm_port)
    test_stub.yum_install_stress_tool(ssh_cmd)
    test_stub.run_all_cpus_load(ssh_cmd)

    status_problem, status_ok = test_stub.query_trigger_in_loop(trigger,50)
    test_util.action_logger('Trigger old status: %s triggered. Trigger new status: %s recovered' % (status_problem, status_ok ))
    if status_problem != 1 or status_ok != 1:
        test_util.test_fail('%s Monitor Test failed, expected Problem or OK status not triggered' % test_item)

    mail_list = test_stub.receive_email()
    keywords = "fired"
    mail_flag = test_stub.check_email(mail_list, keywords, trigger, vm_uuid)
    if mail_flag != 0:
        test_util.test_fail('Failed to Disable Trigger: %s for: %s Trigger Mail' % (trigger, test_item))

    mon_ops.delete_monitor_trigger_action(trigger_action)
    mon_ops.delete_monitor_trigger(trigger)
    mon_ops.delete_email_media(media)
    vm.destroy()
def test():
    global vm1
    global vm2
    # Create VM
    vm1 = test_stub.create_vm()
    vm1.check()
    vm2 = test_stub.create_vm()
    vm2.check()
    # Create Virtual BMC
    test_stub.create_vbmc(vm = vm1, port = int(os.environ.get('ipmiport')))
    test_stub.create_vbmc(vm = vm2, port = int(os.environ.get('ipmiport2')))
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name = chassis)
    test_stub.hack_ks(port = os.environ.get('ipmiport'))
    chassis_uuid1 = test_lib.lib_get_chassis_by_name(chassis).uuid
    # Provision VM1
    bare_operations.provision_baremetal(chassis_uuid1)
    hwinfo1 = test_stub.check_hwinfo(chassis_uuid1)

    chassis_option = test_util.ChassisOption()
    chassis_option.set_name(os.environ.get('ipminame2'))
    chassis_option.set_ipmi_address(os.environ.get('ipmiaddress'))
    chassis_option.set_ipmi_username(os.environ.get('ipmiusername'))
    chassis_option.set_ipmi_password(os.environ.get('ipmipassword'))
    chassis_option.set_ipmi_port(os.environ.get('ipmiport2'))

    test_stub.create_chassis(chassis_name=chassis, chassis_option=chassis_option)
    test_stub.hack_ks(port = os.environ.get('ipmiport2'))
    chassis_uuid2 = test_lib.lib_get_chassis_by_name(os.environ.get('ipminame2')).uuid
    
    bare_operations.provision_baremetal(chassis_uuid2)
    hwinfo2 = test_stub.check_hwinfo(chassis_uuid2)
    if not hwinfo1 or not hwinfo2:
        test_util.test_fail('Fail to get hardware info during the first provision')
    test_stub.delete_vbmc(vm = vm1)
    test_stub.delete_vbmc(vm = vm2)
    #bare_operations.delete_chassis(chassis_uuid1)
    #bare_operations.delete_chassis(chassis_uuid2)
    vm1.destroy()
    vm2.destroy()
    test_util.test_pass('Create chassis Test Success')
def test():
    global vms, ts, invs
    global ga_process_not_alive_num,keep_vm_num
    test_util.test_dsc('create VM with setting password')

    for i in range(vm_num):
        vms.append(test_stub.create_vm(vm_name = 'c7-vm'+str(i), image_name = "batch_test_image"))
    
    for vm in vms:
        t = threading.Thread(target=change_vm_password_wrapper, args=(vm.get_vm().uuid, "root", "password"))
        ts.append(t)
        t.start()

    for t in ts:
        t.join()

    for cnt in range(max_cnt):
        test_util.test_dsc("this is loop:%d" %(cnt))

        for vm in vms:
            t = threading.Thread(target=vm_reboot_wrapper, args=(vm, cnt))
            ts.append(t)
            t.start()

        for t in ts:
            t.join()

        for vm in vms:
            if check_qemu_ga_is_alive(vm) != 0:
                keep_vm_num = keep_vm_num-1
                vms.remove(vm)
                vms.append(test_stub.create_vm(vm_name = 'c7-vm-new-'+str(keep_vm_num), image_name = "batch_test_image"))
                if keep_vm_num < 0:
                    vm.destroy()
                    vm.expunge()

    for vm in vms:
        if vm:
            vm.destroy()
            vm.expunge()

    test_util.test_fail('total vm reboot times:%s; ga not existed vm:%s' %(vm_num*max_cnt, ga_process_not_alive_num))
def test():
    global vm, test_account_uuid, test_account_session, image_uuid
    import uuid
    account_name = uuid.uuid1().get_hex()
    account_pass = uuid.uuid1().get_hex()
    account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = acc_ops.create_normal_account(account_name, account_pass)
    test_account_uuid = test_account.uuid
    test_account_session = acc_ops.login_by_account(account_name, account_pass)
    test_stub.share_admin_resource([test_account_uuid])

    img_cond = res_ops.gen_query_conditions("name", '=', "centos7-installation-no-system-tag")
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, img_cond, None)
    image_uuid = img_inv[0].uuid
    #res_ops.enable_change_vm_password("true", image_uuid, 'ImageVO', session_uuid = test_account_session)
    img_ops.set_image_qga_enable(image_uuid, session_uuid = test_account_session)
    vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag", session_uuid = test_account_session)
    vm.check()

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

    for (usr,passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)

        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = test_account_session)

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)

        vm_ops.change_vm_password(vm.get_vm().uuid, "root", test_stub.original_root_password, session_uuid = test_account_session)
        vm.check()

    #res_ops.enable_change_vm_password("false", img_inv[0].uuid, 'ImageVO', session_uuid = test_account_session)
    img_ops.set_image_qga_disable(img_inv[0].uuid, session_uuid = test_account_session)
    vm.destroy(test_account_session)
    vm.check()
    vm.expunge(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass('enable and change vm password by normal user account Success')
def test():
    global vms, ts, invs
    test_util.test_dsc('create VM with setting password')

    for (usr, passwd) in zip(users, passwds):
        test_util.test_dsc("user:%s; password:%s" % (usr, passwd))

        vms = []
        for i in range(vm_num):
            vms.append(
                test_stub.create_vm(vm_name='c7-vm' + str(i),
                                    image_name="batch_test_image"))

        time.sleep(30)
        for vm in vms:
            t = threading.Thread(target=change_vm_password_wrapper,
                                 args=(vm.get_vm().uuid, usr, passwd))
            ts.append(t)
            t.start()

        for t in ts:
            t.join()

        for vm in vms:
            if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
                test_util.test_fail(
                    "create vm with user:%s password: %s failed", usr, passwd)

        ts = []
        invs = []

        #When vm is stopped:
        #for vm in vms:
        #    vm.stop()

        for vm in vms:
            t = threading.Thread(target=change_vm_password_wrapper,
                                 args=(vm.get_vm().uuid, "root", "password"))
            ts.append(t)
            t.start()

        for t in ts:
            t.join()

        for vm in vms:
            #vm.start()
            vm.check()

            vm.destroy()
            vm.expunge()
            vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vm, exist_users, cur_usr, cur_passwd
    test_util.test_dsc('change VM with assigned password test')

    vm = test_stub.create_vm(vm_name = 'ckvmpswd-c7-64', image_name = "imageName_i_c7")
    vm.check()

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

    cur_usr = "******"
    cur_passwd = "password"

    for (usr,passwd) in zip(users, passwds):

        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)

        cur_usr = usr
        cur_passwd = passwd

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)
        
        #When vm is stopped:
        #vm.stop()
        vm_ops.change_vm_password(vm.get_vm().uuid, "root", test_stub.original_root_password)

        cur_usr = "******"
        cur_passwd = "password"

        #vm.start()
        vm.check()



    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vms, ts, invs
    test_util.test_dsc('create VM with setting password')

    for (usr,passwd) in zip(users, passwds):
        test_util.test_dsc("user:%s; password:%s" %(usr, passwd))

        vms = []
        for i in range(vm_num):
            vms.append(test_stub.create_vm(vm_name = 'c7-vm'+str(i), image_name = "batch_test_image"))
        
        time.sleep(30)
        for vm in vms:
            t = threading.Thread(target=change_vm_password_wrapper, args=(vm.get_vm().uuid, usr, passwd))
            ts.append(t)
            t.start()

        for t in ts:
            t.join()


        for vm in vms:
            if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
                test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)


        ts   = []
        invs = []

        #When vm is stopped:
        #for vm in vms:
        #    vm.stop()

        for vm in vms:
            t = threading.Thread(target=change_vm_password_wrapper, args=(vm.get_vm().uuid, "root", "password"))
            ts.append(t)
            t.start()

        for t in ts:
            t.join()


        for vm in vms:
            #vm.start()
            vm.check()

            vm.destroy()
            vm.expunge()
            vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vm
    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    vm = test_stub.create_vm()
    vm.check()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure")
    vm.stop()
    time.sleep(60)
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('VM stop with ha mode OnHostFailure Test Success')
def test():
    global vm
    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    vm = test_stub.create_vm()
    vm.check()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure")
    vm.stop()
    time.sleep(60)
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('VM stop with ha mode OnHostFailure Test Success')
def test():
    global vm
    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    vm = test_stub.create_vm()
    vm.check()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure")
    rsp = test_lib.lib_execute_ssh_cmd(vm.get_vm().vmNics[0].ip, test_lib.lib_get_vm_username(vm.get_vm()), test_lib.lib_get_vm_password(vm.get_vm()), 'init 0')
    time.sleep(60)
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('VM shutdown with ha mode OnHostFailure Test Success')
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    delete_policy = test_lib.lib_set_delete_policy('vm', 'Delay')
    vm.destroy()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
    vm.recover()
    time.sleep(60)
    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.destroy()
    test_lib.lib_set_delete_policy('vm', delete_policy)
    test_util.test_pass('VM ha never stop auto start with recover Test Success')
def test():
    global test_obj_dict
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

    volume.attach(vm)
    volume.check()

    vm.stop()
    volume2 = test_stub.create_volume()
    test_obj_dict.add_volume(volume2)
    volume2.check()

    volume2.attach(vm)
    volume2.check()

    volume2.detach()
    volume2.check()

    volume2.attach(vm)
    volume2.check()
        
    vm.start()
    vm.check()
    time.sleep(60)

    volume.check()
    volume2.check()

    volume.detach()
    volume.check()
    volume2.check()

    volume.delete()
    volume.check()
    volume2.check()

    vm.destroy()
    volume2.check()

    volume2.delete()
    volume2.check()
        
    test_util.test_pass('Create Data Volume for stopped VM Test Success')
Esempio n. 53
0
def test():
    global vm
    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    vm = test_stub.create_vm()
    vm.check()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
    vm.stop()
    time.sleep(60)
    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('VM ha never stop Test Success')
def test():
    global vm
    # Create VM
    vm = test_stub.create_vm()
    vm.check()
    # Create Virtual BMC
    test_stub.create_vbmc(vm=vm, port=6230)
    # Create Chassis
    chassis = os.environ.get('ipminame')
    test_stub.create_chassis(chassis_name=chassis)
    test_stub.hack_ks(port=6230)
    chassis_uuid = test_lib.lib_get_chassis_by_name(chassis).uuid
    # First time Provision
    bare_operations.provision_baremetal(chassis_uuid)
    hwinfo = test_stub.check_hwinfo(chassis_uuid)
    if not hwinfo:
        test_util.test_fail(
            'Fail to get hardware info during the first provision')
    #Generate cfgItems
    cfgItems, pxe_mac = test_stub.generate_cfgItems(chassis_uuid=chassis_uuid,
                                                    nic_num=1,
                                                    nic_flag=True,
                                                    bond_num=2,
                                                    slave_num=1,
                                                    mode=4)
    host_cfg = test_stub.create_hostcfg(chassis_uuid=chassis_uuid,
                                        unattended=True,
                                        password="******",
                                        cfgItems=cfgItems)

    test_stub.hack_ks(port=6230, ks_file=str(pxe_mac.replace(':', '-')))
    # Second time Provision to install system
    bare_operations.provision_baremetal(chassis_uuid)
    if not test_stub.verify_chassis_status(chassis_uuid, "Rebooting"):
        test_util.test_fail(
            'Chassis failed to Rebooting after the second provision')
    if not test_stub.verify_chassis_status(chassis_uuid, "Provisioning"):
        test_util.test_fail(
            'Chassis failed to Provisioning after the second provision')
    if not test_stub.verify_chassis_status(chassis_uuid, "Provisioned"):
        test_util.test_fail(
            'Chassis failed to Provisioned after the second provision')
    vm.stop()
    vm.start()
    test_stub.delete_vbmc(vm=vm)
    bare_operations.delete_chassis(chassis_uuid)
    vm.destroy()
    test_util.test_pass('Create PXE Test Success')
def test():
    global vm
    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    vm = test_stub.create_vm()
    vm.check()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure")
    rsp = test_lib.lib_execute_ssh_cmd(
        vm.get_vm().vmNics[0].ip, test_lib.lib_get_vm_username(vm.get_vm()),
        test_lib.lib_get_vm_password(vm.get_vm()), 'init 0')
    time.sleep(60)
    vm.check()
    vm.destroy()
    vm.check()
    test_util.test_pass('VM shutdown with ha mode OnHostFailure Test Success')