openstack-armada-app/openstack-helm/files/0008-Check-return-value-of-...

53 lines
2.0 KiB
Diff

From 29a7eea2465284bc5ed5a8f95bc14d6c6c9f0e5e Mon Sep 17 00:00:00 2001
From: Mingyuan Qi <mingyuan.qi@intel.com>
Date: Wed, 11 Dec 2019 08:48:09 +0000
Subject: [PATCH] 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>
---
ironic/templates/bin/_manage-cleaning-network.sh.tpl | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/ironic/templates/bin/_manage-cleaning-network.sh.tpl b/ironic/templates/bin/_manage-cleaning-network.sh.tpl
index 47381a1..2a2af3a 100644
--- a/ironic/templates/bin/_manage-cleaning-network.sh.tpl
+++ b/ironic/templates/bin/_manage-cleaning-network.sh.tpl
@@ -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 \
--
1.8.3.1