Ejemplo n.º 1
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')
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')
Ejemplo n.º 3
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')
Ejemplo n.º 4
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')
Ejemplo n.º 5
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')
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 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')
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')
Ejemplo n.º 9
0
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
    try:
        img_ops.set_image_qga_enable(image_uuid, session_uuid = test_account_session)
    except:
        test_util.test_pass('Enable and change vm password by normal user account Success')
    
    test_util.test_fail('It should be raise exception when setImageQga after image is shared to this normal account, however, got no exception.')
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 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')
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')
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 common_operations(vm,bss,status):

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

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

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

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

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

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

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

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

   #set vm rdp
   vm_ops.set_vm_rdp(vm_uuid,'true')
   vm_ops.set_vm_rdp(vm_uuid,'false')
def test():
    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')
def common_operations(vm, bss, status):

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

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

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

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

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

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

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

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

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

    #set vm rdp
    vm_ops.set_vm_rdp(vm_uuid, 'true')
    vm_ops.set_vm_rdp(vm_uuid, 'false')
 def create(self, username, password):
     self.set_account(acc_ops.create_normal_account(username, password))
     self.username = username
     self.password = password
     super(ZstackTestAccount, self).create()
 def create(self, username, password):
     self.set_account(acc_ops.create_normal_account(username, password))
     self.username = username
     self.password = password
     super(ZstackTestAccount, self).create()