[VMware] Fix problem transferring files with ipv6 host

Need to protect the host name with '[' and ']' before
we create a http/https connection

Fixes LP# 1224479

Change-Id: I8c2e58d3eb5e001eff3c9354c3cdc593469b23ac
This commit is contained in:
Davanum Srinivas 2013-09-12 09:35:18 -04:00 committed by Gerrit Code Review
parent db6721b5f8
commit 022a4da050
2 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,44 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corp.
# Copyright 2011 OpenStack Foundation
#
# 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.
import httplib
from oslo.config import cfg
from nova import test
from nova.virt.vmwareapi import read_write_util
CONF = cfg.CONF
class ReadWriteUtilTestCase(test.TestCase):
def setUp(self):
super(ReadWriteUtilTestCase, self).setUp()
def test_ipv6_host(self):
ipv6_host = 'fd8c:215d:178e:c51e:200:c9ff:fed1:584c'
self.mox.StubOutWithMock(httplib.HTTPConnection, 'endheaders')
httplib.HTTPConnection.endheaders()
self.mox.ReplayAll()
file = read_write_util.VMwareHTTPWriteFile(ipv6_host,
'fake_dc',
'fake_ds',
dict(),
'/tmp/fake.txt',
0)
self.assertEqual(ipv6_host, file.conn.host)
self.assertEqual(443, file.conn.port)

View File

@ -29,6 +29,7 @@ import urlparse
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
from nova import utils
LOG = logging.getLogger(__name__)
@ -117,7 +118,10 @@ class VMwareHTTPWriteFile(VMwareHTTPFile):
def __init__(self, host, data_center_name, datastore_name, cookies,
file_path, file_size, scheme="https"):
base_url = "%s://%s/folder/%s" % (scheme, host, file_path)
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)
param_list = {"dcPath": data_center_name, "dsName": datastore_name}
base_url = base_url + "?" + urllib.urlencode(param_list)
_urlparse = urlparse.urlparse(base_url)