Add the choice of interface for keystoneclient
authorLinda Wang <wangwulin@huawei.com>
Thu, 27 Apr 2017 07:01:24 +0000 (07:01 +0000)
committerLinda Wang <wangwulin@huawei.com>
Tue, 2 May 2017 06:14:44 +0000 (06:14 +0000)
1. When functest is running on external host not jumpserver,
   keystoneclient is used to retrieve or create projects/tenants
   and users, which would fail to establish connection to the admin
   endpoint.
2. Keystoneclient will connect to the public endpoint by setting the
   env OS_INTERFACE to be public.
3. Remove the admin endpoint check in check_os.sh.

JIRA: FUNCTEST-801

Change-Id: I324f5c8fdf61447319070a23f6b6bc6b1bbc1d48
Signed-off-by: Linda Wang <wangwulin@huawei.com>
functest/ci/check_os.sh
functest/tests/unit/utils/test_openstack_utils.py
functest/utils/openstack_utils.py

index 83f9f47..ce0bc20 100755 (executable)
@@ -86,30 +86,6 @@ if [ $RETVAL -ne 0 ]; then
 fi
 echo "  ...OK"
 
-adminURL=$(openstack catalog show  identity |awk '/admin/ {print $4}')
-if [ -z ${adminURL} ]; then
-    echo "ERROR: Cannot determine the admin URL."
-    openstack catalog show identity
-    exit 1
-fi
-adminIP=$(echo $adminURL|sed 's/^.*http.*\:\/\///'|sed 's/.[^:]*$//')
-adminPort=$(echo $adminURL|grep -Po '(?<=:)\d+')
-https_enabled=$(echo $adminURL | grep 'https')
-if [[ -n $https_enabled ]]; then
-    echo ">>Verifying SSL connectivity to the admin endpoint $adminIP:$adminPort..."
-    verify_SSL_connectivity $adminIP $adminPort
-else
-    echo ">>Verifying connectivity to the admin endpoint $adminIP:$adminPort..."
-    verify_connectivity $adminIP $adminPort
-fi
-RETVAL=$?
-if [ $RETVAL -ne 0 ]; then
-    echo "ERROR: Cannot talk to the admin endpoint $adminIP:$adminPort ."
-    echo "$adminURL"
-    exit 1
-fi
-echo "  ...OK"
-
 
 echo "Checking Required OpenStack services:"
 for service in $MANDATORY_SERVICES; do
index 7f3995d..a7df264 100644 (file)
@@ -418,21 +418,45 @@ class OSUtilsTesting(unittest.TestCase):
         mock_logger_info.assert_called_once_with("OS_IDENTITY_API_VERSION is "
                                                  "set in env as '%s'", '3')
 
-    def test_get_keystone_client(self):
+    @mock.patch('functest.utils.openstack_utils.get_session')
+    @mock.patch('functest.utils.openstack_utils.keystoneclient.Client')
+    @mock.patch('functest.utils.openstack_utils.get_keystone_client_version',
+                return_value='3')
+    @mock.patch('functest.utils.openstack_utils.os.getenv',
+                return_value='public')
+    def test_get_keystone_client_with_interface(self, mock_os_getenv,
+                                                mock_keystoneclient_version,
+                                                mock_key_client,
+                                                mock_get_session):
         mock_keystone_obj = mock.Mock()
         mock_session_obj = mock.Mock()
-        with mock.patch('functest.utils.openstack_utils'
-                        '.get_keystone_client_version', return_value='3'), \
-            mock.patch('functest.utils.openstack_utils'
-                       '.keystoneclient.Client',
-                       return_value=mock_keystone_obj) \
-            as mock_key_client, \
-            mock.patch('functest.utils.openstack_utils.get_session',
-                       return_value=mock_session_obj):
-            self.assertEqual(openstack_utils.get_keystone_client(),
-                             mock_keystone_obj)
-            mock_key_client.assert_called_once_with('3',
-                                                    session=mock_session_obj)
+        mock_key_client.return_value = mock_keystone_obj
+        mock_get_session.return_value = mock_session_obj
+        self.assertEqual(openstack_utils.get_keystone_client(),
+                         mock_keystone_obj)
+        mock_key_client.assert_called_once_with('3',
+                                                session=mock_session_obj,
+                                                interface='public')
+
+    @mock.patch('functest.utils.openstack_utils.get_session')
+    @mock.patch('functest.utils.openstack_utils.keystoneclient.Client')
+    @mock.patch('functest.utils.openstack_utils.get_keystone_client_version',
+                return_value='3')
+    @mock.patch('functest.utils.openstack_utils.os.getenv',
+                return_value='admin')
+    def test_get_keystone_client_no_interface(self, mock_os_getenv,
+                                              mock_keystoneclient_version,
+                                              mock_key_client,
+                                              mock_get_session):
+        mock_keystone_obj = mock.Mock()
+        mock_session_obj = mock.Mock()
+        mock_key_client.return_value = mock_keystone_obj
+        mock_get_session.return_value = mock_session_obj
+        self.assertEqual(openstack_utils.get_keystone_client(),
+                         mock_keystone_obj)
+        mock_key_client.assert_called_once_with('3',
+                                                session=mock_session_obj,
+                                                interface='admin')
 
     @mock.patch('functest.utils.openstack_utils.os.getenv',
                 return_value=None)
index 929a761..49b9c84 100644 (file)
@@ -198,7 +198,9 @@ def get_keystone_client_version():
 
 def get_keystone_client(other_creds={}):
     sess = get_session(other_creds)
-    return keystoneclient.Client(get_keystone_client_version(), session=sess)
+    return keystoneclient.Client(get_keystone_client_version(),
+                                 session=sess,
+                                 interface=os.getenv('OS_INTERFACE', 'admin'))
 
 
 def get_nova_client_version():