add option to ignore poll switches by env variable USE_POLL_SWITCHES
Change-Id: I9c7f4fef481314a8616ddb89b0da7fec0a6797c9
This commit is contained in:
parent
8f4b0a4e7a
commit
8065a459ff
100
bin/client.py
100
bin/client.py
@ -37,6 +37,12 @@ flags.add('switch_credential',
|
||||
flags.add('switch_max_retries', type='int',
|
||||
help='max retries of poll switch',
|
||||
default=-1)
|
||||
flags.add('switch_retry_interval', type='int',
|
||||
help='interval to repoll switch',
|
||||
default=10)
|
||||
flags.add_bool('poll_switches',
|
||||
help='if the client polls switches',
|
||||
default=True)
|
||||
flags.add('machines',
|
||||
help='comma separated mac addresses of machines',
|
||||
default='')
|
||||
@ -161,51 +167,53 @@ def _poll_switches(client):
|
||||
else:
|
||||
logging.info('switch %s is already added', switch_ip)
|
||||
|
||||
for switch_ip, switch in all_switches.items():
|
||||
switch_id = switch['id']
|
||||
# if the switch is not in under_monitoring, wait for the
|
||||
# poll switch task update the switch information and change
|
||||
# the switch state.
|
||||
remain_retries = flags.OPTIONS.switch_max_retries
|
||||
while True:
|
||||
if remain_retries != 0:
|
||||
logging.info(
|
||||
'waiting for the switch %s into under_monitoring',
|
||||
switch_ip)
|
||||
status, resp = client.get_switch(switch_id)
|
||||
logging.info('get switch %s status: %s, resp: %s',
|
||||
switch_ip, status, resp)
|
||||
if status >= 400:
|
||||
msg = 'failed to get switch %s' % switch_ip
|
||||
raise Exception(msg)
|
||||
|
||||
switch = resp['switch']
|
||||
all_switches[switch_ip] = switch
|
||||
if switch['state'] == 'notsupported':
|
||||
msg = 'switch %s is not supported', switch_ip
|
||||
raise Exception(msg)
|
||||
elif switch['state'] in ['initialized', 'repolling']:
|
||||
logging.info('switch %s is not updated', switch_ip)
|
||||
else:
|
||||
if switch['state'] == 'under_monitoring':
|
||||
logging.info('switch %s is ready', switch_ip)
|
||||
try:
|
||||
return _get_machines(client)
|
||||
except Exception as error:
|
||||
logging.exception(error)
|
||||
|
||||
status, resp = client.update_switch(
|
||||
switch_id, switch_ip, **switch_credential)
|
||||
if status >= 400:
|
||||
msg = 'failed to update switch %s' % switch_ip
|
||||
raise Exception(msg)
|
||||
|
||||
time.sleep(10)
|
||||
remain_retries -= 1
|
||||
else:
|
||||
msg = 'max retries reached for switch %s' % switch_ip
|
||||
remain_retries = flags.OPTIONS.switch_max_retries
|
||||
while True:
|
||||
time.sleep(flags.OPTIONS.switch_retry_interval)
|
||||
for switch_ip, switch in all_switches.items():
|
||||
switch_id = switch['id']
|
||||
# if the switch is not in under_monitoring, wait for the
|
||||
# poll switch task update the switch information and change
|
||||
# the switch state.
|
||||
logging.info(
|
||||
'waiting for the switch %s into under_monitoring',
|
||||
switch_ip)
|
||||
status, resp = client.get_switch(switch_id)
|
||||
logging.info('get switch %s status: %s, resp: %s',
|
||||
switch_ip, status, resp)
|
||||
if status >= 400:
|
||||
msg = 'failed to get switch %s' % switch_ip
|
||||
raise Exception(msg)
|
||||
|
||||
switch = resp['switch']
|
||||
all_switches[switch_ip] = switch
|
||||
|
||||
if switch['state'] == 'notsupported':
|
||||
msg = 'switch %s is not supported', switch_ip
|
||||
raise Exception(msg)
|
||||
elif switch['state'] in ['initialized', 'repolling']:
|
||||
logging.info('switch %s is not updated', switch_ip)
|
||||
elif switch['state'] == 'under_monitoring':
|
||||
logging.info('switch %s is ready', switch_ip)
|
||||
|
||||
try:
|
||||
return _get_machines(client)
|
||||
except Exception:
|
||||
logging.error('failed to get all machines')
|
||||
|
||||
if remain_retries > 0:
|
||||
for switch_ip, switch in all_switches.items():
|
||||
status, resp = client.update_switch(
|
||||
switch_id, switch_ip, **switch_credential)
|
||||
if status >= 400:
|
||||
msg = 'failed to update switch %s' % switch_ip
|
||||
raise Exception(msg)
|
||||
|
||||
remain_retries -= 1
|
||||
else:
|
||||
msg = 'max retries reached'
|
||||
raise Exception(msg)
|
||||
|
||||
|
||||
def _get_adapter(client):
|
||||
"""get adapter."""
|
||||
@ -566,7 +574,11 @@ def main():
|
||||
flags.init()
|
||||
logsetting.init()
|
||||
client = _get_client()
|
||||
machines = _poll_switches(client)
|
||||
if flags.OPTIONS.poll_switches:
|
||||
machines = _poll_switches(client)
|
||||
else:
|
||||
machines = _get_machines(client)
|
||||
|
||||
adapter_id = _get_adapter(client)
|
||||
cluster_hosts = _add_cluster(client, adapter_id, machines)
|
||||
_set_cluster_security(client, cluster_hosts)
|
||||
|
@ -36,9 +36,8 @@ fi
|
||||
# configure chef client and knife
|
||||
rpm -q chef
|
||||
if [[ "$?" != "0" ]]; then
|
||||
download http://www.opscode.com/chef/install.sh chef_install.sh
|
||||
sudo chmod 755 /tmp/chef_install.sh
|
||||
sudo /tmp/chef_install.sh
|
||||
download http://opscode-omnibus-packages.s3.amazonaws.com/el/${IMAGE_VERSION_MAJOR}/${IMAGE_ARCH}/chef-11.8.0-1.el6.${IMAGE_ARCH}.rpm
|
||||
rpm -ivh /tmp/chef-11.8.0-1.el6.${IMAGE_ARCH}.rpm
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "chef install failed"
|
||||
exit 1
|
||||
|
@ -7,6 +7,7 @@ export SWITCH_IPS=${SWITCH_IPS:-'10.145.81.219'}
|
||||
export SWITCH_VERSION=${SWITCH_VERSION:-'2c'}
|
||||
export SWITCH_COMMUNITY=${SWITCH_COMMUNITY:-'public'}
|
||||
export SWITCH_CREDENTIAL=${SWITCH_CREDENTIAL:-"version=${SWITCH_VERSION},community=${SWITCH_COMMUNITY}"}
|
||||
export USE_POLL_SWITCHES=${USE_POLL_SWITCHES:-true}
|
||||
|
||||
export HOST_ROLES=${HOST_ROLES:-''}
|
||||
|
||||
|
@ -143,7 +143,28 @@ if [[ "$?" != "0" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
${CLIENT_SCRIPT} --logfile= --loglevel=info --logdir= --networking="${NETWORKING}" --partitions="${PARTITION}" --credentials="${SECURITY}" --host_roles="${host_roles_list}" --dashboard_role="${DASHBOARD_ROLE}" --switch_ips="${SWITCH_IPS}" --machines="${machines}" --switch_credential="${SWITCH_CREDENTIAL}" --deployment_timeout="${DEPLOYMENT_TIMEOUT}"
|
||||
if [[ "$USE_POLL_SWITCHES" == "0" || "$USE_POLL_SWITCHES" == "false" ]]; then
|
||||
POLL_SWITCHES_FLAG="nopoll_switches"
|
||||
TMP_SWITCH_MACHINE_FILE=$(mktemp)
|
||||
> ${TMP_SWITCH_MACHINE_FILE}
|
||||
for switch_ip in ${SWITCH_IPS//,/ }; do
|
||||
echo "switch,${switch_ip},huawei,${SWITCH_VERSION},${SWITCH_COMMUNITY},under_monitoring" >> ${TMP_SWITCH_MACHINE_FILE}
|
||||
switch_port=1
|
||||
for mac in ${machines//,/ }; do
|
||||
echo "machine,${switch_ip},${switch_port},1,${mac}" >> ${TMP_SWITCH_MACHINE_FILE}
|
||||
let switch_port+=1
|
||||
done
|
||||
break
|
||||
done
|
||||
echo "generated switch machine file: $TMP_SWITCH_MACHINE_FILE"
|
||||
cat $TMP_SWITCH_MACHINE_FILE
|
||||
echo "======================================================="
|
||||
/opt/compass/bin/manage_db.py set_switch_machines --switch_machines_file ${TMP_SWITCH_MACHINE_FILE}
|
||||
else
|
||||
POLL_SWITCHES_FLAG="poll_switches"
|
||||
fi
|
||||
|
||||
${CLIENT_SCRIPT} --logfile= --loglevel=info --logdir= --networking="${NETWORKING}" --partitions="${PARTITION}" --credentials="${SECURITY}" --host_roles="${host_roles_list}" --dashboard_role="${DASHBOARD_ROLE}" --switch_ips="${SWITCH_IPS}" --machines="${machines}" --switch_credential="${SWITCH_CREDENTIAL}" --deployment_timeout="${DEPLOYMENT_TIMEOUT}" --${POLL_SWITCHES_FLAG}
|
||||
rc=$?
|
||||
# Tear down machines after the test
|
||||
if [[ $rc != 0 ]]; then
|
||||
|
Loading…
Reference in New Issue
Block a user