From 022a4da0507924f57b563e7a5a09ea9d01e63c0e Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Thu, 12 Sep 2013 09:35:18 -0400 Subject: [PATCH] [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 --- .../virt/vmwareapi/test_read_write_util.py | 44 +++++++++++++++++++ nova/virt/vmwareapi/read_write_util.py | 6 ++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 nova/tests/virt/vmwareapi/test_read_write_util.py diff --git a/nova/tests/virt/vmwareapi/test_read_write_util.py b/nova/tests/virt/vmwareapi/test_read_write_util.py new file mode 100644 index 000000000000..9ae65d760fc2 --- /dev/null +++ b/nova/tests/virt/vmwareapi/test_read_write_util.py @@ -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) diff --git a/nova/virt/vmwareapi/read_write_util.py b/nova/virt/vmwareapi/read_write_util.py index 94010ec50166..ac90e8a08ed2 100644 --- a/nova/virt/vmwareapi/read_write_util.py +++ b/nova/virt/vmwareapi/read_write_util.py @@ -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)