Add unit tests for _get_unversioned_endpoint
This commit adds the first unit tests for the verify_tempest_config
script which covers the code used to format an unversioned endpoint
from a versioned one returned from the keystone catalog. This also
breaks that section of the script off into a separate method so that
mocks were not needed for such a simple test case.
Partially implements bp: config-verification
Change-Id: I6f48034af5fc187f6ae7d5c9b3dccb61f309ae25
diff --git a/tempest/cmd/verify_tempest_config.py b/tempest/cmd/verify_tempest_config.py
index 4d74f53..7b2e60b 100755
--- a/tempest/cmd/verify_tempest_config.py
+++ b/tempest/cmd/verify_tempest_config.py
@@ -75,6 +75,12 @@
not CONF.image_feature_enabled.api_v2, update)
+def _get_unversioned_endpoint(base_url):
+ endpoint_parts = urlparse.urlparse(base_url)
+ endpoint = endpoint_parts.scheme + '://' + endpoint_parts.netloc
+ return endpoint
+
+
def _get_api_versions(os, service):
client_dict = {
'nova': os.servers_client,
@@ -82,8 +88,7 @@
'cinder': os.volumes_client,
}
client_dict[service].skip_path()
- endpoint_parts = urlparse.urlparse(client_dict[service].base_url)
- endpoint = endpoint_parts.scheme + '://' + endpoint_parts.netloc
+ endpoint = _get_unversioned_endpoint(client_dict[service].base_url)
__, body = RAW_HTTP.request(endpoint, 'GET')
client_dict[service].reset_path()
body = json.loads(body)
diff --git a/tempest/tests/cmd/__init__.py b/tempest/tests/cmd/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/tests/cmd/__init__.py
diff --git a/tempest/tests/cmd/test_verify_tempest_config.py b/tempest/tests/cmd/test_verify_tempest_config.py
new file mode 100644
index 0000000..b4b0cc3
--- /dev/null
+++ b/tempest/tests/cmd/test_verify_tempest_config.py
@@ -0,0 +1,30 @@
+# Copyright 2014 IBM Corp.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+from tempest.cmd import verify_tempest_config
+from tempest.tests import base
+
+
+class TestGetAPIVersions(base.TestCase):
+
+ def test_url_grab_versioned_nova_nossl(self):
+ base_url = 'http://127.0.0.1:8774/v2/'
+ endpoint = verify_tempest_config._get_unversioned_endpoint(base_url)
+ self.assertEqual('http://127.0.0.1:8774', endpoint)
+
+ def test_url_grab_versioned_nova_ssl(self):
+ base_url = 'https://127.0.0.1:8774/v3/'
+ endpoint = verify_tempest_config._get_unversioned_endpoint(base_url)
+ self.assertEqual('https://127.0.0.1:8774', endpoint)