Skip to content

Commit 0b2f188

Browse files
authored
Address fixes to make sure t2 topology deploy works both with and without macsec_enabled (sonic-net#17530)
1 parent c181ecc commit 0b2f188

6 files changed

+35
-8
lines changed

ansible/config_sonic_basedon_testbed.yml

-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@
595595
topo_name: "{{ topo }}"
596596
port_index_map: "{{ port_index_map | default({}) }}"
597597
become: true
598-
when: "'t2' not in topo"
599598

600599
- name: Copy macsec profile json to dut
601600
copy: src=../tests/common/macsec/profile.json

ansible/library/generate_golden_config_db.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def generate(self):
407407
elif self.topo_name in ["t1-smartswitch-ha", "t1-28-lag", "smartswitch-t1"]:
408408
config = self.generate_smartswitch_golden_config_db()
409409
self.module.run_command("sudo rm -f {}".format(TEMP_SMARTSWITCH_CONFIG_PATH))
410-
elif "t2" in self.topo_name:
410+
elif "t2" in self.topo_name and self.macsec_profile:
411411
config = self.generate_t2_golden_config_db()
412412
self.module.run_command("sudo rm -f {}".format(MACSEC_PROFILE_PATH))
413413
self.module.run_command("sudo rm -f {}".format(GOLDEN_CONFIG_TEMPLATE_PATH))

ansible/library/get_macsec_profile.py

+29-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,48 @@
55
from ansible.module_utils.basic import AnsibleModule
66

77

8-
def get_macsec_profile(module, macsec_profile):
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):
926
with open('/tmp/profile.json') as f:
1027
macsec_profiles = json.load(f)
1128

1229
profile = macsec_profiles.get(macsec_profile)
1330
if profile:
1431
profile['macsec_profile'] = macsec_profile
1532

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+
1639
return profile
1740

1841

1942
def main():
20-
module = AnsibleModule(argument_spec=dict(macsec_profile=dict(required=True, type='str')))
43+
module = AnsibleModule(argument_spec=dict(
44+
macsec_profile=dict(required=True, type='str'),
45+
vm_type=dict(required=True, type='str')))
2146

2247
macsec_profile = module.params['macsec_profile']
23-
module.exit_json(profile=get_macsec_profile(module, macsec_profile), changed=False)
48+
vm_type = module.params['vm_type']
49+
module.exit_json(profile=get_macsec_profile(module, macsec_profile, vm_type), changed=False)
2450

2551

2652
if __name__ == "__main__":

ansible/roles/eos/tasks/ceos_config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- name: Get the macsec profile data from profile_name
4343
get_macsec_profile:
4444
macsec_profile: "{{ macsec_profile }}"
45+
vm_type: "{{ vm_type }}"
4546
register: profile_raw
4647
become: true
4748
when: "'t2' == base_topo and enable_macsec is defined"

ansible/templates/minigraph_link_meta.j2

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{%- set ns = namespace(link_metadata_defined=False) -%}
22

3-
{%- if 'dualtor' in topo or (macsec_card is defined and macsec_card == True and 't2' in topo) -%}
3+
{%- if 'dualtor' in topo or
4+
(macsec_card is defined and enable_macsec is defined and macsec_card == True and 't2' in topo) -%}
45
{% set ns.link_metadata_defined = True %}
56
{%- endif -%}
67

@@ -38,7 +39,7 @@
3839
</a:LinkMetadata>
3940
{% endfor %}
4041
{% endif %}
41-
{% 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 %}
4243
{% for index in range(vms_number) %}
4344
{% set vm_intfs=vm_topo_config['vm'][vms[index]]['intfs'][dut_index|int]|sort %}
4445
{% set dut_intfs=vm_topo_config['vm'][vms[index]]['interface_indexes'][dut_index|int]|sort %}

ansible/templates/minigraph_meta.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
<a:Value>{{ switch_type }}</a:Value>
227227
</a:DeviceProperty>
228228
{% endif %}
229-
{% if macsec_card is defined and macsec_card == True and 't2' in topo %}
229+
{% if macsec_card is defined and enable_macsec is defined and macsec_card == True and 't2' in topo %}
230230
<a:DeviceProperty>
231231
<a:Name>MacSecProfile</a:Name>
232232
<a:Value>PrimaryKey="MACSEC_PROFILE" FallbackKey="macsec-profile2" MacsecPolicy=""</a:Value>

0 commit comments

Comments
 (0)