def test(): global ldap_server_uuid global new_account_uuid global new_account_uuid2 system_tags = ["ldapCleanBindingFilter::(uidNumber=1002)", "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'), 'None', system_tags) 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) 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') new_account2 = acc_ops.create_account('new_account2', 'password', 'Normal') new_account_uuid2 = new_account2.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) '''
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)
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)
def test(): global ldap_server_uuid global new_account_uuid global new_account_uuid2 system_tags = [ "ldapCleanBindingFilter::(uidNumber=1002)", "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'), 'None', system_tags) 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) 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') new_account2 = acc_ops.create_account('new_account2', 'password', 'Normal') new_account_uuid2 = new_account2.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) '''
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)
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')
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(): 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)
@author: Carl ''' import zstackwoodpecker.test_lib as test_lib import zstackwoodpecker.operations.resource_operations as res_ops import zstackwoodpecker.operations.account_operations as acc_ops from test_stub import * import random import string new_account_uuid = None global new_account random_name=''.join(random.sample(string.ascii_letters + string.digits, 8)) new_account = acc_ops.create_account(random_name, 'password', 'Normal') new_account_uuid = new_account.uuid class Change_VM_Owner_Parall(VM_Operation_Parall): def operate_vm_parall(self, vm_uuid): try: res_ops.change_recource_owner(new_account.uuid,vm_uuid) except: self.exc_info.append(sys.exc_info()) def check_operation_result(self): for i in range(0, self.i): real_account_uuid=res_ops.get_resource_owner(self.vms[i].uuid.split(';')) #real_account.uuid=real_account.uuid if cmp(new_account.uuid,real_account_uuid): test_util.test_fail('Fail to change VM owner %s.' % self.vms[i].uuid)
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)
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 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 vm global schd 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 = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler', start_date+60, 120) check_scheduler_state(schd, '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('simple_schduler_snapshot') 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 + 60) 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('simple_schduler_snapshot') 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, '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('simple_schduler_snapshot') 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('simple_schduler_snapshot') if snapshot_num != new_snapshot_num: test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num)) schd_ops.delete_scheduler(schd.uuid) vm.destroy() account_operations.delete_account(new_account.uuid) test_util.test_pass('Check Scheduler State after Changing Volume Owner Success')
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')
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)