Add looking for env variables to overwrite hardcoded values
Also add timeout for checking installation status To be suitable for jenkins test. The PRESET_VALUES can all be set to compass IP. Also set mac address to the pxe vm in jenkins slaves. Currently we only test os-dashboard role to save time. Change-Id: I6194f62f21887af173c5c318577c4eb86de0eabf
This commit is contained in:
parent
c798020b99
commit
d5c2d5eedb
@ -2,16 +2,17 @@
|
|||||||
"""Example code to deploy a cluster by compass client api."""
|
"""Example code to deploy a cluster by compass client api."""
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
from compass.apiclient.restful import Client
|
from compass.apiclient.restful import Client
|
||||||
|
|
||||||
|
|
||||||
COMPASS_SERVER_URL = 'http://10.145.88.210:8080'
|
COMPASS_SERVER_URL = 'http://127.0.0.1'
|
||||||
SWITCH_IP = '10.145.88.1'
|
SWITCH_IP = '10.145.81.220'
|
||||||
SWITCH_SNMP_VERSION = 'v2c'
|
SWITCH_SNMP_VERSION = 'v2c'
|
||||||
SWITCH_SNMP_COMMUNITY = 'public'
|
SWITCH_SNMP_COMMUNITY = 'public'
|
||||||
MACHINES_TO_ADD = ['00:0c:29:c3:40:7c', '00:0c:29:e9:f6:a6']
|
MACHINES_TO_ADD = ['00:11:20:30:40:01']
|
||||||
CLUSTER_NAME = 'cluster'
|
CLUSTER_NAME = 'cluster2'
|
||||||
HOST_NAME_PREFIX = 'host'
|
HOST_NAME_PREFIX = 'host'
|
||||||
SERVER_USERNAME = 'root'
|
SERVER_USERNAME = 'root'
|
||||||
SERVER_PASSWORD = 'root'
|
SERVER_PASSWORD = 'root'
|
||||||
@ -19,40 +20,53 @@ SERVICE_USERNAME = 'service'
|
|||||||
SERVICE_PASSWORD = 'service'
|
SERVICE_PASSWORD = 'service'
|
||||||
CONSOLE_USERNAME = 'console'
|
CONSOLE_USERNAME = 'console'
|
||||||
CONSOLE_PASSWORD = 'console'
|
CONSOLE_PASSWORD = 'console'
|
||||||
NAMESERVERS = '10.145.88.210'
|
#NAMESERVERS = '192.168.10.6'
|
||||||
SEARCH_PATH = 'ods.com'
|
SEARCH_PATH = 'ods.com'
|
||||||
GATEWAY = '10.145.88.1'
|
#GATEWAY = '192.168.10.6'
|
||||||
PROXY = 'http://10.145.88.210:3128'
|
#PROXY = 'http://192.168.10.6:3128'
|
||||||
NTP_SERVER = '10.145.88.210'
|
#NTP_SERVER = '192.168.10.6'
|
||||||
MANAGEMENT_IP_START = '10.145.88.130'
|
MANAGEMENT_IP_START = '192.168.10.130'
|
||||||
MANAGEMENT_IP_END = '10.145.88.255'
|
MANAGEMENT_IP_END = '192.168.10.254'
|
||||||
MANAGEMENT_GATEWAY = '10.145.88.1'
|
MANAGEMENT_IP_GATEWAY = '192.168.10.1'
|
||||||
MANAGEMENT_NETMASK = '255.255.255.0'
|
MANAGEMENT_NETMASK = '255.255.255.0'
|
||||||
MANAGEMENT_NIC = 'eth0'
|
MANAGEMENT_NIC = 'eth0'
|
||||||
MANAGEMENT_PROMISC = 0
|
MANAGEMENT_PROMISC = 0
|
||||||
TENANT_IP_START = '192.168.100.100'
|
TENANT_IP_START = '192.168.10.100'
|
||||||
TENANT_IP_END = '192.168.100.255'
|
TENANT_IP_END = '192.168.10.255'
|
||||||
TENANT_GATEWAY = '192.168.100.1'
|
TENANT_IP_GATEWAY = '192.168.10.1'
|
||||||
TENANT_NETMASK = '255.255.255.0'
|
TENANT_NETMASK = '255.255.255.0'
|
||||||
TENANT_NIC = 'eth0'
|
TENANT_NIC = 'eth0'
|
||||||
TENANT_PROMISC = 0
|
TENANT_PROMISC = 0
|
||||||
PUBLIC_IP_START = '12.234.32.100'
|
PUBLIC_IP_START = '12.234.32.100'
|
||||||
PUBLIC_IP_END = '12.234.32.255'
|
PUBLIC_IP_END = '12.234.32.255'
|
||||||
PUBLIC_GATEWAY = '12.234.32.1'
|
PUBLIC_IP_GATEWAY = '12.234.32.1'
|
||||||
PUBLIC_NETMASK = '255.255.255.0'
|
PUBLIC_NETMASK = '255.255.255.0'
|
||||||
PUBLIC_NIC = 'eth1'
|
PUBLIC_NIC = 'eth1'
|
||||||
PUBLIC_PROMISC = 1
|
PUBLIC_PROMISC = 1
|
||||||
STORAGE_IP_START = '172.16.100.100'
|
STORAGE_IP_START = '172.16.100.100'
|
||||||
STORAGE_IP_END = '172.16.100.255'
|
STORAGE_IP_END = '172.16.100.255'
|
||||||
STORAGE_GATEWAY = '172.16.100.1'
|
|
||||||
STORAGE_NETMASK = '255.255.255.0'
|
STORAGE_NETMASK = '255.255.255.0'
|
||||||
|
STORAGE_IP_GATEWAY = '172.16.100.1'
|
||||||
STORAGE_NIC = 'eth0'
|
STORAGE_NIC = 'eth0'
|
||||||
STORAGE_PROMISC = 0
|
STORAGE_PROMISC = 0
|
||||||
HOME_PERCENTAGE = 40
|
HOME_PERCENTAGE = 40
|
||||||
TMP_PERCENTAGE = 10
|
TMP_PERCENTAGE = 10
|
||||||
VAR_PERCENTAGE = 15
|
VAR_PERCENTAGE = 15
|
||||||
ROLES_LIST = [[], ['os-single-controller']]
|
ROLES_LIST = [['os-dashboard']]
|
||||||
|
|
||||||
|
PRESET_VALUES = {
|
||||||
|
'NAMESERVERS':'192.168.10.1',
|
||||||
|
'NTP_SERVER':'192.168.10.1',
|
||||||
|
'GATEWAY':'192.168.10.1',
|
||||||
|
'PROXY':'http://192.168.10.1:3128',
|
||||||
|
}
|
||||||
|
print os.environ.get("NAMESERVERS")
|
||||||
|
for v in PRESET_VALUES:
|
||||||
|
if os.environ.get(v):
|
||||||
|
PRESET_VALUES[v]=os.environ.get(v)
|
||||||
|
print ( v + PRESET_VALUES[v] + " is set by env variables")
|
||||||
|
else:
|
||||||
|
print (PRESET_VALUES[v])
|
||||||
|
|
||||||
# get apiclient object.
|
# get apiclient object.
|
||||||
client = Client(COMPASS_SERVER_URL)
|
client = Client(COMPASS_SERVER_URL)
|
||||||
@ -157,34 +171,34 @@ print 'set security config to cluster %s status: %s, resp: %s' % (
|
|||||||
# set cluster networking
|
# set cluster networking
|
||||||
status, resp = client.set_networking(
|
status, resp = client.set_networking(
|
||||||
cluster_id,
|
cluster_id,
|
||||||
nameservers=NAMESERVERS,
|
nameservers=PRESET_VALUES["NAMESERVERS"],
|
||||||
search_path=SEARCH_PATH,
|
search_path=SEARCH_PATH,
|
||||||
gateway=GATEWAY,
|
gateway=PRESET_VALUES["GATEWAY"],
|
||||||
proxy=PROXY,
|
proxy=PRESET_VALUES["PROXY"],
|
||||||
ntp_server=NTP_SERVER,
|
ntp_server=PRESET_VALUES["NTP_SERVER"],
|
||||||
management_ip_start=MANAGEMENT_IP_START,
|
management_ip_start=MANAGEMENT_IP_START,
|
||||||
management_ip_end=MANAGEMENT_IP_END,
|
management_ip_end=MANAGEMENT_IP_END,
|
||||||
management_gateway=MANAGEMENT_GATEWAY,
|
|
||||||
management_netmask=MANAGEMENT_NETMASK,
|
management_netmask=MANAGEMENT_NETMASK,
|
||||||
management_nic=MANAGEMENT_NIC,
|
management_nic=MANAGEMENT_NIC,
|
||||||
|
management_gateway=MANAGEMENT_IP_GATEWAY,
|
||||||
management_promisc=MANAGEMENT_PROMISC,
|
management_promisc=MANAGEMENT_PROMISC,
|
||||||
tenant_ip_start=TENANT_IP_START,
|
tenant_ip_start=TENANT_IP_START,
|
||||||
tenant_ip_end=TENANT_IP_END,
|
tenant_ip_end=TENANT_IP_END,
|
||||||
tenant_gateway=TENANT_GATEWAY,
|
|
||||||
tenant_netmask=TENANT_NETMASK,
|
tenant_netmask=TENANT_NETMASK,
|
||||||
tenant_nic=TENANT_NIC,
|
tenant_nic=TENANT_NIC,
|
||||||
|
tenant_gateway=TENANT_IP_GATEWAY,
|
||||||
tenant_promisc=TENANT_PROMISC,
|
tenant_promisc=TENANT_PROMISC,
|
||||||
public_ip_start=PUBLIC_IP_START,
|
public_ip_start=PUBLIC_IP_START,
|
||||||
public_ip_end=PUBLIC_IP_END,
|
public_ip_end=PUBLIC_IP_END,
|
||||||
public_gateway=PUBLIC_GATEWAY,
|
|
||||||
public_netmask=PUBLIC_NETMASK,
|
public_netmask=PUBLIC_NETMASK,
|
||||||
public_nic=PUBLIC_NIC,
|
public_nic=PUBLIC_NIC,
|
||||||
|
public_gateway=PUBLIC_IP_GATEWAY,
|
||||||
public_promisc=PUBLIC_PROMISC,
|
public_promisc=PUBLIC_PROMISC,
|
||||||
storage_ip_start=STORAGE_IP_START,
|
storage_ip_start=STORAGE_IP_START,
|
||||||
storage_ip_end=STORAGE_IP_END,
|
storage_ip_end=STORAGE_IP_END,
|
||||||
storage_gateway=STORAGE_GATEWAY,
|
|
||||||
storage_netmask=STORAGE_NETMASK,
|
storage_netmask=STORAGE_NETMASK,
|
||||||
storage_nic=STORAGE_NIC,
|
storage_nic=STORAGE_NIC,
|
||||||
|
storage_gateway=STORAGE_IP_GATEWAY,
|
||||||
storage_promisc=STORAGE_PROMISC)
|
storage_promisc=STORAGE_PROMISC)
|
||||||
print 'set networking config to cluster %s status: %s, resp: %s' % (
|
print 'set networking config to cluster %s status: %s, resp: %s' % (
|
||||||
cluster_id, status, resp)
|
cluster_id, status, resp)
|
||||||
@ -218,13 +232,14 @@ print 'deploy cluster %s status: %s, resp: %s' % (cluster_id, status, resp)
|
|||||||
|
|
||||||
|
|
||||||
# get intalling progress.
|
# get intalling progress.
|
||||||
|
timeout = time.time() + 60*90
|
||||||
while True:
|
while True:
|
||||||
status, resp = client.get_cluster_installing_progress(cluster_id)
|
status, resp = client.get_cluster_installing_progress(cluster_id)
|
||||||
print 'get cluster %s installing progress status: %s, resp: %s' % (
|
print 'get cluster %s installing progress status: %s, resp: %s' % (
|
||||||
cluster_id, status, resp)
|
cluster_id, status, resp)
|
||||||
progress = resp['progress']
|
progress = resp['progress']
|
||||||
if (progress['state'] not in ['UNINITIALIZED', 'INSTALLING'] or
|
if (progress['state'] not in ['UNINITIALIZED', 'INSTALLING'] or
|
||||||
progress['percentage'] >= 1.0):
|
progress['percentage'] >= 1.0) or time.time() > timeout:
|
||||||
break
|
break
|
||||||
|
|
||||||
for host_id in host_ids:
|
for host_id in host_ids:
|
||||||
@ -232,7 +247,7 @@ while True:
|
|||||||
print 'get host %s installing progress status: %s, resp: %s' % (
|
print 'get host %s installing progress status: %s, resp: %s' % (
|
||||||
host_id, status, resp)
|
host_id, status, resp)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
status, resp = client.get_dashboard_links(cluster_id)
|
status, resp = client.get_dashboard_links(cluster_id)
|
||||||
|
@ -223,7 +223,7 @@ if [[ "$?" != "0" ]]; then
|
|||||||
else
|
else
|
||||||
echo "$IMAGE_SOURCE is downloaded"
|
echo "$IMAGE_SOURCE is downloaded"
|
||||||
fi
|
fi
|
||||||
|
ls /var/lib/cobbler/iso
|
||||||
sudo mkdir -p /mnt/${IMAGE_NAME}-${IMAGE_ARCH}
|
sudo mkdir -p /mnt/${IMAGE_NAME}-${IMAGE_ARCH}
|
||||||
if [ $(mount | grep -c "/mnt/${IMAGE_NAME}-${IMAGE_ARCH} ") -eq 0 ]; then
|
if [ $(mount | grep -c "/mnt/${IMAGE_NAME}-${IMAGE_ARCH} ") -eq 0 ]; then
|
||||||
sudo mount -o loop /var/lib/cobbler/iso/${IMAGE_NAME}-${IMAGE_ARCH}.iso /mnt/${IMAGE_NAME}-${IMAGE_ARCH}
|
sudo mount -o loop /var/lib/cobbler/iso/${IMAGE_NAME}-${IMAGE_ARCH}.iso /mnt/${IMAGE_NAME}-${IMAGE_ARCH}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user