def create_vpc_vrouter(vr_name='test_vpc'): conf = res_ops.gen_query_conditions('name', '=', 'test_vpc') vr_list = res_ops.query_resource(res_ops.APPLIANCE_VM, conf) if vr_list: return ZstackTestVR(vr_list[0]) vr_offering = res_ops.get_resource(res_ops.VR_OFFERING)[0] vr_inv = vpc_ops.create_vpc_vrouter(name=vr_name, virtualrouter_offering_uuid=vr_offering.uuid) return ZstackTestVR(vr_inv)
def create_vpc_vrouter(vr_name='test_vpc'): conf = res_ops.gen_query_conditions('name', '=', 'test_vpc') vr_list = res_ops.query_resource(res_ops.APPLIANCE_VM, conf) if vr_list: return ZstackTestVR(vr_list[0]) vr_offering = res_ops.get_resource(res_ops.VR_OFFERING)[0] vr_inv = vpc_ops.create_vpc_vrouter(name=vr_name, virtualrouter_offering_uuid=vr_offering.uuid) dns_server = os.getenv('DNSServer') vpcdns_ops.add_dns_to_vpc_router(vr_inv.uuid, dns_server) return ZstackTestVR(vr_inv)
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 l2_vxlan_network_uuid,project_uuid,project_operator_uuid,vni_range_uuid,vxlan_pool_uuid,l3_vpc_network_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_project7' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid cond = res_ops.gen_query_conditions("name",'=',"test_project7") linked_account_uuid = res_ops.query_resource(res_ops.ACCOUNT,cond)[0].uuid # 2 create project operator project_operator_name = 'username7' 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 zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid attributes = [{"name": "__ProjectRelatedZone__", "value": zone_uuid}] iam2_ops.add_attributes_to_iam2_project(project_uuid, attributes) # 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 # 4 share vxlan pool to project l2vxlan_pools = res_ops.query_resource(res_ops.L2_VXLAN_NETWORK_POOL) for l2vxlan_pool in l2vxlan_pools: acc_ops.share_resources([linked_account_uuid],[l2vxlan_pool.uuid]) # 5 create l2 vxlan l2_vxlan_network_uuid = vxlan_ops.create_l2_vxlan_network('l2_vxlan',vxlan_pool_uuid,zone_uuid,session_uuid=project_login_uuid).uuid # 6 use l2 vxlan to create l3 vpc l3_vpc_network = create_l3_vpc('test_vpc',l2_vxlan_network_uuid,project_login_uuid) l3_vpc_network_uuid = l3_vpc_network.uuid # add ip range ir_option = test_util.IpRangeOption() ir_option.set_name('iprange2') ir_option.set_description('iprange for vpc') ir_option.set_netmask('255.255.255.0') ir_option.set_gateway('192.168.23.1') ir_option.set_l3_uuid(l3_vpc_network_uuid) ir_option.set_startIp('192.168.23.2') ir_option.set_endIp('192.168.23.254') net_ops.add_ip_range(ir_option) # add network service AttachNetworkServiceToL3Network(l3_vpc_network_uuid,allservices,session_uuid = project_login_uuid) # share the vr_offering to project and do create vpc router and vpc network cond = res_ops.gen_query_conditions("name",'=',"virtual-router-vm") vr_offering_uuid = res_ops.query_resource(res_ops.VR_OFFERING,cond)[0].uuid acc_ops.share_resources([linked_account_uuid],[vr_offering_uuid]) vpc_ops.create_vpc_vrouter(name = 'test_vpc_vr', virtualrouter_offering_uuid = vr_offering_uuid,session_uuid = project_login_uuid) vpc_vr = test_stub.query_vpc_vrouter('test_vpc_vr') vpc_vr.add_nic(l3_vpc_network_uuid) # 7 expunge the project and check the l2 vxlan iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) try: l2_vxlan_network_test_uuid = res_ops.query_resource(res_ops.L2_VXLAN_NETWORK)[0].uuid except: test_util.test_pass( "l2 vxlan is delete after deleted the project " ) test_util.test_dsc('test l2 l2 cascade delete') # 8 check the vpc network and vpc_vr try: cond = res_ops.gen_query_conditions("name",'=',"test_vpc") l3_vpc_network_uuid = res_ops.query_resource(res_ops.L3_NETWORK,cond)[0].uuid except: test_util.test_pass( "l3_vpc is delete after deleted the project") cond = res_ops.gen_query_conditions("name",'=',"test_vpc_vr") vpc_vr = res_ops.query_resource(res_ops.VIRTUALROUTER_VM,cond) if not vpc_vr.inv.state is 'Paused': test_util.test_fail( "vpc vr [%s] is still exist after delete and expunge the project [%s]" % (vpc_vr.uuid,project_uuid)) # 9 delete vni_range_uuid = res_ops.get_resource(res_ops.VNI_RANGE)[0].uuid vxlan_ops.delete_vni_range(vni_range_uuid) net_ops.delete_l2(vxlan_pool_uuid) iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
def test(): global l2_vxlan_network_uuid,project_uuid,project_operator_uuid,vni_range_uuid,vxlan_pool_uuid,l3_vpc_network_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_project7' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid #cond = res_ops.gen_query_conditions("name",'=',"test_project7") #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 = 'username7' 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 zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid attributes = [{"name": "__ProjectRelatedZone__", "value": zone_uuid}] iam2_ops.add_attributes_to_iam2_project(project_uuid, attributes) # 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 # 4 share vxlan pool to project l2vxlan_pools = res_ops.query_resource(res_ops.L2_VXLAN_NETWORK_POOL) for l2vxlan_pool in l2vxlan_pools: acc_ops.share_resources([linked_account_uuid],[l2vxlan_pool.uuid]) # 5 create l2 vxlan l2_vxlan_network_uuid = vxlan_ops.create_l2_vxlan_network('l2_vxlan',vxlan_pool_uuid,zone_uuid,session_uuid=project_login_uuid).uuid # 6 use l2 vxlan to create l3 vpc l3_vpc_network = create_l3_vpc('test_vpc',l2_vxlan_network_uuid,project_login_uuid) l3_vpc_network_uuid = l3_vpc_network.uuid # add ip range ir_option = test_util.IpRangeOption() ir_option.set_name('iprange2') ir_option.set_description('iprange for vpc') ir_option.set_netmask('255.255.255.0') ir_option.set_gateway('192.168.23.1') ir_option.set_l3_uuid(l3_vpc_network_uuid) ir_option.set_startIp('192.168.23.2') ir_option.set_endIp('192.168.23.254') net_ops.add_ip_range(ir_option) # add network service AttachNetworkServiceToL3Network(l3_vpc_network_uuid,allservices,session_uuid = project_login_uuid) # share the vr_offering to project and do create vpc router and vpc network cond = res_ops.gen_query_conditions("name",'=',"virtual-router-vm") vr_offering_uuid = res_ops.query_resource(res_ops.VR_OFFERING,cond)[0].uuid acc_ops.share_resources([linked_account_uuid],[vr_offering_uuid]) vpc_ops.create_vpc_vrouter(name = 'test_vpc_vr', virtualrouter_offering_uuid = vr_offering_uuid,session_uuid = project_login_uuid) vpc_vr = test_stub.query_vpc_vrouter('test_vpc_vr') vpc_vr.add_nic(l3_vpc_network_uuid) # 7 expunge the project and check the l2 vxlan iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) try: l2_vxlan_network_test_uuid = res_ops.query_resource(res_ops.L2_VXLAN_NETWORK)[0].uuid except: test_util.test_pass( "l2 vxlan is delete after deleted the project " ) test_util.test_dsc('test l2 l2 cascade delete') # 8 check the vpc network and vpc_vr try: cond = res_ops.gen_query_conditions("name",'=',"test_vpc") l3_vpc_network_uuid = res_ops.query_resource(res_ops.L3_NETWORK,cond)[0].uuid except: test_util.test_pass( "l3_vpc is delete after deleted the project") cond = res_ops.gen_query_conditions("name",'=',"test_vpc_vr") vpc_vr = res_ops.query_resource(res_ops.VIRTUALROUTER_VM,cond) if not vpc_vr.inv.state is 'Paused': test_util.test_fail( "vpc vr [%s] is still exist after delete and expunge the project [%s]" % (vpc_vr.uuid,project_uuid)) # 9 delete vni_range_uuid = res_ops.get_resource(res_ops.VNI_RANGE)[0].uuid vxlan_ops.delete_vni_range(vni_range_uuid) net_ops.delete_l2(vxlan_pool_uuid) iam2_ops.delete_iam2_virtual_id(project_operator_uuid)