Skip to content
Snippets Groups Projects
Commit 620b808c authored by Mark Goddard's avatar Mark Goddard
Browse files

Improve error reporting in password utilities

The kolla-genpwd and kolla-mergepwd commands can be used to manipulate
the kolla passwords.yml file. The format is a YAML encoded dict of
password variable names to their values. If the format is not a dict,
the error messages are unhelpful.  In particular, this can happen if the
file is encrypted e.g. via Ansible Vault.

For kolla-genpwd:

    AttributeError: 'NoneType' object has no attribute 'items'

For kolla-mergepwd:

    AttributeError: 'NoneType' object has no attribute 'update'

This change adds a more friendly message.

Change-Id: I27f0835b904e05006ae401adf383090322e1b891
Closes-Bug: #1880220
parent 8659acb2
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,10 @@ def genpwd(passwords_file, length, uuid_keys, ssh_keys, blank_keys,
with open(passwords_file, 'r') as f:
passwords = yaml.safe_load(f.read())
if not isinstance(passwords, dict):
print("ERROR: Passwords file not in expected key/value format")
sys.exit(1)
for k, v in passwords.items():
if (k in ssh_keys and
(v is None or
......
......@@ -13,6 +13,7 @@
# limitations under the License.
import argparse
import sys
import yaml
......@@ -23,6 +24,14 @@ def mergepwd(old, new, final, clean=False):
with open(new, "r") as new_file:
new_passwords = yaml.safe_load(new_file)
if not isinstance(old_passwords, dict):
print("ERROR: Old passwords file not in expected key/value format")
sys.exit(1)
if not isinstance(new_passwords, dict):
print("ERROR: New passwords file not in expected key/value format")
sys.exit(1)
if clean:
# keep only new keys
for key in new_passwords:
......
---
fixes:
- |
Improves error reporting in ``kolla-genpwd`` and ``kolla-mergepwd`` when
input files are not in the expected format. `LP#1880220
<https://bugs.launchpad.net/kolla-ansible/+bug/1880220>`__.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment