blob: 07af68a7b13dc7b87eacdf1f60d46ef3ad7693ce [file] [log] [blame]
Andrea Frittoli9806f2d2017-09-01 14:50:07 +01001# Copyright 2017 IBM Corp.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import fixtures
17
18from tempest.lib.services import clients
19
20
21class RegistryFixture(fixtures.Fixture):
22 """A fixture to setup a test client registry
23
24 The clients registry is a singleton. In Tempest it's filled with
25 content from configuration. When testing Tempest lib classes without
26 configuration it's handy to have the registry setup to be able to access
27 service client factories.
28
29 This fixture sets up the registry using a fake plugin, which includes all
30 services specified at __init__ time. Any other plugin in the registry
31 is removed at setUp time. The fake plugin is removed from the registry
32 on cleanup.
33 """
34
35 PLUGIN_NAME = 'fake_plugin_for_test'
36
37 def __init__(self):
38 """Initialise the registry fixture"""
39 self.services = set(['compute', 'identity.v2', 'identity.v3',
Archit Modia8cb7012019-03-28 14:26:45 -040040 'image.v1', 'image.v2', 'network', 'placement',
41 'volume.v1', 'volume.v2', 'volume.v3',
42 'object-storage'])
Andrea Frittoli9806f2d2017-09-01 14:50:07 +010043
44 def _setUp(self):
45 # Cleanup the registry
46 registry = clients.ClientsRegistry()
47 registry._service_clients = {}
48 # Prepare the clients for registration
49 all_clients = []
50 service_clients = clients.tempest_modules()
51 for sc in self.services:
52 sc_module = service_clients[sc]
53 sc_unversioned = sc.split('.')[0]
Andrea Frittoli986407d2017-10-11 10:23:17 +000054 sc_name = sc.replace('.', '_').replace('-', '_')
Andrea Frittoli9806f2d2017-09-01 14:50:07 +010055 # Pass the bare minimum params to satisfy the clients interface
56 service_client_data = dict(
57 name=sc_name, service_version=sc, service=sc_unversioned,
58 module_path=sc_module.__name__,
59 client_names=sc_module.__all__)
60 all_clients.append(service_client_data)
61 registry.register_service_client(self.PLUGIN_NAME, all_clients)
62
63 def _cleanup():
64 del registry._service_clients[self.PLUGIN_NAME]
65
66 self.addCleanup(_cleanup)