make net_config_override of undercloud.conf work with yaml

On setting net_config_override parameter, the undercloud uses
a JSON or YAML format template to configure the networking
with os-net-config and ignores the network parameters set in
undercloud.conf. We can use this parameter when we want to
configure bonding or add an option to the interface.

This patch will allow net_config_override to work with a json
or a yaml as an input.

Closes-Bug: #1927090
Change-Id: I5f5cec5a1622be4983b4d0db392453d1c489fa40
(cherry picked from commit 253bd6e7db)
(cherry picked from commit 06a82e0ebf)
(cherry picked from commit aa9996e139)
This commit is contained in:
Srinivas Atmakuri 2021-05-04 17:15:32 +05:30 committed by Steve Baker
parent c13638dcb1
commit a6fcdbf0df
2 changed files with 6 additions and 6 deletions

View File

@ -130,16 +130,16 @@ class StandaloneConfig(BaseConfig):
cfg.StrOpt('net_config_override', cfg.StrOpt('net_config_override',
default='', default='',
help=_( help=_(
'Path to network config override template.' 'Path to network config override template. '
'Relative paths get computed inside of $HOME. ' 'Relative paths get computed inside of $HOME. '
'Must be in the json format.' 'Must be in the json or yaml format. '
'Its content overrides anything in t-h-t ' 'Its content overrides anything in t-h-t '
'<role>NetConfigOverride. The processed ' '<role>NetConfigOverride. The processed '
'template is then passed in Heat via the ' 'template is then passed in Heat via the '
'generated parameters file created in ' 'generated parameters file created in '
'output_dir and used to configure the networking ' 'output_dir and used to configure the networking '
'via run-os-net-config. If you wish to disable ' 'via run-os-net-config. If you wish to disable '
'you can set this location to an empty file.' 'you can set this location to an empty file. '
'Templated for instack j2 tags ' 'Templated for instack j2 tags '
'may be used, ' 'may be used, '
'for example:\n%s ') % NETCONFIG_TAGS_EXAMPLE 'for example:\n%s ') % NETCONFIG_TAGS_EXAMPLE

View File

@ -15,12 +15,12 @@
"""Plugin action implementation""" """Plugin action implementation"""
import json
import logging import logging
import netaddr import netaddr
import os import os
import shutil import shutil
import sys import sys
import yaml
from cryptography import x509 from cryptography import x509
@ -782,9 +782,9 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
os.path.split(data_file)[-1]).render(context).replace( os.path.split(data_file)[-1]).render(context).replace(
"'", '"').replace('&quot;', '"') "'", '"').replace('&quot;', '"')
try: try:
net_config_json = json.loads(net_config_str) net_config_json = yaml.safe_load(net_config_str)
except ValueError: except ValueError:
net_config_json = json.loads("{%s}" % net_config_str) net_config_json = yaml.safe_load("{%s}" % net_config_str)
if 'network_config' not in net_config_json: if 'network_config' not in net_config_json:
msg = ('Unsupported data format in net_config_override ' msg = ('Unsupported data format in net_config_override '