Adds Python 3.x support in utils network module

Replaces urllib2 usage with the six equivalent.
This commit is contained in:
Alessandro Pilotti 2014-09-08 15:29:49 +03:00
parent adce4d7536
commit c13680eeec
2 changed files with 6 additions and 5 deletions

View File

@ -27,7 +27,7 @@ CONF = cfg.CONF
class NetworkUtilsTest(unittest.TestCase):
@mock.patch('cloudbaseinit.osutils.factory.get_os_utils')
@mock.patch('urlparse.urlparse')
@mock.patch('six.moves.urllib.parse.urlparse')
def _test_check_metadata_ip_route(self, mock_urlparse, mock_get_os_utils,
side_effect):
mock_utils = mock.MagicMock()

View File

@ -13,8 +13,9 @@
# under the License.
import sys
import urllib2
import urlparse
from six.moves.urllib import parse
from six.moves.urllib import request
from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.osutils import factory as osutils_factory
@ -28,7 +29,7 @@ def check_url(url, retries_count=MAX_URL_CHECK_RETRIES):
for i in range(0, MAX_URL_CHECK_RETRIES):
try:
LOG.debug("Testing url: %s" % url)
urllib2.urlopen(url)
request.urlopen(url)
return True
except Exception:
pass
@ -44,7 +45,7 @@ def check_metadata_ip_route(metadata_url):
if sys.platform == 'win32' and osutils.check_os_version(6, 0):
# 169.254.x.x addresses are not getting routed starting from
# Windows Vista / 2008
metadata_netloc = urlparse.urlparse(metadata_url).netloc
metadata_netloc = parse.urlparse(metadata_url).netloc
metadata_host = metadata_netloc.split(':')[0]
if metadata_host.startswith("169.254."):