Check return value of get subnets before iterate for ironic

With the update of openstack clients:
openstack client >= 4.0.0
neutron client >= 6.14.0
neturon lib >= 1.29.1

The command 'openstack network show ${network} -f value -c subnets'
returns '[]' instead of null string if no subnets found in the
specific network. This commit adds a check logic to avoid subsequent
command returns error by using '[]' as subnet input.

Change-Id: I7e7d5209227b0e34131b7715dbd3faa6066a94b7
Signed-off-by: Mingyuan Qi <mingyuan.qi@intel.com>
This commit is contained in:
Mingyuan Qi 2019-12-11 08:48:09 +00:00 committed by Chris Wedgwood
parent f6fe35d452
commit 1fd5ec6595
1 changed files with 10 additions and 7 deletions

View File

@ -28,13 +28,16 @@ else
IRONIC_NEUTRON_CLEANING_NET_ID=$(openstack network show ${neutron_network_name} -f value -c id)
fi
for SUBNET in $(openstack network show $IRONIC_NEUTRON_CLEANING_NET_ID -f value -c subnets); do
CURRENT_SUBNET=$(openstack subnet show $SUBNET -f value -c name)
if [ "x${CURRENT_SUBNET}" == "x${neutron_subnet_name}" ]; then
openstack subnet show ${neutron_subnet_name}
SUBNET_EXISTS=true
fi
done
SUBNETS=$(openstack network show $IRONIC_NEUTRON_CLEANING_NET_ID -f value -c subnets)
if [ "x${SUBNETS}" != "x[]" ]; then
for SUBNET in ${SUBNETS}; do
CURRENT_SUBNET=$(openstack subnet show $SUBNET -f value -c name)
if [ "x${CURRENT_SUBNET}" == "x${neutron_subnet_name}" ]; then
openstack subnet show ${neutron_subnet_name}
SUBNET_EXISTS=true
fi
done
fi
if [ "x${SUBNET_EXISTS}" != "xtrue" ]; then
openstack subnet create \