Browse Source

Fix network-v2 node port idempotency

Store the 'name_upper' of the networks in the
network name id map, and use this name when
setting the port name in port definitions.

The port name is checked agains existing ports,
and since THT uses the upper case network name
when setting the port name the same (name_upper)
must be used here.

Closes-Bug: #1928711
Related: blueprint network-data-v2-ports
Change-Id: Iac7f351ce9ee965c17b6bc2956d140efe25ffcf4
(cherry picked from commit f6bb059017)
changes/13/792513/1
Harald Jensås 3 months ago
parent
commit
a73d2ec0db
  1. 6
      tripleo_ansible/ansible_plugins/module_utils/network_data_v2.py
  2. 3
      tripleo_ansible/ansible_plugins/modules/tripleo_overcloud_network_ports.py
  3. 8
      tripleo_ansible/tests/modules/test_network_data_v2.py
  4. 47
      tripleo_ansible/tests/modules/test_tripleo_overcloud_network_ports.py

6
tripleo_ansible/ansible_plugins/module_utils/network_data_v2.py

@ -476,9 +476,13 @@ def create_name_id_maps(conn):
net_id_map = {}
cidr_prefix_map = {}
for net in conn.network.networks():
tags = tags_to_dict(net.tags)
subnets = conn.network.subnets(network_id=net.id)
net_id_map[net.id] = net.name
net_name_map[net.name] = dict(id=net.id)
net_name_map[net.name] = dict(
id=net.id,
name_upper=tags.get('tripleo_network_name')
)
subnets_map = net_name_map[net.name]['subnets'] = dict()
for s in subnets:

3
tripleo_ansible/ansible_plugins/modules/tripleo_overcloud_network_ports.py

@ -302,6 +302,7 @@ def generate_port_defs(net_maps, instance, inst_ports):
for net in instance['networks']:
net_name = net['network']
net_name_upper = net_maps['by_name'][net_name]['name_upper']
if net.get('vif', False):
# VIF port's are managed by metalsmith.
@ -326,7 +327,7 @@ def generate_port_defs(net_maps, instance, inst_ports):
fixed_ips = [{'subnet_id': subnet_id}]
port_name = '_'.join([hostname, net_name])
port_name = '_'.join([hostname, net_name_upper])
port_def = dict(name=port_name, dns_name=hostname, network_id=net_id,
fixed_ips=fixed_ips)

8
tripleo_ansible/tests/modules/test_network_data_v2.py

@ -444,12 +444,14 @@ class TestNetworkDataV2(tests_base.TestCase):
network1 = stubs.FakeNeutronNetwork(
id='network1_id',
name='network1',
subnet_ids=['subnet1_id', 'subnet2_id']
subnet_ids=['subnet1_id', 'subnet2_id'],
tags=['tripleo_network_name=Network1']
)
network2 = stubs.FakeNeutronNetwork(
id='network2_id',
name='network2',
subnet_ids=['subnet3_id', 'subnet4_id']
subnet_ids=['subnet3_id', 'subnet4_id'],
tags=['tripleo_network_name=Network2']
)
conn_mock.network.networks.return_value = self.a2g([network1,
network2])
@ -459,6 +461,7 @@ class TestNetworkDataV2(tests_base.TestCase):
expected_by_name_map = {
'network1': {
'id': 'network1_id',
'name_upper': 'Network1',
'subnets': {
'subnet1': 'subnet1_id',
'subnet2': 'subnet2_id'
@ -466,6 +469,7 @@ class TestNetworkDataV2(tests_base.TestCase):
},
'network2': {
'id': 'network2_id',
'name_upper': 'Network2',
'subnets': {
'subnet3': 'subnet3_id',
'subnet4': 'subnet4_id'

47
tripleo_ansible/tests/modules/test_tripleo_overcloud_network_ports.py

@ -38,18 +38,21 @@ FAKE_INSTANCE = {
FAKE_NET_NAME_MAP = {
'ctlplane': {
'id': 'ctlplane_id',
'name_upper': 'ctlplane',
'subnets': {
'ctlplane-subnet': 'ctlplane_subnet_id'
}
},
'foo': {
'id': 'foo_id',
'name_upper': 'Foo',
'subnets': {
'foo_subnet': 'foo_subnet_id',
}
},
'bar': {
'id': 'bar_id',
'name_upper': 'Bar',
'subnets': {
'bar_subnet': 'bar_subnet_id',
}
@ -121,11 +124,11 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
create_port_defs, update_port_defs = plugin.generate_port_defs(
FAKE_MAPS, FAKE_INSTANCE, inst_ports)
self.assertEqual([
{'name': 'instance0_foo',
{'name': 'instance0_Foo',
'dns_name': 'instance0',
'network_id': 'foo_id',
'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]},
{'name': 'instance0_bar',
{'name': 'instance0_Bar',
'dns_name': 'instance0',
'network_id': 'bar_id',
'fixed_ips': [{'subnet_id': 'bar_subnet_id'}]},
@ -134,21 +137,21 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
def test_generate_port_defs_update(self):
port_foo = stubs.FakeNeutronPort(
name='instance0_foo', network_id='foo_id',
name='instance0_Foo', network_id='foo_id',
fixed_ips=[{'subnet_id': 'foo_subnet_id'}])
port_bar = stubs.FakeNeutronPort(
name='instance0_bar', network_id='bar_id',
name='instance0_Bar', network_id='bar_id',
fixed_ips=[{'subnet_id': 'bar_subnet_id'}])
inst_ports = [port_foo, port_bar]
create_port_defs, update_port_defs = plugin.generate_port_defs(
FAKE_MAPS, FAKE_INSTANCE, inst_ports)
self.assertEqual([], create_port_defs)
self.assertEqual([
{'name': 'instance0_foo',
{'name': 'instance0_Foo',
'dns_name': 'instance0',
'network_id': 'foo_id',
'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]},
{'name': 'instance0_bar',
{'name': 'instance0_Bar',
'dns_name': 'instance0',
'network_id': 'bar_id',
'fixed_ips': [{'subnet_id': 'bar_subnet_id'}]}
@ -156,19 +159,19 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
def test_generate_port_defs_create_and_update(self):
port_foo = stubs.FakeNeutronPort(
name='instance0_foo', network_id='foo_id',
name='instance0_Foo', network_id='foo_id',
fixed_ips=[{'subnet_id': 'foo_subnet_id'}])
inst_ports = [port_foo]
create_port_defs, update_port_defs = plugin.generate_port_defs(
FAKE_MAPS, FAKE_INSTANCE, inst_ports)
self.assertEqual([
{'name': 'instance0_bar',
{'name': 'instance0_Bar',
'dns_name': 'instance0',
'network_id': 'bar_id',
'fixed_ips': [{'subnet_id': 'bar_subnet_id'}]},
], create_port_defs)
self.assertEqual([
{'name': 'instance0_foo',
{'name': 'instance0_Foo',
'dns_name': 'instance0',
'network_id': 'foo_id',
'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]},
@ -182,11 +185,11 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
create_port_defs, update_port_defs = plugin.generate_port_defs(
FAKE_MAPS, instance, inst_ports)
self.assertEqual([
{'name': 'instance0_foo',
{'name': 'instance0_Foo',
'dns_name': 'instance0',
'network_id': 'foo_id',
'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]},
{'name': 'instance0_bar',
{'name': 'instance0_Bar',
'dns_name': 'instance0',
'network_id': 'bar_id',
'fixed_ips': [{'subnet_id': 'bar_subnet_id'}]},
@ -220,11 +223,11 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
create_port_defs, update_port_defs = plugin.generate_port_defs(
maps, instance, inst_ports)
self.assertEqual([
{'name': 'instance0_foo',
{'name': 'instance0_Foo',
'dns_name': 'instance0',
'network_id': 'foo_id',
'fixed_ips': [{'ip_address': 'baz_fixed_ip'}]},
{'name': 'instance0_bar',
{'name': 'instance0_Bar',
'dns_name': 'instance0',
'network_id': 'bar_id',
'fixed_ips': [{'ip_address': 'bar_fixed_ip'}]},
@ -353,11 +356,11 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
def test__provision_ports_create(self, mock_conn, mock_pre_provisioned,
mock_create_ports, mock_update_ports):
create_port_defs = [
dict(name='instance0_foo',
dict(name='instance0_Foo',
dns_name='instance0',
network_id='foo_id',
fixed_ips=[{'subnet_id': 'foo_subnet_id'}]),
dict(name='instance0_bar',
dict(name='instance0_Bar',
dns_name='instance0',
network_id='bar_id',
fixed_ips=[{'subnet_id': 'bar_subnet_id'}]),
@ -385,23 +388,23 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
def test__provision_ports_update(self, mock_conn, mock_pre_provisioned,
mock_create_ports, mock_update_ports):
port_foo = stubs.FakeNeutronPort(
name='instance0_foo',
name='instance0_Foo',
dns_name='instance0',
network_id='foo_id',
fixed_ips=[{'subnet_id': 'foo_subnet_id'}],
tags=[])
port_bar = stubs.FakeNeutronPort(
name='instance0_bar',
name='instance0_Bar',
dns_name='instance0',
network_id='bar_id',
fixed_ips=[{'subnet_id': 'bar_subnet_id'}],
tags=[])
update_port_defs = [
dict(name='instance0_foo',
dict(name='instance0_Foo',
dns_name='instance0',
network_id='foo_id',
fixed_ips=[{'subnet_id': 'foo_subnet_id'}]),
dict(name='instance0_bar',
dict(name='instance0_Bar',
dns_name='instance0',
network_id='bar_id',
fixed_ips=[{'subnet_id': 'bar_subnet_id'}]),
@ -432,19 +435,19 @@ class TestTripleoOvercloudNetworkPorts(tests_base.TestCase):
mock_create_ports,
mock_update_ports):
port_foo = stubs.FakeNeutronPort(
name='instance0_foo',
name='instance0_Foo',
dns_name='instance0',
network_id='foo_id',
fixed_ips=[{'subnet_id': 'foo_subnet_id'}],
tags=[])
create_port_defs = [
dict(name='instance0_bar',
dict(name='instance0_Bar',
dns_name='instance0',
network_id='bar_id',
fixed_ips=[{'subnet_id': 'bar_subnet_id'}]),
]
update_port_defs = [
dict(name='instance0_foo',
dict(name='instance0_Foo',
dns_name='instance0',
network_id='foo_id',
fixed_ips=[{'subnet_id': 'foo_subnet_id'}]),

Loading…
Cancel
Save