modify update progress to db code

now we update the progress to host-role tables,the old code update to
the role tables which is useless.
now during the period of install ,we can use command daisy host-list
--cluster-id get every time progress,which is also reflect in dashboard.
and preckeck and deploy should be  after all hosts prepared

Change-Id: I8a8b2155bcaec458c259d3830c49d50b3c5d22d2
Signed-off-by: luyao <lu.yao135@zte.com.cn>
This commit is contained in:
luyao 2016-07-25 16:41:29 +08:00 committed by Zhou Ya
parent b73af5d9bb
commit 4b9656f843

120
code/daisy/daisy/api/backends/kolla/install.py Executable file → Normal file
View File

@ -66,10 +66,11 @@ kolla_state = kolla_cmn.KOLLA_STATE
daisy_kolla_path = kolla_cmn.daisy_kolla_path daisy_kolla_path = kolla_cmn.daisy_kolla_path
install_kolla_progress = 0.0 install_kolla_progress = 0.0
install_mutex = threading.Lock() install_mutex = threading.Lock()
kolla_file = "/home/kolla_install"
def update_progress_to_db(req, role_id_list, def update_progress_to_db(req, role_id_list,
status, progress_percentage_step=0.0): status, progress=0.0):
""" """
Write install progress and status to db, we use global lock object Write install progress and status to db, we use global lock object
'install_mutex' to make sure this function is thread safety. 'install_mutex' to make sure this function is thread safety.
@ -80,23 +81,40 @@ def update_progress_to_db(req, role_id_list,
""" """
global install_mutex global install_mutex
global install_kolla_progress
install_mutex.acquire(True) install_mutex.acquire(True)
install_kolla_progress += progress_percentage_step
role = {} role = {}
for role_id in role_id_list: for role_id in role_id_list:
if 0 == cmp(status, kolla_state['INSTALLING']):
role['status'] = status role['status'] = status
role['progress'] = install_kolla_progress role['progress'] = progress
if 0 == cmp(status, kolla_state['INSTALL_FAILED']):
role['status'] = status
elif 0 == cmp(status, kolla_state['ACTIVE']):
role['status'] = status
role['progress'] = 100
daisy_cmn.update_role(req, role_id, role) daisy_cmn.update_role(req, role_id, role)
install_mutex.release() install_mutex.release()
def update_host_progress_to_db(req, role_id_list, host,
status, message, progress=0.0):
for role_id in role_id_list:
role_hosts = daisy_cmn.get_hosts_of_role(req, role_id)
for role_host in role_hosts:
if role_host['host_id'] == host['id']:
role_host['status'] = status
role_host['progress'] = progress
role_host['messages'] = message
daisy_cmn.update_role_host(req, role_host['id'], role_host)
def update_all_host_progress_to_db(req, role_id_list, host_id_list,
status, message, progress=0.0):
for host_id in host_id_list:
for role_id in role_id_list:
role_hosts = daisy_cmn.get_hosts_of_role(req, role_id)
for role_host in role_hosts:
if role_host['host_id'] == host_id:
role_host['status'] = status
role_host['progress'] = progress
role_host['messages'] = message
daisy_cmn.update_role_host(req, role_host['id'], role_host)
def _ping_hosts_test(ips): def _ping_hosts_test(ips):
ping_cmd = 'fping' ping_cmd = 'fping'
for ip in set(ips): for ip in set(ips):
@ -170,7 +188,6 @@ def _get_local_ip():
def get_cluster_kolla_config(req, cluster_id): def get_cluster_kolla_config(req, cluster_id):
LOG.info(_("get kolla config from database...")) LOG.info(_("get kolla config from database..."))
params = dict(limit=1000000)
mgt_ip_list = set() mgt_ip_list = set()
kolla_config = {} kolla_config = {}
controller_ip_list = [] controller_ip_list = []
@ -235,12 +252,12 @@ def generate_kolla_config_file(cluster_id, kolla_config):
if kolla_config: if kolla_config:
config.update_globals_yml(kolla_config) config.update_globals_yml(kolla_config)
config.update_password_yml() config.update_password_yml()
config.add_role_to_inventory(self.kolla_file, kolla_config) config.add_role_to_inventory(kolla_file, kolla_config)
class KOLLAInstallTask(Thread): class KOLLAInstallTask(Thread):
""" """
Class for install tecs bin. Class for kolla install openstack.
""" """
""" Definition for install states.""" """ Definition for install states."""
INSTALL_STATES = { INSTALL_STATES = {
@ -295,19 +312,19 @@ class KOLLAInstallTask(Thread):
self.message = "hosts %s ping failed" % unreached_hosts self.message = "hosts %s ping failed" % unreached_hosts
raise exception.NotFound(message=self.message) raise exception.NotFound(message=self.message)
generate_kolla_config_file(self.cluster_id, kolla_config) generate_kolla_config_file(self.cluster_id, kolla_config)
(role_id_list, hosts_list) = kolla_cmn.get_roles_and_hosts_list( (role_id_list, host_id_list, hosts_list) = \
self.req, self.cluster_id) kolla_cmn.get_roles_and_hosts_list(self.req, self.cluster_id)
update_progress_to_db(self.req, role_id_list, self.message = "Begin install"
kolla_state['INSTALLING'], 0.0) update_all_host_progress_to_db(self.req, role_id_list,
install_progress_percentage = round(1 * 1.0 / len(hosts_list), 2) * 100 host_id_list, kolla_state['INSTALLING'],
self.message, 0)
docker_registry_ip = _get_local_ip()
with open(self.log_file, "w+") as fp:
for host in hosts_list: for host in hosts_list:
host_ip = host['mgtip'] host_ip = host['mgtip']
cmd = 'mkdir -p /var/log/daisy/daisy_install/' cmd = 'sshpass -p ossdbg1 ssh -o StrictHostKeyChecking=no %s \
daisy_cmn.subprocess_call(cmd) "if [ ! -d %s ];then mkdir %s;fi" ' % \
var_log_path = "/var/log/daisy/daisy_install/\ (host_ip, self.host_prepare_file, self.host_prepare_file)
%s_install_kolla.log" % host_ip
with open(var_log_path, "w+") as fp:
cmd = 'clush -S -b -w %s mkdir /home/kolla' % (host_ip,)
daisy_cmn.subprocess_call(cmd, fp) daisy_cmn.subprocess_call(cmd, fp)
cmd = "scp -o ConnectTimeout=10 \ cmd = "scp -o ConnectTimeout=10 \
/var/lib/daisy/kolla/prepare.sh \ /var/lib/daisy/kolla/prepare.sh \
@ -320,32 +337,47 @@ class KOLLAInstallTask(Thread):
try: try:
exc_result = subprocess.check_output( exc_result = subprocess.check_output(
'sshpass -p ossdbg1 ssh -o StrictHostKeyChecking=' 'sshpass -p ossdbg1 ssh -o StrictHostKeyChecking='
'no %s %s/prepare.sh' % 'no %s %s/prepare.sh %s' %
(host_ip, self.host_prepare_file), (host_ip, self.host_prepare_file, docker_registry_ip),
shell=True, stderr=subprocess.STDOUT) shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
update_progress_to_db(req, role_id_list, self.message = "Prepare install failed!"
kolla_state['INSTALL_FAILED']) update_host_progress_to_db(self.req, role_id_list, host,
kolla_state['INSTALL_FAILED'],
self.message)
LOG.info(_("prepare for %s failed!" % host_ip)) LOG.info(_("prepare for %s failed!" % host_ip))
fp.write(e.output.strip()) fp.write(e.output.strip())
exit() exit()
else: else:
LOG.info(_("prepare for %s successfully!" % host_ip)) LOG.info(_("prepare for %s successfully!" % host_ip))
fp.write(exc_result) fp.write(exc_result)
self.message = "Preparing for installation successful!"
update_host_progress_to_db(self.req, role_id_list, host,
kolla_state['INSTALLING'],
self.message, 10)
try: try:
exc_result = subprocess.check_output( exc_result = subprocess.check_output(
'%s/kolla/tools/kolla-ansible prechecks' % '%s/kolla/tools/kolla-ansible prechecks -i '
self.kolla_file, shell=True, stderr=subprocess.STDOUT) '%s/kolla/ansible/inventory/multinode' %
(self.kolla_file, self.kolla_file),
shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
update_progress_to_db(req, role_id_list, self.message = "kolla-ansible preckecks failed!"
kolla_state['INSTALL_FAILED']) update_all_host_progress_to_db(self.req, role_id_list,
LOG.info(_("kolla-ansible preckecks %s failed!" % host_ip)) host_id_list,
kolla_state['INSTALL_FAILED'],
self.message)
LOG.info(_("kolla-ansible preckecks failed!"))
fp.write(e.output.strip()) fp.write(e.output.strip())
exit() exit()
else: else:
LOG.info(_("kolla-ansible preckecks for %s successfully!" LOG.info(_("kolla-ansible preckecks successfully!"))
% host_ip))
fp.write(exc_result) fp.write(exc_result)
self.message = "Precheck for installation successfully!"
update_all_host_progress_to_db(self.req, role_id_list,
host_id_list,
kolla_state['INSTALLING'],
self.message, 30)
try: try:
exc_result = subprocess.check_output( exc_result = subprocess.check_output(
'%s/kolla/tools/kolla-ansible deploy -i ' '%s/kolla/tools/kolla-ansible deploy -i '
@ -353,15 +385,19 @@ class KOLLAInstallTask(Thread):
(self.kolla_file, self.kolla_file), (self.kolla_file, self.kolla_file),
shell=True, stderr=subprocess.STDOUT) shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
update_progress_to_db(req, role_id_list, self.message = "kolla-ansible deploy failed!"
kolla_state['INSTALL_FAILED']) update_all_host_progress_to_db(self.req, role_id_list,
LOG.info(_("kolla-ansible deploy %s failed!" % host_ip)) host_id_list,
kolla_state['INSTALL_FAILED'],
self.message)
LOG.info(_("kolla-ansible deploy failed!"))
fp.write(e.output.strip()) fp.write(e.output.strip())
exit() exit()
else: else:
LOG.info(_("kolla-ansible deploy for %s successfully!" LOG.info(_("kolla-ansible deploy successfully!"))
% host_ip))
fp.write(exc_result) fp.write(exc_result)
update_progress_to_db(req, role_id_list, self.message = "install successfully!"
update_all_host_progress_to_db(self.req, role_id_list,
host_id_list,
kolla_state['ACTIVE'], kolla_state['ACTIVE'],
install_progress_percentage) self.message, 100)