From 0b57e3be28f1b42d7cea436feb04fbcdf83e8484 Mon Sep 17 00:00:00 2001 From: Yao Lu Date: Tue, 29 Nov 2016 22:39:37 +0800 Subject: implement deploy on virthal pod Change-Id: I600e21f0d36f37c75cac4ace5f7225e32ab93d56 Signed-off-by: Yao Lu --- deploy/check_openstack_progress.sh | 20 ++++ deploy/check_os_progress.sh | 22 ++++ .../config/vm_environment/zte-virtual1/deploy.yml | 26 ++--- .../config/vm_environment/zte-virtual1/network.yml | 59 +++++----- deploy/daisy.conf | 34 ++++++ deploy/get_conf.py | 50 +++++---- deploy/get_para_from_deploy.py | 52 +++++++++ deploy/tempest.py | 123 +++++++++++---------- deploy/trustme.sh | 88 +++++++++++++++ 9 files changed, 351 insertions(+), 123 deletions(-) create mode 100755 deploy/check_openstack_progress.sh create mode 100755 deploy/check_os_progress.sh create mode 100644 deploy/daisy.conf create mode 100755 deploy/get_para_from_deploy.py create mode 100755 deploy/trustme.sh (limited to 'deploy') diff --git a/deploy/check_openstack_progress.sh b/deploy/check_openstack_progress.sh new file mode 100755 index 00000000..c1c88eb8 --- /dev/null +++ b/deploy/check_openstack_progress.sh @@ -0,0 +1,20 @@ +#!/bin/bash +source /root/daisyrc_admin +echo "check openstack installing progress..." +cluster_id=`daisy cluster-list | awk -F "|" '{print $2}' | sed -n '4p'` +while true; do + openstack_install_active=`daisy host-list --cluster-id $cluster_id | awk -F "|" '{print $12}' | grep -c "active" ` + openstack_install_failed=`daisy host-list --cluster-id $cluster_id | awk -F "|" '{print $12}' | grep -c "install-failed" ` + if [ $openstack_install_active -eq 1 ]; then + echo "openstack installing successful ..." + break + elif [ $openstack_install_failed -gt 0 ]; then + echo "openstack installing have failed..." + tail -n 200 /var/log/daisy/kolla_$cluster_id* + exit 1 + else + progress=`daisy host-list --cluster-id $cluster_id |grep DISCOVERY_SUCCESSFUL |awk -F "|" '{print $11}'|sed s/[[:space:]]//g` + echo " openstack in installing , progress is $progress%" + sleep 30 + fi +done diff --git a/deploy/check_os_progress.sh b/deploy/check_os_progress.sh new file mode 100755 index 00000000..bf44fe28 --- /dev/null +++ b/deploy/check_os_progress.sh @@ -0,0 +1,22 @@ +#!/bin/bash +source /root/daisyrc_admin +cluster_id=`daisy cluster-list | awk -F "|" '{print $2}' | sed -n '4p'` +daisy install $cluster_id --skip-pxe-ipmi true +echo "check os installing progress..." +while true; do + os_install_active=`daisy host-list --cluster-id $cluster_id | awk -F "|" '{print $8}' | grep -c "active" ` + os_install_failed=`daisy host-list --cluster-id $cluster_id | awk -F "|" '{print $8}' | grep -c "install-failed" ` + if [ $os_install_active -eq 1 ]; then + echo "os installing successful ..." + break + elif [ $os_install_failed -gt 0 ]; then + echo "os installing have failed..." + exit 1 + else + progress=`daisy host-list --cluster-id $cluster_id |grep DISCOVERY_SUCCESSFUL |awk -F "|" '{print $7}'|sed s/[[:space:]]//g` + echo "os in installing, the progress is $progress%" + sleep 10 + fi +done +systemctl disable dhcpd +systemctl stop dhcpd diff --git a/deploy/config/vm_environment/zte-virtual1/deploy.yml b/deploy/config/vm_environment/zte-virtual1/deploy.yml index e12a981e..78c32014 100644 --- a/deploy/config/vm_environment/zte-virtual1/deploy.yml +++ b/deploy/config/vm_environment/zte-virtual1/deploy.yml @@ -1,22 +1,12 @@ hosts: -- name: 'Node5' +- name: 'all_in_one' roles: - 'CONTROLLER_LB' - 'COMPUTER' - ip: '192.168.122.152' - password: 'ossdbg1' - interface: - - phynic: 'ens3' - logic: - - name: 'MANAGEMENT' - ip: '192.168.122.152' - - name: 'PUBLICAPI' - ip: - - name: 'physnet1' - ip: - - name: 'STORAGE' - ip: - - phynic: 'ens8' - logic: - - name: 'EXTERNAL' - ip: +disks: + daisy: 100G + controller: 100G + compute: 100G +daisy_passwd: 'r00tme' +daisy_ip: '10.20.11.2' +daisy_gateway: '10.20.11.1' diff --git a/deploy/config/vm_environment/zte-virtual1/network.yml b/deploy/config/vm_environment/zte-virtual1/network.yml index ea08117d..36863882 100644 --- a/deploy/config/vm_environment/zte-virtual1/network.yml +++ b/deploy/config/vm_environment/zte-virtual1/network.yml @@ -14,37 +14,46 @@ network-config-metadata: created: 'Mon Oct 31 2016' comment: networks: - - cidr: '192.168.122.0/24' - gateway: '192.168.122.1' + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' ip_ranges: - - 'start': '192.168.122.1' - 'end': '192.168.122.254' + - 'start': '10.20.11.3' + 'end': '10.20.11.10' name: 'MANAGEMENT' - - cidr: '192.168.122.0/24' - gateway: '192.168.122.1' + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' ip_ranges: - - start: '192.168.122.1' - end: '192.168.122.254' + - start: '10.20.11.3' + end: '10.20.11.10' name: 'STORAGE' - - cidr: '192.168.2.0/24' - gateway: '192.168.2.1' + - cidr: '172.10.101.0/24' + gateway: '172.10.101.0' ip_ranges: - - 'start': '192.168.2.1' - 'end': '192.168.2.254' + - 'start': '172.10.101.1' + 'end': '172.10.101.10' 'name': 'EXTERNAL' - - cidr: '192.168.122.0/24' - gateway: '192.168.122.1' + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' ip_ranges: - - 'start': '192.168.122.1' - 'end': '192.168.122.254' + - 'start': '10.20.11.3' + 'end': '10.20.11.10' name: 'PUBLICAPI' - - cidr: '192.168.122.0/24' - gateway: '192.168.122.1' + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' ip_ranges: - - 'start': '192.168.122.1' - 'end': '192.168.122.254' - name: 'physnet1' - -internal_vip: '192.168.122.144' - -public_vip: '192.168.122.144' + - 'start': '10.20.11.3' + 'end': '10.20.11.10' + name: 'TENANT' +interfaces: + - name: 'EXTERNAL' + interface: 'ens8' + - name: 'MANAGEMENT' + interface: 'ens3' + - name: 'PUBLICAPI' + interface: 'ens3' + - name: 'STORAGE' + interface: 'ens3' + - name: 'TENANT' + interface: 'ens3' +internal_vip: '10.20.11.11' +public_vip: '10.20.11.11' diff --git a/deploy/daisy.conf b/deploy/daisy.conf new file mode 100644 index 00000000..f8ce0534 --- /dev/null +++ b/deploy/daisy.conf @@ -0,0 +1,34 @@ +[DEFAULT] +#The mangement ip of daisy +#When Daisy will be installed in the virtual machine, this option is required. +daisy_management_ip= + +[BACKEND] +#Default backend types of daisy, including tecs, zenic, proton, kolla. +#If you want to create a cluster with more than one backend, +#all backend names should be provided for this configuration item, +#such as, default_backend_types=tecs,zenic,proton,kolla. +default_backend_types=kolla + +[OS] +#Default os install types of daisy +os_install_type=pxe + +[PXE] +#Set to 'yes' if you want to build a PXE server, otherwise to 'no'. +build_pxe=no + +#the nic name, to build a PXE server on this nic. +eth_name= + +#The ip value of PXE server +ip_address=99.99.1.5 + +#the net mask of PXE server +net_mask=255.255.255.0 + +#The start value of PXE client ip range +client_ip_begin=99.99.1.50 + +#The end value of PXE client ip range +client_ip_end=99.99.1.150 diff --git a/deploy/get_conf.py b/deploy/get_conf.py index 5ce9806b..eaac8b17 100755 --- a/deploy/get_conf.py +++ b/deploy/get_conf.py @@ -23,7 +23,9 @@ def decorator_mk(types): result = {} for item in item_list: ret = func(item) - if ret: + if ret.keys()[0] in result: + result[ret.keys()[0]].append(ret.values()[0][0]) + else: result.update(ret) return result return wrapter @@ -33,20 +35,24 @@ def decorator_mk(types): @decorator_mk('networks') def network(network=None): net_plane = network.get('name', '') + if net_plane == "TENANT": + net_plane = "physnet1" network.pop('name') map = {} map[net_plane] = network return map -@decorator_mk('hosts') -def interface(host=None): - interface = host.get('interface', '') - map = {} - for k in interface: - for v in k['logic']: - map[v['name']] = {'ip': v['ip'], 'phynic': k['phynic']} - return map +@decorator_mk('interfaces') +def interface(interface=None): + net_name = interface.get('name', '') + if net_name == "TENANT": + net_name = "physnet1" + interface_name = interface.get('interface', '') + map2 = {} + map = {'ip': '', 'name': net_name} + map2[interface_name] = [map] + return map2 @decorator_mk('hosts') @@ -70,23 +76,27 @@ def host(host=None): def network_config_parse(s, dha_file): network_map = network(s) vip = s.get('internal_vip') - return network_map, vip + interface_map = interface(s) + return network_map, vip, interface_map def dha_config_parse(s, dha_file): - host_interface_map = interface(s) host_role_map = role(s) - host_ip_passwd_map = host(s) - return host_interface_map, host_role_map, host_ip_passwd_map + hosts_name = [] + for name in host_role_map: + hosts_name.append(name) + return hosts_name def config(dha_file, network_file): data = init(dha_file) - host_interface_map, host_role_map, host_ip_passwd_map = \ - dha_config_parse(data, dha_file) + hosts_name = dha_config_parse(data, dha_file) data = init(network_file) - network_map, vip = network_config_parse(data, network_file) - for k in host_interface_map: - host_interface_map[k].update(network_map[k]) - return host_interface_map, host_role_map, \ - host_ip_passwd_map, network_map, vip + network_map, vip, interface_map = network_config_parse(data, network_file) + for interface_name in interface_map: + for name in interface_map[interface_name]: + if name.get('name', None) == 'MANAGEMENT': + name['ip'] = network_map.get( + 'MANAGEMENT', None).get( + 'ip_ranges', None)[0].get('start', None) + return interface_map, hosts_name, network_map, vip diff --git a/deploy/get_para_from_deploy.py b/deploy/get_para_from_deploy.py new file mode 100755 index 00000000..c0e08c56 --- /dev/null +++ b/deploy/get_para_from_deploy.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +############################################################################## +# Copyright (c) 2016 ZTE Coreporation and others. +# hu.zhijiang@zte.com.cn +# lu.yao135@zte.com.cn +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import get_conf +from oslo_config import cfg +import sys + +_CLI_OPTS = [ + cfg.StrOpt('dha', + help='The dha file path'), +] + + +def parse(conf, args): + conf.register_cli_opts(_CLI_OPTS) + conf(args=args) + + +def get_yml_para(dha_file): + data = get_conf.init(dha_file) + disks = data.get("disks", 0) + daisyserver_size = disks.get("daisy", 0) + controller_node_size = disks.get("controller", 0) + compute_node_size = disks.get("compute", 0) + daisy_passwd = data.get("daisy_passwd", "") + daisy_ip = data.get("daisy_ip", "") + daisy_gateway = data.get("daisy_gateway", "") + return daisyserver_size, controller_node_size,\ + compute_node_size, daisy_passwd, daisy_ip, daisy_gateway + + +def get_conf_from_deploy(): + conf = cfg.ConfigOpts() + parse(conf, sys.argv[1:]) + daisyserver_size, controller_node_size, compute_node_size,\ + daisy_passwd, daisy_ip, daisy_gateway = get_yml_para(conf['dha']) + print daisyserver_size + print controller_node_size + print compute_node_size + print daisy_passwd + print daisy_ip + print daisy_gateway + +if __name__ == "__main__": + get_conf_from_deploy() diff --git a/deploy/tempest.py b/deploy/tempest.py index 011f1e5c..1efe159f 100755 --- a/deploy/tempest.py +++ b/deploy/tempest.py @@ -14,12 +14,12 @@ from daisyclient.v1 import client as daisy_client import get_conf import traceback import time -import subprocess daisy_version = 1.0 daisy_endpoint = "http://127.0.0.1:19292" client = daisy_client.Client(version=daisy_version, endpoint=daisy_endpoint) - +iso_path = "/var/lib/daisy/kolla/CentOS-7-x86_64-DVD-1511.iso" +deployment_interface = "ens3" cluster_name = "clustertest" _CLI_OPTS = [ @@ -27,6 +27,10 @@ _CLI_OPTS = [ help='The dha file path'), cfg.StrOpt('network', help='The network file path'), + cfg.StrOpt('cluster', + help='Config cluster'), + cfg.StrOpt('host', + help='Config host'), ] @@ -42,62 +46,56 @@ def print_bar(msg): print ("--------------------------------------------") -def foo(): +def prepare_install(): try: print("get config...") conf = cfg.ConfigOpts() parse(conf, sys.argv[1:]) - host_interface_map, host_role_map, \ - host_ip_passwd_map, network_map, vip = \ + host_interface_map, hosts_name, network_map, vip = \ get_conf.config(conf['dha'], conf['network']) - print("clean deploy host...") - clean_deploy_host(host_ip_passwd_map) - print("discover host...") - discover_host(host_ip_passwd_map) - print("add cluster...") - cluster_meta = {'name': cluster_name, 'description': ''} - clusters_info = client.clusters.add(**cluster_meta) - cluster_id = clusters_info.id - print("cluster_id=%s." % cluster_id) - print("update network...") - update_network(cluster_id, network_map) - print("update hosts interface...") - hosts_info = get_hosts() - add_hosts_interface(cluster_id, hosts_info, host_interface_map, - host_role_map, vip) + if conf['cluster'] and conf['cluster'] == 'yes': + print("add cluster...") + cluster_meta = {'name': cluster_name, 'description': '', + 'target_systems': 'os+kolla'} + clusters_info = client.clusters.add(**cluster_meta) + cluster_id = clusters_info.id + print("cluster_id=%s." % cluster_id) + print("update network...") + update_network(cluster_id, network_map) + print("build pxe...") + build_pxe_for_discover(cluster_id) + elif conf['host'] and conf['host'] == 'yes': + print("discover host...") + discover_host(hosts_name) + print("update hosts interface...") + hosts_info = get_hosts() + cluster_info = get_cluster() + cluster_id = cluster_info.id + add_hosts_interface(cluster_id, hosts_info, + host_interface_map, vip) + build_pxe_for_os(cluster_id) except Exception: print("Deploy failed!!!.%s." % traceback.format_exc()) else: print_bar("Everything is done!") -def clean_deploy_host(host_ip_passwd_map): - for host_ip_passwd in host_ip_passwd_map: - command = 'sshpass -p %s ssh %s -o UserKnownHostsFile=/dev/null \ - -oStrictHostKeyChecking=no \ - "/home/daisy/forDel/tools/cleanup-containers"' % \ - (host_ip_passwd['passwd'], host_ip_passwd['ip']) - subprocess.call(command, - shell=True, - stdout=open('/dev/null', 'w'), - stderr=subprocess.STDOUT) - command = 'sshpass -p %s ssh %s -o UserKnownHostsFile=/dev/null \ - -oStrictHostKeyChecking=no \ - "/home/daisy/forDel/tools/cleanup-images"' % \ - (host_ip_passwd['passwd'], host_ip_passwd['ip']) - subprocess.call(command, - shell=True, - stdout=open('/dev/null', 'w'), - stderr=subprocess.STDOUT) - - -def discover_host(host_ip_passwd_map): - for host_ip_passwd in host_ip_passwd_map: - client.hosts.add_discover_host(**host_ip_passwd) - client.hosts.discover_host() +def build_pxe_for_discover(cluster_id): + cluster_meta = {'cluster_id': cluster_id, + 'deployment_interface': deployment_interface} + client.install.install(**cluster_meta) + + +def build_pxe_for_os(cluster_id): + cluster_meta = {'cluster_id': cluster_id, + 'pxe_only': "true"} + client.install.install(**cluster_meta) + + +def discover_host(hosts_name): while True: hosts_info = get_hosts() - if len(hosts_info) == len(host_ip_passwd_map): + if len(hosts_info) == len(hosts_name): print('discover hosts success!') break else: @@ -126,23 +124,30 @@ def get_hosts(): return hosts_info +def get_cluster(): + cluster_list_generator = client.clusters.list() + cluster_list = [cluster for cluster in cluster_list_generator] + for cluster in cluster_list: + cluster_info = client.clusters.get(cluster.id) + return cluster_info + + def add_hosts_interface(cluster_id, hosts_info, host_interface_map, - host_role_map, vip): + vip): for host in hosts_info: host = host.to_dict() host['cluster'] = cluster_id - host_name = host['name'] for interface in host['interfaces']: interface_name = interface['name'] interface['assigned_networks'] = \ - host_interface_map[host_name][interface_name] + host_interface_map[interface_name] + host['os_version'] = iso_path client.hosts.update(host['id'], **host) print("update role...") - add_host_role(cluster_id, host['id'], host['name'], - host_role_map, vip) + add_host_role(cluster_id, host['id'], host['name'], vip) -def add_host_role(cluster_id, host_id, host_name, host_role_map, vip): +def add_host_role(cluster_id, host_id, host_name, vip): role_meta = {'filters': {'cluster_id': cluster_id}} role_list_generator = client.roles.list(**role_meta) role_list = [role for role in role_list_generator] @@ -150,15 +155,13 @@ def add_host_role(cluster_id, host_id, host_name, host_role_map, vip): role.name == "CONTROLLER_LB"][0] computer_role_id = [role.id for role in role_list if role.name == "COMPUTER"][0] - if "CONTROLLER_LB" in host_role_map[host_name]: - role_lb_update_meta = {'nodes': [host_id], - 'cluster_id': cluster_id, 'vip': vip} - client.roles.update(lb_role_id, **role_lb_update_meta) - if "COMPUTER" in host_role_map[host_name]: - role_computer_update_meta = {'nodes': [host_id], - 'cluster_id': cluster_id} - client.roles.update(computer_role_id, **role_computer_update_meta) + role_lb_update_meta = {'nodes': [host_id], + 'cluster_id': cluster_id, 'vip': vip} + client.roles.update(lb_role_id, **role_lb_update_meta) + role_computer_update_meta = {'nodes': [host_id], + 'cluster_id': cluster_id} + client.roles.update(computer_role_id, **role_computer_update_meta) if __name__ == "__main__": - foo() + prepare_install() diff --git a/deploy/trustme.sh b/deploy/trustme.sh new file mode 100755 index 00000000..eedda5ce --- /dev/null +++ b/deploy/trustme.sh @@ -0,0 +1,88 @@ +#!/bin/sh +#to be trusted by other host£¬and no password needed when use ssh command + +#check parameters legality +logfile=/var/log/trustme.log +function print_log +{ + local promt="$1" + echo -e "$promt" + echo -e "`date -d today +"%Y-%m-%d %H:%M:%S"` $promt" >> $logfile +} +ip=$1 +passwd=$2 +if [ -z $passwd ]; then + print_log "Usage: `basename $0` ipaddr passwd" + exit 1 +fi + +rpm -qi sshpass >/dev/null +if [ $? != 0 ]; then + print_log "Please install sshpass first" + exit 1 +fi + +#ping other host +unreachable=`ping $ip -c 1 -W 3 | grep -c "100% packet loss"` +if [ $unreachable -eq 1 ]; then + print_log "host $ip is unreachable" + exit 1 +fi + +#generate ssh pubkey +if [ ! -e ~/.ssh/id_dsa.pub ]; then + print_log "generating ssh public key ..." + ssh-keygen -t dsa -f /root/.ssh/id_dsa -N "" <> ~/.ssh/authorized_keys" +if [ $? != 0 ]; then + print_log "ssh $ip to add public key for authorized_keys failed" + exit 1 +fi +print_log "rm tmp file $ip:$tmpfile" +sshpass -p $passwd ssh -o StrictHostKeyChecking=no $ip "rm $tmpfile" +if [ $? != 0 ]; then + print_log "ssh $ip to delete tmp file failed" + exit 1 +fi +print_log "trustme ok!" + -- cgit 1.2.3-korg