From 14f9246fcdcd7c9428d3e837eeb66a06adb68bce Mon Sep 17 00:00:00 2001
From: Vladislav Belogrudov <vladislav.belogrudov@oracle.com>
Date: Fri, 25 Nov 2016 15:52:03 +0300
Subject: [PATCH] Add tool to merge passwords during release upgrade

Typical usage:
   cp /etc/kolla/passwords.yml /etc/kolla/passwords.yml.old
   kolla-genpwd
   kolla-mergepwd --old /etc/kolla/passwords.yml.old \
                  --new /etc/kolla/passwords.yml     \
                  --final /etc/kolla/passwords.yml

Change-Id: Ibbc598909e28e096145841aec929d0cfcf8f7cab
Implements: blueprint kolla-merge-passwords
---
 kolla/cmd/mergepwd.py    | 39 +++++++++++++++++++++++++++++++++++++++
 setup.cfg                |  1 +
 tools/merge_passwords.py |  1 +
 3 files changed, 41 insertions(+)
 create mode 100755 kolla/cmd/mergepwd.py
 create mode 120000 tools/merge_passwords.py

diff --git a/kolla/cmd/mergepwd.py b/kolla/cmd/mergepwd.py
new file mode 100755
index 0000000000..b8fde1c778
--- /dev/null
+++ b/kolla/cmd/mergepwd.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import argparse
+import yaml
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--old", help="old password file", required=True)
+    parser.add_argument("--new", help="new password file", required=True)
+    parser.add_argument("--final", help="merged password file", required=True)
+    args = parser.parse_args()
+
+    with open(args.old, "r") as old_file:
+        old_passwords = yaml.safe_load(old_file)
+
+    with open(args.new, "r") as new_file:
+        new_passwords = yaml.safe_load(new_file)
+
+    new_passwords.update(old_passwords)
+
+    with open(args.final, "w") as destination:
+        yaml.dump(new_passwords, destination)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/setup.cfg b/setup.cfg
index bacc903c68..8f78de6597 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -43,6 +43,7 @@ scripts =
 console_scripts =
     kolla-build = kolla.cmd.build:main
     kolla-genpwd = kolla.cmd.genpwd:main
+    kolla-mergepwd = kolla.cmd.mergepwd:main
 oslo.config.opts =
     kolla = kolla.opts:list_opts
 
diff --git a/tools/merge_passwords.py b/tools/merge_passwords.py
new file mode 120000
index 0000000000..ce2431d00a
--- /dev/null
+++ b/tools/merge_passwords.py
@@ -0,0 +1 @@
+../kolla/cmd/mergepwd.py
\ No newline at end of file