aboutsummaryrefslogtreecommitdiffstats
path: root/func/env_setup.py
diff options
context:
space:
mode:
authorwu.zhihui <wu.zhihui1@zte.com.cn>2016-08-05 15:05:30 +0800
committerwu.zhihui <wu.zhihui1@zte.com.cn>2016-08-18 23:26:02 +0800
commitddac3b6c756d531aaf7a7a39465424c9ee858734 (patch)
tree9b2c171cb157ff8a1e3a9ef45a8ab4328b5603b4 /func/env_setup.py
parentdd0a00b503f1d6e8d43d30646ffc2642bb04fe93 (diff)
Fetch all compute ips via installer Fuel.
1. Fetch all compute ips via installer Fuel. 2. check the machines' ip. if unassigned, assign one of compute's ip to it. if assigned by test case yaml, check the validation. JIRA: QTIP-98 Change-Id: I5517916c594a14055087134d20c1fe4320b6d707 Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn>
Diffstat (limited to 'func/env_setup.py')
-rw-r--r--func/env_setup.py59
1 files changed, 57 insertions, 2 deletions
diff --git a/func/env_setup.py b/func/env_setup.py
index 9c0dadb3..fdddf49a 100644
--- a/func/env_setup.py
+++ b/func/env_setup.py
@@ -1,5 +1,5 @@
##############################################################################
-# Copyright (c) 2015 Dell Inc and others.
+# Copyright (c) 2016 Dell Inc, ZTE and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -14,9 +14,16 @@ import yaml
import time
import paramiko
import socket
+from os.path import expanduser
+import random
+import logging
+
+LOG = logging.getLogger(__name__)
+LOG.setLevel(logging.DEBUG)
class Env_setup:
+
roles_ip_list = [] # ROLE and its corresponding IP address list
ip_pw_list = [] # IP and password, this will be used to ssh
roles_dict = defaultdict(list)
@@ -110,10 +117,58 @@ class Env_setup:
time.sleep(10)
print ('\n\n %s is UP \n\n ' % ipvar)
- def get_host_machine_info(self, host_tag):
+ @staticmethod
+ def fetch_compute_ips():
+ LOG.info("Fetch compute ips through installer")
+ ips = []
+
+ installer_type = os.environ['INSTALLER_TYPE']
+ installer_ip = os.environ['INSTALLER_IP']
+ if installer_type.down.lower() != "fuel" or "compass":
+ raise RuntimeError("%s is not supported" % installer_type)
+ if installer_ip:
+ raise RuntimeError("undefine environment variable INSTALLER_IP")
+
+ cmd = "bash ./fetch_compute_ip.sh -i %s -a %s" % \
+ (installer_type, installer_ip)
+ os.system(cmd)
+ home = expanduser("~")
+ os.chdir(home)
+ with open("ips.log", "r") as file:
+ data = file.read()
+ if data:
+ ips.extend(data.rstrip('\n').split('\n'))
+ LOG.info("All compute ips: %s" % ips)
+ return ips
+
+ def check_machine_ips(self, host_tag):
+ LOG.info("Check machine ips")
+ ips = self.fetch_compute_ips()
+ ips_num = len(ips)
+ num = len(host_tag)
+ if num > ips_num:
+ err = "host num %s > compute ips num %s" % (num, ips_num)
+ raise RuntimeError(err)
+ for x in range(num):
+ hostlabel = 'machine_' + str(x + 1)
+ if host_tag[hostlabel]['ip']:
+ if host_tag[hostlabel]['ip'] in ips:
+ info = "%s's ip %s is defined by test case yaml file" % \
+ (hostlabel, host_tag[hostlabel]['ip'])
+ LOG.info(info)
+ else:
+ err = "%s is not in %s" % (host_tag[hostlabel]['ip'], ips)
+ raise RuntimeError(err)
+ else:
+ host_tag[hostlabel]['ip'] = random.choice(ips)
+ info = "assign ip %s to %s" % (host_tag[hostlabel]['ip'], hostlabel)
+ ips.remove(host_tag[hostlabel]['ip'])
+
+ def get_host_machine_info(self, host_tag):
num = len(host_tag)
offset = len(self.roles_ip_list)
+ self.check_machine_ips(host_tag)
for x in range(num):
hostlabel = 'machine_' + str(x + 1)
self.roles_ip_list.insert(