From d3875eab55c014d33ebefed2052f4f77d318ddf0 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 27 Apr 2017 17:02:03 +0100 Subject: [PATCH] trivial: Remove dead code The following functions are unused by anything but tests, or are only used in one place and don't merit being in a utils module: - xhtml_escape - check_isinstance Remove or replace them. Change-Id: I5a57a416cb0912ad42fe8cdd6cf264020bdf2652 --- nova/tests/unit/test_utils.py | 23 ----------------------- nova/utils.py | 28 +--------------------------- nova/virt/driver.py | 9 +++++++-- 3 files changed, 8 insertions(+), 52 deletions(-) diff --git a/nova/tests/unit/test_utils.py b/nova/tests/unit/test_utils.py index cbd13c305543..60b40c3c6b0f 100644 --- a/nova/tests/unit/test_utils.py +++ b/nova/tests/unit/test_utils.py @@ -170,14 +170,6 @@ class GenericUtilsTestCase(test.NoDBTestCase): self.assertEqual(fake_execute.uid, 2) self.assertEqual(fake_execute.uid, os.getuid()) - def test_xhtml_escape(self): - self.assertEqual('"foo"', utils.xhtml_escape('"foo"')) - self.assertEqual(''foo'', utils.xhtml_escape("'foo'")) - self.assertEqual('&', utils.xhtml_escape('&')) - self.assertEqual('>', utils.xhtml_escape('>')) - self.assertEqual('<', utils.xhtml_escape('<')) - self.assertEqual('<foo>', utils.xhtml_escape('')) - def test_get_shortened_ipv6(self): self.assertEqual("abcd:ef01:2345:6789:abcd:ef01:c0a8:fefe", utils.get_shortened_ipv6( @@ -247,21 +239,6 @@ class GenericUtilsTestCase(test.NoDBTestCase): cmd = utils.get_root_helper() self.assertEqual('sudo nova-rootwrap foo', cmd) - @mock.patch('nova.utils.RootwrapProcessHelper') - def test_get_root_helper_proc(self, mock_proc_helper): - self.flags(use_rootwrap_daemon=False) - self.flags(rootwrap_config="/path/to/conf") - utils._get_rootwrap_helper() - mock_proc_helper.assert_called_once_with() - - @mock.patch('nova.utils.RootwrapDaemonHelper') - def test_get_root_helper_daemon(self, mock_daemon_helper): - conf_path = '/path/to/conf' - self.flags(use_rootwrap_daemon=True) - self.flags(rootwrap_config=conf_path) - utils._get_rootwrap_helper() - mock_daemon_helper.assert_called_once_with(conf_path) - def test_use_sudo(self): self.flags(disable_rootwrap=True, group='workarounds') cmd = utils.get_root_helper() diff --git a/nova/utils.py b/nova/utils.py index 3a466652f449..9551b795ffe8 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -35,7 +35,6 @@ import sys import tempfile import textwrap import time -from xml.sax import saxutils import eventlet import netaddr @@ -163,13 +162,6 @@ def get_root_helper(): return cmd -def _get_rootwrap_helper(): - if CONF.use_rootwrap_daemon: - return RootwrapDaemonHelper(CONF.rootwrap_config) - else: - return RootwrapProcessHelper() - - class RootwrapProcessHelper(object): def trycmd(self, *cmd, **kwargs): kwargs['root_helper'] = get_root_helper() @@ -330,11 +322,6 @@ DEFAULT_PASSWORD_SYMBOLS = ('23456789', # Removed: 0,1 'abcdefghijkmnopqrstuvwxyz') # Removed: l -# ~5 bits per symbol -EASIER_PASSWORD_SYMBOLS = ('23456789', # Removed: 0, 1 - 'ABCDEFGHJKLMNPQRSTUVWXYZ') # Removed: I, O - - def last_completed_audit_period(unit=None, before=None): """This method gives you the most recently *completed* audit period. @@ -480,13 +467,7 @@ def get_my_linklocal(interface): raise exception.NovaException(msg) -def xhtml_escape(value): - """Escapes a string so it is valid within XML or XHTML. - - """ - return saxutils.escape(value, {'"': '"', "'": '''}) - - +# TODO(sfinucan): Replace this with the equivalent from oslo.utils def utf8(value): """Try to turn a string into utf-8 if possible. @@ -503,13 +484,6 @@ def utf8(value): return value.encode('utf-8') -def check_isinstance(obj, cls): - """Checks that obj is of type cls, and lets PyLint infer types.""" - if isinstance(obj, cls): - return obj - raise Exception(_('Expected object of type: %s') % (str(cls))) - - def parse_server_string(server_str): """Parses the given server_string and returns a tuple of host and port. If it's not a combination of host part and port, the port element diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 07d0b941e660..4858b2e9c0e3 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -28,7 +28,6 @@ import six import nova.conf from nova.i18n import _, _LE, _LI -from nova import utils from nova.virt import event as virtevent CONF = nova.conf.CONF @@ -1624,10 +1623,16 @@ def load_compute_driver(virtapi, compute_driver=None): driver = importutils.import_object( 'nova.virt.%s' % compute_driver, virtapi) - return utils.check_isinstance(driver, ComputeDriver) + if isinstance(driver, ComputeDriver): + return driver + raise ValueError() except ImportError: LOG.exception(_LE("Unable to load the virtualization driver")) sys.exit(1) + except ValueError: + LOG.exception("Compute driver '%s' from 'nova.virt' is not of type" + "'%s'", compute_driver, str(ComputeDriver)) + sys.exit(1) def is_xenapi():