def test_speed_glance(create_image, openstack_clients, record_property): """ Simplified Performance Tests Download / upload lance 1. Step download image 2. Step upload image """ image_size_megabytes = utils.get_configuration().get("IMAGE_SIZE_MB") image = openstack_clients.image.images.create(name="test_image", disk_format='iso', container_format='bare') start_time = time.time() openstack_clients.image.images.upload(image.id, image_data=open( "/tmp/image_mk_framework.dd", 'rb')) end_time = time.time() speed_upload = image_size_megabytes / (end_time - start_time) start_time = time.time() with open("/tmp/image_mk_framework.download", 'wb') as image_file: for item in openstack_clients.image.images.data(image.id): image_file.write(item) end_time = time.time() speed_download = image_size_megabytes / (end_time - start_time) openstack_clients.image.images.delete(image.id) record_property("Upload", speed_upload) record_property("Download", speed_download) print "++++++++++++++++++++++++++++++++++++++++" print 'upload - {} Mb/s'.format(speed_upload) print 'download - {} Mb/s'.format(speed_download)
def create_image(): image_size_megabytes = utils.get_configuration().get("IMAGE_SIZE_MB") line = 'dd if=/dev/zero of=/tmp/image_mk_framework.dd bs=1M count={image_size}'.format( image_size=image_size_megabytes) subprocess.call(line, shell=True) yield # teardown subprocess.call('rm -f /tmp/image_mk_framework.dd'.split()) subprocess.call('rm -f /tmp/image_mk_framework.download'.split())
def __init__(self, fip, user='******', password='******', private_key=None): transport = SSHTransport(fip, user, password, private_key) config = utils.get_configuration() preparation_cmd = config.get('iperf_prep_string') or [''] transport.exec_command(preparation_cmd) offline_iperf = utils.get_configuration().get("offline_iperf") if offline_iperf: transport.put_file( "/var/lib/cvp-spt/iperf_2.0.5+dfsg1-2_amd64.deb", "/home/ubuntu/iperf_2.0.5+dfsg1-2_amd64.deb") transport.exec_command( 'sudo dpkg -i /home/ubuntu/iperf_2.0.5+dfsg1-2_amd64.deb') else: transport.exec_command( 'sudo apt-get update; sudo apt-get install -y iperf') transport.exec_command("sudo ifconfig ens3 mtu 9100") transport.exec_command('nohup iperf -s > file 2>&1 &')
def __init__(self, fip, user='******', password='******', private_key=None): transport = SSHTransport(fip, user, password, private_key) config = utils.get_configuration() preparation_cmd = config.get('iperf_prep_string') or [''] transport.exec_command(preparation_cmd) transport.exec_command( 'sudo apt-get update; sudo apt-get install -y iperf') transport.exec_command('nohup iperf -s > file 2>&1 &')
def os_resources(openstack_clients): os_actions = os_client.OSCliActions(openstack_clients) os_resource = {} config = utils.get_configuration() image_name = config.get('image_name') or ['Ubuntu'] os_images_list = [image.id for image in openstack_clients.image.images.list(filters={'name': image_name})] if os_images_list.__len__() == 0: print "No images with name {}. This name can be redefined with 'image_name' env var ".format(image_name) exit() os_resource['image_id'] = str(os_images_list[0]) os_resource['flavor_id'] = [flavor.id for flavor in openstack_clients.compute.flavors.list() if flavor.name == 'spt-test'] if not os_resource['flavor_id']: os_resource['flavor_id'] = os_actions.create_flavor('spt-test', 1536, 1, 3).id else: os_resource['flavor_id'] = str(os_resource['flavor_id'][0]) os_resource['sec_group'] = os_actions.create_sec_group() os_resource['keypair'] = openstack_clients.compute.keypairs.create('spt-test-{}'.format(random.randrange(100, 999))) os_resource['net1'] = os_actions.create_network_resources() os_resource['ext_net'] = os_actions.get_external_network() adm_tenant = os_actions.get_admin_tenant() os_resource['router'] = os_actions.create_router(os_resource['ext_net'], adm_tenant.id) os_resource['net2'] = os_actions.create_network(adm_tenant.id) os_resource['subnet2'] = os_actions.create_subnet(os_resource['net2'], adm_tenant, '10.2.7.0/24') for subnet in openstack_clients.network.list_subnets()['subnets']: if subnet['network_id'] == os_resource['net1']['id']: os_resource['subnet1'] = subnet['id'] openstack_clients.network.add_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet1']}) openstack_clients.network.add_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet2']['id']}) yield os_resource # time.sleep(5) openstack_clients.network.remove_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet1']}) openstack_clients.network.remove_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet2']['id']}) openstack_clients.network.remove_gateway_router(os_resource['router']['id']) time.sleep(5) openstack_clients.network.delete_router(os_resource['router']['id']) time.sleep(5) # openstack_clients.network.delete_subnet(subnet1['id']) openstack_clients.network.delete_network(os_resource['net1']['id']) openstack_clients.network.delete_network(os_resource['net2']['id']) openstack_clients.compute.security_groups.delete(os_resource['sec_group'].id) openstack_clients.compute.keypairs.delete(os_resource['keypair'].name) openstack_clients.compute.flavors.delete(os_resource['flavor_id'])
def test_hw2hw (local_salt_client,hw_pair,record_property): helpp = helpers.helpers(local_salt_client) config = utils.get_configuration() nodes = local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), fun='network.interfaces') short_name = [] short_name.append(hw_pair[0].split('.')[0]) short_name.append(hw_pair[1].split('.')[0]) nets = config.get('networks') local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), fun='cmd.run', param=['nohup iperf -s > file 2>&1 &']) global_results = [] for net in nets: for interf in nodes[hw_pair[0]]: if 'inet' not in nodes[hw_pair[0]][interf].keys(): continue ip = nodes[hw_pair[0]][interf]['inet'][0]['address'] if (IPAddress(ip) in IPNetwork(net)) and (nodes[hw_pair[0]][interf]['inet'][0]['broadcast']): for interf2 in nodes[hw_pair[1]]: if 'inet' not in nodes[hw_pair[1]][interf2].keys(): continue ip2 = nodes[hw_pair[1]][interf2]['inet'][0]['address'] if (IPAddress(ip2) in IPNetwork(net)) and (nodes[hw_pair[1]][interf2]['inet'][0]['broadcast']): print "Will IPERF between {0} and {1}".format(ip,ip2) try: res = helpp.start_iperf_between_hosts(global_results, hw_pair[0], hw_pair[1], ip, ip2, net) record_property("1-worst {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] < res[2] else res[2]) record_property("1-best {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] > res[2] else res[2]) record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3]) record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3]) print "Measurement between {} and {} " \ "has been finished".format(hw_pair[0], hw_pair[1]) except Exception as e: print "Failed for {0} {1}".format( hw_pair[0], hw_pair[1]) print e local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), fun='cmd.run', param=['killall -9 iperf']) helpp.draw_table_with_results(global_results)
def test_vm2vm (openstack_clients, pair, os_resources, record_property): os_actions = os_client.OSCliActions(openstack_clients) config = utils.get_configuration() timeout = int(config.get('nova_timeout', 30)) try: zone1 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[0]] zone2 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[1]] vm1 = os_actions.create_basic_server(os_resources['image_id'], os_resources['flavor_id'], os_resources['net1'], '{0}:{1}'.format(zone1[0],pair[0]), [os_resources['sec_group'].name], os_resources['keypair'].name) vm2 = os_actions.create_basic_server(os_resources['image_id'], os_resources['flavor_id'], os_resources['net1'], '{0}:{1}'.format(zone1[0],pair[0]), [os_resources['sec_group'].name], os_resources['keypair'].name) vm3 = os_actions.create_basic_server(os_resources['image_id'], os_resources['flavor_id'], os_resources['net1'], '{0}:{1}'.format(zone2[0],pair[1]), [os_resources['sec_group'].name], os_resources['keypair'].name) vm4 = os_actions.create_basic_server(os_resources['image_id'], os_resources['flavor_id'], os_resources['net2'], '{0}:{1}'.format(zone2[0],pair[1]), [os_resources['sec_group'].name], os_resources['keypair'].name) vm_info = [] vms = [] vms.extend([vm1,vm2,vm3,vm4]) fips = [] time.sleep(5) for i in range(4): fip = openstack_clients.compute.floating_ips.create(os_resources['ext_net']['name']) fips.append(fip.id) status = openstack_clients.compute.servers.get(vms[i]).status if status != 'ACTIVE': print "VM #{0} {1} is not ready. Status {2}".format(i,vms[i].id,status) time.sleep(timeout) status = openstack_clients.compute.servers.get(vms[i]).status if status != 'ACTIVE': raise Exception('VM is not ready') vms[i].add_floating_ip(fip) private_address = vms[i].addresses[vms[i].addresses.keys()[0]][0]['addr'] time.sleep(5) try: ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key) except Exception as e: print e print "ssh.prepare_iperf was not successful, retry after {} sec".format(timeout) time.sleep(timeout) ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key) vm_info.append({'vm': vms[i], 'fip': fip.ip, 'private_address': private_address}) transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu', password='******', private_key=os_resources['keypair'].private_key) result1 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[1]['private_address'])) print ' '.join(result1.split()[-2::]) record_property("same {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result1.split()[-2::])) result2 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[2]['private_address'])) print ' '.join(result2.split()[-2::]) record_property("diff host {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result2.split()[-2::])) result3 = transport1.exec_command('iperf -c {} -P 10 | tail -n 1'.format(vm_info[2]['private_address'])) print ' '.join(result3.split()[-2::]) record_property("dif host 10 threads {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result3.split()[-2::])) result4 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[2]['fip'])) print ' '.join(result4.split()[-2::]) record_property("diff host fip {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result4.split()[-2::])) result5 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[3]['private_address'])) print ' '.join(result5.split()[-2::]) record_property("diff host, diff net {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result5.split()[-2::])) print "Remove VMs" for vm in vms: openstack_clients.compute.servers.delete(vm) print "Remove FIPs" for fip in fips: openstack_clients.compute.floating_ips.delete(fip) except Exception as e: print e print "Something went wrong" for vm in vms: openstack_clients.compute.servers.delete(vm) for fip in fips: openstack_clients.compute.floating_ips.delete(fip) pytest.fail("Something went wrong")