summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYao Lu <lu.yao135@zte.com.cn>2016-11-17 16:02:52 +0800
committerYao Lu <lu.yao135@zte.com.cn>2016-11-19 09:36:40 +0000
commitea776f2faf1d99c49d3dcf256fd0eda840c83639 (patch)
tree45429fe147e03fb99446faa688bf29242c416c04
parent463ab9c7337079a68491d2eccb1e3778a8ec4479 (diff)
add common config and parse it to prepare deploy
Change-Id: I864082b885a4c7117f0b546da602e9580e8ccf46 Signed-off-by: Yao Lu <lu.yao135@zte.com.cn>
-rwxr-xr-xci/deploy/deploy.sh51
-rw-r--r--deploy/config/vm_environment/zte-virtual1/deploy.yml20
-rw-r--r--deploy/config/vm_environment/zte-virtual1/network.yml50
-rwxr-xr-xdeploy/get_conf.py123
-rwxr-xr-xdeploy/tempest.py164
5 files changed, 383 insertions, 25 deletions
diff --git a/ci/deploy/deploy.sh b/ci/deploy/deploy.sh
index 29c63cd0..11865b4a 100755
--- a/ci/deploy/deploy.sh
+++ b/ci/deploy/deploy.sh
@@ -2,7 +2,7 @@
##############################################################################
# Copyright (c) 2016 ZTE Coreporation and others.
# hu.zhijiang@zte.com.cn
-# sun.jing22@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
@@ -12,36 +12,37 @@
######exit before finish test#######
exit 0
-##########TODO after test#########################
-DAISYDIR=$WORKSPACE
-json_file=$DAISYDIR/deploy/config/vm_environment/zte-virtual/template.json
-source ~/daisyrc_admin
-daisy discover-host-add 192.168.122.152 ossdbg1
-daisy discover-host
+##########TODO after test##########
+DHA=$1
+NETWORK=$2
+tempest_path=$WORKSPACE/deploy
-cnt=30
-while [ $cnt -ge 0 ]; do
- host_id=`daisy host-list | awk -F "|" '{print $2}'| grep -o "[^ ]\+\( \+[^ ]\+\)*" `
- if [ -z "$host_id" ]; then
- echo "host have not discoverd , loop again ... "
- cnt=$[$cnt-1]
- sleep 30
- else
- echo "host list checkout successful... "
- break
- fi
-done
-daisy host-list
+echo "====== clean && install daisy==========="
+.$WORKSPACE/opnfv.bin clean
+rc=$?
+if [ $rc -ne 0 ]; then
+ echo "daisy clean failed"
+ exit 1
+else
+ echo "daisy clean successfully"
+fi
+.$WORKSPACE/opnfv.bin install
+rc=$?
+if [ $rc -ne 0 ]; then
+ echo "daisy install failed"
+ exit 1
+else
+ echo "daisy install successfully"
+fi
-echo "======prepare install os(centos) & kolla(openstack) ==========="
-daisy import-json-to-template $json_file
-daisy import-template-to-db template testdaisy
-daisy template-to-host testdaisy DaisyNode $host_id
+source ~/daisyrc_admin
+
+echo "======prepare install openstack==========="
+python $tempest_path/tempest.py --dha $DHA --network $NETWORK
echo "======daisy install kolla(openstack)==========="
cluster_id=`daisy cluster-list | awk -F "|" '{print $2}' | sed -n '4p'`
daisy install $cluster_id
-
echo "check installing proess..."
var=1
while [ $var -eq 1 ]; do
diff --git a/deploy/config/vm_environment/zte-virtual1/deploy.yml b/deploy/config/vm_environment/zte-virtual1/deploy.yml
new file mode 100644
index 00000000..5390ecf9
--- /dev/null
+++ b/deploy/config/vm_environment/zte-virtual1/deploy.yml
@@ -0,0 +1,20 @@
+hosts:
+- name: 'Node5'
+ roles:
+ - 'CONTROLLER_LB'
+ - 'COMPUTER'
+ ip: '192.168.122.152'
+ password: 'ossdbg1'
+ interface:
+ - 'ens3':
+ - name: 'MANAGEMENT'
+ ip: '192.168.122.152'
+ - name: 'PUBLICAPI'
+ ip:
+ - name: 'physnet1'
+ ip:
+ - name: 'STORAGE'
+ ip:
+ 'ens8':
+ - name: 'EXTERNAL'
+ ip:
diff --git a/deploy/config/vm_environment/zte-virtual1/network.yml b/deploy/config/vm_environment/zte-virtual1/network.yml
new file mode 100644
index 00000000..50fca1be
--- /dev/null
+++ b/deploy/config/vm_environment/zte-virtual1/network.yml
@@ -0,0 +1,50 @@
+##############################################################################
+# Copyright (c) 2016 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@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
+##############################################################################
+
+network-config-metadata:
+ title: 'zte-virtual1 network config'
+ version: '0.1'
+ created: 'Mon Oct 31 2016'
+ comment:
+networks:
+- cidr: '192.168.122.0/24'
+ gateway: '192.168.122.1'
+ ip_ranges:
+ - 'start': '192.168.122.1'
+ 'end': '192.168.122.254'
+ name: 'MANAGEMENT'
+- cidr: '192.168.122.0/24'
+ gateway: '192.168.122.1'
+ ip_ranges:
+ - start: '192.168.122.1'
+ end: '192.168.122.254'
+ name: 'STORAGE'
+- cidr: '192.168.2.0/24'
+ gateway: '192.168.2.1'
+ ip_ranges:
+ - 'start': '192.168.2.1'
+ 'end': '192.168.2.254'
+ 'name': 'EXTERNAL'
+- cidr: '192.168.122.0/24'
+ gateway: '192.168.122.1'
+ ip_ranges:
+ - 'start': '192.168.122.1'
+ 'end': '192.168.122.254'
+ name: 'PUBLICAPI'
+- cidr: '192.168.122.0/24'
+ gateway: '192.168.122.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'
diff --git a/deploy/get_conf.py b/deploy/get_conf.py
new file mode 100755
index 00000000..37cacb51
--- /dev/null
+++ b/deploy/get_conf.py
@@ -0,0 +1,123 @@
+#!/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 yaml
+
+
+def init(file):
+ with open(file) as fd:
+ return yaml.load(fd)
+
+
+def networkdecorator(func):
+ def wrapter(s, seq):
+ network_list = s.get('networks', [])
+ result = {}
+ for network in network_list:
+ s = func(s, seq, network)
+ if not s:
+ continue
+ result.update(s)
+ if len(result) == 0:
+ return ""
+ else:
+ return result
+ return wrapter
+
+
+def hostdecorator(func):
+ def wrapter(s, seq):
+ host_list = s.get('hosts', [])
+ result = {}
+ for host in host_list:
+ s = func(s, seq, host)
+ if not s:
+ continue
+ result.update(s)
+ if len(result) == 0:
+ return ""
+ else:
+ return result
+ return wrapter
+
+
+def decorator(func):
+ def wrapter(s, seq):
+ host_list = s.get('hosts', [])
+ result = []
+ for host in host_list:
+ s = func(s, seq, host)
+ if not s:
+ continue
+ result.append(s)
+ if len(result) == 0:
+ return ""
+ else:
+ return result
+ return wrapter
+
+
+@networkdecorator
+def network(s, seq, network=None):
+ net_plane = network.get('name', '')
+ network.pop('name')
+ map = {}
+ map[net_plane] = network
+ return map
+
+
+@hostdecorator
+def interface(s, seq, host=None):
+ hostname = host.get('name', '')
+ interface = host.get('interface', '')[0]
+ map = {}
+ map[hostname] = interface
+ return map
+
+
+@hostdecorator
+def role(s, seq, host=None):
+ hostname = host.get('name', '')
+ role = host.get('roles', '')
+ map = {}
+ map[hostname] = role
+ return map
+
+
+@decorator
+def host(s, seq, host=None):
+ hostip = host.get('ip', [])
+ passwd = host.get('password', [])
+ map = {}
+ map = {'ip': hostip, 'passwd': passwd}
+ return map
+
+
+def network_config_parse(s, dha_file):
+ network_map = network(s, ',')
+ vip = s.get('internal_vip')
+ return network_map, vip
+
+
+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
+
+
+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)
+ data = init(network_file)
+ network_map, vip = network_config_parse(data, network_file)
+ return host_interface_map, host_role_map, \
+ host_ip_passwd_map, network_map, vip
diff --git a/deploy/tempest.py b/deploy/tempest.py
new file mode 100755
index 00000000..011f1e5c
--- /dev/null
+++ b/deploy/tempest.py
@@ -0,0 +1,164 @@
+#!/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
+##############################################################################
+from oslo_config import cfg
+import sys
+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)
+
+cluster_name = "clustertest"
+
+_CLI_OPTS = [
+ cfg.StrOpt('dha',
+ help='The dha file path'),
+ cfg.StrOpt('network',
+ help='The network file path'),
+]
+
+
+# ------------------------------------------------------------------------------------------
+def parse(conf, args):
+ conf.register_cli_opts(_CLI_OPTS)
+ conf(args=args)
+
+
+def print_bar(msg):
+ print ("--------------------------------------------")
+ print (msg)
+ print ("--------------------------------------------")
+
+
+def foo():
+ 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 = \
+ 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)
+ 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()
+ while True:
+ hosts_info = get_hosts()
+ if len(hosts_info) == len(host_ip_passwd_map):
+ print('discover hosts success!')
+ break
+ else:
+ time.sleep(10)
+
+
+def update_network(cluster_id, network_map):
+ network_meta = {'filters': {'cluster_id': cluster_id}}
+ network_info_gernerator = client.networks.list(**network_meta)
+ network_info_list = [net for net in network_info_gernerator]
+ for net in network_info_list:
+ network_id = net.id
+ network_name = net.name
+ if network_map.get(network_name):
+ network_meta = network_map[network_name]
+ client.networks.update(network_id, **network_meta)
+
+
+def get_hosts():
+ hosts_list_generator = client.hosts.list()
+ hosts_list = [host for host in hosts_list_generator]
+ hosts_info = []
+ for host in hosts_list:
+ host_info = client.hosts.get(host.id)
+ hosts_info.append(host_info)
+ return hosts_info
+
+
+def add_hosts_interface(cluster_id, hosts_info, host_interface_map,
+ host_role_map, 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]
+ client.hosts.update(host['id'], **host)
+ print("update role...")
+ add_host_role(cluster_id, host['id'], host['name'],
+ host_role_map, vip)
+
+
+def add_host_role(cluster_id, host_id, host_name, host_role_map, 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]
+ lb_role_id = [role.id for role in role_list if
+ 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)
+
+
+if __name__ == "__main__":
+ foo()