From f5943e36ef9075e846be0de55778abbba8b2c000 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Tue, 5 Sep 2023 15:20:29 +0200 Subject: [PATCH 01/16] Refine config persistence in /etc/sonic/config_db.json Optimize persistence strategy by selectively storing essential segments, such as breakout and port configurations, instead of the entire running configuration. This mitigates undesired configurations, particularly those arising from metal-core. --- partition/roles/sonic/README.md | 6 +- partition/roles/sonic/defaults/main.yaml | 1 + partition/roles/sonic/handlers/main.yaml | 17 +--- partition/roles/sonic/tasks/main.yaml | 44 ++++++++-- partition/roles/sonic/templates/metal.yaml.j2 | 48 +++++++---- .../roles/sonic/test/data/exit/input.yaml | 58 ++++++++++--- .../roles/sonic/test/data/exit/metal.yaml | 30 ++++++- .../roles/sonic/test/data/mgmtleaf/frr.conf | 8 +- .../roles/sonic/test/data/mgmtleaf/input.yaml | 82 ++++++++++++++++--- .../roles/sonic/test/data/mgmtleaf/metal.yaml | 68 +++++++++++++-- .../roles/sonic/test/data/spine/frr.conf | 8 +- .../roles/sonic/test/data/spine/input.yaml | 32 +++++++- .../roles/sonic/test/data/spine/metal.yaml | 27 +++++- 13 files changed, 340 insertions(+), 89 deletions(-) diff --git a/partition/roles/sonic/README.md b/partition/roles/sonic/README.md index a083b47d..5e4040e6 100644 --- a/partition/roles/sonic/README.md +++ b/partition/roles/sonic/README.md @@ -17,8 +17,8 @@ It depends on the `switch_facts` module from `ansible-common`, so make sure modu | sonic_mgmtif_gateway | | If using a fixed management IP, the default gateway for the management interface. | | sonic_ip_masquerade | | Enable ip masquerading on eth0. | | sonic_breakouts | | The breakout configuration for ports, e.g. `dict('Ethernet0'='4x25G')` | -| sonic_ports | | Special configuration for ports (mtu, fec, have highest precedence) | -| sonic_ports.name | | The port name. | +| sonic_config_action | | Either `load` or `reload`. In the latter case all services will be restarted. | +| sonic_ports | | Configuration for ports (mtu, fec, have highest precedence). These ports will be up by default. | | sonic_ports.speed | | Speed of the port. | | sonic_ports.mtu | | MTU of the port. | | sonic_ports.fec | | FEC used for the port. | @@ -42,7 +42,7 @@ It depends on the `switch_facts` module from `ansible-common`, so make sure modu | sonic_vlans.ip | | The IP of the SVI of this VLAN. | | sonic_vlans.dhcp_servers | | DHCP servers to relay to. | | sonic_vlans.untagged_ports | | Array of untagged ports to bind to this VLAN. | -| sonic_vlans.tagged_ports | | Array of tagged ports to bind to this VLAN. | +| sonic_vlans.tagged_ports | | Array of tagged ports to bind to this VLAN. | | sonic_vlans.vrf | | The VRF to bind the VLANs SVI to. | | sonic_vteps | | VTEPs to configure. If defined FRR will automatically advertise all VNIs. | | sonic_vteps.comment | | Description for the VTEP. | diff --git a/partition/roles/sonic/defaults/main.yaml b/partition/roles/sonic/defaults/main.yaml index 3acbb816..2200346c 100644 --- a/partition/roles/sonic/defaults/main.yaml +++ b/partition/roles/sonic/defaults/main.yaml @@ -4,6 +4,7 @@ sonic_ntpservers: [] sonic_nameservers: [] sonic_ip_masquerade: false sonic_timezone: Europe/Berlin +sonic_config_action: reload ## Physical settings sonic_breakouts: {} diff --git a/partition/roles/sonic/handlers/main.yaml b/partition/roles/sonic/handlers/main.yaml index a89d7620..235269f0 100644 --- a/partition/roles/sonic/handlers/main.yaml +++ b/partition/roles/sonic/handlers/main.yaml @@ -3,18 +3,6 @@ systemd: daemon_reload: yes -- name: write metal conf to db - ansible.builtin.command: sonic-cfggen --yaml /etc/sonic/metal.yaml --write-to-db - notify: config save - -- name: config save - ansible.builtin.command: config save -y - -- name: config save and reload - systemd: - name: config-save-reload - state: started - - name: restart bgp systemd: name: bgp @@ -25,8 +13,11 @@ name: caclmgrd state: restarted +- name: config load + ansible.builtin.command: config load --yes + - name: config reload - ansible.builtin.command: config reload -y + ansible.builtin.command: config reload --yes async: 120 poll: 0 notify: wait for new connection diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index c9fd14c6..05212280 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -10,6 +10,7 @@ - sonic_mgmt_vrf is defined - sonic_loopback_address is defined - sonic_asn is defined + - sonic_config_action in ['load', 'reload'] - sonic_ntpservers is defined - sonic_nameservers is defined - metal_stack_switch_os_is_sonic @@ -53,13 +54,42 @@ with_dict: "{{ sonic_breakouts }}" when: sonic_breakouts is defined -- name: Render metal config for config_db.json - template: - src: metal.yaml.j2 - dest: /etc/sonic/metal.yaml - notify: - - write metal conf to db - - config reload +- name: Get running configuration + ansible.builtin.command: show runningconfiguration all + register: sonic_running_cfg + +- name: Extract running configuration for breakouts and ports + ansible.builtin.set_fact: + sonic_running_cfg_breakouts: "{{ sonic_running_cfg | community.general.json_query('BREAKOUT_CFG') }}" + sonic_running_cfg_hwsku: "{{ sonic_running_cfg | community.general.json_query('DEVICE_METADATA.localhost.hwsku') }}" + sonic_running_cfg_mac: "{{ sonic_running_cfg | community.general.json_query('DEVICE_METADATA.localhost.mac') }}" + sonic_running_cfg_platform: "{{ sonic_running_cfg | community.general.json_query('DEVICE_METADATA.localhost.platform') }}" + sonic_running_cfg_ports: "{{ sonic_running_cfg | community.general.json_query('PORT') }}" + +- name: Fail if running configuration doesn't contain required informations + ansible.builtin.assert: + that: + - sonic_running_cfg_breakouts is defined and sonic_running_cfg_breakouts | length > 0 + - sonic_running_cfg_hwsku is defined and sonic_running_cfg_hwsku | length > 0 + - sonic_running_cfg_mac is defined and sonic_running_cfg_mac | length > 0 + - sonic_running_cfg_platform is defined and sonic_running_cfg_platform | length > 0 + - sonic_running_cfg_ports is defined and sonic_running_cfg_ports | length > 0 + fail_msg: The running configuration is incomplete because it does not contain 'BREAKOUT_CFG', 'PORT', or complete 'DEVICE_METADATA'. + +- name: Fail if running configuration doesn't contain 'PORT' + ansible.builtin.fail: + msg: The running configuration doesn't contain 'PORT' {{ sonic_running_cfg }} + when: "sonic_running_cfg_ports | length == 0" + +- name: Render config_db + set_fact: + config_db: "{{ lookup('template', 'metal.yaml.j2') }}" + +- name: Save config_db as JSON file + copy: + content: "{{ config_db | from_yaml | to_nice_json }}" + dest: /etc/sonic/config_db.json + notify: "config {{ sonic_config_action }}" - name: Set NTP timezone timezone: diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index fe86e054..bc895d2e 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -4,6 +4,9 @@ DEVICE_METADATA: localhost: docker_routing_config_mode: split hostname: "{{ inventory_hostname }}" + hwsku: "{{ sonic_running_cfg_hwsku }}" + mac: "{{ sonic_running_cfg_mac }}" + platform: "{{ sonic_running_cfg_platform }}" type: "LeafRouter" frr_mgmt_framework_config: "true" @@ -41,34 +44,49 @@ MGMT_VRF_CONFIG: {% if sonic_ports|length > 0 %} INTERFACE: - {% for port in sonic_ports %} - {% if port.name in sonic_bgp_ports|default([]) or port.vrf is defined %} - {{ port.name }}: - {% if port.name in sonic_bgp_ports|default([]) %} + {% for name, cfg in sonic_ports.items() %} + {% if name in sonic_bgp_ports|default([]) or cfg.vrf is defined %} + {{ name }}: + {% if name in sonic_bgp_ports|default([]) %} ipv6_use_link_local_only: enable {% endif %} - {% if port.vrf is defined %} - vrf_name: "{{ port.vrf }}" + {% if cfg.vrf is defined %} + vrf_name: "{{ cfg.vrf }}" {% endif %} {% elif port.ips is defined %} {{ port.name }}: {} {% endif %} - {% for ip in port.ips|default([]) %} - {{ port.name }}|{{ ip }}: {} + {% for ip in cfg.ips|default([]) %} + {{ name }}|{{ ip }}: {} {% endfor %} {% endfor %} {% endif %} -{% if sonic_ports|length > 0 %} + +BREAKOUT_CFG: + {% for name, cfg in sonic_running_cfg_breakouts.items() %} + {{ name }}: + brkout_mode: "{{ cfg.brkout_mode }}" + {% endfor %} PORT: - {% for port in sonic_ports %} - {{ port.name }}: + {% for name, cfg in sonic_running_cfg_ports.items() %} + {{ name }}: + alias: {{ cfg.alias }} + autoneg: "off" + index: "{{ cfg.index }}" + lanes: "{{ cfg.lanes }}" + parent_port: {{ cfg.parent_port }} + {% if sonic_ports[name] is defined %} admin_status: up - speed: "{{ port.speed|default(sonic_ports_default_speed) }}" - mtu: "{{ port.mtu|default(sonic_ports_default_mtu) }}" - fec: "{{ port.fec|default(sonic_ports_default_fec)|string|lower }}" + speed: "{{ sonic_ports[name].speed|default(cfg.speed) }}" + mtu: "{{ sonic_ports[name].mtu|default(sonic_ports_default_mtu) }}" + fec: "{{ sonic_ports[name].fec|default(sonic_ports_default_fec)|string|lower }}" + {% else %} + speed: "{{ cfg.speed }}" + mtu: "{{ sonic_ports_default_mtu }}" + fec: "{{ sonic_ports_default_fec|string|lower }}" + {% endif %} {% endfor %} -{% endif %} {% if sonic_vlans is defined and sonic_vlans|length > 0 %} VLAN: diff --git a/partition/roles/sonic/test/data/exit/input.yaml b/partition/roles/sonic/test/data/exit/input.yaml index 509a9b30..4c597b5e 100644 --- a/partition/roles/sonic/test/data/exit/input.yaml +++ b/partition/roles/sonic/test/data/exit/input.yaml @@ -7,24 +7,56 @@ sonic_breakouts: Ethernet0: "4x10G" sonic_ports: -- name: Ethernet0 - speed: 10000 - mtu: 1500 - vrf: VrfMpls - ips: - - 10.0.0.2/32 + Ethernet0: + speed: 10000 + mtu: 1500 + vrf: VrfMpls + ips: + - 10.0.0.2/32 # Uplink for pxe VLAN -- name: Ethernet1 - speed: 10000 -- name: Ethernet2 - speed: 10000 -- name: Ethernet3 + Ethernet1: + speed: 10000 + Ethernet2: + speed: 10000 + Ethernet3: speed: 10000 ips: - 10.1.2.2/30 # spine uplinks -- name: Ethernet112 -- name: Ethernet116 + Ethernet112: + Ethernet116: + +sonic_running_cfg_breakouts: + Ethernet0: + brkout_mode: "4x10G" + Ethernet112: + brkout_mode: "1x100G[40G]" + Ethernet116: + brkout_mode: "1x100G[40G]" + +sonic_running_cfg_hwsku: Accton-AS7726-32X +sonic_running_cfg_mac: e0:01:a6:e3:29:3c +sonic_running_cfg_platform: x86_64-accton_as7726_32x-r0 + +sonic_running_cfg_ports: + Ethernet0: + alias: Eth1/1(Port1) + index: "1" + lanes: "1" + parent_port: Ethernet0 + speed: "10000" + Ethernet112: + alias: Eth29(Port29) + index: "29" + lanes: "113,114,115,116" + parent_port: Ethernet112 + speed: "100000" + Ethernet116: + alias: Eth30(Port30) + index: "30" + lanes: "117,118,119,120" + parent_port: Ethernet116 + speed: "100000" sonic_bgp_ports: - Ethernet112 diff --git a/partition/roles/sonic/test/data/exit/metal.yaml b/partition/roles/sonic/test/data/exit/metal.yaml index 4b2d1dba..ae5550e2 100644 --- a/partition/roles/sonic/test/data/exit/metal.yaml +++ b/partition/roles/sonic/test/data/exit/metal.yaml @@ -3,6 +3,9 @@ DEVICE_METADATA: localhost: docker_routing_config_mode: split hostname: "exit01" + hwsku: "Accton-AS7726-32X" + mac: "e0:01:a6:e3:29:3c" + platform: "x86_64-accton_as7726_32x-r0" type: "LeafRouter" frr_mgmt_framework_config: "true" @@ -36,8 +39,21 @@ INTERFACE: Ethernet116: ipv6_use_link_local_only: enable +BREAKOUT_CFG: + Ethernet0: + brkout_mode: "4x10G" + Ethernet112: + brkout_mode: "1x100G[40G]" + Ethernet116: + brkout_mode: "1x100G[40G]" + PORT: Ethernet0: + alias: Eth1/1(Port1) + autoneg: "off" + index: "1" + lanes: "1" + parent_port: Ethernet0 admin_status: up speed: "10000" mtu: "1500" @@ -58,13 +74,23 @@ PORT: mtu: "9216" fec: "none" Ethernet112: + alias: Eth29(Port29) + autoneg: "off" + index: "29" + lanes: "113,114,115,116" + parent_port: Ethernet112 admin_status: up - speed: "10000" + speed: "100000" mtu: "9216" fec: "none" Ethernet116: + alias: Eth30(Port30) + autoneg: "off" + index: "30" + lanes: "117,118,119,120" + parent_port: Ethernet116 admin_status: up - speed: "10000" + speed: "100000" mtu: "9216" fec: "none" diff --git a/partition/roles/sonic/test/data/mgmtleaf/frr.conf b/partition/roles/sonic/test/data/mgmtleaf/frr.conf index 436860eb..ff440493 100644 --- a/partition/roles/sonic/test/data/mgmtleaf/frr.conf +++ b/partition/roles/sonic/test/data/mgmtleaf/frr.conf @@ -5,11 +5,11 @@ service integrated-vtysh-config ! log syslog informational ! -interface Ethernet50 +interface Ethernet120 ipv6 nd ra-interval 6 no ipv6 nd suppress-ra ! -interface Ethernet51 +interface Ethernet124 ipv6 nd ra-interval 6 no ipv6 nd suppress-ra ! @@ -19,8 +19,8 @@ router bgp 420000000 neighbor FABRIC peer-group neighbor FABRIC remote-as external neighbor FABRIC timers 1 3 - neighbor Ethernet50 interface peer-group FABRIC - neighbor Ethernet51 interface peer-group FABRIC + neighbor Ethernet120 interface peer-group FABRIC + neighbor Ethernet124 interface peer-group FABRIC ! address-family ipv4 unicast redistribute connected route-map DENY_MGMT diff --git a/partition/roles/sonic/test/data/mgmtleaf/input.yaml b/partition/roles/sonic/test/data/mgmtleaf/input.yaml index b3ef81ca..1f306818 100644 --- a/partition/roles/sonic/test/data/mgmtleaf/input.yaml +++ b/partition/roles/sonic/test/data/mgmtleaf/input.yaml @@ -13,20 +13,78 @@ sonic_breakouts: sonic_ports_default_speed: 1000 sonic_ports_default_mtu: 9000 sonic_ports: -- name: Ethernet0 -- name: Ethernet1 -- name: Ethernet2 -- name: Ethernet3 -- name: Ethernet50 - speed: 100000 - mtu: 9216 - fec: rs -- name: Ethernet51 - speed: 100000 + Ethernet0: + Ethernet1: + Ethernet2: + Ethernet3: + Ethernet120: + speed: 100000 + mtu: 9216 + fec: rs + Ethernet124: + speed: 100000 + +sonic_running_cfg_breakouts: + Ethernet0: + brkout_mode: "4x25G" + Ethernet4: + brkout_mode: "1x100G[40G]" + Ethernet120: + brkout_mode: "1x100G[40G]" + Ethernet124: + brkout_mode: "1x100G[40G]" + +sonic_running_cfg_hwsku: Accton-AS7726-32X +sonic_running_cfg_mac: e0:01:a6:e3:29:3c +sonic_running_cfg_platform: x86_64-accton_as7726_32x-r0 + +sonic_running_cfg_ports: + Ethernet0: + alias: Eth1/1(Port1) + index: "1" + lanes: "1" + parent_port: Ethernet0 + speed: "25000" + Ethernet1: + alias: Eth1/2(Port1) + index: '1' + lanes: '2' + parent_port: Ethernet0 + speed: '25000' + Ethernet2: + alias: Eth1/3(Port1) + index: '1' + lanes: '3' + parent_port: Ethernet0 + speed: '25000' + Ethernet3: + alias: Eth1/4(Port1) + index: '1' + lanes: '4' + parent_port: Ethernet0 + speed: '25000' + Ethernet4: + alias: Eth2(Port2) + index: '2' + lanes: '5,6,7,8' + parent_port: Ethernet4 + speed: '100000' + Ethernet120: + alias: Eth31(Port31) + index: '31' + lanes: '121,122,123,124' + parent_port: Ethernet120 + speed: '100000' + Ethernet124: + alias: Eth32(Port32) + index: '32' + lanes: '125,126,127,128' + parent_port: Ethernet124 + speed: '100000' sonic_bgp_ports: -- Ethernet50 -- Ethernet51 +- Ethernet120 +- Ethernet124 sonic_vlans: - id: 1 diff --git a/partition/roles/sonic/test/data/mgmtleaf/metal.yaml b/partition/roles/sonic/test/data/mgmtleaf/metal.yaml index 1ec4be26..30cf018b 100644 --- a/partition/roles/sonic/test/data/mgmtleaf/metal.yaml +++ b/partition/roles/sonic/test/data/mgmtleaf/metal.yaml @@ -3,6 +3,9 @@ DEVICE_METADATA: localhost: docker_routing_config_mode: split hostname: "r01mgmtleaf" + hwsku: "Accton-AS7726-32X" + mac: "e0:01:a6:e3:29:3c" + platform: "x86_64-accton_as7726_32x-r0" type: "LeafRouter" frr_mgmt_framework_config: "true" @@ -31,38 +34,87 @@ MGMT_VRF_CONFIG: mgmtVrfEnabled: "true" INTERFACE: - Ethernet50: + Ethernet120: ipv6_use_link_local_only: enable - Ethernet51: + Ethernet124: ipv6_use_link_local_only: enable +BREAKOUT_CFG: + Ethernet0: + brkout_mode: "4x25G" + Ethernet4: + brkout_mode: "1x100G[40G]" + Ethernet120: + brkout_mode: "1x100G[40G]" + Ethernet124: + brkout_mode: "1x100G[40G]" + PORT: Ethernet0: + alias: Eth1/1(Port1) + autoneg: "off" + index: "1" + lanes: "1" + parent_port: Ethernet0 admin_status: up - speed: "1000" + speed: "25000" mtu: "9000" fec: "none" Ethernet1: + alias: Eth1/2(Port1) + autoneg: "off" + index: "1" + lanes: "2" + parent_port: Ethernet0 admin_status: up - speed: "1000" + speed: "25000" mtu: "9000" fec: "none" Ethernet2: + alias: Eth1/3(Port1) + autoneg: "off" + index: "1" + lanes: "3" + parent_port: Ethernet0 admin_status: up - speed: "1000" + speed: "25000" mtu: "9000" fec: "none" Ethernet3: + alias: Eth1/4(Port1) + autoneg: "off" + index: "1" + lanes: "4" + parent_port: Ethernet0 admin_status: up - speed: "1000" + speed: "25000" + mtu: "9000" + fec: "none" + Ethernet4: + alias: Eth2(Port2) + autoneg: "off" + index: "2" + lanes: "5,6,7,8" + parent_port: Ethernet4 + speed: "100000" mtu: "9000" fec: "none" - Ethernet50: + Ethernet120: + alias: Eth31(Port31) + autoneg: "off" + index: "31" + lanes: "121,122,123,124" + parent_port: Ethernet120 admin_status: up speed: "100000" mtu: "9216" fec: "rs" - Ethernet51: + Ethernet124: + alias: Eth32(Port32) + autoneg: "off" + index: "32" + lanes: "125,126,127,128" + parent_port: Ethernet124 admin_status: up speed: "100000" mtu: "9000" diff --git a/partition/roles/sonic/test/data/spine/frr.conf b/partition/roles/sonic/test/data/spine/frr.conf index d1e04a6a..5826ab01 100644 --- a/partition/roles/sonic/test/data/spine/frr.conf +++ b/partition/roles/sonic/test/data/spine/frr.conf @@ -5,11 +5,11 @@ service integrated-vtysh-config ! log syslog informational ! -interface Ethernet50 +interface Ethernet120 ipv6 nd ra-interval 6 no ipv6 nd suppress-ra ! -interface Ethernet51 +interface Ethernet124 ipv6 nd ra-interval 6 no ipv6 nd suppress-ra ! @@ -19,8 +19,8 @@ router bgp 420000000 neighbor FABRIC peer-group neighbor FABRIC remote-as external neighbor FABRIC timers 1 3 - neighbor Ethernet50 interface peer-group FABRIC - neighbor Ethernet51 interface peer-group FABRIC + neighbor Ethernet120 interface peer-group FABRIC + neighbor Ethernet124 interface peer-group FABRIC ! address-family ipv4 unicast redistribute connected route-map LOOPBACKS diff --git a/partition/roles/sonic/test/data/spine/input.yaml b/partition/roles/sonic/test/data/spine/input.yaml index 30842c38..1dd012b4 100644 --- a/partition/roles/sonic/test/data/spine/input.yaml +++ b/partition/roles/sonic/test/data/spine/input.yaml @@ -5,14 +5,38 @@ sonic_loopback_address: 10.0.0.1 sonic_asn: 420000000 sonic_bgp_ports: -- Ethernet50 -- Ethernet51 +- Ethernet120 +- Ethernet124 sonic_ports_default_speed: 100000 sonic_ports_default_mtu: 9216 sonic_ports: -- name: Ethernet50 -- name: Ethernet51 + Ethernet120: + Ethernet124: + +sonic_running_cfg_breakouts: + Ethernet120: + brkout_mode: "1x100G[40G]" + Ethernet124: + brkout_mode: "1x100G[40G]" + +sonic_running_cfg_hwsku: Accton-AS7726-32X +sonic_running_cfg_mac: e0:01:a6:e3:29:3c +sonic_running_cfg_platform: x86_64-accton_as7726_32x-r0 + +sonic_running_cfg_ports: + Ethernet120: + alias: Eth31(Port31) + index: '31' + lanes: '121,122,123,124' + parent_port: Ethernet120 + speed: '100000' + Ethernet124: + alias: Eth32(Port32) + index: '32' + lanes: '125,126,127,128' + parent_port: Ethernet124 + speed: '100000' sonic_frr_l2vpn_evpn: true sonic_frr_route_map: diff --git a/partition/roles/sonic/test/data/spine/metal.yaml b/partition/roles/sonic/test/data/spine/metal.yaml index 7fc90636..d1cccb5a 100644 --- a/partition/roles/sonic/test/data/spine/metal.yaml +++ b/partition/roles/sonic/test/data/spine/metal.yaml @@ -3,6 +3,9 @@ DEVICE_METADATA: localhost: docker_routing_config_mode: split hostname: "spine01" + hwsku: "Accton-AS7726-32X" + mac: "e0:01:a6:e3:29:3c" + platform: "x86_64-accton_as7726_32x-r0" type: "LeafRouter" frr_mgmt_framework_config: "true" @@ -26,18 +29,34 @@ MGMT_VRF_CONFIG: mgmtVrfEnabled: "true" INTERFACE: - Ethernet50: + Ethernet120: ipv6_use_link_local_only: enable - Ethernet51: + Ethernet124: ipv6_use_link_local_only: enable +BREAKOUT_CFG: + Ethernet120: + brkout_mode: "1x100G[40G]" + Ethernet124: + brkout_mode: "1x100G[40G]" + PORT: - Ethernet50: + Ethernet120: + alias: Eth31(Port31) + autoneg: "off" + index: "31" + lanes: "121,122,123,124" + parent_port: Ethernet120 admin_status: up speed: "100000" mtu: "9216" fec: "none" - Ethernet51: + Ethernet124: + alias: Eth32(Port32) + autoneg: "off" + index: "32" + lanes: "125,126,127,128" + parent_port: Ethernet124 admin_status: up speed: "100000" mtu: "9216" From 70b22bf3b4512f99919474079806f3229b0ffb0e Mon Sep 17 00:00:00 2001 From: Gerrit Date: Thu, 7 Sep 2023 14:27:23 +0200 Subject: [PATCH 02/16] Cleanup old metal.yaml file. --- partition/roles/sonic/tasks/main.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index 05212280..c19edca2 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -54,6 +54,11 @@ with_dict: "{{ sonic_breakouts }}" when: sonic_breakouts is defined +- name: Delete deprecated metal.yaml + file: + path: "/etc/sonic/metal.yaml" + state: absent + - name: Get running configuration ansible.builtin.command: show runningconfiguration all register: sonic_running_cfg From a4c5693e667ff58725fcd6c508f7e477a142c3f5 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Thu, 7 Sep 2023 14:27:35 +0200 Subject: [PATCH 03/16] Typo. --- partition/roles/sonic/tasks/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index c19edca2..1e1eb461 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -71,7 +71,7 @@ sonic_running_cfg_platform: "{{ sonic_running_cfg | community.general.json_query('DEVICE_METADATA.localhost.platform') }}" sonic_running_cfg_ports: "{{ sonic_running_cfg | community.general.json_query('PORT') }}" -- name: Fail if running configuration doesn't contain required informations +- name: Fail if running configuration doesn't contain required information ansible.builtin.assert: that: - sonic_running_cfg_breakouts is defined and sonic_running_cfg_breakouts | length > 0 From 1a9b2f3f01ebdd6d77316d3ef36909fe1dca8b29 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Thu, 7 Sep 2023 14:28:15 +0200 Subject: [PATCH 04/16] Add MGMT_PORT to config_db.json. This key should be contained as otherwise validations would fail. --- partition/roles/sonic/templates/metal.yaml.j2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index bc895d2e..975608e4 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -37,6 +37,12 @@ MGMT_INTERFACE: eth0|{{ sonic_mgmtif_ip }}: {} {% endif %} +MGMT_PORT: + eth0: + alias: "eth0" + admin_status: "up" + description: "Management Port" + {% endif %} MGMT_VRF_CONFIG: vrf_global: From 8b36ae933ccdacf8f9b57881fedeae64ee322284 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 8 Sep 2023 13:48:33 +0200 Subject: [PATCH 05/16] Fix parsing of the running configuration --- partition/roles/sonic/tasks/main.yaml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index 1e1eb461..43e86eb9 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -55,13 +55,17 @@ when: sonic_breakouts is defined - name: Delete deprecated metal.yaml - file: + ansible.builtin.file: path: "/etc/sonic/metal.yaml" state: absent - name: Get running configuration ansible.builtin.command: show runningconfiguration all - register: sonic_running_cfg + register: sonic_running_cfg_result + +- name: Parse running configuration + ansible.builtin.set_fact: + sonic_running_cfg: "{{ sonic_running_cfg_result.stdout | from_json }}" - name: Extract running configuration for breakouts and ports ansible.builtin.set_fact: @@ -74,18 +78,13 @@ - name: Fail if running configuration doesn't contain required information ansible.builtin.assert: that: - - sonic_running_cfg_breakouts is defined and sonic_running_cfg_breakouts | length > 0 - - sonic_running_cfg_hwsku is defined and sonic_running_cfg_hwsku | length > 0 - - sonic_running_cfg_mac is defined and sonic_running_cfg_mac | length > 0 - - sonic_running_cfg_platform is defined and sonic_running_cfg_platform | length > 0 - - sonic_running_cfg_ports is defined and sonic_running_cfg_ports | length > 0 + - sonic_running_cfg_breakouts + - sonic_running_cfg_hwsku + - sonic_running_cfg_mac + - sonic_running_cfg_platform + - sonic_running_cfg_ports fail_msg: The running configuration is incomplete because it does not contain 'BREAKOUT_CFG', 'PORT', or complete 'DEVICE_METADATA'. -- name: Fail if running configuration doesn't contain 'PORT' - ansible.builtin.fail: - msg: The running configuration doesn't contain 'PORT' {{ sonic_running_cfg }} - when: "sonic_running_cfg_ports | length == 0" - - name: Render config_db set_fact: config_db: "{{ lookup('template', 'metal.yaml.j2') }}" From a0b996b609fae342b8664d0cf6c376f759ae32cb Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 8 Sep 2023 13:50:34 +0200 Subject: [PATCH 06/16] Revert changing sonic_ports from list to dict --- partition/roles/sonic/README.md | 1 + partition/roles/sonic/tasks/main.yaml | 4 ++++ partition/roles/sonic/templates/metal.yaml.j2 | 9 +++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/partition/roles/sonic/README.md b/partition/roles/sonic/README.md index 5e4040e6..b5d2d390 100644 --- a/partition/roles/sonic/README.md +++ b/partition/roles/sonic/README.md @@ -19,6 +19,7 @@ It depends on the `switch_facts` module from `ansible-common`, so make sure modu | sonic_breakouts | | The breakout configuration for ports, e.g. `dict('Ethernet0'='4x25G')` | | sonic_config_action | | Either `load` or `reload`. In the latter case all services will be restarted. | | sonic_ports | | Configuration for ports (mtu, fec, have highest precedence). These ports will be up by default. | +| sonic_ports.name | | The port name. | | sonic_ports.speed | | Speed of the port. | | sonic_ports.mtu | | MTU of the port. | | sonic_ports.fec | | FEC used for the port. | diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index 43e86eb9..f2da65f7 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -14,6 +14,10 @@ - sonic_ntpservers is defined - sonic_nameservers is defined - metal_stack_switch_os_is_sonic +- name: Populate sonic_ports_dict + set_fact: + sonic_ports_dict: "{{ sonic_ports_dict|default({}) | combine( {item.name: item} ) }}" + loop: "{{ sonic_ports }}" - name: render resolv.conf template: diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index 975608e4..a81439a9 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -82,11 +82,12 @@ PORT: index: "{{ cfg.index }}" lanes: "{{ cfg.lanes }}" parent_port: {{ cfg.parent_port }} - {% if sonic_ports[name] is defined %} + {% if sonic_ports_dict[name] is defined %} + {% set port = sonic_ports_dict[name] %} admin_status: up - speed: "{{ sonic_ports[name].speed|default(cfg.speed) }}" - mtu: "{{ sonic_ports[name].mtu|default(sonic_ports_default_mtu) }}" - fec: "{{ sonic_ports[name].fec|default(sonic_ports_default_fec)|string|lower }}" + speed: "{{ port.speed|default(cfg.speed) }}" + mtu: "{{ port.mtu|default(sonic_ports_default_mtu) }}" + fec: "{{ port.fec|default(sonic_ports_default_fec)|string|lower }}" {% else %} speed: "{{ cfg.speed }}" mtu: "{{ sonic_ports_default_mtu }}" From 9e58b19086130e5d64c7f5a2840f2dd48657e073 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 8 Sep 2023 13:53:12 +0200 Subject: [PATCH 07/16] Use default values for speed, mtu, and fec only for configured ports --- partition/roles/sonic/defaults/main.yaml | 5 ----- partition/roles/sonic/tasks/main.yaml | 11 +++++++++++ partition/roles/sonic/templates/metal.yaml.j2 | 4 +--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/partition/roles/sonic/defaults/main.yaml b/partition/roles/sonic/defaults/main.yaml index 2200346c..a23435ee 100644 --- a/partition/roles/sonic/defaults/main.yaml +++ b/partition/roles/sonic/defaults/main.yaml @@ -9,11 +9,6 @@ sonic_config_action: reload ## Physical settings sonic_breakouts: {} sonic_ports: [] -#- name: Ethernet50 -# speed: 10000 -sonic_ports_default_speed: 10000 -sonic_ports_default_mtu: 9216 -sonic_ports_default_fec: none ## BGP related settings sonic_loopback_address: diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index f2da65f7..3324d450 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -14,6 +14,17 @@ - sonic_ntpservers is defined - sonic_nameservers is defined - metal_stack_switch_os_is_sonic + +- name: Check mandatory variables on non-empty sonic_ports are set + assert: + fail_msg: "default port configuration is necessary on non-empty sonic_ports" + quiet: yes + that: + - sonic_ports_default_speed is defined + - sonic_ports_default_mtu is defined + - sonic_ports_default_fec is defined + when: sonic_ports + - name: Populate sonic_ports_dict set_fact: sonic_ports_dict: "{{ sonic_ports_dict|default({}) | combine( {item.name: item} ) }}" diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index a81439a9..cca61546 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -85,13 +85,11 @@ PORT: {% if sonic_ports_dict[name] is defined %} {% set port = sonic_ports_dict[name] %} admin_status: up - speed: "{{ port.speed|default(cfg.speed) }}" + speed: "{{ port.speed|default(sonic_ports_default_speed) }}" mtu: "{{ port.mtu|default(sonic_ports_default_mtu) }}" fec: "{{ port.fec|default(sonic_ports_default_fec)|string|lower }}" {% else %} speed: "{{ cfg.speed }}" - mtu: "{{ sonic_ports_default_mtu }}" - fec: "{{ sonic_ports_default_fec|string|lower }}" {% endif %} {% endfor %} {% if sonic_vlans is defined and sonic_vlans|length > 0 %} From 0ae6845c44849e1889b84b3cc98f744c47b23d25 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 8 Sep 2023 13:53:39 +0200 Subject: [PATCH 08/16] Rename cfg to running_cfg --- partition/roles/sonic/templates/metal.yaml.j2 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index cca61546..73a956b1 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -75,13 +75,13 @@ BREAKOUT_CFG: {% endfor %} PORT: - {% for name, cfg in sonic_running_cfg_ports.items() %} + {% for name, running_cfg in sonic_running_cfg_ports.items() %} {{ name }}: - alias: {{ cfg.alias }} + alias: {{ running_cfg.alias }} autoneg: "off" - index: "{{ cfg.index }}" - lanes: "{{ cfg.lanes }}" - parent_port: {{ cfg.parent_port }} + index: "{{ running_cfg.index }}" + lanes: "{{ running_cfg.lanes }}" + parent_port: {{ running_cfg.parent_port }} {% if sonic_ports_dict[name] is defined %} {% set port = sonic_ports_dict[name] %} admin_status: up @@ -89,7 +89,7 @@ PORT: mtu: "{{ port.mtu|default(sonic_ports_default_mtu) }}" fec: "{{ port.fec|default(sonic_ports_default_fec)|string|lower }}" {% else %} - speed: "{{ cfg.speed }}" + speed: "{{ running_cfg.speed }}" {% endif %} {% endfor %} {% if sonic_vlans is defined and sonic_vlans|length > 0 %} From e233af9bd485d4083a9b69301b9ef043338cf7a2 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 8 Sep 2023 13:56:59 +0200 Subject: [PATCH 09/16] Revert changes to INTERFACE --- partition/roles/sonic/templates/metal.yaml.j2 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index 73a956b1..740ff611 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -50,20 +50,20 @@ MGMT_VRF_CONFIG: {% if sonic_ports|length > 0 %} INTERFACE: - {% for name, cfg in sonic_ports.items() %} - {% if name in sonic_bgp_ports|default([]) or cfg.vrf is defined %} - {{ name }}: - {% if name in sonic_bgp_ports|default([]) %} + {% for port in sonic_ports %} + {% if port.name in sonic_bgp_ports|default([]) or port.vrf is defined %} + {{ port.name }}: + {% if port.name in sonic_bgp_ports|default([]) %} ipv6_use_link_local_only: enable {% endif %} - {% if cfg.vrf is defined %} - vrf_name: "{{ cfg.vrf }}" + {% if port.vrf is defined %} + vrf_name: "{{ port.vrf }}" {% endif %} {% elif port.ips is defined %} {{ port.name }}: {} {% endif %} - {% for ip in cfg.ips|default([]) %} - {{ name }}|{{ ip }}: {} + {% for ip in port.ips|default([]) %} + {{ port.name }}|{{ ip }}: {} {% endfor %} {% endfor %} {% endif %} From 181771c6b30cbd1be52cb1ea2f95cb3aba57922b Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 8 Sep 2023 14:39:19 +0200 Subject: [PATCH 10/16] Fix tests --- partition/roles/sonic/templates/metal.yaml.j2 | 16 +++++----- .../roles/sonic/test/data/exit/input.yaml | 32 +++++++++++++------ .../roles/sonic/test/data/exit/metal.yaml | 32 ++++++++++++------- .../roles/sonic/test/data/mgmtleaf/input.yaml | 5 +-- .../roles/sonic/test/data/mgmtleaf/metal.yaml | 16 ++++++---- .../roles/sonic/test/data/spine/input.yaml | 5 +-- .../roles/sonic/test/data/spine/metal.yaml | 6 ++++ 7 files changed, 73 insertions(+), 39 deletions(-) diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index 740ff611..89edf48b 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -37,33 +37,33 @@ MGMT_INTERFACE: eth0|{{ sonic_mgmtif_ip }}: {} {% endif %} +{% endif %} MGMT_PORT: eth0: alias: "eth0" admin_status: "up" description: "Management Port" -{% endif %} MGMT_VRF_CONFIG: vrf_global: mgmtVrfEnabled: "{{ sonic_mgmt_vrf | lower }}" -{% if sonic_ports|length > 0 %} +{% if sonic_ports_dict|length > 0 %} INTERFACE: - {% for port in sonic_ports %} - {% if port.name in sonic_bgp_ports|default([]) or port.vrf is defined %} - {{ port.name }}: - {% if port.name in sonic_bgp_ports|default([]) %} + {% for name, port in sonic_ports_dict.items() %} + {% if name in sonic_bgp_ports|default([]) or port.vrf is defined %} + {{ name }}: + {% if name in sonic_bgp_ports|default([]) %} ipv6_use_link_local_only: enable {% endif %} {% if port.vrf is defined %} vrf_name: "{{ port.vrf }}" {% endif %} {% elif port.ips is defined %} - {{ port.name }}: {} + {{ name }}: {} {% endif %} {% for ip in port.ips|default([]) %} - {{ port.name }}|{{ ip }}: {} + {{ name }}|{{ ip }}: {} {% endfor %} {% endfor %} {% endif %} diff --git a/partition/roles/sonic/test/data/exit/input.yaml b/partition/roles/sonic/test/data/exit/input.yaml index 4c597b5e..dfb5b4a5 100644 --- a/partition/roles/sonic/test/data/exit/input.yaml +++ b/partition/roles/sonic/test/data/exit/input.yaml @@ -6,22 +6,16 @@ sonic_loopback_address: 10.0.0.1 sonic_breakouts: Ethernet0: "4x10G" -sonic_ports: +sonic_ports_default_fec: none +sonic_ports_default_mtu: 9216 +sonic_ports_default_speed: 100000 +sonic_ports_dict: Ethernet0: speed: 10000 mtu: 1500 vrf: VrfMpls ips: - 10.0.0.2/32 -# Uplink for pxe VLAN - Ethernet1: - speed: 10000 - Ethernet2: - speed: 10000 - Ethernet3: - speed: 10000 - ips: - - 10.1.2.2/30 # spine uplinks Ethernet112: Ethernet116: @@ -45,6 +39,24 @@ sonic_running_cfg_ports: lanes: "1" parent_port: Ethernet0 speed: "10000" + Ethernet1: + alias: Eth1/2(Port1) + index: "1" + lanes: "2" + parent_port: Ethernet0 + speed: "10000" + Ethernet2: + alias: Eth1/3(Port1) + index: "1" + lanes: "3" + parent_port: Ethernet0 + speed: "10000" + Ethernet3: + alias: Eth1/4(Port1) + index: "1" + lanes: "4" + parent_port: Ethernet0 + speed: "10000" Ethernet112: alias: Eth29(Port29) index: "29" diff --git a/partition/roles/sonic/test/data/exit/metal.yaml b/partition/roles/sonic/test/data/exit/metal.yaml index ae5550e2..2b57deb1 100644 --- a/partition/roles/sonic/test/data/exit/metal.yaml +++ b/partition/roles/sonic/test/data/exit/metal.yaml @@ -24,6 +24,12 @@ LOOPBACK_INTERFACE: Loopback0: {} Loopback0|10.0.0.1/32: {} +MGMT_PORT: + eth0: + alias: "eth0" + admin_status: "up" + description: "Management Port" + MGMT_VRF_CONFIG: vrf_global: mgmtVrfEnabled: "true" @@ -32,8 +38,6 @@ INTERFACE: Ethernet0: vrf_name: "VrfMpls" Ethernet0|10.0.0.2/32: {} - Ethernet3: {} - Ethernet3|10.1.2.2/30: {} Ethernet112: ipv6_use_link_local_only: enable Ethernet116: @@ -59,20 +63,26 @@ PORT: mtu: "1500" fec: "none" Ethernet1: - admin_status: up + alias: Eth1/2(Port1) + autoneg: "off" + index: "1" + lanes: "2" + parent_port: Ethernet0 speed: "10000" - mtu: "9216" - fec: "none" Ethernet2: - admin_status: up + alias: Eth1/3(Port1) + autoneg: "off" + index: "1" + lanes: "3" + parent_port: Ethernet0 speed: "10000" - mtu: "9216" - fec: "none" Ethernet3: - admin_status: up + alias: Eth1/4(Port1) + autoneg: "off" + index: "1" + lanes: "4" + parent_port: Ethernet0 speed: "10000" - mtu: "9216" - fec: "none" Ethernet112: alias: Eth29(Port29) autoneg: "off" diff --git a/partition/roles/sonic/test/data/mgmtleaf/input.yaml b/partition/roles/sonic/test/data/mgmtleaf/input.yaml index 1f306818..3144cc7a 100644 --- a/partition/roles/sonic/test/data/mgmtleaf/input.yaml +++ b/partition/roles/sonic/test/data/mgmtleaf/input.yaml @@ -10,9 +10,10 @@ sonic_ntpservers: ['1.2.3.4'] sonic_breakouts: Ethernet0: "4x25G" -sonic_ports_default_speed: 1000 +sonic_ports_default_fec: none sonic_ports_default_mtu: 9000 -sonic_ports: +sonic_ports_default_speed: 1000 +sonic_ports_dict: Ethernet0: Ethernet1: Ethernet2: diff --git a/partition/roles/sonic/test/data/mgmtleaf/metal.yaml b/partition/roles/sonic/test/data/mgmtleaf/metal.yaml index 30cf018b..13375a14 100644 --- a/partition/roles/sonic/test/data/mgmtleaf/metal.yaml +++ b/partition/roles/sonic/test/data/mgmtleaf/metal.yaml @@ -29,6 +29,12 @@ MGMT_INTERFACE: eth0|10.255.255.254/30: gwaddr: "10.255.255.253" +MGMT_PORT: + eth0: + alias: "eth0" + admin_status: "up" + description: "Management Port" + MGMT_VRF_CONFIG: vrf_global: mgmtVrfEnabled: "true" @@ -57,7 +63,7 @@ PORT: lanes: "1" parent_port: Ethernet0 admin_status: up - speed: "25000" + speed: "1000" mtu: "9000" fec: "none" Ethernet1: @@ -67,7 +73,7 @@ PORT: lanes: "2" parent_port: Ethernet0 admin_status: up - speed: "25000" + speed: "1000" mtu: "9000" fec: "none" Ethernet2: @@ -77,7 +83,7 @@ PORT: lanes: "3" parent_port: Ethernet0 admin_status: up - speed: "25000" + speed: "1000" mtu: "9000" fec: "none" Ethernet3: @@ -87,7 +93,7 @@ PORT: lanes: "4" parent_port: Ethernet0 admin_status: up - speed: "25000" + speed: "1000" mtu: "9000" fec: "none" Ethernet4: @@ -97,8 +103,6 @@ PORT: lanes: "5,6,7,8" parent_port: Ethernet4 speed: "100000" - mtu: "9000" - fec: "none" Ethernet120: alias: Eth31(Port31) autoneg: "off" diff --git a/partition/roles/sonic/test/data/spine/input.yaml b/partition/roles/sonic/test/data/spine/input.yaml index 1dd012b4..1af2451d 100644 --- a/partition/roles/sonic/test/data/spine/input.yaml +++ b/partition/roles/sonic/test/data/spine/input.yaml @@ -8,9 +8,10 @@ sonic_bgp_ports: - Ethernet120 - Ethernet124 -sonic_ports_default_speed: 100000 +sonic_ports_default_fec: none sonic_ports_default_mtu: 9216 -sonic_ports: +sonic_ports_default_speed: 100000 +sonic_ports_dict: Ethernet120: Ethernet124: diff --git a/partition/roles/sonic/test/data/spine/metal.yaml b/partition/roles/sonic/test/data/spine/metal.yaml index d1cccb5a..6c63856e 100644 --- a/partition/roles/sonic/test/data/spine/metal.yaml +++ b/partition/roles/sonic/test/data/spine/metal.yaml @@ -24,6 +24,12 @@ LOOPBACK_INTERFACE: Loopback0: {} Loopback0|10.0.0.1/32: {} +MGMT_PORT: + eth0: + alias: "eth0" + admin_status: "up" + description: "Management Port" + MGMT_VRF_CONFIG: vrf_global: mgmtVrfEnabled: "true" From 268dad1e1f60c4a9bf4220e227b8491fc114e2c8 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 8 Sep 2023 14:59:51 +0200 Subject: [PATCH 11/16] Set default value for sonic_ports_default_fec --- partition/roles/sonic/defaults/main.yaml | 1 + partition/roles/sonic/tasks/main.yaml | 5 ++--- partition/roles/sonic/test/data/exit/input.yaml | 1 - partition/roles/sonic/test/data/mgmtleaf/input.yaml | 1 - partition/roles/sonic/test/data/spine/input.yaml | 1 - 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/partition/roles/sonic/defaults/main.yaml b/partition/roles/sonic/defaults/main.yaml index a23435ee..4928c5df 100644 --- a/partition/roles/sonic/defaults/main.yaml +++ b/partition/roles/sonic/defaults/main.yaml @@ -9,6 +9,7 @@ sonic_config_action: reload ## Physical settings sonic_breakouts: {} sonic_ports: [] +sonic_ports_default_fec: none ## BGP related settings sonic_loopback_address: diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index 3324d450..51cb08e4 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -20,9 +20,8 @@ fail_msg: "default port configuration is necessary on non-empty sonic_ports" quiet: yes that: - - sonic_ports_default_speed is defined - - sonic_ports_default_mtu is defined - - sonic_ports_default_fec is defined + - sonic_ports_default_speed + - sonic_ports_default_mtu when: sonic_ports - name: Populate sonic_ports_dict diff --git a/partition/roles/sonic/test/data/exit/input.yaml b/partition/roles/sonic/test/data/exit/input.yaml index dfb5b4a5..f6dbdd15 100644 --- a/partition/roles/sonic/test/data/exit/input.yaml +++ b/partition/roles/sonic/test/data/exit/input.yaml @@ -6,7 +6,6 @@ sonic_loopback_address: 10.0.0.1 sonic_breakouts: Ethernet0: "4x10G" -sonic_ports_default_fec: none sonic_ports_default_mtu: 9216 sonic_ports_default_speed: 100000 sonic_ports_dict: diff --git a/partition/roles/sonic/test/data/mgmtleaf/input.yaml b/partition/roles/sonic/test/data/mgmtleaf/input.yaml index 3144cc7a..89383ceb 100644 --- a/partition/roles/sonic/test/data/mgmtleaf/input.yaml +++ b/partition/roles/sonic/test/data/mgmtleaf/input.yaml @@ -10,7 +10,6 @@ sonic_ntpservers: ['1.2.3.4'] sonic_breakouts: Ethernet0: "4x25G" -sonic_ports_default_fec: none sonic_ports_default_mtu: 9000 sonic_ports_default_speed: 1000 sonic_ports_dict: diff --git a/partition/roles/sonic/test/data/spine/input.yaml b/partition/roles/sonic/test/data/spine/input.yaml index 1af2451d..ee686988 100644 --- a/partition/roles/sonic/test/data/spine/input.yaml +++ b/partition/roles/sonic/test/data/spine/input.yaml @@ -8,7 +8,6 @@ sonic_bgp_ports: - Ethernet120 - Ethernet124 -sonic_ports_default_fec: none sonic_ports_default_mtu: 9216 sonic_ports_default_speed: 100000 sonic_ports_dict: From 0b46ca8d03d7557e6c8bcc0f6d14abd5c886d20a Mon Sep 17 00:00:00 2001 From: Robert Volkmann <20912167+robertvolkmann@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:37:15 +0200 Subject: [PATCH 12/16] Add default for sonic_ports_dict --- partition/roles/sonic/defaults/main.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/partition/roles/sonic/defaults/main.yaml b/partition/roles/sonic/defaults/main.yaml index 4928c5df..8b75d422 100644 --- a/partition/roles/sonic/defaults/main.yaml +++ b/partition/roles/sonic/defaults/main.yaml @@ -9,6 +9,7 @@ sonic_config_action: reload ## Physical settings sonic_breakouts: {} sonic_ports: [] +sonic_ports_dict: {} sonic_ports_default_fec: none ## BGP related settings @@ -41,4 +42,4 @@ sonic_frr_static_routes_mgmt: [] sonic_interconnects: {} sonic_interconnects_default_peer_group: EXTERNAL -sonic_interconnects_default_bgp_timers: '1 3' \ No newline at end of file +sonic_interconnects_default_bgp_timers: '1 3' From 4870a0f14562a68566216654006548dbf14879ec Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Thu, 21 Sep 2023 13:16:36 +0200 Subject: [PATCH 13/16] bgp should run after a config reload --- partition/roles/sonic/handlers/main.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/partition/roles/sonic/handlers/main.yaml b/partition/roles/sonic/handlers/main.yaml index 235269f0..56f37fd6 100644 --- a/partition/roles/sonic/handlers/main.yaml +++ b/partition/roles/sonic/handlers/main.yaml @@ -3,11 +3,6 @@ systemd: daemon_reload: yes -- name: restart bgp - systemd: - name: bgp - state: restarted - - name: restart caclmgrd systemd: name: caclmgrd @@ -28,3 +23,8 @@ sleep: 5 delay: 30 timeout: 300 + +- name: restart bgp + systemd: + name: bgp + state: restarted From 5a0620c4f375197b164bcf838baf118e27d52a78 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Thu, 21 Sep 2023 14:07:18 +0200 Subject: [PATCH 14/16] Prevent 'changed' for 'Get running configuration' --- partition/roles/sonic/tasks/main.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index 51cb08e4..e69a3cf7 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -76,6 +76,7 @@ - name: Get running configuration ansible.builtin.command: show runningconfiguration all register: sonic_running_cfg_result + changed_when: false - name: Parse running configuration ansible.builtin.set_fact: From 3b26d661411812e8b9d0241be3a6f4eebf1b8381 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 22 Sep 2023 10:25:08 +0200 Subject: [PATCH 15/16] Fetch autoneg from running configuration --- partition/roles/sonic/templates/metal.yaml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partition/roles/sonic/templates/metal.yaml.j2 b/partition/roles/sonic/templates/metal.yaml.j2 index 89edf48b..4204a4c2 100644 --- a/partition/roles/sonic/templates/metal.yaml.j2 +++ b/partition/roles/sonic/templates/metal.yaml.j2 @@ -78,7 +78,7 @@ PORT: {% for name, running_cfg in sonic_running_cfg_ports.items() %} {{ name }}: alias: {{ running_cfg.alias }} - autoneg: "off" + autoneg: "{{ running_cfg.autoneg|default("off")|string|lower }}" index: "{{ running_cfg.index }}" lanes: "{{ running_cfg.lanes }}" parent_port: {{ running_cfg.parent_port }} From 800499ed21c41ba571b1c5f8200008cf328bfeec Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 22 Sep 2023 11:16:20 +0200 Subject: [PATCH 16/16] Change sonic_config_action to `load` --- partition/roles/sonic/README.md | 2 +- partition/roles/sonic/defaults/main.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/partition/roles/sonic/README.md b/partition/roles/sonic/README.md index b5d2d390..3c1b3791 100644 --- a/partition/roles/sonic/README.md +++ b/partition/roles/sonic/README.md @@ -17,7 +17,7 @@ It depends on the `switch_facts` module from `ansible-common`, so make sure modu | sonic_mgmtif_gateway | | If using a fixed management IP, the default gateway for the management interface. | | sonic_ip_masquerade | | Enable ip masquerading on eth0. | | sonic_breakouts | | The breakout configuration for ports, e.g. `dict('Ethernet0'='4x25G')` | -| sonic_config_action | | Either `load` or `reload`. In the latter case all services will be restarted. | +| sonic_config_action | | Either `load` or `reload`. In the latter case all services will be restarted. If not given, defaults to `load` | | sonic_ports | | Configuration for ports (mtu, fec, have highest precedence). These ports will be up by default. | | sonic_ports.name | | The port name. | | sonic_ports.speed | | Speed of the port. | diff --git a/partition/roles/sonic/defaults/main.yaml b/partition/roles/sonic/defaults/main.yaml index 8b75d422..67f92ef4 100644 --- a/partition/roles/sonic/defaults/main.yaml +++ b/partition/roles/sonic/defaults/main.yaml @@ -4,7 +4,7 @@ sonic_ntpservers: [] sonic_nameservers: [] sonic_ip_masquerade: false sonic_timezone: Europe/Berlin -sonic_config_action: reload +sonic_config_action: load ## Physical settings sonic_breakouts: {}