def test(): global new_offering_uuid test_util.test_dsc('Test VM disk bandwidth QoS by 20MB') #unit is KB volume_bandwidth = 5 * 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', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.install_fio(vm_inv) test_stub.test_fio_bandwidth(vm_inv, volume_bandwidth) if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume( vm_inv).uuid).volumeBandwidth != volume_bandwidth: test_util.test_fail('Retrieved disk qos not match') vm_ops.set_vm_disk_qos( test_lib.lib_get_root_volume(vm_inv).uuid, volume_bandwidth / 2) test_stub.test_fio_bandwidth(vm_inv, volume_bandwidth / 2) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc( 'Test VM network outbound & inbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 1024 new_offering = test_lib.lib_create_instance_offering(net_outbound_bandwidth = net_bandwidth, \ net_inbound_bandwidth = net_bandwidth) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_net_inbound_outbound_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.create_test_file(vm_inv, net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm_inv, net_bandwidth) test_stub.test_scp_vm_inbound_speed(vm_inv, net_bandwidth) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network Outbound QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM network outbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 1*1024 new_offering = test_lib.lib_create_instance_offering(net_outbound_bandwidth = net_bandwidth*8*1024) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_net_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.create_test_file(vm_inv, net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm_inv, net_bandwidth) if test_stub.test_scp_vm_inbound_speed(vm_inv, net_bandwidth, raise_exception=False): test_util.test_fail('VM network inbound is not expected to be limited when only outbound qos is set') vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network Outbound QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM network outbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 1 * 1024 new_offering = test_lib.lib_create_instance_offering( net_outbound_bandwidth=net_bandwidth * 8 * 1024) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_net_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.create_test_file(vm_inv, net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm_inv, net_bandwidth) if test_stub.test_scp_vm_inbound_speed(vm_inv, net_bandwidth, raise_exception=False): test_util.test_fail( 'VM network inbound is not expected to be limited when only outbound qos is set' ) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network Outbound QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM disk bandwidth QoS by 20MB') #unit is KB volume_bandwidth = 5*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', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.install_fio(vm_inv) test_stub.test_fio_bandwidth(vm_inv, volume_bandwidth) if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidth != volume_bandwidth: test_util.test_fail('Retrieved disk qos not match') vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volume_bandwidth/2) test_stub.test_fio_bandwidth(vm_inv, volume_bandwidth/2) vm_ops.del_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid) if test_stub.test_fio_bandwidth(vm_inv, volume_bandwidth/2, raise_exception=False): test_util.test_fail('disk qos is not expected to have limit after qos setting is deleted') vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM network outbound & inbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 1*1024 new_offering = test_lib.lib_create_instance_offering(net_outbound_bandwidth = net_bandwidth*8*1024, \ net_inbound_bandwidth = net_bandwidth*8*1024) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_net_inbound_outbound_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.create_test_file(vm_inv, net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm_inv, net_bandwidth) test_stub.test_scp_vm_inbound_speed(vm_inv, net_bandwidth) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network Outbound QoS Test Pass')
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', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) 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) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Disk QoS Test Pass')
def error_cleanup(): global volume_offering_uuid,new_offering_uuid test_lib.lib_error_cleanup(test_obj_dict) try: vm_ops.delete_instance_offering(new_offering_uuid) vol_ops.delete_disk_offering(volume_offering_uuid) except: pass
def error_cleanup(): global vm, all_volume_offering_uuid, rw_volume_offering_uuid, all_volume_uuid, rw_volume_uuid, test_account_session, instance_offering_uuid if vm: vm.destroy(test_account_session) vol_ops.delete_disk_offering(all_volume_offering_uuid) vol_ops.delete_disk_offering(rw_volume_offering_uuid) vol_ops.delete_volume(all_volume_uuid, test_account_session) vol_ops.delete_volume(rw_volume_uuid, test_account_session) acc_ops.delete_account(test_account_uuid) vm_ops.delete_instance_offering(instance_offering_uuid)
def test(): global new_offering_uuid test_util.test_dsc('Test VM disk bandwidth QoS by 20MB') #unit is KB write_bandwidth = 5*1024*1024 read_bandwidth = 10*1024*1024 new_offering = test_lib.lib_create_instance_offering(read_bandwidth=read_bandwidth, write_bandwidth=write_bandwidth) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_volume_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.install_fio(vm_inv) # test_stub.test_fio_bandwidth(vm_inv, read_bandwidth) vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, read_bandwidth*2) if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidth != read_bandwidth*2: test_util.test_fail('Retrieved disk qos not match') if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidthRead == read_bandwidth: test_util.test_fail('read qos must be cleared after set total qos') if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidthWrite == write_bandwidth: test_util.test_fail('write qos must be cleared after set total qos') vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, read_bandwidth*2, 'read') if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidthRead != read_bandwidth*2: test_util.test_fail('Retrieved disk qos not match') test_stub.test_fio_bandwidth(vm_inv, read_bandwidth*2, '/dev/vda') vm_ops.del_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, mode='all') if test_stub.test_fio_bandwidth(vm_inv, read_bandwidth, '/dev/vda', raise_exception=False): test_util.test_fail('disk qos is not expected to have limit after qos setting is deleted') vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, write_bandwidth*2, 'write') if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidthWrite != write_bandwidth*2: test_util.test_fail('Retrieved disk qos not match') test_stub.test_fio_bandwidth(vm_inv, write_bandwidth*2) vm_ops.del_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, mode='all') if test_stub.test_fio_bandwidth(vm_inv, write_bandwidth, raise_exception=False): test_util.test_fail('disk qos is not expected to have limit after qos setting is deleted') vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc( 'Test VM network outbound & inbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 1024 new_offering = test_lib.lib_create_instance_offering(net_outbound_bandwidth = net_bandwidth, \ net_inbound_bandwidth = net_bandwidth) new_offering_uuid = new_offering.uuid vm1 = test_stub.create_vm(vm_name = 'vm_net_inbound_outbound_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm1) vm1.check() vm1_inv = vm1.get_vm() test_stub.make_ssh_no_password(vm1_inv) vm1_ip = vm1_inv.vmNics[0].ip vm2 = test_stub.create_vm(vm_name = 'vm_net_inbound_outbound_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm2) vm2.check() vm2_inv = vm2.get_vm() vm2_ip = vm2_inv.vmNics[0].ip test_stub.make_ssh_no_password(vm2_inv) test_stub.copy_key_file(vm1_inv) test_stub.copy_key_file(vm2_inv) test_stub.create_test_file(vm1_inv, net_bandwidth) test_stub.create_test_file(vm2_inv, net_bandwidth) l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vm1.add_nic(l3_net_uuid) vm2.add_nic(l3_net_uuid) ssh_cmd = 'ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null' cmd = "pkill dhclient" os.system("%s %s %s" % (ssh_cmd, vm1_ip, cmd)) os.system("%s %s %s" % (ssh_cmd, vm2_ip, cmd)) cmd = "dhclient eth0 eth1" os.system("%s %s %s" % (ssh_cmd, vm1_ip, cmd)) os.system("%s %s %s" % (ssh_cmd, vm2_ip, cmd)) test_stub.test_scp_outbound_speed( vm1_ip, test_lib.lib_get_vm_nic_by_l3(vm2.get_vm(), l3_net_uuid).ip, net_bandwidth) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network Outbound QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM network outbound & inbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 1024 new_offering = test_lib.lib_create_instance_offering(net_outbound_bandwidth = net_bandwidth, \ net_inbound_bandwidth = net_bandwidth) new_offering_uuid = new_offering.uuid vm1 = test_stub.create_vm(vm_name = 'vm_net_inbound_outbound_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm1) vm1.check() vm1_inv = vm1.get_vm() test_stub.make_ssh_no_password(vm1_inv) vm1_ip = vm1_inv.vmNics[0].ip vm2 = test_stub.create_vm(vm_name = 'vm_net_inbound_outbound_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm2) vm2.check() vm2_inv = vm2.get_vm() vm2_ip = vm2_inv.vmNics[0].ip test_stub.make_ssh_no_password(vm2_inv) test_stub.copy_key_file(vm1_inv) test_stub.copy_key_file(vm2_inv) test_stub.create_test_file(vm1_inv, net_bandwidth) test_stub.create_test_file(vm2_inv, net_bandwidth) l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vm1.add_nic(l3_net_uuid) vm2.add_nic(l3_net_uuid) ssh_cmd = 'ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null' cmd = "pkill dhclient" os.system("%s %s %s" % (ssh_cmd, vm1_ip, cmd)) os.system("%s %s %s" % (ssh_cmd, vm2_ip, cmd)) cmd = "dhclient eth0 eth1" os.system("%s %s %s" % (ssh_cmd, vm1_ip, cmd)) os.system("%s %s %s" % (ssh_cmd, vm2_ip, cmd)) test_stub.test_scp_outbound_speed(vm1_ip, test_lib.lib_get_vm_nic_by_l3(vm2.get_vm(), l3_net_uuid).ip, net_bandwidth) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network Outbound QoS Test Pass')
def error_cleanup(): 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 if vm: vm.destroy() 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)
def test(): global new_offering_uuid test_util.test_dsc('Test VM disk bandwidth QoS by 20MB') #unit is KB write_bandwidth = 15*1024*1024 new_offering = test_lib.lib_create_instance_offering(write_bandwidth=write_bandwidth) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_volume_qos', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) 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) if vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidthRead != -1 and \ vm_ops.get_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid).volumeBandwidthWrite != write_bandwidth: test_util.test_fail('Retrieved disk qos not match') test_stub.test_fio_bandwidth(vm_inv, write_bandwidth) if test_stub.test_fio_bandwidth(vm_inv, write_bandwidth/2, '/dev/vda', raise_exception=False): test_util.test_fail('disk write read is not expected to have limit as only write qos was set') vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Disk wirte QoS Test Pass')
def test(): global deploy_conf global vm_inv global vm test_util.test_dsc('Test Delete VR Offering and Teboot Normal VM') vm = test_stub.create_basic_vm() test_obj_dict.add_vm(vm) vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip vm.check() test_util.test_dsc('Record current virtual router offering information') deploy_conf = exp_ops.export_zstack_deployment_config( test_lib.deploy_config) cond = res_ops.gen_query_conditions('zone.vmInstance.uuid', '=', vm_inv.uuid) vr_offering_uuid = res_ops.query_resource(res_ops.VR_OFFERING, cond)[0].uuid test_util.test_dsc('Delete VR-RM and VR-Offering') cond = res_ops.gen_query_conditions('zone.vmInstance.uuid', '=', vm_inv.uuid) vr_vm_uuid = res_ops.query_resource(res_ops.VIRTUALROUTER_VM, cond)[0].uuid vm_ops.destroy_vm(vr_vm_uuid) vm_ops.delete_instance_offering(vr_offering_uuid) test_util.test_dsc( 'Create new VR-Offering, same as the former one, stop and start VM') session_uuid = acc_ops.login_as_admin() dep_ops.add_virtual_router(None, None, deploy_conf, session_uuid) vm.reboot() vm.destroy() test_obj_dict.rm_vm(vm) test_util.test_pass('Delete VR Offering and reboot normal VM: SUCCESS')
def test(): global new_offering_uuid test_util.test_dsc('Test VM disk IOPS by 200') volume_iops = 200 new_offering = test_lib.lib_create_instance_offering(volume_iops = volume_iops) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_volume_iops', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.install_fio(vm_inv) test_stub.test_fio_iops(vm_inv, volume_iops) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network IOPS Test Pass')
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', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.install_fio(vm_inv) test_stub.test_fio_bandwidth(vm_inv, volume_bandwidth) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM disk IOPS by 200') volume_iops = 200 new_offering = test_lib.lib_create_instance_offering( volume_iops=volume_iops) new_offering_uuid = new_offering.uuid vm = test_stub.create_vm(vm_name = 'vm_volume_iops', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() test_stub.make_ssh_no_password(vm_inv) test_stub.install_fio(vm_inv) test_stub.test_fio_iops(vm_inv, volume_iops) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network IOPS Test Pass')
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', \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) 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) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Disk QoS Test Pass')
def test(): global deploy_conf global vm_inv global vm test_util.test_dsc('Test Delete VR Offering and Teboot Normal VM') vm = test_stub.create_basic_vm() test_obj_dict.add_vm(vm) vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip vm.check() test_util.test_dsc('Record current virtual router offering information') deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config) cond = res_ops.gen_query_conditions('zone.vmInstance.uuid', '=', vm_inv.uuid) vr_offering_uuid = res_ops.query_resource(res_ops.VR_OFFERING, cond)[0].uuid test_util.test_dsc('Delete VR-RM and VR-Offering') cond = res_ops.gen_query_conditions('zone.vmInstance.uuid', '=', vm_inv.uuid) vr_vm_uuid = res_ops.query_resource(res_ops.VIRTUALROUTER_VM, cond)[0].uuid vm_ops.destroy_vm(vr_vm_uuid) vm_ops.delete_instance_offering(vr_offering_uuid) test_util.test_dsc('Create new VR-Offering, same as the former one, stop and start VM') session_uuid = acc_ops.login_as_admin() dep_ops.add_virtual_router(None, None, deploy_conf, session_uuid) vm.reboot() vm.destroy() test_obj_dict.rm_vm(vm) test_util.test_pass('Delete VR Offering and reboot normal VM: SUCCESS')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory over provision method') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 2 target_vm_num = 4 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) real_availableMemory = host_res.availableMemory avail_mem = real_availableMemory * over_provision_rate if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 512MB, skip test.') return True test_util.test_logger('host available memory is: %s' % host_res.availableMemory) original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) new_offering_mem = int((avail_mem - 1) / target_vm_num) if (new_offering_mem % 2) != 0 : new_offering_mem = new_offering_mem - 1 new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid times = 1 while (times <= target_vm_num): try: vm_name = 'mem_over_prs_vm_%d' % times vm = test_stub.create_vm(vm_name = vm_name, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) host_res_new = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) test_util.test_logger('After create vm: %s, host available memory is: %s' % (vm_name, host_res_new.availableMemory)) except Exception as e: test_util.test_logger("Unexpected VM Creation Failure in memory over provision test. Previous available memory is %s" % host_res_new.availableMemory) raise e times += 1 host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 > new_offering_mem: test_util.test_fail('Available memory: %d is still bigger than offering memory: %d , after creating 4 vms.' % (avail_mem2, new_offering_mem)) try: vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_bad', \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except: test_util.test_logger("Expected VM Creation Failure in memory over provision test. ") else: test_util.test_fail("The 5th VM is still created up, which is wrong") test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 cpuSpeed = 16 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_cpuSpeed(cpuSpeed) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url('http://172.20.1.15:7480/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) l3_name = os.environ.get('l3PublicNetworkName') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid) test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip test_lib.lib_wait_target_up(vm_ip, '22', 2400) cmd ='[ -e /root ] && echo yes || echo no' ssh_num = 0 ssh_ok = 0 while ssh_num <= 5 and ssh_ok == 0 : rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: time.sleep(30) else: ssh_ok = 1 break ssh_num = ssh_num + 1 if ssh_ok == 0: test_util.test_fail('fail to ssh to VM') vm.check() vm.destroy() test_obj_dict.rm_vm(vm) image.delete() test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation Test Success')
def test(): global vm, session_uuid global all_volume_offering_uuid, rw_volume_offering_uuid, instance_offering_uuid global test_account_uuid test_util.test_dsc('Test normal account change the qos network and volume ') #create normal account test_util.test_dsc('create normal account') account_name = 'a' account_pass = hashlib.sha512(account_name).hexdigest() test_account = acc_ops.create_normal_account(account_name, account_pass) test_account_uuid = test_account.uuid test_account_session = acc_ops.login_by_account(account_name, account_pass) #create disk offering test_util.test_dsc('create disk offering') name_all = 'all_disk_offering' volume_bandwidth = 30*1024*1024 all_volume_offering = test_lib.lib_create_disk_offering(name = name_all, volume_bandwidth = volume_bandwidth) all_volume_offering_uuid = all_volume_offering.uuid name_rw = 'rw_disk_offering' volume_read_bandwidth = 90*1024*1024 volume_write_bandwidth = 100*1024*1024 rw_volume_offering = test_lib.lib_create_disk_offering(name = name_rw, read_bandwidth = volume_read_bandwidth, write_bandwidth = volume_write_bandwidth) rw_volume_offering_uuid = rw_volume_offering.uuid #create instance offering test_util.test_dsc('create instance offering') read_bandwidth = 50*1024*1024 write_bandwidth = 60*1024*1024 net_outbound_bandwidth = 70*1024*1024 net_inbound_bandwidth = 80*1024*1024 new_instance_offering = test_lib.lib_create_instance_offering(read_bandwidth = read_bandwidth, write_bandwidth=write_bandwidth, net_outbound_bandwidth = net_outbound_bandwidth, net_inbound_bandwidth = net_inbound_bandwidth) instance_offering_uuid = new_instance_offering.uuid #share admin resoure to normal account test_util.test_dsc('share admin resoure to normal account') test_stub.share_admin_resource([test_account_uuid]) acc_ops.share_resources([test_account_uuid], [all_volume_offering_uuid, rw_volume_offering_uuid]) #create vm with 2 data volumes test_util.test_dsc('create vm with volumes qos by normal account a') l3net_uuid = res_ops.get_resource(res_ops.L3_NETWORK, session_uuid = test_account_session)[0].uuid cond = res_ops.gen_query_conditions('platform', '=', 'Linux') image_uuid = res_ops.query_resource(res_ops.IMAGE, cond, session_uuid = test_account_session)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_l3_uuids([l3net_uuid]) vm = test_stub.create_vm_with_volume(vm_creation_option = vm_creation_option, data_volume_uuids = [all_volume_offering_uuid, rw_volume_offering_uuid], session_uuid = test_account_session) vm_inv = vm.get_vm() # get the nic uuid test_util.test_dsc('get the vm_nic') l3_uuid = vm_inv.vmNics[0].l3NetworkUuid vm_nic = test_lib.lib_get_vm_nic_by_l3(vm_inv, l3_uuid) # get the volume uuid test_util.test_dsc('get the vm data volumes') cond1 = res_ops.gen_query_conditions("diskOfferingUuid", '=', all_volume_offering_uuid) cond2 = res_ops.gen_query_conditions("diskOfferingUuid", '=', rw_volume_offering_uuid) all_volume_uuid = res_ops.query_resource(res_ops.VOLUME, cond1)[0].uuid rw_volume_uuid = res_ops.query_resource(res_ops.VOLUME, cond2)[0].uuid #set root disk qos test_util.test_dsc('set read*2, read/2, write*2, write/2 and del the root disk read and write qos') try: vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = read_bandwidth*2, mode = 'read', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('del the root disk read qos') try: vm_ops.del_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, mode = 'read', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = read_bandwidth/2, mode = 'read', session_uuid = test_account_session) test_util.test_dsc('set 2 times the root disk write qos') try: vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = write_bandwidth*2, mode = 'write', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('del the root disk write qos') try: vm_ops.del_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, mode = 'write', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('set below the root disk write qos') vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, volumeBandwidth = write_bandwidth/2, mode = 'write', session_uuid = test_account_session) #set data disk all_volume_uuid qos test_util.test_dsc('set read*2, read/2, write*2, write/2 and del the volume1 disk read and write qos') try: vm_ops.set_vm_disk_qos(all_volume_uuid, volumeBandwidth = volume_bandwidth*2, session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('del the data volume qos') try: vm_ops.del_vm_disk_qos(all_volume_uuid, session_uuid = test_account_session) except: print "Test results were in line with expectations" pass vm_ops.set_vm_disk_qos(all_volume_uuid, volumeBandwidth = volume_bandwidth/2, session_uuid = test_account_session) #set data disk rw_volume_uuid write qos test_util.test_dsc('set 2 times the data rw_volume_uuid write qos') try: vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_write_bandwidth*2, mode = 'write', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('del the data rw_volume_uuid write qos') try: vm_ops.del_vm_disk_qos(rw_volume_uuid, mode = 'write', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_write_bandwidth/2, mode = 'write', session_uuid = test_account_session) #set data disk rw_volume_uuid read qos test_util.test_dsc('set 2 times the data rw_volume_uuid read qos') try: vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_read_bandwidth*2, mode = 'read', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('del the data rw_volume_uuid read qos') try: vm_ops.del_vm_disk_qos(rw_volume_uuid, mode = 'read', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass vm_ops.set_vm_disk_qos(rw_volume_uuid, volumeBandwidth = volume_read_bandwidth/2, mode = 'read', session_uuid = test_account_session) # set the vm nic qos test_util.test_dsc('set higher than net out and in ') try: vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth*2, inboundBandwidth = net_inbound_bandwidth*2, session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('set higher than net out and equal in ') try: vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth*2, inboundBandwidth = net_inbound_bandwidth, session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('del net in ') try: vm_ops.del_vm_nic_qos(vm_nic.uuid, direction = 'in', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('del net out ') try: vm_ops.del_vm_nic_qos(vm_nic.uuid, direction = 'out', session_uuid = test_account_session) except: print "Test results were in line with expectations" pass test_util.test_dsc('set equal net out and in ') try: vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth, inboundBandwidth = net_inbound_bandwidth, session_uuid = test_account_session) #except: except Exception as e: test_util.test_logger(e) test_util.test_dsc('set below net out and in ') vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_outbound_bandwidth/2, inboundBandwidth = net_inbound_bandwidth/2, session_uuid = test_account_session) vm.check() vm.destroy(test_account_session) vm.check() vol_ops.delete_disk_offering(all_volume_offering_uuid) vol_ops.delete_disk_offering(rw_volume_offering_uuid) vol_ops.delete_volume(all_volume_uuid, test_account_session) vol_ops.delete_volume(rw_volume_uuid, test_account_session) acc_ops.delete_account(test_account_uuid) vm_ops.delete_instance_offering(instance_offering_uuid) test_util.test_pass('Create VM Test Success')
def test(): global ssh_timeout data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) cond = res_ops.gen_query_conditions('name', '=', 'image-iso') iso_image = res_ops.query_resource(res_ops.IMAGE, cond) if not iso_image: img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('imageServer')+'/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) else: image_uuid = iso_image[0].uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid, system_tags=["cdroms::%s::Empty::Empty" % (image_uuid)]) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #test_lib.lib_wait_target_up(vm_ip, '22', 2400) #vm.check() #cmd ='[ -e /root ] && echo yes || echo no' cmd ='[ -e /root ]' #ssh_num = 0 #ssh_ok = 0 #while ssh_num <= 5 and ssh_ok == 0 : # rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) # if rsp == False: # time.sleep(30) # else: # ssh_ok = 1 # break # ssh_num = ssh_num + 1 #if ssh_ok == 0: # test_util.test_fail('fail to ssh to VM') ssh_timeout = test_lib.SSH_TIMEOUT test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("iso has not been failed to installed.") cmd_cdrom = 'ls /dev/ | grep sr | wc -l' cdroms = test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd_cdrom) assert str(cdroms).strip() == '3' test_lib.SSH_TIMEOUT = ssh_timeout vm.destroy() test_obj_dict.rm_vm(vm) # image.delete() # test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation Test Success')
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 error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if new_offering_uuid: vm_ops.delete_instance_offering(new_offering_uuid)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if original_rate: test_lib.lib_set_provision_memory_rate(original_rate) if new_offering_uuid: vm_ops.delete_instance_offering(new_offering_uuid)
def test(): global image global test_obj_dict #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip("skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 1024*1024*1024 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('isoForVmUrl')) image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #delete iso image.delete() test_obj_dict.rm_image(image) #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(vm, "VM_TEST_STATE") vm.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): global ssh_timeout data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url('http://172.20.1.15:7480/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #test_lib.lib_wait_target_up(vm_ip, '22', 2400) #vm.check() #cmd ='[ -e /root ] && echo yes || echo no' cmd ='[ -e /root ]' #ssh_num = 0 #ssh_ok = 0 #while ssh_num <= 5 and ssh_ok == 0 : # rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) # if rsp == False: # time.sleep(30) # else: # ssh_ok = 1 # break # ssh_num = ssh_num + 1 #if ssh_ok == 0: # test_util.test_fail('fail to ssh to VM') ssh_timeout = test_lib.SSH_TIMEOUT test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("iso has not been failed to installed.") test_lib.SSH_TIMEOUT = ssh_timeout vm.destroy() test_obj_dict.rm_vm(vm) image.delete() test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation Test Success')
def test(): #skip ceph in c74 cmd = "cat /etc/redhat-release | grep '7.4'" mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName rsp = test_lib.lib_execute_ssh_cmd(mn_ip, 'root', 'password', cmd, 180) if rsp != False: ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == 'Ceph': test_util.test_skip('cannot hotplug iso to the vm in ceph,it is a libvirt bug:https://bugzilla.redhat.com/show_bug.cgi?id=1541702.') global image global test_obj_dict allow_bs_list = [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE, inventory.CEPH_BACKUP_STORAGE_TYPE] test_lib.skip_test_when_bs_type_not_in_list(allow_bs_list) allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint'] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip("skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 1024*1024*1024 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('isoForVmUrl')) image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #clone vm cloned_vm_name = ['cloned_vm_name'] cloned_vm_obj = vm.clone(cloned_vm_name)[0] test_obj_dict.add_vm(cloned_vm_obj) #delete iso image.delete() test_obj_dict.rm_image(image) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #create image by vm root volume cloned_vm_img_name = "cloned_vm_image1" img_option2 = test_util.ImageOption() img_option2.set_backup_storage_uuid_list([bs_uuid]) img_option2.set_root_volume_uuid(cloned_vm_obj.vm.rootVolumeUuid) img_option2.set_name(cloned_vm_img_name) image1 = test_image.ZstackTestImage() image1.set_creation_option(img_option2) image1.create() image1.check() test_obj_dict.add_image(image1) bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE) if inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE == bs_list[0] and len(bs_list) == 1 : #export image image1.export() #create vm vm2 = test_stub.create_vm('image-vm', cloned_vm_img_name, l3_name) #delete image image1.delete() test_obj_dict.rm_image(image1) #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") #expunge image image1.expunge() #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") vm.destroy() vm2.destroy() cloned_vm_obj.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
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 original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num)): thread = threading.Thread(target = parallelly_create_vm, \ args = ('parallel_vm_creating_%d' % times, \ host.uuid, \ new_offering.uuid, )) thread.start() times += 1 times = 1 print 'Running VM: %s ' % len(test_obj_dict.get_vm_list()) while threading.active_count() > 1: check_thread_exception() time.sleep(1) if times > 5: test_util.test_fail('creating vm time exceed 5s') times += 1 check_thread_exception() for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e) raise e host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Parallel vm creation Test 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 volume_offering_uuid,new_offering_uuid test_util.test_dsc('Test VM data volume bandwidth QoS by 20MB') # Only imagestore supports full clone bs = res_ops.query_resource(res_ops.BACKUP_STORAGE) for i in bs: if i.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: break else: test_util.test_skip('Skip test on non-imagestore') # SharedBlock and AliyunNAS not support full clone ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type in ['SharedBlock', 'AliyunNAS']: test_util.test_skip('Skip test on SharedBlock and AliyunNAS PS') #unit is KB write_bandwidth = 10*1024*1024 new_offering = test_lib.lib_create_instance_offering(write_bandwidth = write_bandwidth) new_offering_uuid = new_offering.uuid new_volume_offering = test_lib.lib_create_disk_offering(write_bandwidth = write_bandwidth) volume_offering_uuid = new_volume_offering.uuid vm = test_stub.create_vm(vm_name='vm_volume_qos', instance_offering_uuid = new_offering_uuid, disk_offering_uuids = [volume_offering_uuid]) test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() cond = res_ops.gen_query_conditions("vmInstanceUuid", '=', vm_inv.uuid) cond = res_ops.gen_query_conditions("type", '=', 'Data', cond) volume_uuid = res_ops.query_resource(res_ops.VOLUME, cond)[0].uuid test_lib.lib_mkfs_for_volume(volume_uuid, vm_inv) path = '/mnt' user_name = 'root' user_password = '******' os.system("sshpass -p '%s' ssh %s@%s 'mount /dev/vdb1 %s'"%(user_password, user_name, vm_inv.vmNics[0].ip, path)) vm.check() test_stub.make_ssh_no_password(vm_inv) # test_stub.install_fio(vm_inv) vm_ops.set_vm_disk_qos(test_lib.lib_get_data_volumes(vm_inv)[0].uuid, write_bandwidth*2, 'write') vm_ops.set_vm_disk_qos(test_lib.lib_get_root_volume(vm_inv).uuid, write_bandwidth*2, 'write') new_vm = vm.clone(['full_cloned_vm'], full=True)[0] new_vm.check() test_obj_dict.add_vm(new_vm) volumes_number = len(test_lib.lib_get_all_volumes(new_vm.vm)) if volumes_number != 2: test_util.test_fail('Did not find 2 volumes for [vm:] %s. But we assigned 2 data volume when create the vm. We only catch %s volumes' % (new_vm.vm.uuid, volumes_number)) else: test_util.test_logger('Find 2 volumes for [vm:] %s.' % new_vm.vm.uuid) new_vm_inv = new_vm.get_vm() test_stub.install_fio(new_vm_inv) if vm_ops.get_vm_disk_qos(test_lib.lib_get_data_volumes(new_vm_inv)[0].uuid).volumeBandwidthWrite != write_bandwidth*2: test_util.test_fail('Retrieved disk qos not match') test_stub.test_fio_bandwidth(new_vm_inv, write_bandwidth*2) test_stub.test_fio_bandwidth(new_vm_inv, write_bandwidth*2, path) if test_stub.test_fio_bandwidth(vm_inv, write_bandwidth, '/dev/vda', raise_exception=False): test_util.test_fail('disk read qos is not expected to have limit as only read qos was set') if test_stub.test_fio_bandwidth(vm_inv, write_bandwidth, '/dev/vdb', raise_exception=False): test_util.test_fail('disk read qos is not expected to have limit as only read qos was set') vm_ops.delete_instance_offering(new_offering_uuid) vol_ops.delete_disk_offering(volume_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM data volume read QoS Test Pass')
def test(): global image global test_obj_dict #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip( "skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 1024 * 1024 * 1024 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('isoForVmUrl')) image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #delete iso image.delete() test_obj_dict.rm_image(image) #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(vm, "VM_TEST_REIMAGE") vm.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) try: vm_ops.delete_instance_offering(new_offering_uuid) except: pass
def test(): data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 cpuSpeed = 16 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_cpuSpeed(cpuSpeed) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url( 'http://172.20.1.15:7480/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) l3_name = os.environ.get('l3PublicNetworkName') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid) test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip test_lib.lib_wait_target_up(vm_ip, '22', 2400) cmd = '[ -e /root ] && echo yes || echo no' ssh_num = 0 ssh_ok = 0 while ssh_num <= 5 and ssh_ok == 0: rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: time.sleep(30) else: ssh_ok = 1 break ssh_num = ssh_num + 1 if ssh_ok == 0: test_util.test_fail('fail to ssh to VM') vm.check() vm.destroy() test_obj_dict.rm_vm(vm) image.delete() test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation Test Success')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num+3)): try: vm = test_stub.create_vm(vm_name = 'mem_reclaim_vm_%d' % times, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_logger("VM Creation Failure in memory reclaiming test. :%s " % e) pass times += 1 for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e) pass host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num)): thread = threading.Thread(target = parallelly_create_vm, \ args = ('parallel_vm_creating_%d' % times, \ host.uuid, \ new_offering.uuid, )) thread.start() times += 1 times = 1 print 'Running VM: %s ' % len(test_obj_dict.get_vm_list()) while threading.active_count() > 1: check_thread_exception() time.sleep(1) if times > 30: test_util.test_fail('creating vm time exceed 30s') times += 1 check_thread_exception() for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e) raise e host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Parallel vm creation Test Pass')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory over provision method') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.') return True host = host[0] over_provision_rate = 2 target_vm_num = 4 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) real_availableMemory = host_res.availableMemory - \ sizeunit.get_size(test_lib.lib_get_reserved_memory()) avail_mem = real_availableMemory * over_provision_rate if avail_mem <= 1024 * 1024 * 1024: test_util.test_skip('Available memory is less than 512MB, skip test.') return True test_util.test_logger('host available memory is: %s' % host_res.availableMemory) original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) new_offering_mem = avail_mem / target_vm_num new_offering = test_lib.lib_create_instance_offering( memorySize=new_offering_mem) new_offering_uuid = new_offering.uuid times = 1 while (times <= target_vm_num): try: vm_name = 'mem_over_prs_vm_%d' % times vm = test_stub.create_vm(vm_name = vm_name, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) host_res_new = test_lib.lib_get_cpu_memory_capacity( host_uuids=[host.uuid]) test_util.test_logger( 'After create vm: %s, host available memory is: %s' % (vm_name, host_res_new.availableMemory)) except Exception as e: test_util.test_logger( "Unexpected VM Creation Failure in memory over provision test. Previous available memory is %s" % host_res_new.availableMemory) raise e times += 1 host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 > new_offering_mem: test_util.test_fail( 'Available memory: %d is still bigger than offering memory: %d , after creating 4 vms.' % (avail_mem2, new_offering_mem)) try: vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_bad', \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except: test_util.test_logger( "Expected VM Creation Failure in memory over provision test. ") else: test_util.test_fail("The 5th VM is still created up, which is wrong") test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): global image global test_obj_dict allow_bs_list = [ inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE, inventory.CEPH_BACKUP_STORAGE_TYPE, inventory.SFTP_BACKUP_STORAGE_TYPE ] test_lib.skip_test_when_bs_type_not_in_list(allow_bs_list) allow_ps_list = [ inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint' ] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip( "skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 2147483648 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url( 'http://172.20.1.15:7480/iso/CentOS-x86_64-7.2-Minimal.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #clone vm cloned_vm_name = ['cloned_vm_name'] cloned_vm_obj = vm.clone(cloned_vm_name)[0] test_obj_dict.add_vm(cloned_vm_obj) #delete iso image.delete() test_obj_dict.rm_image(image) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #create image by vm root volume cloned_vm_img_name = "cloned_vm_image1" img_option2 = test_util.ImageOption() img_option2.set_backup_storage_uuid_list([bs_uuid]) img_option2.set_root_volume_uuid(cloned_vm_obj.vm.rootVolumeUuid) img_option2.set_name(cloned_vm_img_name) image1 = test_image.ZstackTestImage() image1.set_creation_option(img_option2) image1.create() image1.check() test_obj_dict.add_image(image1) #export image image1.export() #create vm vm2 = test_stub.create_vm('image-vm', cloned_vm_img_name, l3_name) #delete image image1.delete() test_obj_dict.rm_image(image1) #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") #expunge image image1.expunge() #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") vm.destroy() vm2.destroy() cloned_vm_obj.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.') return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024 * 1024 * 1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering( memorySize=new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num + 3)): try: vm = test_stub.create_vm(vm_name = 'mem_reclaim_vm_%d' % times, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_logger( "VM Creation Failure in memory reclaiming test. :%s " % e) pass times += 1 for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger( "VM Destroying Failure in memory reclaiming test. :%s " % e) pass host_res2 = test_lib.lib_get_cpu_memory_capacity( host_uuids=[host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail( 'Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')