blob: 55149447d83bf6a1a38916c34eb41b3bbadedd0f [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import pytest
2import time
3import subprocess
4import 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
19
20
21@pytest.fixture
22def create_image():
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)
26
27 is_cmd_successful = subprocess.call(create_file_cmdline.split()) == 0
28 yield is_cmd_successful
29 # teardown
30 subprocess.call('rm -f /tmp/image_mk_framework.dd'.split())
31 subprocess.call('rm -f /tmp/image_mk_framework.download'.split())
32
33
34def test_speed_glance(create_image, openstack_clients, record_property):
35 """
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
41 """
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))
56
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)
62 start_time = time.time()
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))
69 end_time = time.time()
70
71 speed_upload = image_size_megabytes / (end_time - start_time)
72
73 start_time = time.time()
74 # it creates new file /tmp/image_mk_framework.download . It should be removed in teardown
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
80 speed_download = image_size_megabytes / (end_time - start_time)
81
82 openstack_clients.image.images.delete(image.id)
83 record_property("Upload", speed_upload)
84 record_property("Download", speed_download)
85
86 print("++++++++++++++++++++++++++++++++++++++++")
87 print('upload - {} Mb/s'.format(speed_upload))
88 print('download - {} Mb/s'.format(speed_download))