Skip to content

Commit

Permalink
Merge branch 'main' into qos_scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
stalabi1 authored Apr 12, 2024
2 parents 469087c + ee72140 commit e85bf6b
Show file tree
Hide file tree
Showing 44 changed files with 1,281 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- sonic_logging - Add support for protocol option in logging module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/317).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- sonic_route_maps - Add playbook check and diff modes support for route_maps module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/331).
- sonic_prefix_lists - Add playbook check and diff modes support for prefix_lists module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/331).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- sonic_bgp_neighbors - Add playbook check and diff modes support for bgp_neighbors module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/360).
- sonic_bgp_neighbors_af - Add playbook check and diff modes support for bgp_neighbors_af module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/360).
2 changes: 2 additions & 0 deletions changelogs/fragments/366-github-issue-357-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- sonic_interfaces - Fix GitHub issue 357 - set proper default value when deleted (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/366).
1 change: 1 addition & 0 deletions plugins/module_utils/network/sonic/argspec/facts/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, **kwargs):
'route_maps',
'stp',
'sflow',
'fips',
'qos_scheduler'
]

Expand Down
Empty file.
54 changes: 54 additions & 0 deletions plugins/module_utils/network/sonic/argspec/fips/fips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# -*- coding: utf-8 -*-
# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

#############################################
# WARNING #
#############################################
#
# This file is auto generated by the resource
# module builder playbook.
#
# Do not edit this file manually.
#
# Changes to this file will be over written
# by the resource module builder.
#
# Changes should be made in the model used to
# generate this file or in the resource module
# builder template.
#
#############################################

"""
The arg spec for the sonic_fips module
"""

from __future__ import absolute_import, division, print_function
__metaclass__ = type


class FipsArgs(object): # pylint: disable=R0903
"""The arg spec for the sonic_fips module
"""

def __init__(self, **kwargs):
pass

argument_spec = {
'config': {
'options': {
'enable': {
'type': 'bool'
}
},
'type': 'dict'
},
'state': {
'choices': ['merged', 'deleted'],
'default': 'merged',
'type': 'str'
}
} # pylint: disable=C0301
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def __init__(self, **kwargs):
'type': 'str'},
'remote_port': {'type': 'int'},
'source_interface': {'type': 'str'},
'vrf': {'type': 'str'}
'vrf': {'type': 'str'},
'protocol': {'choices': ['TCP', 'UDP'],
'type': 'str'},
},
'type': 'list'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils import (
update_states,
get_diff,
remove_matching_defaults
remove_matching_defaults,
add_config_defaults,
remove_empties_from_list
)
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.formatted_diff_utils import (
__DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF,
__DELETE_LEAFS_THEN_CONFIG_IF_NO_NON_KEY_LEAF,
get_new_config,
get_formatted_config_diff
)
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.sort_config_util import (
sort_config,
remove_void_config
)
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.bgp_utils import (
validate_bgps,
Expand Down Expand Up @@ -139,6 +151,45 @@
],
]

is_delete_all = False
TEST_KEYS_sort_config = [
{'config': {'__test_keys': ('vrf_name', 'bgp_as')}},
{'neighbors': {'__test_keys': ('neighbor',)}},
{'peer_group': {'__test_keys': ('name',)}},
{'afis': {'__test_keys': ('afi', 'safi')}},
]


def __derive_bgp_nbrs_delete_op(key_set, command, exist_conf):

done, new_conf = __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF(key_set, command, exist_conf)
if done:
return done, new_conf
else:
return __DELETE_LEAFS_THEN_CONFIG_IF_NO_NON_KEY_LEAF(key_set, command, new_conf)


def __derive_bgp_neighbors_delete_op(key_set, command, exist_conf):

if is_delete_all:
new_conf = {'bgp_as': exist_conf['bgp_as'], 'vrf_name': exist_conf['vrf_name']}
return True, new_conf

done, new_conf = __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF(key_set, command, exist_conf)
if not new_conf:
new_conf = {'bgp_as': command['bgp_as'], 'vrf_name': command['vrf_name']}

return done, new_conf


TEST_KEYS_generate_config = [
{'__default_ops': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{'config': {'vrf_name': '', 'bgp_as': '', '__delete_op': __derive_bgp_neighbors_delete_op}},
{'neighbors': {'neighbor': '', '__delete_op': __derive_bgp_nbrs_delete_op}},
{'peer_group': {'name': '', '__delete_op': __derive_bgp_nbrs_delete_op}},
{'afis': {'afi': '', 'safi': '', '__delete_op': __derive_bgp_nbrs_delete_op}},
]


class Bgp_neighbors(ConfigBase):
"""
Expand Down Expand Up @@ -198,6 +249,22 @@ def execute_module(self):
if result['changed']:
result['after'] = changed_bgp_facts

new_config = changed_bgp_facts
old_config = existing_bgp_facts
if self._module.check_mode:
result.pop('after', None)
new_config = get_new_config(commands, existing_bgp_facts,
TEST_KEYS_generate_config)
new_config = self.post_process_generated_config(new_config)
old_config = remove_empties_from_list(old_config)
result['after(generated)'] = new_config

if self._module._diff:
new_config = sort_config(new_config, TEST_KEYS_sort_config)
old_config = sort_config(old_config, TEST_KEYS_sort_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down Expand Up @@ -265,6 +332,7 @@ def _state_deleted(self, want, have, diff):
:returns: the commands necessary to remove the current configuration
of the provided objects
"""
global is_delete_all
is_delete_all = False
if not want:
is_delete_all = True
Expand Down Expand Up @@ -490,7 +558,9 @@ def find_pg(self, have, bgp_as, vrf_name, peergroup):

def find_af(self, have, bgp_as, vrf_name, peergroup, afi, safi):
mat_pg = self.find_pg(have, bgp_as, vrf_name, peergroup)
if mat_pg and mat_pg['address_family'].get('afis', None) is not None:
if mat_pg and mat_pg.get('address_family', None) and \
mat_pg['address_family'].get('afis', None) is not None:

mat_af = next((af for af in mat_pg['address_family']['afis'] if af['afi'] == afi and af['safi'] == safi), None)
return mat_af

Expand Down Expand Up @@ -1100,3 +1170,14 @@ def get_delete_bgp_neighbor_requests(self, commands, have, want, is_delete_all):
if peer_group:
requests.extend(self.get_delete_specific_bgp_peergroup_param_request(vrf_name, cmd, want_match))
return requests

def post_process_generated_config(self, configs):
TEST_KEYS_remove_void_config = [
{'neighbors': {'__test_keys': ('neighbor',)}},
{'peer_group': {'__test_keys': ('name',)}},
{'afis': {'__test_keys': ('afi', 'safi')}},
]
confs = remove_void_config(configs, TEST_KEYS_remove_void_config)
for default_entry in default_entries:
add_config_defaults(confs, default_entry)
return confs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils import (
update_states,
get_diff,
remove_empties_from_list
)
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.formatted_diff_utils import (
__DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF,
__DELETE_LEAFS_THEN_CONFIG_IF_NO_NON_KEY_LEAF,
get_new_config,
get_formatted_config_diff
)
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.sort_config_util import (
sort_config,
remove_void_config
)
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.bgp_utils import (
validate_bgps,
Expand All @@ -46,6 +57,46 @@
]


is_delete_all = False
TEST_KEYS_sort_config = [
{'config': {'__test_keys': ('vrf_name', 'bgp_as')}},
{'neighbors': {'__test_keys': ('neighbor',)}},
{'address_family': {'__test_keys': ('afi', 'safi')}},
{'route_map': {'__test_keys': ('name', 'direction')}},
]


def __derive_bgp_nbrs_af_delete_op(key_set, command, exist_conf):

done, new_conf = __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF(key_set, command, exist_conf)
if done:
return done, new_conf
else:
return __DELETE_LEAFS_THEN_CONFIG_IF_NO_NON_KEY_LEAF(key_set, command, new_conf)


def __derive_bgp_neighbors_af_delete_op(key_set, command, exist_conf):

if is_delete_all:
new_conf = {'bgp_as': exist_conf['bgp_as'], 'vrf_name': exist_conf['vrf_name']}
return True, new_conf

done, new_conf = __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF(key_set, command, exist_conf)
if not new_conf:
new_conf = {'bgp_as': command['bgp_as'], 'vrf_name': command['vrf_name']}

return done, new_conf


TEST_KEYS_generate_config = [
{'__default_ops': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{'config': {'vrf_name': '', 'bgp_as': '', '__delete_op': __derive_bgp_neighbors_af_delete_op}},
{'neighbors': {'neighbor': '', '__delete_op': __derive_bgp_nbrs_af_delete_op}},
{'address_family': {'afi': '', 'safi': '', '__delete_op': __derive_bgp_nbrs_af_delete_op}},
{'route_map': {'name': '', 'direction': '', '__delete_op': __derive_bgp_nbrs_af_delete_op}},
]


class Bgp_neighbors_af(ConfigBase):
"""
The sonic_bgp_neighbors_af class
Expand Down Expand Up @@ -119,6 +170,22 @@ def execute_module(self):
if result['changed']:
result['after'] = changed_bgp_neighbors_af_facts

new_config = changed_bgp_neighbors_af_facts
old_config = existing_bgp_neighbors_af_facts
if self._module.check_mode:
result.pop('after', None)
new_config = get_new_config(commands, existing_bgp_neighbors_af_facts,
TEST_KEYS_generate_config)
new_config = self.post_process_generated_config(new_config)
old_config = remove_empties_from_list(old_config)
result['after(generated)'] = new_config

if self._module._diff:
new_config = sort_config(new_config, TEST_KEYS_sort_config)
old_config = sort_config(old_config, TEST_KEYS_sort_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down Expand Up @@ -190,6 +257,7 @@ def _state_deleted(self, want, have, diff):
of the provided objects
"""
# if want is none, then delete all the bgp_neighbors_afs
global is_delete_all
is_delete_all = False
if not want:
commands = have
Expand Down Expand Up @@ -577,3 +645,11 @@ def get_delete_bgp_neighbors_af_requests(self, commands, have, is_delete_all):
match = next((have_cfg for have_cfg in have if have_cfg['vrf_name'] == vrf_name and have_cfg['bgp_as'] == as_val), None)
requests.extend(self.get_delete_single_bgp_neighbors_af_request(cmd, is_delete_all, match))
return requests

def post_process_generated_config(self, configs):
TEST_KEYS_remove_void_config = [
{'neighbors': {'__test_keys': ('neighbor',)}},
{'address_family': {'__test_keys': ('afi', 'safi')}},
]
confs = remove_void_config(configs, TEST_KEYS_remove_void_config)
return confs
Empty file.
Loading

0 comments on commit e85bf6b

Please sign in to comment.