From 7fab4cf1fa75d4251369e230f2792df0a16b4019 Mon Sep 17 00:00:00 2001 From: "wu.zhihui" Date: Mon, 13 Mar 2017 17:16:50 +0800 Subject: add the cleanup step in runner.py Add the cleanup step in runner.py Change-Id: I0016986485eab5d7ab45d4a7a393bea5fb6f96b5 Signed-off-by: wu.zhihui (cherry picked from commit 57ec2e7a9757cbb1da8a1f73f0c55e8a5cb67bec) --- qtip/driver/ansible_driver.py | 3 +++ qtip/runner/runner.py | 4 +++- qtip/scripts/cleanup_creds.sh | 11 ++++++++++- qtip/util/env.py | 18 +++++++++++------- 4 files changed, 27 insertions(+), 9 deletions(-) (limited to 'qtip') diff --git a/qtip/driver/ansible_driver.py b/qtip/driver/ansible_driver.py index 356c39b7..34ef46ed 100644 --- a/qtip/driver/ansible_driver.py +++ b/qtip/driver/ansible_driver.py @@ -46,6 +46,9 @@ class AnsibleDriver(object): self.env_setup_flag = True logger.info("Setup test enviroment, Done!") + def cleanup(self): + self.env.cleanup() + def run(self, metric_list, **kwargs): if 'args' in self.config: extra_vars = self.merge_two_dicts(kwargs, self.config['args']) diff --git a/qtip/runner/runner.py b/qtip/runner/runner.py index 47795bc3..8bdbfb78 100644 --- a/qtip/runner/runner.py +++ b/qtip/runner/runner.py @@ -36,7 +36,9 @@ def run_benchmark(result_dir, benchmarks): os.makedirs(result_dir) driver = AnsibleDriver({'args': {'result_dir': result_dir}}) driver.pre_run() - return driver.run(benchmarks) + result = driver.run(benchmarks) + driver.cleanup() + return result def generate_report(result_dir, start_time, stop_time): diff --git a/qtip/scripts/cleanup_creds.sh b/qtip/scripts/cleanup_creds.sh index b4eee924..1a7ddc1a 100755 --- a/qtip/scripts/cleanup_creds.sh +++ b/qtip/scripts/cleanup_creds.sh @@ -1,11 +1,20 @@ #! /bin/bash +############################################################################## +# Copyright (c) 2017 ZTE corp. and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## DEST_IP=$1 +PRIVATE_KEY=$2 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" + ssh $sshoptions -i $PRIVATE_KEY root@$DEST_IP "sed -i '/root@$HOSTNAME/d' /root/.ssh/authorized_keys" ;; esac diff --git a/qtip/util/env.py b/qtip/util/env.py index 830c9b38..ffa56ae4 100644 --- a/qtip/util/env.py +++ b/qtip/util/env.py @@ -18,7 +18,7 @@ import paramiko from qtip.util.logger import QtipLogger -logger = QtipLogger('ansible_driver').get +logger = QtipLogger('env').get SCRIPT_DIR = path.join(path.dirname(__file__), path.pardir, 'scripts') KEYNAME = 'QtipKey' @@ -191,14 +191,18 @@ class AnsibleEnvSetup(object): return False def cleanup(self): - IF_DEBUG = os.getenv('IF_DEBUG') + CI_DEBUG = os.getenv('CI_DEBUG') - if IF_DEBUG: + if CI_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)) + cmd = 'bash {0}/cleanup_creds.sh {1} {2}'.format( + SCRIPT_DIR, ip, self.keypair['private']) + os.system(cmd) + + logger.info("Cleanup hostfile and keypair.") + clean_file(self.hostfile, + self.keypair['private'], + self.keypair['public']) -- cgit 1.2.3-korg