Extend network info in generated inventory

When building the inventory from neutron resources,
set network related role_vars in the generated
ansible inventory. The following vars are set:

  {{ network_name }}_cidr
  {{ network_name }}_dns_nameservers
  {{ network_name }}_gateway_ip
  {{ network_name }}_host_routes
  {{ network_name }}_mtu
  {{ network_name }}_vlan_id
  ctlplane_subnet_cidr
  networks_all
  networks_lower
  role_networks

Partial-Implements: blueprint network-data-v2-ports
Change-Id: I3072895b44845736050255fb0b6d5f0bdd5c5f48
This commit is contained in:
Harald Jensås 2021-01-21 14:42:34 +01:00
parent 9f44451112
commit 26f33ce897
4 changed files with 426 additions and 119 deletions

View File

@ -202,6 +202,8 @@ TRIPLEO_NETWORK_CONFIG_RESOURCE = 'NetworkConfig'
HOST_NETWORK = 'ctlplane' HOST_NETWORK = 'ctlplane'
DEFAULT_VLAN_ID = "1"
# The key is different in RoleConfig than in RoleData, so we need both so they # The key is different in RoleConfig than in RoleData, so we need both so they
# are correctly found. # are correctly found.
EXTERNAL_TASKS = ['external_deploy_tasks', 'external_deploy_steps_tasks'] EXTERNAL_TASKS = ['external_deploy_tasks', 'external_deploy_steps_tasks']

View File

@ -16,6 +16,7 @@
# under the License. # under the License.
from collections import OrderedDict from collections import OrderedDict
import copy
import logging import logging
import os import os
import sys import sys
@ -26,6 +27,7 @@ from heatclient.exc import HTTPNotFound
import openstack import openstack
from tripleo_common import exception from tripleo_common import exception
import tripleo_common.constants as constants
HOST_NETWORK = 'ctlplane' HOST_NETWORK = 'ctlplane'
DEFAULT_DOMAIN = 'localdomain.' DEFAULT_DOMAIN = 'localdomain.'
@ -93,10 +95,11 @@ class NeutronData(object):
A data object with for inventory generation enriched neutron data. A data object with for inventory generation enriched neutron data.
""" """
def __init__(self, networks, subnets, ports): def __init__(self, networks, subnets, ports, host_network=None):
self.networks = networks self.networks = networks
self.subnets = subnets self.subnets = subnets
self.ports = ports self.ports = ports
self.host_network = host_network or HOST_NETWORK
self.networks_by_id = self._networks_by_id() self.networks_by_id = self._networks_by_id()
self.subnets_by_id = self._subnets_by_id() self.subnets_by_id = self._subnets_by_id()
self.ports_by_role_and_host = self._ports_by_role_and_host() self.ports_by_role_and_host = self._ports_by_role_and_host()
@ -110,6 +113,15 @@ class NeutronData(object):
key, value = tag.rsplit('=') key, value = tag.rsplit('=')
except ValueError: except ValueError:
continue continue
# Make booleans type bool
value = True if value in {'True', 'true', True} else value
value = False if value in {'False', 'false', False} else value
# Convert network index value to integer
if key == 'tripleo_net_idx':
value = int(value)
tag_dict.update({key: value}) tag_dict.update({key: value})
return tag_dict return tag_dict
@ -124,10 +136,33 @@ class NeutronData(object):
# neutron is useless as a inventory source in this case. # neutron is useless as a inventory source in this case.
if not mandatory_tags.issubset(tags): if not mandatory_tags.issubset(tags):
raise exception.MissingMandatoryNeutronResourceTag() raise exception.MissingMandatoryNeutronResourceTag()
hostname = tags['tripleo_hostname'] hostname = tags['tripleo_hostname']
dns_domain = self.networks_by_id[port.network_id]['dns_domain'] network_id = port.network_id
net_name = self.networks_by_id[port.network_id]['name'] network = self.networks_by_id[network_id]
ip_address = port.fixed_ips[0].get('ip_address') fixed_ips = port.fixed_ips[0]
subnet_id = fixed_ips.get('subnet_id')
subnet = self.subnets_by_id[subnet_id]
# "TripleO" cidr is the number of bits in the network mask
cidr = subnet['cidr'].split('/')[1]
dns_domain = network['dns_domain']
dns_nameservers = subnet['dns_nameservers']
mtu = network['mtu']
net_name = network['name']
ip_address = fixed_ips.get('ip_address')
gateway_ip = subnet['gateway_ip']
# Need deepcopy here so that adding default entry does not end
# up in the subnet object and leak to other nodes with a different
# default route network.
host_routes = copy.deepcopy(subnet['host_routes'])
# If this is the default route network, add a default route using
# gateway_ip to the host_routes unless it's already present
if tags.get('tripleo_default_route'):
host_routes.append({'default': True, 'nexthop': gateway_ip})
vlan_id = subnet['tags'].get('tripleo_vlan_id',
constants.DEFAULT_VLAN_ID)
role_name = tags['tripleo_role'] role_name = tags['tripleo_role']
role = ports_by_role_and_host.setdefault(role_name, {}) role = ports_by_role_and_host.setdefault(role_name, {})
@ -136,24 +171,44 @@ class NeutronData(object):
{'name': port.name, {'name': port.name,
'hostname': hostname, 'hostname': hostname,
'dns_domain': dns_domain, 'dns_domain': dns_domain,
'network_id': port.network_id, 'network_id': network_id,
'network_name': net_name, 'network_name': net_name,
'fixed_ips': port.fixed_ips, 'fixed_ips': port.fixed_ips,
'subnet_id': subnet_id,
'ip_address': ip_address, 'ip_address': ip_address,
'tags': self._tags_to_dict(port.tags)} 'mtu': mtu,
'cidr': cidr,
'gateway_ip': gateway_ip,
'dns_nameservers': dns_nameservers,
'host_routes': host_routes,
'vlan_id': vlan_id,
'tags': tags}
) )
return ports_by_role_and_host return ports_by_role_and_host
def _networks_by_id(self): def _networks_by_id(self):
mandatory_tags = {'tripleo_network_name'}
networks_by_id = {} networks_by_id = {}
for net in self.networks: for net in self.networks:
tags = self._tags_to_dict(net.tags)
# In case of missing required tags, raise an error.
# neutron is useless as a inventory source in this case.
if (net.name != self.host_network and
not mandatory_tags.issubset(tags)):
raise exception.MissingMandatoryNeutronResourceTag()
if net.name != self.host_network:
name_upper = tags['tripleo_network_name']
else:
name_upper = self.host_network
networks_by_id.update( networks_by_id.update(
{net.id: {'name': net.name, {net.id: {'name': net.name,
'name_upper': name_upper,
'subnet_ids': net.subnet_ids, 'subnet_ids': net.subnet_ids,
'mtu': net.mtu, 'mtu': net.mtu,
'dns_domain': net.dns_domain, 'dns_domain': net.dns_domain,
'tags': self._tags_to_dict(net.tags)} 'tags': tags}
} }
) )
@ -428,7 +483,8 @@ class TripleoInventory(object):
return data return data
def _add_host_from_neutron_data(self, host, ports, role_networks): def _add_host_from_neutron_data(self, host, ports, role_networks,
role_vars):
for port in ports: for port in ports:
net_name = port['network_name'] net_name = port['network_name']
@ -436,6 +492,14 @@ class TripleoInventory(object):
if net_name not in role_networks: if net_name not in role_networks:
role_networks.append(net_name) role_networks.append(net_name)
# Append to role_vars if not already present
net_config_keys = {'cidr', 'dns_nameservers', 'gateway_ip',
'host_routes', 'vlan_id'}
for key in net_config_keys:
var = '{}_{}'.format(net_name, key)
if var not in role_vars:
role_vars.setdefault(var, port[key])
# Add variable for hostname on network # Add variable for hostname on network
host.setdefault('{}_hostname'.format(net_name), '.'.join( host.setdefault('{}_hostname'.format(net_name), '.'.join(
[port['hostname'], port['dns_domain']])) [port['hostname'], port['dns_domain']]))
@ -459,9 +523,21 @@ class TripleoInventory(object):
def _inventory_from_neutron_data(self, ret, children, dynamic): def _inventory_from_neutron_data(self, ret, children, dynamic):
if not self.neutron_data: if not self.neutron_data:
return return
ports_by_role_and_host = self.neutron_data.ports_by_role_and_host
networks_by_id = self.neutron_data.networks_by_id
for role_name, ports_by_host in ( netname_by_idx = {
self.neutron_data.ports_by_role_and_host.items()): net['tags'].get('tripleo_net_idx'):
net['tags'].get('tripleo_network_name')
for _, net in networks_by_id.items()
if net['name'] != self.host_network}
networks_all = [netname_by_idx[idx] for idx in sorted(netname_by_idx)]
networks_lower = {net['name_upper']: net['name']
for _, net in networks_by_id.items()}
networks_upper = {net['name']: net['name_upper']
for _, net in networks_by_id.items()}
for role_name, ports_by_host in ports_by_role_and_host.items():
role = ret.setdefault(role_name, {}) role = ret.setdefault(role_name, {})
hosts = role.setdefault('hosts', {}) hosts = role.setdefault('hosts', {})
role_vars = role.setdefault('vars', {}) role_vars = role.setdefault('vars', {})
@ -471,9 +547,24 @@ class TripleoInventory(object):
role_networks = role_vars.setdefault('tripleo_role_networks', []) role_networks = role_vars.setdefault('tripleo_role_networks', [])
for hostname, ports in ports_by_host.items(): for hostname, ports in ports_by_host.items():
host = hosts.setdefault(hostname, {}) host = hosts.setdefault(hostname, {})
self._add_host_from_neutron_data(host, ports, role_networks) self._add_host_from_neutron_data(host, ports, role_networks,
role_vars)
# The nic config templates use ctlplane_subnet_cidr, not
# ctlplane_cidr. Handle the special case.
role_vars.setdefault(self.host_network + '_subnet_cidr',
role_vars[self.host_network + '_cidr'])
role_vars.setdefault('tripleo_role_networks',
sorted(role_networks))
role_vars.setdefault(
'role_networks',
[networks_upper[net] for net in role_networks])
role_vars.setdefault('networks_all', networks_all)
role_vars.setdefault('networks_lower', networks_lower)
for _, net in networks_by_id.items():
role_vars.setdefault(net['name'] + '_mtu', net['mtu'])
role_vars['tripleo_role_networks'] = sorted(role_networks)
children.add(role_name) children.add(role_name)
self.hostvars.update(hosts) self.hostvars.update(hosts)

View File

@ -28,9 +28,11 @@ internal_api_network = stubs.FakeNeutronNetwork(
name='internal_api', name='internal_api',
id='internal_api_network_id', id='internal_api_network_id',
mtu=1500, mtu=1500,
dns_domain='inernalapi.example.com', dns_domain='internalapi.example.com',
subnet_ids=['internal_api_subnet_id'], subnet_ids=['internal_api_subnet_id'],
tags=['tripleo_vip=true', 'tripleo_network_name=InternalApi'], tags=['tripleo_net_idx=0',
'tripleo_vip=true',
'tripleo_network_name=InternalApi'],
) )
ctlplane_subnet = stubs.FakeNeutronSubnet( ctlplane_subnet = stubs.FakeNeutronSubnet(
@ -69,7 +71,8 @@ controller0_ports = [
tags=['tripleo_hostname=c-0', tags=['tripleo_hostname=c-0',
'tripleo_network_name=ctlplane', 'tripleo_network_name=ctlplane',
'tripleo_role=Controller', 'tripleo_role=Controller',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=True'],
), ),
stubs.FakeNeutronPort(name='c-0-internal_api', stubs.FakeNeutronPort(name='c-0-internal_api',
id='controller_0_internal_api_id', id='controller_0_internal_api_id',
@ -79,7 +82,8 @@ controller0_ports = [
tags=['tripleo_hostname=c-0', tags=['tripleo_hostname=c-0',
'tripleo_network_name=InternalApi', 'tripleo_network_name=InternalApi',
'tripleo_role=Controller', 'tripleo_role=Controller',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=False'],
), ),
] ]
@ -92,7 +96,8 @@ controller1_ports = [
tags=['tripleo_hostname=c-1', tags=['tripleo_hostname=c-1',
'tripleo_network_name=ctlplane', 'tripleo_network_name=ctlplane',
'tripleo_role=Controller', 'tripleo_role=Controller',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=True'],
), ),
stubs.FakeNeutronPort(name='c-1-internal_api', stubs.FakeNeutronPort(name='c-1-internal_api',
id='controller_1_internal_api_id', id='controller_1_internal_api_id',
@ -102,7 +107,8 @@ controller1_ports = [
tags=['tripleo_hostname=c-1', tags=['tripleo_hostname=c-1',
'tripleo_network_name=InternalApi', 'tripleo_network_name=InternalApi',
'tripleo_role=Controller', 'tripleo_role=Controller',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=False'],
), ),
] ]
@ -115,7 +121,8 @@ controller2_ports = [
tags=['tripleo_hostname=c-2', tags=['tripleo_hostname=c-2',
'tripleo_network_name=ctlplane', 'tripleo_network_name=ctlplane',
'tripleo_role=Controller', 'tripleo_role=Controller',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=True'],
), ),
stubs.FakeNeutronPort(name='c-2-internal_api', stubs.FakeNeutronPort(name='c-2-internal_api',
id='controller_2_internal_api_id', id='controller_2_internal_api_id',
@ -125,7 +132,8 @@ controller2_ports = [
tags=['tripleo_hostname=c-2', tags=['tripleo_hostname=c-2',
'tripleo_network_name=InternalApi', 'tripleo_network_name=InternalApi',
'tripleo_role=Controller', 'tripleo_role=Controller',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=False'],
), ),
] ]
@ -138,7 +146,8 @@ compute_0_ports = [
tags=['tripleo_hostname=cp-0', tags=['tripleo_hostname=cp-0',
'tripleo_network_name=ctlplane', 'tripleo_network_name=ctlplane',
'tripleo_role=Compute', 'tripleo_role=Compute',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=True'],
), ),
stubs.FakeNeutronPort(name='cp-0-internal_api', stubs.FakeNeutronPort(name='cp-0-internal_api',
id='compute_0_internal_api_id', id='compute_0_internal_api_id',
@ -148,7 +157,8 @@ compute_0_ports = [
tags=['tripleo_hostname=cp-0', tags=['tripleo_hostname=cp-0',
'tripleo_network_name=InternalApi', 'tripleo_network_name=InternalApi',
'tripleo_role=Compute', 'tripleo_role=Compute',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=False'],
), ),
] ]
@ -162,6 +172,7 @@ custom_0_ports = [
tags=['tripleo_hostname=cs-0', tags=['tripleo_hostname=cs-0',
'tripleo_network_name=ctlplane', 'tripleo_network_name=ctlplane',
'tripleo_role=CustomRole', 'tripleo_role=CustomRole',
'tripleo_stack=overcloud'], 'tripleo_stack=overcloud',
'tripleo_default_route=True'],
), ),
] ]

View File

@ -750,7 +750,8 @@ class TestInventory(base.TestCase):
role_networks = role_vars.setdefault('tripleo_role_networks', []) role_networks = role_vars.setdefault('tripleo_role_networks', [])
hosts = role.setdefault('hosts', {}) hosts = role.setdefault('hosts', {})
ports = neutron_data.ports_by_role_and_host['Compute']['cp-0'] ports = neutron_data.ports_by_role_and_host['Compute']['cp-0']
self.inventory._add_host_from_neutron_data(hosts, ports, role_networks) self.inventory._add_host_from_neutron_data(hosts, ports, role_networks,
role_vars)
self.assertEqual(OrderedDict([ self.assertEqual(OrderedDict([
('Compute', ('Compute',
{'hosts': { {'hosts': {
@ -758,9 +759,21 @@ class TestInventory(base.TestCase):
'canonical_hostname': 'cp-0.example.com.', 'canonical_hostname': 'cp-0.example.com.',
'ctlplane_hostname': 'cp-0.ctlplane.example.com.', 'ctlplane_hostname': 'cp-0.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.20', 'ctlplane_ip': '192.0.2.20',
'internal_api_hostname': 'cp-0.inernalapi.example.com', 'internal_api_hostname': 'cp-0.internalapi.example.com',
'internal_api_ip': '198.51.100.150'}, 'internal_api_ip': '198.51.100.150'},
'vars': { 'vars': {
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253',
'192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_vlan_id': '1',
'internal_api_cidr': '25',
'internal_api_dns_nameservers': [],
'internal_api_gateway_ip': '198.51.100.129',
'internal_api_host_routes': [],
'internal_api_vlan_id': '20',
'tripleo_role_networks': ['ctlplane', 'internal_api'] 'tripleo_role_networks': ['ctlplane', 'internal_api']
}}) }})
]), ret) ]), ret)
@ -786,16 +799,35 @@ class TestInventory(base.TestCase):
'canonical_hostname': 'c-0.example.com.', 'canonical_hostname': 'c-0.example.com.',
'ctlplane_hostname': 'c-0.ctlplane.example.com.', 'ctlplane_hostname': 'c-0.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.10', 'ctlplane_ip': '192.0.2.10',
'internal_api_hostname': 'c-0.inernalapi.example.com', 'internal_api_hostname': 'c-0.internalapi.example.com',
'internal_api_ip': '198.51.100.140'}, 'internal_api_ip': '198.51.100.140'},
'c-1': { 'c-1': {
'ansible_host': '192.0.2.11', 'ansible_host': '192.0.2.11',
'canonical_hostname': 'c-1.example.com.', 'canonical_hostname': 'c-1.example.com.',
'ctlplane_hostname': 'c-1.ctlplane.example.com.', 'ctlplane_hostname': 'c-1.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.11', 'ctlplane_ip': '192.0.2.11',
'internal_api_hostname': 'c-1.inernalapi.example.com', 'internal_api_hostname': 'c-1.internalapi.example.com',
'internal_api_ip': '198.51.100.141'}}, 'internal_api_ip': '198.51.100.141'}},
'vars': {'ansible_ssh_user': 'heat-admin', 'vars': {'ansible_ssh_user': 'heat-admin',
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253',
'192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_mtu': 1500,
'ctlplane_subnet_cidr': '24',
'ctlplane_vlan_id': '1',
'internal_api_cidr': '25',
'internal_api_dns_nameservers': [],
'internal_api_gateway_ip': '198.51.100.129',
'internal_api_host_routes': [],
'internal_api_mtu': 1500,
'internal_api_vlan_id': '20',
'networks_all': ['InternalApi'],
'networks_lower': {'InternalApi': 'internal_api',
'ctlplane': 'ctlplane'},
'role_networks': ['ctlplane', 'InternalApi'],
'serial': 1, 'serial': 1,
'tripleo_role_name': 'Controller', 'tripleo_role_name': 'Controller',
'tripleo_role_networks': ['ctlplane', 'internal_api'] 'tripleo_role_networks': ['ctlplane', 'internal_api']
@ -807,9 +839,28 @@ class TestInventory(base.TestCase):
'canonical_hostname': 'cp-0.example.com.', 'canonical_hostname': 'cp-0.example.com.',
'ctlplane_hostname': 'cp-0.ctlplane.example.com.', 'ctlplane_hostname': 'cp-0.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.20', 'ctlplane_ip': '192.0.2.20',
'internal_api_hostname': 'cp-0.inernalapi.example.com', 'internal_api_hostname': 'cp-0.internalapi.example.com',
'internal_api_ip': '198.51.100.150'}}, 'internal_api_ip': '198.51.100.150'}},
'vars': {'ansible_ssh_user': 'heat-admin', 'vars': {'ansible_ssh_user': 'heat-admin',
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253',
'192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_mtu': 1500,
'ctlplane_subnet_cidr': '24',
'ctlplane_vlan_id': '1',
'internal_api_cidr': '25',
'internal_api_dns_nameservers': [],
'internal_api_gateway_ip': '198.51.100.129',
'internal_api_host_routes': [],
'internal_api_mtu': 1500,
'internal_api_vlan_id': '20',
'networks_all': ['InternalApi'],
'networks_lower': {'InternalApi': 'internal_api',
'ctlplane': 'ctlplane'},
'role_networks': ['ctlplane', 'InternalApi'],
'serial': 1, 'serial': 1,
'tripleo_role_name': 'Compute', 'tripleo_role_name': 'Compute',
'tripleo_role_networks': ['ctlplane', 'internal_api'] 'tripleo_role_networks': ['ctlplane', 'internal_api']
@ -834,6 +885,25 @@ class TestInventory(base.TestCase):
('Controller', { ('Controller', {
'hosts': ['c-0', 'c-1'], 'hosts': ['c-0', 'c-1'],
'vars': {'ansible_ssh_user': 'heat-admin', 'vars': {'ansible_ssh_user': 'heat-admin',
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253',
'192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_mtu': 1500,
'ctlplane_vlan_id': '1',
'internal_api_cidr': '25',
'internal_api_dns_nameservers': [],
'internal_api_gateway_ip': '198.51.100.129',
'internal_api_host_routes': [],
'internal_api_mtu': 1500,
'ctlplane_subnet_cidr': '24',
'internal_api_vlan_id': '20',
'networks_all': ['InternalApi'],
'networks_lower': {'InternalApi': 'internal_api',
'ctlplane': 'ctlplane'},
'role_networks': ['ctlplane', 'InternalApi'],
'serial': 1, 'serial': 1,
'tripleo_role_name': 'Controller', 'tripleo_role_name': 'Controller',
'tripleo_role_networks': ['ctlplane', 'internal_api'] 'tripleo_role_networks': ['ctlplane', 'internal_api']
@ -841,6 +911,25 @@ class TestInventory(base.TestCase):
('Compute', { ('Compute', {
'hosts': ['cp-0'], 'hosts': ['cp-0'],
'vars': {'ansible_ssh_user': 'heat-admin', 'vars': {'ansible_ssh_user': 'heat-admin',
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253',
'192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_mtu': 1500,
'ctlplane_vlan_id': '1',
'internal_api_cidr': '25',
'internal_api_dns_nameservers': [],
'internal_api_gateway_ip': '198.51.100.129',
'internal_api_host_routes': [],
'internal_api_mtu': 1500,
'ctlplane_subnet_cidr': '24',
'internal_api_vlan_id': '20',
'networks_all': ['InternalApi'],
'networks_lower': {'InternalApi': 'internal_api',
'ctlplane': 'ctlplane'},
'role_networks': ['ctlplane', 'InternalApi'],
'serial': 1, 'serial': 1,
'tripleo_role_name': 'Compute', 'tripleo_role_name': 'Compute',
'tripleo_role_networks': ['ctlplane', 'internal_api'] 'tripleo_role_networks': ['ctlplane', 'internal_api']
@ -936,7 +1025,7 @@ class TestInventory(base.TestCase):
'ctlplane_hostname': 'c-0.ctlplane.example.com.', 'ctlplane_hostname': 'c-0.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.10', 'ctlplane_ip': '192.0.2.10',
'deploy_server_id': 'a', 'deploy_server_id': 'a',
'internal_api_hostname': 'c-0.inernalapi.example.com', 'internal_api_hostname': 'c-0.internalapi.example.com',
'internal_api_ip': '198.51.100.140'}, 'internal_api_ip': '198.51.100.140'},
'c-1': { 'c-1': {
'ansible_host': '192.0.2.11', 'ansible_host': '192.0.2.11',
@ -944,7 +1033,7 @@ class TestInventory(base.TestCase):
'ctlplane_hostname': 'c-1.ctlplane.example.com.', 'ctlplane_hostname': 'c-1.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.11', 'ctlplane_ip': '192.0.2.11',
'deploy_server_id': 'b', 'deploy_server_id': 'b',
'internal_api_hostname': 'c-1.inernalapi.example.com', 'internal_api_hostname': 'c-1.internalapi.example.com',
'internal_api_ip': '198.51.100.141'}, 'internal_api_ip': '198.51.100.141'},
'c-2': { 'c-2': {
'ansible_host': '192.0.2.12', 'ansible_host': '192.0.2.12',
@ -952,11 +1041,29 @@ class TestInventory(base.TestCase):
'ctlplane_hostname': 'c-2.ctlplane.example.com.', 'ctlplane_hostname': 'c-2.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.12', 'ctlplane_ip': '192.0.2.12',
'deploy_server_id': 'c', 'deploy_server_id': 'c',
'internal_api_hostname': 'c-2.inernalapi.example.com', 'internal_api_hostname': 'c-2.internalapi.example.com',
'internal_api_ip': '198.51.100.142'}}, 'internal_api_ip': '198.51.100.142'}},
'vars': { 'vars': {
'ansible_ssh_user': 'heat-admin', 'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a', 'bootstrap_server_id': 'a',
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253', '192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_mtu': 1500,
'ctlplane_subnet_cidr': '24',
'ctlplane_vlan_id': '1',
'internal_api_cidr': '25',
'internal_api_dns_nameservers': [],
'internal_api_gateway_ip': '198.51.100.129',
'internal_api_host_routes': [],
'internal_api_mtu': 1500,
'internal_api_vlan_id': '20',
'networks_all': ['InternalApi'],
'networks_lower': {'InternalApi': 'internal_api',
'ctlplane': 'ctlplane'},
'role_networks': ['ctlplane', 'InternalApi'],
'serial': 1, 'serial': 1,
'tripleo_role_name': 'Controller', 'tripleo_role_name': 'Controller',
'tripleo_role_networks': ['ctlplane', 'internal_api']} 'tripleo_role_networks': ['ctlplane', 'internal_api']}
@ -969,10 +1076,30 @@ class TestInventory(base.TestCase):
'ctlplane_hostname': 'cp-0.ctlplane.example.com.', 'ctlplane_hostname': 'cp-0.ctlplane.example.com.',
'ctlplane_ip': '192.0.2.20', 'ctlplane_ip': '192.0.2.20',
'deploy_server_id': 'd', 'deploy_server_id': 'd',
'internal_api_hostname': 'cp-0.inernalapi.example.com', 'internal_api_hostname':
'cp-0.internalapi.example.com',
'internal_api_ip': '198.51.100.150'}}, 'internal_api_ip': '198.51.100.150'}},
'vars': {'ansible_ssh_user': 'heat-admin', 'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a', 'bootstrap_server_id': 'a',
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253',
'192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_mtu': 1500,
'ctlplane_subnet_cidr': '24',
'ctlplane_vlan_id': '1',
'internal_api_cidr': '25',
'internal_api_dns_nameservers': [],
'internal_api_gateway_ip': '198.51.100.129',
'internal_api_host_routes': [],
'internal_api_mtu': 1500,
'internal_api_vlan_id': '20',
'networks_all': ['InternalApi'],
'networks_lower': {'InternalApi': 'internal_api',
'ctlplane': 'ctlplane'},
'role_networks': ['ctlplane', 'InternalApi'],
'serial': 1, 'serial': 1,
'tripleo_role_name': 'Compute', 'tripleo_role_name': 'Compute',
'tripleo_role_networks': ['ctlplane', 'internal_api']} 'tripleo_role_networks': ['ctlplane', 'internal_api']}
@ -987,6 +1114,20 @@ class TestInventory(base.TestCase):
'deploy_server_id': 'e'}}, 'deploy_server_id': 'e'}},
'vars': {'ansible_ssh_user': 'heat-admin', 'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a', 'bootstrap_server_id': 'a',
'ctlplane_cidr': '24',
'ctlplane_dns_nameservers': ['192.0.2.253',
'192.0.2.254'],
'ctlplane_gateway_ip': '192.0.2.1',
'ctlplane_host_routes': [{'default': True,
'nexthop': '192.0.2.1'}],
'ctlplane_mtu': 1500,
'ctlplane_subnet_cidr': '24',
'ctlplane_vlan_id': '1',
'internal_api_mtu': 1500,
'networks_all': ['InternalApi'],
'networks_lower': {'InternalApi': 'internal_api',
'ctlplane': 'ctlplane'},
'role_networks': ['ctlplane'],
'serial': 1, 'serial': 1,
'tripleo_role_name': 'CustomRole', 'tripleo_role_name': 'CustomRole',
'tripleo_role_networks': ['ctlplane']} 'tripleo_role_networks': ['ctlplane']}
@ -1042,15 +1183,18 @@ class TestNeutronData(base.TestCase):
'dns_domain': 'ctlplane.example.com.', 'dns_domain': 'ctlplane.example.com.',
'mtu': 1500, 'mtu': 1500,
'name': 'ctlplane', 'name': 'ctlplane',
'name_upper': 'ctlplane',
'subnet_ids': ['ctlplane_subnet_id'], 'subnet_ids': ['ctlplane_subnet_id'],
'tags': {}}, 'tags': {}},
'internal_api_network_id': { 'internal_api_network_id': {
'dns_domain': 'inernalapi.example.com', 'dns_domain': 'internalapi.example.com',
'mtu': 1500, 'mtu': 1500,
'name': 'internal_api', 'name': 'internal_api',
'name_upper': 'InternalApi',
'subnet_ids': ['internal_api_subnet_id'], 'subnet_ids': ['internal_api_subnet_id'],
'tags': {'tripleo_network_name': 'InternalApi', 'tags': {'tripleo_net_idx': 0,
'tripleo_vip': 'true'} 'tripleo_network_name': 'InternalApi',
'tripleo_vip': True}
}, },
}, self.neutron_data.networks_by_id) }, self.neutron_data.networks_by_id)
@ -1079,87 +1223,146 @@ class TestNeutronData(base.TestCase):
}, self.neutron_data.subnets_by_id) }, self.neutron_data.subnets_by_id)
def test__ports_by_role_and_host(self): def test__ports_by_role_and_host(self):
self.assertEqual({ self.assertTrue(
'Controller': { 'Controller' in self.neutron_data.ports_by_role_and_host)
'c-0': [ self.assertTrue(
{'dns_domain': 'ctlplane.example.com.', 'Compute' in self.neutron_data.ports_by_role_and_host)
'fixed_ips': [{'ip_address': '192.0.2.10', ctr_role = self.neutron_data.ports_by_role_and_host['Controller']
'subnet_id': 'ctlplane_subnet_id'}], cmp_role = self.neutron_data.ports_by_role_and_host['Compute']
'hostname': 'c-0', self.assertTrue('c-0' in ctr_role)
'ip_address': '192.0.2.10', self.assertTrue('c-1' in ctr_role)
'name': 'c-0-ctlplane', ctr_0 = ctr_role['c-0']
'network_id': 'ctlplane_network_id', ctr_1 = ctr_role['c-1']
'network_name': 'ctlplane', self.assertTrue('cp-0' in cmp_role)
'tags': {'tripleo_hostname': 'c-0', cmp_0 = cmp_role['cp-0']
'tripleo_network_name': 'ctlplane', self.assertEqual(
'tripleo_role': 'Controller', [{'cidr': '24',
'tripleo_stack': 'overcloud'}}, 'dns_domain': 'ctlplane.example.com.',
{'dns_domain': 'inernalapi.example.com', 'dns_nameservers': ['192.0.2.253', '192.0.2.254'],
'fixed_ips': [{'ip_address': '198.51.100.140', 'fixed_ips': [{'ip_address': '192.0.2.10',
'subnet_id': 'internal_api_subnet_id'}], 'subnet_id': 'ctlplane_subnet_id'}],
'hostname': 'c-0', 'gateway_ip': '192.0.2.1',
'ip_address': '198.51.100.140', 'host_routes': [{'default': True, 'nexthop': '192.0.2.1'}],
'name': 'c-0-internal_api', 'hostname': 'c-0',
'network_id': 'internal_api_network_id', 'ip_address': '192.0.2.10',
'network_name': 'internal_api', 'mtu': 1500,
'tags': {'tripleo_hostname': 'c-0', 'name': 'c-0-ctlplane',
'tripleo_network_name': 'InternalApi', 'network_id': 'ctlplane_network_id',
'tripleo_role': 'Controller', 'network_name': 'ctlplane',
'tripleo_stack': 'overcloud'}}, 'subnet_id': 'ctlplane_subnet_id',
], 'tags': {'tripleo_default_route': True,
'c-1': [ 'tripleo_hostname': 'c-0',
{'dns_domain': 'ctlplane.example.com.', 'tripleo_network_name': 'ctlplane',
'fixed_ips': [{'ip_address': '192.0.2.11', 'tripleo_role': 'Controller',
'subnet_id': 'ctlplane_subnet_id'}], 'tripleo_stack': 'overcloud'},
'hostname': 'c-1', 'vlan_id': '1'},
'ip_address': '192.0.2.11', {'cidr': '25',
'name': 'c-1-ctlplane', 'dns_domain': 'internalapi.example.com',
'network_id': 'ctlplane_network_id', 'dns_nameservers': [],
'network_name': 'ctlplane', 'fixed_ips': [{'ip_address': '198.51.100.140',
'tags': {'tripleo_hostname': 'c-1', 'subnet_id': 'internal_api_subnet_id'}],
'tripleo_network_name': 'ctlplane', 'gateway_ip': '198.51.100.129',
'tripleo_role': 'Controller', 'host_routes': [],
'tripleo_stack': 'overcloud'}}, 'hostname': 'c-0',
{'dns_domain': 'inernalapi.example.com', 'ip_address': '198.51.100.140',
'fixed_ips': [{'ip_address': '198.51.100.141', 'mtu': 1500,
'subnet_id': 'internal_api_subnet_id'}], 'name': 'c-0-internal_api',
'hostname': 'c-1', 'network_id': 'internal_api_network_id',
'ip_address': '198.51.100.141', 'network_name': 'internal_api',
'name': 'c-1-internal_api', 'subnet_id': 'internal_api_subnet_id',
'network_id': 'internal_api_network_id', 'tags': {'tripleo_default_route': False,
'network_name': 'internal_api', 'tripleo_hostname': 'c-0',
'tags': {'tripleo_hostname': 'c-1', 'tripleo_network_name': 'InternalApi',
'tripleo_network_name': 'InternalApi', 'tripleo_role': 'Controller',
'tripleo_role': 'Controller', 'tripleo_stack': 'overcloud'},
'tripleo_stack': 'overcloud'}}, 'vlan_id': '20'}],
] ctr_0
}, )
'Compute': { self.assertEqual(
'cp-0': [ [{'cidr': '24',
{'dns_domain': 'ctlplane.example.com.', 'dns_domain': 'ctlplane.example.com.',
'fixed_ips': [{'ip_address': '192.0.2.20', 'dns_nameservers': ['192.0.2.253', '192.0.2.254'],
'subnet_id': 'ctlplane_subnet_id'}], 'fixed_ips': [{'ip_address': '192.0.2.11',
'hostname': 'cp-0', 'subnet_id': 'ctlplane_subnet_id'}],
'ip_address': '192.0.2.20', 'gateway_ip': '192.0.2.1',
'name': 'cp-0-ctlplane', 'host_routes': [{'default': True, 'nexthop': '192.0.2.1'}],
'network_id': 'ctlplane_network_id', 'hostname': 'c-1',
'network_name': 'ctlplane', 'ip_address': '192.0.2.11',
'tags': {'tripleo_hostname': 'cp-0', 'mtu': 1500,
'tripleo_network_name': 'ctlplane', 'name': 'c-1-ctlplane',
'tripleo_role': 'Compute', 'network_id': 'ctlplane_network_id',
'tripleo_stack': 'overcloud'}}, 'network_name': 'ctlplane',
{'dns_domain': 'inernalapi.example.com', 'subnet_id': 'ctlplane_subnet_id',
'fixed_ips': [{'ip_address': '198.51.100.150', 'tags': {'tripleo_default_route': True,
'subnet_id': 'internal_api_subnet_id'}], 'tripleo_hostname': 'c-1',
'hostname': 'cp-0', 'tripleo_network_name': 'ctlplane',
'ip_address': '198.51.100.150', 'tripleo_role': 'Controller',
'name': 'cp-0-internal_api', 'tripleo_stack': 'overcloud'},
'network_id': 'internal_api_network_id', 'vlan_id': '1'},
'network_name': 'internal_api', {'cidr': '25',
'tags': {'tripleo_hostname': 'cp-0', 'dns_domain': 'internalapi.example.com',
'tripleo_network_name': 'InternalApi', 'dns_nameservers': [],
'tripleo_role': 'Compute', 'fixed_ips': [{'ip_address': '198.51.100.141',
'tripleo_stack': 'overcloud'}}, 'subnet_id': 'internal_api_subnet_id'}],
] 'gateway_ip': '198.51.100.129',
}, 'host_routes': [],
}, self.neutron_data.ports_by_role_and_host) 'hostname': 'c-1',
'ip_address': '198.51.100.141',
'mtu': 1500,
'name': 'c-1-internal_api',
'network_id': 'internal_api_network_id',
'network_name': 'internal_api',
'subnet_id': 'internal_api_subnet_id',
'tags': {'tripleo_default_route': False,
'tripleo_hostname': 'c-1',
'tripleo_network_name': 'InternalApi',
'tripleo_role': 'Controller',
'tripleo_stack': 'overcloud'},
'vlan_id': '20'}],
ctr_1
)
self.assertEqual(
[{'cidr': '24',
'dns_domain': 'ctlplane.example.com.',
'dns_nameservers': ['192.0.2.253', '192.0.2.254'],
'fixed_ips': [{'ip_address': '192.0.2.20',
'subnet_id': 'ctlplane_subnet_id'}],
'gateway_ip': '192.0.2.1',
'host_routes': [{'default': True, 'nexthop': '192.0.2.1'}],
'hostname': 'cp-0',
'ip_address': '192.0.2.20',
'mtu': 1500,
'name': 'cp-0-ctlplane',
'network_id': 'ctlplane_network_id',
'network_name': 'ctlplane',
'subnet_id': 'ctlplane_subnet_id',
'tags': {'tripleo_default_route': True,
'tripleo_hostname': 'cp-0',
'tripleo_network_name': 'ctlplane',
'tripleo_role': 'Compute',
'tripleo_stack': 'overcloud'},
'vlan_id': '1'},
{'cidr': '25',
'dns_domain': 'internalapi.example.com',
'dns_nameservers': [],
'fixed_ips': [{'ip_address': '198.51.100.150',
'subnet_id': 'internal_api_subnet_id'}],
'gateway_ip': '198.51.100.129',
'host_routes': [],
'hostname': 'cp-0',
'ip_address': '198.51.100.150',
'mtu': 1500,
'name': 'cp-0-internal_api',
'network_id': 'internal_api_network_id',
'network_name': 'internal_api',
'subnet_id': 'internal_api_subnet_id',
'tags': {'tripleo_default_route': False,
'tripleo_hostname': 'cp-0',
'tripleo_network_name': 'InternalApi',
'tripleo_role': 'Compute',
'tripleo_stack': 'overcloud'},
'vlan_id': '20'}],
cmp_0
)
self.assertEqual({'Controller': ctr_role, 'Compute': cmp_role},
self.neutron_data.ports_by_role_and_host)