env cleanup 89/30289/2
authorwu.zhihui <wu.zhihui1@zte.com.cn>
Sat, 11 Mar 2017 02:19:21 +0000 (10:19 +0800)
committerwu.zhihui <wu.zhihui1@zte.com.cn>
Sat, 11 Mar 2017 02:29:13 +0000 (10:29 +0800)
If IF_DEBUG is True, there is not cleanup step.
If IF_DEBUG is False, host file and keypair will be
deleted on local  and public key will be removed from
remote nodes in the end of test.

Change-Id: I4a88acc2d428e41e4abaedacb011e27468b2cb57
Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn>
qtip/scripts/cleanup_creds.sh [new file with mode: 0755]
qtip/util/env.py

diff --git a/qtip/scripts/cleanup_creds.sh b/qtip/scripts/cleanup_creds.sh
new file mode 100755 (executable)
index 0000000..b4eee92
--- /dev/null
@@ -0,0 +1,11 @@
+#! /bin/bash
+
+DEST_IP=$1
+HOSTNAME=$(hostname)
+sshoptions="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
+
+case "$INSTALLER_TYPE" in
+    fuel)
+        ssh $sshoptions -i ./config/QtipKey root@$DEST_IP "sed -i '/root@$HOSTNAME/d' /root/.ssh/authorized_keys"
+        ;;
+esac
index 24e0865..830c9b3 100644 (file)
@@ -16,6 +16,10 @@ import time
 
 import paramiko
 
+from qtip.util.logger import QtipLogger
+
+logger = QtipLogger('ansible_driver').get
+
 SCRIPT_DIR = path.join(path.dirname(__file__), path.pardir, 'scripts')
 KEYNAME = 'QtipKey'
 PRIVATE_KEY = '{0}/qtip/{1}'.format(os.environ['HOME'], KEYNAME)
@@ -185,3 +189,16 @@ class AnsibleEnvSetup(object):
                     return False
                 time.sleep(2)
         return False
+
+    def cleanup(self):
+        IF_DEBUG = os.getenv('IF_DEBUG')
+
+        if IF_DEBUG:
+            logger.info("DEBUG Mode: please do cleanup by manual.")
+        else:
+            logger.info("Cleanup hostfile and keypair.")
+            clean_file(self.hostfile, self.keypair, self.keypair + '.pub')
+
+            for ip in self.host_ip_list:
+                logger.info("Cleanup authorized_keys from {0}...".format(ip))
+                os.system('bash %s/cleanup_creds.sh {0}'.format(ip))