From 35ee53216776e571ef5f2dc70219d9d5b123370f Mon Sep 17 00:00:00 2001 From: Nicholas Jones Date: Fri, 10 Feb 2017 09:43:30 -0600 Subject: [PATCH] Switch and/or to ternary operator Since version 2.5 Python has had an official ternary operator, this commit switches out the old and/or style for the more predictable and readable official version. Partial-Bug: #1663631 Change-Id: I064d842a6869d50fe232c7edf2b2202933027ec6 --- cinder/api/contrib/hosts.py | 2 +- cinder/api/contrib/services.py | 2 +- cinder/test.py | 2 +- cinder/tests/unit/volume/test_volume_migration.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cinder/api/contrib/hosts.py b/cinder/api/contrib/hosts.py index 31c2ed47943..a1855bf8e38 100644 --- a/cinder/api/contrib/hosts.py +++ b/cinder/api/contrib/hosts.py @@ -51,7 +51,7 @@ def _list_hosts(req, service=None): for host in services: delta = curr_time - (host.updated_at or host.created_at) alive = abs(delta.total_seconds()) <= CONF.service_down_time - status = (alive and "available") or "unavailable" + status = "available" if alive else "unavailable" active = 'enabled' if host.disabled: active = 'disabled' diff --git a/cinder/api/contrib/services.py b/cinder/api/contrib/services.py index d69ea07d500..23cae982194 100644 --- a/cinder/api/contrib/services.py +++ b/cinder/api/contrib/services.py @@ -77,7 +77,7 @@ class ServiceController(wsgi.Controller): if abs(delta_sec) >= abs(delta_mod.total_seconds()): updated_at = svc.modified_at alive = abs(delta_sec) <= CONF.service_down_time - art = (alive and "up") or "down" + art = "up" if alive else "down" active = 'enabled' if svc.disabled: active = 'disabled' diff --git a/cinder/test.py b/cinder/test.py index 2972a9f476b..99f0de6dfea 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -302,7 +302,7 @@ class TestCase(testtools.TestCase): self.override_config(k, v) def start_service(self, name, host=None, **kwargs): - host = host and host or uuid.uuid4().hex + host = host if host else uuid.uuid4().hex kwargs.setdefault('host', host) kwargs.setdefault('binary', 'cinder-%s' % name) svc = service.Service.create(**kwargs) diff --git a/cinder/tests/unit/volume/test_volume_migration.py b/cinder/tests/unit/volume/test_volume_migration.py index 916a3dce888..4e885a7ad58 100644 --- a/cinder/tests/unit/volume/test_volume_migration.py +++ b/cinder/tests/unit/volume/test_volume_migration.py @@ -532,7 +532,7 @@ class VolumeMigrationTestCase(base.BaseVolumeTestCase): retyping=False, previous_status='available'): - initial_status = retyping and 'retyping' or status + initial_status = 'retyping' if retyping else status old_volume = tests_utils.create_volume(self.context, size=0, host=CONF.host, status=initial_status,