diff options
| author | Marcin Juszkiewicz <marcin.juszkiewicz+kolla@linaro.org> | 2022-05-24 13:18:20 +0200 |
|---|---|---|
| committer | Marcin Juszkiewicz <marcin.juszkiewicz+kolla@linaro.org> | 2022-05-24 13:18:20 +0200 |
| commit | 333c74feb400d81e8c7cb3b4f529dd6d2510b586 (patch) | |
| tree | 024c919f288db0d1bc4a19307cde83e38e18d685 /kolla_ansible | |
| parent | 5d28a7c89bbac4a15f7d8f7a64c3767ea988efbd (diff) | |
| download | kolla-ansible-333c74feb400d81e8c7cb3b4f529dd6d2510b586.tar.gz kolla-ansible-333c74feb400d81e8c7cb3b4f529dd6d2510b586.zip | |
genpwd: handle lack of password file nicer
From:
(kolla) 13:11 (s) marcin@puchatek:kolla-ansible$ kolla-genpwd
Traceback (most recent call last):
File "/home/marcin/.virtualenvs/kolla/bin/kolla-genpwd", line 8, in <module>
sys.exit(main())
File "/home/marcin/.virtualenvs/kolla/lib/python3.10/site-packages/kolla_ansible/cmd/genpwd.py", line 135, in main
genpwd(passwords_file, length, uuid_keys, ssh_keys, blank_keys,
File "/home/marcin/.virtualenvs/kolla/lib/python3.10/site-packages/kolla_ansible/cmd/genpwd.py", line 59, in genpwd
with open(passwords_file, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/etc/kolla/passwords.yml'
To:
(kolla) 13:17 (s) marcin@puchatek:kolla-ansible$ kolla-genpwd
ERROR: Passwords file "/etc/kolla/passwords.yml" is missing
Change-Id: I18a9559daeb3d124a03dcb735ebb01a2cf24f617
Diffstat (limited to 'kolla_ansible')
| -rwxr-xr-x | kolla_ansible/cmd/genpwd.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/kolla_ansible/cmd/genpwd.py b/kolla_ansible/cmd/genpwd.py index 6bfda5367..b8b176e33 100755 --- a/kolla_ansible/cmd/genpwd.py +++ b/kolla_ansible/cmd/genpwd.py @@ -56,8 +56,12 @@ def generate_RSA(bits=4096): def genpwd(passwords_file, length, uuid_keys, ssh_keys, blank_keys, fernet_keys, hmac_md5_keys): - with open(passwords_file, 'r') as f: - passwords = yaml.safe_load(f.read()) + try: + with open(passwords_file, 'r') as f: + passwords = yaml.safe_load(f.read()) + except FileNotFoundError: + print(f"ERROR: Passwords file \"{passwords_file}\" is missing") + sys.exit(1) if not isinstance(passwords, dict): print("ERROR: Passwords file not in expected key/value format") |
