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 | |
| 13 | import json |
| 14 | |
Anton Arefiev | d5998c0 | 2016-06-09 17:57:09 +0300 | [diff] [blame] | 15 | from ironic_tempest_plugin.services.baremetal import base |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 16 | from tempest import clients |
| 17 | from tempest.common import credentials_factory as common_creds |
| 18 | from tempest import config |
Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 19 | |
| 20 | |
| 21 | CONF = config.CONF |
| 22 | ADMIN_CREDS = common_creds.get_configured_admin_credentials() |
| 23 | |
| 24 | |
| 25 | class Manager(clients.Manager): |
| 26 | def __init__(self, |
| 27 | credentials=ADMIN_CREDS, |
| 28 | service=None, |
| 29 | api_microversions=None): |
| 30 | super(Manager, self).__init__(credentials, service) |
| 31 | self.introspection_client = BaremetalIntrospectionClient( |
| 32 | self.auth_provider, |
| 33 | CONF.baremetal_introspection.catalog_type, |
| 34 | CONF.identity.region, |
| 35 | endpoint_type=CONF.baremetal_introspection.endpoint_type, |
| 36 | **self.default_params_with_timeout_values) |
| 37 | |
| 38 | |
| 39 | class BaremetalIntrospectionClient(base.BaremetalClient): |
| 40 | """Base Tempest REST client for Ironic Inspector API v1.""" |
| 41 | version = '1' |
| 42 | uri_prefix = 'v1' |
| 43 | |
| 44 | @base.handle_errors |
| 45 | def purge_rules(self): |
| 46 | """Purge all existing rules.""" |
| 47 | return self._delete_request('rules', uuid=None) |
| 48 | |
| 49 | @base.handle_errors |
| 50 | def import_rule(self, rule_path): |
| 51 | """Import introspection rules from a json file.""" |
| 52 | with open(rule_path, 'r') as fp: |
| 53 | rules = json.load(fp) |
| 54 | if not isinstance(rules, list): |
| 55 | rules = [rules] |
| 56 | |
| 57 | for rule in rules: |
| 58 | self._create_request('rules', rule) |
| 59 | |
| 60 | @base.handle_errors |
| 61 | def get_status(self, uuid): |
| 62 | """Get introspection status for a node.""" |
| 63 | return self._show_request('introspection', uuid=uuid) |
| 64 | |
| 65 | @base.handle_errors |
| 66 | def get_data(self, uuid): |
| 67 | """Get introspection data for a node.""" |
| 68 | return self._show_request('introspection', uuid=uuid, |
| 69 | uri='/%s/introspection/%s/data' % |
| 70 | (self.uri_prefix, uuid)) |