add option to ignore poll switches by env variable USE_POLL_SWITCHES
Change-Id: I9c7f4fef481314a8616ddb89b0da7fec0a6797c9
This commit is contained in:
parent
8f4b0a4e7a
commit
8065a459ff
@ -37,6 +37,12 @@ flags.add('switch_credential',
|
|||||||
flags.add('switch_max_retries', type='int',
|
flags.add('switch_max_retries', type='int',
|
||||||
help='max retries of poll switch',
|
help='max retries of poll switch',
|
||||||
default=-1)
|
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',
|
flags.add('machines',
|
||||||
help='comma separated mac addresses of machines',
|
help='comma separated mac addresses of machines',
|
||||||
default='')
|
default='')
|
||||||
@ -161,14 +167,14 @@ def _poll_switches(client):
|
|||||||
else:
|
else:
|
||||||
logging.info('switch %s is already added', switch_ip)
|
logging.info('switch %s is already added', 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():
|
for switch_ip, switch in all_switches.items():
|
||||||
switch_id = switch['id']
|
switch_id = switch['id']
|
||||||
# if the switch is not in under_monitoring, wait for the
|
# if the switch is not in under_monitoring, wait for the
|
||||||
# poll switch task update the switch information and change
|
# poll switch task update the switch information and change
|
||||||
# the switch state.
|
# the switch state.
|
||||||
remain_retries = flags.OPTIONS.switch_max_retries
|
|
||||||
while True:
|
|
||||||
if remain_retries != 0:
|
|
||||||
logging.info(
|
logging.info(
|
||||||
'waiting for the switch %s into under_monitoring',
|
'waiting for the switch %s into under_monitoring',
|
||||||
switch_ip)
|
switch_ip)
|
||||||
@ -181,29 +187,31 @@ def _poll_switches(client):
|
|||||||
|
|
||||||
switch = resp['switch']
|
switch = resp['switch']
|
||||||
all_switches[switch_ip] = switch
|
all_switches[switch_ip] = switch
|
||||||
|
|
||||||
if switch['state'] == 'notsupported':
|
if switch['state'] == 'notsupported':
|
||||||
msg = 'switch %s is not supported', switch_ip
|
msg = 'switch %s is not supported', switch_ip
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
elif switch['state'] in ['initialized', 'repolling']:
|
elif switch['state'] in ['initialized', 'repolling']:
|
||||||
logging.info('switch %s is not updated', switch_ip)
|
logging.info('switch %s is not updated', switch_ip)
|
||||||
else:
|
elif switch['state'] == 'under_monitoring':
|
||||||
if switch['state'] == 'under_monitoring':
|
|
||||||
logging.info('switch %s is ready', switch_ip)
|
logging.info('switch %s is ready', switch_ip)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return _get_machines(client)
|
return _get_machines(client)
|
||||||
except Exception as error:
|
except Exception:
|
||||||
logging.exception(error)
|
logging.error('failed to get all machines')
|
||||||
|
|
||||||
|
if remain_retries > 0:
|
||||||
|
for switch_ip, switch in all_switches.items():
|
||||||
status, resp = client.update_switch(
|
status, resp = client.update_switch(
|
||||||
switch_id, switch_ip, **switch_credential)
|
switch_id, switch_ip, **switch_credential)
|
||||||
if status >= 400:
|
if status >= 400:
|
||||||
msg = 'failed to update switch %s' % switch_ip
|
msg = 'failed to update switch %s' % switch_ip
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
time.sleep(10)
|
|
||||||
remain_retries -= 1
|
remain_retries -= 1
|
||||||
else:
|
else:
|
||||||
msg = 'max retries reached for switch %s' % switch_ip
|
msg = 'max retries reached'
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
|
|
||||||
@ -566,7 +574,11 @@ def main():
|
|||||||
flags.init()
|
flags.init()
|
||||||
logsetting.init()
|
logsetting.init()
|
||||||
client = _get_client()
|
client = _get_client()
|
||||||
|
if flags.OPTIONS.poll_switches:
|
||||||
machines = _poll_switches(client)
|
machines = _poll_switches(client)
|
||||||
|
else:
|
||||||
|
machines = _get_machines(client)
|
||||||
|
|
||||||
adapter_id = _get_adapter(client)
|
adapter_id = _get_adapter(client)
|
||||||
cluster_hosts = _add_cluster(client, adapter_id, machines)
|
cluster_hosts = _add_cluster(client, adapter_id, machines)
|
||||||
_set_cluster_security(client, cluster_hosts)
|
_set_cluster_security(client, cluster_hosts)
|
||||||
|
@ -36,9 +36,8 @@ fi
|
|||||||
# configure chef client and knife
|
# configure chef client and knife
|
||||||
rpm -q chef
|
rpm -q chef
|
||||||
if [[ "$?" != "0" ]]; then
|
if [[ "$?" != "0" ]]; then
|
||||||
download http://www.opscode.com/chef/install.sh 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
|
||||||
sudo chmod 755 /tmp/chef_install.sh
|
rpm -ivh /tmp/chef-11.8.0-1.el6.${IMAGE_ARCH}.rpm
|
||||||
sudo /tmp/chef_install.sh
|
|
||||||
if [[ "$?" != "0" ]]; then
|
if [[ "$?" != "0" ]]; then
|
||||||
echo "chef install failed"
|
echo "chef install failed"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -7,6 +7,7 @@ export SWITCH_IPS=${SWITCH_IPS:-'10.145.81.219'}
|
|||||||
export SWITCH_VERSION=${SWITCH_VERSION:-'2c'}
|
export SWITCH_VERSION=${SWITCH_VERSION:-'2c'}
|
||||||
export SWITCH_COMMUNITY=${SWITCH_COMMUNITY:-'public'}
|
export SWITCH_COMMUNITY=${SWITCH_COMMUNITY:-'public'}
|
||||||
export SWITCH_CREDENTIAL=${SWITCH_CREDENTIAL:-"version=${SWITCH_VERSION},community=${SWITCH_COMMUNITY}"}
|
export SWITCH_CREDENTIAL=${SWITCH_CREDENTIAL:-"version=${SWITCH_VERSION},community=${SWITCH_COMMUNITY}"}
|
||||||
|
export USE_POLL_SWITCHES=${USE_POLL_SWITCHES:-true}
|
||||||
|
|
||||||
export HOST_ROLES=${HOST_ROLES:-''}
|
export HOST_ROLES=${HOST_ROLES:-''}
|
||||||
|
|
||||||
|
@ -143,7 +143,28 @@ if [[ "$?" != "0" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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=$?
|
rc=$?
|
||||||
# Tear down machines after the test
|
# Tear down machines after the test
|
||||||
if [[ $rc != 0 ]]; then
|
if [[ $rc != 0 ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user