Solve version upgrade errors

Cherry-picked from https://review.openstack.org/#/c/498347/

Change-Id: I33010c0f12ac78c517e3ca69dc247f30ce75e75b
Signed-off-by: Zhijiang Hu <hu.zhijiang@zte.com.cn>
This commit is contained in:
Zhijiang Hu 2017-08-28 04:59:10 -04:00
parent 33e274cf88
commit d4f3a417c8
10 changed files with 178 additions and 176 deletions

View File

@ -12,6 +12,7 @@ echo -e "other_args=\"--insecure-registry $daisy_management_ip:4000 --insecure-r
echo -e "[Service]\nMountFlags=shared\nEnvironmentFile=/etc/sysconfig/docker\nExecStart=\nExecStart=/usr/bin/docker daemon \$other_args" > $config_path
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
yum install -y python-docker-py
yum -y install ntp
systemctl enable ntpd.service

View File

@ -28,7 +28,7 @@ from daisy import i18n
from daisy.common import exception
import daisy.registry.client.v1.api as registry
import daisy.api.backends.common as daisy_cmn
from daisy.api.backends.kolla import config as kconfig
LOG = logging.getLogger(__name__)
_ = i18n._
@ -49,6 +49,7 @@ KOLLA_STATE = {
'UPDATING': 'updating',
'UPDATE_FAILED': 'update-failed',
}
kolla_file = "/home/kolla_install"
def get_cluster_hosts(req, cluster_id):
@ -501,3 +502,155 @@ def version_load(kolla_version_pkg_file, hosts_list):
-e REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/tmp/registry \
-v %s:/tmp/registry --name registry registry:2' % registry_file)
LOG.info(_('docker server loaded finished.'))
def get_cluster_kolla_config(req, cluster_id):
LOG.info(_("get kolla config from database..."))
mgt_ip_list = set()
kolla_config = {}
controller_ip_list = []
computer_ip_list = []
storage_ip_list = []
mgt_macname_list = []
pub_macname_list = []
dat_macname_list = []
ext_macname_list = []
sto_macname_list = []
hbt_macname_list = []
vlans_id = {}
openstack_version = '3.0.0'
docker_namespace = 'kolla'
host_name_ip = {}
host_name_ip_list = []
version_flag = False
version_path = daisy_kolla_ver_path
for parent, dirnames, filenames in os.walk(version_path):
for filename in filenames:
if filename.endswith('.version'):
filename = version_path + filename
for line in open(filename):
if 'tag' in line:
version_flag = True
kolla_openstack_version = line.strip()
openstack_version = kolla_openstack_version.split(
"= ")[1]
if version_flag == False:
version_path = kolla_file + '/kolla-ansible/ansible/group_vars/'
for parent, dirnames, filenames in os.walk(version_path):
for filename in filenames:
if filename == 'all.yml':
filename = version_path + filename
for line in open(filename):
if 'openstack_release:' in line:
version_flag = True
kolla_openstack_version = line.strip()
openstack_version = kolla_openstack_version.split(
": ")[1].strip('\"')
LOG.info(_("openstack version is %s"), openstack_version)
docker_registry_ip = _get_local_ip()
docker_registry = docker_registry_ip + ':4000'
LOG.info(_("get cluster network detail..."))
cluster_networks = daisy_cmn.get_cluster_networks_detail(req, cluster_id)
for network in cluster_networks:
vlans_id.update({network.get('network_type'): network.get('vlan_id')})
all_roles = get_roles_detail(req)
roles = [role for role in all_roles if
(role['cluster_id'] == cluster_id and
role['deployment_backend'] == daisy_cmn.kolla_backend_name)]
for role in roles:
if role['name'] == 'CONTROLLER_LB':
kolla_vip = role['vip']
role_hosts = get_hosts_of_role(req, role['id'])
for role_host in role_hosts:
host_detail = get_host_detail(
req, role_host['host_id'])
deploy_host_cfg = get_controller_node_cfg(
req, host_detail, cluster_networks)
mgt_ip = deploy_host_cfg['mgtip']
host_name_ip = {
deploy_host_cfg['host_name']: deploy_host_cfg['mgtip']}
controller_ip_list.append(mgt_ip)
mgt_macname = deploy_host_cfg['mgt_macname']
pub_macname = deploy_host_cfg['pub_macname']
sto_macname = deploy_host_cfg['sto_macname']
hbt_macname = deploy_host_cfg.get('hbt_macname')
mgt_macname_list.append(mgt_macname)
pub_macname_list.append(pub_macname)
sto_macname_list.append(sto_macname)
hbt_macname_list.append(hbt_macname)
if host_name_ip not in host_name_ip_list:
host_name_ip_list.append(host_name_ip)
if len(set(mgt_macname_list)) != 1 or \
len(set(pub_macname_list)) != 1 or \
len(set(sto_macname_list)) != 1 or \
len(set(hbt_macname_list)) > 1:
msg = (_("hosts interface name of public and \
management and storage and heartbeat \
must be same!"))
LOG.error(msg)
raise HTTPForbidden(msg)
kolla_config.update({'Version': openstack_version})
kolla_config.update({'Namespace': docker_namespace})
kolla_config.update({'VIP': kolla_vip})
kolla_config.update({'IntIfMac': mgt_macname})
kolla_config.update({'PubIfMac': pub_macname})
kolla_config.update({'StoIfMac': sto_macname})
kolla_config.update({'HbtIfMac': hbt_macname})
kolla_config.update({'LocalIP': docker_registry})
kolla_config.update({'Controller_ips': controller_ip_list})
kolla_config.update({'Network_ips': controller_ip_list})
kolla_config.update({'Odl_ips': controller_ip_list[0]})
#kolla_config.update({'Storage_ips': controller_ip_list})
kolla_config.update({'vlans_id': vlans_id})
if role['name'] == 'COMPUTER':
role_hosts = get_hosts_of_role(req, role['id'])
for role_host in role_hosts:
host_detail = get_host_detail(
req, role_host['host_id'])
deploy_host_cfg = get_computer_node_cfg(
req, host_detail, cluster_networks)
mgt_ip = deploy_host_cfg['mgtip']
host_name_ip = {
deploy_host_cfg['host_name']: deploy_host_cfg['mgtip']}
computer_ip_list.append(mgt_ip)
if host_name_ip not in host_name_ip_list:
host_name_ip_list.append(host_name_ip)
dat_macname = deploy_host_cfg['dat_macname']
dat_macname_list.append(dat_macname)
ext_macname = deploy_host_cfg['ext_macname']
ext_macname_list.append(ext_macname)
if len(set(dat_macname_list)) != 1 or \
len(set(ext_macname_list)) != 1:
msg = (_("computer hosts interface name of dataplane \
and external must be same!"))
LOG.error(msg)
raise HTTPForbidden(msg)
kolla_config.update({'Computer_ips': computer_ip_list})
kolla_config.update({'TulIfMac': dat_macname})
kolla_config.update({'ExtIfMac': ext_macname})
mgt_ip_list = set(controller_ip_list + computer_ip_list)
for ctl_host_ip in controller_ip_list:
if len(storage_ip_list) > 2:
break
storage_ip_list.append(ctl_host_ip)
for com_host_ip in computer_ip_list:
if com_host_ip not in controller_ip_list:
if len(storage_ip_list) > 2:
break
storage_ip_list.append(com_host_ip)
kolla_config.update({'Storage_ips': storage_ip_list})
return (kolla_config, mgt_ip_list, host_name_ip_list)
def generate_kolla_config_file(req, cluster_id, kolla_config, multicast_flag):
LOG.info(_("generate kolla config..."))
if kolla_config:
kconfig.update_globals_yml(kolla_config, multicast_flag)
kconfig.update_password_yml()
kconfig.add_role_to_inventory(kolla_file, kolla_config)
kconfig.enable_cinder_backend(req,
cluster_id,
kolla_config)
kconfig.enable_neutron_backend(req, cluster_id, kolla_config)

View File

@ -17,16 +17,13 @@
/install endpoint for kolla API
"""
import subprocess
import os
import time
from oslo_log import log as logging
from webob.exc import HTTPForbidden
from threading import Thread
import threading
from daisy import i18n
import daisy.api.v1
from daisy.common import exception
from daisy.api.backends.kolla import config
import daisy.api.backends.common as daisy_cmn
import daisy.api.backends.kolla.common as kolla_cmn
import daisy.api.common as api_cmn
@ -53,8 +50,6 @@ kolla_state = kolla_cmn.KOLLA_STATE
daisy_kolla_path = kolla_cmn.daisy_kolla_path
install_kolla_progress = 0.0
install_mutex = threading.Lock()
kolla_file = "/home/kolla_install"
kolla_config_file = "/etc/kolla/globals.yml"
daisy_kolla_ver_path = kolla_cmn.daisy_kolla_ver_path
thread_flag = {}
@ -152,156 +147,6 @@ def _check_ping_hosts(ping_ips, max_ping_times):
return ips
def get_cluster_kolla_config(req, cluster_id):
LOG.info(_("get kolla config from database..."))
mgt_ip_list = set()
kolla_config = {}
controller_ip_list = []
computer_ip_list = []
storage_ip_list = []
mgt_macname_list = []
pub_macname_list = []
dat_macname_list = []
ext_macname_list = []
sto_macname_list = []
hbt_macname_list = []
vlans_id = {}
openstack_version = '3.0.0'
docker_namespace = 'kolla'
host_name_ip = {}
host_name_ip_list = []
version_flag = False
version_path = kolla_cmn.daisy_kolla_ver_path
for parent, dirnames, filenames in os.walk(version_path):
for filename in filenames:
if filename.endswith('.version'):
filename = version_path + filename
for line in open(filename):
if 'tag' in line:
version_flag = True
kolla_openstack_version = line.strip()
openstack_version = kolla_openstack_version.split(
"= ")[1]
if version_flag == False:
version_path = kolla_file + '/kolla-ansible/ansible/group_vars/'
for parent, dirnames, filenames in os.walk(version_path):
for filename in filenames:
if filename == 'all.yml':
filename = version_path + filename
for line in open(filename):
if 'openstack_release:' in line:
version_flag = True
kolla_openstack_version = line.strip()
openstack_version = kolla_openstack_version.split(
": ")[1].strip('\"')
LOG.info(_("openstack version is %s" % openstack_version))
docker_registry_ip = kolla_cmn._get_local_ip()
docker_registry = docker_registry_ip + ':4000'
LOG.info(_("get cluster network detail..."))
cluster_networks = daisy_cmn.get_cluster_networks_detail(req, cluster_id)
for network in cluster_networks:
vlans_id.update({network.get('network_type'): network.get('vlan_id')})
all_roles = kolla_cmn.get_roles_detail(req)
roles = [role for role in all_roles if
(role['cluster_id'] == cluster_id and
role['deployment_backend'] == daisy_cmn.kolla_backend_name)]
for role in roles:
if role['name'] == 'CONTROLLER_LB':
kolla_vip = role['vip']
role_hosts = kolla_cmn.get_hosts_of_role(req, role['id'])
for role_host in role_hosts:
host_detail = kolla_cmn.get_host_detail(
req, role_host['host_id'])
deploy_host_cfg = kolla_cmn.get_controller_node_cfg(
req, host_detail, cluster_networks)
mgt_ip = deploy_host_cfg['mgtip']
host_name_ip = {
deploy_host_cfg['host_name']: deploy_host_cfg['mgtip']}
controller_ip_list.append(mgt_ip)
mgt_macname = deploy_host_cfg['mgt_macname']
pub_macname = deploy_host_cfg['pub_macname']
sto_macname = deploy_host_cfg['sto_macname']
hbt_macname = deploy_host_cfg.get('hbt_macname')
mgt_macname_list.append(mgt_macname)
pub_macname_list.append(pub_macname)
sto_macname_list.append(sto_macname)
hbt_macname_list.append(hbt_macname)
if host_name_ip not in host_name_ip_list:
host_name_ip_list.append(host_name_ip)
if len(set(mgt_macname_list)) != 1 or \
len(set(pub_macname_list)) != 1 or \
len(set(sto_macname_list)) != 1 or \
len(set(hbt_macname_list)) > 1:
msg = (_("hosts interface name of public and \
management and storage and heartbeat \
must be same!"))
LOG.error(msg)
raise HTTPForbidden(msg)
kolla_config.update({'Version': openstack_version})
kolla_config.update({'Namespace': docker_namespace})
kolla_config.update({'VIP': kolla_vip})
kolla_config.update({'IntIfMac': mgt_macname})
kolla_config.update({'PubIfMac': pub_macname})
kolla_config.update({'StoIfMac': sto_macname})
kolla_config.update({'HbtIfMac': hbt_macname})
kolla_config.update({'LocalIP': docker_registry})
kolla_config.update({'Controller_ips': controller_ip_list})
kolla_config.update({'Network_ips': controller_ip_list})
kolla_config.update({'Odl_ips': controller_ip_list[0]})
#kolla_config.update({'Storage_ips': controller_ip_list})
kolla_config.update({'vlans_id': vlans_id})
if role['name'] == 'COMPUTER':
role_hosts = kolla_cmn.get_hosts_of_role(req, role['id'])
for role_host in role_hosts:
host_detail = kolla_cmn.get_host_detail(
req, role_host['host_id'])
deploy_host_cfg = kolla_cmn.get_computer_node_cfg(
req, host_detail, cluster_networks)
mgt_ip = deploy_host_cfg['mgtip']
host_name_ip = {
deploy_host_cfg['host_name']: deploy_host_cfg['mgtip']}
computer_ip_list.append(mgt_ip)
if host_name_ip not in host_name_ip_list:
host_name_ip_list.append(host_name_ip)
dat_macname = deploy_host_cfg['dat_macname']
dat_macname_list.append(dat_macname)
ext_macname = deploy_host_cfg['ext_macname']
ext_macname_list.append(ext_macname)
if len(set(dat_macname_list)) != 1 or \
len(set(ext_macname_list)) != 1:
msg = (_("computer hosts interface name of dataplane \
and external must be same!"))
LOG.error(msg)
raise HTTPForbidden(msg)
kolla_config.update({'Computer_ips': computer_ip_list})
kolla_config.update({'TulIfMac': dat_macname})
kolla_config.update({'ExtIfMac': ext_macname})
mgt_ip_list = set(controller_ip_list + computer_ip_list)
for ctl_host_ip in controller_ip_list:
if len(storage_ip_list) > 2:
break
storage_ip_list.append(ctl_host_ip)
for com_host_ip in computer_ip_list:
if com_host_ip not in controller_ip_list:
if len(storage_ip_list) > 2:
break
storage_ip_list.append(com_host_ip)
kolla_config.update({'Storage_ips': storage_ip_list})
return (kolla_config, mgt_ip_list, host_name_ip_list)
def generate_kolla_config_file(req, cluster_id, kolla_config, multicast_flag):
LOG.info(_("generate kolla config..."))
if kolla_config:
config.update_globals_yml(kolla_config, multicast_flag)
config.update_password_yml()
config.add_role_to_inventory(kolla_file, kolla_config)
config.enable_cinder_backend(req,
cluster_id,
kolla_config)
config.enable_neutron_backend(req, cluster_id, kolla_config)
def config_nodes_hosts(host_name_ip_list, host_ip):
config_scripts = []
hosts_file = "/etc/hosts"
@ -557,7 +402,7 @@ class KOLLAInstallTask(Thread):
self.cluster_id)
(kolla_config, self.mgt_ip_list, host_name_ip_list) = \
get_cluster_kolla_config(self.req, self.cluster_id)
kolla_cmn.get_cluster_kolla_config(self.req, self.cluster_id)
if not self.mgt_ip_list:
msg = _("there is no host in cluster %s") % self.cluster_id
raise exception.ThreadBinException(msg)
@ -664,13 +509,11 @@ class KOLLAInstallTask(Thread):
self.message, 15)
# always call generate_kolla_config_file after version_load()
# TODO: re-config docker registry server based upon return value of
# kolla_cmn.version_load_mcast
LOG.info(_("begin to generate kolla config file ..."))
(kolla_config, self.mgt_ip_list, host_name_ip_list) = \
get_cluster_kolla_config(self.req, self.cluster_id)
generate_kolla_config_file(self.req, self.cluster_id,
kolla_config, res)
kolla_cmn.get_cluster_kolla_config(self.req, self.cluster_id)
kolla_cmn.generate_kolla_config_file(self.req, self.cluster_id,
kolla_config, res)
LOG.info(_("generate kolla config file in /etc/kolla/ dir..."))
if thread_flag.get('flag', None) and thread_flag['flag'] == False:

View File

@ -112,11 +112,16 @@ class KOLLAUpgradeTask(Thread):
'messages': self.message})
res = kolla_cmn.version_load_mcast(kolla_version_pkg_file,
hosts_list)
hosts)
# always call generate_kolla_config_file after version_load()
LOG.info(_("begin to generate kolla config file ..."))
(kolla_config, self.mgt_ip_list, host_name_ip_list) = \
kolla_cmn.get_cluster_kolla_config(self.req, self.cluster_id)
kolla_cmn.generate_kolla_config_file(self.req, self.cluster_id,
kolla_config, res)
LOG.info(_("generate kolla config file in /etc/kolla/ dir..."))
# TODO: re-config docker registry server based upon return value of
# kolla_cmn.version_load_mcast
hosts_ip_set = set()
for host in hosts:
host_meta = daisy_cmn.get_host_detail(self.req, host["host_id"])
host_ip = daisy_cmn.get_management_ip(host_meta)

View File

@ -17,6 +17,7 @@ import mock
import webob
from daisy import test
from daisy.api.backends.kolla import install
from daisy.api.backends.kolla import common as kcommon
from daisy.context import RequestContext
import subprocess
from oslo_serialization import jsonutils
@ -481,7 +482,7 @@ class TestInstall(test.TestCase):
'ext_macname': u''}
(kolla_config, mgt_ip_list, host_name_ip_list) =\
install.get_cluster_kolla_config(
kcommon.get_cluster_kolla_config(
self.req,
'8ad27e36-f3e2-48b4-84b8-5b676c6fabde')
cmd_end1 = 'rm -rf %s/test.version' % daisy_kolla_ver_path
@ -509,8 +510,8 @@ class TestInstall(test.TestCase):
@mock.patch('daisy.api.backends.common.get_cluster_roles_detail')
@mock.patch('daisy.api.backends.common.get_cluster_networks_detail')
@mock.patch('daisy.api.backends.common.get_hosts_of_role')
@mock.patch('daisy.api.backends.kolla.install.generate_kolla_config_file')
@mock.patch('daisy.api.backends.kolla.install.get_cluster_kolla_config')
@mock.patch('daisy.api.backends.kolla.common.generate_kolla_config_file')
@mock.patch('daisy.api.backends.kolla.common.get_cluster_kolla_config')
@mock.patch('subprocess.Popen.poll')
@mock.patch('subprocess.check_output')
@mock.patch('daisy.api.backends.common.subprocess_call')

View File

@ -42,5 +42,5 @@ commands = python setup.py build_sphinx
# H404 multi line docstring should start with a summary
# H405 multi line docstring summary not separated with an empty line
# H904 Wrap long lines in parentheses instead of a backslash
ignore = E711,E712,H302,H402,H404,H405,H904,F841,F821,E265,F812,F402,E226,E731,H101,H201,H231,H233,H237,H238,H301,H306,H401,H403,H701,H702,H703,F999
ignore = E711,E712,H302,H402,H404,H405,H904,F841,F821,E265,F812,F402,E226,E731,H101,H201,H231,H233,H237,H238,H301,H306,H401,H403,H701,H702,H703,F999,H102,H903
exclude = .venv,.git,.tox,dist,doc,etc,*daisy/locale*,*openstack/common*,*lib/python*,*egg,build,daisy/db/sqlalchemy/api.py,daisy/i18n.py

View File

@ -36,6 +36,6 @@ downloadcache = ~/cache/pip
# H302 import only modules
# H303 no wildcard import
# H404 multi line docstring should start with a summary
ignore = F403,F812,F821,H233,H302,H303,H404,F841,F401,E731,H101,H201,H231,H233,H237,H238,H301,H306,H401,H403,H701,H702,H703,F999
ignore = F403,F812,F821,H233,H302,H303,H404,F841,F401,E731,E123,E501,H101,H201,H231,H233,H237,H238,H301,H306,H401,H402,H403,H701,H702,H703,F999,H102,H903
show-source = True
exclude = .venv,.tox,dist,doc,*egg,build

View File

@ -20,9 +20,7 @@ deps = -r{toxinidir}/requirements.txt
commands = /bin/bash run_tests.sh -N --no-pep8 {posargs}
[testenv:pep8]
commands =
/bin/bash run_tests.sh -N --pep8
/bin/bash run_tests.sh -N --makemessages --check-only
commands = flake8
[testenv:venv]
commands = {posargs}
@ -59,7 +57,7 @@ downloadcache = ~/cache/pip
[flake8]
exclude = .venv,.git,.tox,dist,*openstack/common*,*lib/python*,*egg,build,panel_template,dash_template,local_settings.py,*/local/*,*/test/test_plugins/*,.ropeproject
# H405 multi line docstring summary not separated with an empty line
ignore = H405,F821,F841,C901,E731,F405,H101,H201,H231,H233,H237,H238,H301,H306,H401,H403,H701,H702,H703,F999
ignore = H405,F821,F841,C901,E731,F405,H101,H104,H201,H231,H233,H237,H238,H301,H306,H401,H403,H404,H701,H702,H703,F999,H102,H903
max-complexity = 20
[hacking]

View File

@ -3,6 +3,6 @@
# E123 skipped because it is ignored by default in the default pep8
# E129 skipped because it is too limiting when combined with other rules
# Skipped because of new hacking 0.9: H405
ignore = E125,E123,E129,H404,H405,F999
ignore = E125,E123,E129,H404,H405,F999,H102,H903
show-source = True
exclude = .git,.venv,.tox,dist,doc,openstack,*egg

View File

@ -75,6 +75,7 @@ function kolla_install
echo -e "[Service]\nMountFlags=shared" > $config_path
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
check_and_install_rpm python-docker-py
check_and_install_rpm ntp
systemctl enable ntpd.service