summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/nova/nova.conf.sample6
-rw-r--r--nova/tests/test_vmwareapi.py46
-rw-r--r--nova/virt/vmwareapi/vim.py49
3 files changed, 85 insertions, 16 deletions
diff --git a/etc/nova/nova.conf.sample b/etc/nova/nova.conf.sample
index 4d8fabd00..762576e84 100644
--- a/etc/nova/nova.conf.sample
+++ b/etc/nova/nova.conf.sample
@@ -2256,10 +2256,8 @@
# Options defined in nova.virt.vmwareapi.vim
#
-# VIM Service WSDL Location e.g
-# http://<server>/vimService.wsdl. Due to a bug in vSphere ESX
-# 4.1 default wsdl. Refer readme-vmware to setup (string
-# value)
+# Optional VIM Service WSDL Location e.g
+# http://<server>/vimService.wsdl
#vmwareapi_wsdl_loc=<None>
diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py
index 60f7db72c..bbd5a2caa 100644
--- a/nova/tests/test_vmwareapi.py
+++ b/nova/tests/test_vmwareapi.py
@@ -19,9 +19,11 @@
"""
Test suite for VMwareAPI.
"""
-import mox
import urllib2
+import mox
+from oslo.config import cfg
+
from nova.compute import power_state
from nova.compute import task_states
from nova import context
@@ -35,6 +37,7 @@ from nova.tests.vmwareapi import db_fakes
from nova.tests.vmwareapi import stubs
from nova.virt.vmwareapi import driver
from nova.virt.vmwareapi import fake as vmwareapi_fake
+from nova.virt.vmwareapi import vim
from nova.virt.vmwareapi import vm_util
@@ -52,6 +55,47 @@ class fake_http_resp(object):
return "console log"
+class VMwareAPIConfTestCase(test.TestCase):
+ """Unit tests for VMWare API configurations."""
+ def setUp(self):
+ super(VMwareAPIConfTestCase, self).setUp()
+
+ def tearDown(self):
+ super(VMwareAPIConfTestCase, self).tearDown()
+
+ def test_configure_without_wsdl_loc_override(self):
+ # Test the default configuration behavior. By default,
+ # use the WSDL sitting on the host we are talking to in
+ # order to bind the SOAP client.
+ wsdl_loc = cfg.CONF.vmwareapi_wsdl_loc
+ self.assertIsNone(wsdl_loc)
+ wsdl_url = vim.Vim.get_wsdl_url("https", "www.example.com")
+ url = vim.Vim.get_soap_url("https", "www.example.com")
+ self.assertEqual("https://www.example.com/sdk/vimService.wsdl",
+ wsdl_url)
+ self.assertEqual("https://www.example.com/sdk", url)
+
+ def test_configure_with_wsdl_loc_override(self):
+ # Use the setting vmwareapi_wsdl_loc to override the
+ # default path to the WSDL.
+ #
+ # This is useful as a work-around for XML parsing issues
+ # found when using some WSDL in combination with some XML
+ # parsers.
+ #
+ # The wsdl_url should point to a different host than the one we
+ # are actually going to send commands to.
+ fake_wsdl = "https://www.test.com/sdk/foo.wsdl"
+ self.flags(vmwareapi_wsdl_loc=fake_wsdl)
+ wsdl_loc = cfg.CONF.vmwareapi_wsdl_loc
+ self.assertIsNotNone(wsdl_loc)
+ self.assertEqual(fake_wsdl, wsdl_loc)
+ wsdl_url = vim.Vim.get_wsdl_url("https", "www.example.com")
+ url = vim.Vim.get_soap_url("https", "www.example.com")
+ self.assertEqual(fake_wsdl, wsdl_url)
+ self.assertEqual("https://www.example.com/sdk", url)
+
+
class VMwareAPIVMTestCase(test.TestCase):
"""Unit tests for Vmware API connection calls."""
diff --git a/nova/virt/vmwareapi/vim.py b/nova/virt/vmwareapi/vim.py
index 775f77453..69480c8e1 100644
--- a/nova/virt/vmwareapi/vim.py
+++ b/nova/virt/vmwareapi/vim.py
@@ -37,10 +37,9 @@ ADDRESS_IN_USE_ERROR = 'Address already in use'
vmwareapi_wsdl_loc_opt = cfg.StrOpt('vmwareapi_wsdl_loc',
default=None,
- help='VIM Service WSDL Location '
+ help='Optional VIM Service WSDL Location '
'e.g http://<server>/vimService.wsdl. '
- 'Due to a bug in vSphere ESX 4.1 default wsdl. '
- 'Refer readme-vmware to setup')
+ 'Optional over-ride to default location for bug work-arounds')
CONF = cfg.CONF
CONF.register_opt(vmwareapi_wsdl_loc_opt)
@@ -86,16 +85,44 @@ class Vim:
self._protocol = protocol
self._host_name = host
+ self.wsdl_url = Vim.get_wsdl_url(protocol, host)
+ self.url = Vim.get_soap_url(protocol, host)
+ self.client = suds.client.Client(self.wsdl_url, location=self.url,
+ plugins=[VIMMessagePlugin()])
+ self._service_content = self.RetrieveServiceContent(
+ "ServiceInstance")
+
+ @staticmethod
+ def get_wsdl_url(protocol, host_name):
+ """
+ allows override of the wsdl location, making this static
+ means we can test the logic outside of the constructor
+ without forcing the test environment to have multiple valid
+ wsdl locations to test against.
+
+ :param protocol: https or http
+ :param host_name: localhost or other server name
+ :return: string to WSDL location for vSphere WS Management API
+ """
+ # optional WSDL location over-ride for work-arounds
wsdl_url = CONF.vmwareapi_wsdl_loc
if wsdl_url is None:
- raise Exception(_("Must specify vmwareapi_wsdl_loc"))
- # TODO(sateesh): Use this when VMware fixes their faulty wsdl
- #wsdl_url = '%s://%s/sdk/vimService.wsdl' % (self._protocol,
- # self._host_name)
- url = '%s://%s/sdk' % (self._protocol, self._host_name)
- self.client = suds.client.Client(wsdl_url, location=url,
- plugins=[VIMMessagePlugin()])
- self._service_content = self.RetrieveServiceContent("ServiceInstance")
+ # calculate default WSDL location if no override supplied
+ wsdl_url = '%s://%s/sdk/vimService.wsdl' % (protocol, host_name)
+ return wsdl_url
+
+ @staticmethod
+ def get_soap_url(protocol, host_name):
+ """
+ Calculates the location of the SOAP services
+ for a particular server. Created as a static
+ method for testing.
+
+ :param protocol: https or http
+ :param host_name: localhost or other vSphere server name
+ :return: the url to the active vSphere WS Management API
+ """
+ return '%s://%s/sdk' % (protocol, host_name)
def get_service_content(self):
"""Gets the service content object."""