Debug prepare/install/uninstall

1. do not do prepare.sh again for the next install
2. solve some bugs in installation thread
3. add more log for future to debug prepare.sh

Cherry-pick from 044b79a276

Change-Id: I3a31f3b3f6fb355aa13bb0a191306264c454b176
This commit is contained in:
Zhijiang Hu 2017-09-07 20:22:55 +08:00
parent 0e8bb8c6e1
commit 4dc22b9a9c
3 changed files with 36 additions and 41 deletions

View File

@ -8,6 +8,12 @@
##############################################################################
set -e
config_path=/etc/systemd/system/docker.service.d/kolla.conf
if [ -f "$config_path" ]; then
# Prevent prepare.sh to run again
exit 0
fi
echo "nameserver 8.8.8.8" > /etc/resolv.conf
daisy_management_ip=$1
yum -y install epel-release
@ -18,7 +24,6 @@ yum install -y https://mirrors.nju.edu.cn/docker/yum/repo/centos7/Packages/docke
[ "$?" -ne 0 ] && { exit 1; }
mkdir -p /etc/systemd/system/docker.service.d
config_path=/etc/systemd/system/docker.service.d/kolla.conf
touch /etc/sysconfig/docker
echo -e "other_args=\"--insecure-registry $daisy_management_ip:4000 --insecure-registry 127.0.0.1:4000\"" > /etc/sysconfig/docker
echo -e "[Service]\nMountFlags=shared\nEnvironmentFile=/etc/sysconfig/docker\nExecStart=\nExecStart=/usr/bin/docker daemon \$other_args" > $config_path

View File

@ -24,6 +24,7 @@ import threading
from daisy import i18n
import daisy.api.v1
from daisy.common import exception
from daisy.common import utils
import daisy.api.backends.common as daisy_cmn
import daisy.api.backends.kolla.common as kolla_cmn
import daisy.api.common as api_cmn
@ -325,11 +326,11 @@ def _thread_bin(req, cluster_id, host, root_passwd, fp, host_name_ip_list,
shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
message = "exec prepare.sh on %s failed!", host_ip
LOG.error(message + e)
LOG.error(message)
fp.write(e.output.strip())
raise exception.InstallException(message)
else:
LOG.info(_("prepare for %s successfully!" % host_ip))
LOG.info("prepare for %s successfully!", host_ip)
fp.write(exc_result)
message = "Preparing for installation successful!"
update_host_progress_to_db(req, role_id_list, host,
@ -341,7 +342,7 @@ def thread_bin(req, cluster_id, host, root_passwd, host_name_ip_list,
host_prepare_file, docker_registry_ip, role_id_list):
host_prepare_log = "/var/log/daisy/kolla_prepare_%s_%s.log" %\
(self.cluster_id, host['mgtip'])
(cluster_id, host['mgtip'])
with open(host_prepare_log, "w+") as fp:
try:
_thread_bin(req, cluster_id, host, root_passwd,
@ -349,12 +350,13 @@ def thread_bin(req, cluster_id, host, root_passwd, host_name_ip_list,
host_prepare_file, docker_registry_ip,
role_id_list)
except Exception as e:
thread_flag['flag'] = False
message = "Prepare for installation failed!"
LOG.error(message, e)
LOG.error(message)
update_host_progress_to_db(req, role_id_list, host,
kolla_state['INSTALL_FAILED'],
message)
thread_flag['flag'] = False
fp.write(utils.exception_to_str(e))
class KOLLAInstallTask(Thread):
@ -490,7 +492,8 @@ class KOLLAInstallTask(Thread):
LOG.error("join kolla prepare installation "
"thread %s failed!", t)
if thread_flag.get('flag', None) and thread_flag['flag'] == False:
if thread_flag.get('flag', None) is not None and \
thread_flag['flag'] == False:
self.message = "prepare deploy nodes failed!"
LOG.error(self.message)
raise exception.InstallException(self.message)

View File

@ -97,43 +97,30 @@ def _calc_uninstall_progress(log_file):
def remove_registry(req, hosts_id_list, host_ip, log_file):
LOG.info(_("begin to remove docker images on host %s" % host_ip))
try:
check_docker_container_cmd = \
"ssh -o StrictHostKeyChecking=no %s \
docker ps |grep registry:2 |awk -F ' ' '{print $2}'" % (host_ip)
docker_container_result = \
subprocess.check_output(check_docker_container_cmd,
shell=True,
stderr=subprocess.STDOUT)
LOG.info(_("begin to remove docker registry on host %s" % host_ip))
check_docker_container_cmd = \
"ssh -o StrictHostKeyChecking=no %s \
docker ps |grep registry:2 |awk -F ' ' '{print $2}'" % (host_ip)
docker_container_result = \
subprocess.check_output(check_docker_container_cmd,
shell=True,
stderr=subprocess.STDOUT)
stop_docker_container_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker stop registry"' % (host_ip)
remove_docker_container_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker rm registry"' % (host_ip)
remove_docker_images_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker rmi -f registry:2"' % (host_ip)
stop_docker_container_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker stop registry"' % (host_ip)
remove_docker_container_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker rm registry"' % (host_ip)
remove_docker_images_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker rmi -f registry:2"' % (host_ip)
if "registry:2" in docker_container_result:
daisy_cmn.subprocess_call(stop_docker_container_cmd, log_file)
daisy_cmn.subprocess_call(remove_docker_container_cmd, log_file)
daisy_cmn.subprocess_call(remove_docker_images_cmd, log_file)
if "registry:2" in docker_container_result:
daisy_cmn.subprocess_call(stop_docker_container_cmd, log_file)
daisy_cmn.subprocess_call(remove_docker_container_cmd, log_file)
except Exception as e:
message = "remove docker images failed on host %s!" % host_ip
LOG.error(message)
thread_flag['flag'] = False
update_all_host_progress_to_db(req, hosts_id_list,
{'progress': 90,
'status': kolla_state[
'UNINSTALL_FAILED'],
'messages': message})
raise exception.UninstallException(message)
else:
LOG.info(_("remove docker images on host %s successfully!" % host_ip))
LOG.info(_("remove docker images on host %s successfully!" % host_ip))
class KOLLAUninstallTask(Thread):