From fd1ec71146ed7c0ec415374ab47e83b631f3c444 Mon Sep 17 00:00:00 2001
From: =?utf8?q?C=C3=A9dric=20Ollivier?= <cedric.ollivier@orange.com>
Date: Thu, 12 Sep 2019 11:15:06 +0200
Subject: [PATCH] Allow skipping list_services
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Shade forces the use of admin endpoints when listing services [1].

A new env var is added to allow running Functest when only public
endpoints are reachable (e.g. testing from a VM as proposed for ONAP
integration).

It seems the best approach as list_services provides key data and
we do avoid blocking requests.

It seems easier and more generic than listing all calls in
testcases.yaml.

[1] https://github.com/openstack/shade/blob/master/shade/openstackcloud.py#L9956

Change-Id: Idcbe5d364f4230ffe1da34e7da0e99e863f15c5e
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit f3072c8b1f32feacc9785165477efee9a328eb2e)
---
 .../opnfv_tests/openstack/api/connection_check.py  | 22 +++++++++++++++-------
 functest/utils/env.py                              |  3 ++-
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/functest/opnfv_tests/openstack/api/connection_check.py b/functest/opnfv_tests/openstack/api/connection_check.py
index 48d06211b..7a320b5e4 100644
--- a/functest/opnfv_tests/openstack/api/connection_check.py
+++ b/functest/opnfv_tests/openstack/api/connection_check.py
@@ -16,11 +16,20 @@ import os_client_config
 import shade
 from xtesting.core import testcase
 
+from functest.utils import env
+
 
 class ConnectionCheck(testcase.TestCase):
     """Perform simplest queries"""
     __logger = logging.getLogger(__name__)
 
+    func_list = [
+        "get_network_extensions", "list_aggregates", "list_domains",
+        "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"]
+
     def __init__(self, **kwargs):
         if "case_name" not in kwargs:
             kwargs["case_name"] = 'connection_check'
@@ -38,13 +47,12 @@ class ConnectionCheck(testcase.TestCase):
         try:
             assert self.cloud
             self.start_time = time.time()
-            for func in ["get_network_extensions",
-                         "list_aggregates", "list_domains", "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"]:
+            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")
+            for func in self.func_list:
                 self.__logger.debug(
                     "%s: %s", func, getattr(self.cloud, func)())
             data = self.cloud._network_client.get("/service-providers.json")
diff --git a/functest/utils/env.py b/functest/utils/env.py
index 892d1749d..ba8d6ce55 100644
--- a/functest/utils/env.py
+++ b/functest/utils/env.py
@@ -39,7 +39,8 @@ INPUTS = {
     'NEW_USER_ROLE': 'Member',
     'USE_DYNAMIC_CREDENTIALS': 'True',
     'BLOCK_MIGRATION': 'True',
-    'CLEAN_ORPHAN_SECURITY_GROUPS': 'True'
+    'CLEAN_ORPHAN_SECURITY_GROUPS': 'True',
+    'PUBLIC_ENDPOINT_ONLY': 'False'
 }
 
 
-- 
2.16.6