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
This commit is contained in:
parent
387fea043f
commit
35ee532167
cinder
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user