Debian Codegraph @

ironic_tempest_plugin/tests/api/admin/test_volume_target.py

raw
1 # Copyright 2017 FUJITSU LIMITED
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15
16 from tempest.lib.common.utils import data_utils
17 from tempest.lib import decorators
18 from tempest.lib import exceptions as lib_exc
19
20 from ironic_tempest_plugin.tests.api.admin import api_microversion_fixture
21 from ironic_tempest_plugin.tests.api import base
22
23
24 class TestVolumeTarget(base.BaseBaremetalTest):
25 """Basic test cases for volume target."""
26
27 min_microversion = '1.32'
28 extra = {'key1': 'value1', 'key2': 'value2'}
29
30 def setUp(self):
31 super(TestVolumeTarget, self).setUp()
32 self.useFixture(
33 api_microversion_fixture.APIMicroversionFixture(
34 self.min_microversion))
35 _, self.chassis = self.create_chassis()
36 _, self.node = self.create_node(self.chassis['uuid'])
37 _, self.volume_target = self.create_volume_target(
38 self.node['uuid'], volume_type=data_utils.rand_name('volume_type'),
39 volume_id=data_utils.rand_name('volume_id'),
40 boot_index=10,
41 extra=self.extra)
42
43 @decorators.attr(type=['negative'])
44 @decorators.idempotent_id('da5c27d4-68cc-499f-b8ab-3048b87d3bca')
45 def test_create_volume_target_error(self):
46 """Create a volume target.
47
48 Fail when creating a volume target with same boot index as the
49 existing volume target.
50 """
51 regex_str = (r'.*A volume target .*already exists')
52
53 self.assertRaisesRegex(
54 lib_exc.Conflict, regex_str,
55 self.create_volume_target,
56 self.node['uuid'],
57 volume_type=data_utils.rand_name('volume_type'),
58 volume_id=data_utils.rand_name('volume_id'),
59 boot_index=self.volume_target['boot_index'])
60
61 @decorators.idempotent_id('ea3a9b2e-8971-4830-9274-abaf0239f1ce')
62 def test_delete_volume_target(self):
63 """Delete a volume target."""
64 # Powering off the Node before deleting a volume target.
65 self.client.set_node_power_state(self.node['uuid'], 'power off')
66
67 self.delete_volume_target(self.volume_target['uuid'])
68 self.assertRaises(lib_exc.NotFound, self.client.show_volume_target,
69 self.volume_target['uuid'])
70
71 @decorators.attr(type=['negative'])
72 @decorators.idempotent_id('532a06bc-a9b2-44b0-828a-c53279c87cb2')
73 def test_delete_volume_target_error(self):
74 """Fail when deleting a volume target on node with power on state."""
75 # Powering on the Node before deleting a volume target.
76 self.client.set_node_power_state(self.node['uuid'], 'power on')
77
78 regex_str = (r'.*The requested action \\\\"volume target '
79 r'deletion\\\\" can not be performed on node*')
80
81 self.assertRaisesRegex(lib_exc.BadRequest,
82 regex_str,
83 self.delete_volume_target,
84 self.volume_target['uuid'])
85
86 @decorators.idempotent_id('a2598388-8f61-4b7e-944f-f37e4f60e1e2')
87 def test_show_volume_target(self):
88 """Show a specified volume target."""
89 _, volume_target = self.client.show_volume_target(
90 self.volume_target['uuid'])
91 self._assertExpected(self.volume_target, volume_target)
92
93 @decorators.idempotent_id('ae99a986-d93c-4324-9cdc-41d89e3a659f')
94 def test_list_volume_targets(self):
95 """List volume targets."""
96 _, body = self.client.list_volume_targets()
97 self.assertIn(self.volume_target['uuid'],
98 [i['uuid'] for i in body['targets']])
99 self.assertIn(self.volume_target['volume_type'],
100 [i['volume_type'] for i in body['targets']])
101 self.assertIn(self.volume_target['volume_id'],
102 [i['volume_id'] for i in body['targets']])
103
104 @decorators.idempotent_id('9da25447-0370-4b33-9c1f-d4503f5950ae')
105 def test_list_with_limit(self):
106 """List volume targets with limit."""
107 for i in range(2):
108 _, self.volume_target = self.create_volume_target(
109 self.node['uuid'],
110 volume_type=data_utils.rand_name('volume_type'),
111 volume_id=data_utils.rand_name('volume_id'),
112 boot_index=11 + i,
113 extra=self.extra)
114
115 _, body = self.client.list_volume_targets(limit=3)
116
117 next_marker = body['targets'][-1]['uuid']
118 self.assertIn(next_marker, body['next'])
119
120 @decorators.idempotent_id('8559cd08-feae-4f1a-a0ad-5bad8ea12b76')
121 def test_update_volume_target_replace(self):
122 """Update a volume target by replacing volume id."""
123 new_volume_id = data_utils.rand_name('volume_id')
124
125 patch = [{'path': '/volume_id',
126 'op': 'replace',
127 'value': new_volume_id}]
128
129 # Powering off the Node before updating a volume target.
130 self.client.set_node_power_state(self.node['uuid'], 'power off')
131
132 self.client.update_volume_target(self.volume_target['uuid'], patch)
133
134 _, body = self.client.show_volume_target(self.volume_target['uuid'])
135 self.assertEqual(new_volume_id, body['volume_id'])
136
137 @decorators.attr(type=['negative'])
138 @decorators.idempotent_id('fd5266d3-4f3c-4dce-9c87-bfdea2b756c7')
139 def test_update_volume_target_replace_error(self):
140 """Fail when updating a volume target on node with power on state."""
141 new_volume_id = data_utils.rand_name('volume_id')
142
143 patch = [{'path': '/volume_id',
144 'op': 'replace',
145 'value': new_volume_id}]
146
147 # Powering on the Node before updating a volume target.
148 self.client.set_node_power_state(self.node['uuid'], 'power on')
149
150 regex_str = (r'.*The requested action \\\\"volume target '
151 r'update\\\\" can not be performed on node*')
152
153 self.assertRaisesRegex(lib_exc.BadRequest,
154 regex_str,
155 self.client.update_volume_target,
156 self.volume_target['uuid'],
157 patch)
158
159 @decorators.idempotent_id('1c13a4ee-1a49-4739-8c19-77960fbd1af8')
160 def test_update_volume_target_remove_item(self):
161 """Update a volume target by removing one item from the collection."""
162 new_extra = {'key1': 'value1'}
163 _, body = self.client.show_volume_target(self.volume_target['uuid'])
164 volume_id = body['volume_id']
165 volume_type = body['volume_type']
166
167 # Powering off the Node before updating a volume target.
168 self.client.set_node_power_state(self.node['uuid'], 'power off')
169
170 # Removing one item from the collection
171 self.client.update_volume_target(self.volume_target['uuid'],
172 [{'path': '/extra/key2',
173 'op': 'remove'}])
174
175 _, body = self.client.show_volume_target(self.volume_target['uuid'])
176 self.assertEqual(new_extra, body['extra'])
177
178 # Assert nothing else was changed
179 self.assertEqual(volume_id, body['volume_id'])
180 self.assertEqual(volume_type, body['volume_type'])
181
182 @decorators.idempotent_id('6784ddb0-9144-41ea-b8a0-f888ad5c5b62')
183 def test_update_volume_target_remove_collection(self):
184 """Update a volume target by removing the collection."""
185 _, body = self.client.show_volume_target(self.volume_target['uuid'])
186 volume_id = body['volume_id']
187 volume_type = body['volume_type']
188
189 # Powering off the Node before updating a volume target.
190 self.client.set_node_power_state(self.node['uuid'], 'power off')
191
192 # Removing the collection
193 self.client.update_volume_target(self.volume_target['uuid'],
194 [{'path': '/extra',
195 'op': 'remove'}])
196 _, body = self.client.show_volume_target(self.volume_target['uuid'])
197 self.assertEqual({}, body['extra'])
198
199 # Assert nothing else was changed
200 self.assertEqual(volume_id, body['volume_id'])
201 self.assertEqual(volume_type, body['volume_type'])
202
203 @decorators.idempotent_id('9629715d-57ba-423b-b985-232674cc3a25')
204 def test_update_volume_target_add(self):
205 """Update a volume target by adding to the collection."""
206 new_extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
207
208 patch = [{'path': '/extra/key3',
209 'op': 'add',
210 'value': new_extra['key3']}]
211
212 # Powering off the Node before updating a volume target.
213 self.client.set_node_power_state(self.node['uuid'], 'power off')
214
215 self.client.update_volume_target(self.volume_target['uuid'], patch)
216
217 _, body = self.client.show_volume_target(self.volume_target['uuid'])
218 self.assertEqual(new_extra, body['extra'])