Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 1 | import pytest |
| 2 | import time |
| 3 | import subprocess |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 4 | import utils |
| 5 | |
| 6 | |
| 7 | def is_parsable(value, to): |
| 8 | """ |
| 9 | Check if value can be converted into some type |
| 10 | :param value: input value that should be converted |
| 11 | :param to: type of output value like int, float. It's not a string! |
| 12 | :return: bool |
| 13 | """ |
| 14 | try: |
| 15 | to(value) |
| 16 | except: |
| 17 | return False |
| 18 | return True |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 19 | |
| 20 | |
| 21 | @pytest.fixture |
| 22 | def create_image(): |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 23 | image_size_megabytes = utils.get_configuration().get("IMAGE_SIZE_MB") |
| 24 | create_file_cmdline = 'dd if=/dev/zero of=/tmp/image_mk_framework.dd bs=1M count={image_size}'.format( |
| 25 | image_size=image_size_megabytes) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 26 | |
Hanna Arhipova | 7a1702b | 2019-07-16 16:44:46 +0300 | [diff] [blame^] | 27 | is_cmd_successful = subprocess.call(create_file_cmdline, shell=True) == 0 |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 28 | yield is_cmd_successful |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 29 | # teardown |
Hanna Arhipova | 7a1702b | 2019-07-16 16:44:46 +0300 | [diff] [blame^] | 30 | subprocess.call('rm -f /tmp/image_mk_framework.dd', shell=True) |
| 31 | subprocess.call('rm -f /tmp/image_mk_framework.download', shell=True) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 32 | |
| 33 | |
| 34 | def test_speed_glance(create_image, openstack_clients, record_property): |
| 35 | """ |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 36 | Simplified Performance Tests Download / upload Glance |
| 37 | 1. Create file with random data (dd) |
| 38 | 2. Upload data as image to glance. |
| 39 | 3. Download image. |
| 40 | 4. Measure download/upload speed and print them into stdout |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 41 | """ |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 42 | image_size_megabytes = utils.get_configuration().get("IMAGE_SIZE_MB") |
| 43 | if not is_parsable(image_size_megabytes, int): |
| 44 | pytest.fail("Can't convert IMAGE_SIZE_MB={} to 'int'".format(image_size_megabytes)) |
| 45 | image_size_megabytes = int(image_size_megabytes) |
| 46 | if not create_image: |
| 47 | pytest.skip("Can't create image, maybe there is lack of disk space to create file {}MB". |
| 48 | format(image_size_megabytes)) |
| 49 | try: |
| 50 | image = openstack_clients.image.images.create( |
| 51 | name="test_image", |
| 52 | disk_format='iso', |
| 53 | container_format='bare') |
| 54 | except BaseException as e: |
| 55 | pytest.fail("Can't create image in Glance. Occurred error: {}".format(e)) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 56 | |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 57 | # FIXME: Error may happens while executing images.upload: |
| 58 | # CommunicationError: Error finding address for |
| 59 | # http://os-ctl-vip.harhipova-cicd-os-test.local:9292/v2/images/8bce33dd-9837-4646-b747-7f7f5ce01092/file: Unable to establish connection to http://os-ctl-vip.harhipova-cicd-os-test.local:9292/v2/images/8bce33dd-9837-4646-b747-7f7f5ce01092/file: [Errno 32] Broken pipe |
| 60 | # This may happen because of low disk space on ctl node or old cryptography package |
| 61 | # (will be fixed after upgrading to Python3) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 62 | start_time = time.time() |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 63 | try: |
| 64 | openstack_clients.image.images.upload( |
| 65 | image.id, |
| 66 | image_data=open("/tmp/image_mk_framework.dd", 'rb')) |
| 67 | except BaseException as e: |
| 68 | pytest.fail("Can't upload image in Glance. Occurred error: {}".format(e)) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 69 | end_time = time.time() |
| 70 | |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 71 | speed_upload = image_size_megabytes / (end_time - start_time) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 72 | |
| 73 | start_time = time.time() |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 74 | # it creates new file /tmp/image_mk_framework.download . It should be removed in teardown |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 75 | with open("/tmp/image_mk_framework.download", 'wb') as image_file: |
| 76 | for item in openstack_clients.image.images.data(image.id): |
| 77 | image_file.write(item) |
| 78 | end_time = time.time() |
| 79 | |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 80 | speed_download = image_size_megabytes / (end_time - start_time) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 81 | |
| 82 | openstack_clients.image.images.delete(image.id) |
| 83 | record_property("Upload", speed_upload) |
| 84 | record_property("Download", speed_download) |
| 85 | |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 86 | print("++++++++++++++++++++++++++++++++++++++++") |
| 87 | print('upload - {} Mb/s'.format(speed_upload)) |
| 88 | print('download - {} Mb/s'.format(speed_download)) |