Debian Codegraph @

config_tempest/services/compute.py

raw
1 # Copyright 2013 Red Hat, Inc.
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
16 import json
17
18 from tempest.lib import exceptions
19
20 from config_tempest import constants as C
21 from config_tempest.services.base import VersionedService
22 from config_tempest import utils
23
24
25 class ComputeService(VersionedService):
26 def set_versions(self):
27 url_without_version = utils.get_base_url(self.service_url)
28 body = self.do_get(url_without_version, top_level=False)
29 self.versions_body = json.loads(body)
30 self.versions = self.deserialize_versions(self.versions_body)
31
32 def set_default_tempest_options(self, conf):
33 conf.set('compute-feature-enabled', 'console_output', 'True')
34 num_compute = self._get_number_of_hosts()
35 # set min_compute_nodes to enable migration tests in env
36 # with multiple compute nodes
37 conf.set('compute', 'min_compute_nodes', str(num_compute))
38 # Resize only works if it has at least 2 compute nodes
39 # or if nova has the option allow_resize_to_same_host
40 # set to true. Unfortunately we can't get this info from
41 # nova api, so we only set it when we know there's 2
42 # compute nodes
43 if num_compute >= 2:
44 conf.set('compute-feature-enabled', 'resize', 'True')
45 # set microversions
46 m_versions = self.filter_api_microversions()
47 conf.set('compute', 'min_microversion', m_versions['min_microversion'])
48 conf.set('compute', 'max_microversion', m_versions['max_microversion'])
49
50 def _get_number_of_hosts(self):
51 # Right now the client returned is hosts, in the future
52 # change it to a dict, and get the client as requested
53 try:
54 hosts = self.client.list_hosts()['hosts']
55 compute_hosts = [h for h in hosts if h['service'] == 'compute']
56 return len(compute_hosts)
57 except exceptions.Forbidden:
58 C.LOG.info('Can not retrieve hosts, user are not allowed')
59 return 1
60
61 @staticmethod
62 def get_service_type():
63 return ['compute']
64
65 @staticmethod
66 def get_codename():
67 return 'nova'