From 9be036cf1fa6b4992a29fa815c3dedd8650b9625 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Wed, 16 May 2018 09:54:00 +0200 Subject: [PATCH] Enhancements in nova support This patch add the discover of nova following options: * compute-feature-enabled.attach_encrypted_volume Also add the defaults to the following to true: * compute-feature-enabled.console_output * compute-feature-enabled.resize Change-Id: I96f140de50d5cfaeaab06e1e4d15e427c50b215b --- config_tempest/clients.py | 14 +++++++++++ config_tempest/services/base.py | 3 +++ config_tempest/services/compute.py | 23 +++++++++++++++++++ config_tempest/services/services.py | 10 ++++++++ config_tempest/tests/services/test_compute.py | 17 ++++++++++++++ .../nova-improvements-5a0600f022ab797c.yaml | 8 +++++++ 6 files changed, 75 insertions(+) create mode 100644 releasenotes/notes/nova-improvements-5a0600f022ab797c.yaml diff --git a/config_tempest/clients.py b/config_tempest/clients.py index 5da0cc9e..a1d36461 100644 --- a/config_tempest/clients.py +++ b/config_tempest/clients.py @@ -15,6 +15,7 @@ from tempest.lib import exceptions from tempest.lib.services.compute import flavors_client +from tempest.lib.services.compute import hosts_client from tempest.lib.services.compute import networks_client as nova_net_client from tempest.lib.services.compute import servers_client from tempest.lib.services.identity.v2 import identity_client @@ -107,6 +108,12 @@ class ClientManager(object): endpoint_type='publicURL', default_params=default_params) + self.hosts_client = hosts_client.HostsClient( + self.auth_provider, + conf.get_defaulted('compute', 'catalog_type'), + self.identity_region, + **default_params) + self.set_users_client( auth=self.auth_provider, identity_version=creds.identity_version, @@ -208,6 +215,11 @@ class ClientManager(object): :type service_name: string :rtype: client object or None when the client doesn't exist """ + # TODO(arxcruz): This function is under used, it should return + # a dictionary of all services for a particular client, for + # example, we need hosts_client and flavors_client for compute + # should return {'hosts': self.hosts_client, 'flavors': self.flavors } + # and so on. if service_name == "image": return self.images elif service_name == "network": @@ -215,6 +227,8 @@ class ClientManager(object): # currently needs to have an access to get_neutron/nova_client # methods which are chosen according to neutron presence return self + elif service_name == "compute": + return self.hosts_client else: return None diff --git a/config_tempest/services/base.py b/config_tempest/services/base.py index 550da909..37319198 100644 --- a/config_tempest/services/base.py +++ b/config_tempest/services/base.py @@ -75,6 +75,9 @@ class Service(object): def get_versions(self): return self.versions + def set_default_tempest_options(self, conf): + pass + class VersionedService(Service): def set_versions(self, top_level=True): diff --git a/config_tempest/services/compute.py b/config_tempest/services/compute.py index 5723bd6f..152ae8a4 100644 --- a/config_tempest/services/compute.py +++ b/config_tempest/services/compute.py @@ -14,7 +14,9 @@ # under the License. from base import VersionedService +import config_tempest.constants as C import json +from tempest.lib import exceptions class ComputeService(VersionedService): @@ -28,3 +30,24 @@ class ComputeService(VersionedService): body = self.do_get(url, top_level=top_level) body = json.loads(body) self.versions = self.deserialize_versions(body) + + def set_default_tempest_options(self, conf): + conf.set('compute-feature-enabled', 'console_output', 'True') + # Resize only works if it has at least 2 compute nodes + # or if nova has the option allow_resize_to_same_host + # set to true. Unfortunately we can't get this info from + # nova api, so we only set it when we know there's 2 + # compute nodes + if self._get_number_of_hosts() >= 2: + conf.set('compute-feature-enabled', 'resize', 'True') + + def _get_number_of_hosts(self): + # Right now the client returned is hosts, in the future + # change it to a dict, and get the client as requested + try: + hosts = self.client.list_hosts()['hosts'] + compute_hosts = [h for h in hosts if h['service'] == 'compute'] + return len(compute_hosts) + except exceptions.Forbidden: + C.LOG.info('Can not retrieve hosts, user are not allowed') + return 1 diff --git a/config_tempest/services/services.py b/config_tempest/services/services.py index a3e9752b..6b78a1ac 100644 --- a/config_tempest/services/services.py +++ b/config_tempest/services/services.py @@ -65,6 +65,9 @@ class Services(object): # discover versions of the service service.set_versions() + # default tempest options + service.set_default_tempest_options(self._conf) + self._services.append(service) service_name = 'volume' @@ -210,6 +213,13 @@ class Services(object): self._conf.set('service_available', 'aodh', 'True') self._conf.set('service_available', 'aodh_plugin', 'True') + # TODO(arxcruz): This should be set in compute service, not here, + # however, it requires a refactor in the code, which is not our + # goal right now + self._conf.set('compute-feature-enabled', + 'attach_encrypted_volume', + str(self.is_service('key-manager'))) + def set_supported_api_versions(self): # set supported API versions for services with more of them for service, service_info in C.SERVICE_VERSIONS.iteritems(): diff --git a/config_tempest/tests/services/test_compute.py b/config_tempest/tests/services/test_compute.py index a2fbca05..2a901bc0 100644 --- a/config_tempest/tests/services/test_compute.py +++ b/config_tempest/tests/services/test_compute.py @@ -13,7 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import mock + from config_tempest.services.compute import ComputeService +from config_tempest.tempest_conf import TempestConf from config_tempest.tests.base import BaseServiceTest @@ -32,3 +35,17 @@ class TestComputeService(BaseServiceTest): def test_set_get_versions(self): exp_resp = ['v2.0', 'v2.1'] self._set_get_versions(self.Service, exp_resp, self.FAKE_VERSIONS) + + @mock.patch('config_tempest.services.compute' + '.ComputeService._get_number_of_hosts') + def test_set_default_tempest_options(self, mock_get_number_of_hosts): + mock_get_number_of_hosts.return_value = 2 + conf = TempestConf() + self.Service.set_default_tempest_options(conf) + self.assertEqual( + conf.get('compute-feature-enabled', + 'resize'), 'True') + self.assertEqual( + conf.get('compute-feature-enabled', + 'console_output'), 'True') + mock_get_number_of_hosts.assert_called_once() diff --git a/releasenotes/notes/nova-improvements-5a0600f022ab797c.yaml b/releasenotes/notes/nova-improvements-5a0600f022ab797c.yaml new file mode 100644 index 00000000..43d537f1 --- /dev/null +++ b/releasenotes/notes/nova-improvements-5a0600f022ab797c.yaml @@ -0,0 +1,8 @@ +--- +prelude: > + Improve nova discovery settings +features: + - | + Discover when there is more than one compute node and set the resize + option according, when the tool is executed with admin credentials. + Set by default the console_output to true.