summaryrefslogtreecommitdiffstats
path: root/deploy/tempest.py
diff options
context:
space:
mode:
authorZhijiang Hu <hu.zhijiang@zte.com.cn>2016-12-20 07:29:16 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-12-20 07:29:16 +0000
commitd5df56b8ef5d5967e471db482d09fac36afc449a (patch)
treeffda79a1f00c54ef81f854b38037f18cec4d5dc9 /deploy/tempest.py
parent3dce9ea92689ace8b88c3996b28adc09d3ab8197 (diff)
parent0b57e3be28f1b42d7cea436feb04fbcdf83e8484 (diff)
Merge "implement deploy on virthal pod"
Diffstat (limited to 'deploy/tempest.py')
-rwxr-xr-xdeploy/tempest.py123
1 files changed, 63 insertions, 60 deletions
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()