Treat null admin_state_up as False
This patch changes the to_dict function for the API obj, if the user pass null into admin_state_up to request. We treat it as False. Depends-On: https://review.openstack.org/#/c/583413/ Story: 2002927 Task: 22914 Change-Id: Iab79b422983f6b2124837fd9ebe60a85b0516f41
This commit is contained in:
parent
7edad93909
commit
0e13939769
|
@ -168,6 +168,12 @@ class BaseType(wtypes.Base):
|
|||
if (isinstance(self.project_id, wtypes.UnsetType) and
|
||||
not isinstance(self.tenant_id, wtypes.UnsetType)):
|
||||
self.project_id = self.tenant_id
|
||||
if hasattr(self, 'admin_state_up') and getattr(
|
||||
self, 'admin_state_up') is None:
|
||||
# This situation will be hit during request with
|
||||
# admin_state_up is null. If users specify this field to null,
|
||||
# then we treat it as False
|
||||
self.admin_state_up = bool(self.admin_state_up)
|
||||
wsme_dict = {}
|
||||
for attr in dir(self):
|
||||
if attr.startswith('_'):
|
||||
|
|
|
@ -20,11 +20,13 @@ from octavia.tests.unit import base
|
|||
class TestTypeRename(types.BaseType):
|
||||
_type_to_model_map = {'renamed': 'original',
|
||||
'child_one': 'child.one',
|
||||
'child_two': 'child.two'}
|
||||
'child_two': 'child.two',
|
||||
'admin_state_up': 'enabled'}
|
||||
id = wtypes.wsattr(wtypes.StringType())
|
||||
renamed = wtypes.wsattr(wtypes.StringType())
|
||||
child_one = wtypes.wsattr(wtypes.StringType())
|
||||
child_two = wtypes.wsattr(wtypes.StringType())
|
||||
admin_state_up = wtypes.wsattr(bool)
|
||||
|
||||
|
||||
class TestTypeRenameSubset(types.BaseType):
|
||||
|
@ -49,10 +51,11 @@ class ChildTestModel(data_models.BaseDataModel):
|
|||
|
||||
class TestModel(data_models.BaseDataModel):
|
||||
|
||||
def __init__(self, id=None, original=None, child=None):
|
||||
def __init__(self, id=None, original=None, child=None, enabled=None):
|
||||
self.id = id
|
||||
self.original = original
|
||||
self.child = child
|
||||
self.enabled = enabled
|
||||
|
||||
def to_dict(self):
|
||||
result = super(TestModel, self).to_dict()
|
||||
|
@ -111,6 +114,14 @@ class TestTypeDataModelRenames(base.TestCase):
|
|||
self.assertEqual('1234', type_dict['project_id'])
|
||||
self.assertNotIn('tenant_id', type_dict)
|
||||
|
||||
def test_type_to_dict_when_admin_state_up_is_null(self):
|
||||
rtype = TestTypeRename(id='1234', renamed='turtles',
|
||||
child_one='baby_turtle_one',
|
||||
child_two='baby_turtle_two',
|
||||
admin_state_up=None)
|
||||
rtype_dict = rtype.to_dict()
|
||||
self.assertFalse(rtype_dict['enabled'])
|
||||
|
||||
|
||||
class TestToDictModel(data_models.BaseDataModel):
|
||||
def __init__(self, text, parent=None):
|
||||
|
|
Loading…
Reference in New Issue