summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhongjun <zhong.jun@zte.com.cn>2017-05-19 08:52:41 +0800
committerzhongjun <zhong.jun@zte.com.cn>2017-05-19 08:52:41 +0800
commit97fbb386bc7e8e7f0229b5e71f1814918b0b7835 (patch)
tree4e0f73913ef2cf8dda6d163382354573955396df
parentbfacd100e576a50be19447f7c1b6cea2ac55ebd0 (diff)
Code optimization for list traversal
1.replace the list to generator to simply the code. Change-Id: Ia67cf265f3ca004eab5abb8b1d742f53b7d554ad Signed-off-by: zhongjun <zhong.jun@zte.com.cn>
-rw-r--r--deploy/tempest.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/deploy/tempest.py b/deploy/tempest.py
index bd1bc04f..3510528a 100644
--- a/deploy/tempest.py
+++ b/deploy/tempest.py
@@ -151,8 +151,7 @@ def discover_host(hosts_name):
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:
+ for net in network_info_gernerator:
network_id = net.id
network_name = net.name
if network_map.get(network_name):
@@ -162,9 +161,8 @@ def update_network(cluster_id, network_map):
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:
+ for host in hosts_list_generator:
host_info = client.hosts.get(host.id)
hosts_info.append(host_info)
return hosts_info
@@ -172,8 +170,7 @@ def get_hosts():
def get_cluster():
cluster_list_generator = client.clusters.list()
- cluster_list = [cluster for cluster in cluster_list_generator]
- for cluster in cluster_list:
+ for cluster in cluster_list_generator:
cluster_info = client.clusters.get(cluster.id)
return cluster_info
@@ -229,8 +226,7 @@ def add_host_role(cluster_id, host_id, host_exp_name, host_real_name, vip):
def enable_cinder_backend(cluster_id, service_name, disk_name, protocol_type):
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
+ lb_role_id = [role.id for role in role_list_generator if
role.name == "CONTROLLER_LB"][0]
service_disk_meta = {'service': service_name,
'disk_location': 'local',