Normalize url without port with schema default port

In function get_bare_url, it will assert url startswith base_url,
if base_url is 'http://neutron.openstack.svc.cluster.local:80/',
while url is 'http://neutron.openstack.svc.cluster.local/v2.0/router/...',
it will raise error. here need to add default schema port 80 to url to
fix this problem.

Change-Id: I44d623d3d0d96711f7ca93fc24b40c024dd86446
Closes-Bug: #1829962
diff --git a/neutron_tempest_plugin/api/base.py b/neutron_tempest_plugin/api/base.py
index 7b91d94..2c062c4 100644
--- a/neutron_tempest_plugin/api/base.py
+++ b/neutron_tempest_plugin/api/base.py
@@ -1111,8 +1111,10 @@
 
     def get_bare_url(self, url):
         base_url = self.client.base_url
-        self.assertTrue(url.startswith(base_url))
-        return url[len(base_url):]
+        base_url_normalized = utils.normalize_url(base_url)
+        url_normalized = utils.normalize_url(url)
+        self.assertTrue(url_normalized.startswith(base_url_normalized))
+        return url_normalized[len(base_url_normalized):]
 
     @classmethod
     def _extract_resources(cls, body):
diff --git a/neutron_tempest_plugin/common/utils.py b/neutron_tempest_plugin/common/utils.py
index 3649cb6..bd7a367 100644
--- a/neutron_tempest_plugin/common/utils.py
+++ b/neutron_tempest_plugin/common/utils.py
@@ -21,9 +21,18 @@
 import functools
 import threading
 import time
+try:
+    import urlparse
+except ImportError:
+    from urllib import parse as urlparse
 
 import eventlet
 
+SCHEMA_PORT_MAPPING = {
+    "http": 80,
+    "https": 443,
+}
+
 
 class classproperty(object):
     def __init__(self, f):
@@ -102,3 +111,15 @@
         bases = (overrider_class, overriden_class)
         overriden_class = type(name, bases, {})
     return overriden_class
+
+
+def normalize_url(url):
+    """Normalize url without port with schema default port
+
+    """
+    parse_result = urlparse.urlparse(url)
+    (scheme, netloc, url, params, query, fragment) = parse_result
+    port = parse_result.port
+    if scheme in SCHEMA_PORT_MAPPING and not port:
+        netloc = netloc + ":" + str(SCHEMA_PORT_MAPPING[scheme])
+    return urlparse.urlunparse((scheme, netloc, url, params, query, fragment))