Merge "Add --clean to kolla-mergepwd"

This commit is contained in:
Zuul 2020-02-10 19:00:16 +00:00 committed by Gerrit Code Review
commit a38c672ab4
3 changed files with 23 additions and 3 deletions

View File

@ -217,3 +217,8 @@ For example:
kolla-genpwd -p passwords.yml.new kolla-genpwd -p passwords.yml.new
kolla-mergepwd --old passwords.yml.old --new passwords.yml.new --final /etc/kolla/passwords.yml kolla-mergepwd --old passwords.yml.old --new passwords.yml.new --final /etc/kolla/passwords.yml
.. note::
``kolla-mergepwd``, by default, keeps old, unused passwords intact.
To alter this behavior, and remove such entries, use the ``--clean``
argument when invoking ``kolla-mergepwd``.

View File

@ -16,14 +16,21 @@ import argparse
import yaml import yaml
def mergepwd(old, new, final): def mergepwd(old, new, final, clean=False):
with open(old, "r") as old_file: with open(old, "r") as old_file:
old_passwords = yaml.safe_load(old_file) old_passwords = yaml.safe_load(old_file)
with open(new, "r") as new_file: with open(new, "r") as new_file:
new_passwords = yaml.safe_load(new_file) new_passwords = yaml.safe_load(new_file)
new_passwords.update(old_passwords) if clean:
# keep only new keys
for key in new_passwords:
if key in old_passwords:
new_passwords[key] = old_passwords[key]
else:
# old behavior
new_passwords.update(old_passwords)
with open(final, "w") as destination: with open(final, "w") as destination:
yaml.safe_dump(new_passwords, destination, default_flow_style=False) yaml.safe_dump(new_passwords, destination, default_flow_style=False)
@ -34,8 +41,11 @@ def main():
parser.add_argument("--old", help="old password file", required=True) parser.add_argument("--old", help="old password file", required=True)
parser.add_argument("--new", help="new password file", required=True) parser.add_argument("--new", help="new password file", required=True)
parser.add_argument("--final", help="merged password file", required=True) parser.add_argument("--final", help="merged password file", required=True)
parser.add_argument("--clean",
help="clean (keep only new keys)",
action='store_true')
args = parser.parse_args() args = parser.parse_args()
mergepwd(args.old, args.new, args.final) mergepwd(args.old, args.new, args.final, args.clean)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -0,0 +1,5 @@
---
features:
- |
Adds ``--clean`` argument to ``kolla-mergepwd``. It allows to clean old
(not used anymore) keys from the passwords file.