blob: 6076dd3ef621fcdc966a4f0e806c7587db06e6ae [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 Arefiev44f678c2016-03-17 12:11:30 +020013from tempest import clients
14from tempest.common import credentials_factory as common_creds
15from tempest import config
Anton Arefiev44f678c2016-03-17 12:11:30 +020016
Riccardo Pittau16098692020-04-21 17:06:10 +020017from ironic_tempest_plugin.services.baremetal import base
18
Anton Arefiev44f678c2016-03-17 12:11:30 +020019
20CONF = config.CONF
Anton Arefiev44f678c2016-03-17 12:11:30 +020021
22
23class Manager(clients.Manager):
24 def __init__(self,
Masayuki Igawa51266a52019-02-04 17:13:56 +090025 credentials=None,
Anton Arefiev44f678c2016-03-17 12:11:30 +020026 api_microversions=None):
Masayuki Igawa51266a52019-02-04 17:13:56 +090027 if not credentials:
28 credentials = common_creds.get_configured_admin_credentials()
Dmitry Tantsurf00d68d2017-01-05 12:08:39 +010029 super(Manager, self).__init__(credentials)
Anton Arefiev44f678c2016-03-17 12:11:30 +020030 self.introspection_client = BaremetalIntrospectionClient(
31 self.auth_provider,
32 CONF.baremetal_introspection.catalog_type,
33 CONF.identity.region,
Jim Rollenhagen1611df82016-12-07 10:31:43 -050034 endpoint_type=CONF.baremetal_introspection.endpoint_type)
Anton Arefiev44f678c2016-03-17 12:11:30 +020035
36
37class 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 Arefiev6b003562016-09-13 12:17:29 +030048 def create_rules(self, rules):
49 """Create introspection rules."""
50 if not isinstance(rules, list):
51 rules = [rules]
Anton Arefiev44f678c2016-03-17 12:11:30 +020052 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 Arefiev6b003562016-09-13 12:17:29 +030066
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 Nozhka1eb13cf2016-11-04 17:15:50 +020076
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