summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Jensås <hjensas@redhat.com>2020-09-09 04:55:43 +0200
committerHarald Jensås <hjensas@redhat.com>2021-03-05 01:17:54 +0000
commit546bc2391511fab3f2d8e0474f7aa1b6a0cde708 (patch)
treec7053c53abd76ad1634e067ac88086b188e16c29
parent777e56d2e1b2c7edcabf80b0a316d91a9f3192e7 (diff)
downloadheat-546bc2391511fab3f2d8e0474f7aa1b6a0cde708.tar.gz
Net attr: Sort segments without name attribute first
Useing get_attr, pulling index 0 in the segments list of a network to associate the a subnet with the "first" segment is useful since the "first" segment is created by neutron behind the scenes on network create. A resource reference cannot be used since the "first" segment is'nt a heat resource. The issue is the order of the segments list is'nt reliable. On stack update index 0 may be a different segment, and we end up trying to update the segment_id for a subnet. Changeing the segment association is not allowed, so the stack update fails. While not perfect, sorting the list so that segments where name is None comes first will ensure that index 0 can be used. The template author should ensure segments defined in the heat template all have a names set, so that only the segment creted implicitly by neutron have 'None' name. Closes-Bug: #1894920 Change-Id: I097aba2a97144327bec188e6c71629d0f6c95901 (cherry picked from commit 539b2a4c4993787db0cd71750d3d159e584deccb)
-rw-r--r--heat/engine/resources/openstack/neutron/net.py7
-rw-r--r--releasenotes/notes/os-neutron-net-segments-attribute-semi-predictable-b40a869317d053cc.yaml16
2 files changed, 22 insertions, 1 deletions
diff --git a/heat/engine/resources/openstack/neutron/net.py b/heat/engine/resources/openstack/neutron/net.py
index 62a19e1ff..d0d2ebd8d 100644
--- a/heat/engine/resources/openstack/neutron/net.py
+++ b/heat/engine/resources/openstack/neutron/net.py
@@ -284,8 +284,13 @@ class Net(neutron.NeutronResource):
if self.resource_id is None:
return
if name == self.SEGMENTS:
- return [segment.to_dict() for segment in list(self.client(
+ segments = [segment.to_dict() for segment in list(self.client(
'openstack').network.segments(network_id=self.resource_id))]
+ # Sort segments without name attribute first.
+ # See bug: https://bugs.launchpad.net/tripleo/+bug/1894920
+ segments.sort(key=lambda s: s['name'] is not None)
+ return segments
+
attributes = self._show_resource()
return attributes[name]
diff --git a/releasenotes/notes/os-neutron-net-segments-attribute-semi-predictable-b40a869317d053cc.yaml b/releasenotes/notes/os-neutron-net-segments-attribute-semi-predictable-b40a869317d053cc.yaml
new file mode 100644
index 000000000..f398d8928
--- /dev/null
+++ b/releasenotes/notes/os-neutron-net-segments-attribute-semi-predictable-b40a869317d053cc.yaml
@@ -0,0 +1,16 @@
+---
+fixes:
+ - |
+ The ordering in the list of segments returned by ``OS::Neutron::Net``
+ resources is not predictable. Stack updates changeing attributes
+ of the network can cause the list of segments to shift.
+
+ The ordering is now slightly more predictable, segments with name=``None``
+ are now placed first in the list. This doesn't guarantee the order, but
+ typically only the segment implicitly created by neutron has no name
+ attribute set. The template author should ensure other segments on the
+ network does have a name set, so that the implicit segment will always be
+ index 0. Resolving attributes of the implcitly created segment on the
+ network resource can then predictibly happen using index 0. See `bug:
+ 1894920 <https://bugs.launchpad.net/tripleo/+bug/1894920>`_.
+