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

164
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'] = progress
role['progress'] = install_kolla_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'],
for host in hosts_list: self.message, 0)
host_ip = host['mgtip'] docker_registry_ip = _get_local_ip()
cmd = 'mkdir -p /var/log/daisy/daisy_install/' with open(self.log_file, "w+") as fp:
daisy_cmn.subprocess_call(cmd) for host in hosts_list:
var_log_path = "/var/log/daisy/daisy_install/\ host_ip = host['mgtip']
%s_install_kolla.log" % host_ip cmd = 'sshpass -p ossdbg1 ssh -o StrictHostKeyChecking=no %s \
with open(var_log_path, "w+") as fp: "if [ ! -d %s ];then mkdir %s;fi" ' % \
cmd = 'clush -S -b -w %s mkdir /home/kolla' % (host_ip,) (host_ip, self.host_prepare_file, self.host_prepare_file)
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,48 +337,67 @@ 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)
try: self.message = "Preparing for installation successful!"
exc_result = subprocess.check_output( update_host_progress_to_db(self.req, role_id_list, host,
'%s/kolla/tools/kolla-ansible prechecks' % kolla_state['INSTALLING'],
self.kolla_file, shell=True, stderr=subprocess.STDOUT) self.message, 10)
except subprocess.CalledProcessError as e: try:
update_progress_to_db(req, role_id_list, exc_result = subprocess.check_output(
kolla_state['INSTALL_FAILED']) '%s/kolla/tools/kolla-ansible prechecks -i '
LOG.info(_("kolla-ansible preckecks %s failed!" % host_ip)) '%s/kolla/ansible/inventory/multinode' %
fp.write(e.output.strip()) (self.kolla_file, self.kolla_file),
exit() shell=True, stderr=subprocess.STDOUT)
else: except subprocess.CalledProcessError as e:
LOG.info(_("kolla-ansible preckecks for %s successfully!" self.message = "kolla-ansible preckecks failed!"
% host_ip)) update_all_host_progress_to_db(self.req, role_id_list,
fp.write(exc_result) host_id_list,
try: kolla_state['INSTALL_FAILED'],
exc_result = subprocess.check_output( self.message)
'%s/kolla/tools/kolla-ansible deploy -i ' LOG.info(_("kolla-ansible preckecks failed!"))
'%s/kolla/ansible/inventory/multinode' % fp.write(e.output.strip())
(self.kolla_file, self.kolla_file), exit()
shell=True, stderr=subprocess.STDOUT) else:
except subprocess.CalledProcessError as e: LOG.info(_("kolla-ansible preckecks successfully!"))
update_progress_to_db(req, role_id_list, fp.write(exc_result)
kolla_state['INSTALL_FAILED']) self.message = "Precheck for installation successfully!"
LOG.info(_("kolla-ansible deploy %s failed!" % host_ip)) update_all_host_progress_to_db(self.req, role_id_list,
fp.write(e.output.strip()) host_id_list,
exit() kolla_state['INSTALLING'],
else: self.message, 30)
LOG.info(_("kolla-ansible deploy for %s successfully!" try:
% host_ip)) exc_result = subprocess.check_output(
fp.write(exc_result) '%s/kolla/tools/kolla-ansible deploy -i '
update_progress_to_db(req, role_id_list, '%s/kolla/ansible/inventory/multinode' %
kolla_state['ACTIVE'], (self.kolla_file, self.kolla_file),
install_progress_percentage) shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
self.message = "kolla-ansible deploy failed!"
update_all_host_progress_to_db(self.req, role_id_list,
host_id_list,
kolla_state['INSTALL_FAILED'],
self.message)
LOG.info(_("kolla-ansible deploy failed!"))
fp.write(e.output.strip())
exit()
else:
LOG.info(_("kolla-ansible deploy successfully!"))
fp.write(exc_result)
self.message = "install successfully!"
update_all_host_progress_to_db(self.req, role_id_list,
host_id_list,
kolla_state['ACTIVE'],
self.message, 100)