add ip to EXTERNAL plane to add the vlan isolation

modify config network to thread

Change-Id: I21a02e5a63bef49b681f3b90d9b311ceffcb8375
This commit is contained in:
zhouya 2017-05-31 15:27:57 +08:00
parent 1b27aacb08
commit b67988c905
3 changed files with 117 additions and 30 deletions

View File

@ -14,12 +14,10 @@
# under the License.
import re
import os
import yaml
import subprocess
from oslo_log import log as logging
from daisy import i18n
from Crypto.PublicKey import RSA
import daisy.registry.client.v1.api as registry
import daisy.api.backends.common as daisy_cmn

View File

@ -302,27 +302,67 @@ def config_nodes_hosts(host_name_ip_list, host_ip):
def _calc_progress(log_file):
progress = 20
progress = 30
mariadb_result = subprocess.call(
'cat %s |grep "Running MariaDB"' % log_file,
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if mariadb_result == 0:
progress = 30
progress = 35
rabbitmq_result = subprocess.call(
'cat %s |grep "Running RabbitMQ"' % log_file,
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if rabbitmq_result == 0:
progress = 40
keystone_result = subprocess.call(
'cat %s |grep "Running Keystone"' % log_file,
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if keystone_result == 0:
progress = 40
nova_result = subprocess.call(
'cat %s |grep "Running Nova"' % log_file, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if nova_result == 0:
progress = 45
glance_result = subprocess.call(
'cat %s |grep "Running Glance"' % log_file,
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if glance_result == 0:
progress = 50
cinder_result = subprocess.call(
'cat %s |grep "Running Cinder"' % log_file,
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if cinder_result == 0:
progress = 55
nova_bootstrap_result = subprocess.call(
'cat %s |grep "Running Nova bootstrap"' % log_file,
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if nova_bootstrap_result == 0:
progress = 60
neutron_result = subprocess.call(
'cat %s |grep "Running Neutron"' % log_file, shell=True,
nova_simple_result = subprocess.call(
'cat %s |grep "Running nova simple"' % log_file, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if neutron_result == 0:
if nova_simple_result == 0:
progress = 65
netron_bootstrap_result = subprocess.call(
'cat %s |grep "Running Neutron bootstrap"' % log_file, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if netron_bootstrap_result == 0:
progress = 70
neutron_lbaas_result = subprocess.call(
'cat %s |grep "Running Neutron lbaas"' % log_file, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if neutron_lbaas_result == 0:
progress = 75
neutron_vpnaas_result = subprocess.call(
'cat %s |grep "Running Neutron vpnaas"' % log_file, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if neutron_vpnaas_result == 0:
progress = 80
heat_result = subprocess.call(
'cat %s |grep "Running Heat"' % log_file, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if heat_result == 0:
progress = 85
horizon_result = subprocess.call(
'cat %s |grep "Restart horizon"' % log_file, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if horizon_result == 0:
progress = 90
return progress
@ -344,12 +384,41 @@ def _get_hosts_id_by_mgnt_ips(req, cluster_id, ips):
return hosts_id_needed
def _thread_bin(req, host, root_passwd, fp, host_name_ip_list,
def configure_external_interface_vlan(req, cluster_id, host_ip):
cluster_networks = daisy_cmn.get_cluster_networks_detail(req, cluster_id)
for network in cluster_networks:
if 'EXTERNAL' in network.get('network_type') and \
network.get('vlan_id') != None:
ext_interface = network.get('physnet_name').split("_")[1]
cmd1 = 'ssh -o StrictHostKeyChecking=no %s \
"touch /etc/sysconfig/network-scripts/ifcfg-%s.%s"' \
% (host_ip, ext_interface, network.get('vlan_id'))
cmd2 = 'echo -e "BOOTPROTO=static\nONBOOT=yes\nDEVICE=%s.%s\n'\
'VLAN=yes" > /etc/sysconfig/network-scripts/ifcfg-%s.%s' \
% (ext_interface, network.get('vlan_id'),
ext_interface, network.get('vlan_id'))
cmd3 = "ssh -o StrictHostKeyChecking=no %s '%s'" % (host_ip, cmd2)
try:
exc_cmd1 = subprocess.check_output(cmd1,
shell=True,
stderr=subprocess.STDOUT)
exc_cmd2 = subprocess.check_output(cmd3,
shell=True,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
message = "config external interface vlan on %s failed!"\
% host_ip
LOG.error(message + e)
raise exception.InstallException(message)
else:
LOG.info(_("config external interface vlan on %s successfully!"
% host_ip))
def _thread_bin(req, cluster_id, host, root_passwd, fp, host_name_ip_list,
host_prepare_file, docker_registry_ip, role_id_list):
host_ip = host['mgtip']
cmd = '/var/lib/daisy/trustme.sh %s %s' % \
(host_ip, root_passwd)
daisy_cmn.subprocess_call(cmd, fp)
config_nodes_hosts(host_name_ip_list, host_ip)
cmd = 'ssh -o StrictHostKeyChecking=no %s \
@ -387,7 +456,7 @@ def _thread_bin(req, host, root_passwd, fp, host_name_ip_list,
shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
message = "exec prepare.sh in %s failed!" % host_ip
LOG.error(message)
LOG.error(message + e)
fp.write(e.output.strip())
raise exception.InstallException(message)
else:
@ -399,14 +468,14 @@ def _thread_bin(req, host, root_passwd, fp, host_name_ip_list,
message, 10)
def thread_bin(req, host, root_passwd, fp, host_name_ip_list,
def thread_bin(req, cluster_id, host, root_passwd, fp, host_name_ip_list,
host_prepare_file, docker_registry_ip, role_id_list):
try:
_thread_bin(req, host, root_passwd, fp, host_name_ip_list,
_thread_bin(req, cluster_id, host, root_passwd, fp, host_name_ip_list,
host_prepare_file, docker_registry_ip, role_id_list)
except Exception as e:
message = "Prepare for installation failed!"
LOG.error(message)
LOG.error(message + e)
update_host_progress_to_db(req, role_id_list, host,
kolla_state['INSTALL_FAILED'],
message)
@ -479,6 +548,7 @@ class KOLLAInstallTask(Thread):
raise exception.InstallException(self.message)
root_passwd = 'ossdbg1'
threads_net = []
for mgnt_ip in self.mgt_ip_list:
check_hosts_id = _get_hosts_id_by_mgnt_ips(self.req,
self.cluster_id,
@ -486,10 +556,29 @@ class KOLLAInstallTask(Thread):
is_ssh_host = daisy_cmn._judge_ssh_host(self.req,
check_hosts_id[0])
if not is_ssh_host:
LOG.info(_("Begin to config network\
on %s" % mgnt_ip))
cmd = '/var/lib/daisy/trustme.sh %s %s' % \
(mgnt_ip, root_passwd)
daisy_cmn.subprocess_call(cmd)
LOG.info(_("Begin to config network on %s" % mgnt_ip))
ssh_host_info = {'ip': mgnt_ip, 'root_pwd': root_passwd}
api_cmn.config_network_new(ssh_host_info, 'kolla')
configure_external_interface_vlan(self.req,
self.cluster_id,
mgnt_ip)
t_net = threading.Thread(target=api_cmn.config_network_new,
args=(ssh_host_info, 'kolla'))
t_net.setDaemon(True)
t_net.start()
threads_net.append(t_net)
try:
LOG.info(_("config network threads"
" have started, please waiting...."))
for t_net in threads_net:
t_net.join()
except:
LOG.error("join config network "
"thread %s failed!" % t_net)
#api_cmn.config_network_new(ssh_host_info, 'kolla')
time.sleep(20)
@ -498,15 +587,15 @@ class KOLLAInstallTask(Thread):
self.message = "Begin install"
update_all_host_progress_to_db(self.req, role_id_list,
host_id_list, kolla_state['INSTALLING'],
self.message, 0)
self.message, 5)
docker_registry_ip = kolla_cmn._get_local_ip()
with open(self.log_file, "w+") as fp:
threads = []
for host in hosts_list:
t = threading.Thread(target=thread_bin,
args=(self.req, host, root_passwd, fp,
host_name_ip_list,
args=(self.req, self.cluster_id, host,
root_passwd, fp, host_name_ip_list,
self.host_prepare_file,
docker_registry_ip, role_id_list))
t.setDaemon(True)
@ -597,15 +686,15 @@ class KOLLAInstallTask(Thread):
(self.kolla_file, self.kolla_file),
shell=True, stdout=fp, stderr=fp)
self.message = "begin deploy openstack"
self.progress = 20
self.progress = 25
execute_times = 0
while True:
time.sleep(5)
return_code = cmd.poll()
if self.progress == 90:
if self.progress == 95:
break
elif return_code == 0:
self.progress = 90
self.progress = 95
elif return_code == 1:
self.message = "KOLLA deploy openstack failed"
LOG.error(self.message)

View File

@ -208,7 +208,7 @@ class TestOsInstall(test.TestCase):
@mock.patch("daisy.api.backends.common.get_local_deployment_ip")
@mock.patch('daisy.api.backends.common.update_db_host_status')
@mock.patch('daisy.api.backends.common.subprocess_call')
def test_upgrade_no_local_ip(self, mock_subprocess_call,
def test_upgrade_no_local_ip(self, mock_subprocess_call,
mock_update_db_host,
mock_get_local_deployment_ip,
mock_check_ping_hosts,