|
| 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 | +import ast |
| 14 | +import json |
| 15 | + |
| 16 | +from tempest.lib.common.utils import data_utils |
| 17 | + |
| 18 | +from openstackclient.tests.functional.identity.v3 import common |
| 19 | + |
| 20 | + |
| 21 | +class AccessRuleTests(common.IdentityTests): |
| 22 | + ACCESS_RULE_FIELDS = [ |
| 23 | + 'id', |
| 24 | + 'service', |
| 25 | + 'method', |
| 26 | + 'path', |
| 27 | + ] |
| 28 | + ACCESS_RULE_LIST_HEADERS = [ |
| 29 | + 'ID', |
| 30 | + 'Service', |
| 31 | + 'Method', |
| 32 | + 'Path', |
| 33 | + ] |
| 34 | + |
| 35 | + def setUp(self): |
| 36 | + super().setUp() |
| 37 | + |
| 38 | + application_credential_name = data_utils.rand_name('name') |
| 39 | + access_rules = json.dumps( |
| 40 | + [ |
| 41 | + { |
| 42 | + 'method': 'GET', |
| 43 | + 'path': '/v2.1/servers', |
| 44 | + 'service': 'compute', |
| 45 | + }, |
| 46 | + { |
| 47 | + 'method': 'GET', |
| 48 | + 'path': '/v2.0/networks', |
| 49 | + 'service': 'networking', |
| 50 | + }, |
| 51 | + ] |
| 52 | + ) |
| 53 | + raw_output = self.openstack( |
| 54 | + f"application credential create {application_credential_name} " |
| 55 | + f"--access-rules '{access_rules}'" |
| 56 | + ) |
| 57 | + # we immediately delete the application credential since it will leave |
| 58 | + # the access rules around |
| 59 | + self.openstack( |
| 60 | + f'application credential delete {application_credential_name}' |
| 61 | + ) |
| 62 | + |
| 63 | + items = self.parse_show_as_object(raw_output) |
| 64 | + self.access_rule_ids = [ |
| 65 | + x['id'] for x in ast.literal_eval(items['access_rules']) |
| 66 | + ] |
| 67 | + self.addCleanup( |
| 68 | + self.openstack, |
| 69 | + 'access rule delete ' |
| 70 | + + ' '.join([x for x in self.access_rule_ids]), |
| 71 | + ) |
| 72 | + |
| 73 | + def test_access_rule(self): |
| 74 | + # list |
| 75 | + |
| 76 | + raw_output = self.openstack('access rule list') |
| 77 | + items = self.parse_listing(raw_output) |
| 78 | + self.assert_table_structure(items, self.ACCESS_RULE_LIST_HEADERS) |
| 79 | + |
| 80 | + # show |
| 81 | + |
| 82 | + raw_output = self.openstack( |
| 83 | + f'access rule show {self.access_rule_ids[0]}' |
| 84 | + ) |
| 85 | + items = self.parse_show(raw_output) |
| 86 | + self.assert_show_fields(items, self.ACCESS_RULE_FIELDS) |
0 commit comments