From 7b9199de9514339fd8fcae662be931d8f0c6d3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Fri, 29 May 2020 20:29:31 +0200 Subject: [PATCH] os-net-config-mappings move out of firsboot Define the parameter NetConfigDataLookup in overcloud.yaml, and write it's content into ansible group_vars. The parameter was previously used in the firstboot heat software config resource firstboot/os-net-config-mappings.yaml. With nova-less none of the firstboot software configuration resource can be used. The depends-on change in tripleo-ansible will parse the lookup data, and write the os-net-config mapping file. Depends-On: https://review.opendev.org/749669 Change-Id: I583bf17c0020bb2a90f885ece0cd5684fc27a980 Blueprint: nova-less-deploy --- firstboot/os-net-config-mappings.yaml | 141 +++++------------- overcloud.j2.yaml | 35 +++++ ...ings-move-to-ansible-940a48711870ac58.yaml | 14 ++ 3 files changed, 84 insertions(+), 106 deletions(-) create mode 100644 releasenotes/notes/os-net-config-mappings-move-to-ansible-940a48711870ac58.yaml diff --git a/firstboot/os-net-config-mappings.yaml b/firstboot/os-net-config-mappings.yaml index dc105034c0..39dc14949a 100644 --- a/firstboot/os-net-config-mappings.yaml +++ b/firstboot/os-net-config-mappings.yaml @@ -1,39 +1,11 @@ heat_template_version: rocky description: > - Configure os-net-config mappings for specific nodes - Your environment file needs to look like: - resource_registry: - OS::TripleO::NodeUserData: /usr/share/openstack-tripleo-heat-templates/firstboot/os-net-config-mappings.yaml - parameter_defaults: - NetConfigDataLookup: - node1: - nic1: "00:c8:7c:e6:f0:2e" - node2: - nic1: "00:18:7d:99:0c:b6" - node3: - dmiString: 'system-uuid' - id: 'A8C85861-1B16-4803-8689-AFC62984F8F6' - nic1: em3 - # Dell PowerEdge - nodegroup1: - dmiString: "system-product-name" - id: "PowerEdge R630" - nic1: em3 - nic2: em1 - nic3: em2 - # Cisco UCS B200-M4" - nodegroup2: - dmiString: "system-product-name" - id: "UCSB-B200-M4" - nic1: enp7s0 - nic2: enp6s0 + DEPRECATED! Configure os-net-config mappings for specific nodes - This will result in the first node* entry where either: - a) a mac matches a local device - or b) a DMI String matches the specified id - being written as a mapping file for os-net-config in - /etc/os-net-config/mapping.yaml + DEPRECATION NOTE: + This template has been replaced by an ansible module in tripleo-ansible. + The parameter NetConfigDataLookup is still used, and the input format remain the same for compatibility. parameters: # Note this requires a liberty heat or newer in the undercloud due to @@ -43,80 +15,37 @@ parameters: NetConfigDataLookup: type: json default: {} - description: per-node configuration map + description: > + Configure os-net-config mappings for specific nodes + Your environment file needs to look like: + parameter_defaults: + NetConfigDataLookup: + node1: + nic1: "00:c8:7c:e6:f0:2e" + node2: + nic1: "00:18:7d:99:0c:b6" + node3: + dmiString: 'system-uuid' + id: 'A8C85861-1B16-4803-8689-AFC62984F8F6' + nic1: em3 + # Dell PowerEdge + nodegroup1: + dmiString: "system-product-name" + id: "PowerEdge R630" + nic1: em3 + nic2: em1 + nic3: em2 + # Cisco UCS B200-M4" + nodegroup2: + dmiString: "system-product-name" + id: "UCSB-B200-M4" + nic1: enp7s0 + nic2: enp6s0 + + This will result in the first node* entry where either a mac matches a + local device or a DMI String matches the specified id being written as a + mapping file for os-net-config. (/etc/os-net-config/mapping.yaml) resources: - userdata: - type: OS::Heat::MultipartMime - properties: - parts: - - config: {get_resource: OsNetConfigMappings} - OsNetConfigMappings: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - str_replace: - template: | - #!/bin/sh - eth_addr=$(cat /sys/class/net/*/address | tr '\n' ',') - mkdir -p /etc/os-net-config - - # needed to handle where python lives - function get_python() { - command -v python3 || command -v python2 || command -v python || exit 1 - } - - # Create an os-net-config mapping file, note this defaults to - # /etc/os-net-config/mapping.yaml, so we use that name despite - # rendering the result as json - echo '$node_lookup' | $(get_python) -c " - import json - import sys - import copy - from subprocess import PIPE, Popen - import yaml - - def write_mapping_file(interface_mapping): - with open('/etc/os-net-config/mapping.yaml', 'w') as f: - yaml.safe_dump(interface_mapping, f, default_flow_style=False) - - # cast to lower case for MAC address match - eth_addr='$eth_addr'.lower() - - input = sys.stdin.readline() or '{}' - data = json.loads(input) - for node in data: - interface_mapping = {'interface_mapping': - copy.deepcopy(data[node])} - if 'dmiString' in interface_mapping['interface_mapping']: - del interface_mapping['interface_mapping']['dmiString'] - if 'id' in interface_mapping['interface_mapping']: - del interface_mapping['interface_mapping']['id'] - - # Match on mac addresses first - cast all to lower case - lc_interface_mapping = copy.deepcopy(interface_mapping) - for key,x in lc_interface_mapping['interface_mapping'].items(): - lc_interface_mapping['interface_mapping'][key] = x.lower() - if any(x in eth_addr.split(',') for x in lc_interface_mapping['interface_mapping'].values()): - write_mapping_file(lc_interface_mapping) - break - - # If data contain dmiString and id keys, try to match node(group) - if 'dmiString' in data[node] and 'id' in data[node]: - ps = Popen([ 'dmidecode', - '--string', data[node].get('dmiString') ], - stdout=PIPE, universal_newlines=True) - out, err = ps.communicate() - # See LP#1816652 - if data[node].get('id').lower() == out.rstrip().lower(): - write_mapping_file(lc_interface_mapping) - break - " - params: - $node_lookup: {get_param: NetConfigDataLookup} - -outputs: - OS::stack_id: - value: {get_resource: userdata} + type: OS::Heat::None diff --git a/overcloud.j2.yaml b/overcloud.j2.yaml index 383db64e73..b2ac06f16e 100644 --- a/overcloud.j2.yaml +++ b/overcloud.j2.yaml @@ -307,6 +307,40 @@ parameters: default: {} description: Map of extra global_config_settings data to set on each node. + NetConfigDataLookup: + type: json + default: {} + description: > + Configure os-net-config mappings for specific nodes + Your environment file needs to look like: + parameter_defaults: + NetConfigDataLookup: + node1: + nic1: "00:c8:7c:e6:f0:2e" + node2: + nic1: "00:18:7d:99:0c:b6" + node3: + dmiString: 'system-uuid' + id: 'A8C85861-1B16-4803-8689-AFC62984F8F6' + nic1: em3 + # Dell PowerEdge + nodegroup1: + dmiString: "system-product-name" + id: "PowerEdge R630" + nic1: em3 + nic2: em1 + nic3: em2 + # Cisco UCS B200-M4" + nodegroup2: + dmiString: "system-product-name" + id: "UCSB-B200-M4" + nic1: enp7s0 + nic2: enp6s0 + + This will result in the first node* entry where either a mac matches a + local device or a DMI String matches the specified id being written as a + mapping file for os-net-config. (/etc/os-net-config/mapping.yaml) + {% for role in roles %} {%- if role.deprecated_param_scheduler_hints is defined or role.deprecated_param_extraconfig is defined %} {%- if not parameter_groups_defined|default(false) %} @@ -1209,6 +1243,7 @@ outputs: neutron_physical_bridge_name: {get_param: NeutronPhysicalBridge} neutron_public_interface_name: {get_param: NeutronPublicInterface} network_deployment_actions: {get_attr: [{{role.name}}NetworkDeploymentActionsValue, value]} + tripleo_network_config_os_net_config_mappings: {get_param: NetConfigDataLookup} - {get_param: {{role.name}}ExtraGroupVars} {%- endfor %} RoleNetHostnameMap: diff --git a/releasenotes/notes/os-net-config-mappings-move-to-ansible-940a48711870ac58.yaml b/releasenotes/notes/os-net-config-mappings-move-to-ansible-940a48711870ac58.yaml new file mode 100644 index 0000000000..961cf9fdac --- /dev/null +++ b/releasenotes/notes/os-net-config-mappings-move-to-ansible-940a48711870ac58.yaml @@ -0,0 +1,14 @@ +--- +upgrade: + - | + Operators utilizing the ``firstboot/os-net-config-mappings.yaml`` should + remove the resource registry entry. The template was replaced by a module + in ansible. The data format and parameter ``NetConfigDataLookup`` is still + used. +deprecations: + - | + The firstboot template ``firstboot/os-net-config-mappings.yaml`` that was + used to create an os-net-config mapping file has been deprecated and + replaced by an ansible module. The parameter ``NetConfigDataLookup`` + remains with no data format change for compatibility. +