| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from tempest.lib.common.utils import data_utils |
| 14 |
from tempest.lib import decorators |
| 15 |
from tempest.lib import exceptions as lib_exc |
| 16 |
|
| 17 |
from ironic_tempest_plugin.tests.api.admin import api_microversion_fixture |
| 18 |
from ironic_tempest_plugin.tests.api import base |
| 19 |
|
| 20 |
|
| 21 |
class TestInspectionRulesNegative(base.BaseBaremetalTest): |
| 22 |
"""Negative Inspection Rules test""" |
| 23 |
|
| 24 |
# Inspection rules API was introduced in microversion 1.96 |
| 25 |
# We will be skipping this test for the older version. |
| 26 |
min_microversion = '1.96' |
| 27 |
|
| 28 |
def setUp(self): |
| 29 |
super(TestInspectionRulesNegative, self).setUp() |
| 30 |
|
| 31 |
_, self.node = self.create_node(None) |
| 32 |
|
| 33 |
self.useFixture( |
| 34 |
api_microversion_fixture.APIMicroversionFixture('1.96')) |
| 35 |
|
| 36 |
def _create_inspection_rule_payload(self, **kwargs): |
| 37 |
"""Create a Inspection rule payload.""" |
| 38 |
payload = { |
| 39 |
"description": "Inspection rule to log node UUID", |
| 40 |
"conditions": [], |
| 41 |
"actions": [ |
| 42 |
{ |
| 43 |
"op": "log", |
| 44 |
"args": { |
| 45 |
"msg": "Node with UUID {node.uuid} is being inspected" |
| 46 |
} |
| 47 |
} |
| 48 |
], |
| 49 |
"phase": "main", |
| 50 |
"priority": 0, |
| 51 |
"sensitive": False |
| 52 |
} |
| 53 |
|
| 54 |
payload.update(kwargs) |
| 55 |
|
| 56 |
return payload |
| 57 |
|
| 58 |
@decorators.idempotent_id('55403d94-53ce-41ab-989a-da3399314c9d') |
| 59 |
@decorators.attr(type=['negative']) |
| 60 |
def test_create_invalid_priority_fails(self): |
| 61 |
"""Test to create Inspection rule with invalid priorities""" |
| 62 |
invalid_priorities = [-1, 10000, 5000.50] |
| 63 |
|
| 64 |
for priority_val in invalid_priorities: |
| 65 |
payload = self._create_inspection_rule_payload( |
| 66 |
priority=priority_val) |
| 67 |
|
| 68 |
self.assertRaises(lib_exc.BadRequest, |
| 69 |
self.create_inspection_rule, |
| 70 |
rule_uuid=None, payload=payload) |
| 71 |
|
| 72 |
@decorators.idempotent_id('cf9615b3-904e-4456-b00a-622d39892b88') |
| 73 |
@decorators.attr(type=['negative']) |
| 74 |
def test_delete_by_wrong_uiid(self): |
| 75 |
"""Test to delete Inspection Rule with wrong uuid""" |
| 76 |
rule_uuid = data_utils.rand_uuid() |
| 77 |
self.assertRaises(lib_exc.NotFound, |
| 78 |
self.delete_inspection_rule, |
| 79 |
rule_uuid=rule_uuid) |