blob: 3b1a75bd845f26700c9ff1fb759cc1ac5caeb1be [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
20ADMIN_CREDS = common_creds.get_configured_admin_credentials()
21
22
23class Manager(clients.Manager):
24 def __init__(self,
25 credentials=ADMIN_CREDS,
Anton Arefiev44f678c2016-03-17 12:11:30 +020026 api_microversions=None):
Dmitry Tantsurf00d68d2017-01-05 12:08:39 +010027 super(Manager, self).__init__(credentials)
Anton Arefiev44f678c2016-03-17 12:11:30 +020028 self.introspection_client = BaremetalIntrospectionClient(
29 self.auth_provider,
30 CONF.baremetal_introspection.catalog_type,
31 CONF.identity.region,
Jim Rollenhagen1611df82016-12-07 10:31:43 -050032 endpoint_type=CONF.baremetal_introspection.endpoint_type)
Anton Arefiev44f678c2016-03-17 12:11:30 +020033
34
35class BaremetalIntrospectionClient(base.BaremetalClient):
36 """Base Tempest REST client for Ironic Inspector API v1."""
37 version = '1'
38 uri_prefix = 'v1'
39
40 @base.handle_errors
41 def purge_rules(self):
42 """Purge all existing rules."""
43 return self._delete_request('rules', uuid=None)
44
45 @base.handle_errors
Anton Arefiev6b003562016-09-13 12:17:29 +030046 def create_rules(self, rules):
47 """Create introspection rules."""
48 if not isinstance(rules, list):
49 rules = [rules]
Anton Arefiev44f678c2016-03-17 12:11:30 +020050 for rule in rules:
51 self._create_request('rules', rule)
52
53 @base.handle_errors
54 def get_status(self, uuid):
55 """Get introspection status for a node."""
56 return self._show_request('introspection', uuid=uuid)
57
58 @base.handle_errors
59 def get_data(self, uuid):
60 """Get introspection data for a node."""
61 return self._show_request('introspection', uuid=uuid,
62 uri='/%s/introspection/%s/data' %
63 (self.uri_prefix, uuid))
Anton Arefiev6b003562016-09-13 12:17:29 +030064
65 @base.handle_errors
66 def start_introspection(self, uuid):
67 """Start introspection for a node."""
68 resp, _body = self.post(url=('/%s/introspection/%s' %
69 (self.uri_prefix, uuid)),
70 body=None)
71 self.expected_success(202, resp.status)
72
73 return resp
Sergii Nozhka1eb13cf2016-11-04 17:15:50 +020074
75 @base.handle_errors
76 def abort_introspection(self, uuid):
77 """Abort introspection for a node."""
78 resp, _body = self.post(url=('/%s/introspection/%s/abort' %
79 (self.uri_prefix, uuid)),
80 body=None)
81 self.expected_success(202, resp.status)
82
83 return resp