def add_storage_for_backup(deployConfig): print "try to add backup storage" if xmlobject.has_element(deployConfig, 'backupStorages.imageStoreBackupStorage'): print "find image store backup storage" for bs in xmlobject.safe_list(deployConfig.backupStorages.imageStoreBackupStorage): if hasattr(bs, 'local_backup_storage_'): print "find local_backup_storage" cond = res_ops.gen_query_conditions('tag', '=', "allowbackup") tags = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) if len(tags) > 0: print "local backup storage already exists" break cond = res_ops.gen_query_conditions('name', '=', bs.name_) bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond) print bss add_local_bs_tag = tag_ops.create_system_tag('ImageStoreBackupStorageVO', bss[0].uuid,'allowbackup') if xmlobject.has_element(deployConfig, 'backupStorages.imageStoreBackupStorage'): for bs in xmlobject.safe_list(deployConfig.backupStorages.imageStoreBackupStorage): if hasattr(bs, 'remote_backup_storage_'): print "find remote_backup_storage" cond = res_ops.gen_query_conditions('tag', '=', "remotebackup") tags = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) if len(tags) > 0: print "remote backup storage already exists" break cond = res_ops.gen_query_conditions('name', '=', bs.name_) bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond) print bss add_local_bs_tag = tag_ops.create_system_tag('ImageStoreBackupStorageVO', bss[0].uuid,'remotebackup')
def test(): global new_offering_uuid test_util.test_dsc('Test VM disk bandwidth QoS by 20MB') #unit is KB volume_bandwidth = 25*1024*1024 # new_offering = test_lib.lib_create_instance_offering(volume_bandwidth = volume_bandwidth) # new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_volume_qos') test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() disk_offering = test_lib.lib_create_disk_offering(diskSize=1073741824,name="1G") volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) tag_ops.create_system_tag('DiskOfferingVO', disk_offering.uuid, "volumeTotalBandwidth::26214400") volume_creation_option.set_name('volume-1') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) vm_inv = vm.get_vm() test_lib.lib_mkfs_for_volume(volume.get_volume().uuid, vm_inv) mount_point = '/tmp/zstack/test' test_stub.attach_mount_volume(volume, vm, mount_point) test_stub.make_ssh_no_password(vm_inv) test_stub.install_fio(vm_inv) test_stub.test_fio_bandwidth(vm_inv, volume_bandwidth, mount_point) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Disk QoS Test Pass')
def test(): global vm, vm2, image_uuid test_util.test_dsc('create VM with setting password') for root_password in root_password_list: test_util.test_dsc("root_password: \"%s\"" %(root_password)) vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag") backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) for bs in backup_storage_list: if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: break if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE: break if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: break else: vm.destroy() test_util.test_skip('Not find image store type backup storage.') vm.check() #add tag to vm tag_ops.create_system_tag('VmInstanceVO', vm.get_vm().uuid, "qemuga") vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password) #create image by the vm with tag vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid image_option1 = test_util.ImageOption() image_option1.set_root_volume_uuid(root_volume_uuid) image_option1.set_name('add_tag_vm_to_image') image_option1.set_format('qcow2') image_option1.set_backup_storage_uuid_list([bs.uuid]) vm.stop() image = img_ops.create_root_volume_template(image_option1) #create vm by new image vm2 = test_stub.create_vm(vm_name = 'c7-vm-add-tag-from-previous-vm', image_name = "add_tag_vm_to_image") if not test_lib.lib_check_login_in_vm(vm2.get_vm(), "root", root_password): test_util.test_fail("create vm with user:%s password: %s failed", "root", root_password) vm_ops.change_vm_password(vm2.get_vm().uuid, "root", root_password) image_uuid = image.uuid if not image_uuid: img_ops.delete_image(image_uuid) img_ops.expunge_image(image_uuid) test_util.test_pass('add system tag on a no system tag image test passed')
def test(): test_util.test_dsc(''' Test Description: Will create 1 test VM with 1 NIC firstly. Then will attach a new NIC to VM with different L3 Network. ''') image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l3_net_list = [l3_net_uuid] l3_name = os.environ.get('l3VlanNetworkName3') l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name).uuid vm = test_stub.create_vm(l3_net_list, image_uuid, 'attach_nic_vm', \ default_l3_uuid = l3_net_uuid) test_obj_dict.add_vm(vm) #vm.check() #change static IP need to stop VM firstly. vm.stop() vm.add_nic(l3_net_uuid2) ip_address2 = net_ops.get_free_ip(l3_net_uuid2)[0].ip static_ip_system_tag2 = test_lib.lib_create_vm_static_ip_tag(\ l3_net_uuid2, \ ip_address2) tag_ops.create_system_tag('VmInstanceVO', vm.get_vm().uuid, \ static_ip_system_tag2) vm.start() attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm()) if l3_net_uuid2 != attached_nic.l3NetworkUuid: test_util.test_fail( "After attach a nic, VM:%s last nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2)) test_lib.lib_restart_vm_network(vm.get_vm()) if attached_nic.ip != ip_address2: test_util.test_fail('new added NIC ip address:%s is not static ip: %s' \ % (attached_nic.ip, ip_address2)) vm.check() vm.remove_nic(attached_nic.uuid) attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm()) if l3_net_uuid != attached_nic.l3NetworkUuid: test_util.test_fail( "After detached NIC, VM:%s only nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2)) vm.destroy() test_util.test_pass('Test Attach Nic to VM successfully.')
def test(): test_util.test_dsc(''' Test Description: Will create 1 test VM with 1 NIC firstly. Then will attach a new NIC to VM with different L3 Network. ''') image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l3_net_list = [l3_net_uuid] l3_name = os.environ.get('l3VlanNetworkName3') l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name).uuid vm = test_stub.create_vm(l3_net_list, image_uuid, 'attach_nic_vm', \ default_l3_uuid = l3_net_uuid) test_obj_dict.add_vm(vm) #vm.check() #change static IP need to stop VM firstly. vm.stop() vm.add_nic(l3_net_uuid2) ip_address2 = net_ops.get_free_ip(l3_net_uuid2)[0].ip static_ip_system_tag2 = test_lib.lib_create_vm_static_ip_tag(\ l3_net_uuid2, \ ip_address2) tag_ops.create_system_tag('VmInstanceVO', vm.get_vm().uuid, \ static_ip_system_tag2) vm.start() attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm()) if l3_net_uuid2 != attached_nic.l3NetworkUuid: test_util.test_fail("After attach a nic, VM:%s last nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2)) test_lib.lib_restart_vm_network(vm.get_vm()) if attached_nic.ip != ip_address2: test_util.test_fail('new added NIC ip address:%s is not static ip: %s' \ % (attached_nic.ip, ip_address2)) vm.check() vm.remove_nic(attached_nic.uuid) attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm()) if l3_net_uuid != attached_nic.l3NetworkUuid: test_util.test_fail("After detached NIC, VM:%s only nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2)) vm.destroy() test_util.test_pass('Test Attach Nic to VM successfully.')
def add_ps_network_gateway_sys_tag(): ''' Add system tag for mn to monitor the storage network in network separated. Currently, not support multiple PS case ''' pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE) if len(pss) > 1: test_util.test_logger("add ps gateway skip for multiple ps case.") return ps = pss[0] test_util.test_logger( "add system tag: resourceUuid=%s tag=%s" % (ps.uuid, "primaryStorage::gateway::cidr::192.168.0.0/16")) tag_ops.create_system_tag('PrimaryStorageVO', ps.uuid, "primaryStorage::gateway::cidr::192.168.0.0/16")
def test(): global vm global tag_uuid test_stub.skip_if_scenario_not_multiple_networks() vm = test_stub.create_basic_vm() vm.check() console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid) console_management_ip = console.hostIp cluster = res_ops.get_resource(res_ops.CLUSTER)[0] tag_inv = tag_ops.create_system_tag('ClusterVO', cluster.uuid, "display::network::cidr::172.20.0.0/16") tag_uuid = tag_inv.uuid console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid) console_display_ip = console.hostIp if console_management_ip == console_display_ip: test_util.test_fail("console ip has not been switched as expected: %s and %s" %(console_management_ip, console_display_ip)) console1 = test_lib.lib_request_console_access(vm.get_vm().uuid) console_req_ip = console1.hostname if console_management_ip == console_req_ip: test_util.test_fail("console ip has not been switched as expected: %s and %s" %(console_management_ip, console_req_ip)) test_util.test_pass('Create VM Test Success')
def test(): host = res_ops.query_resource(res_ops.HOST)[0] host_uuid = host.uuid host_state = host.state ept_status = host_ops.get_ept_status(host.managementIp, host.username, "password", host.sshPort) #Test ept changes under maintenance state if host_state != "Maintenance": host_ops.change_host_state(host_uuid, "maintain") time.sleep(10) if ept_status == "enable": try: tag_ops.create_system_tag("HostVO", host_uuid, "pageTableExtensionDisabled") host_ops.change_host_state(host_uuid, "enable") time.sleep(60) status = host_ops.get_ept_status(host.managementIp, host.username, "password", host.sshPort) if status != "disable": test_util.test_fail('Fail to disable ept') except: test_util.test_fail('Exception catched when disabling ept') else: try: cond = res_ops.gen_query_conditions('tag', '=', 'pageTableExtensionDisabled') cond = res_ops.gen_query_conditions('resourceUuid', '=', host_uuid, cond) tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0] if tag != None: tag_ops.delete_tag(tag.uuid) host_ops.change_host_state(host_uuid, "enable") time.sleep(60) status = host_ops.get_ept_status(host.managementIp, host.username, "password", host.sshPort) if status != "enable": test_util.test_fail('Fail to enable ept') except: test_util.test_fail('Exception catched when enabling ept') #Enable ept cond = res_ops.gen_query_conditions('tag', '=', 'pageTableExtensionDisabled') cond = res_ops.gen_query_conditions('resourceUuid', '=', host_uuid, cond) tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) if tag != []: if host_state != "Maintenance": host_ops.change_host_state(host_uuid, "maintain") time.sleep(10) tag_ops.delete_tag(tag[0].uuid) host_ops.change_host_state(host_uuid, "enable") time.sleep(60) test_util.test_pass('EPT disable/enable Test Success')
def add_ps_network_gateway_sys_tag(): ''' This function currently only support 1 NFS storage separation. TODO: Fix for multiple ps and other type of storage network separation support ''' pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE) if len(pss) > 1: test_util.test_logger("add ps gateway skip for multiple ps case.") return ps = pss[0] if ps.type == "NFS": test_util.test_logger("add system tag: resourceUuid=%s tag=%s" %(ps.uuid, "primaryStorage::gateway::cidr::10.0.0.1/8")) tag_ops.create_system_tag('PrimaryStorageVO', ps.uuid, "primaryStorage::gateway::cidr::10.0.0.1/8") else: test_util.test_logger("add ps gateway skip for not other ps type case.")
def add_ps_network_gateway_sys_tag(): ''' This function currently only support 1 NFS storage separation. TODO: Fix for multiple ps and other type of storage network separation support ''' pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE) if len(pss) > 1: test_util.test_logger("add ps gateway skip for multiple ps case.") return ps = pss[0] if ps.type == "NFS": test_util.test_logger( "add system tag: resourceUuid=%s tag=%s" % (ps.uuid, "primaryStorage::gateway::cidr::10.0.0.1/8")) tag_ops.create_system_tag('PrimaryStorageVO', ps.uuid, "primaryStorage::gateway::cidr::10.0.0.1/8") else: test_util.test_logger( "add ps gateway skip for not other ps type case.")
def test(): global vm ova_image_name = 'centos-dhcp' network_pattern1 = os.environ['vcenterDefaultNetwork'] cpuNum = 2 memorySize = 2*1024*1024*1024 cond = res_ops.gen_query_conditions('type', '!=', 'Vcenter') ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) for i in ps: if (i.type == 'Ceph') or (i.type == 'Sharedblock'): break else: test_util.test_skip('Skip test on non ceph or sharedblock PS') ps_uuid = ps[0].uuid cond = res_ops.gen_query_conditions('primaryStorage.uuid', '=', ps_uuid) cluster_uuid = res_ops.query_resource(res_ops.CLUSTER, cond)[0].uuid cond = res_ops.gen_query_conditions('clusterUuid', '=', cluster_uuid) host = res_ops.query_resource(res_ops.HOST, cond)[0] new_offering = test_lib.lib_create_instance_offering(cpuNum = cpuNum, memorySize = memorySize) vm = test_stub.create_vm_in_vcenter(vm_name = 'v2v-test', image_name = ova_image_name, l3_name = network_pattern1, instance_offering_uuid = new_offering.uuid) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) l3_name = os.environ.get('l3VlanNetworkName1') l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid v2v_conversion_host = test_stub.add_v2v_conversion_host('v2v_host', host.uuid, '/tmp/zstack', 'VMWARE') tag_ops.create_system_tag("V2VConversionHostVO", v2v_conversion_host.uuid, "networkInboundBandwidth::167772160") url = 'vmware://%s' % vm.vm.uuid avail_mem = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableMemory avail_cpu = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableCpu avail_cap = test_lib.lib_get_storage_capacity(ps_uuids = [ps_uuid]).availableCapacity migrate_task = test_stub.convert_vm_from_foreign_hypervisor('test', url, cpuNum, memorySize, ps_uuid, [l3_uuid], cluster_uuid, v2v_conversion_host.uuid) for i in range(30): cond = res_ops.gen_query_conditions('uuid', '=', migrate_task.uuid) long_job = res_ops.query_resource(res_ops.LONGJOB, cond)[0] if long_job.state == 'Failed': test_util.test_fail('v2v long job failed.') elif long_job.state == 'Running': time.sleep(60) elif long_job.state == 'Succeeded': test_util.test_logger('v2v long job has been finished.') break avail_mem2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableMemory avail_cpu2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableCpu avail_cap2 = test_lib.lib_get_storage_capacity(ps_uuids = [ps_uuid]).availableCapacity if (avail_mem - memorySize) != avail_mem2: test_util.test_fail('Available memory: %d is different with expected available memory: %d' % (avail_mem2, avail_mem - memorySize)) if (avail_cpu - cpuNum) != avail_cpu2: test_util.test_fail('Available cpuNum: %d is different with expected available cpuNum: %d' % (avail_cpu2, avail_cpu1 - memorySize)) cond = res_ops.gen_query_conditions('type', '=', 'root') cond = res_ops.gen_query_conditions('primaryStorageUuid', '=', ps_uuid, cond) vm_root_volume_size = res_ops.query_resource(res_ops.VOLUME, cond)[0].size if (avail_cap - vm_root_volume_size - disk_offering.diskSize) != avail_cap2: test_util.test_fail('Available storage: %d is different with expected available storage: %d' % (avail_cap2, avail_cap - vm_root_volume_size - disk_offering.diskSize)) actual_qos = (vm_root_volume_size + disk_offering.diskSize) / long_job.executeTime if actual_qos > 167772160: test_util.test_fail('Fail to set qos for converting vm, expect qos:167772160 < actual_qos:%s.' % actual_qos) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("Migrate vcenter vm to zstack successfully.")
def test(): global vm, all_volume_offering_uuid, rw_volume_offering_uuid, all_volume_uuid, rw_volume_uuid, volume_offering_3, volume_offering_4, volume_offering_5, volume_offering_6 global instance_offering_uuid, volume_uuid_3, volume_uuid_4, volume_uuid_5, volume_uuid_6 #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 volume_offering_3 = test_lib.lib_create_disk_offering(name = "volume_offering_3") volume_offering_4 = test_lib.lib_create_disk_offering(name = "volume_offering_4") volume_offering_5 = test_lib.lib_create_disk_offering(name = "volume_offering_5") volume_offering_6 = test_lib.lib_create_disk_offering(name = "volume_offering_6") #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 #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)[0].uuid cond = res_ops.gen_query_conditions('name', '=', 'ttylinux') image_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[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, volume_offering_3.uuid, volume_offering_4.uuid, volume_offering_5.uuid, volume_offering_6.uuid]) vm_inv = vm.get_vm() # 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) cond3 = res_ops.gen_query_conditions("diskOfferingUuid", '=', volume_offering_3.uuid) cond4 = res_ops.gen_query_conditions("diskOfferingUuid", '=', volume_offering_4.uuid) cond5 = res_ops.gen_query_conditions("diskOfferingUuid", '=', volume_offering_5.uuid) cond6 = res_ops.gen_query_conditions("diskOfferingUuid", '=', volume_offering_6.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 volume_uuid_3 = res_ops.query_resource(res_ops.VOLUME, cond3)[0].uuid volume_uuid_4 = res_ops.query_resource(res_ops.VOLUME, cond4)[0].uuid volume_uuid_5 = res_ops.query_resource(res_ops.VOLUME, cond5)[0].uuid volume_uuid_6 = res_ops.query_resource(res_ops.VOLUME, cond6)[0].uuid tag_ops.create_system_tag('VolumeVO', all_volume_uuid, "capability::virtio-scsi") tag_ops.create_system_tag('VolumeVO', rw_volume_uuid, "capability::virtio-scsi") tag_ops.create_system_tag('VolumeVO', volume_uuid_3, "capability::virtio-scsi") tag_ops.create_system_tag('VolumeVO', volume_uuid_4, "capability::virtio-scsi") tag_ops.create_system_tag('VolumeVO', volume_uuid_5, "capability::virtio-scsi") tag_ops.create_system_tag('VolumeVO', volume_uuid_6, "capability::virtio-scsi") vm.check() vm.reboot() vol_ops.detach_volume(all_volume_uuid, vm_inv.uuid) vol_ops.detach_volume(rw_volume_uuid, vm_inv.uuid) vol_ops.detach_volume(volume_uuid_3, vm_inv.uuid) vol_ops.detach_volume(volume_uuid_4, vm_inv.uuid) vol_ops.detach_volume(volume_uuid_5, vm_inv.uuid) vol_ops.detach_volume(volume_uuid_6, vm_inv.uuid) vm.check() vol_ops.attach_volume(all_volume_uuid, vm_inv.uuid) vol_ops.attach_volume(rw_volume_uuid, vm_inv.uuid) vol_ops.attach_volume(volume_uuid_3, vm_inv.uuid) vol_ops.attach_volume(volume_uuid_4, vm_inv.uuid) vol_ops.attach_volume(volume_uuid_5, vm_inv.uuid) vol_ops.attach_volume(volume_uuid_6, vm_inv.uuid) vm.reboot() vm.check() vol_ops.detach_volume(all_volume_uuid, vm_inv.uuid) vm.check() vol_ops.attach_volume(all_volume_uuid, vm_inv.uuid) vm.destroy() vm.check() vol_ops.delete_disk_offering(all_volume_offering_uuid) vol_ops.delete_disk_offering(rw_volume_offering_uuid) vol_ops.delete_disk_offering(volume_offering_3.uuid) vol_ops.delete_disk_offering(volume_offering_4.uuid) vol_ops.delete_disk_offering(volume_offering_5.uuid) vol_ops.delete_disk_offering(volume_offering_6.uuid) vol_ops.delete_volume(all_volume_uuid) vol_ops.delete_volume(rw_volume_uuid) vol_ops.delete_volume(volume_uuid_3) vol_ops.delete_volume(volume_uuid_4) vol_ops.delete_volume(volume_uuid_5) vol_ops.delete_volume(volume_uuid_6) vm_ops.delete_instance_offering(instance_offering_uuid) test_util.test_pass('Create VM with volumes and detach/attach and after reboot and detach/attach Test Success')
def test(): global ps_inv global tag curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid zone1_name = os.environ.get('zoneName1') zone1 = res_ops.get_resource(res_ops.ZONE, name = zone1_name)[0] #pick up primary storage 1 and set system tag for instance offering. zone_name = os.environ.get('zoneName1') zone_uuid = res_ops.get_resource(res_ops.ZONE, name = zone_name)[0].uuid cond = res_ops.gen_query_conditions('zoneUuid', '=', zone_uuid) ps_inv = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0] if ps_inv.type == inventory.NFS_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('nfsPrimaryStorageName1') elif ps_inv.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('cephPrimaryStorageName1') ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name1)[0] conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_vm_detach_ps') vm_creation_option.set_zone_uuid(zone1.uuid) tag = tag_ops.create_system_tag('InstanceOfferingVO', \ instance_offering_uuid, \ 'primaryStorage::allocator::uuid::%s' % ps_inv.uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) volume1 = test_stub.create_volume() test_obj_dict.add_volume(volume1) volume1.attach(vm1) test_util.test_dsc("Delete Primary Storage") #need to delete tag as well tag_ops.delete_tag(tag.uuid) ps_ops.delete_primary_storage(ps_inv.uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.DESTROYED) vm1.update() test_obj_dict.rm_volume(volume1) volume1.update() test_lib.lib_robot_status_check(test_obj_dict) test_util.test_dsc("Recover Primary Storage") test_stub.recover_ps(ps_inv) test_lib.lib_robot_status_check(test_obj_dict) #update tag ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name1)[0] tag = tag_ops.create_system_tag('InstanceOfferingVO', \ instance_offering_uuid, \ 'primaryStorage::allocator::uuid::%s' % ps_inv.uuid) test_util.test_dsc("Create new VM and Volume") vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) volume2 = test_stub.create_volume() test_obj_dict.add_volume(volume2) volume2.attach(vm2) vm2.check() volume2.check() tag_ops.delete_tag(tag.uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test deleting primary storage Success')
def test(): zstack_pri_name = os.environ['l3VlanDNATNetworkName'] zstack_image = os.environ['imageName_net'] zstack_vr_name = os.environ['virtualRouterOfferingName_s'] cond = res_ops.gen_query_conditions('name', '=', zstack_vr_name) zstack_vr_instance = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0] cond = res_ops.gen_query_conditions('name', '=', zstack_pri_name) zstack_pri = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0] zstack_pri_uuid = zstack_pri.uuid zstack_tag = "guestL3Network::" + zstack_pri_uuid tag_ops.create_system_tag("InstanceOfferingVO", zstack_vr_instance.uuid, zstack_tag) vcenter_pri_name = os.environ['l3vCenterNoVlanNetworkName'] vcenter_image = os.environ['image_dhcp_name'] vcenter_vr_name = os.environ['vCenterVirtualRouterOfferingName'] cond = res_ops.gen_query_conditions('name', '=', vcenter_vr_name) vcenter_vr_instance = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0] cond = res_ops.gen_query_conditions('name', '=', vcenter_pri_name) vcenter_pri = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0] vcenter_pri_uuid = vcenter_pri.uuid vcenter_tag = "guestL3Network::" + vcenter_pri_uuid tag_ops.create_system_tag("InstanceOfferingVO", vcenter_vr_instance.uuid, vcenter_tag) test_util.test_dsc('Create test vm') vm1 = test_stub.create_vm(vm_name='test_ipsec_1', image_name = zstack_image, l3_name=zstack_pri_name) test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vm_in_vcenter(vm_name='test_ipsec_2', image_name = vcenter_image, l3_name=vcenter_pri_name) test_obj_dict.add_vm(vm2) time.sleep(50) test_util.test_dsc('Create 2 vip with 2 snat ip') pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vip1 = zstack_vip_header.ZstackTestVip() vip1.get_snat_ip_as_vip(vr1_pub_ip) vip1.isVcenter = True test_obj_dict.add_vip(vip1) pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) vip2 = zstack_vip_header.ZstackTestVip() vip2.get_snat_ip_as_vip(vr2_pub_ip) vip2.isVcenter = True test_obj_dict.add_vip(vip2) test_util.test_dsc('Create ipsec with 2 vip') zstack_pri_cidr = zstack_pri.ipRanges[0].networkCidr vcenter_pri_cidr = vcenter_pri.ipRanges[0].networkCidr ipsec1 = ipsec_ops.create_ipsec_connection('zstack_vcenter', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [vcenter_pri_cidr]) ipsec2 = ipsec_ops.create_ipsec_connection('vcenter_zstack', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [zstack_pri_cidr]) #conditions = res_ops.gen_query_conditions('name', '=', 'test_ipsec_1') #vm1 = res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0] #conditions = res_ops.gen_query_conditions('name', '=', 'test_ipsec_2') #vm2 = res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0] if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm1 in zstack could not connect to vm2 in vcenter with IPsec') if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm2 in vcenter could not connect to vm1 in zstack with IPsec') ipsec_ops.delete_ipsec_connection(ipsec1.uuid) ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Create Ipsec Success')
def test(): host = dict() host['Broadwell'] = [] host['Haswell-noTSX'] = [] _hosts = res_ops.query_resource(res_ops.HOST) if len(_hosts) < 4: test_util.test_fail("this case need at least 4 hosts") for i in _hosts[:2]: test_stub.set_host_cpu_model(i.managementIp, model='Broadwell') host['Broadwell'].append(i) for i in _hosts[2:]: test_stub.set_host_cpu_model(i.managementIp, model='Haswell-noTSX') host['Haswell-noTSX'].append(i) hosts = host['Broadwell'] + host['Haswell-noTSX'] clusters = res_ops.query_resource(res_ops.CLUSTER) for i in clusters: cls_ops.delete_cluster(i.uuid) clusters = [] zone = res_ops.query_resource(res_ops.ZONE)[0] cluster_option = test_util.ClusterOption() cluster_option.set_hypervisor_type('KVM') cluster_option.set_zone_uuid(zone.uuid) cluster_option.set_name('Broadwell_1') cluster1 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO', cluster1.uuid, tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster1) cluster_option.set_name('Broadwell_2') cluster2 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO', cluster2.uuid, tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster2) cluster_option.set_name('Haswell-noTSX_1') cluster3 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO', cluster3.uuid, tag="clusterKVMCpuModel::Haswell-noTSX") clusters.append(cluster3) conditions = res_ops.gen_query_conditions('name', '=', 'vlan-test9') l2 = res_ops.query_resource(res_ops.L2_VLAN_NETWORK, conditions)[0] conditions = res_ops.gen_query_conditions('name', '=', 'l2-public') l2_public = res_ops.query_resource(res_ops.L2_NETWORK, conditions)[0] ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) _hosts = [] for i in range(len(clusters)): net_ops.attach_l2(l2.uuid, clusters[i].uuid) net_ops.attach_l2(l2_public.uuid, clusters[i].uuid) for j in ps: ps_ops.attach_primary_storage(j.uuid, clusters[i].uuid) host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[i].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[i].managementIp) host_option.set_management_ip(hosts[i].managementIp) _hosts.append(host_ops.add_kvm_host(host_option)) # test host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[0].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[3].managementIp) host_option.set_management_ip(hosts[3].managementIp) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_logger(e) host_option.set_cluster_uuid(clusters[2].uuid) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_fail("test cluster cpu model faild") # migrate vm conditions = res_ops.gen_query_conditions('name', '=', 'ttylinux') img = res_ops.query_resource(res_ops.IMAGE, conditions)[0] ins = res_ops.query_resource(res_ops.INSTANCE_OFFERING)[0] conditions = res_ops.gen_query_conditions('name', '=', 'l3VlanNetwork9') l3 = res_ops.query_resource(res_ops.L3_NETWORK, conditions)[0] vms = [] for i in [0, 2]: vm_option = test_util.VmOption() vm_option.set_name("vm") vm_option.set_image_uuid(img.uuid) vm_option.set_cluster_uuid(clusters[i].uuid) vm_option.set_host_uuid(_hosts[i].uuid) vm_option.set_instance_offering_uuid(ins.uuid) vm_option.set_l3_uuids([l3.uuid]) vm_option.set_default_l3_uuid(l3.uuid) vms.append(vm_ops.create_vm(vm_option)) time.sleep(20) try: vm_ops.migrate_vm(vms[0].uuid, _hosts[1].uuid) except Exception as e: test_util.test_fail(e) try: vm_ops.migrate_vm(vms[1].uuid, _hosts[1].uuid) except Exception as e: test_util.test_logger(e) test_util.test_pass("test cluster cpu model pass")
def test(): test_util.test_dsc('Create vrouter vm and check multi nics') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm1) vm1_ip = vm1.get_vm().vmNics[0].ip vm1_nic_uuid = vm1.get_vm().vmNics[0].uuid vr1 = test_lib.lib_find_vr_by_vm(vm1.vm)[0] vr1_uuid = vr1.uuid vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr1_private_ip = test_lib.lib_find_vr_private_ip(vr1) l3network1_uuid = vm1.get_vm().vmNics[0].l3NetworkUuid cond = res_ops.gen_query_conditions('uuid', '=', l3network1_uuid) l3network1_cidr = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid) vr_offering_mn_network_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].managementNetworkUuid vr1_pub_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].managementNetworkUuid vr_offering_image_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].imageUuid vr_offering_zone_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].zoneUuid vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3PublicNetworkName')) public_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3NoVlanNetworkName1')) second_public_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid second_public_l3network_cidr = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr #Attach second public network to vrouter second_public_l3network_attached = False for vm_nic in vr1_nics: if vm_nic.l3NetworkUuid == second_public_l3network_uuid: second_public_l3network_attached = True if not second_public_l3network_attached: net_ops.attach_l3(second_public_l3network_uuid, vr1_uuid) #Get vr1 nic_uuid on second public network cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid) vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics vr1_second_pub_nic_uuid = '' for vm_nic in vr1_nics: if vm_nic.l3NetworkUuid == second_public_l3network_uuid: vr1_second_pub_nic_uuid = vm_nic.uuid #Create new vrouter offering vr_offering_name = "virtual_router_offering1" vr_offering_cpu_num = 2 vr_offering_mem_size = 536870912 #512MB vr_offering = net_ops.create_virtual_router_offering(vr_offering_name, vr_offering_cpu_num, vr_offering_mem_size, vr_offering_image_uuid, vr_offering_zone_uuid, vr_offering_mn_network_uuid, second_public_l3network_uuid) vr_offering_uuid = vr_offering.uuid cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3VlanNetworkName4')) user_defined_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid #Attach Virtual Router Offering tag = tag_ops.create_system_tag('InstanceOfferingVO',vr_offering_uuid, 'guestL3Network::%s' % user_defined_l3network_uuid) #Create vms for each public network eip attach vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) vm2_ip = vm2.get_vm().vmNics[0].ip vm2_nic_uuid = vm2.get_vm().vmNics[0].uuid l3network2_uuid = vm2.get_vm().vmNics[0].l3NetworkUuid vm3 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4')) vm3_ip = vm3.get_vm().vmNics[0].ip vm3_nic_uuid = vm3.get_vm().vmNics[0].uuid l3network3_uuid = vm3.get_vm().vmNics[0].l3NetworkUuid #Create eip for each vms, vm1 has 2 eip on each public network vip11 = test_stub.create_vip('vm1_vip1', public_l3network_uuid) vip11_uuid = vip11.get_vip().uuid eip11 = test_stub.create_eip('vm1_eip1', vip11_uuid, vm_obj=vm1) vip11.attach_eip(eip11) eip11_pub_ip = eip11.get_eip().vipIp vip11.check() eip11.attach(vm1_nic_uuid, vm1) vip12 = test_stub.create_vip('vm1_vip2', second_public_l3network_uuid) vip12_uuid = vip12.get_vip().uuid eip12 = test_stub.create_eip('vm1_eip2', vip12_uuid, vm_obj=vm1) vip12.attach_eip(eip12) eip12_pub_ip = eip12.get_eip().vipIp vip12.check() eip12.attach(vm1_nic_uuid, vm1) vip2 = test_stub.create_vip('vm2_vip', public_l3network_uuid) vip2_uuid = vip2.get_vip().uuid eip2 = test_stub.create_eip('vm2_eip', vip2_uuid, vm_obj=vm2) vip2.attach_eip(eip2) eip2_pub_ip = eip2.get_eip().vipIp vip2.check() eip2.attach(vm2_nic_uuid, vm2) vip3 = test_stub.create_vip('vm3_vip', second_public_l3network_uuid) vip3_uuid = vip3.get_vip().uuid eip3 = test_stub.create_eip('vm3_eip', vip3_uuid, vm_obj=vm3) vip3.attach_eip(eip3) eip3_pub_ip = eip3.get_eip().vipIp vip3.check() eip3.attach(vm3_nic_uuid, vm3) time.sleep(40) #waiting for eip binding #Check if the network is able to ping with eip user_name = "root" user_password = "******" rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm1_ip, eip2_pub_ip)) if rsp_ping != 0: test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm1_ip, eip2_pub_ip)) rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm1_ip, eip3_pub_ip)) if rsp_ping != 0: test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm1_ip, eip3_pub_ip)) rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm2_ip, eip11_pub_ip)) if rsp_ping != 0: test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm2_ip, eip11_pub_ip)) rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'"%(user_password, user_name, vm3_ip, eip12_pub_ip)) if rsp_ping != 0: test_util.test_fail('Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm3_ip, eip12_pub_ip)) #Delete vips and vr offering vip11.delete() vip12.delete() vip2.delete() vip3.delete() vm_ops.delete_instance_offering(vr_offering_uuid) #Dettach the route table to vrouter and second public nework if vr1_second_pub_nic_uuid != '': net_ops.detach_l3(vr1_second_pub_nic_uuid) vm1.destroy() vm2.destroy() vm3.destroy() net_ops.destroy_vrouter(vr1_uuid) test_util.test_pass('Check Multi Nics Success')
def test(): global l2_vxlan_network_uuid, project_uuid, project_operator_uuid, vni_range_uuid, vxlan_pool_uuid, l3_vr_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.get_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 the l2 vxlan to create l3 # 6.1 create l3_vr_network l3_vr_network_uuid = net_ops.create_l3( 'l3_vr_network', l2_vxlan_network_uuid, session_uuid=project_login_uuid).uuid cond = res_ops.gen_query_conditions('name', '=', 'virtual-router-vm') vr_instance_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0].uuid tag = "guestL3Network::" + l3_vr_network_uuid tag_ops.create_system_tag("InstanceOfferingVO", vr_instance_uuid, tag) # add ip range ir_option = test_util.IpRangeOption() ir_option.set_name('iprange1') ir_option.set_description('iprange for vrouter network') ir_option.set_netmask('255.255.255.0') ir_option.set_gateway('192.168.22.1') ir_option.set_l3_uuid(l3_vr_network_uuid) ir_option.set_startIp('192.168.22.2') ir_option.set_endIp('192.168.22.254') net_ops.add_ip_range(ir_option) # add dns AddDnsToL3Network(l3_vr_network_uuid, dns_text, session_uuid=project_login_uuid) # add network service AttachNetworkServiceToL3Network(l3_vr_network_uuid, allservices, session_uuid=project_login_uuid) # create vrouter vm test_stub.share_admin_resource_include_vxlan_pool([linked_account_uuid]) vr_vm = test_stub.create_vr_vm(test_obj_dict, l3_vr_network_uuid, session_uuid=project_login_uuid) test_stub.check_resource_not_exist(vr_vm.uuid, res_ops.VM_INSTANCE) #6 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 delete the project ") test_util.test_dsc('test l2 l2 cascade delete') # 7 check the l3 vrouter network try: cond = res_ops.gen_query_conditions("name", '=', "l3_vr_network") l3_vrouter_network_uuid = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].uuid except: test_util.test_pass( "l3_vrouter network is deleted after delete the project") # todo:check the virtual router vm # 8 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 ps_inv global ps_uuid global cluster_uuid global tag curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #pick up primary storage 1 and set system tag for instance offering. zone_name = os.environ.get('zoneName1') zone_uuid = res_ops.get_resource(res_ops.ZONE, name = zone_name)[0].uuid cond = res_ops.gen_query_conditions('zoneUuid', '=', zone_uuid) ps_inv = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0] if ps_inv.type == inventory.NFS_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('nfsPrimaryStorageName1') elif ps_inv.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('cephPrimaryStorageName1') ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name1)[0] ps_uuid = ps_inv.uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, \ conditions)[0].uuid vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_vm_ps_ops') tag = tag_ops.create_system_tag('InstanceOfferingVO', \ instance_offering_uuid, \ 'primaryStorage::allocator::uuid::%s' % ps_uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) cluster_uuid = vm1.get_vm().clusterUuid test_util.test_dsc("Detach Primary Storage") ps_ops.detach_primary_storage(ps_uuid, cluster_uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED) vm1.update() vm1.set_state(vm_header.STOPPED) vm1.check() vm1.start() vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) test_util.test_dsc("Delete Primary Storage") tag_ops.delete_tag(tag.uuid) ps_ops.delete_primary_storage(ps_inv.uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.DESTROYED) vm1.set_state(vm_header.DESTROYED) vm1.check() test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.DESTROYED) vm2.set_state(vm_header.DESTROYED) vm2.check() try: vm3 = test_lib.lib_create_vm(vm_creation_option) except: test_util.test_logger('Catch expected vm creation exception, since primary storage has been deleted. ') else: test_util.test_fail('Fail: Primary Storage has been deleted. But vm is still created with it.') test_stub.recover_ps(ps_inv) test_util.test_dsc("Attach Primary Storage") test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test primary storage operations Success')
def test(): # create_instanceoffering_min_cpu with tag_soft instance_offering_option = test_util.InstanceOfferingOption() instance_offering_option.set_cpuNum(1) instance_offering_option.set_memorySize(1*1024*1024*1024) instance_offering_option.set_allocatorStrategy("MinimumCPUUsageHostAllocatorStrategy") instance_offering_option.set_type("UserVm") instance_offering_option.set_name('cpu') cpu_off = vm_ops.create_instance_offering(instance_offering_option) test_obj_dict.add_instance_offering(cpu_off) cpu_tag = tag_ops.create_system_tag(resourceType="InstanceOfferingVO",resourceUuid=cpu_off.uuid,tag="minimumCPUUsageHostAllocatorStrategyMode::soft") # create_instanceoffering_min_memory with tag_soft instance_offering_option.set_cpuNum(1) instance_offering_option.set_memorySize(1*1024*1024*1024) instance_offering_option.set_allocatorStrategy("MinimumMemoryUsageHostAllocatorStrategy") instance_offering_option.set_type("UserVm") instance_offering_option.set_name('memory') memory_off = vm_ops.create_instance_offering(instance_offering_option) test_obj_dict.add_instance_offering(cpu_off) memory_tag = tag_ops.create_system_tag(resourceType="InstanceOfferingVO",resourceUuid=memory_off.uuid,tag="minimumMemoryUsageHostAllocatorStrategyMode::soft") # kill prometheus cmd = "kill -9 `netstat -nlp | awk -F'[ /]*' '/9090/{print $(NF-2)}'`" mn_ip = os.environ["ZSTACK_BUILT_IN_HTTP_SERVER_IP"] test_lib.lib_execute_ssh_cmd(mn_ip,"root","password",cmd) condition = res_ops.gen_query_conditions('name', '=', 'ttylinux') img_name = res_ops.query_resource(res_ops.IMAGE,condition)[0].name l3_name = res_ops.query_resource(res_ops.L3_NETWORK)[0].name try: vm = test_stub.create_vm_with_instance_offering("cpu_1",img_name,l3_name,cpu_off) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_fail(e) try: vm = test_stub.create_vm_with_instance_offering("memory_1",img_name,l3_name,memory_off) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_fail(e) tag_ops.update_system_tag(cpu_tag.uuid,tag="minimumCPUUsageHostAllocatorStrategyMode::hard") tag_ops.update_system_tag(memory_tag.uuid,tag="minimumMemoryUsageHostAllocatorStrategyMode::hard") try: vm = test_stub.create_vm_with_instance_offering("cpu_2",img_name,l3_name,cpu_off) test_obj_dict.add_vm(vm) test_util.test_fail("hard model can not create vm") except Exception as e: test_util.test_logger(e) try: vm = test_stub.create_vm_with_instance_offering("memory_2",img_name,l3_name,memory_off) test_obj_dict.add_vm(vm) test_util.test_fail("hard model can not create vm") except Exception as e: test_util.test_logger(e) test_lib.lib_execute_ssh_cmd(mn_ip,"root","password","zstack-ctl restart_node",timeout=300) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("test instanceoffering soft->hard and create vm case pass")
def test(): global ps_uuid global cluster_uuid global tag curr_deploy_conf = exp_ops.export_zstack_deployment_config( test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid cluster1_name = os.environ.get('clusterName1') cluster1 = res_ops.get_resource(res_ops.CLUSTER, name=cluster1_name)[0] #pick up primary storage 1 and set system tag for instance offering. ps_name1 = os.environ.get('nfsPrimaryStorageName1') ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name=ps_name1)[0] ps_uuid = ps_inv.uuid cluster_uuid = cluster1.uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, \ conditions)[0].uuid vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_vm_detach_ps') vm_creation_option.set_cluster_uuid(cluster_uuid) tag = tag_ops.create_system_tag('InstanceOfferingVO', \ instance_offering_uuid, \ 'primaryStorage::allocator::uuid::%s' % ps_uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) volume1 = test_stub.create_volume() test_obj_dict.add_volume(volume1) volume1.attach(vm1) test_util.test_dsc("Detach Primary Storage") ps_ops.detach_primary_storage(ps_uuid, cluster_uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED) test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED) vm1.update() vm1.set_state(vm_header.STOPPED) vm2.update() vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() test_util.test_dsc("Attach Primary Storage") ps_ops.attach_primary_storage(ps_uuid, cluster_uuid) vm1.start() vm2.start() vm3 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm3) vm1.check() volume1.check() vm2.check() vm3.check() test_util.test_dsc("Delete new added tag") tag_ops.delete_tag(tag.uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test detaching primary storage Success')
def test(): global ps_inv global ps_uuid global cluster_uuid global tag curr_deploy_conf = exp_ops.export_zstack_deployment_config( test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #pick up primary storage 1 and set system tag for instance offering. zone_name = os.environ.get('zoneName1') zone_uuid = res_ops.get_resource(res_ops.ZONE, name=zone_name)[0].uuid cond = res_ops.gen_query_conditions('zoneUuid', '=', zone_uuid) ps_inv = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0] if ps_inv.type == inventory.NFS_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('nfsPrimaryStorageName1') elif ps_inv.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('cephPrimaryStorageName1') ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name=ps_name1)[0] ps_uuid = ps_inv.uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, \ conditions)[0].uuid vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_vm_ps_ops') tag = tag_ops.create_system_tag('InstanceOfferingVO', \ instance_offering_uuid, \ 'primaryStorage::allocator::uuid::%s' % ps_uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) cluster_uuid = vm1.get_vm().clusterUuid test_util.test_dsc("Detach Primary Storage") ps_ops.detach_primary_storage(ps_uuid, cluster_uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED) vm1.update() vm1.set_state(vm_header.STOPPED) vm1.check() vm1.start() vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) test_util.test_dsc("Delete Primary Storage") tag_ops.delete_tag(tag.uuid) ps_ops.delete_primary_storage(ps_inv.uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.DESTROYED) vm1.set_state(vm_header.DESTROYED) vm1.check() test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.DESTROYED) vm2.set_state(vm_header.DESTROYED) vm2.check() try: vm3 = test_lib.lib_create_vm(vm_creation_option) except: test_util.test_logger( 'Catch expected vm creation exception, since primary storage has been deleted. ' ) else: test_util.test_fail( 'Fail: Primary Storage has been deleted. But vm is still created with it.' ) test_stub.recover_ps(ps_inv) test_util.test_dsc("Attach Primary Storage") test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test primary storage operations Success')
def test(): global l2_vxlan_network_uuid,project_uuid,project_operator_uuid,vni_range_uuid,vxlan_pool_uuid,l3_vr_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.get_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 the l2 vxlan to create l3 # 6.1 create l3_vr_network l3_vr_network_uuid = net_ops.create_l3('l3_vr_network',l2_vxlan_network_uuid,session_uuid=project_login_uuid).uuid cond = res_ops.gen_query_conditions('name','=','virtual-router-vm') vr_instance_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,cond)[0].uuid tag = "guestL3Network::" + l3_vr_network_uuid tag_ops.create_system_tag("InstanceOfferingVO",vr_instance_uuid,tag) # add ip range ir_option = test_util.IpRangeOption() ir_option.set_name('iprange1') ir_option.set_description('iprange for vrouter network') ir_option.set_netmask('255.255.255.0') ir_option.set_gateway('192.168.22.1') ir_option.set_l3_uuid(l3_vr_network_uuid) ir_option.set_startIp('192.168.22.2') ir_option.set_endIp('192.168.22.254') net_ops.add_ip_range(ir_option) # add dns AddDnsToL3Network(l3_vr_network_uuid,dns_text,session_uuid = project_login_uuid) # add network service AttachNetworkServiceToL3Network(l3_vr_network_uuid,allservices,session_uuid = project_login_uuid) # create vrouter vm test_stub.share_admin_resource_include_vxlan_pool([linked_account_uuid]) vr_vm = test_stub.create_vr_vm(test_obj_dict, l3_vr_network_uuid,session_uuid=project_login_uuid) test_stub.check_resource_not_exist(vr_vm.uuid,res_ops.VM_INSTANCE) #6 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 delete the project " ) test_util.test_dsc('test l2 l2 cascade delete') # 7 check the l3 vrouter network try: cond = res_ops.gen_query_conditions("name",'=',"l3_vr_network") l3_vrouter_network_uuid = res_ops.query_resource(res_ops.L3_NETWORK,cond)[0].uuid except: test_util.test_pass( "l3_vrouter network is deleted after delete the project") # todo:check the virtual router vm # 8 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(): test_util.test_dsc('Create vrouter vm and check multi nics') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm1) vm1_ip = vm1.get_vm().vmNics[0].ip vm1_nic_uuid = vm1.get_vm().vmNics[0].uuid vr1 = test_lib.lib_find_vr_by_vm(vm1.vm)[0] vr1_uuid = vr1.uuid vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr1_private_ip = test_lib.lib_find_vr_private_ip(vr1) l3network1_uuid = vm1.get_vm().vmNics[0].l3NetworkUuid cond = res_ops.gen_query_conditions('uuid', '=', l3network1_uuid) l3network1_cidr = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid) vr_offering_mn_network_uuid = res_ops.query_resource( res_ops.APPLIANCE_VM, cond)[0].managementNetworkUuid vr1_pub_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].managementNetworkUuid vr_offering_image_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].imageUuid vr_offering_zone_uuid = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].zoneUuid vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3PublicNetworkName')) public_l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3NoVlanNetworkName1')) second_public_l3network_uuid = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].uuid second_public_l3network_cidr = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr #Attach second public network to vrouter second_public_l3network_attached = False for vm_nic in vr1_nics: if vm_nic.l3NetworkUuid == second_public_l3network_uuid: second_public_l3network_attached = True if not second_public_l3network_attached: net_ops.attach_l3(second_public_l3network_uuid, vr1_uuid) #Get vr1 nic_uuid on second public network cond = res_ops.gen_query_conditions('uuid', '=', vr1_uuid) vr1_nics = res_ops.query_resource(res_ops.APPLIANCE_VM, cond)[0].vmNics vr1_second_pub_nic_uuid = '' for vm_nic in vr1_nics: if vm_nic.l3NetworkUuid == second_public_l3network_uuid: vr1_second_pub_nic_uuid = vm_nic.uuid #Create new vrouter offering vr_offering_name = "virtual_router_offering1" vr_offering_cpu_num = 2 vr_offering_mem_size = 536870912 #512MB vr_offering = net_ops.create_virtual_router_offering( vr_offering_name, vr_offering_cpu_num, vr_offering_mem_size, vr_offering_image_uuid, vr_offering_zone_uuid, vr_offering_mn_network_uuid, second_public_l3network_uuid) vr_offering_uuid = vr_offering.uuid cond = res_ops.gen_query_conditions('name', '=', os.environ.get('l3VlanNetworkName4')) user_defined_l3network_uuid = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].uuid #Attach Virtual Router Offering tag = tag_ops.create_system_tag( 'InstanceOfferingVO', vr_offering_uuid, 'guestL3Network::%s' % user_defined_l3network_uuid) #Create vms for each public network eip attach vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) vm2_ip = vm2.get_vm().vmNics[0].ip vm2_nic_uuid = vm2.get_vm().vmNics[0].uuid l3network2_uuid = vm2.get_vm().vmNics[0].l3NetworkUuid vm3 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4')) vm3_ip = vm3.get_vm().vmNics[0].ip vm3_nic_uuid = vm3.get_vm().vmNics[0].uuid l3network3_uuid = vm3.get_vm().vmNics[0].l3NetworkUuid #Create eip for each vms, vm1 has 2 eip on each public network vip11 = test_stub.create_vip('vm1_vip1', public_l3network_uuid) vip11_uuid = vip11.get_vip().uuid eip11 = test_stub.create_eip('vm1_eip1', vip11_uuid, vm_obj=vm1) vip11.attach_eip(eip11) eip11_pub_ip = eip11.get_eip().vipIp vip11.check() eip11.attach(vm1_nic_uuid, vm1) vip12 = test_stub.create_vip('vm1_vip2', second_public_l3network_uuid) vip12_uuid = vip12.get_vip().uuid eip12 = test_stub.create_eip('vm1_eip2', vip12_uuid, vm_obj=vm1) vip12.attach_eip(eip12) eip12_pub_ip = eip12.get_eip().vipIp vip12.check() eip12.attach(vm1_nic_uuid, vm1) vip2 = test_stub.create_vip('vm2_vip', public_l3network_uuid) vip2_uuid = vip2.get_vip().uuid eip2 = test_stub.create_eip('vm2_eip', vip2_uuid, vm_obj=vm2) vip2.attach_eip(eip2) eip2_pub_ip = eip2.get_eip().vipIp vip2.check() eip2.attach(vm2_nic_uuid, vm2) vip3 = test_stub.create_vip('vm3_vip', second_public_l3network_uuid) vip3_uuid = vip3.get_vip().uuid eip3 = test_stub.create_eip('vm3_eip', vip3_uuid, vm_obj=vm3) vip3.attach_eip(eip3) eip3_pub_ip = eip3.get_eip().vipIp vip3.check() eip3.attach(vm3_nic_uuid, vm3) #Check if the network is able to ping with eip user_name = "root" user_password = "******" rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" % (user_password, user_name, vm1_ip, eip2_pub_ip)) if rsp_ping != 0: if vr1_second_pub_nic_uuid != '': net_ops.detach_l3(vr1_second_pub_nic_uuid) test_util.test_fail( 'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm1_ip, eip2_pub_ip)) rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" % (user_password, user_name, vm1_ip, eip3_pub_ip)) if rsp_ping != 0: if vr1_second_pub_nic_uuid != '': net_ops.detach_l3(vr1_second_pub_nic_uuid) test_util.test_fail( 'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm1_ip, eip3_pub_ip)) rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" % (user_password, user_name, vm2_ip, eip11_pub_ip)) if rsp_ping != 0: if vr1_second_pub_nic_uuid != '': net_ops.detach_l3(vr1_second_pub_nic_uuid) test_util.test_fail( 'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm2_ip, eip11_pub_ip)) rsp_ping = os.system("sshpass -p '%s' ssh %s@%s 'ping -c 4 %s'" % (user_password, user_name, vm3_ip, eip12_pub_ip)) if rsp_ping != 0: if vr1_second_pub_nic_uuid != '': net_ops.detach_l3(vr1_second_pub_nic_uuid) test_util.test_fail( 'Exception: [vm ip:] %s ping [Eip:] %s fail. But it should ping successfully.' % (vm3_ip, eip12_pub_ip)) #Delete vips and vr offering vip11.delete() vip12.delete() vip2.delete() vip3.delete() vm_ops.delete_instance_offering(vr_offering_uuid) #Dettach the route table to vrouter and second public nework if vr1_second_pub_nic_uuid != '': net_ops.detach_l3(vr1_second_pub_nic_uuid) vm1.destroy() vm2.destroy() vm3.destroy() net_ops.destroy_vrouter(vr1_uuid) test_util.test_pass('Check Multi Nics Success')
def test(): # create_instanceoffering_min_cpu with tag_soft instance_offering_option = test_util.InstanceOfferingOption() instance_offering_option.set_cpuNum(1) instance_offering_option.set_memorySize(1 * 1024 * 1024 * 1024) instance_offering_option.set_allocatorStrategy( "MinimumCPUUsageHostAllocatorStrategy") instance_offering_option.set_type("UserVm") instance_offering_option.set_name('cpu') cpu_off = vm_ops.create_instance_offering(instance_offering_option) test_obj_dict.add_instance_offering(cpu_off) cpu_tag = tag_ops.create_system_tag( resourceType="InstanceOfferingVO", resourceUuid=cpu_off.uuid, tag="minimumCPUUsageHostAllocatorStrategyMode::soft") # create_instanceoffering_min_memory with tag_soft instance_offering_option.set_cpuNum(1) instance_offering_option.set_memorySize(1 * 1024 * 1024 * 1024) instance_offering_option.set_allocatorStrategy( "MinimumMemoryUsageHostAllocatorStrategy") instance_offering_option.set_type("UserVm") instance_offering_option.set_name('memory') memory_off = vm_ops.create_instance_offering(instance_offering_option) test_obj_dict.add_instance_offering(cpu_off) memory_tag = tag_ops.create_system_tag( resourceType="InstanceOfferingVO", resourceUuid=memory_off.uuid, tag="minimumMemoryUsageHostAllocatorStrategyMode::soft") # kill prometheus cmd = "kill -9 `netstat -nlp | awk -F'[ /]*' '/9090/{print $(NF-2)}'`" mn_ip = os.environ["ZSTACK_BUILT_IN_HTTP_SERVER_IP"] test_lib.lib_execute_ssh_cmd(mn_ip, "root", "password", cmd) condition = res_ops.gen_query_conditions('name', '=', 'ttylinux') img_name = res_ops.query_resource(res_ops.IMAGE, condition)[0].name l3_name = res_ops.query_resource(res_ops.L3_NETWORK)[0].name try: vm = test_stub.create_vm_with_instance_offering( "cpu_1", img_name, l3_name, cpu_off) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_fail(e) try: vm = test_stub.create_vm_with_instance_offering( "memory_1", img_name, l3_name, memory_off) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_fail(e) tag_ops.update_system_tag( cpu_tag.uuid, tag="minimumCPUUsageHostAllocatorStrategyMode::hard") tag_ops.update_system_tag( memory_tag.uuid, tag="minimumMemoryUsageHostAllocatorStrategyMode::hard") try: vm = test_stub.create_vm_with_instance_offering( "cpu_2", img_name, l3_name, cpu_off) test_obj_dict.add_vm(vm) test_util.test_fail("hard model can not create vm") except Exception as e: test_util.test_logger(e) try: vm = test_stub.create_vm_with_instance_offering( "memory_2", img_name, l3_name, memory_off) test_obj_dict.add_vm(vm) test_util.test_fail("hard model can not create vm") except Exception as e: test_util.test_logger(e) test_lib.lib_execute_ssh_cmd(mn_ip, "root", "password", "zstack-ctl restart_node", timeout=300) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass( "test instanceoffering soft->hard and create vm case pass")
def test(): test_util.test_dsc('Test Set Data Volume WWN') vm1=test_stub.create_basic_vm() vm2=test_stub.create_basic_vm() vm1.check() vm2.check() test_obj_dict.add_vm(vm1) test_obj_dict.add_vm(vm2) volume1 = test_stub.create_volume() tag_ops.create_system_tag('VolumeVO',volume1.get_volume().uuid,"capability::virtio-scsi") volume2 = test_stub.create_volume() tag_ops.create_system_tag('VolumeVO',volume2.get_volume().uuid,"capability::virtio-scsi") test_obj_dict.add_volume(volume1) test_obj_dict.add_volume(volume2) vm1_inv = vm1.get_vm() vm2_inv = vm2.get_vm() mount_point_1 = '/tmp/zstack/test1' mount_point_2 = '/tmp/zstack/test2' test_lib.lib_mkfs_for_volume(volume1.get_volume().uuid, vm1_inv) test_stub.attach_mount_volume(volume1, vm1, mount_point_1) test_lib.lib_mkfs_for_volume(volume2.get_volume().uuid, vm1_inv) test_stub.attach_mount_volume(volume2, vm1, mount_point_2) wwn_dev_cmd=" ls /dev/disk/by-id -la | awk '$9~/^wwn-.*-part1/ {print $9,$11}'" wwn_dev_list=test_lib.lib_execute_command_in_vm(vm1_inv,wwn_dev_cmd) if not wwn_dev_list or wwn_dev_list == "<no stdout output>": test_util.test_fail('vm [%s] cannot show data volume wwn '%(vm1.get_vm().uuid)) for wwn_dev in wwn_dev_list.strip().split('\n'): wwn = wwn_dev.split()[0] device = wwn_dev.split()[1].split('/')[-1] path_cmd = "mount | awk '/^\/dev\/"+device+"/ {print $3}'" mount_point = test_lib.lib_execute_command_in_vm(vm1_inv, path_cmd).strip() test_stub.create_test_file(vm1_inv,mount_point+'/'+wwn) test_lib.lib_execute_command_in_vm(vm1_inv, 'umount '+mount_point+' >/dev/null') volume1.detach() volume2.detach() wwn_cmd="ls /dev/disk/by-id -la | awk '$9~/^wwn-.*-part1/ {print $9}'" test_stub.attach_mount_volume(volume1, vm2, mount_point_1) set_wwn_1 = test_lib.lib_execute_command_in_vm(vm2_inv, wwn_cmd).strip() check_file_cmd = "ls "+mount_point_1 file_list = test_lib.lib_execute_command_in_vm(vm2_inv, check_file_cmd) if set_wwn_1 not in file_list.split(): test_util.test_fail('wwn [%s] file does not exist in wwn [%s] volume' % (set_wwn_1, set_wwn_1)) wwn_1 = set_wwn_1.split('-')[1] cond = res_ops.gen_query_conditions('resourceUuid', '=', volume1.get_volume().uuid) cond = res_ops.gen_query_conditions('tag','=','kvm::volume::%s' % (wwn_1),cond) volume1_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) if not volume1_tag_invs: cond = res_ops.gen_query_conditions('resourceUuid', '=', volume1.get_volume().uuid) volume1_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) for tag_inv in volume1_tag_invs: if tag_inv.tag.startswith("kvm::volume::"): volume1_tag = tag_inv.tag.split("::")[2] test_util.test_fail('data volume [%s] with tag [%s] does not match its wwn number [%s] in vm' % (volume2.get_volume().uuid,volume1_tag, wwn_1)) break volume1.detach() test_stub.attach_mount_volume(volume2, vm2, mount_point_2) set_wwn_2 = test_lib.lib_execute_command_in_vm(vm2_inv, wwn_cmd).strip() check_file_cmd = "ls "+mount_point_2 file_list = test_lib.lib_execute_command_in_vm(vm2_inv, check_file_cmd) if set_wwn_2 not in file_list.split(): test_util.test_fail('wwn [%s] file does not exist in wwn [%s] volume' % (set_wwn_2, set_wwn_2)) wwn_2 = set_wwn_2.split('-')[1] cond = res_ops.gen_query_conditions('resourceUuid', '=', volume2.get_volume().uuid) cond = res_ops.gen_query_conditions('tag','=','kvm::volume::%s'%(wwn_2),cond) volume2_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) if not volume2_tag_invs: cond = res_ops.gen_query_conditions('resourceUuid', '=', volume2.get_volume().uuid) volume2_tag_invs = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) for tag_inv in volume2_tag_invs: if tag_inv.tag.startswith("kvm::volume::"): volume2_tag = tag_inv.tag.split("::")[2] test_util.test_fail('data volume [%s] with tag [%s] does not match its wwn number [%s] in vm' % (volume2.get_volume().uuid,volume2_tag, wwn_2)) break volume2.detach() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Set Data Volume WWN Test Pass')
def test(): test_util.test_dsc('Create Scheduler Trigger and Scheduler Job') cond = res_ops.gen_query_conditions('type', '=', 'ImageStoreBackupStorage') bs = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond) if not bs : test_util.test_skip('Not find image store type backup storage.') image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3PublicNetworkName') remote_bs_vm = test_stub.create_vm('remote_bs_vm', image_name, l3_name) test_obj_dict.add_vm(remote_bs_vm) image_name = os.environ.get('imageName_s') l3_name = os.environ.get('l3VlanNetworkName1') test_vm = test_stub.create_vm('test-vm', image_name, l3_name) test_obj_dict.add_vm(test_vm) add_local_bs_tag = tag_ops.create_system_tag('ImageStoreBackupStorageVO', bs[0].uuid,'allowbackup') #wait for vm start up test_lib.lib_wait_target_up(remote_bs_vm.vm.vmNics[0].ip, '22', 90) remote_bs = test_stub.create_image_store_backup_storage('remote_bs', remote_bs_vm.vm.vmNics[0].ip, 'root', 'password', '/zstack_bs', '22') add_remote_bs = tag_ops.create_system_tag('ImageStoreBackupStorageVO', remote_bs.uuid,'remotebackup') zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid bs_ops.attach_backup_storage(remote_bs.uuid, zone_uuid) parameters= {"retentionType":"Count","retentionValue":"1","backupStorageUuids":bs[0].uuid,"remoteBackupStorageUuid":""} schd_job = schd_ops.create_scheduler_job('backup_database_scheduler', 'backup_database_scheduler', '7ae6456c0b01324dae6d4bef358a5772', 'databaseBackup',parameters=parameters) schd_trigger = schd_ops.create_scheduler_trigger('backup_database_schedule',type='cron', cron='0 * * ? * *') schd_ops.add_scheduler_job_to_trigger(schd_trigger.uuid, schd_job.uuid) #wait for 60s *2 time.sleep(120) db_backup1 = schd_ops.query_db_backup() if len(db_backup1) != 1: test_util.test_fail('there sholuld be 1 db backup,but now there are %s' % len(db_backup1)) db_backup2 = schd_ops.get_db_backup_from_imagestore(url = 'ssh://*****:*****@%s:22/zstack_bs' % bs[0].hostname) if len(db_backup2.backups) != 1: test_util.test_fail('there sholuld be 1 db backup,but now there are %s' % len(db_backup2.backups)) db_url = schd_ops.export_db_backup_from_bs(bs[0].uuid, db_backup1[0].uuid) test_util.test_dsc('export database backup successfully,url is %s' % db_url.databaseBackupUrl) schd_ops.sync_db_from_imagestore_bs(remote_bs.uuid, bs[0].uuid, db_backup1[0].uuid) test_vm.destroy() test_util.test_dsc('Recover db From BackupStorage') backupStorageUrl = 'ssh://*****:*****@%s:22/zstack_bs' % remote_bs_vm.vm.vmNics[0].ip recover_db = schd_ops.recover_db_from_backup(backupStorageUrl = backupStorageUrl, backupInstallPath = db_backup2.backups[0].installPath, mysqlRootPassword='******') #wait for db recover time.sleep(60) cond = res_ops.gen_query_conditions('name', '=', 'test-vm') vm = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if not vm: test_util.test_fail('there sholuld be a vm after recovering db from remote backup bs') schd_ops.change_scheduler_state(schd_job.uuid, 'disable') db_backup3 = schd_ops.query_db_backup() zone = res_ops.query_resource(res_ops.ZONE)[0] zone_ops.delete_zone(zone.uuid) recover_db = schd_ops.recover_db_from_backup(uuid=db_backup3[0].uuid, mysqlRootPassword='******') #wait for db recover time.sleep(60) vm = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if not vm: test_util.test_fail('there sholuld be a vm after recovering db from local backup bs') test_util.test_dsc('Clear env') schd_ops.del_scheduler_job(schd_job.uuid) schd_ops.del_scheduler_trigger(schd_trigger.uuid) tag_ops.delete_tag(add_local_bs_tag.uuid) bs_ops.delete_backup_storage(remote_bs.uuid) bs_ops.reclaim_space_from_bs(bs[0].uuid) remote_bs_vm.destroy() test_vm.destroy()
def test(): host = dict() host['Broadwell'] = [] host['Haswell-noTSX'] = [] _hosts = res_ops.query_resource(res_ops.HOST) if len(_hosts) < 4: test_util.test_fail("this case need at least 4 hosts") for i in _hosts[:2]: test_stub.set_host_cpu_model(i.managementIp, model='Broadwell') host['Broadwell'].append(i) for i in _hosts[2:]: test_stub.set_host_cpu_model(i.managementIp, model='Haswell-noTSX') host['Haswell-noTSX'].append(i) hosts = host['Broadwell'] + host['Haswell-noTSX'] clusters = res_ops.query_resource(res_ops.CLUSTER) for i in clusters: cls_ops.delete_cluster(i.uuid) clusters = [] zone = res_ops.query_resource(res_ops.ZONE)[0] cluster_option = test_util.ClusterOption() cluster_option.set_hypervisor_type('KVM') cluster_option.set_zone_uuid(zone.uuid) cluster_option.set_name('Broadwell_1') cluster1 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO',cluster1.uuid,tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster1) cluster_option.set_name('Broadwell_2') cluster2 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO',cluster2.uuid,tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster2) cluster_option.set_name('Haswell-noTSX_1') cluster3 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO',cluster3.uuid,tag="clusterKVMCpuModel::Haswell-noTSX") clusters.append(cluster3) conditions = res_ops.gen_query_conditions('name', '=', 'vlan-test9') l2 = res_ops.query_resource(res_ops.L2_VLAN_NETWORK, conditions)[0] conditions = res_ops.gen_query_conditions('name', '=', 'l2-public') l2_public = res_ops.query_resource(res_ops.L2_NETWORK, conditions)[0] ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) _hosts = [] for i in range(len(clusters)): net_ops.attach_l2(l2.uuid, clusters[i].uuid) net_ops.attach_l2(l2_public.uuid, clusters[i].uuid) for j in ps: ps_ops.attach_primary_storage(j.uuid, clusters[i].uuid) host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[i].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[i].managementIp) host_option.set_management_ip(hosts[i].managementIp) _hosts.append(host_ops.add_kvm_host(host_option)) # test host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[0].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[3].managementIp) host_option.set_management_ip(hosts[3].managementIp) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_logger(e) cond = res_ops.gen_query_conditions('name', '=', hosts[3].managementIp) host_uuid = res_ops.query_resource(res_ops.HOST, cond)[0].uuid host_ops.delete_host(host_uuid) host_option.set_cluster_uuid(clusters[2].uuid) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_fail("test cluster cpu model faild") # migrate vm conditions = res_ops.gen_query_conditions('name', '=', 'ttylinux') img = res_ops.query_resource(res_ops.IMAGE, conditions)[0] conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') ins = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0] conditions = res_ops.gen_query_conditions('name', '=', 'public network') l3 = res_ops.query_resource(res_ops.L3_NETWORK, conditions)[0] vms = [] for i in [0,2]: vm_option = test_util.VmOption() vm_option.set_name("vm") vm_option.set_image_uuid(img.uuid) vm_option.set_cluster_uuid(clusters[i].uuid) vm_option.set_host_uuid(_hosts[i].uuid) vm_option.set_instance_offering_uuid(ins.uuid) vm_option.set_l3_uuids([l3.uuid]) vm_option.set_default_l3_uuid(l3.uuid) vms.append(vm_ops.create_vm(vm_option)) time.sleep(20) try: vm_ops.migrate_vm(vms[0].uuid, _hosts[1].uuid) except Exception as e: test_util.test_fail(e) try: vm_ops.migrate_vm(vms[1].uuid, _hosts[1].uuid) except Exception as e: test_util.test_logger(e) test_util.test_pass("test cluster cpu model pass")
def test(): global ps_uuid global cluster_uuid global tag curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid cluster1_name = os.environ.get('clusterName1') cluster1 = res_ops.get_resource(res_ops.CLUSTER, name = cluster1_name)[0] #pick up primary storage 1 and set system tag for instance offering. ps_name1 = os.environ.get('nfsPrimaryStorageName1') ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name = ps_name1)[0] ps_uuid = ps_inv.uuid cluster_uuid = cluster1.uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, \ conditions)[0].uuid vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_vm_detach_ps') vm_creation_option.set_cluster_uuid(cluster_uuid) tag = tag_ops.create_system_tag('InstanceOfferingVO', \ instance_offering_uuid, \ 'primaryStorage::allocator::uuid::%s' % ps_uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) volume1 = test_stub.create_volume() test_obj_dict.add_volume(volume1) volume1.attach(vm1) test_util.test_dsc("Detach Primary Storage") ps_ops.detach_primary_storage(ps_uuid, cluster_uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED) test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED) vm1.update() vm1.set_state(vm_header.STOPPED) vm2.update() vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() test_util.test_dsc("Attach Primary Storage") ps_ops.attach_primary_storage(ps_uuid, cluster_uuid) vm1.start() vm2.start() vm3 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm3) vm1.check() volume1.check() vm2.check() vm3.check() test_util.test_dsc("Delete new added tag") tag_ops.delete_tag(tag.uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test detaching primary storage Success')