Skip to content

Commit 8c4e0b5

Browse files
authored
[202503][Cherrypick PR] Address fixes to make sure t2 topology deploy works both with and without macsec_enabled (#17530) (#361)
manual cherry-pick of PR - sonic-net/sonic-mgmt#17530
2 parents 311eaff + 4c9c0c5 commit 8c4e0b5

6 files changed

Lines changed: 101 additions & 2 deletions

File tree

ansible/config_sonic_basedon_testbed.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,26 @@
613613
hwsku: "{{ hwsku }}"
614614
become: true
615615

616+
- name: Copy macsec profile json to dut
617+
copy: src=../tests/common/macsec/profile.json
618+
dest=/tmp/profile.json
619+
become: true
620+
when: "('t2' in topo) and (enable_macsec is defined)"
621+
622+
- name: Copy golden_config_db_t2 template to DUT
623+
copy: src=templates/golden_config_db_t2.j2
624+
dest=/tmp/golden_config_db_t2.j2
625+
become: true
626+
when: "('t2' in topo) and (enable_macsec is defined)"
627+
628+
- name: Generate golden_config_db.json for t2
629+
generate_golden_config_db:
630+
topo_name: "{{ topo }}"
631+
macsec_profile: "{{ macsec_profile }}"
632+
num_asics: "{{ num_asics }}"
633+
become: true
634+
when: "('t2' in topo) and (enable_macsec is defined)"
635+
616636
- name: Use minigraph case
617637
block:
618638
- name: execute cli "config load_minigraph --override_config -y" to apply new minigraph

ansible/library/generate_golden_config_db.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ def generate(self):
274274
module_msg = module_msg + " for smartswitch"
275275
elif self.topo_name in ["ft2-64"]:
276276
config = self.generate_ft2_golden_config_db()
277+
elif "t2" in self.topo_name and self.macsec_profile:
278+
config = self.generate_t2_golden_config_db()
279+
self.module.run_command("sudo rm -f {}".format(MACSEC_PROFILE_PATH))
280+
self.module.run_command("sudo rm -f {}".format(GOLDEN_CONFIG_TEMPLATE_PATH))
277281
elif self.hwsku and is_full_lossy_hwsku(self.hwsku):
278282
module_msg = module_msg + " for full lossy hwsku"
279283
config = self.generate_full_lossy_golden_config_db()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
import json
5+
from ansible.module_utils.basic import AnsibleModule
6+
7+
8+
def convert_to_eos(cipher_name):
9+
# Set the cipher suite as 256 xpn by default
10+
eos_cipher_name = 'aes256-gcm-xpn'
11+
12+
if cipher_name == 'GCM-AES-XPN-256':
13+
eos_cipher_name = 'aes256-gcm-xpn'
14+
elif cipher_name == 'GCM-AES-128':
15+
eos_cipher_name = 'aes128-gcm'
16+
elif cipher_name == 'GCM-AES-256':
17+
eos_cipher_name = 'aes256-gcm'
18+
elif cipher_name == 'GCM-AES-XPN-128':
19+
eos_cipher_name = 'aes128-gcm-xpn'
20+
21+
return eos_cipher_name
22+
23+
24+
# This API support EoS based templates now
25+
def get_macsec_profile(module, macsec_profile, vm_type):
26+
with open('/tmp/profile.json') as f:
27+
macsec_profiles = json.load(f)
28+
29+
profile = macsec_profiles.get(macsec_profile)
30+
if profile:
31+
profile['macsec_profile'] = macsec_profile
32+
33+
# Currently handling ceos, add more cases for vsonic etc
34+
if vm_type == 'ceos':
35+
# Get the cipher suite in eos terminology
36+
eos_cipher_suite_name = convert_to_eos(profile['cipher_suite'])
37+
profile['cipher_suite'] = eos_cipher_suite_name
38+
39+
return profile
40+
41+
42+
def main():
43+
module = AnsibleModule(argument_spec=dict(
44+
macsec_profile=dict(required=True, type='str'),
45+
vm_type=dict(required=True, type='str')))
46+
47+
macsec_profile = module.params['macsec_profile']
48+
vm_type = module.params['vm_type']
49+
module.exit_json(profile=get_macsec_profile(module, macsec_profile, vm_type), changed=False)
50+
51+
52+
if __name__ == "__main__":
53+
main()

ansible/roles/eos/tasks/ceos_config.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@
3232
state: directory
3333
delegate_to: "{{ VM_host[0] }}"
3434

35+
- name: Copy macsec profile json to dut
36+
copy: src=../../../../tests/common/macsec/profile.json
37+
dest=/tmp/profile.json
38+
become: true
39+
when: "'t2' == base_topo and enable_macsec is defined"
40+
delegate_to: "{{ VM_host[0] }}"
41+
42+
- name: Get the macsec profile data from profile_name
43+
get_macsec_profile:
44+
macsec_profile: "{{ macsec_profile }}"
45+
vm_type: "{{ vm_type }}"
46+
register: profile_raw
47+
become: true
48+
when: "'t2' == base_topo and enable_macsec is defined"
49+
delegate_to: "{{ VM_host[0] }}"
50+
51+
- name: Flatten profile data into a flat structure
52+
set_fact:
53+
profile: "{{ profile_raw.profile }}"
54+
when: "'t2' == base_topo and enable_macsec is defined"
55+
delegate_to: "{{ VM_host[0] }}"
56+
3557
- name: update startup-config
3658
become: yes
3759
template: src="{{ base_topo }}-{{ props.swrole }}.j2"

ansible/templates/minigraph_link_meta.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</a:LinkMetadata>
4040
{% endfor %}
4141
{% endif %}
42-
{% if macsec_card is defined and macsec_card == True and 't2' in topo %}
42+
{% if macsec_card is defined and enable_macsec is defined and macsec_card == True and 't2' in topo %}
4343
{% for index in range(vms_number) %}
4444
{% set vm_intfs=vm_topo_config['vm'][vms[index]]['intfs'][dut_index|int]|sort %}
4545
{% set dut_intfs=vm_topo_config['vm'][vms[index]]['interface_indexes'][dut_index|int]|sort %}

ansible/templates/minigraph_meta.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
<a:Value>{{ switch_type }}</a:Value>
234234
</a:DeviceProperty>
235235
{% endif %}
236-
{% if macsec_card is defined and macsec_card == True and 't2' in topo %}
236+
{% if macsec_card is defined and enable_macsec is defined and macsec_card == True and 't2' in topo %}
237237
<a:DeviceProperty>
238238
<a:Name>MacSecProfile</a:Name>
239239
<a:Value>PrimaryKey="MACSEC_PROFILE" FallbackKey="macsec-profile2" MacsecPolicy=""</a:Value>

0 commit comments

Comments
 (0)