Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 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 | |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 13 | from tempest import clients |
| 14 | from tempest.common import credentials_factory as common_creds |
| 15 | from tempest import config |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 16 | |
Riccardo Pittau | 1609869 | 2020-04-21 17:06:10 +0200 | [diff] [blame] | 17 | from ironic_tempest_plugin.services.baremetal import base |
| 18 | |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 19 | |
| 20 | CONF = config.CONF |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class Manager(clients.Manager): |
| 24 | def __init__(self, |
Masayuki Igawa | 51266a5 | 2019-02-04 17:13:56 +0900 | [diff] [blame] | 25 | credentials=None, |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 26 | api_microversions=None): |
Masayuki Igawa | 51266a5 | 2019-02-04 17:13:56 +0900 | [diff] [blame] | 27 | if not credentials: |
| 28 | credentials = common_creds.get_configured_admin_credentials() |
Dmitry Tantsur | f00d68d | 2017-01-05 12:08:39 +0100 | [diff] [blame] | 29 | super(Manager, self).__init__(credentials) |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 30 | self.introspection_client = BaremetalIntrospectionClient( |
| 31 | self.auth_provider, |
| 32 | CONF.baremetal_introspection.catalog_type, |
| 33 | CONF.identity.region, |
Jim Rollenhagen | 1611df8 | 2016-12-07 10:31:43 -0500 | [diff] [blame] | 34 | endpoint_type=CONF.baremetal_introspection.endpoint_type) |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 35 | |
| 36 | |
| 37 | class BaremetalIntrospectionClient(base.BaremetalClient): |
| 38 | """Base Tempest REST client for Ironic Inspector API v1.""" |
| 39 | version = '1' |
| 40 | uri_prefix = 'v1' |
| 41 | |
| 42 | @base.handle_errors |
| 43 | def purge_rules(self): |
| 44 | """Purge all existing rules.""" |
| 45 | return self._delete_request('rules', uuid=None) |
| 46 | |
| 47 | @base.handle_errors |
Anton Arefiev | 6b00356 | 2016-09-13 12:17:29 +0300 | [diff] [blame] | 48 | def create_rules(self, rules): |
| 49 | """Create introspection rules.""" |
| 50 | if not isinstance(rules, list): |
| 51 | rules = [rules] |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 52 | for rule in rules: |
| 53 | self._create_request('rules', rule) |
| 54 | |
| 55 | @base.handle_errors |
| 56 | def get_status(self, uuid): |
| 57 | """Get introspection status for a node.""" |
| 58 | return self._show_request('introspection', uuid=uuid) |
| 59 | |
| 60 | @base.handle_errors |
| 61 | def get_data(self, uuid): |
| 62 | """Get introspection data for a node.""" |
| 63 | return self._show_request('introspection', uuid=uuid, |
| 64 | uri='/%s/introspection/%s/data' % |
| 65 | (self.uri_prefix, uuid)) |
Anton Arefiev | 6b00356 | 2016-09-13 12:17:29 +0300 | [diff] [blame] | 66 | |
| 67 | @base.handle_errors |
| 68 | def start_introspection(self, uuid): |
| 69 | """Start introspection for a node.""" |
| 70 | resp, _body = self.post(url=('/%s/introspection/%s' % |
| 71 | (self.uri_prefix, uuid)), |
| 72 | body=None) |
| 73 | self.expected_success(202, resp.status) |
| 74 | |
| 75 | return resp |
Sergii Nozhka | 1eb13cf | 2016-11-04 17:15:50 +0200 | [diff] [blame] | 76 | |
| 77 | @base.handle_errors |
| 78 | def abort_introspection(self, uuid): |
| 79 | """Abort introspection for a node.""" |
| 80 | resp, _body = self.post(url=('/%s/introspection/%s/abort' % |
| 81 | (self.uri_prefix, uuid)), |
| 82 | body=None) |
| 83 | self.expected_success(202, resp.status) |
| 84 | |
| 85 | return resp |