blob: 87d6e4a6769065c0d229709c174c4ef0e8d28e1b [file] [log] [blame]
Hanna Arhipova55cc1292019-01-08 14:22:18 +02001import pytest
2import time
3import subprocess
Hanna Arhipova04ac2002019-03-01 13:12:41 +02004import utils
5
6
7def 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 Arhipova55cc1292019-01-08 14:22:18 +020019
20
21@pytest.fixture
22def create_image():
Hanna Arhipova04ac2002019-03-01 13:12:41 +020023 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 Arhipova55cc1292019-01-08 14:22:18 +020026
Hanna Arhipova7a1702b2019-07-16 16:44:46 +030027 is_cmd_successful = subprocess.call(create_file_cmdline, shell=True) == 0
Hanna Arhipova04ac2002019-03-01 13:12:41 +020028 yield is_cmd_successful
Hanna Arhipova55cc1292019-01-08 14:22:18 +020029 # teardown
Hanna Arhipova7a1702b2019-07-16 16:44:46 +030030 subprocess.call('rm -f /tmp/image_mk_framework.dd', shell=True)
31 subprocess.call('rm -f /tmp/image_mk_framework.download', shell=True)
Hanna Arhipova55cc1292019-01-08 14:22:18 +020032
33
34def test_speed_glance(create_image, openstack_clients, record_property):
35 """
Hanna Arhipova04ac2002019-03-01 13:12:41 +020036 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 Arhipova55cc1292019-01-08 14:22:18 +020041 """
Hanna Arhipova04ac2002019-03-01 13:12:41 +020042 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 Arhipova55cc1292019-01-08 14:22:18 +020056
Hanna Arhipova04ac2002019-03-01 13:12:41 +020057 # 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 Arhipova55cc1292019-01-08 14:22:18 +020062 start_time = time.time()
Hanna Arhipova04ac2002019-03-01 13:12:41 +020063 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 Arhipova55cc1292019-01-08 14:22:18 +020069 end_time = time.time()
70
Hanna Arhipova04ac2002019-03-01 13:12:41 +020071 speed_upload = image_size_megabytes / (end_time - start_time)
Hanna Arhipova55cc1292019-01-08 14:22:18 +020072
73 start_time = time.time()
Hanna Arhipova04ac2002019-03-01 13:12:41 +020074 # it creates new file /tmp/image_mk_framework.download . It should be removed in teardown
Hanna Arhipova55cc1292019-01-08 14:22:18 +020075 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 Arhipova04ac2002019-03-01 13:12:41 +020080 speed_download = image_size_megabytes / (end_time - start_time)
Hanna Arhipova55cc1292019-01-08 14:22:18 +020081
82 openstack_clients.image.images.delete(image.id)
83 record_property("Upload", speed_upload)
84 record_property("Download", speed_download)
85
Hanna Arhipova04ac2002019-03-01 13:12:41 +020086 print("++++++++++++++++++++++++++++++++++++++++")
87 print('upload - {} Mb/s'.format(speed_upload))
88 print('download - {} Mb/s'.format(speed_download))