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