From d47a8355d17648d216dc5e72e420695dfcbb3fe2 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Fri, 8 May 2015 16:49:22 -0400 Subject: [PATCH] Drop explicit suds dependency we should just use what oslo.vmware requires. Transitive dependency should be enough for Nova. Remove a few imports in a test case to pass the nova policy of "if any explicit import then need an entry in requirements". Also remove tests relating to suds as oslo.vmware uses suds and any of these tests should be there instead. Co-Authored-By: Victor Stinner Change-Id: I28f29d3e5745c21b99dc0cf9eb0cfe4f95dffd17 --- nova/tests/unit/test_hacking.py | 3 -- nova/tests/unit/virt/vmwareapi/stubs.py | 40 ------------------- .../unit/virt/vmwareapi/test_driver_api.py | 30 -------------- .../unit/virt/vmwareapi/test_vim_util.py | 39 ------------------ nova/virt/vmwareapi/vim_util.py | 3 +- test-requirements.txt | 1 - 6 files changed, 1 insertion(+), 115 deletions(-) diff --git a/nova/tests/unit/test_hacking.py b/nova/tests/unit/test_hacking.py index 145fd987b4..c469f12de8 100644 --- a/nova/tests/unit/test_hacking.py +++ b/nova/tests/unit/test_hacking.py @@ -274,9 +274,6 @@ class HackingTestCase(test.NoDBTestCase): checks.validate_log_translations(ok, ok, 'f')))) def test_no_mutable_default_args(self): - self.assertEqual(1, len(list(checks.no_mutable_default_args( - " def fake_suds_context(calls={}):")))) - self.assertEqual(1, len(list(checks.no_mutable_default_args( "def get_info_from_bdm(virt_type, bdm, mapping=[])")))) diff --git a/nova/tests/unit/virt/vmwareapi/stubs.py b/nova/tests/unit/virt/vmwareapi/stubs.py index 623ea3c992..2e3dd5ae3f 100644 --- a/nova/tests/unit/virt/vmwareapi/stubs.py +++ b/nova/tests/unit/virt/vmwareapi/stubs.py @@ -17,9 +17,6 @@ Stubouts for the test suite """ -import contextlib - -import mock from oslo_vmware import exceptions as vexc from nova.tests.unit.virt.vmwareapi import fake @@ -77,40 +74,3 @@ def set_stubs(stubs): stubs.Set(driver.VMwareAPISession, "vim", fake_vim_prop) stubs.Set(driver.VMwareAPISession, "_is_vim_object", fake_is_vim_object) - - -def fake_suds_context(calls=None): - """Generate a suds client which automatically mocks all SOAP method calls. - - Calls are stored in , indexed by the name of the call. If you need - to mock the behaviour of specific API calls you can pre-populate - with appropriate Mock objects. - """ - - calls = calls or {} - - class fake_factory(object): - def create(self, name): - return mock.NonCallableMagicMock(name=name) - - class fake_service(object): - def __getattr__(self, attr_name): - if attr_name in calls: - return calls[attr_name] - - mock_call = mock.MagicMock(name=attr_name) - calls[attr_name] = mock_call - return mock_call - - class fake_client(object): - def __init__(self, wdsl_url, **kwargs): - self.service = fake_service() - self.factory = fake_factory() - - return contextlib.nested( - mock.patch('suds.client.Client', fake_client), - - # As we're not connecting to a real host there's no need to wait - # between retries - mock.patch.object(driver, 'TIME_BETWEEN_API_CALL_RETRIES', 0) - ) diff --git a/nova/tests/unit/virt/vmwareapi/test_driver_api.py b/nova/tests/unit/virt/vmwareapi/test_driver_api.py index 35be43c724..5a7cd1135f 100644 --- a/nova/tests/unit/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/unit/virt/vmwareapi/test_driver_api.py @@ -21,7 +21,6 @@ Test suite for VMwareAPI. import collections import contextlib -import copy import datetime from eventlet import greenthread @@ -34,9 +33,7 @@ from oslo_utils import uuidutils from oslo_vmware import exceptions as vexc from oslo_vmware.objects import datastore as ds_obj from oslo_vmware import pbm -from oslo_vmware import vim from oslo_vmware import vim_util as oslo_vim_util -import suds from nova import block_device from nova.compute import api as compute_api @@ -86,33 +83,6 @@ class fake_service_content(object): self.ServiceContent.fake = 'fake' -class VMwareSudsTest(test.NoDBTestCase): - - def setUp(self): - super(VMwareSudsTest, self).setUp() - - def new_client_init(self, url, **kwargs): - return - - mock.patch.object(suds.client.Client, - '__init__', new=new_client_init).start() - self.vim = self._vim_create() - self.addCleanup(mock.patch.stopall) - - def _mock_getattr(self, attr_name): - self.assertEqual("RetrieveServiceContent", attr_name) - return lambda obj, **kwargs: fake_service_content() - - def _vim_create(self): - with mock.patch.object(vim.Vim, '__getattr__', self._mock_getattr): - return vim.Vim() - - def test_exception_with_deepcopy(self): - self.assertIsNotNone(self.vim) - self.assertRaises(vexc.VimException, - copy.deepcopy, self.vim) - - def _fake_create_session(inst): session = vmwareapi_fake.DataObject() session.key = 'fake_key' diff --git a/nova/tests/unit/virt/vmwareapi/test_vim_util.py b/nova/tests/unit/virt/vmwareapi/test_vim_util.py index d00e127b66..1469a02fbd 100644 --- a/nova/tests/unit/virt/vmwareapi/test_vim_util.py +++ b/nova/tests/unit/virt/vmwareapi/test_vim_util.py @@ -12,15 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. -import collections - import fixtures import mock from nova import test from nova.tests.unit.virt.vmwareapi import fake -from nova.tests.unit.virt.vmwareapi import stubs -from nova.virt.vmwareapi import driver from nova.virt.vmwareapi import vim_util @@ -63,41 +59,6 @@ class VMwareVIMUtilTestCase(test.NoDBTestCase): 'fake-type', 'fake-property') self.assertIsNone(res) - def test_get_dynamic_properties_with_token(self): - ObjectContent = collections.namedtuple('ObjectContent', ['propSet']) - DynamicProperty = collections.namedtuple('Property', ['name', 'val']) - - # Add a token to our results, indicating that more are available - result = fake.FakeRetrieveResult(token='fake_token') - - # We expect these properties to be returned - result.add_object(ObjectContent(propSet=[ - DynamicProperty(name='name1', val='value1'), - DynamicProperty(name='name2', val='value2') - ])) - - # These properties should be ignored - result.add_object(ObjectContent(propSet=[ - DynamicProperty(name='name3', val='value3') - ])) - - retrievePropertiesEx = mock.MagicMock(name='RetrievePropertiesEx') - retrievePropertiesEx.return_value = result - - calls = {'RetrievePropertiesEx': retrievePropertiesEx} - with stubs.fake_suds_context(calls): - session = driver.VMwareAPISession(host_ip='localhost') - - service_content = session.vim.service_content - props = session._call_method(vim_util, "get_dynamic_properties", - service_content.propertyCollector, - 'fake_type', None) - - self.assertEqual(props, { - 'name1': 'value1', - 'name2': 'value2' - }) - @mock.patch.object(vim_util, 'get_object_properties', return_value=None) def test_get_dynamic_properties_no_objects(self, mock_get_object_props): res = vim_util.get_dynamic_properties('fake-vim', 'fake-obj', diff --git a/nova/virt/vmwareapi/vim_util.py b/nova/virt/vmwareapi/vim_util.py index 1d3e436470..ec5b3f74c0 100644 --- a/nova/virt/vmwareapi/vim_util.py +++ b/nova/virt/vmwareapi/vim_util.py @@ -21,7 +21,6 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_vmware import vim_util as vutil import six -import suds from nova.i18n import _LW @@ -47,7 +46,7 @@ def object_to_dict(obj, list_depth=1): are converted. """ d = {} - for k, v in six.iteritems(suds.sudsobject.asdict(obj)): + for k, v in six.iteritems(dict(obj)): if hasattr(v, '__keylist__'): d[k] = object_to_dict(v, list_depth=list_depth) elif isinstance(v, list): diff --git a/test-requirements.txt b/test-requirements.txt index fa2671fd1b..06c25165b0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -22,5 +22,4 @@ testtools>=0.9.36,!=1.2.0 tempest-lib>=0.5.0 # vmwareapi driver specific dependencies -suds>=0.4 oslo.vmware>=0.11.1 # Apache-2.0