blob: 2934e544cb52c5315d612ac372ea6a4cf52b5ccc [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,
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,
33 endpoint_type=CONF.baremetal_introspection.endpoint_type,
34 **self.default_params_with_timeout_values)
35
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