From 1fd911c1b679f29c5ad93c7810916ddc8e7146c9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 29 Jun 2015 15:53:44 +0200 Subject: [PATCH] Port drbdmanagedrv driver to Python 3 * Replace map() with a list-comprehension where a list is expected * Replace apply(fn, args) with fn(*args) * Use str.replace() to remove "{" and "}" characters in _clean_uuid(), instead of using str.translate() * Use literal syntax to create a new dictionary instead of using dict() + dict.items() * tox.ini: add cinder.tests.unit.test_drbdmanagedrv to Python 3.4 Blueprint cinder-python3 Change-Id: I4cb3ae422381442b778de024882e75f31eded5eb --- cinder/tests/unit/test_drbdmanagedrv.py | 4 ++-- cinder/volume/drivers/drbdmanagedrv.py | 9 +++++---- tox.ini | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cinder/tests/unit/test_drbdmanagedrv.py b/cinder/tests/unit/test_drbdmanagedrv.py index 8f91dc606..14cc24552 100644 --- a/cinder/tests/unit/test_drbdmanagedrv.py +++ b/cinder/tests/unit/test_drbdmanagedrv.py @@ -200,13 +200,13 @@ class DrbdManageTestCase(test.TestCase): return None def fake_issue_dbus_call(self, fn, *args): - return apply(fn, args) + return fn(*args) def fake_issue_dbus_connect(self): self.odm = DrbdManageFakeDriver() def call_or_reconnect(self, method, *params): - return apply(method, params) + return method(*params) # Tests per se diff --git a/cinder/volume/drivers/drbdmanagedrv.py b/cinder/volume/drivers/drbdmanagedrv.py index 8350c1239..fcac7901f 100644 --- a/cinder/volume/drivers/drbdmanagedrv.py +++ b/cinder/volume/drivers/drbdmanagedrv.py @@ -138,7 +138,9 @@ class DrbdManageDriver(driver.VolumeDriver): # Some uuid library versions put braces around the result!? # We don't want them, just a plain [0-9a-f-]+ string. id = str(uuid.uuid4()) - return id.translate(None, "{}") + id = id.replace("{", "") + id = id.replace("}", "") + return id def _check_result(self, res, ignore=None, ret=0): seen_success = False @@ -397,8 +399,7 @@ class DrbdManageDriver(driver.VolumeDriver): temp_id = self._clean_uuid() snapshot = {'id': temp_id} - self.create_snapshot(dict(snapshot.items() + - [('volume_id', src_vref['id'])])) + self.create_snapshot({'id': temp_id, 'volume_id': src_vref['id']}) self.create_volume_from_snapshot(volume, snapshot) @@ -468,7 +469,7 @@ class DrbdManageDriver(driver.VolumeDriver): self.empty_dict) self._check_result(res) - nodes = map(lambda d: d[0], data) + nodes = [d[0] for d in data] if len(nodes) < 1: raise exception.VolumeBackendAPIException( _('Snapshot res "%s" that is not deployed anywhere?') % diff --git a/tox.ini b/tox.ini index 144737a4a..0007c5604 100644 --- a/tox.ini +++ b/tox.ini @@ -44,6 +44,7 @@ commands = cinder.tests.unit.test_dellfc \ cinder.tests.unit.test_dellsc \ cinder.tests.unit.test_dellscapi \ + cinder.tests.unit.test_drbdmanagedrv \ cinder.tests.unit.test_emc_xtremio \ cinder.tests.unit.test_eqlx \ cinder.tests.unit.test_evaluator \ -- 2.45.2