Merge "VMware: Fix problem transferring files with ipv6 host"

This commit is contained in:
Jenkins 2014-12-04 19:36:14 +00:00 committed by Gerrit Code Review
commit f7d2599dda
2 changed files with 32 additions and 6 deletions

View File

@ -14,7 +14,9 @@
# under the License.
import httplib
import urllib2
import mock
from oslo.config import cfg
from nova import test
@ -37,3 +39,22 @@ class ReadWriteUtilTestCase(test.NoDBTestCase):
0)
self.assertEqual(ipv6_host, file.conn.host)
self.assertEqual(443, file.conn.port)
@mock.patch.object(urllib2, 'Request',
return_value='fake_request')
@mock.patch.object(urllib2, 'urlopen')
def test_ipv6_host_read(self, mock_open, mock_request):
ipv6_host = 'fd8c:215d:178e:c51e:200:c9ff:fed1:584c'
folder = 'tmp/fake.txt'
read_write_util.VMwareHTTPReadFile(ipv6_host,
'fake_dc',
'fake_ds',
dict(),
folder)
base_url = 'https://[%s]/folder/%s' % (ipv6_host, folder)
base_url += '?dsName=fake_ds&dcPath=fake_dc'
headers = {'Cookie': '', 'User-Agent': 'OpenStack-ESX-Adapter'}
mock_request.assert_called_with(base_url,
None,
headers)
mock_open.assert_called_with('fake_request')

View File

@ -106,16 +106,22 @@ class VMwareHTTPFile(object):
"""Get size of the file to be read."""
raise NotImplementedError()
def _get_base_url(self, scheme, host, file_path):
if utils.is_valid_ipv6(host):
base_url = "%s://[%s]/folder/%s" % (scheme, host,
urllib.pathname2url(file_path))
else:
base_url = "%s://%s/folder/%s" % (scheme, host,
urllib.pathname2url(file_path))
return base_url
class VMwareHTTPWriteFile(VMwareHTTPFile):
"""VMware file write handler class."""
def __init__(self, host, data_center_name, datastore_name, cookies,
file_path, file_size, scheme="https"):
if utils.is_valid_ipv6(host):
base_url = "%s://[%s]/folder/%s" % (scheme, host, file_path)
else:
base_url = "%s://%s/folder/%s" % (scheme, host, file_path)
base_url = self._get_base_url(scheme, host, file_path)
param_list = {"dcPath": data_center_name, "dsName": datastore_name}
base_url = base_url + "?" + urllib.urlencode(param_list)
_urlparse = urlparse.urlparse(base_url)
@ -151,8 +157,7 @@ class VMwareHTTPReadFile(VMwareHTTPFile):
def __init__(self, host, data_center_name, datastore_name, cookies,
file_path, scheme="https"):
base_url = "%s://%s/folder/%s" % (scheme, host,
urllib.pathname2url(file_path))
base_url = self._get_base_url(scheme, host, file_path)
param_list = {"dcPath": data_center_name, "dsName": datastore_name}
base_url = base_url + "?" + urllib.urlencode(param_list)
headers = {'User-Agent': USER_AGENT,