Merge "Update code to pass pep8 under python 3"

This commit is contained in:
Zuul 2018-05-03 13:09:03 +00:00 committed by Gerrit Code Review
commit f414212d79
6 changed files with 24 additions and 26 deletions

View File

@ -39,7 +39,7 @@ class DragonflowException(Exception):
if six.PY2: if six.PY2:
def __unicode__(self): def __unicode__(self):
return unicode(self.msg) return six.text_type(self.msg)
def __str__(self): def __str__(self):
return self.msg return self.msg

View File

@ -45,8 +45,8 @@ class RejectRules(ctypes.Structure):
self.version_eq_given, self.version_gt_given, self.version_eq_given, self.version_gt_given,
self.given_version) self.given_version)
def __cmp__(self, other): def __lt__(self, other):
return cmp(self._as_tuple(), other._as_tuple()) return self._as_tuple() < other._as_tuple()
def __repr__(self): def __repr__(self):
return 'ramcloud.RejectRules(%s)' % str(self._as_tuple()) return 'ramcloud.RejectRules(%s)' % str(self._as_tuple())

View File

@ -11,6 +11,7 @@
# under the License. # under the License.
import crc16 import crc16
import six
RedisClusterHashSlots = 16384 RedisClusterHashSlots = 16384
@ -21,7 +22,7 @@ def key2slot(key):
This also works for binary keys that is used in python 3. This also works for binary keys that is used in python 3.
""" """
k = unicode(key) k = six.text_type(key)
start = k.find("{") start = k.find("{")
if start > -1: if start > -1:

View File

@ -10,9 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import sys
from oslo_log import log from oslo_log import log
from oslo_utils import excutils
from dragonflow.tests.common import app_testing_objects from dragonflow.tests.common import app_testing_objects
from dragonflow.tests.common import utils as test_utils from dragonflow.tests.common import utils as test_utils
@ -46,12 +45,10 @@ class TestApps(test_base.DFTestBase):
['ovsdb-client', 'dump', 'Open_vSwitch'], ['ovsdb-client', 'dump', 'Open_vSwitch'],
True True
) )
except Exception as e: except Exception:
traceback = sys.exc_info()[2] with excutils.save_and_reraise_exception():
try: try:
topology.close() topology.close()
except Exception: except Exception:
pass # Ignore pass # Ignore
# Just calling raise may raise an exception from topology.close()
raise e, None, traceback
topology.close() topology.close()

View File

@ -416,13 +416,13 @@ class TestDbTableMonitors(PubSubTestBase):
} }
expected_event = { expected_event = {
'table': unicode('chassis'), 'table': six.text_type('chassis'),
'key': unicode('chassis-1'), 'key': six.text_type('chassis-1'),
'action': unicode('create'), 'action': six.text_type('create'),
'value': None, 'value': None,
} }
self.assertNotIn(expected_event, self.namespace.events) self.assertNotIn(expected_event, self.namespace.events)
expected_event['value'] = unicode(jsonutils.dumps(test_chassis)) expected_event['value'] = six.text_type(jsonutils.dumps(test_chassis))
self.assertNotIn(expected_event, self.namespace.events) self.assertNotIn(expected_event, self.namespace.events)
self.nb_api.driver.create_key( self.nb_api.driver.create_key(
'chassis', 'chassis',
@ -435,13 +435,13 @@ class TestDbTableMonitors(PubSubTestBase):
test_chassis["ip"] = "2.3.4.5" test_chassis["ip"] = "2.3.4.5"
expected_event = { expected_event = {
'table': unicode('chassis'), 'table': six.text_type('chassis'),
'key': unicode('chassis-1'), 'key': six.text_type('chassis-1'),
'action': unicode('set'), 'action': six.text_type('set'),
'value': None, 'value': None,
} }
self.assertNotIn(expected_event, self.namespace.events) self.assertNotIn(expected_event, self.namespace.events)
expected_event['value'] = unicode(jsonutils.dumps(test_chassis)) expected_event['value'] = six.text_type(jsonutils.dumps(test_chassis))
self.assertNotIn(expected_event, self.namespace.events) self.assertNotIn(expected_event, self.namespace.events)
self.nb_api.driver.set_key( self.nb_api.driver.set_key(
'chassis', 'chassis',
@ -453,9 +453,9 @@ class TestDbTableMonitors(PubSubTestBase):
self.assertIn(expected_event, self.namespace.events) self.assertIn(expected_event, self.namespace.events)
expected_event = { expected_event = {
'table': unicode('chassis'), 'table': six.text_type('chassis'),
'key': unicode('chassis-1'), 'key': six.text_type('chassis-1'),
'action': unicode('delete'), 'action': six.text_type('delete'),
'value': None, 'value': None,
} }
self.assertNotIn(expected_event, self.namespace.events) self.assertNotIn(expected_event, self.namespace.events)