blob: f82aed6ac6a153b5b621b51450585e29bdef4d86 [file] [log] [blame]
Anton Arefiev44f678c2016-03-17 12:11:30 +02001# 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 Arefievd5998c02016-06-09 17:57:09 +030013from ironic_tempest_plugin.services.baremetal import base
Anton Arefiev44f678c2016-03-17 12:11:30 +020014from tempest import clients
15from tempest.common import credentials_factory as common_creds
16from tempest import config
Anton Arefiev44f678c2016-03-17 12:11:30 +020017
18
19CONF = config.CONF
Anton Arefiev44f678c2016-03-17 12:11:30 +020020
21
22class Manager(clients.Manager):
23 def __init__(self,
Masayuki Igawa51266a52019-02-04 17:13:56 +090024 credentials=None,
Anton Arefiev44f678c2016-03-17 12:11:30 +020025 api_microversions=None):
Masayuki Igawa51266a52019-02-04 17:13:56 +090026 if not credentials:
27 credentials = common_creds.get_configured_admin_credentials()
Dmitry Tantsurf00d68d2017-01-05 12:08:39 +010028 super(Manager, self).__init__(credentials)
Anton Arefiev44f678c2016-03-17 12:11:30 +020029 self.introspection_client = BaremetalIntrospectionClient(
30 self.auth_provider,
31 CONF.baremetal_introspection.catalog_type,
32 CONF.identity.region,
Jim Rollenhagen1611df82016-12-07 10:31:43 -050033 endpoint_type=CONF.baremetal_introspection.endpoint_type)
Anton Arefiev44f678c2016-03-17 12:11:30 +020034
35
36class 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 Arefiev6b003562016-09-13 12:17:29 +030047 def create_rules(self, rules):
48 """Create introspection rules."""
49 if not isinstance(rules, list):
50 rules = [rules]
Anton Arefiev44f678c2016-03-17 12:11:30 +020051 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 Arefiev6b003562016-09-13 12:17:29 +030065
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 Nozhka1eb13cf2016-11-04 17:15:50 +020075
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