forked from harvester/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.py
130 lines (117 loc) · 5.28 KB
/
volume.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright (c) 2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 3 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com
from harvester_e2e_tests import utils
import pytest
pytest_plugins = [
'harvester_e2e_tests.fixtures.api_endpoints',
'harvester_e2e_tests.fixtures.api_version',
'harvester_e2e_tests.fixtures.session',
]
@pytest.fixture(scope='class')
def volume(request, kubevirt_api_version, admin_session,
harvester_api_endpoints):
request_json = utils.get_json_object_from_template(
'basic_volume',
size=8,
description='Test volume'
)
resp = admin_session.post(harvester_api_endpoints.create_volume,
json=request_json)
assert resp.status_code == 201, 'Unable to create a blank volume: %s' % (
resp.content)
volume_data = resp.json()
yield volume_data
if not request.config.getoption('--do-not-cleanup'):
utils.delete_volume(request, admin_session,
harvester_api_endpoints, volume_data)
@pytest.fixture(scope='class')
def volume_image_form(request, kubevirt_api_version, admin_session,
harvester_api_endpoints, image):
request_json = utils.get_json_object_from_template(
'basic_volume',
size=8,
description='Test volume using Image Form'
)
imageid = "/".join([image['metadata']['namespace'],
image['metadata']['name']])
request_json['metadata']['annotations'][
'harvesterhci.io/imageId'] = imageid
resp = admin_session.post(harvester_api_endpoints.create_volume,
json=request_json)
assert resp.status_code == 201, 'Unable to create a blank volume'
volume_data = resp.json()
assert volume_data['metadata']['annotations'].get(
'harvesterhci.io/imageId') == imageid
yield volume_data
if not request.config.getoption('--do-not-cleanup'):
utils.delete_volume(request, admin_session,
harvester_api_endpoints, volume_data)
@pytest.fixture(scope='class')
def volume_with_image(request, kubevirt_api_version, admin_session,
harvester_api_endpoints, image):
request_json = utils.get_json_object_from_template(
'basic_volume',
size=8,
description='Test volume using Image & Label'
)
imageid = "/".join([image['metadata']['namespace'],
image['metadata']['name']])
request_json['metadata']['annotations'][
'harvesterhci.io/imageId'] = imageid
request_json['metadata']['labels'] = {
'test.harvesterhci.io': 'for-test'
}
resp = admin_session.post(harvester_api_endpoints.create_volume,
json=request_json)
assert resp.status_code == 201, 'Unable to create a blank volume'
volume_data = resp.json()
assert volume_data['metadata']['annotations'].get(
'harvesterhci.io/imageId') == imageid
assert volume_data['metadata']['labels'].get(
'test.harvesterhci.io') == 'for-test'
yield volume_data
if not request.config.getoption('--do-not-cleanup'):
utils.delete_volume(request, admin_session,
harvester_api_endpoints, volume_data)
@pytest.fixture(scope='class')
def volume_using_terraform(request, kubevirt_api_version, admin_session,
harvester_api_endpoints):
vol_data = utils.create_volume_terraform(request, admin_session,
harvester_api_endpoints,
'resource_volume',
10)
yield vol_data
if not request.config.getoption('--do-not-cleanup'):
utils.destroy_resource(
request,
admin_session, 'harvester_volume.' + vol_data['metadata']['name'])
@pytest.fixture(scope='class')
def volume_with_image_using_terraform(request, kubevirt_api_version,
admin_session, harvester_api_endpoints,
image_using_terraform):
image_name = image_using_terraform['metadata']['name']
vol_data = utils.create_volume_terraform(request, admin_session,
harvester_api_endpoints,
'resource_volume_image',
10, image_name)
imageid = "/".join([image_using_terraform['metadata']['namespace'],
image_name])
assert vol_data['metadata']['annotations'].get(
'harvesterhci.io/imageId') == imageid
yield vol_data
if not request.config.getoption('--do-not-cleanup'):
utils.destroy_resource(request, admin_session, 'all')