From 10b8ccfdd7ed23726676b1a0a1d868b83e13401f Mon Sep 17 00:00:00 2001 From: git-harry Date: Tue, 25 Nov 2014 22:40:37 +0000 Subject: [PATCH] Remove Python 2.6 backwards compatibility code Python 2.6 is no longer supported in cinder as of kilo. The code in the project that is specifically for compatibility with 2.6 is therefore no longer required. This commit removes code referenced as being required specifically for compatibility with Python 2.6. This commit removes: - total_seconds from cinder/utils.py - TestCase.assertGreater from cinder/test.py - TestCase.assertGreaterEqual from cinder/test.py - StorwizeSVCDriverTestCase.assertLessEqual from cinder/tests/test_storwize_svc.py Change-Id: I2aca4a6a84bc8ddfa70bd47a331b6fac6f82220f --- cinder/api/contrib/hosts.py | 2 +- cinder/api/contrib/services.py | 2 +- cinder/test.py | 23 ----------------------- cinder/tests/test_storwize_svc.py | 5 ----- cinder/utils.py | 11 +---------- 5 files changed, 3 insertions(+), 40 deletions(-) diff --git a/cinder/api/contrib/hosts.py b/cinder/api/contrib/hosts.py index 47bd6b06fef..35f2c81aecb 100644 --- a/cinder/api/contrib/hosts.py +++ b/cinder/api/contrib/hosts.py @@ -107,7 +107,7 @@ def _list_hosts(req, service=None): hosts = [] for host in services: delta = curr_time - (host['updated_at'] or host['created_at']) - alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time + alive = abs(delta.total_seconds()) <= CONF.service_down_time status = (alive and "available") or "unavailable" active = 'enabled' if host['disabled']: diff --git a/cinder/api/contrib/services.py b/cinder/api/contrib/services.py index 0e58d65f244..318774f9215 100644 --- a/cinder/api/contrib/services.py +++ b/cinder/api/contrib/services.py @@ -105,7 +105,7 @@ class ServiceController(wsgi.Controller): svcs = [] for svc in services: delta = now - (svc['updated_at'] or svc['created_at']) - alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time + alive = abs(delta.total_seconds()) <= CONF.service_down_time art = (alive and "up") or "down" active = 'enabled' if svc['disabled']: diff --git a/cinder/test.py b/cinder/test.py index 1f64ccc28f5..f487468a0fa 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -37,7 +37,6 @@ from oslo.utils import strutils from oslo.utils import timeutils import stubout import testtools -from testtools import matchers from cinder.common import config # noqa Need to register global_opts from cinder.db import migration @@ -320,25 +319,3 @@ class TestCase(testtools.TestCase): 'd1value': d1value, 'd2value': d2value, }) - - def assertGreater(self, first, second, msg=None): - """Python < v2.7 compatibility. Assert 'first' > 'second'.""" - try: - f = super(TestCase, self).assertGreater - except AttributeError: - self.assertThat(first, - matchers.GreaterThan(second), - message=msg or '') - else: - f(first, second, msg=msg) - - def assertGreaterEqual(self, first, second, msg=None): - """Python < v2.7 compatibility. Assert 'first' >= 'second'.""" - try: - f = super(TestCase, self).assertGreaterEqual - except AttributeError: - self.assertThat(first, - matchers.Not(matchers.LessThan(second)), - message=msg or '') - else: - f(first, second, msg=msg) diff --git a/cinder/tests/test_storwize_svc.py b/cinder/tests/test_storwize_svc.py index 0baed6a0514..5e74244b70a 100644 --- a/cinder/tests/test_storwize_svc.py +++ b/cinder/tests/test_storwize_svc.py @@ -2382,11 +2382,6 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.driver.delete_volume(clone) self._assert_vol_exists(clone['name'], False) - # Note defined in python 2.6, so define here... - def assertLessEqual(self, a, b, msg=None): - if not a <= b: - self.fail('%s not less than or equal to %s' % (repr(a), repr(b))) - def test_storwize_svc_get_volume_stats(self): self._set_flag('reserved_percentage', 25) stats = self.driver.get_volume_stats() diff --git a/cinder/utils.py b/cinder/utils.py index 15ee88b836d..eca0d912114 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -479,15 +479,6 @@ def make_dev_path(dev, partition=None, base='/dev'): return path -def total_seconds(td): - """Local total_seconds implementation for compatibility with python 2.6.""" - if hasattr(td, 'total_seconds'): - return td.total_seconds() - else: - return ((td.days * 86400 + td.seconds) * 10 ** 6 + - td.microseconds) / 10.0 ** 6 - - def sanitize_hostname(hostname): """Return a hostname which conforms to RFC-952 and RFC-1123 specs.""" if isinstance(hostname, unicode): @@ -512,7 +503,7 @@ def service_is_up(service): """Check whether a service is up based on last heartbeat.""" last_heartbeat = service['updated_at'] or service['created_at'] # Timestamps in DB are UTC. - elapsed = total_seconds(timeutils.utcnow() - last_heartbeat) + elapsed = (timeutils.utcnow() - last_heartbeat).total_seconds() return abs(elapsed) <= CONF.service_down_time