| 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 TestVolumeConnector(base.BaseBaremetalTest): |
| 25 |
"""Basic test cases for volume connector.""" |
| 26 |
|
| 27 |
min_microversion = '1.32' |
| 28 |
extra = {'key1': 'value1', 'key2': 'value2'} |
| 29 |
|
| 30 |
def setUp(self): |
| 31 |
super(TestVolumeConnector, 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_connector = self.create_volume_connector( |
| 38 |
self.node['uuid'], type='iqn', |
| 39 |
connector_id=data_utils.rand_name('connector_id'), |
| 40 |
extra=self.extra) |
| 41 |
|
| 42 |
@decorators.attr(type=['negative']) |
| 43 |
@decorators.idempotent_id('3c3cbf45-488a-4386-a811-bf0aa2589c58') |
| 44 |
def test_create_volume_connector_error(self): |
| 45 |
"""Create a volume connector. |
| 46 |
|
| 47 |
Fail when creating a volume connector with same connector_id |
| 48 |
& type as an existing volume connector. |
| 49 |
""" |
| 50 |
regex_str = (r'.*A volume connector .*already exists') |
| 51 |
|
| 52 |
self.assertRaisesRegex( |
| 53 |
lib_exc.Conflict, regex_str, |
| 54 |
self.create_volume_connector, |
| 55 |
self.node['uuid'], |
| 56 |
type=self.volume_connector['type'], |
| 57 |
connector_id=self.volume_connector['connector_id']) |
| 58 |
|
| 59 |
@decorators.idempotent_id('5795f816-0789-42e6-bb9c-91b4876ad13f') |
| 60 |
def test_delete_volume_connector(self): |
| 61 |
"""Delete a volume connector.""" |
| 62 |
# Powering off the Node before deleting a volume connector. |
| 63 |
self.client.set_node_power_state(self.node['uuid'], 'power off') |
| 64 |
|
| 65 |
self.delete_volume_connector(self.volume_connector['uuid']) |
| 66 |
self.assertRaises(lib_exc.NotFound, self.client.show_volume_connector, |
| 67 |
self.volume_connector['uuid']) |
| 68 |
|
| 69 |
@decorators.attr(type=['negative']) |
| 70 |
@decorators.idempotent_id('ccbda5e6-52b7-400c-94d7-25eec1d590f0') |
| 71 |
def test_delete_volume_connector_error(self): |
| 72 |
"""Delete a volume connector |
| 73 |
|
| 74 |
Fail when deleting a volume connector on node |
| 75 |
with powered on state. |
| 76 |
""" |
| 77 |
|
| 78 |
# Powering on the Node before deleting a volume connector. |
| 79 |
self.client.set_node_power_state(self.node['uuid'], 'power on') |
| 80 |
|
| 81 |
regex_str = (r'.*The requested action \\\\"volume connector ' |
| 82 |
r'deletion\\\\" can not be performed on node*') |
| 83 |
|
| 84 |
self.assertRaisesRegex(lib_exc.BadRequest, |
| 85 |
regex_str, |
| 86 |
self.delete_volume_connector, |
| 87 |
self.volume_connector['uuid']) |
| 88 |
|
| 89 |
@decorators.idempotent_id('6e4f50b7-0f4f-41c2-971e-d751abcac4e0') |
| 90 |
def test_show_volume_connector(self): |
| 91 |
"""Show a specified volume connector.""" |
| 92 |
_, volume_connector = self.client.show_volume_connector( |
| 93 |
self.volume_connector['uuid']) |
| 94 |
self._assertExpected(self.volume_connector, volume_connector) |
| 95 |
|
| 96 |
@decorators.idempotent_id('a4725778-e164-4ee5-96a0-66119a35f783') |
| 97 |
def test_list_volume_connectors(self): |
| 98 |
"""List volume connectors.""" |
| 99 |
_, body = self.client.list_volume_connectors() |
| 100 |
self.assertIn(self.volume_connector['uuid'], |
| 101 |
[i['uuid'] for i in body['connectors']]) |
| 102 |
self.assertIn(self.volume_connector['type'], |
| 103 |
[i['type'] for i in body['connectors']]) |
| 104 |
self.assertIn(self.volume_connector['connector_id'], |
| 105 |
[i['connector_id'] for i in body['connectors']]) |
| 106 |
|
| 107 |
@decorators.idempotent_id('1d0459ad-01c0-46db-b930-7301bc2a3c98') |
| 108 |
def test_list_with_limit(self): |
| 109 |
"""List volume connectors with limit.""" |
| 110 |
for i in range(2): |
| 111 |
_, self.volume_connector = self.create_volume_connector( |
| 112 |
self.node['uuid'], type='iqn', |
| 113 |
connector_id=data_utils.rand_name('connector_id'), |
| 114 |
extra=self.extra) |
| 115 |
|
| 116 |
_, body = self.client.list_volume_connectors(limit=3) |
| 117 |
|
| 118 |
next_marker = body['connectors'][-1]['uuid'] |
| 119 |
self.assertIn(next_marker, body['next']) |
| 120 |
|
| 121 |
@decorators.idempotent_id('3c6f8354-e9bd-4f21-aae2-6deb96b04be7') |
| 122 |
def test_update_volume_connector_replace(self): |
| 123 |
"""Update a volume connector with new connector id.""" |
| 124 |
new_connector_id = data_utils.rand_name('connector_id') |
| 125 |
|
| 126 |
patch = [{'path': '/connector_id', |
| 127 |
'op': 'replace', |
| 128 |
'value': new_connector_id}] |
| 129 |
|
| 130 |
# Powering off the Node before updating a volume connector. |
| 131 |
self.client.set_node_power_state(self.node['uuid'], 'power off') |
| 132 |
|
| 133 |
self.client.update_volume_connector( |
| 134 |
self.volume_connector['uuid'], patch) |
| 135 |
|
| 136 |
_, body = self.client.show_volume_connector( |
| 137 |
self.volume_connector['uuid']) |
| 138 |
self.assertEqual(new_connector_id, body['connector_id']) |
| 139 |
|
| 140 |
@decorators.attr(type=['negative']) |
| 141 |
@decorators.idempotent_id('5af8dc7a-9965-4787-8184-e60aeaf30957') |
| 142 |
def test_update_volume_connector_replace_error(self): |
| 143 |
"""Updating a volume connector. |
| 144 |
|
| 145 |
Fail when updating a volume connector on node |
| 146 |
with power on state. |
| 147 |
""" |
| 148 |
|
| 149 |
new_connector_id = data_utils.rand_name('connector_id') |
| 150 |
|
| 151 |
patch = [{'path': '/connector_id', |
| 152 |
'op': 'replace', |
| 153 |
'value': new_connector_id}] |
| 154 |
|
| 155 |
# Powering on the Node before updating a volume connector. |
| 156 |
self.client.set_node_power_state(self.node['uuid'], 'power on') |
| 157 |
|
| 158 |
regex_str = (r'.*The requested action \\\\"volume connector ' |
| 159 |
r'update\\\\" can not be performed on node*') |
| 160 |
self.assertRaisesRegex(lib_exc.BadRequest, |
| 161 |
regex_str, |
| 162 |
self.client.update_volume_connector, |
| 163 |
self.volume_connector['uuid'], |
| 164 |
patch) |
| 165 |
|
| 166 |
@decorators.idempotent_id('b95c75eb-4048-482e-99ff-fe1d32538383') |
| 167 |
def test_update_volume_connector_remove_item(self): |
| 168 |
"""Update a volume connector by removing one item from collection.""" |
| 169 |
new_extra = {'key1': 'value1'} |
| 170 |
_, body = self.client.show_volume_connector( |
| 171 |
self.volume_connector['uuid']) |
| 172 |
connector_id = body['connector_id'] |
| 173 |
connector_type = body['type'] |
| 174 |
|
| 175 |
# Powering off the Node before updating a volume connector. |
| 176 |
self.client.set_node_power_state(self.node['uuid'], 'power off') |
| 177 |
|
| 178 |
# Removing one item from the collection |
| 179 |
self.client.update_volume_connector(self.volume_connector['uuid'], |
| 180 |
[{'path': '/extra/key2', |
| 181 |
'op': 'remove'}]) |
| 182 |
_, body = self.client.show_volume_connector( |
| 183 |
self.volume_connector['uuid']) |
| 184 |
self.assertEqual(new_extra, body['extra']) |
| 185 |
|
| 186 |
# Assert nothing else was changed |
| 187 |
self.assertEqual(connector_id, body['connector_id']) |
| 188 |
self.assertEqual(connector_type, body['type']) |
| 189 |
|
| 190 |
@decorators.idempotent_id('8de03acd-532a-476f-8bc9-0e8b23bfe609') |
| 191 |
def test_update_volume_connector_remove_collection(self): |
| 192 |
"""Update a volume connector by removing collection.""" |
| 193 |
_, body = self.client.show_volume_connector( |
| 194 |
self.volume_connector['uuid']) |
| 195 |
connector_id = body['connector_id'] |
| 196 |
connector_type = body['type'] |
| 197 |
|
| 198 |
# Powering off the Node before updating a volume connector. |
| 199 |
self.client.set_node_power_state(self.node['uuid'], 'power off') |
| 200 |
|
| 201 |
# Removing the collection |
| 202 |
self.client.update_volume_connector(self.volume_connector['uuid'], |
| 203 |
[{'path': '/extra', |
| 204 |
'op': 'remove'}]) |
| 205 |
_, body = self.client.show_volume_connector( |
| 206 |
self.volume_connector['uuid']) |
| 207 |
self.assertEqual({}, body['extra']) |
| 208 |
|
| 209 |
# Assert nothing else was changed |
| 210 |
self.assertEqual(connector_id, body['connector_id']) |
| 211 |
self.assertEqual(connector_type, body['type']) |
| 212 |
|
| 213 |
@decorators.idempotent_id('bfb0ca6b-086d-4663-9b25-e0eaf42da55b') |
| 214 |
def test_update_volume_connector_add(self): |
| 215 |
"""Update a volume connector by adding one item to collection.""" |
| 216 |
new_extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'} |
| 217 |
|
| 218 |
patch = [{'path': '/extra/key3', |
| 219 |
'op': 'add', |
| 220 |
'value': new_extra['key3']}, |
| 221 |
{'path': '/extra/key3', |
| 222 |
'op': 'add', |
| 223 |
'value': new_extra['key3']}] |
| 224 |
|
| 225 |
# Powering off the Node before updating a volume connector. |
| 226 |
self.client.set_node_power_state(self.node['uuid'], 'power off') |
| 227 |
|
| 228 |
self.client.update_volume_connector( |
| 229 |
self.volume_connector['uuid'], patch) |
| 230 |
|
| 231 |
_, body = self.client.show_volume_connector( |
| 232 |
self.volume_connector['uuid']) |
| 233 |
self.assertEqual(new_extra, body['extra']) |