Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 1 | import pytest |
| 2 | import time |
| 3 | import subprocess |
Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame^] | 4 | import utils |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 5 | |
| 6 | |
| 7 | @pytest.fixture |
| 8 | def create_image(): |
| 9 | line = 'echo "Executing dd on $(hostname -f)"; ' \ |
| 10 | 'dd if=/dev/zero of=/tmp/image_mk_framework.dd bs=1M count=9000 ;' \ |
| 11 | 'echo "Free space :" ; ' \ |
| 12 | 'df -H / ' |
| 13 | |
| 14 | subprocess.call(line.split()) |
| 15 | yield |
| 16 | # teardown |
| 17 | subprocess.call('rm /tmp/image_mk_framework.dd'.split()) |
| 18 | subprocess.call('rm /tmp/image_mk_framework.download'.split()) |
| 19 | |
| 20 | |
| 21 | def test_speed_glance(create_image, openstack_clients, record_property): |
| 22 | """ |
| 23 | Simplified Performance Tests Download / upload lance |
| 24 | 1. Step download image |
| 25 | 2. Step upload image |
| 26 | """ |
| 27 | image = openstack_clients.image.images.create( |
| 28 | name="test_image", |
| 29 | disk_format='iso', |
| 30 | container_format='bare') |
| 31 | |
| 32 | start_time = time.time() |
| 33 | openstack_clients.image.images.upload( |
| 34 | image.id, |
| 35 | image_data=open("/tmp/image_mk_framework.dd", 'rb')) |
| 36 | end_time = time.time() |
| 37 | |
| 38 | speed_upload = 9000 / (end_time - start_time) |
| 39 | |
| 40 | start_time = time.time() |
| 41 | with open("/tmp/image_mk_framework.download", 'wb') as image_file: |
| 42 | for item in openstack_clients.image.images.data(image.id): |
| 43 | image_file.write(item) |
| 44 | end_time = time.time() |
| 45 | |
| 46 | speed_download = 9000 / (end_time - start_time) |
| 47 | |
| 48 | openstack_clients.image.images.delete(image.id) |
| 49 | record_property("Upload", speed_upload) |
| 50 | record_property("Download", speed_download) |
| 51 | |
| 52 | print "++++++++++++++++++++++++++++++++++++++++" |
| 53 | print 'upload - {} Mb/s'.format(speed_upload) |
| 54 | print 'download - {} Mb/s'.format(speed_download) |