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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
|
# Copyright 2016 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from tempest.lib import decorators
from tempest.lib import exceptions
import testtools
from mistral_tempest_tests.tests import base
from mistral_tempest_tests.tests import utils
class ActionTestsV2(base.TestCase):
_service = 'workflowv2'
@staticmethod
def get_field_value(body, act_name, field):
return [body['actions'][i][field]
for i in range(len(body['actions']))
if body['actions'][i]['name'] == act_name][0]
def tearDown(self):
for act in self.client.actions:
self.client.delete_obj('actions', act)
self.client.actions = []
super(ActionTestsV2, self).tearDown()
@decorators.attr(type='smoke')
@decorators.idempotent_id('2e1a578a-1c27-409a-96be-84b5c41498cd')
def test_get_list_actions(self):
resp, body = self.client.get_list_obj('actions')
self.assertEqual(200, resp.status)
self.assertNotEmpty(body['actions'])
self.assertNotIn('next', body)
# TODO(rakhmerov): Fix pagination.
@testtools.skip('Fix pagination of the /actions endpoint')
@decorators.attr(type='smoke')
@decorators.idempotent_id('786ee85c-c32d-4ac9-8f45-79ab6bc47ef1')
def test_get_list_actions_with_pagination(self):
resp, body = self.client.get_list_obj(
'actions?limit=1&sort_keys=name&sort_dirs=desc'
)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body['actions']))
self.assertIn('next', body)
name_1 = body['actions'][0].get('name')
next_ = body.get('next')
param_dict = utils.get_dict_from_string(
next_.split('?')[1],
delimiter='&'
)
# NOTE: 'id' gets included into sort keys automatically with 'desc'
# sorting to avoid pagination looping.
expected_sub_dict = {
'limit': 1,
'sort_keys': 'name,id',
'sort_dirs': 'desc,asc'
}
self.assertEqual(param_dict, param_dict | expected_sub_dict)
# Query again using 'next' hint
url_param = next_.split('/')[-1]
resp, body = self.client.get_list_obj(url_param)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body['actions']))
name_2 = body['actions'][0].get('name')
self.assertGreater(name_1, name_2)
@decorators.attr(type='negative')
@decorators.idempotent_id('5148358e-200f-49c7-8e88-1ddeec61c6a9')
def test_get_list_actions_nonexist_sort_dirs(self):
context = self.assertRaises(
exceptions.BadRequest,
self.client.get_list_obj,
'actions?limit=1&sort_keys=id&sort_dirs=nonexist'
)
self.assertIn(
'Unknown sort direction',
context.resp_body.get('faultstring')
)
@decorators.attr(type='negative')
@decorators.idempotent_id('85482ce8-70f4-47a6-9e80-de1ac22b6412')
def test_get_list_actions_invalid_limit(self):
context = self.assertRaises(
exceptions.BadRequest,
self.client.get_list_obj,
'actions?limit=-1&sort_keys=id&sort_dirs=asc'
)
self.assertIn(
'Limit must be positive',
context.resp_body.get('faultstring')
)
@decorators.attr(type='negative')
@decorators.idempotent_id('a203e75b-2013-422f-b9eb-da4375041058')
def test_get_list_actions_duplicate_sort_keys(self):
context = self.assertRaises(
exceptions.BadRequest,
self.client.get_list_obj,
'actions?limit=1&sort_keys=id,id&sort_dirs=asc,asc'
)
self.assertIn(
'Length of sort_keys must be equal or greater than sort_dirs',
context.resp_body.get('faultstring')
)
@decorators.attr(type='smoke')
@decorators.idempotent_id('9a53af71-8f1e-4ad5-b572-2c4c621715c0')
def test_get_list_actions_equal_to_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
resp, body = self.client.get_list_obj('actions?name=greeting')
self.assertEqual(200, resp.status)
self.assertNotEmpty(body['actions'])
self.assertEqual(1, len(body['actions']))
self.assertEqual('greeting', body['actions'][0]['name'])
@decorators.attr(type='smoke')
@decorators.idempotent_id('3c3d28ce-9490-41ae-a918-c28f843841e1')
def test_get_list_actions_not_equal_to_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
resp, body = self.client.get_list_obj('actions?name=neq:greeting')
self.assertEqual(200, resp.status)
self.assertNotEmpty(body['actions'])
self.assertGreater(len(body['actions']), 0)
for act in body['actions']:
self.assertNotEqual('greeting', act['name'])
@decorators.attr(type='smoke')
@decorators.idempotent_id('84823a84-5caa-427d-8a2c-622a1d1893b1')
def test_get_list_actions_in_list_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
resp, body = self.client.get_list_obj(
'actions?name=in:greeting,std.echo'
)
self.assertEqual(200, resp.status)
self.assertEqual(2, len(body['actions']))
for act in body['actions']:
self.assertIn(act['name'], ['greeting', 'std.echo'])
@decorators.attr(type='smoke')
@decorators.idempotent_id('4b05dfcf-ef39-4032-9528-c8422c7329dd')
def test_get_list_actions_not_in_list_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
resp, body = self.client.get_list_obj(
'actions?name=nin:greeting,std.echo'
)
self.assertEqual(200, resp.status)
self.assertGreater(len(body['actions']), 0)
for act in body['actions']:
self.assertNotIn(act['name'], ['greeting', 'std.echo'])
@decorators.attr(type='smoke')
@decorators.idempotent_id('20b3d527-447d-492b-8cb7-ac5e3757d7d5')
def test_get_list_actions_greater_than_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
# NOTE(rakhmerov): The filter "name=gt:freeting" might seem weird
# but we can use it because Mistral compare alphabetical order
# of action names with filter value.
resp, body = self.client.get_list_obj('actions?name=gt:freeting')
self.assertEqual(200, resp.status)
# There should be at least "greeting" action in the result set
# and possible some other standard actions whose names go after
# "freeting" in the alphabet order.
self.assertGreater(len(body['actions']), 0)
# Make sure the "greeting" action is in the result set.
self.assertEqual(
1,
len([act for act in body['actions'] if act['name'] == 'greeting'])
)
# TODO(rakhmerov): Come up with a good test, we can't use 'created_at'
# anymore.
@testtools.skip('Come up with a good test')
@decorators.attr(type='smoke')
@decorators.idempotent_id('7f598dba-f169-47ec-a487-f0ed31484aff')
def test_get_list_actions_greater_than_equal_to_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
created_acts = [action['name'] for action in body['actions']]
_, body = self.client.get_object('actions', created_acts[0])
time = body['created_at']
resp, body = self.client.get_list_obj(
'actions?created_at=gte:' + time.replace(' ', '%20')
)
actions = [action['name'] for action in body['actions']]
self.assertEqual(200, resp.status)
self.assertIn(created_acts[0], actions)
# TODO(rakhmerov): Come up with a good test, we can't use 'created_at'
# anymore.
@testtools.skip('Come up with a good test')
@decorators.attr(type='smoke')
@decorators.idempotent_id('874fb57d-a762-4dc3-841d-396657510d23')
def test_get_list_actions_less_than_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
created_acts = [action['name'] for action in body['actions']]
_, body = self.client.get_object('actions', created_acts[0])
time = body['created_at']
resp, body = self.client.get_list_obj(
'actions?created_at=lt:' + time.replace(' ', '%20')
)
actions = [action['name'] for action in body['actions']]
self.assertEqual(200, resp.status)
self.assertNotIn(created_acts[0], actions)
# TODO(rakhmerov): Come up with a good test, we can't use 'created_at'
# anymore.
@testtools.skip('Come up with a good test')
@decorators.attr(type='smoke')
@decorators.idempotent_id('1fda6c31-b0c3-4b78-9f67-b920e1f6c973')
def test_get_list_actions_less_than_equal_to_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
created_acts = [action['name'] for action in body['actions']]
_, body = self.client.get_object('actions', created_acts[0])
time = body['created_at']
resp, body = self.client.get_list_obj(
'actions?created_at=lte:' + time.replace(' ', '%20')
)
actions = [action['name'] for action in body['actions']]
self.assertEqual(200, resp.status)
self.assertIn(created_acts[0], actions)
@decorators.attr(type='smoke')
@decorators.idempotent_id('cbb716f1-7fc7-4884-8fa9-6ff2bc35ee29')
def test_get_list_actions_multiple_filter(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
# TODO(rakhmerov): Both filters are temporarily related to the
# field 'name', there's no other suitable field right now to
# to apply a filter to. We could use "&tags=has:hello", for
# example, but it will work only after the Action Provider
# transition is completed, now this filter is broken.
resp, body = self.client.get_list_obj(
'actions?name=in:greeting,farewell&name=greeting'
)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body['actions']))
self.assertEqual('greeting', body['actions'][0]['name'])
@decorators.attr(type='negative')
@decorators.idempotent_id('45fdc1f3-4d89-4035-9b76-08ef94c92628')
def test_get_list_actions_invalid_filter(self):
self.assertRaises(
exceptions.BadRequest,
self.client.get_list_obj,
'actions?is_system<False'
)
self.assertRaises(
exceptions.BadRequest,
self.client.get_list_obj,
'actions?is_system!=False'
)
self.assertRaises(
exceptions.BadRequest,
self.client.get_list_obj,
'actions?created_at>2016-02-23%2008:51:26'
)
@decorators.attr(type='sanity')
@decorators.idempotent_id('5dbceaf3-6a32-4a4f-9427-1bbdb6f3c574')
def test_create_and_delete_few_actions(self):
resp, body = self.client.create_action('action_v2.yaml')
self.assertEqual(201, resp.status)
created_acts = [action['name'] for action in body['actions']]
resp, body = self.client.get_list_obj('actions')
self.assertEqual(200, resp.status)
actions = [action['name'] for action in body['actions']]
for act in created_acts:
self.assertIn(act, actions)
self.client.delete_obj('actions', act)
_, body = self.client.get_list_obj('actions')
actions = [action['name'] for action in body['actions']]
for act in created_acts:
self.assertNotIn(act, actions)
self.client.actions.remove(act)
@decorators.attr(type='sanity')
@decorators.idempotent_id('d7dad5de-6b1f-4813-b789-78f075252639')
def test_get_action(self):
_, body = self.client.create_action('action_v2.yaml')
action_name = body['actions'][0]['name']
resp, body = self.client.get_object('actions', action_name)
self.assertEqual(200, resp.status)
self.assertEqual(action_name, body['name'])
@decorators.attr(type='sanity')
@decorators.idempotent_id('21a031c8-8e2d-421f-8dfe-71a3b5e44381')
def test_update_action(self):
_, body = self.client.create_action('action_v2.yaml')
action = body['actions'][0]['name']
act_created_at = self.get_field_value(
body=body, act_name=action, field='created_at')
self.assertNotIn('updated at', body['actions'])
resp, body = self.client.update_request('actions', 'action_v2.yaml')
self.assertEqual(200, resp.status)
actions = [act['name'] for act in body['actions']]
self.assertIn(action, actions)
updated_act_created_at = self.get_field_value(
body=body, act_name=action, field='created_at')
self.assertEqual(act_created_at.split(".")[0], updated_act_created_at)
self.assertTrue(all(['updated_at' in item
for item in body['actions']]))
@decorators.attr(type='sanity')
@decorators.idempotent_id('329b1030-c55c-45f0-8129-cc892bc23dcc')
def test_get_action_definition(self):
_, body = self.client.create_action('action_v2.yaml')
act_name = body['actions'][0]['name']
resp, body = self.client.get_definition('actions', act_name)
self.assertEqual(200, resp.status)
self.assertIsNotNone(body)
self.assertIn(act_name, body)
@decorators.attr(type='negative')
@decorators.idempotent_id('c2b5be88-571a-4855-922f-9a338dba6adb')
def test_get_nonexistent_action(self):
self.assertRaises(
exceptions.NotFound,
self.client.get_object,
'actions', 'nonexist'
)
@decorators.attr(type='negative')
@decorators.idempotent_id('fc2fafcb-9bb4-4a18-a507-3f9964f4a08a')
def test_double_creation(self):
self.client.create_action('action_v2.yaml')
self.assertRaises(
exceptions.Conflict,
self.client.create_action,
'action_v2.yaml'
)
@decorators.attr(type='negative')
@decorators.idempotent_id('0c456a73-9c39-4aeb-b3ca-3ea4338bc9ab')
def test_create_action_invalid_def(self):
self.assertRaises(
exceptions.BadRequest,
self.client.create_action,
'wb_v2.yaml'
)
@decorators.attr(type='negative')
@decorators.idempotent_id('469677b5-22ab-4e2a-aee6-5bcc9dac93de')
def test_update_action_invalid_def(self):
self.assertRaises(
exceptions.BadRequest,
self.client.update_request,
'actions',
'wb_v2.yaml'
)
@decorators.attr(type='negative')
@decorators.idempotent_id('ab444607-40fc-47cb-982f-83762d5b64c9')
def test_delete_nonexistent_action(self):
self.assertRaises(
exceptions.NotFound,
self.client.delete_obj,
'actions',
'nonexist'
)
# TODO(rakhmerov): Rewrite it after https://review.opendev.org/#/c/746022/
# is merged.
@testtools.skip('Needs to be rewritten.')
@decorators.attr(type='negative')
@decorators.idempotent_id('74d0d480-793a-46ca-b88a-8336c1897f3a')
def test_delete_standard_action(self):
self.assertRaises(
exceptions.BadRequest,
self.client.delete_obj,
'actions',
'nova.servers_create'
)
|