def test(): global new_offering_uuid test_util.test_dsc('Test change VM network bandwidth QoS by 1MB') vm = test_stub.create_vm(vm_name='vm_net_qos') l3_uuid = vm.get_vm().vmNics[0].l3NetworkUuid test_obj_dict.add_vm(vm) net_bandwidth = 512 * 1024 vm_nic = test_lib.lib_get_vm_nic_by_l3(vm.vm, l3_uuid) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth / 2) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth / 2) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth / 2) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS change instance offering Test Pass')
def test(): success_round = 0 for i in range(0,vm_max): test_util.test_logger("clear %s data" % billing_resource) test_stub.resource_price_clear(billing_resource) test_util.test_logger("=====SPENDING CHECK VIP %s=====" % str(i+1)) bill_ip_in = test_stub.PublicIpNicInBilling() time_unit = random.choice(time_unit_dict) price = str(random.randint(0,9999)) resource_unit = random.choice(resource_unit_dict.keys()) bill_ip_in.set_timeUnit(time_unit) bill_ip_in.set_price(price) bill_ip_in.set_resourceUnit(resource_unit) test_util.test_logger("create ip nic in billing\n price=%s, timeUnit=%s" % (price, time_unit)) bill_ip_in.create_resource_type() test_util.test_logger("create ip nic instance and set qos") global vm vm = test_stub.create_vm_billing("test_vmm", test_stub.set_vm_resource()[0], None,\ test_stub.set_vm_resource()[1], test_stub.set_vm_resource()[2]) qos_in = 1048576 #1M vm_nic_uuid = vm.vm.vmNics[0].uuid vm_ops.set_vm_nic_qos(vm_nic_uuid, inboundBandwidth = qos_in) qos_size = qos_in/resource_unit_dict[resource_unit] test_util.test_logger("@DEBUG@: qos_size=%s resource_unit=%s" % (qos_size, resource_unit)) test_util.test_logger("====check ip nic %s spending====" % vm_nic_uuid) for r in range(0,round_max): test_util.test_logger('===spending check round %s-%s===' % (str(i+1), str(r+1))) if test_stub.check(bill_ip_in, billing_resource, random.choice(offset_unit_dict), random.randint(0,3), qos_size): success_round += 1 else: test_util.test_fail("check ip nic billing spending finished\n success: %s/%s" % (success_round, round_sum)) test_util.test_pass("check ip nic billing spending finished\n success: %s/%s" % (success_round, round_sum))
def test(): global new_offering_uuid test_util.test_dsc('Test change VM network bandwidth QoS by 1MB') vm = test_stub.create_vm(vm_name = 'vm_net_qos') vm.check() l3_uuid = vm.get_vm().vmNics[0].l3NetworkUuid test_obj_dict.add_vm(vm) net_bandwidth = 512 vm_nic = test_lib.lib_get_vm_nic_by_l3(vm.vm, l3_uuid) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth*8*1024) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth*8*1024/2) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth/2) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth/2) vm_ops.del_vm_nic_qos(vm_nic.uuid, 'out') time.sleep(1) if test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth/2, raise_exception=False): test_util.test_fail('VM network Outbound is not expected to be limited after qos setting is deleted') test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS change instance offering Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test change VM network bandwidth QoS by 1MB') vm = test_stub.create_vm(vm_name = 'vm_net_qos') l3_uuid = vm.get_vm().vmNics[0].l3NetworkUuid test_obj_dict.add_vm(vm) net_bandwidth = 512 * 1024 vm_nic = test_lib.lib_get_vm_nic_by_l3(vm.vm, l3_uuid) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth/2) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth/2) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth/2) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS change instance offering Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM 2nic outbound & inbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 2 * 1024 vm1 = test_stub.create_vm(vm_name='vm_net_inbound_outbound_qos', l3_name=os.environ.get('l3PublicNetworkName')) l3_net_uuid2 = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetworkName1')).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', l3_name=os.environ.get('l3PublicNetworkName')) 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) vm1.add_nic(l3_net_uuid2) vm2.add_nic(l3_net_uuid2) # Set a single nic to smaller bandwidth vm_nic = test_lib.lib_get_vm_nic_by_l3(vm1.vm, l3_net_uuid2) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth * 8 * 1024 / 2) vm1.stop() vm2.stop() vm1.start() vm2.start() 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_uuid2).ip, net_bandwidth / 2) #vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network 2nd nic QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test VM 2nic outbound & inbound bandwidth QoS by 1MB') #unit is KB net_bandwidth = 1 * 1024 vm1 = test_stub.create_vm(vm_name = 'vm_net_inbound_outbound_qos', l3_name=os.environ.get('l3PublicNetworkName')) l3_net_uuid2 = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetworkName1')).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', l3_name=os.environ.get('l3PublicNetworkName')) 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) vm1.add_nic(l3_net_uuid2) vm2.add_nic(l3_net_uuid2) 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)) #l3_name = os.environ.get('l3VlanNetworkName1') #l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid #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) # Set a single nic to smaller bandwidth vm_nic = test_lib.lib_get_vm_nic_by_l3(vm1.vm, l3_net_uuid2) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth*8*1024/2) cmd = '%s %s "ping %s -c 10"' %(ssh_cmd, vm1_ip, test_lib.lib_get_vm_nic_by_l3(vm2.get_vm(), l3_net_uuid2).ip) ping_ret=1 while ping_ret: ping_ret = os.system(cmd) test_stub.test_scp_outbound_speed(vm1_ip, test_lib.lib_get_vm_nic_by_l3(vm2.get_vm(), l3_net_uuid2).ip, net_bandwidth/2) #l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName')).uuid #test_stub.test_scp_outbound_speed(vm1_ip, test_lib.lib_get_vm_nic_by_l3(vm2.get_vm(), l3_net_uuid2).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 2nd nic QoS Test Pass')
def test(): global new_offering_uuid test_util.test_dsc('Test change VM network bandwidth QoS by 1MB') vm = test_stub.create_vm(vm_name='vm_net_qos') l3_uuid = vm.get_vm().vmNics[0].l3NetworkUuid test_obj_dict.add_vm(vm) net_bandwidth = 512 vm_nic = test_lib.lib_get_vm_nic_by_l3(vm.vm, l3_uuid) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth * 8 * 1024) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth=net_bandwidth * 8 * 1024 / 2) vm.check() time.sleep(1) test_stub.make_ssh_no_password(vm.get_vm()) test_stub.create_test_file(vm.get_vm(), net_bandwidth / 2) test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth / 2) vm_ops.del_vm_nic_qos(vm_nic.uuid, 'out') time.sleep(1) if test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth / 2, raise_exception=False): test_util.test_fail( 'VM network Outbound is not expected to be limited after qos setting is deleted' ) vm.stop() vm.start() vm.check() if test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth / 2, raise_exception=False): test_util.test_fail( 'VM network Outbound is not expected to be limited after qos setting is deleted even after reboot' ) vm.reboot() vm.check() if test_stub.test_scp_vm_outbound_speed(vm.get_vm(), net_bandwidth / 2, raise_exception=False): test_util.test_fail( 'VM network Outbound is not expected to be limited after qos setting is deleted even after reboot' ) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('VM Network QoS change instance offering Test Pass')
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(): cond = res_ops.gen_query_conditions('system', '=', 'false') imageUuid = res_ops.query_resource_fields(res_ops.IMAGE, cond)[0].uuid cond = res_ops.gen_query_conditions('type', '=', 'UserVm') instanceOfferingUuid = res_ops.query_resource_fields(res_ops.INSTANCE_OFFERING, cond)[0].uuid cond = res_ops.gen_query_conditions('name', '=', 'public network') l3NetworkUuids = res_ops.query_resource_fields(res_ops.L3_NETWORK, cond)[0].uuid vm_name = 'vm-1' create_bill(1, "pubIpVmNicBandwidthIn", "s", "m") resourcePrices = query_resource_price() for resource_price in resourcePrices: delete_price(resource_price.uuid) ##parallel create bill counter = 0 for i in range(0, 200): ipin = threading.Thread(target=create_bill, args=(i, "pubIpVmNicBandwidthIn", "s", "k")) ipout = threading.Thread(target=create_bill, args=(i, "pubIpVmNicBandwidthOut", "m", "m")) vipin = threading.Thread(target=create_bill, args=(i, "pubIpVipBandwidthIn", "h", "g")) vipout = threading.Thread(target=create_bill, args=(i, "pubIpVipBandwidthOut", "d", "m")) while threading.active_count() > 10: time.sleep(3) ipin.start() ipout.start() vipin.start() vipout.start() #Delete all price resourcePrices = query_resource_price() ##wait 15s for all prices created i = 0 while len(resourcePrices) != 800: print len(resourcePrices) time.sleep(3) if i > 5: test_util.test_fail("Fail to create 800 prices") i = i + 1 resourcePrices = query_resource_price() #Delete all price for resource_price in resourcePrices: delete_price(resource_price.uuid) ipin = threading.Thread(target=create_bill, args=(10, "pubIpVmNicBandwidthIn", "s", "m")) ipout = threading.Thread(target=create_bill, args=(10, "pubIpVmNicBandwidthOut", "s", "m")) vipin = threading.Thread(target=create_bill, args=(10, "pubIpVipBandwidthIn", "s", "m")) vipout = threading.Thread(target=create_bill, args=(10, "pubIpVipBandwidthOut", "s", "m")) ipin.start() ipout.start() vipin.start() vipout.start() net_bandwidth = 10*1024*1024 vm = create_vm(vm_name, imageUuid, None,instanceOfferingUuid, l3NetworkUuids) vm_inv = vm.get_vm() vm_nic = test_lib.lib_get_vm_nic_by_l3(vm_inv, l3NetworkUuids) vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_bandwidth, inboundBandwidth = net_bandwidth) cond = res_ops.gen_query_conditions('name', '=', 'admin') time.sleep(1) admin_uuid = res_ops.query_resource_fields(res_ops.ACCOUNT, cond)[0].uuid prices = bill_ops.calculate_account_spending(admin_uuid) if prices.total < 180: test_util.test_fail("test billing fail, bill is lesser than 180 after vm nic qos set") #Delete vm nic qos vm_ops.del_vm_nic_qos(vm_nic.uuid, "in") vm_ops.del_vm_nic_qos(vm_nic.uuid, "out") time.sleep(1) # Total cost should not grow up price1 = bill_ops.calculate_account_spending(admin_uuid) time.sleep(2) price2 = bill_ops.calculate_account_spending(admin_uuid) if price1.total != price2.total: test_util.test_fail("test billing fail, bill still grows up after deleting vm nic qos. price1 total: %s, price2 total: %s" % (price1.total, price2.total)) #Delete vm nic resource price price_ipin = query_resource_price(resource_name = "pubIpVmNicBandwidthIn")[0] price_ipout = query_resource_price(resource_name = "pubIpVmNicBandwidthOut")[0] delete_price(price_ipin.uuid) delete_price(price_ipout.uuid) #make sure vm nic resource price has been deleted price_ipin = query_resource_price(resource_name = "pubIpVmNicBandwidthIn") price_ipout = query_resource_price(resource_name = "pubIpVmNicBandwidthOut") if len(price_ipin) > 0 or len(price_ipout)> 0: test_util.test_fail("Fail to clean vm nic resource price. length of pubIpVmNicBandwidthIn: %d, length of pubIpVmNicBandwidthOut: %d" %(len(price_ipin), len(price_ipout))) # price.total should be 0, after the prices are deleted prices = bill_ops.calculate_account_spending(admin_uuid) if prices.total != 0: test_util.test_fail("test billing fail, bill is not 0. Bill is: %s" % (prices.total)) #create vip qos vip = test_stub.create_vip("test_vip_qos_price", l3NetworkUuids) vip_uuid = vip.get_vip().uuid vip_qos = net_ops.set_vip_qos(vip_uuid=vip_uuid, inboundBandwidth = net_bandwidth, outboundBandwidth = net_bandwidth) time.sleep(1) prices = bill_ops.calculate_account_spending(admin_uuid) if prices.total < 180: print prices.total test_util.test_fail("test billing fail, bill is lesser than 180 after vip qos set") #Delete vip qos net_ops.delete_vip_qos(vip_uuid) time.sleep(1) # Total cost should not grow up price1 = bill_ops.calculate_account_spending(admin_uuid) time.sleep(2) price2 = bill_ops.calculate_account_spending(admin_uuid) if price1.total != price2.total: test_util.test_fail("test billing fail, bill still grows up after deleting vip qos. price1 total: %s, price2 total: %s" % (price1.total, price2.total)) #Delete vip resource price price_vipin = query_resource_price(resource_name = "pubIpVipBandwidthIn")[0] price_vipout = query_resource_price(resource_name = "pubIpVipBandwidthOut")[0] delete_price(price_vipin.uuid) delete_price(price_vipout.uuid) #make sure vm nic resource price has been deleted price_vipin = query_resource_price(resource_name = "pubIpVipBandwidthIn") price_vipout = query_resource_price(resource_name = "pubIpVipBandwidthOut") if len(price_vipin) > 0 or len(price_vipout)> 0: test_util.test_fail("Fail to clean vip resource price. length of pubIpVipBandwidthIn: %d, length of pubIpVipBandwidthOut: %d" %(len(price_vipin), len(price_vipout))) # price.total should be 0, after the prices are deleted prices = bill_ops.calculate_account_spending(admin_uuid) if prices.total != 0: test_util.test_fail("test billing fail, bill is not 0. Bill is: %s" % (prices.total)) test_util.test_pass("test billing pass")
def test(): test_util.test_logger("start check vm lifecycle") test_util.test_logger("create public ip billing") bill_ip = test_stub.PublicIpBilling() ipin = threading.Thread(target=bill_ip.create_resource_type(),\ args=(bill_ip.get_resourceName())) bill_ip.set_resourceName("pubIpVmNicBandwidthOut") ipout = threading.Thread(target=bill_ip.create_resource_type(),\ args=(bill_ip.get_resourceName())) ipin.start() ipout.start() test_util.test_logger("create vm instance") global vm vm = test_stub.create_vm_billing("test_vmm", test_stub.set_vm_resource()[0], None,\ test_stub.set_vm_resource()[1], test_stub.set_vm_resource()[2]) vm_nic = test_lib.lib_get_vm_nic_by_l3(vm.get_vm(), test_stub.set_vm_resource()[2]) test_util.test_logger("set vm nic bandwidth") net_bandwidth = 10*1024*1024 vm_ops.set_vm_nic_qos(vm_nic.uuid, outboundBandwidth = net_bandwidth, inboundBandwidth = net_bandwidth) time.sleep(1) test_util.test_logger("verify calculate if right is") if bill_ip.get_price_total().total < 100: test_util.test_fail("test billing fail, bill is %s ,less than 100" %(bill_ip.get_price_total().total)) test_util.test_logger("stop vm instance") vm.stop() bill_ip.compare("stop") test_util.test_logger("destory vm instance") vm.destroy() bill_ip.compare("destory") test_util.test_logger("recover vm instance") vm.recover() vm.start() bill_ip.compare("recover") test_util.test_logger("get host total and primarystorge type") Host_uuid = test_stub.get_resource_from_vmm(res_ops.HOST,vm.get_vm().zoneUuid,vm.get_vm().hostUuid) PrimaryFlag = test_stub.get_resource_from_vmm(res_ops.PRIMARY_STORAGE,vm.get_vm().zoneUuid) if Host_uuid and PrimaryFlag == 0: test_util.test_logger("migration vm instance") prices = bill_ip.get_price_total() vm.migrate(Host_uuid) prices1 = bill_ip.get_price_total() if prices1.total > prices.total: bill_ip.compare("migration") else: test_util.test_fail("test bill fail, maybe can not calculate when vm live migration") BackStorageFlag = test_stub.get_resource_from_vmm(res_ops.BACKUP_STORAGE) if BackStorageFlag == 1: clone = vm.clone(["clone-1"]) vm.clean() bill_ip.compare("clone") clone[0].clean() else: test_util.test_logger("clean vm instance") vm.clean() bill_ip.compare("clean") test_util.test_logger("delete public ip resource") resourcePrices = test_stub.query_resource_price() for resource_price in resourcePrices: test_stub.delete_price(resource_price.uuid) test_util.test_pass("check vm lifecycle with public ip billing pass")