remove null_safe_int from module scope
The null_safe_int implementation is not a fortunate one as it returns empty string when called with None. This can be dangerous as it is not a int. However there is no generic good value to return so this cannot be really fixed. Currently the null_safe_int is only used to convert the progress field of the Instance object into the legacy instance notifications. This patch proposes no to break that legacy behavior but also discurage the usage of this convesion in general by removing null_safe_int from the module scope and inlining to the the only place it is used. Change-Id: I58b1c128c27d5ae7922eead95f808ea77b3fcd06
This commit is contained in:
parent
d804819f5b
commit
45ad7f3a28
@ -391,10 +391,6 @@ def null_safe_str(s):
|
||||
return str(s) if s else ''
|
||||
|
||||
|
||||
def null_safe_int(s):
|
||||
return int(s) if s else ''
|
||||
|
||||
|
||||
def null_safe_isotime(s):
|
||||
if isinstance(s, datetime.datetime):
|
||||
return utils.strtime(s)
|
||||
@ -475,7 +471,11 @@ def info_from_instance(context, instance, network_info,
|
||||
# Status properties
|
||||
state=instance.vm_state,
|
||||
state_description=null_safe_str(instance.task_state),
|
||||
progress=null_safe_int(instance.progress),
|
||||
# NOTE(gibi): It might seems wrong to default the progress to an empty
|
||||
# string but this is how legacy work and this code only used by the
|
||||
# legacy notification so try to keep the compatibility here but also
|
||||
# keep it contained.
|
||||
progress=int(instance.progress) if instance.progress else '',
|
||||
|
||||
# accessIPs
|
||||
access_ip_v4=instance.access_ip_v4,
|
||||
|
@ -39,14 +39,6 @@ class TestNullSafeUtils(test.NoDBTestCase):
|
||||
line = 'test'
|
||||
self.assertEqual(line, base.null_safe_str(line))
|
||||
|
||||
def test_null_safe_int(self):
|
||||
number = None
|
||||
# TODO(gibi): Fix null_safe_int to return 0 as default instead of empty
|
||||
# string
|
||||
self.assertEqual('', base.null_safe_int(number))
|
||||
number = 10
|
||||
self.assertEqual(number, base.null_safe_int(number))
|
||||
|
||||
|
||||
class TestSendInstanceUpdateNotification(test.NoDBTestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user