Remove redundant defaults

This change removes some redundant definitions of default values
according to the following three points.

- The get method returns None by default if the key doesn't exist,
  so it is unnecessary to define None explicitly.

- Setting '' as parameter defaults is redundant because we always use
  "if CONF.get('<name>'):" to check whether the parameter is set.

- In oslo.config all options default to None unless the default
  parameter is explicitly set. Thus defining default=None is redundant.

Change-Id: Ib14b24b9054fe4d0efc3e03f9c6683ae999e3202
This commit is contained in:
Takashi Kajinami 2021-06-27 01:07:01 +09:00
parent 0e1b67162c
commit ee1990ef65
8 changed files with 40 additions and 68 deletions

View File

@ -80,12 +80,11 @@ class MinionConfig(StandaloneConfig):
default=['0.pool.ntp.org', '1.pool.ntp.org',
'2.pool.ntp.org', '3.pool.ntp.org'],
help=_('List of ntp servers to use.')),
cfg.StrOpt('minion_timezone', default=None,
cfg.StrOpt('minion_timezone',
help=_('Host timezone to be used. If no timezone is '
'specified, the existing timezone configuration '
'is used.')),
cfg.StrOpt('minion_service_certificate',
default='',
help=_(
'TODO: '
'Certificate file to use for OpenStack service SSL '

View File

@ -130,7 +130,6 @@ class StandaloneConfig(BaseConfig):
'command.')
),
cfg.StrOpt('hieradata_override',
default='',
help=_(
'Path to hieradata override file. Relative paths '
'get computed inside of $HOME. When it points to a '
@ -145,7 +144,6 @@ class StandaloneConfig(BaseConfig):
'require a manual revision.')
),
cfg.StrOpt('net_config_override',
default='',
help=_(
'Path to network config override template. '
'Relative paths get computed inside of $HOME. '
@ -162,19 +160,16 @@ class StandaloneConfig(BaseConfig):
'for example:\n%s ') % NETCONFIG_TAGS_EXAMPLE
),
cfg.StrOpt('templates',
default='',
help=_('The tripleo-heat-templates directory to '
'override')
),
cfg.StrOpt('roles_file',
default=None,
help=_('Roles file to override for heat. May be an '
'absolute path or the path relative to the '
'tripleo-heat-templates directory used for '
'deployment')
),
cfg.StrOpt('networks_file',
default=None,
help=_('Networks file to override for heat. May be an '
'absolute path or the path relative to the '
'tripleo-heat-templates directory used for '
@ -190,7 +185,6 @@ class StandaloneConfig(BaseConfig):
' directly If this is set to false, a '
'containerized version of heat-all is used.')),
cfg.StrOpt('heat_container_image',
default='',
help=_('Custom URL for the heat-all container image to '
'use as part of the undercloud deployment. If '
'not specified, the default "%s" is used. '
@ -199,7 +193,6 @@ class StandaloneConfig(BaseConfig):
'undercloud install.' % DEFAULT_HEAT_CONTAINER)
),
cfg.StrOpt('container_images_file',
default='',
required=False,
help=_(
'REQUIRED if authentication is needed to fetch '
@ -221,7 +214,6 @@ class StandaloneConfig(BaseConfig):
'only by advanced users.')),
# container config bits
cfg.StrOpt('container_registry_mirror',
default='',
help=_(
'An optional container registry mirror that will '
'be used.')

View File

@ -143,7 +143,7 @@ class UndercloudConfig(StandaloneConfig):
default=['0.pool.ntp.org', '1.pool.ntp.org',
'2.pool.ntp.org', '3.pool.ntp.org'],
help=_('List of ntp servers to use.')),
cfg.StrOpt('undercloud_timezone', default=None,
cfg.StrOpt('undercloud_timezone',
help=_('Host timezone to be used. If no timezone is '
'specified, the existing timezone configuration '
'is used.')),
@ -177,7 +177,6 @@ class UndercloudConfig(StandaloneConfig):
'local_ip/local_interface should reside '
'in this subnet.')),
cfg.StrOpt('undercloud_service_certificate',
default='',
help=_(
'Certificate file to use for OpenStack service SSL '
'connections. Setting this enables SSL for the '
@ -209,7 +208,6 @@ class UndercloudConfig(StandaloneConfig):
'trust chain.')
),
cfg.StrOpt('service_principal',
default='',
help=_(
'The kerberos principal for the service that will '
'use the certificate. This is only needed if your '
@ -279,7 +277,6 @@ class UndercloudConfig(StandaloneConfig):
help=_('Enable or disable SELinux during the '
'deployment.')),
cfg.StrOpt('ipa_otp',
default='',
help=_(
'One Time Password to register Undercloud node '
'with an IPA server.')

View File

@ -335,7 +335,7 @@ class TestNetworkSettings(TestBaseNetworkSettings):
undercloud_admin_host='192.168.24.1',
undercloud_public_host='192.168.24.2',
generate_service_certificate=False,
undercloud_service_certificate='')
undercloud_service_certificate=None)
undercloud_config._process_network_args(env)
def test_start_end_all_addresses(self):

View File

@ -2349,8 +2349,8 @@ def check_env_for_proxy(no_proxy_hosts=None):
"""
if no_proxy_hosts is None:
no_proxy_hosts = ['127.0.0.1']
http_proxy = os.environ.get('http_proxy', None)
https_proxy = os.environ.get('https_proxy', None)
http_proxy = os.environ.get('http_proxy')
https_proxy = os.environ.get('https_proxy')
if os.environ.get('no_proxy'):
no_proxy = os.environ.get('no_proxy').split(',')
else:

View File

@ -172,13 +172,11 @@ def prepare_minion_deploy(upgrade=False, no_validations=False,
else:
env_data['SELinuxMode'] = 'permissive'
if CONF.get('minion_ntp_servers', None):
if CONF.get('minion_ntp_servers'):
env_data['NtpServer'] = CONF['minion_ntp_servers']
if CONF.get('minion_timezone', None):
env_data['TimeZone'] = CONF['minion_timezone']
else:
env_data['TimeZone'] = utils.get_local_timezone()
env_data['TimeZone'] = (CONF.get('minion_timezone') or
utils.get_local_timezone())
# TODO(aschultz): fix this logic, look it up out of undercloud-outputs.yaml
env_data['DockerInsecureRegistryAddress'] = [
@ -188,31 +186,25 @@ def prepare_minion_deploy(upgrade=False, no_validations=False,
env_data['ContainerCli'] = CONF['container_cli']
if CONF.get('container_registry_mirror', None):
if CONF.get('container_registry_mirror'):
env_data['DockerRegistryMirror'] = CONF['container_registry_mirror']
# This parameter the IP address used to bind the local container registry
env_data['LocalContainerRegistry'] = CONF['minion_local_ip'].split('/')[0]
if CONF.get('minion_local_ip', None):
if CONF.get('minion_local_ip'):
deploy_args.append('--local-ip=%s' % CONF['minion_local_ip'])
if CONF.get('templates', None):
tht_templates = CONF['templates']
deploy_args.append('--templates=%s' % tht_templates)
else:
tht_templates = THT_HOME
deploy_args.append('--templates=%s' % THT_HOME)
tht_templates = CONF.get('templates') or THT_HOME
deploy_args.append('--templates=%s' % tht_templates)
if CONF.get('roles_file', constants.MINION_ROLES_FILE):
if CONF.get('roles_file'):
deploy_args.append('--roles-file=%s' % CONF['roles_file'])
if CONF.get('networks_file'):
deploy_args.append('--networks-file=%s' % CONF['networks_file'])
else:
deploy_args.append('--networks-file=%s' %
os.path.join(tht_templates,
constants.UNDERCLOUD_NETWORKS_FILE))
networks_file = (CONF.get('networks_file') or
os.path.join(tht_templates,
constants.UNDERCLOUD_NETWORKS_FILE))
deploy_args.append('--networks-file=%s' % networks_file)
if yes:
deploy_args += ['-y']
@ -238,7 +230,7 @@ def prepare_minion_deploy(upgrade=False, no_validations=False,
tht_templates,
"environments/lifecycle/undercloud-upgrade-prepare.yaml")]
if not CONF.get('heat_native', False):
if not CONF.get('heat_native'):
deploy_args.append('--heat-native=False')
else:
deploy_args.append('--heat-native')
@ -281,7 +273,7 @@ def prepare_minion_deploy(upgrade=False, no_validations=False,
utils.makedirs(output_dir)
# TODO(aschultz): move this to a central class
if CONF.get('net_config_override', None):
if CONF.get('net_config_override'):
data_file = CONF['net_config_override']
if os.path.abspath(data_file) != data_file:
data_file = os.path.join(USER_HOME, data_file)
@ -308,7 +300,7 @@ def prepare_minion_deploy(upgrade=False, no_validations=False,
try:
context[tag] = CONF[mapped_value]
except cfg.NoSuchOptError:
context[tag] = env_data.get(mapped_value, None)
context[tag] = env_data.get(mapped_value)
# this returns a unicode string, convert it in into json
net_config_str = net_config_env.get_template(
@ -331,7 +323,7 @@ def prepare_minion_deploy(upgrade=False, no_validations=False,
utils.write_env_file(env_data, params_file, registry_overwrites)
deploy_args += ['-e', params_file]
if CONF.get('hieradata_override', None):
if CONF.get('hieradata_override'):
data_file = CONF['hieradata_override']
if os.path.abspath(data_file) != data_file:
data_file = os.path.join(USER_HOME, data_file)

View File

@ -192,7 +192,7 @@ class DeployOvercloud(command.Command):
# Update parameters from commandline
for param, arg in param_args:
if getattr(args, arg, None) is not None:
if getattr(args, arg) is not None:
parameters[param] = getattr(args, arg)
parameters[

View File

@ -495,20 +495,18 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
else:
env_data['SELinuxMode'] = 'permissive'
if CONF.get('undercloud_ntp_servers', None):
if CONF.get('undercloud_ntp_servers'):
env_data['NtpServer'] = CONF['undercloud_ntp_servers']
if CONF.get('undercloud_timezone', None):
env_data['TimeZone'] = CONF['undercloud_timezone']
else:
env_data['TimeZone'] = utils.get_local_timezone()
env_data['TimeZone'] = (CONF.get('undercloud_timezone') or
utils.get_local_timezone())
if CONF.get('enable_validations', False):
if CONF.get('enable_validations'):
env_data['UndercloudConfigFilePath'] = constants.UNDERCLOUD_CONF_PATH
if not no_validations:
env_data['EnableValidations'] = CONF['enable_validations']
if CONF.get('overcloud_domain_name', None):
if CONF.get('overcloud_domain_name'):
env_data['NeutronDnsDomain'] = CONF['overcloud_domain_name']
deploy_args.append('--local-domain=%s' % CONF['overcloud_domain_name'])
@ -530,7 +528,7 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
env_data['ContainerCli'] = CONF['container_cli']
if CONF.get('container_registry_mirror', None):
if CONF.get('container_registry_mirror'):
env_data['DockerRegistryMirror'] = CONF['container_registry_mirror']
# This parameter the IP address used to bind the local container registry
@ -545,25 +543,19 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
env_data['AdditionalArchitectures'] = \
','.join(CONF['additional_architectures'])
if CONF.get('local_ip', None):
if CONF.get('local_ip'):
deploy_args.append('--local-ip=%s' % CONF['local_ip'])
if CONF.get('templates', None):
tht_templates = CONF['templates']
deploy_args.append('--templates=%s' % tht_templates)
else:
tht_templates = THT_HOME
deploy_args.append('--templates=%s' % THT_HOME)
tht_templates = CONF.get('templates') or THT_HOME
deploy_args.append('--templates=%s' % tht_templates)
if CONF.get('roles_file', constants.UNDERCLOUD_ROLES_FILE):
if CONF.get('roles_file'):
deploy_args.append('--roles-file=%s' % CONF['roles_file'])
if CONF.get('networks_file'):
deploy_args.append('--networks-file=%s' % CONF['networks_file'])
else:
deploy_args.append('--networks-file=%s' %
os.path.join(tht_templates,
constants.UNDERCLOUD_NETWORKS_FILE))
networks_file = (CONF.get('networks_file') or
os.path.join(tht_templates,
constants.UNDERCLOUD_NETWORKS_FILE))
deploy_args.append('--networks-file=%s' % networks_file)
if yes:
deploy_args += ['-y']
@ -718,7 +710,7 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
admin_ip = netaddr.IPAddress(admin_host)
deploy_args += ['--control-virtual-ip', admin_host]
if not CONF.get('net_config_override', None):
if not CONF.get('net_config_override'):
if (admin_ip not in local_net.cidr or
public_ip not in local_net.cidr):
LOG.warning('undercloud_admin_host or undercloud_public_host '
@ -741,7 +733,7 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
if CONF.get('cleanup'):
deploy_args.append('--cleanup')
if CONF.get('net_config_override', None):
if CONF.get('net_config_override'):
data_file = CONF['net_config_override']
if os.path.abspath(data_file) != data_file:
data_file = os.path.join(USER_HOME, data_file)
@ -776,7 +768,7 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
try:
context[tag] = CONF[mapped_value]
except cfg.NoSuchOptError:
context[tag] = env_data.get(mapped_value, None)
context[tag] = env_data.get(mapped_value)
# this returns a unicode string, convert it in into json
net_config_str = net_config_env.get_template(
@ -799,7 +791,7 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
utils.write_env_file(env_data, params_file, registry_overwrites)
deploy_args += ['-e', params_file]
if CONF.get('hieradata_override', None):
if CONF.get('hieradata_override'):
data_file = CONF['hieradata_override']
if os.path.abspath(data_file) != data_file:
data_file = os.path.join(USER_HOME, data_file)