Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible support for Versatile hash feature #401

Merged
merged 9 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/401-versatile-hash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- sonic_system - Adding Versatile Hash feature.(https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/401).
4 changes: 4 additions & 0 deletions plugins/module_utils/network/sonic/argspec/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def __init__(self, **kwargs):
'auto_breakout': {
'choices': ['ENABLE', 'DISABLE'],
'type': 'str'
},
'load_share_hash_algo': {
'choices': ['CRC', 'XOR', 'CRC_32LO', 'CRC_32HI', 'CRC_CCITT', 'CRC_XOR', 'JENKINS_HASH_LO', 'JENKINS_HASH_HI'],
'type': 'str'
}
},
'type': 'dict'
Expand Down
32 changes: 29 additions & 3 deletions plugins/module_utils/network/sonic/config/system/system.py
ohu1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def __derive_system_config_delete_op(key_set, command, exist_conf):
new_conf['anycast_address']['mac_address'] = None
if 'auto_breakout' in command:
new_conf['auto_breakout'] = 'DISABLE'
if 'load_share_hash_algo' in command:
new_conf['load_share_hash_algo'] = None
return True, new_conf


Expand Down Expand Up @@ -239,18 +241,18 @@ def _state_replaced_overridden(self, want, have):
'ipv6': True
},
'auto_breakout': 'DISABLE'

}
del_request_method = {
'hostname': self.get_hostname_delete_request,
'interface_naming': self.get_intfname_delete_request,
'auto_breakout': self.get_auto_breakout_delete_request
'auto_breakout': self.get_auto_breakout_delete_request,
'load_share_hash_algo': self.get_load_share_hash_algo_delete_request
}

new_have = remove_empties(have)
new_want = remove_empties(want)

for option in ('hostname', 'interface_naming', 'auto_breakout'):
for option in ('hostname', 'interface_naming', 'auto_breakout', 'load_share_hash_algo'):
if option in new_want:
if new_want[option] != new_have.get(option):
add_command[option] = new_want[option]
Expand Down Expand Up @@ -312,6 +314,11 @@ def get_create_system_request(self, want, commands):
if auto_breakout_payload:
request = {'path': auto_breakout_path, 'method': method, 'data': auto_breakout_payload}
requests.append(request)
load_share_hash_algo_path = "data/openconfig-loadshare-mode-ext:loadshare/hash-algorithm/config"
load_share_hash_algo_payload = self.build_create_load_share_hash_algo_payload(commands)
if load_share_hash_algo_payload:
request = {'path': load_share_hash_algo_path, 'method': method, 'data': load_share_hash_algo_payload}
ohu1 marked this conversation as resolved.
Show resolved Hide resolved
requests.append(request)
return requests

def build_create_hostname_payload(self, commands):
Expand Down Expand Up @@ -356,6 +363,13 @@ def build_create_auto_breakout_payload(self, commands):
payload.update({'sonic-device-metadata:auto-breakout': commands["auto_breakout"]})
return payload

def build_create_load_share_hash_algo_payload(self, commands):
payload = {}
if "load_share_hash_algo" in commands and commands["load_share_hash_algo"]:
payload = {"openconfig-loadshare-mode-ext:config": {}}
payload['openconfig-loadshare-mode-ext:config'].update({"algorithm": commands["load_share_hash_algo"]})
return payload

def remove_default_entries(self, data):
new_data = {}
if not data:
Expand Down Expand Up @@ -383,6 +397,9 @@ def remove_default_entries(self, data):
auto_breakout_mode = data.get('auto_breakout', None)
if auto_breakout_mode != "DISABLE":
new_data["auto_breakout"] = auto_breakout_mode
load_share_hash_algo = data.get('load_share_hash_algo', None)
if load_share_hash_algo is not None:
new_data["load_share_hash_algo"] = load_share_hash_algo
return new_data

def get_delete_all_system_request(self, have):
Expand All @@ -399,6 +416,9 @@ def get_delete_all_system_request(self, have):
if "auto_breakout" in have:
request = self.get_auto_breakout_delete_request()
requests.append(request)
if "load_share_hash_algo" in have:
request = self.get_load_share_hash_algo_delete_request()
requests.append(request)
return requests

def get_hostname_delete_request(self):
Expand Down Expand Up @@ -439,3 +459,9 @@ def get_auto_breakout_delete_request(self):
method = DELETE
request = {'path': path, 'method': method}
return request

def get_load_share_hash_algo_delete_request(self):
path = 'data/openconfig-loadshare-mode-ext:loadshare/hash-algorithm/config/algorithm'
method = DELETE
request = {'path': path, 'method': method}
return request
21 changes: 20 additions & 1 deletion plugins/module_utils/network/sonic/facts/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ def get_anycast_addr(self):
data = {}
return data

def get_load_share_hash_algo(self):
"""Get load share hash algorithm"""
request = [{"path": "data/openconfig-loadshare-mode-ext:loadshare/hash-algorithm/config", "method": GET}]
try:
response = edit_config(self._module, to_request(self._module, request))
except ConnectionError as exc:
self._module.fail_json(msg=str(exc), code=exc.code)
if ('openconfig-loadshare-mode-ext:config' in response[0][1]):
data = response[0][1]['openconfig-loadshare-mode-ext:config']
else:
data = {}
return data

def populate_facts(self, connection, ansible_facts, data=None):
""" Populate the facts for system
:param connection: the device connection
Expand All @@ -103,12 +116,15 @@ def populate_facts(self, connection, ansible_facts, data=None):
anycast_addr = self.get_anycast_addr()
if anycast_addr:
data.update(anycast_addr)
load_share_hash_algo = self.get_load_share_hash_algo()
if load_share_hash_algo:
data.update(load_share_hash_algo)
objs = []
objs = self.render_config(self.generated_spec, data)
facts = {}
if objs:
params = utils.validate_config(self.argument_spec, {'config': objs})
facts['system'] = params['config']
facts['system'] = utils.remove_empties(params['config'])
ansible_facts['ansible_network_resources'].update(facts)
return ansible_facts

Expand Down Expand Up @@ -144,4 +160,7 @@ def parse_sonic_system(self, spec, conf):
config['anycast_address']['mac_address'] = conf['gwmac']
if ('auto-breakout' in conf) and (conf['auto-breakout']):
config['auto_breakout'] = conf['auto-breakout']
if ('algorithm' in conf) and (conf['algorithm']):
config['load_share_hash_algo'] = conf['algorithm']

return utils.remove_empties(config)
28 changes: 28 additions & 0 deletions plugins/modules/sonic_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@
choices:
- ENABLE
- DISABLE
load_share_hash_algo:
description:
- Specifies different types of ECMP Load share hash algorithm
version_added: 2.5.0
type: str
choices:
- CRC
- XOR
- CRC_32LO
- CRC_32HI
- CRC_CCITT
- CRC_XOR
- JENKINS_HASH_LO
- JENKINS_HASH_HI
state:
description:
- Specifies the operation to be performed on the system parameters configured on the device.
Expand All @@ -104,6 +118,7 @@
#ip anycast-address enable
#ipv6 anycast-address enable
#interface-naming standard
#ip load-share hash algorithm JENKINS_HASH_HI

- name: Merge provided configuration with device configuration
dellemc.enterprise_sonic.sonic_system:
Expand All @@ -112,6 +127,7 @@
interface_naming: standard
anycast_address:
ipv6: true
load_share_hash_algo: JENKINS_HASH_HI
state: deleted

# After state:
Expand All @@ -134,6 +150,7 @@
#ip anycast-address enable
#ipv6 anycast-address enable
#interface-naming standard
#ip load-share hash algorithm JENKINS_HASH_HI

- name: Delete all system related configs in device configuration
dellemc.enterprise_sonic.sonic_system:
Expand Down Expand Up @@ -164,6 +181,7 @@
ipv6: true
ipv4: true
mac_address: aa:bb:cc:dd:ee:ff
load_share_hash_algo: JENKINS_HASH_HI
state: merged

# After state:
Expand All @@ -175,6 +193,7 @@
#ip anycast-address enable
#ipv6 anycast-address enable
#interface-naming standard
#ip load-share hash algorithm JENKINS_HASH_HI

# Using replaced
#
Expand Down Expand Up @@ -219,6 +238,7 @@
anycast_address:
ipv6: true
ipv4: true
load_share_hash_algo: JENKINS_HASH_HI
state: replaced

# After state:
Expand All @@ -229,6 +249,7 @@
#ip anycast-address enable
#ipv6 anycast-address enable
#interface-naming standard
#ip load-share hash algorithm JENKINS_HASH_HI

# Using overridden
#
Expand All @@ -240,6 +261,7 @@
#ip anycast-mac-address aa:bb:cc:dd:ee:ff
#ip anycast-address enable
#ipv6 anycast-address enable
#ip load-share hash algorithm JENKINS_HASH_HI

- name: Override system configuration.
sonic_system:
Expand All @@ -249,6 +271,7 @@
anycast_address:
ipv4: true
mac_address: bb:aa:cc:dd:ee:ff
load_share_hash_algo: CRC_XOR
state: overridden

# After state:
Expand All @@ -259,6 +282,7 @@
#ip anycast-mac-address bb:aa:cc:dd:ee:ff
#ip anycast-address enable
#interface-naming standard
#ip load-share hash algorithm CRC_XOR

# Using merged
#
Expand All @@ -274,6 +298,7 @@
hostname: SONIC
interface_naming: standard
auto_breakout: ENABLE
load_share_hash_algo: JENKINS_HASH_HI
state: merged

# After state:
Expand All @@ -284,6 +309,7 @@
#hostname SONIC
#interface-naming standard
#auto-breakout
#ip load-share hash algorithm JENKINS_HASH_HI

# Using deleted
#
Expand All @@ -295,12 +321,14 @@
#hostname SONIC
#interface-naming standard
#auto-breakout
#ip load-share hash algorithm JENKINS_HASH_HI

- name: Delete auto-breakout configuration on the device
dellemc.enterprise_sonic.sonic_system:
config:
hostname: SONIC
auto_breakout: ENABLE
load_share_hash_algo: JENKINS_HASH_HI
state: deleted

# After state:
Expand Down
5 changes: 5 additions & 0 deletions tests/regression/roles/sonic_system/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ tests:
ipv4: false
ipv6: false
auto_breakout: ENABLE
load_share_hash_algo: JENKINS_HASH_HI

- name: test_case_02
description: Update created System properties
state: merged
input:
hostname: SONIC-new
interface_naming: standard_extended
load_share_hash_algo: JENKINS_HASH_LO

- name: test_case_03
description: Update System properties - associate mac address
Expand All @@ -36,6 +38,7 @@ tests:
anycast_address:
ipv4: false
auto_breakout: ENABLE
load_share_hash_algo: JENKINS_HASH_LO

- name: test_case_05
description: Delete System associated anycast mac address
Expand All @@ -54,6 +57,7 @@ tests:
ipv4: true
mac_address: 00:09:5B:EC:EE:F2
auto_breakout: ENABLE
load_share_hash_algo: CRC_XOR

- name: test_case_07
description: Replace some System configuration
Expand All @@ -74,6 +78,7 @@ tests:
anycast_address:
ipv4: true
auto_breakout: ENABLE
load_share_hash_algo: CRC_32HI

test_delete_all:
- name: del_all_test_case_01
Expand Down
Loading
Loading