Prevent KeyError when getting value of optional key

Closes-Bug: #2066115
Change-Id: Ica10eb749b48410583cb34bfa2fda0433a26c664
Signed-off-by: MinhNLH2 <minh.nlh.work@gmail.com>
This commit is contained in:
MinhNLH2 2024-05-19 20:58:47 +07:00
parent 47823cce7c
commit fcce68a914
5 changed files with 8 additions and 11 deletions

View File

@ -180,7 +180,7 @@ class CreateAggregateWorkflow(workflows.Workflow):
api.nova.aggregate_create(
request,
name=context['name'],
availability_zone=context['availability_zone'] or None)
availability_zone=context.get('availability_zone') or None)
except Exception:
exceptions.handle(request, _('Unable to create host aggregate.'))
return False

View File

@ -109,8 +109,8 @@ class CreateApplicationCredentialForm(forms.SelfHandlingForm):
new_app_cred = api.keystone.application_credential_create(
request,
name=data['name'],
description=data['description'] or None,
secret=data['secret'] or None,
description=data.get('description') or None,
secret=data.get('secret') or None,
expires_at=expiration or None,
roles=roles,
access_rules=access_rules,

View File

@ -162,8 +162,6 @@ class CreateUserForm(PasswordMixin, BaseUserForm, AddExtraColumnMixIn):
try:
LOG.info('Creating user with name "%s"', data['name'])
desc = data["description"]
if "email" in data:
data['email'] = data['email'] or None
# add extra information
EXTRA_INFO = settings.USER_TABLE_EXTRA_INFO
@ -176,10 +174,10 @@ class CreateUserForm(PasswordMixin, BaseUserForm, AddExtraColumnMixIn):
new_user = \
api.keystone.user_create(request,
name=data['name'],
email=data['email'],
email=data.get('email') or None,
description=desc or None,
password=data['password'],
project=data['project'] or None,
project=data.get('project') or None,
enabled=data['enabled'],
domain=domain.id,
**kwargs)

View File

@ -87,7 +87,7 @@ class UpdateInstanceInfoAction(workflows.Action):
api.nova.server_update(request,
data['instance_id'],
data['name'],
description=data.get('description'))
description=data.get('description') or None)
except Exception:
exceptions.handle(request, ignore=True)
return False

View File

@ -81,9 +81,8 @@ class UpdateView(workflows.WorkflowView):
for key in ('cidr', 'ip_version', 'enable_dhcp'):
initial[key] = subnet[key]
initial['gateway_ip'] = subnet['gateway_ip'] or ''
initial['no_gateway'] = (subnet['gateway_ip'] is None)
initial['gateway_ip'] = subnet.get('gateway_ip', '')
initial['no_gateway'] = not initial['gateway_ip']
if initial['ip_version'] == 6:
initial['ipv6_modes'] = utils.get_ipv6_modes_menu_from_attrs(
subnet['ipv6_ra_mode'], subnet['ipv6_address_mode'])