]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove Python 2.6 backwards compatibility code
authorgit-harry <git-harry@live.co.uk>
Tue, 25 Nov 2014 22:40:37 +0000 (22:40 +0000)
committergit-harry <git-harry@live.co.uk>
Wed, 26 Nov 2014 08:14:34 +0000 (08:14 +0000)
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
cinder/api/contrib/services.py
cinder/test.py
cinder/tests/test_storwize_svc.py
cinder/utils.py

index 47bd6b06fef4bb565fe68d6e790dd32a51344769..35f2c81aecb62a13bb0a3dd6114e6ba4cdef7ec8 100644 (file)
@@ -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']:
index 0e58d65f2440209c41495afc073ca0f38f31fec4..318774f9215febb934b47186905d0bdb6da4b2e2 100644 (file)
@@ -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']:
index 1f64ccc28f510a288cc992a170fd04b977250e15..f487468a0fa6f1648dee5c0bf8ed6c2b45068f17 100644 (file)
@@ -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)
index 0baed6a051410bee652ec0a3e4a06a8c259d0437..5e74244b70a0d3b430a0158ceca5211624a9c64a 100644 (file)
@@ -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()
index 15ee88b836dead63a4dcfdf408396eaaa6c12b31..eca0d9121144487ef6e2a3dd4ad439699e0dc134 100644 (file)
@@ -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