commit e4a13c34deae216de23cd0c5ba6c337da704a4d7 Author: Yuxing Jiang Date: Fri Sep 25 17:46:58 2020 -0400 Preserve quotations when loading yaml using ruamel.yaml RoundTripLoader in ruamel.yaml will omit superfluous quotation marks. In some cases, the result by loading a yaml with and dumping it out will be unreadable by PyYAML. For example, the pattern: hosts: ["mon-logstash:port"] will be transformed to: hosts: [mon-logstash:port] Currently, the Armada project is using PyYAML. It's better to keep the quotes to allow the following process have to use PyYAML. This commit adds the parameter preserve_quotes=True to the RoundTripLoader to perserve the quotes when loading the original charts. Tested with a fresh install, upload the stx-monitor tarball with right formatted yaml files and successful apply the application. Change-Id: I1fd16b24bfb62ffc3bc885babbf6eb8a9356c421 Depends-on: https://review.opendev.org/#/c/754501/ Partial-Bug: 1896530 Signed-off-by: Yuxing Jiang diff --git a/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py b/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py index 807a1ec..6f3a9af 100644 --- a/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py +++ b/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py @@ -536,7 +536,11 @@ class AppOperator(object): if os.path.exists(app_manifest_file): with open(app_manifest_file, 'r') as f: - charts = list(yaml.load_all(f, Loader=yaml.RoundTripLoader)) + # The RoundTripLoader removes the superfluous quotes by default, + # resulting the dumped out charts not readable in Armada. + # Set preserve_quotes=True to preserve all the quotes. + charts = list(yaml.load_all( + f, Loader=yaml.RoundTripLoader, preserve_quotes=True)) for chart in charts: if "armada/Chart/" in chart['schema']: diff --git a/sysinv/sysinv/sysinv/sysinv/helm/manifest_base.py b/sysinv/sysinv/sysinv/sysinv/helm/manifest_base.py index cd9c38f..6931dfe 100644 --- a/sysinv/sysinv/sysinv/sysinv/helm/manifest_base.py +++ b/sysinv/sysinv/sysinv/sysinv/helm/manifest_base.py @@ -94,8 +94,11 @@ class ArmadaManifestOperator(object): if os.path.exists(summary_fqpn): self.manifest_path = os.path.dirname(summary_fqpn) with open(summary_fqpn, 'r') as f: + # The RoundTripLoader removes the superfluous quotes by default, + # resulting the dumped out charts not readable in Armada. + # Set preserve_quotes=True to preserve all the quotes. files_written = list(yaml.load_all( - f, Loader=yaml.RoundTripLoader))[0] + f, Loader=yaml.RoundTripLoader, preserve_quotes=True))[0] return files_written def load(self, manifest_fqpn): @@ -111,8 +114,11 @@ class ArmadaManifestOperator(object): self.delete_manifest = "%s-del%s" % os.path.splitext(manifest_fqpn) with open(manifest_fqpn, 'r') as f: + # The RoundTripLoader removes the superfluous quotes by default, + # resulting the dumped out charts not readable in Armada. + # Set preserve_quotes=True to preserve all the quotes. self.content = list(yaml.load_all( - f, Loader=yaml.RoundTripLoader)) + f, Loader=yaml.RoundTripLoader, preserve_quotes=True)) # Generate the lookup tables # For the individual chart docs