Change render_unsets default to False

The API WSME Types all inherit a to_dict method that accepts as a parameter
render_unsets. It is currently set to True by default but should be False for
consistency and also because it just makes better sense. This has caused some
unnecessary workarounds and work before it was known this existed.

Closes-Bug: 1555493
Change-Id: Idd21a003c0b1e3092f979013f8c19d75f17d0249
This commit is contained in:
Brandon Logan 2016-03-10 00:17:30 -06:00
parent 972cdba6ee
commit 89335a3851
8 changed files with 20 additions and 18 deletions

View File

@ -104,7 +104,7 @@ class HealthMonitorController(base.BaseController):
except exceptions.NotFound:
pass
hm_dict = db_prepare.create_health_monitor(
health_monitor.to_dict(), self.pool_id)
health_monitor.to_dict(render_unsets=True), self.pool_id)
self._test_lb_and_listener_statuses(context.session)
try:

View File

@ -78,7 +78,7 @@ class L7PolicyController(base.BaseController):
"""Creates a l7policy on a listener."""
context = pecan.request.context.get('octavia_context')
l7policy_dict = validate.sanitize_l7policy_api_args(
l7policy.to_dict(), create=True)
l7policy.to_dict(render_unsets=True), create=True)
# Make sure any pool specified by redirect_pool_id exists
if 'redirect_pool_id' in l7policy_dict.keys():
self._get_db_pool(

View File

@ -89,8 +89,8 @@ class L7RuleController(base.BaseController):
raise exceptions.L7RuleValidation(error=e)
context = pecan.request.context.get('octavia_context')
self._check_l7policy_max_rules(context.session)
l7rule_dict = db_prepare.create_l7rule(l7rule.to_dict(),
self.l7policy_id)
l7rule_dict = db_prepare.create_l7rule(
l7rule.to_dict(render_unsets=True), self.l7policy_id)
self._test_lb_and_listener_statuses(context.session)
try:
@ -127,11 +127,9 @@ class L7RuleController(base.BaseController):
"""Updates a l7rule."""
context = pecan.request.context.get('octavia_context')
db_l7rule = self._get_db_l7rule(context.session, id)
new_l7rule_dict = db_l7rule.to_dict()
for k, v in l7rule.to_dict().items():
if v is not None:
new_l7rule_dict.update({k: v})
new_l7rule = data_models.L7Rule(**new_l7rule_dict)
new_l7rule = db_l7rule.to_dict()
new_l7rule.update(l7rule.to_dict())
new_l7rule = data_models.L7Rule.from_dict(new_l7rule)
try:
validate.l7rule_data(new_l7rule)
except Exception as e:

View File

@ -160,7 +160,7 @@ class ListenersController(base.BaseController):
self._secure_data(listener)
context = pecan.request.context.get('octavia_context')
listener_dict = db_prepare.create_listener(
listener.to_dict(), self.load_balancer_id)
listener.to_dict(render_unsets=True), self.load_balancer_id)
if listener_dict['default_pool_id']:
self._validate_pool(context.session,
listener_dict['default_pool_id'])
@ -181,7 +181,7 @@ class ListenersController(base.BaseController):
context = pecan.request.context.get('octavia_context')
db_listener = self._get_db_listener(context.session, id)
listener_dict = listener.to_dict()
if listener_dict['default_pool_id']:
if listener_dict.get('default_pool_id'):
self._validate_pool(context.session,
listener_dict['default_pool_id'])
self._test_lb_and_listener_statuses(context.session, id=id)

View File

@ -74,7 +74,7 @@ class LoadBalancersController(base.BaseController):
def _create_load_balancer_graph(self, context, load_balancer):
prepped_lb = db_prepare.create_load_balancer_tree(
load_balancer.to_dict())
load_balancer.to_dict(render_unsets=True))
try:
db_lb = self.repositories.create_load_balancer_tree(
context.session, prepped_lb)
@ -100,7 +100,9 @@ class LoadBalancersController(base.BaseController):
context = pecan.request.context.get('octavia_context')
if load_balancer.listeners:
return self._create_load_balancer_graph(context, load_balancer)
lb_dict = db_prepare.create_load_balancer(load_balancer.to_dict())
lb_dict = db_prepare.create_load_balancer(load_balancer.to_dict(
render_unsets=True
))
vip_dict = lb_dict.pop('vip', {})
try:
db_lb = self.repositories.create_load_balancer_and_vip(

View File

@ -91,7 +91,8 @@ class MembersController(base.BaseController):
def post(self, member):
"""Creates a pool member on a pool."""
context = pecan.request.context.get('octavia_context')
member_dict = db_prepare.create_member(member.to_dict(), self.pool_id)
member_dict = db_prepare.create_member(member.to_dict(
render_unsets=True), self.pool_id)
self._test_lb_and_listener_statuses(context.session)
try:

View File

@ -140,7 +140,7 @@ class PoolsController(base.BaseController):
# For some API requests the listener_id will be passed in the
# pool_dict:
context = pecan.request.context.get('octavia_context')
pool_dict = db_prepare.create_pool(pool.to_dict())
pool_dict = db_prepare.create_pool(pool.to_dict(render_unsets=True))
if 'listener_id' in pool_dict:
if pool_dict['listener_id'] is not None:
self.listener_id = pool_dict.pop('listener_id')

View File

@ -65,7 +65,7 @@ class BaseType(wtypes.Base):
"""
return cls(**data_model.to_dict())
def to_dict(self, render_unsets=True):
def to_dict(self, render_unsets=False):
"""Converts Octavia WSME type to dictionary.
:param render_unsets: If True, will convert items that are WSME Unset
@ -79,9 +79,10 @@ class BaseType(wtypes.Base):
if value and callable(value):
continue
if value and isinstance(value, BaseType):
value = value.to_dict()
value = value.to_dict(render_unsets=render_unsets)
if value and isinstance(value, list):
value = [val.to_dict() if isinstance(val, BaseType) else val
value = [val.to_dict(render_unsets=render_unsets)
if isinstance(val, BaseType) else val
for val in value]
if isinstance(value, wtypes.UnsetType):
if render_unsets: