def error_cleanup():
    global project_uuid,project_operator_uuid, vxlan_pool_uuid,vni_range_uuid,l2_vxlan_network_uuid,account1_uuid,account2_uuid

    if project_operator_uuid:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if project_uuid:
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)
        
                
    if vni_range_uuid:
        vxlan_ops.delete_vni_range(vni_range_uuid)
    vpc_ops.remove_all_vpc_vrouter()
    test_lib.lib_error_cleanup(test_obj_dict)
        
    if vxlan_pool_uuid:
        net_ops.delete_l2(vxlan_pool_uuid)
    if l2_vxlan_network_uuid:
        net_ops.delete_l2(l2_vxlan_network_uuid)
        
    if account1_uuid:
        acc_ops.delete_account(account1_uuid)
    if account2_uuid:
        acc_ops.delete_account(account2_uuid)
    if platform_admin_uuid:
        iam2_ops.delete_iam2_virtual_id(platform_admin_uuid)
コード例 #2
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')
コード例 #3
0
def error_cleanup():
   global vm
   global test_account_uuid
   if vm:
      vm.destroy()
   if test_account_uuid:
      acc_ops.delete_account(test_account_uuid)
コード例 #4
0
def env_recover():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
コード例 #5
0
def error_cleanup():
    global project_uuid, project_operator_uuid, vxlan_pool_uuid, vni_range_uuid, l2_vxlan_network_uuid, account1_uuid, account2_uuid

    if project_operator_uuid:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if project_uuid:
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)

    if vni_range_uuid:
        vxlan_ops.delete_vni_range(vni_range_uuid)
    vpc_ops.remove_all_vpc_vrouter()
    test_lib.lib_error_cleanup(test_obj_dict)

    if vxlan_pool_uuid:
        net_ops.delete_l2(vxlan_pool_uuid)
    if l2_vxlan_network_uuid:
        net_ops.delete_l2(l2_vxlan_network_uuid)

    if account1_uuid:
        acc_ops.delete_account(account1_uuid)
    if account2_uuid:
        acc_ops.delete_account(account2_uuid)
    if platform_admin_uuid:
        iam2_ops.delete_iam2_virtual_id(platform_admin_uuid)
コード例 #6
0
def test():
    global vm
    global test_account_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])
    vm = test_stub.create_vm(session_uuid = test_account_session)
    vm.check()
    vm.stop(session_uuid = test_account_session)
    vm.check()
    vm.start(session_uuid = test_account_session)
    vm.check()
    vm.reboot(session_uuid = test_account_session)
    vm.check()
    vm.destroy(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass('Operate VM by normal user account Success')
コード例 #7
0
def error_cleanup():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
コード例 #8
0
def env_recover():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
コード例 #9
0
def error_cleanup():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
def error_cleanup():
    global vm
    global test_account_uuid
    if vm:
        vm.destroy()
    if test_account_uuid:
        acc_ops.delete_account(test_account_uuid)
コード例 #11
0
def test():
    global ldap_server_uuid
    global new_account_uuid

    system_tag = ["ldapUseAsLoginName::uid"]
    ldap_server = ldp_ops.add_ldap_server('ldap1',
                                          'ldap for test',
                                          os.environ.get('ldapServerUrl'),
                                          os.environ.get('ldapServerBase'),
                                          os.environ.get('ldapServerUsername'),
                                          os.environ.get('ldapServerPassword'),
                                          'TLS',
                                          systemtags=system_tag)
    ldap_server_uuid = ldap_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]

    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapDn'),
                                             new_account.uuid)
    ldap_account_uuid = ldap_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'),
                                         os.environ.get('ldapPassword'))
    acc_ops.logout(session_uuid)

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(
            os.environ.get('ldapUid'),
            os.environ.get('ldapPassword') + '1')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with wrong password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), '')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with blank password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), None)
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login without password')

    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
コード例 #12
0
def test():
    global vm
    global test_account_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])
    vm = test_stub.create_vm_with_volume(session_uuid=test_account_session)
    vm.check()
    volumes_number = len(test_lib.lib_get_all_volumes(vm.vm))
    if volumes_number != 2:
        test_util.test_fail(
            'Did not find 2 volumes for [vm:] %s. But we assigned 1 data volume when create the vm. We only catch %s volumes'
            % (vm.vm.uuid, volumes_number))
    else:
        test_util.test_logger('Find 2 volumes for [vm:] %s.' % vm.vm.uuid)
    vm.destroy(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass('Create VM with volume by normal user account Success')
コード例 #13
0
def error_cleanup():
    global vm, test_account_uuid, test_account_session, image_uuid
    if image_uuid:
        img_ops.set_image_qga_disable(image_uuid, session_uuid = test_account_session)
    if vm:
        vm.destroy(test_account_session)
    if test_account_uuid:
        acc_ops.delete_account(test_account_uuid)
コード例 #14
0
def error_cleanup():
    global vm, test_account_uuid, test_account_session, vip, eip, l2_uuid, l2_uuid
    if vm:
        vm.destroy(test_account_session)
    acc_ops.delete_account(test_account_uuid)
    vip.delete()
    net_ops.delete_eip(eip.eip.uuid, session_uuid = test_account_session)
    net_ops.delete_l2(l2_uuid)
    net_ops.delete_l2(l2_uuid2)
コード例 #15
0
ファイル: test_stub.py プロジェクト: TinaL3/zstack-woodpecker
def create_delete_account(account_name='test', session_uuid=None):
    try:
        account_inv = acc_ops.create_normal_account(account_name, 'password', session_uuid)
    except:
	test_util.test_logger('ignore exception')
    try:
        acc_ops.delete_account(account_inv.uuid, session_uuid)
    except:
        test_util.test_logger('ignore exception')
def error_cleanup():
    global vm, test_account_uuid, test_account_session, image_uuid
    if image_uuid:
        #res_ops.enable_change_vm_password("false", image_uuid, 'ImageVO', session_uuid = test_account_session)
        img_ops.set_image_qga_disable(image_uuid, session_uuid = test_account_session)
    if vm:
        vm.destroy(test_account_session)
    if test_account_uuid:
        acc_ops.delete_account(test_account_uuid)
コード例 #17
0
def create_delete_account(account_name='test', session_uuid=None):
    try:
        account_inv = acc_ops.create_normal_account(account_name, 'password', session_uuid)
    except:
	test_util.test_logger('ignore exception')
    try:
        acc_ops.delete_account(account_inv.uuid, session_uuid)
    except:
        test_util.test_logger('ignore exception')
コード例 #18
0
def test():
    global ldap_server_uuid
    global new_account_uuid

    ldap_server = ldp_ops.add_ldap_server('ldap1', 'ldap for test', os.environ.get('ldapServerUrl'), os.environ.get('ldapServerBase'), os.environ.get('ldapServerUsername'), os.environ.get('ldapServerPassword'), 'TLS')
    ldap_server_uuid = ldap_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]

    get_expected_exception = False
    try:
        ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapUid'), account.uuid)
    except:
	get_expected_exception = True
    if not get_expected_exception:
        test_util.test_fail('should not be able to bind ldapuid to admin account')

    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapUid'), new_account.uuid)
    ldap_account_uuid = ldap_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
    acc_ops.logout(session_uuid)

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword')+'1')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with wrong password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), '')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with blank password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), None)
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login without password')

    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
コード例 #19
0
def error_cleanup():
    global vm, all_volume_offering_uuid, rw_volume_offering_uuid, all_volume_uuid, rw_volume_uuid, test_account_session, instance_offering_uuid
    if vm:
        vm.destroy(test_account_session)
    vol_ops.delete_disk_offering(all_volume_offering_uuid)
    vol_ops.delete_disk_offering(rw_volume_offering_uuid)
    vol_ops.delete_volume(all_volume_uuid, test_account_session)
    vol_ops.delete_volume(rw_volume_uuid, test_account_session)
    acc_ops.delete_account(test_account_uuid)
    vm_ops.delete_instance_offering(instance_offering_uuid)
def test():
    global vm
    global schd_job1
    global schd_job2
    global schd_trigger1
    global schd_trigger2
    global new_account

    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    start_date = int(time.time())
    schd_job1 = schd_ops.create_scheduler_job('simple_stop_vm_scheduler', 'simple_stop_vm_scheduler', vm.get_vm().uuid, 'stopVm', None)
    schd_trigger1 = schd_ops.create_scheduler_trigger('simple_stop_vm_scheduler', start_date+30, None, 60, 'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger1.uuid, schd_job1.uuid)
    #schd1 = vm_ops.stop_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_stop_vm_scheduler', start_date+30, 60)

    schd_job2 = schd_ops.create_scheduler_job('simple_start_vm_scheduler', 'simple_start_vm_scheduler', vm.get_vm().uuid, 'startVm', None)
    schd_trigger2 = schd_ops.create_scheduler_trigger('simple_start_vm_scheduler', start_date+60, None, 60, 'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger2.uuid, schd_job2.uuid)
    #schd2 = vm_ops.start_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_start_vm_scheduler', start_date+60, 60)

    test_stub.sleep_util(start_date+130)

    test_util.test_dsc('check scheduler state after creating scheduler')
    check_scheduler_state(schd_job1, 'Enabled')
    check_scheduler_state(schd_job2, 'Enabled')
    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob', start_date+30):
        test_util.test_fail('StopVmInstanceJob not executed at expected timestamp range')
    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob', start_date+60):
        test_util.test_fail('StartVmInstanceJob not executed at expected timestamp range')
    
#    vm.check();
    new_account = account_operations.create_account('new_account', 'password', 'Normal')

    res_ops.change_recource_owner(new_account.uuid, vm.vm.uuid)

    current_time = int(time.time())
    except_start_time =  start_date + 60 * (((current_time - start_date) % 60) + 1)
    test_stub.sleep_util(except_start_time + 130)
 
    test_util.test_dsc('check scheduler state after changing the owner of vm')
    check_scheduler_state(schd_job1, 'Disabled')
    check_scheduler_state(schd_job2, 'Disabled')
    if check_scheduler_msg('run scheduler for job: StopVmInstanceJob', except_start_time+30):
        test_util.test_fail('StopVmInstanceJob executed at unexpected timestamp range')
    if check_scheduler_msg('run scheduler for job: StartVmInstanceJob', except_start_time+60):
        test_util.test_fail('StartVmInstanceJob executed at unexpected timestamp range')

    schd_ops.del_scheduler_job(schd_job1.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger1.uuid)
    schd_ops.del_scheduler_job(schd_job2.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger2.uuid)
    vm.destroy()
    account_operations.delete_account(new_account.uuid)

    test_util.test_pass('Check Scheduler State after Changing VM Owner Success')
コード例 #21
0
def error_cleanup():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
def error_cleanup():
    global vm
    global schd
    global new_account
 
    test_lib.lib_error_cleanup(test_obj_dict)

    if schd:
	schd_ops.delete_scheduler(schd.uuid)

    if new_account:
       account_operations.delete_account(new_account.uuid) 
コード例 #23
0
def error_cleanup():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
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')
コード例 #25
0
def test():
    global ad_server_uuid
    global new_account_uuid

    system_tag = ["ldapUseAsLoginName::cn"]
    ad_server = ldp_ops.add_ldap_server('ad1', 'ad for test', os.environ.get('adServerUrl'), os.environ.get('adServerBase'), os.environ.get('adServerUsername'), os.environ.get('adServerPassword'), systemtags=system_tag)
    ad_server_uuid = ad_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]
    account_uuid = account.uuid
    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ad_account = ldp_ops.bind_ldap_account(os.environ.get('adUserDn'), account.uuid)
    ad_account_uuid = ad_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), os.environ.get('adPassword'))
    new_account2 = acc_ops.create_account('new_account2', 'password', 'Normal', session_uuid)
    acc_ops.delete_account(new_account2.uuid)
    acc_ops.logout(session_uuid)
    
    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), os.environ.get('adPassword')+'1')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with wrong password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), '')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with blank password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), None)
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login without password')

    ldp_ops.unbind_ldap_account(ad_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ad_server_uuid)
    test_util.test_pass('Login zstack admin by AD Success')
    acc_ops.logout(session_uuid)
コード例 #26
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', image_name = "imageName_i_c7", 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)

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

        #vm.start(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('change vm password by normal user account Success')
コード例 #27
0
def error_cleanup():
    global vm
    global schd_job
    global schd_trigger
    global new_account

    test_lib.lib_error_cleanup(test_obj_dict)

    if schd_job:
        schd_ops.del_scheduler_job(schd_job.uuid)
    if schd_trigger:
        schd_ops.del_scheduler_trigger(schd_trigger.uuid)

    if new_account:
        account_operations.delete_account(new_account.uuid)
def error_cleanup():
    global project_uuid,project_operator_uuid, test_account_uuid, l2_uuid, l2_uuid1

    if project_operator_uuid:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if project_uuid:
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
    if l2_uuid:
        net_ops.delete_l2(l2_uuid)
    if l2_uuid1:
        net_ops.delete_l2(l2_uuid1)
    if test_account_uuid:
        acc_ops.delete_account(test_account_uuid)
def error_cleanup():
    global vm
    global schd_job
    global schd_trigger
    global new_account
 
    test_lib.lib_error_cleanup(test_obj_dict)

    if schd_job:
	schd_ops.del_scheduler_job(schd_job.uuid)
    if schd_trigger:
	schd_ops.del_scheduler_trigger(schd_trigger.uuid)

    if new_account:
       account_operations.delete_account(new_account.uuid) 
def test():
    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)
    global vm
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    test_util.test_dsc('Test change vm image with quota limited')
    test_account_uuid = test_account.uuid
    #set normal account's storage capacity as 4G
    acc_ops.update_quota(test_account.uuid, "volume.capacity", "4294967296")
    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(session_uuid=test_account_session)
    vm.check()
    image_option = test_util.ImageOption()
    image_option.set_name('8G')
    image_option.set_format('qcow2')
    image_option.set_url(
        "http://172.20.1.15:7480/diskimages/CentOS-7-x86_64-Cloudinit-8G-official.qcow2"
    )
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)
    new_image.add_root_volume_template()

    test_stub.share_admin_resource([test_account_uuid])
    vm.stop(session_uuid=test_account_session)
    image_uuid = test_lib.lib_get_image_by_name("8G").uuid
    try:
        vm_ops.change_vm_image(vm.get_vm().uuid,
                               image_uuid,
                               session_uuid=test_account_session)
    except:
        acc_ops.delete_account(test_account_uuid)
        img_ops.delete_image(test_lib.lib_get_image_by_name('8G').uuid)
        test_util.test_pass(
            'Change Vm Image With Limited Storage Quota Test Success ')
    test_util.test_fail('Overstep the limit of storage capacity')
コード例 #31
0
def error_cleanup():
    global vm
    global schd1
    global schd2
    global new_account
 
    if vm:
        vm.destroy()

    if schd1:
	schd_ops.delete_scheduler(schd1.uuid)

    if schd2:
	schd_ops.delete_scheduler(schd2.uuid)

    if new_account:
       account_operations.delete_account(new_account.uuid) 
def test():
    global vm
    global schd1
    global schd2
    global new_account

    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    start_date = int(time.time())
    schd1 = vm_ops.stop_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_stop_vm_scheduler', start_date+30, 60)
    schd2 = vm_ops.start_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_start_vm_scheduler', start_date+60, 60)

    test_stub.sleep_util(start_date+130)

    test_util.test_dsc('check scheduler state after creating scheduler')
    check_scheduler_state(schd1, 'Enabled')
    check_scheduler_state(schd2, 'Enabled')
    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob', start_date+30):
        test_util.test_fail('StopVmInstanceJob not executed at expected timestamp range')
    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob', start_date+60):
        test_util.test_fail('StartVmInstanceJob not executed at expected timestamp range')
    
#    vm.check();
    new_account = account_operations.create_account('new_account', 'password', 'Normal')

    res_ops.change_recource_owner(new_account.uuid, vm.vm.uuid)

    current_time = int(time.time())
    except_start_time =  start_date + 60 * (((current_time - start_date) % 60) + 1)
    test_stub.sleep_util(except_start_time + 130)
 
    test_util.test_dsc('check scheduler state after changing the owner of vm')
    check_scheduler_state(schd1, 'Disabled')
    check_scheduler_state(schd2, 'Disabled')
    if check_scheduler_msg('run scheduler for job: StopVmInstanceJob', except_start_time+30):
        test_util.test_fail('StopVmInstanceJob executed at unexpected timestamp range')
    if check_scheduler_msg('run scheduler for job: StartVmInstanceJob', except_start_time+60):
        test_util.test_fail('StartVmInstanceJob executed at unexpected timestamp range')

    schd_ops.delete_scheduler(schd1.uuid)
    schd_ops.delete_scheduler(schd2.uuid)
    vm.destroy()
    account_operations.delete_account(new_account.uuid)

    test_util.test_pass('Check Scheduler State after Changing VM Owner Success')
def test():
   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)
   global vm
   bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
   bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
   if not bss:
      test_util.test_skip("not find available backup storage. Skip test")

   test_util.test_dsc('Test change vm image with quota limited')
   test_account_uuid = test_account.uuid
   #set normal account's storage capacity as 4G
   acc_ops.update_quota(test_account.uuid,"volume.capacity","4294967296")
   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(session_uuid = test_account_session)
   vm.check()
   image_option = test_util.ImageOption()
   image_option.set_name('8G')
   image_option.set_format('qcow2')
   image_option.set_url(os.environ.get('imageServer')+"/diskimages/CentOS-7-x86_64-Cloudinit-8G-official.qcow2")
   image_option.set_backup_storage_uuid_list([bss[0].uuid])
   new_image = zstack_image_header.ZstackTestImage()
   new_image.set_creation_option(image_option)
   new_image.add_root_volume_template()

   test_stub.share_admin_resource([test_account_uuid])
   vm.stop(session_uuid = test_account_session)
   image_uuid = test_lib.lib_get_image_by_name("8G").uuid
   try:
      vm_ops.change_vm_image(vm.get_vm().uuid,image_uuid,session_uuid = test_account_session)
   except:
      acc_ops.delete_account(test_account_uuid)
      img_ops.delete_image(test_lib.lib_get_image_by_name('8G').uuid)
      test_util.test_pass('Change Vm Image With Limited Storage Quota Test Success ')
   test_util.test_fail('Overstep the limit of storage capacity')
def error_cleanup():
    global vm
    global schd_job1
    global schd_job2
    global schd_trigger1
    global schd_trigger2
    global new_account
 
    if vm:
        vm.destroy()

    if schd_job1:
	schd_ops.del_scheduler_job(schd_job1.uuid)
    if schd_trigger1:
	schd_ops.del_scheduler_trigger(schd_trigger1.uuid)
    if schd_job2:
	schd_ops.del_scheduler_job(schd_job2.uuid)
    if schd_trigger2:
	schd_ops.del_scheduler_trigger(schd_trigger2.uuid)

    if new_account:
       account_operations.delete_account(new_account.uuid) 
def test():
    global vm
    global test_account_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])
    vm = test_stub.create_vm_with_volume(session_uuid = test_account_session)
    vm.check()
    volumes_number = len(test_lib.lib_get_all_volumes(vm.vm))
    if volumes_number != 2:
        test_util.test_fail('Did not find 2 volumes for [vm:] %s. But we assigned 1 data volume when create the vm. We only catch %s volumes' % (vm.vm.uuid, volumes_number))
    else:
        test_util.test_logger('Find 2 volumes for [vm:] %s.' % vm.vm.uuid)
    vm.destroy(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass('Create VM with volume by normal user account Success')
コード例 #36
0
 def delete(self):
     acc_ops.delete_account(self.get_account().uuid)
     super(ZstackTestAccount, self).delete()
def test():
    global linked_account_uuid,project_uuid,project_operator_uuid,account_lists,l2_uuid,account1_uuid,account2_uuid

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.get_resource(res_ops.CLUSTER)[0].uuid
    # 1 create project
    project_name = 'test_shared_project1'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    linked_account_uuid = project.linkedAccountUuid

    # 2 create project operator
    project_operator_name = 'username_share1'
    project_operator_password = '******'
    attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
    project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid
    # 3 login in project by project operator
    iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid)
    project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password)
    project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid

    l2_inv = net_ops.create_l2_vlan('L2_vlan_2221', 'eth0', zone_uuid, '2221')   
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('share admin resoure to normal account')
    cond = res_ops.gen_query_conditions('name', '=', 'L2_vlan_2221')
    flat_l2_uuid = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    acc_ops.share_resources([linked_account_uuid], [flat_l2_uuid])

    # ut_util.test_dsc('create L3_flat_network names is L3_flat_network by normal account')
    l3_inv = sce_ops.create_l3(zstack_management_ip, 'l3_flat_network', 'L3BasicNetwork', flat_l2_uuid, 'local.com', session_uuid = project_login_uuid)
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.123.2'
    end_ip = '192.168.123.10'
    gateway = '192.168.123.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid, l3_dns, session_uuid = project_login_uuid)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask, session_uuid = project_login_uuid)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions, session_uuid = project_login_uuid).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid,pro_uuid, session_uuid = project_login_uuid)

    test_stub.share_admin_resource_1([linked_account_uuid])

    vm = test_stub.create_vm(session_uuid=project_login_uuid)
    test_obj_dict.add_vm(vm)

    #create normal account
    test_util.test_dsc('create normal account')
    account_name = 'test_abc'
    #account_pass = hashlib.sha512(account_name).hexdigest()
    account_pass = '******'
    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_util.test_dsc('share admin resoure to normal account test_abc')
    test_stub.share_admin_resource_1([test_account_uuid])

    l2_inv1 = sce_ops.create_l2_vlan(zstack_management_ip, 'L2_vlan_2215', 'eth0', '2215', zone_uuid)
    l2_uuid1 = l2_inv1.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(zstack_management_ip, l2_uuid1, cluster_uuid)

    #share admin resoure to normal account
    test_util.test_dsc('share L2 L2_vlan_2215 to normal account test_a')
    cond = res_ops.gen_query_conditions('name', '=', 'L2_vlan_2215')
    flat_l2_uuid1 = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    acc_ops.share_resources([test_account_uuid], [flat_l2_uuid1])

    test_account_session = acc_ops.login_by_account(account_name, account_pass)
    l3_inv1 = sce_ops.create_l3(zstack_management_ip, 'l3_flat_network1', 'L3BasicNetwork', flat_l2_uuid1, 'local.com', session_uuid = test_account_session)
    l3_uuid1 = l3_inv1.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.126.2'
    end_ip = '192.168.126.10'
    gateway = '192.168.126.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network1')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid1, l3_dns, session_uuid = test_account_session)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range', l3_uuid1, start_ip, end_ip, gateway, netmask, session_uuid = test_account_session)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions, session_uuid = test_account_session).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid1,pro_uuid, session_uuid = test_account_session)

    vm2 = test_stub.create_vm(session_uuid = test_account_session)

    test_util.test_dsc('test success normal acount create L3 by admin share L2 ')
    test_obj_dict.add_vm(vm2)

    # 9 delete
    acc_ops.logout(project_login_uuid)
    iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)
    test_lib.lib_error_cleanup(test_obj_dict)

    net_ops.delete_l2(l2_uuid)
    net_ops.delete_l2(l2_uuid1)

    acc_ops.delete_account(test_account_uuid)
def test():
    global vm, session_uuid
    global test_account_uuid, test_account_session
    
    test_util.test_dsc('Test normal account change the qos network and volume ')

    #create normal account
    test_util.test_dsc('create normal account')
    account_name = 'test_a'
    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)

    #create L3 flat network
    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER)[0].uuid
    
    l2_inv = sce_ops.create_l2_vlan(zstack_management_ip, 'L2_vlan_2215', 'eth0', '2215', zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(zstack_management_ip, l2_uuid, cluster_uuid)

    #share admin resoure to normal account
    test_util.test_dsc('share admin resoure to normal account')
    cond = res_ops.gen_query_conditions('name', '=', 'L2_vlan_2215')
    flat_l2_uuid = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    acc_ops.share_resources([test_account_uuid], [flat_l2_uuid])

    test_util.test_dsc('create L3_flat_network names is L3_flat_network by normal account')
    l3_inv = sce_ops.create_l3(zstack_management_ip, 'l3_flat_network', 'L3BasicNetwork', l2_uuid, 'local.com', session_uuid = test_account_session)
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.129.2'
    end_ip = '192.168.129.10'
    gateway = '192.168.129.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid, l3_dns, session_uuid = test_account_session)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask, session_uuid = test_account_session)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions, session_uuid = test_account_session).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid, pro_uuid, session_uuid = test_account_session)

    instance_offerings = res_ops.get_resource(res_ops.INSTANCE_OFFERING)
    for instance_offering in instance_offerings:
        acc_ops.share_resources([test_account_uuid], [instance_offering.uuid])

    #acc_ops.share_resources([test_account_uuid], [instance_offering_uuid])
    cond = res_ops.gen_query_conditions('mediaType', '!=', 'ISO')
    images = res_ops.query_resource(res_ops.IMAGE, cond)
    for image in images:
        acc_ops.share_resources([test_account_uuid], [image.uuid])

    #create vm
    test_util.test_dsc('create vm by normal account test_a')
    vm = test_stub.create_vm(session_uuid = test_account_session)
    
    vm.check()
    vm.destroy(test_account_session)
    net_ops.delete_l2(l2_uuid)
    vm.check()
    acc_ops.delete_account(test_account_uuid)    
    test_util.test_pass('normal account create eip by admin shared vip Test Success')
コード例 #39
0
 def delete(self):
     acc_ops.delete_account(self.get_account().uuid)
     super(ZstackTestAccount, self).delete()
コード例 #40
0
def common_operations(vm,bss,status):

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

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

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

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

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

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

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

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

   #set vm rdp
   vm_ops.set_vm_rdp(vm_uuid,'true')
   vm_ops.set_vm_rdp(vm_uuid,'false')
コード例 #41
0
def test():
    global vm, session_uuid
    global all_volume_offering_uuid, rw_volume_offering_uuid, instance_offering_uuid
    global test_account_uuid
    
    test_util.test_dsc('Test normal account change the qos network and volume ')

    #create normal account
    test_util.test_dsc('create normal account')
    account_name = 'a'
    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)

    #create disk offering
    test_util.test_dsc('create disk offering')
    name_all = 'all_disk_offering'	
    volume_bandwidth = 30*1024*1024
    all_volume_offering = test_lib.lib_create_disk_offering(name = name_all, volume_bandwidth = volume_bandwidth)
    all_volume_offering_uuid = all_volume_offering.uuid

    name_rw = 'rw_disk_offering'	
    volume_read_bandwidth = 90*1024*1024
    volume_write_bandwidth = 100*1024*1024
    rw_volume_offering = test_lib.lib_create_disk_offering(name = name_rw, read_bandwidth = volume_read_bandwidth, write_bandwidth = volume_write_bandwidth)
    rw_volume_offering_uuid = rw_volume_offering.uuid

    #create instance offering 
    test_util.test_dsc('create instance offering')
    read_bandwidth = 50*1024*1024
    write_bandwidth = 60*1024*1024
    net_outbound_bandwidth = 70*1024*1024
    net_inbound_bandwidth = 80*1024*1024
    new_instance_offering = test_lib.lib_create_instance_offering(read_bandwidth = read_bandwidth, write_bandwidth=write_bandwidth, net_outbound_bandwidth = net_outbound_bandwidth, net_inbound_bandwidth = net_inbound_bandwidth)
    instance_offering_uuid = new_instance_offering.uuid
    
    #share admin resoure to normal account
    test_util.test_dsc('share admin resoure to normal account')
    test_stub.share_admin_resource([test_account_uuid])
    acc_ops.share_resources([test_account_uuid], [all_volume_offering_uuid, rw_volume_offering_uuid])

    #create vm with 2 data volumes
    test_util.test_dsc('create vm with volumes qos by normal account a')
    l3net_uuid = res_ops.get_resource(res_ops.L3_NETWORK, session_uuid = test_account_session)[0].uuid
    cond = res_ops.gen_query_conditions('platform', '=', 'Linux')
    image_uuid = res_ops.query_resource(res_ops.IMAGE, cond, session_uuid = test_account_session)[0].uuid
    vm_creation_option = test_util.VmOption()
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_l3_uuids([l3net_uuid])

    vm = test_stub.create_vm_with_volume(vm_creation_option = vm_creation_option,  data_volume_uuids = [all_volume_offering_uuid, rw_volume_offering_uuid], session_uuid = test_account_session)
    vm_inv = vm.get_vm()

    # get  the nic uuid
    test_util.test_dsc('get the vm_nic')
    l3_uuid = vm_inv.vmNics[0].l3NetworkUuid
    vm_nic = test_lib.lib_get_vm_nic_by_l3(vm_inv, l3_uuid)

    # get the volume uuid
    test_util.test_dsc('get the vm data volumes')
    cond1 = res_ops.gen_query_conditions("diskOfferingUuid", '=', all_volume_offering_uuid)
    cond2 = res_ops.gen_query_conditions("diskOfferingUuid", '=', rw_volume_offering_uuid)
    all_volume_uuid = res_ops.query_resource(res_ops.VOLUME, cond1)[0].uuid
    rw_volume_uuid = res_ops.query_resource(res_ops.VOLUME, cond2)[0].uuid
    #set root disk qos
    test_util.test_dsc('set read*2, read/2, write*2, write/2 and del the root disk read and write qos')    
    try:
    	vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = read_bandwidth*2, mode = 'read', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('del the root disk read qos')    
    try:
    	vm_ops.del_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, mode = 'read', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass
    vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = read_bandwidth/2, mode = 'read', session_uuid = test_account_session)

    test_util.test_dsc('set 2 times the root disk write qos')    
    try:
    	vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = write_bandwidth*2, mode = 'write', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('del the root disk write qos')    
    try:
    	vm_ops.del_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, mode = 'write', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('set below the root disk write qos')    
    vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = write_bandwidth/2, mode = 'write', session_uuid = test_account_session)

    #set data disk all_volume_uuid qos
    test_util.test_dsc('set read*2, read/2, write*2, write/2 and del the volume1 disk read and write qos')    
    try:
    	vm_ops.set_vm_disk_qos(all_volume_uuid, volumeBandwidth = volume_bandwidth*2, session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('del the data volume qos')    
    try:
    	vm_ops.del_vm_disk_qos(all_volume_uuid, session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    vm_ops.set_vm_disk_qos(all_volume_uuid, volumeBandwidth = volume_bandwidth/2, session_uuid = test_account_session)

    #set data disk rw_volume_uuid write qos
    test_util.test_dsc('set 2 times the data rw_volume_uuid write qos')    
    try:
    	vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_write_bandwidth*2, mode = 'write', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('del the data rw_volume_uuid  write qos')
    try:
    	vm_ops.del_vm_disk_qos(rw_volume_uuid, mode = 'write', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_write_bandwidth/2, mode = 'write', session_uuid = test_account_session)

    #set data disk rw_volume_uuid read qos
    test_util.test_dsc('set 2 times the data rw_volume_uuid read qos')    
    try:
    	vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_read_bandwidth*2, mode = 'read', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass
    test_util.test_dsc('del the data rw_volume_uuid read qos')
    try:
    	vm_ops.del_vm_disk_qos(rw_volume_uuid, mode = 'read', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass
    vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_read_bandwidth/2, mode = 'read', session_uuid = test_account_session)

   # set the vm nic qos
    test_util.test_dsc('set higher than net out and in ')    
    try:
	vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth*2, inboundBandwidth = net_inbound_bandwidth*2, session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('set higher than net out and equal in ')    
    try:
	vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth*2, inboundBandwidth = net_inbound_bandwidth, session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('del net  in ')    
    try:
	vm_ops.del_vm_nic_qos(vm_nic.uuid, direction = 'in', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('del net out ')    
    try:
	vm_ops.del_vm_nic_qos(vm_nic.uuid, direction = 'out', session_uuid = test_account_session)
    except:
	print "Test results were in line with expectations"
	pass

    test_util.test_dsc('set equal net out and  in ')    
    try:
	vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth, inboundBandwidth = net_inbound_bandwidth, session_uuid = test_account_session)
    #except:
    except Exception as e:	
	test_util.test_logger(e)

    test_util.test_dsc('set below net out and  in ')    
    vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth/2, inboundBandwidth = net_inbound_bandwidth/2, session_uuid = test_account_session)

    vm.check()
    vm.destroy(test_account_session)
    vm.check()
    vol_ops.delete_disk_offering(all_volume_offering_uuid)
    vol_ops.delete_disk_offering(rw_volume_offering_uuid)
    vol_ops.delete_volume(all_volume_uuid, test_account_session)
    vol_ops.delete_volume(rw_volume_uuid, test_account_session)
    acc_ops.delete_account(test_account_uuid)    
    vm_ops.delete_instance_offering(instance_offering_uuid)
    test_util.test_pass('Create VM Test Success')
コード例 #42
0
def test():
    global vm
    global schd_job
    global schd_trigger
    global new_account

    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_name('volume for snapshot scheduler testing')
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    volume.attach(vm)
    volume.detach()

    test_util.test_dsc('create snapshot scheduler')
    start_date = int(time.time())
    #sp_option = test_util.SnapshotOption()
    #sp_option.set_name('simple_schduler_snapshot')
    #sp_option.set_volume_uuid(volume.get_volume().uuid)
    schd_job = schd_ops.create_scheduler_job(
        'simple_create_snapshot_scheduler', 'simple_create_snapshot_scheduler',
        volume.get_volume().uuid, 'volumeSnapshot', None)
    schd_trigger = schd_ops.create_scheduler_trigger(
        'simple_create_snapshot_scheduler', start_date + 60, None, 120,
        'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger.uuid, schd_job.uuid)

    #schd = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler',  start_date+60, 120)

    check_scheduler_state(schd_job, 'Enabled')

    snapshot_num = 0
    for i in range(0, 3):
        test_util.test_logger('round %s' % (i))
        test_stub.sleep_util(start_date + 60 + 120 * i - 2)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (start_date + 60 + 120 * i - 2, snapshot_num))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))
        snapshot_num += 1

        test_stub.sleep_util(start_date + 60 + 120 * i + 65)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (start_date + 60 + 120 * i + 65, snapshot_num + 1))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))

    new_account = account_operations.create_account('new_account', 'password',
                                                    'Normal')

    res_ops.change_recource_owner(new_account.uuid, volume.get_volume().uuid)

    test_util.test_dsc(
        'check scheduler state after changing the owner of volume')
    check_scheduler_state(schd_job, 'Disabled')

    current_time = int(time.time())
    except_start_time = start_date + 120 * ((
        (current_time - start_date) % 120) + 1)

    for i in range(0, 3):
        test_util.test_logger('round %s' % (i))
        test_stub.sleep_util(except_start_time + 60 + 120 * i - 2)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (except_start_time + 60 + 120 * i - 2, snapshot_num))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))

        test_stub.sleep_util(except_start_time + 60 + 120 * i + 60)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (except_start_time + 60 + 120 * i + 65, snapshot_num + 1))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))

    schd_ops.del_scheduler_job(schd_job.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger.uuid)
    vm.destroy()
    account_operations.delete_account(new_account.uuid)

    test_util.test_pass(
        'Check Scheduler State after Changing Volume Owner Success')
def test():
    global linked_account_uuid,project_uuid,project_operator_uuid,account_lists,vni_range_uuid,vxlan_pool_uuid,l2_vxlan_network_uuid,account1_uuid,account2_uuid,platform_admin_uuid

    # create vxlan pool and vni range
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.get_resource(res_ops.CLUSTER)[0].uuid
    vxlan_pool_name = 'vxlan_pool_name'

    vxlan_pool_uuid = vxlan_ops.create_l2_vxlan_network_pool(vxlan_pool_name,zone_uuid).uuid
    vxlan_ops.create_vni_range('vni_range',20,40,vxlan_pool_uuid)
        
    systemTags = ["l2NetworkUuid::%s::clusterUuid::%s::cidr::{172.20.0.1/16}"%(vxlan_pool_uuid,cluster_uuid)]
    net_ops.attach_l2_vxlan_pool(vxlan_pool_uuid,cluster_uuid,systemTags)
        
    # 1 create project
    project_name = 'test_share_project1'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    #cond = res_ops.gen_query_conditions("name",'=',"test_share_project1")
    #linked_account_uuid = res_ops.query_resource(res_ops.ACCOUNT,cond)[0].uuid
    linked_account_uuid = project.linkedAccountUuid

    # 2 create project operator
    project_operator_name = 'share_username1'
    project_operator_password = '******'
    attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
    project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid

    # 3 login in project by project operator
    iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid)
    project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password)
    project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid
    # todo:use the shared resources
        
    # 4 create platformAdmin and login
    username = '******'
    password = '******'
    platform_admin_uuid = iam2_ops.create_iam2_virtual_id(username, password).uuid
    attributes = [{"name":"__PlatformAdmin__"}]
    iam2_ops.add_attributes_to_iam2_virtual_id(platform_admin_uuid, attributes)
    platform_admin_session_uuid = iam2_ops.login_iam2_virtual_id(username, password)

        
    # 5 share platform admin resources to project 
    test_stub.share_admin_resource_include_vxlan_pool([linked_account_uuid],platform_admin_session_uuid)
    # use the shared resources to create vm
    vm = test_stub.create_vm(session_uuid=project_login_uuid)
    volume = test_stub.create_volume(session_uuid=project_login_uuid)
    test_obj_dict.add_volume(volume)
    test_obj_dict.add_vm(vm)
    l2_vxlan_network_uuid = vxlan_ops.create_l2_vxlan_network('l2_vxlan',vxlan_pool_uuid,zone_uuid,session_uuid=project_login_uuid).uuid
    virtual_router_offering_uuid = res_ops.get_resource(res_ops.VR_OFFERING)[0].uuid
    vpc_ops.create_vpc_vrouter('vpc_router',virtual_router_offering_uuid,session_uuid=project_login_uuid)
        
        
    # 6 revoke platform admin resources from project
    test_stub.revoke_admin_resource([linked_account_uuid],platform_admin_session_uuid)
        
       
        
    # 7 share to all
    #create_account
    account1_uuid = acc_ops.create_account('user1','password','Normal').uuid
    account2_uuid = acc_ops.create_account('user2','password','Normal').uuid
        
    account_lists = res_ops.query_resource(res_ops.ACCOUNT)
    for account in account_lists:
        test_stub.share_admin_resource_include_vxlan_pool([account.uuid],platform_admin_session_uuid)
        
            
    # 8 revoke resources from all
    for account in account_lists:
        test_stub.revoke_admin_resource([account.uuid],platform_admin_session_uuid)
        
        
            
    # 9 Negative test
    test_util.test_dsc('Doing negative test.Try to use the resources not shared to create vm')
    try:
        test_stub.create_vm(session_uuid=project_login_uuid)
    except:
        test_util.test_logger('Catch excepted excepttion.can not use the resources not shared to create vm')
    else:
        test_util.test_fail('Catch wrong logic:create vm success with the resources not shared ')
        
    test_util.test_dsc('Doing negative test.Try to use the resources not shared to create volume')
    try:
        test_stub.create_volume(session_uuid=project_login_uuid)
    except:
        test_util.test_logger('Catch excepted excepttion.can not use the resources not shared to create volume')
    else:
        test_util.test_fail('Catch wrong logic:create volume success with the resources not shared ')
    
    test_util.test_dsc('Doing negative test.Try to use the resources not shared to create vxlan network')
    try:
        vxlan_ops.create_l2_vxlan_network('l2_vxlan',vxlan_pool_uuid,zone_uuid,session_uuid=project_login_uuid)
    except:
        test_util.test_logger('Catch excepted excepttion.can not use the resources not shared to create l2 vxlan')
    else:
        test_util.test_fail('Catch wrong logic:create l2 vxlan success with the resources not shared ')
    
    test_util.test_dsc('Doing negative test.Try to use the resources not shared to create vpc_vrouter ')    
    try:
        vpc_ops.create_vpc_vrouter('vpc_router',virtual_router_offerings,session_uuid=project_login_uuid)
    except: 
        test_util.test_logger('Catch excepted excepttion.can not use the resources not shared to create vpc_router')
    else:
        test_util.test_fail('Catch wrong logic:create vpc_router success with the resources not shared ')
            
            
    # 10 delete
    acc_ops.logout(project_login_uuid)
    iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)
    vni_range_uuid = res_ops.get_resource(res_ops.VNI_RANGE)[0].uuid
    vxlan_ops.delete_vni_range(vni_range_uuid)
    vpc_ops.remove_all_vpc_vrouter()
    test_lib.lib_error_cleanup(test_obj_dict)
        
        
    net_ops.delete_l2(vxlan_pool_uuid)
    net_ops.delete_l2(l2_vxlan_network_uuid)
        
        
    acc_ops.delete_account(account1_uuid)
    acc_ops.delete_account(account2_uuid)
    iam2_ops.delete_iam2_virtual_id(platform_admin_uuid)
def error_cleanup():
    global vm, test_account_uuid, test_account_session, l2_uuid 
    if vm:
        vm.destroy(test_account_session)
    acc_ops.delete_account(test_account_uuid)
    net_ops.delete_l2(l2_uuid)
def error_cleanup():
    global vm, test_account_uuid, test_account_session
    if vm:
        vm.destroy(test_account_session)
    if test_account_uuid:
        acc_ops.delete_account(test_account_uuid)
コード例 #46
0
def common_operations(vm, bss, status):

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

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

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

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

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

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

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

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

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

    #set vm rdp
    vm_ops.set_vm_rdp(vm_uuid, 'true')
    vm_ops.set_vm_rdp(vm_uuid, 'false')
コード例 #47
0
def test():
    global ad_server_uuid
    global new_account_uuid

    system_tag = ["ldapUseAsLoginName::cn"]
    ad_server = ldp_ops.add_ldap_server('ad1',
                                        'ad for test',
                                        os.environ.get('adServerUrl'),
                                        os.environ.get('adServerBase'),
                                        os.environ.get('adServerUsername'),
                                        os.environ.get('adServerPassword'),
                                        systemtags=system_tag)
    ad_server_uuid = ad_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]
    account_uuid = account.uuid
    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ad_account = ldp_ops.bind_ldap_account(os.environ.get('adUserDn'),
                                           account.uuid)
    ad_account_uuid = ad_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'),
                                         os.environ.get('adPassword'))
    new_account2 = acc_ops.create_account('new_account2', 'password', 'Normal',
                                          session_uuid)
    acc_ops.delete_account(new_account2.uuid)
    acc_ops.logout(session_uuid)

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(
            os.environ.get('adUserCn'),
            os.environ.get('adPassword') + '1')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with wrong password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), '')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with blank password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), None)
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login without password')

    ldp_ops.unbind_ldap_account(ad_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ad_server_uuid)
    test_util.test_pass('Login zstack admin by AD Success')
    acc_ops.logout(session_uuid)
コード例 #48
0
def error_cleanup():
    global vm, test_account_uuid, test_account_session
    if vm:
        vm.destroy(test_account_session)
    if test_account_uuid:
        acc_ops.delete_account(test_account_uuid)
コード例 #49
0
def test():
    global linked_account_uuid, project_uuid, project_operator_uuid, account_lists, vni_range_uuid, vxlan_pool_uuid, l2_vxlan_network_uuid, account1_uuid, account2_uuid

    # create vxlan pool and vni range
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.get_resource(res_ops.CLUSTER)[0].uuid
    vxlan_pool_name = 'vxlan_pool_name'

    vxlan_pool_uuid = vxlan_ops.create_l2_vxlan_network_pool(
        vxlan_pool_name, zone_uuid).uuid
    vxlan_ops.create_vni_range('vni_range', 20, 40, vxlan_pool_uuid)

    systemTags = [
        "l2NetworkUuid::%s::clusterUuid::%s::cidr::{172.20.0.1/16}" %
        (vxlan_pool_uuid, cluster_uuid)
    ]
    net_ops.attach_l2_vxlan_pool(vxlan_pool_uuid, cluster_uuid, systemTags)

    # 1 create project
    project_name = 'test_share_project1'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    cond = res_ops.gen_query_conditions("name", '=', "test_share_project1")
    linked_account_uuid = res_ops.query_resource(res_ops.ACCOUNT, cond)[0].uuid

    # 2 create project operator
    project_operator_name = 'share_username1'
    project_operator_password = '******'
    attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
    project_operator_uuid = iam2_ops.create_iam2_virtual_id(
        project_operator_name,
        project_operator_password,
        attributes=attributes).uuid
    # 3 login in project by project operator
    iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],
                                             project_uuid)
    project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(
        project_operator_name, project_operator_password)
    project_login_uuid = iam2_ops.login_iam2_project(
        project_name, session_uuid=project_operator_session_uuid).uuid
    # todo:use the shared resources

    # 4 share admin resources to project
    test_stub.share_admin_resource_include_vxlan_pool([linked_account_uuid])
    # use the shared resources to create vm
    vm = test_stub.create_vm(session_uuid=project_login_uuid)
    volume = test_stub.create_volume(session_uuid=project_login_uuid)
    test_obj_dict.add_volume(volume)
    test_obj_dict.add_vm(vm)
    l2_vxlan_network_uuid = vxlan_ops.create_l2_vxlan_network(
        'l2_vxlan',
        vxlan_pool_uuid,
        zone_uuid,
        session_uuid=project_login_uuid).uuid
    virtual_router_offering_uuid = res_ops.get_resource(
        res_ops.VR_OFFERING)[0].uuid
    vpc_ops.create_vpc_vrouter('vpc_router',
                               virtual_router_offering_uuid,
                               session_uuid=project_login_uuid)

    # 5 revoke admin resources from project
    test_stub.revoke_admin_resource([linked_account_uuid])

    # 6 share to all
    #create_account
    account1_uuid = acc_ops.create_account('user1', 'password', 'Normal').uuid
    account2_uuid = acc_ops.create_account('user2', 'password', 'Normal').uuid

    account_lists = res_ops.query_resource(res_ops.ACCOUNT)
    for account in account_lists:
        test_stub.share_admin_resource_include_vxlan_pool([account.uuid])

    # 7 revoke resources from all
    for account in account_lists:
        test_stub.revoke_admin_resource([account.uuid])

    # 8 Negative test
    test_util.test_dsc(
        'Doing negative test.Try to use the resources not shared to create vm')
    try:
        test_stub.create_vm(session_uuid=project_login_uuid)
    except:
        test_util.test_logger(
            'Catch excepted excepttion.can not use the resources not shared to create vm'
        )
    else:
        test_util.test_fail(
            'Catch wrong logic:create vm success with the resources not shared '
        )

    test_util.test_dsc(
        'Doing negative test.Try to use the resources not shared to create volume'
    )
    try:
        test_stub.create_volume(session_uuid=project_login_uuid)
    except:
        test_util.test_logger(
            'Catch excepted excepttion.can not use the resources not shared to create volume'
        )
    else:
        test_util.test_fail(
            'Catch wrong logic:create volume success with the resources not shared '
        )

    test_util.test_dsc(
        'Doing negative test.Try to use the resources not shared to create vxlan network'
    )
    try:
        vxlan_ops.create_l2_vxlan_network('l2_vxlan',
                                          vxlan_pool_uuid,
                                          zone_uuid,
                                          session_uuid=project_login_uuid)
    except:
        test_util.test_logger(
            'Catch excepted excepttion.can not use the resources not shared to create l2 vxlan'
        )
    else:
        test_util.test_fail(
            'Catch wrong logic:create l2 vxlan success with the resources not shared '
        )

    test_util.test_dsc(
        'Doing negative test.Try to use the resources not shared to create vpc_vrouter '
    )
    try:
        vpc_ops.create_vpc_vrouter('vpc_router',
                                   virtual_router_offerings,
                                   session_uuid=project_login_uuid)
    except:
        test_util.test_logger(
            'Catch excepted excepttion.can not use the resources not shared to create vpc_router'
        )
    else:
        test_util.test_fail(
            'Catch wrong logic:create vpc_router success with the resources not shared '
        )

    # 9 delete
    acc_ops.logout(project_login_uuid)
    iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)
    vni_range_uuid = res_ops.get_resource(res_ops.VNI_RANGE)[0].uuid
    vxlan_ops.delete_vni_range(vni_range_uuid)
    vpc_ops.remove_all_vpc_vrouter()
    test_lib.lib_error_cleanup(test_obj_dict)

    net_ops.delete_l2(vxlan_pool_uuid)
    net_ops.delete_l2(l2_vxlan_network_uuid)

    acc_ops.delete_account(account1_uuid)
    acc_ops.delete_account(account2_uuid)
コード例 #50
0
def test():
    global ldap_server_uuid
    global new_account_uuid
    global new_account_uuid2
    system_tag = "ldapUseAsLoginName::uid"
    ldap_server = ldp_ops.add_ldap_server('ldap1', 'ldap for test', os.environ.get('ldapServerUrl'), os.environ.get('ldapServerBase'), os.environ.get('ldapServerUsername'), os.environ.get('ldapServerPassword'), systemtags=[system_tag])
    ldap_server_uuid = ldap_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]

    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    new_account2 = acc_ops.create_account('new_account2', 'password', 'Normal')
    new_account_uuid2 = new_account2.uuid

    ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapDn'), new_account.uuid)
    ldap_account_uuid = ldap_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
    acc_ops.logout(session_uuid)
    ldap_account2 = ldp_ops.bind_ldap_account('uid=ldapuser3,ou=People,dc=mevoco,dc=com', new_account2.uuid)
    ldap_account_uuid2 = ldap_account2.inventory.uuid
    session_uuid2 = acc_ops.login_by_ldap('ldapuser3', 'password')
    acc_ops.logout(session_uuid)

    #Update multi ldap filters
    system_tags = ["ldapCleanBindingFilter::(&(loginShell=/bin/bash)(|(homeDirectory=/home/mldapuser)(homeDirectory=/home/ldapuser3)))", "ldapUseAsLoginName::uid"]
    ldap_filter = ldp_ops.update_ldap_server(ldap_server_uuid, system_tags)

    ldp_ops.clean_invalid_ldap_binding()

    get_excepted_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True

    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with filter account')

    get_excepted_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap('ldapuser3','password')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True

    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with filter account')

    cond = res_ops.gen_query_conditions('resourceUuid', '=', ldap_server_uuid)
    ldap_clean_binding_filter_tag_uuid = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0].uuid
    #Clear filter
    tag_ops.delete_tag(ldap_clean_binding_filter_tag_uuid)
    
    ldap_filter = ldp_ops.update_ldap_server(ldap_server_uuid, [system_tag]) 
    ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapDn'), new_account.uuid)
    ldap_account_uuid = ldap_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
    acc_ops.logout(session_uuid)
    ldap_account2 = ldp_ops.bind_ldap_account('uid=ldapuser3,ou=People,dc=mevoco,dc=com', new_account2.uuid)
    ldap_account_uuid2 = ldap_account2.inventory.uuid
    session_uuid2 = acc_ops.login_by_ldap('ldapuser3', 'password')
    acc_ops.logout(session_uuid)

    ldp_ops.clean_invalid_ldap_binding()

    get_excepted_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True

    if get_excepted_exception:
        test_util.test_fail('should be able to login after removed filter but login failed')

    get_excepted_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap('ldapuser3','password')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True

    if get_excepted_exception:
        test_util.test_fail('should be able to login after removed filter but login failed')

    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    ldp_ops.unbind_ldap_account(ldap_account_uuid2)
    acc_ops.delete_account(new_account_uuid)
    acc_ops.delete_account(new_account_uuid2)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
コード例 #51
0
def test():
    test_util.test_dsc('Create test vm with EIP and check.')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)
    vm.check()

    l3_name = os.environ.get('l3VlanNetworkName1')
    vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid)
    temp_vm1 = None
    if not vrs:
        #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding
        temp_vm1 = test_stub.create_vlan_vm()
        test_obj_dict.add_vm(temp_vm1)
        vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0]
    else:
        vr1 = vrs[0]

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

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

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    pri_l3_uuid = vm_nic.l3NetworkUuid
    vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0]
    vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr)
    l3_uuid = vr_pub_nic.l3NetworkUuid
    vip = test_stub.create_vip('create_eip_test', l3_uuid)
    test_obj_dict.add_vip(vip)

    eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid)
    vip.attach_eip(eip)
    vip.check()

    test_account = account_operations.create_account('account-%s' % time.strftime('%m%d-%H%M%S', time.localtime()), 'password', 'Normal')
    res_ops.change_recource_owner(test_account.uuid, eip.eip.uuid)
    account_operations.delete_account(test_account.uuid)

    eip.attach(vm_nic_uuid, vm)
    vip.check()
    eip.detach()
    vip.check()

    vm.destroy()
    test_obj_dict.rm_vm(vm)
    eip.delete()
    vip.delete()
    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Change EIP Owner Success')