Allow getting service via any endpoint 42/68542/3
authorCédric Ollivier <cedric.ollivier@orange.com>
Thu, 26 Sep 2019 15:29:32 +0000 (17:29 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Sat, 28 Sep 2019 10:12:19 +0000 (12:12 +0200)
It overrides the default implementation provided by Shade.

Change-Id: I3ad2f8ba543be4483f108c4bd7765018dddc5b19
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/core/tenantnetwork.py
functest/opnfv_tests/openstack/api/connection_check.py
functest/opnfv_tests/openstack/rally/rally.py
functest/opnfv_tests/openstack/vmtp/vmtp.py
functest/utils/env.py
functest/utils/functest_utils.py

index a7b4e9c..3b9c7eb 100644 (file)
@@ -31,6 +31,7 @@ from xtesting.core import testcase
 
 from functest.utils import config
 from functest.utils import env
 
 from functest.utils import config
 from functest.utils import env
+from functest.utils import functest_utils
 
 
 class NewProject():
 
 
 class NewProject():
@@ -205,7 +206,7 @@ class TenantNetwork1(testcase.TestCase):
     @staticmethod
     def get_public_auth_url(cloud):
         """Get Keystone public endpoint"""
     @staticmethod
     def get_public_auth_url(cloud):
         """Get Keystone public endpoint"""
-        keystone_id = cloud.search_services('keystone')[0].id
+        keystone_id = functest_utils.search_services(cloud, 'keystone')[0].id
         endpoint = cloud.search_endpoints(
             filters={'interface': 'public',
                      'service_id': keystone_id})[0].url
         endpoint = cloud.search_endpoints(
             filters={'interface': 'public',
                      'service_id': keystone_id})[0].url
index cebb631..927b73b 100644 (file)
@@ -16,7 +16,6 @@ import os_client_config
 import shade
 from xtesting.core import testcase
 
 import shade
 from xtesting.core import testcase
 
-from functest.utils import env
 from functest.utils import functest_utils
 
 
 from functest.utils import functest_utils
 
 
@@ -29,7 +28,7 @@ class ConnectionCheck(testcase.TestCase):
         "list_endpoints", "list_floating_ip_pools", "list_floating_ips",
         "list_hypervisors", "list_keypairs", "list_networks", "list_ports",
         "list_role_assignments", "list_roles", "list_routers", "list_servers",
         "list_endpoints", "list_floating_ip_pools", "list_floating_ips",
         "list_hypervisors", "list_keypairs", "list_networks", "list_ports",
         "list_role_assignments", "list_roles", "list_routers", "list_servers",
-        "list_services", "list_subnets"]
+        "list_subnets"]
 
     def __init__(self, **kwargs):
         if "case_name" not in kwargs:
 
     def __init__(self, **kwargs):
         if "case_name" not in kwargs:
@@ -48,11 +47,8 @@ class ConnectionCheck(testcase.TestCase):
         try:
             assert self.cloud
             self.start_time = time.time()
         try:
             assert self.cloud
             self.start_time = time.time()
-            if env.get('PUBLIC_ENDPOINT_ONLY').lower() == 'true':
-                self.__logger.warning(
-                    "Listing services is skipped "
-                    "because the admin endpoints are unreachable")
-                self.func_list.remove("list_services")
+            self.__logger.debug(
+                "list_services: %s", functest_utils.list_services(self.cloud))
             for func in self.func_list:
                 self.__logger.debug(
                     "%s: %s", func, getattr(self.cloud, func)())
             for func in self.func_list:
                 self.__logger.debug(
                     "%s: %s", func, getattr(self.cloud, func)())
index 9a04f38..d9fb1fb 100644 (file)
@@ -172,6 +172,7 @@ class RallyBase(singlevm.VmReady2):
 
     @staticmethod
     def create_rally_deployment(environ=None):
 
     @staticmethod
     def create_rally_deployment(environ=None):
+        # pylint: disable=unexpected-keyword-arg
         """Create new rally deployment"""
         # set the architecture to default
         pod_arch = env.get("POD_ARCH")
         """Create new rally deployment"""
         # set the architecture to default
         pod_arch = env.get("POD_ARCH")
index 317a786..d102f64 100644 (file)
@@ -125,6 +125,7 @@ class Vmtp(singlevm.VmReady2):
             conf.write(yaml.dump(vmtp_conf))
 
     def run_vmtp(self):
             conf.write(yaml.dump(vmtp_conf))
 
     def run_vmtp(self):
+        # pylint: disable=unexpected-keyword-arg
         """Run Vmtp and generate charts
 
         Raises: Exception on error
         """Run Vmtp and generate charts
 
         Raises: Exception on error
index 04919ac..8c00309 100644 (file)
@@ -36,8 +36,7 @@ INPUTS = {
     'NEW_USER_ROLE': 'Member',
     'USE_DYNAMIC_CREDENTIALS': 'True',
     'BLOCK_MIGRATION': 'True',
     'NEW_USER_ROLE': 'Member',
     'USE_DYNAMIC_CREDENTIALS': 'True',
     'BLOCK_MIGRATION': 'True',
-    'CLEAN_ORPHAN_SECURITY_GROUPS': 'True',
-    'PUBLIC_ENDPOINT_ONLY': 'False'
+    'CLEAN_ORPHAN_SECURITY_GROUPS': 'True'
 }
 
 
 }
 
 
index 42c1edc..5cfffa9 100644 (file)
 
 from __future__ import print_function
 import logging
 
 from __future__ import print_function
 import logging
+import os
 import subprocess
 import sys
 import yaml
 
 import subprocess
 import sys
 import yaml
 
+from shade import _utils
 import six
 
 LOGGER = logging.getLogger(__name__)
 import six
 
 LOGGER = logging.getLogger(__name__)
@@ -140,6 +142,51 @@ def get_openstack_version(cloud):
         return "Unknown"
 
 
         return "Unknown"
 
 
+def list_services(cloud):
+    # pylint: disable=protected-access
+    """Search Keystone services via $OS_INTERFACE.
+
+    It mainly conforms with `Shade
+    <latest/reference/api-microversion-history.html>`_ but allows testing vs
+    public endpoints. It's worth mentioning that it doesn't support keystone
+    v2.
+
+    :returns: a list of ``munch.Munch`` containing the services description
+
+    :raises: ``OpenStackCloudException`` if something goes wrong during the
+        openstack API call.
+    """
+    url, key = '/services', 'services'
+    data = cloud._identity_client.get(
+        url, endpoint_filter={
+            'interface': os.environ.get('OS_INTERFACE', 'public')},
+        error_message="Failed to list services")
+    services = cloud._get_and_munchify(key, data)
+    return _utils.normalize_keystone_services(services)
+
+
+def search_services(cloud, name_or_id=None, filters=None):
+    # pylint: disable=protected-access
+    """Search Keystone services ia $OS_INTERFACE.
+
+    It mainly conforms with `Shade
+    <latest/reference/api-microversion-history.html>`_ but allows testing vs
+    public endpoints. It's worth mentioning that it doesn't support keystone
+    v2.
+
+    :param name_or_id: Name or id of the desired service.
+    :param filters: a dict containing additional filters to use. e.g.
+                    {'type': 'network'}.
+
+    :returns: a list of ``munch.Munch`` containing the services description
+
+    :raises: ``OpenStackCloudException`` if something goes wrong during the
+        openstack API call.
+    """
+    services = list_services(cloud)
+    return _utils._filter_list(services, name_or_id, filters)
+
+
 def convert_dict_to_ini(value):
     "Convert dict to oslo.conf input"
     assert isinstance(value, dict)
 def convert_dict_to_ini(value):
     "Convert dict to oslo.conf input"
     assert isinstance(value, dict)